-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathHttpIntegrationTest.java
More file actions
54 lines (45 loc) · 1.91 KB
/
Copy pathHttpIntegrationTest.java
File metadata and controls
54 lines (45 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.amazonaws.springcloudfunctiondemo;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class HttpIntegrationTest {
@LocalServerPort
private int port;
@Autowired
private TestRestTemplate restTemplate;
@Test
public void testUppercaseFunction() {
// Make the request
var response = restTemplate.postForEntity(
"http://localhost:" + port + "/upperCase",
"Spring",
String.class);
// Verify response
assertEquals(HttpStatus.OK, response.getStatusCode());
assertNotNull(response.getBody());
assertEquals("SPRING", response.getBody());
}
@Test
public void testHandleUnicornHelloFunction() {
var fluffy = new com.amazonaws.springcloudfunctiondemo.Unicorn("Fluffy", 3);
var headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
// Make the request for an existing unicorn
var response = restTemplate.postForEntity(
"http://localhost:" + port + "/helloUnicorn",
fluffy,
String.class);
// Verify response
assertEquals(HttpStatus.OK, response.getStatusCode());
assertNotNull(response.getBody());
assertEquals("Hello Fluffy! You are 3 years old!", response.getBody());
}
}