Skip to content

Commit

Permalink
#1298 javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
Pascal Romanens committed Nov 29, 2023
1 parent dd13481 commit a414353
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,16 @@
import com.amazonaws.services.lambda.runtime.events.SQSBatchResponse;

import software.amazon.lambda.powertools.validation.Validation;
public class Function implements RequestHandler<ApplicationLoadBalancerRequestEvent, ApplicationLoadBalancerResponseEvent> {
// @Validation(inboundSchema = "classpath:/validation/inbound_schema.json", outboundSchema = "classpath:/validation/outbound_schema.json")
// public String handleRequest(SQSEvent input, Context context) {
// return "OK";
// }


@Validation(inboundSchema = "classpath:/validation/inbound_schema.json", outboundSchema = "classpath:/validation/outbound_schema.json")
// @Validation(inboundSchema = "classpath:/validation/inbound_schema.json")
public ApplicationLoadBalancerResponseEvent handleRequest(ApplicationLoadBalancerRequestEvent input, Context context) {
ApplicationLoadBalancerResponseEvent response = new ApplicationLoadBalancerResponseEvent();
response.setBody(input.getBody());
response.setStatusCode(200);
response.setIsBase64Encoded(false);
return response;
}

public class Function
implements RequestHandler<ApplicationLoadBalancerRequestEvent, ApplicationLoadBalancerResponseEvent> {
@Validation(inboundSchema = "classpath:/validation/inbound_schema.json", outboundSchema = "classpath:/validation/outbound_schema.json")
public ApplicationLoadBalancerResponseEvent handleRequest(ApplicationLoadBalancerRequestEvent input,
Context context) {
ApplicationLoadBalancerResponseEvent response = new ApplicationLoadBalancerResponseEvent();
response.setBody(input.getBody());
response.setStatusCode(200);
response.setIsBase64Encoded(false);
return response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,30 @@

import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
import com.amazonaws.services.lambda.runtime.events.APIGatewayV2HTTPResponse;
import com.amazonaws.services.lambda.runtime.events.APIGatewayV2WebSocketResponse;
import com.amazonaws.services.lambda.runtime.events.ApplicationLoadBalancerResponseEvent;

/**
* Provides test arguments that are used in unit tests.
* It creates API Gateway response arguments that can be used to confirm
* that @Validation validates responses and returns a response's headers even
* when validation fails
*/
public class HandledResponseEventsArgumentsProvider implements ArgumentsProvider {

@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {

String body = "{id";

final APIGatewayProxyResponseEvent apiGWProxyResponseEvent = new APIGatewayProxyResponseEvent()
.withBody(body)
.withHeaders(Map.of("header1", "value1,value2,value3"))
.withMultiValueHeaders(Map.of("header1", List.of("value1", "value2", "value3")));
@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {

APIGatewayV2HTTPResponse apiGWV2HTTPResponse = new APIGatewayV2HTTPResponse();
apiGWV2HTTPResponse.setBody(body);
apiGWV2HTTPResponse.setHeaders(Map.of("header1", "value1,value2,value3"));
apiGWV2HTTPResponse.setMultiValueHeaders(Map.of("header1", List.of("value1", "value2", "value3")));
String body = "{id";

APIGatewayV2WebSocketResponse apiGWV2WebSocketResponse = new APIGatewayV2WebSocketResponse();
apiGWV2WebSocketResponse.setBody(body);
final APIGatewayProxyResponseEvent apiGWProxyResponseEvent = new APIGatewayProxyResponseEvent()
.withBody(body)
.withHeaders(Map.of("header1", "value1,value2,value3"))
.withMultiValueHeaders(Map.of("header1", List.of("value1", "value2", "value3")));

ApplicationLoadBalancerResponseEvent albResponseEvent = new ApplicationLoadBalancerResponseEvent();
albResponseEvent.setBody(body);
APIGatewayV2HTTPResponse apiGWV2HTTPResponse = new APIGatewayV2HTTPResponse();
apiGWV2HTTPResponse.setBody(body);
apiGWV2HTTPResponse.setHeaders(Map.of("header1", "value1,value2,value3"));
apiGWV2HTTPResponse.setMultiValueHeaders(Map.of("header1", List.of("value1", "value2", "value3")));

return Stream.of(apiGWProxyResponseEvent, apiGWV2HTTPResponse).map(Arguments::of);
}
return Stream.of(apiGWProxyResponseEvent, apiGWV2HTTPResponse).map(Arguments::of);
}
}

0 comments on commit a414353

Please sign in to comment.