Skip to content

Commit 3042800

Browse files
committed
GH-997 Adding test to validate AWS Context set as header
Resolves #997
1 parent 9074b0b commit 3042800

File tree

1 file changed

+6
-24
lines changed
  • spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/test/java/org/springframework/cloud/function/adapter/aws

1 file changed

+6
-24
lines changed

spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/test/java/org/springframework/cloud/function/adapter/aws/FunctionInvokerTests.java

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.fasterxml.jackson.databind.ObjectMapper;
4545
import org.junit.jupiter.api.BeforeEach;
4646
import org.junit.jupiter.api.Test;
47+
import org.mockito.Mockito;
4748
import reactor.core.publisher.Flux;
4849
import reactor.core.publisher.Mono;
4950

@@ -784,7 +785,7 @@ public void testLBEventAsMessage() throws Exception {
784785

785786
InputStream targetStream = new ByteArrayInputStream(this.sampleLBEvent.getBytes());
786787
ByteArrayOutputStream output = new ByteArrayOutputStream();
787-
invoker.handleRequest(targetStream, output, null);
788+
invoker.handleRequest(targetStream, output, Mockito.mock(Context.class));
788789

789790
Map result = mapper.readValue(output.toByteArray(), Map.class);
790791
assertThat(result.get("body")).isEqualTo("\"Hello from ELB\"");
@@ -1004,26 +1005,6 @@ public void testApiGatewayInAndOutV2() throws Exception {
10041005
assertThat(headers.get("foo")).isEqualTo("bar");
10051006
}
10061007

1007-
// @SuppressWarnings("rawtypes")
1008-
// @Test
1009-
// public void testApiGatewayInAndOutWithException() throws Exception {
1010-
// System.setProperty("MAIN_CLASS", ApiGatewayConfiguration.class.getName());
1011-
// System.setProperty("spring.cloud.function.definition", "inputOutputApiEventException");
1012-
// FunctionInvoker invoker = new FunctionInvoker();
1013-
//
1014-
// InputStream targetStream = new ByteArrayInputStream(this.apiGatewayEvent.getBytes());
1015-
// ByteArrayOutputStream output = new ByteArrayOutputStream();
1016-
// invoker.handleRequest(targetStream, output, null);
1017-
//
1018-
// Map result = mapper.readValue(output.toByteArray(), Map.class);
1019-
// assertThat(result.get("body")).isEqualTo("Intentional");
1020-
//
1021-
// Map headers = (Map) result.get("headers");
1022-
// assertThat(headers.get("foo")).isEqualTo("bar");
1023-
// }
1024-
1025-
1026-
10271008
@SuppressWarnings("rawtypes")
10281009
@Test
10291010
public void testApiGatewayEventAsMessage() throws Exception {
@@ -1347,9 +1328,10 @@ public Function<ApplicationLoadBalancerRequestEvent, ApplicationLoadBalancerResp
13471328

13481329
@Bean
13491330
public Function<Message<ApplicationLoadBalancerRequestEvent>, String> inputLBEventAsMessage(JsonMapper jsonMapper) {
1350-
return v -> {
1351-
System.out.println("Received: " + v);
1352-
return v.getPayload().getBody();
1331+
return message -> {
1332+
System.out.println("Received: " + message);
1333+
assertThat(message.getHeaders().get(AWSLambdaUtils.AWS_CONTEXT)).isNotNull();
1334+
return message.getPayload().getBody();
13531335
};
13541336
}
13551337

0 commit comments

Comments
 (0)