|
2 | 2 |
|
3 | 3 | import com.amazonaws.services.lambda.runtime.api.client.runtimeapi.dto.InvocationRequest; |
4 | 4 | import org.junit.jupiter.api.Test; |
| 5 | +import org.junit.jupiter.params.ParameterizedTest; |
| 6 | +import org.junit.jupiter.params.provider.NullSource; |
| 7 | +import org.junit.jupiter.params.provider.ValueSource; |
5 | 8 |
|
6 | 9 | import java.io.ByteArrayOutputStream; |
7 | 10 | import java.util.ArrayList; |
|
13 | 16 | import java.util.concurrent.TimeUnit; |
14 | 17 |
|
15 | 18 | import static org.junit.jupiter.api.Assertions.assertEquals; |
16 | | -import static org.junit.jupiter.api.Assertions.assertFalse; |
17 | 19 | import static org.junit.jupiter.api.Assertions.assertTrue; |
18 | 20 |
|
19 | 21 | class EventHandlerLoaderTest { |
@@ -60,32 +62,48 @@ void PojoHandlerTest_twoParams() throws Exception { |
60 | 62 | assertSuccessfulInvocation(lambdaRequestHandler); |
61 | 63 | } |
62 | 64 |
|
63 | | - @Test |
64 | | - void PojoHandler_outputSerializer_ignoresClientContextPlatform() throws Exception { |
| 65 | + // Before 2.13.0, a client context with env.platform equal to "Android" (case-insensitive) switched POJO |
| 66 | + // serialization to Gson, which binds fields: pojoOutputHandler returned {"internalField":"field-based-value"} |
| 67 | + // and pojoInputHandler returned "x:true". Every client context must now produce the Jackson result. |
| 68 | + |
| 69 | + @ParameterizedTest(name = "clientContext={0}") |
| 70 | + @NullSource |
| 71 | + @ValueSource(strings = { |
| 72 | + "{\"env\":{\"platform\":\"Android\"}}", |
| 73 | + "{\"env\":{\"platform\":\"android\"}}", |
| 74 | + "{\"env\":{\"platform\":\"iPhoneOS\"}}", |
| 75 | + "{\"env\":{}}", |
| 76 | + "{}" |
| 77 | + }) |
| 78 | + void PojoHandler_outputSerializer_ignoresClientContextPlatform(String clientContext) throws Exception { |
65 | 79 | LambdaRequestHandler handler = |
66 | 80 | getLambdaRequestHandler("test.lambda.handlers.POJOHanlderImpl::pojoOutputHandler"); |
67 | 81 |
|
68 | 82 | InvocationRequest request = getTestInvocationRequest(); |
69 | | - request.setClientContext("{\"env\":{\"platform\":\"Android\"}}"); |
70 | | - |
71 | | - String result = handler.call(request).toString(); |
| 83 | + request.setClientContext(clientContext); |
72 | 84 |
|
73 | | - assertTrue(result.contains("beanProperty"), |
74 | | - "expected property-based (Jackson) serialization, got: " + result); |
75 | | - assertFalse(result.contains("internalField"), |
76 | | - "caller ClientContext must not switch serialization to field-based (Gson), got: " + result); |
| 85 | + assertEquals("{\"beanProperty\":\"property-based-value\"}", handler.call(request).toString()); |
77 | 86 | } |
78 | 87 |
|
79 | | - @Test |
80 | | - void PojoHandler_inputSerializer_bindsOnlyBeanProperties() throws Exception { |
| 88 | + @ParameterizedTest(name = "clientContext={0}") |
| 89 | + @NullSource |
| 90 | + @ValueSource(strings = { |
| 91 | + "{\"env\":{\"platform\":\"Android\"}}", |
| 92 | + "{\"env\":{\"platform\":\"android\"}}", |
| 93 | + "{\"env\":{\"platform\":\"iPhoneOS\"}}", |
| 94 | + "{\"env\":{}}", |
| 95 | + "{}" |
| 96 | + }) |
| 97 | + void PojoHandler_inputSerializer_ignoresClientContextPlatform(String clientContext) throws Exception { |
81 | 98 | LambdaRequestHandler handler = |
82 | 99 | getLambdaRequestHandler("test.lambda.handlers.POJOHanlderImpl::pojoInputHandler"); |
83 | 100 |
|
84 | 101 | InvocationRequest request = getTestInvocationRequest(); |
85 | | - request.setClientContext("{\"env\":{\"platform\":\"Android\"}}"); |
| 102 | + request.setClientContext(clientContext); |
86 | 103 | request.setContent("{\"name\":\"x\",\"locked\":true}".getBytes()); |
87 | 104 |
|
88 | | - assertEquals("false", handler.call(request).toString()); |
| 105 | + // name has a setter and binds; locked has only a getter and keeps its default |
| 106 | + assertEquals("\"x:false\"", handler.call(request).toString()); |
89 | 107 | } |
90 | 108 |
|
91 | 109 | private LambdaRequestHandler getLambdaRequestHandler(String handler) throws ClassNotFoundException { |
|
0 commit comments