@@ -18,7 +18,9 @@ package org.springframework.cloud.function.adapter.aws;
|
|||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
|
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
|
||||||
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
|
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
|
||||||
@@ -41,8 +43,23 @@ public class SpringBootApiGatewayRequestHandlerTests {
|
|||||||
|
|
||||||
private SpringBootApiGatewayRequestHandler handler;
|
private SpringBootApiGatewayRequestHandler handler;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void supplierBean() {
|
||||||
|
System.setProperty("function.name", "supplier");
|
||||||
|
this.handler = new SpringBootApiGatewayRequestHandler(FunctionConfig.class);
|
||||||
|
APIGatewayProxyRequestEvent request = new APIGatewayProxyRequestEvent();
|
||||||
|
|
||||||
|
Object output = this.handler.handleRequest(request, null);
|
||||||
|
assertThat(output).isInstanceOf(APIGatewayProxyResponseEvent.class);
|
||||||
|
assertThat(((APIGatewayProxyResponseEvent) output).getStatusCode())
|
||||||
|
.isEqualTo(200);
|
||||||
|
assertThat(((APIGatewayProxyResponseEvent) output).getBody())
|
||||||
|
.isEqualTo("\"hello!\"");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void functionBean() {
|
public void functionBean() {
|
||||||
|
System.setProperty("function.name", "function");
|
||||||
this.handler = new SpringBootApiGatewayRequestHandler(FunctionConfig.class);
|
this.handler = new SpringBootApiGatewayRequestHandler(FunctionConfig.class);
|
||||||
APIGatewayProxyRequestEvent request = new APIGatewayProxyRequestEvent();
|
APIGatewayProxyRequestEvent request = new APIGatewayProxyRequestEvent();
|
||||||
request.setBody("{\"value\":\"foo\"}");
|
request.setBody("{\"value\":\"foo\"}");
|
||||||
@@ -55,6 +72,19 @@ public class SpringBootApiGatewayRequestHandlerTests {
|
|||||||
.isEqualTo("{\"value\":\"FOO\"}");
|
.isEqualTo("{\"value\":\"FOO\"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void consumerBean() {
|
||||||
|
System.setProperty("function.name", "consumer");
|
||||||
|
this.handler = new SpringBootApiGatewayRequestHandler(FunctionConfig.class);
|
||||||
|
APIGatewayProxyRequestEvent request = new APIGatewayProxyRequestEvent();
|
||||||
|
request.setBody("\"strVal\":\"test for consumer\"");
|
||||||
|
|
||||||
|
Object output = this.handler.handleRequest(request, null);
|
||||||
|
assertThat(output).isInstanceOf(APIGatewayProxyResponseEvent.class);
|
||||||
|
assertThat(((APIGatewayProxyResponseEvent) output).getStatusCode())
|
||||||
|
.isEqualTo(200);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void functionMessageBean() {
|
public void functionMessageBean() {
|
||||||
this.handler = new SpringBootApiGatewayRequestHandler(
|
this.handler = new SpringBootApiGatewayRequestHandler(
|
||||||
@@ -82,6 +112,16 @@ public class SpringBootApiGatewayRequestHandlerTests {
|
|||||||
return foo -> new Bar(foo.getValue().toUpperCase());
|
return foo -> new Bar(foo.getValue().toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Consumer<String> consumer() {
|
||||||
|
return v -> System.out.println(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Supplier<String> supplier() {
|
||||||
|
return () -> "hello!";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
|
|||||||
Reference in New Issue
Block a user