Skip to content

Commit

Permalink
aws-powertools#1298 updated tests in pt-examples-validation + sonar q…
Browse files Browse the repository at this point in the history
…aulity fixes
  • Loading branch information
Pascal Romanens committed Oct 24, 2023
1 parent f311722 commit ddbb2a1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ public void shouldReturnOkStatusWhenInputIsValid() {
}

@Test
public void shouldThrowExceptionWhenRequestInInvalid() {
public void shouldReturnBadRequestWhenRequestInInvalid() {
String bodyWithMissedId = "{\n" +
" \"name\": \"FooBar XY\",\n" +
" \"price\": 258\n" +
" }";
APIGatewayProxyRequestEvent request = new APIGatewayProxyRequestEvent().withBody(bodyWithMissedId);

assertThrows(ValidationException.class, () -> inboundValidation.handleRequest(request, context));
APIGatewayProxyResponseEvent response = inboundValidation.handleRequest(request, context);

assertEquals(400, response.getStatusCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void setUp() {

@ParameterizedTest
@ArgumentsSource(ResponseEventsArgumentsProvider.class)
public void testValidateOutboundJsonSchemaWithExceptions(Object object) throws Throwable {
void testValidateOutboundJsonSchemaWithExceptions(Object object) throws Throwable {
when(validation.schemaVersion()).thenReturn(SpecVersion.VersionFlag.V7);
when(pjp.getSignature()).thenReturn(signature);
when(pjp.getSignature().getDeclaringType()).thenReturn(RequestHandler.class);
Expand All @@ -124,7 +124,7 @@ public void testValidateOutboundJsonSchemaWithExceptions(Object object) throws T

@ParameterizedTest
@ArgumentsSource(HandledResponseEventsArgumentsProvider.class)
public void testValidateOutboundJsonSchemaWithHandledExceptions(Object object) throws Throwable {
void testValidateOutboundJsonSchemaWithHandledExceptions(Object object) throws Throwable {
when(validation.schemaVersion()).thenReturn(SpecVersion.VersionFlag.V7);
when(pjp.getSignature()).thenReturn(signature);
when(pjp.getSignature().getDeclaringType()).thenReturn(RequestHandler.class);
Expand All @@ -139,13 +139,13 @@ public void testValidateOutboundJsonSchemaWithHandledExceptions(Object object) t
if (response instanceof APIGatewayProxyResponseEvent) {
assertThat(response).isInstanceOfSatisfying(APIGatewayProxyResponseEvent.class, t -> {
assertThat(t.getStatusCode()).isEqualTo(400);
assertThat(t.getBody()).satisfies(x -> StringUtils.isNotBlank(x));
assertThat(t.getBody()).isNotBlank();
assertThat(t.getIsBase64Encoded()).isFalse();
});
} else if (response instanceof APIGatewayV2HTTPResponse) {
assertThat(response).isInstanceOfSatisfying(APIGatewayV2HTTPResponse.class, t -> {
assertThat(t.getStatusCode()).isEqualTo(400);
assertThat(t.getBody()).satisfies(x -> StringUtils.isNotBlank(x));
assertThat(t.getBody()).isNotBlank();
assertThat(t.getIsBase64Encoded()).isFalse();
});
} else {
Expand Down Expand Up @@ -199,7 +199,7 @@ public void validate_inputKO_schemaInClasspath_shouldThrowValidationException()
"}");
// price is negative
APIGatewayProxyResponseEvent response = handler.handleRequest(event, context);
assertThat(response.getBody()).satisfies(x -> StringUtils.isNotBlank(x));
assertThat(response.getBody()).isNotBlank();
assertThat(response.getStatusCode()).isEqualTo(400);
}

Expand Down Expand Up @@ -229,7 +229,7 @@ public void validate_inputKO_schemaInString_shouldThrowValidationException() {
"}");

APIGatewayV2HTTPResponse response = handler.handleRequest(event, context);
assertThat(response.getBody()).satisfies(x -> StringUtils.isNotBlank(x));
assertThat(response.getBody()).isNotBlank();
assertThat(response.getStatusCode()).isEqualTo(400);
}

Expand Down

0 comments on commit ddbb2a1

Please sign in to comment.