Java Code Examples for com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent#setBody()

The following examples show how to use com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent#setBody() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpringBootApiGatewayRequestHandlerTests.java    From spring-cloud-function with Apache License 2.0 6 votes vote down vote up
@Test
public void functionBean() {
	System.setProperty("function.name", "function");
	this.handler = new SpringBootApiGatewayRequestHandler(FunctionConfig.class);
	APIGatewayProxyRequestEvent request = new APIGatewayProxyRequestEvent();
	request.setBody("{\"value\":\"foo\"}");

	Object output = this.handler.handleRequest(request, null);
	assertThat(output).isInstanceOf(APIGatewayProxyResponseEvent.class);
	assertThat(((APIGatewayProxyResponseEvent) output).getStatusCode())
			.isEqualTo(200);
	assertThat(((APIGatewayProxyResponseEvent) output).getBody())
			.isEqualTo("{\"value\":\"FOO\"}");

	APIGatewayProxyRequestEvent bodyEncryptedRequest = new APIGatewayProxyRequestEvent();
	bodyEncryptedRequest.setBody(
			Base64.getEncoder().encodeToString("{\"value\":\"foo\"}".getBytes()));
	bodyEncryptedRequest.setIsBase64Encoded(true);

	output = this.handler.handleRequest(bodyEncryptedRequest, null);
	assertThat(output).isInstanceOf(APIGatewayProxyResponseEvent.class);
	assertThat(((APIGatewayProxyResponseEvent) output).getStatusCode())
			.isEqualTo(200);
	assertThat(((APIGatewayProxyResponseEvent) output).getBody())
			.isEqualTo("{\"value\":\"FOO\"}");
}
 
Example 2
Source File: SpringBootApiGatewayRequestHandlerTests.java    From spring-cloud-function with Apache License 2.0 6 votes vote down vote up
@Test
public void functionMessageBean() {
	this.handler = new SpringBootApiGatewayRequestHandler(
			FunctionMessageConfig.class);
	APIGatewayProxyRequestEvent request = new APIGatewayProxyRequestEvent();
	request.setBody("{\"value\":\"foo\"}");

	Object output = this.handler.handleRequest(request, null);
	assertThat(output).isInstanceOf(APIGatewayProxyResponseEvent.class);
	assertThat(((APIGatewayProxyResponseEvent) output).getStatusCode())
			.isEqualTo(200);
	assertThat(((APIGatewayProxyResponseEvent) output).getHeaders().get("spring"))
			.isEqualTo("cloud");
	assertThat(((APIGatewayProxyResponseEvent) output).getBody())
			.isEqualTo("{\"value\":\"FOO\"}");
}
 
Example 3
Source File: SpringBootApiGatewayRequestHandlerTests.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
@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);
}