17
17
*/
18
18
package com .github .kaklakariada .aws .lambda ;
19
19
20
+ import static java .util .Collections .emptyMap ;
20
21
import static org .junit .jupiter .api .Assertions .assertEquals ;
21
22
import static org .mockito .ArgumentMatchers .any ;
22
23
import static org .mockito .ArgumentMatchers .same ;
41
42
import com .fasterxml .jackson .databind .node .JsonNodeFactory ;
42
43
import com .fasterxml .jackson .databind .node .ObjectNode ;
43
44
import com .github .kaklakariada .aws .lambda .listener .RequestProcessingListener ;
44
- import com .github .kaklakariada .aws .lambda .model .request . ApiGatewayRequest ;
45
+ import com .github .kaklakariada .aws .lambda .model .response . ApiGatewayResponse ;
45
46
46
47
public class RequestHandlingServiceTest {
47
48
49
+ private static final String RESPONSE_MESSAGE = "msg" ;
50
+
48
51
@ Mock
49
52
private ControllerAdapter controllerMock ;
50
53
@ Mock
51
54
private Context contextMock ;
52
55
@ Mock
53
- private ApiGatewayRequest apiGatewayRequestMock ;
54
- @ Mock
55
56
private TestResponse responseMock ;
56
57
@ Mock
57
58
private RequestProcessingListener listenerMock ;
@@ -66,13 +67,20 @@ public void setup() {
66
67
objectMapper = new ObjectMapper ();
67
68
jsonFactory = JsonNodeFactory .instance ;
68
69
service = new RequestHandlingService (objectMapper , controllerMock , listenerMock );
69
- when (controllerMock .handleRequest (same (apiGatewayRequestMock ), same (contextMock )))
70
- .thenReturn (new TestResponse ());
70
+ when (controllerMock .handleRequest (any (), same (contextMock ))).thenReturn (new TestResponse (RESPONSE_MESSAGE ));
71
71
}
72
72
73
73
@ Test
74
74
public void testRequest () {
75
- assertEquals (response (200 , "null" ), handleRequest (jsonFactory .objectNode ()));
75
+ assertEquals (response (200 , "{\" message\" :\" " + RESPONSE_MESSAGE + "\" }" ),
76
+ handleRequest (jsonFactory .objectNode ()));
77
+ }
78
+
79
+ @ Test
80
+ public void testRequestReturnApiGatewayResponseUnchanged () {
81
+ final ApiGatewayResponse response = new ApiGatewayResponse (201 , emptyMap (), "response2" );
82
+ when (controllerMock .handleRequest (any (), same (contextMock ))).thenReturn (response );
83
+ assertEquals (response (201 , "response2" ), handleRequest (jsonFactory .objectNode ()));
76
84
}
77
85
78
86
@ Test
@@ -117,6 +125,15 @@ private String handleRequest(String request) {
117
125
return new String (outputStream .toByteArray (), StandardCharsets .UTF_8 );
118
126
}
119
127
120
- private static class TestResponse {
128
+ static class TestResponse {
129
+ private final String message ;
130
+
131
+ TestResponse (String message ) {
132
+ this .message = message ;
133
+ }
134
+
135
+ public String getMessage () {
136
+ return message ;
137
+ }
121
138
}
122
139
}
0 commit comments