use of com.amazonaws.serverless.exceptions.InvalidRequestEventException in project aws-serverless-java-container by awslabs.
the class AwsProxyHttpServletRequestReaderTest method readRequest_invalidEventEmptyMethod_expectException.
@Test
public void readRequest_invalidEventEmptyMethod_expectException() {
try {
AwsProxyRequest req = new AwsProxyRequestBuilder("/path", null).build();
reader.readRequest(req, null, null, ContainerConfig.defaultConfig());
fail("Expected InvalidRequestEventException");
} catch (InvalidRequestEventException e) {
assertEquals(AwsProxyHttpServletRequestReader.INVALID_REQUEST_ERROR, e.getMessage());
}
}
use of com.amazonaws.serverless.exceptions.InvalidRequestEventException in project aws-serverless-java-container by awslabs.
the class AwsProxyHttpServletRequestReaderTest method readRequest_contentCharset_setsDefaultCharsetWhenNotSpecified.
@Test
public void readRequest_contentCharset_setsDefaultCharsetWhenNotSpecified() {
String requestCharset = "application/json";
AwsProxyRequest request = new AwsProxyRequestBuilder(ENCODED_REQUEST_PATH, "GET").header(HttpHeaders.CONTENT_TYPE, requestCharset).build();
try {
HttpServletRequest servletRequest = reader.readRequest(request, null, null, ContainerConfig.defaultConfig());
assertNotNull(servletRequest);
assertNotNull(servletRequest.getHeader(HttpHeaders.CONTENT_TYPE));
String contentAndCharset = requestCharset + "; charset=" + LambdaContainerHandler.getContainerConfig().getDefaultContentCharset();
assertEquals(contentAndCharset, servletRequest.getHeader(HttpHeaders.CONTENT_TYPE));
assertEquals(LambdaContainerHandler.getContainerConfig().getDefaultContentCharset(), servletRequest.getCharacterEncoding());
} catch (InvalidRequestEventException e) {
e.printStackTrace();
fail("Could not read request");
}
}
use of com.amazonaws.serverless.exceptions.InvalidRequestEventException in project aws-serverless-java-container by awslabs.
the class AwsProxyRequestDispatcherTest method forwardRequest_nullHandler_throwsIllegalStateException.
@Test
public void forwardRequest_nullHandler_throwsIllegalStateException() throws InvalidRequestEventException {
AwsProxyRequest proxyRequest = new AwsProxyRequestBuilder("/hello", "GET").build();
HttpServletRequest servletRequest = requestReader.readRequest(proxyRequest, null, new MockLambdaContext(), ContainerConfig.defaultConfig());
AwsProxyRequestDispatcher dispatcher = new AwsProxyRequestDispatcher(FORWARD_PATH, false, null);
try {
dispatcher.forward(servletRequest, new AwsHttpServletResponse(servletRequest, new CountDownLatch(1)));
} catch (ServletException e) {
fail("Unexpected ServletException");
} catch (IOException e) {
fail("Unexpected IOException");
} catch (Exception e) {
assertTrue(e instanceof IllegalStateException);
return;
}
fail();
}
use of com.amazonaws.serverless.exceptions.InvalidRequestEventException in project aws-serverless-java-container by awslabs.
the class AwsProxyExceptionHandlerTest method typedHandle_InvalidRequestEventException_responseString.
@Test
public void typedHandle_InvalidRequestEventException_responseString() throws JsonProcessingException {
AwsProxyResponse resp = exceptionHandler.handle(new InvalidRequestEventException(INVALID_REQUEST_MESSAGE, null));
assertNotNull(resp);
String body = objectMapper.writeValueAsString(new ErrorModel(AwsProxyExceptionHandler.INTERNAL_SERVER_ERROR));
assertEquals(body, resp.getBody());
}
use of com.amazonaws.serverless.exceptions.InvalidRequestEventException in project aws-serverless-java-container by awslabs.
the class AwsProxyExceptionHandlerTest method typedHandle_InvalidRequestEventException_500State.
@Test
public void typedHandle_InvalidRequestEventException_500State() {
AwsProxyResponse resp = exceptionHandler.handle(new InvalidRequestEventException(INVALID_REQUEST_MESSAGE, null));
assertNotNull(resp);
assertEquals(500, resp.getStatusCode());
}
Aggregations