Search in sources :

Example 1 with InvalidRequestEventException

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());
    }
}
Also used : InvalidRequestEventException(com.amazonaws.serverless.exceptions.InvalidRequestEventException) AwsProxyRequestBuilder(com.amazonaws.serverless.proxy.internal.testutils.AwsProxyRequestBuilder) AwsProxyRequest(com.amazonaws.serverless.proxy.model.AwsProxyRequest) Test(org.junit.Test)

Example 2 with InvalidRequestEventException

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");
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) InvalidRequestEventException(com.amazonaws.serverless.exceptions.InvalidRequestEventException) AwsProxyRequestBuilder(com.amazonaws.serverless.proxy.internal.testutils.AwsProxyRequestBuilder) AwsProxyRequest(com.amazonaws.serverless.proxy.model.AwsProxyRequest) Test(org.junit.Test)

Example 3 with InvalidRequestEventException

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();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) AwsProxyRequestBuilder(com.amazonaws.serverless.proxy.internal.testutils.AwsProxyRequestBuilder) AwsProxyRequest(com.amazonaws.serverless.proxy.model.AwsProxyRequest) MockLambdaContext(com.amazonaws.serverless.proxy.internal.testutils.MockLambdaContext) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) ServletException(javax.servlet.ServletException) InvalidRequestEventException(com.amazonaws.serverless.exceptions.InvalidRequestEventException) IOException(java.io.IOException) ContainerInitializationException(com.amazonaws.serverless.exceptions.ContainerInitializationException) Test(org.junit.Test)

Example 4 with InvalidRequestEventException

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());
}
Also used : AwsProxyResponse(com.amazonaws.serverless.proxy.model.AwsProxyResponse) InvalidRequestEventException(com.amazonaws.serverless.exceptions.InvalidRequestEventException) ErrorModel(com.amazonaws.serverless.proxy.model.ErrorModel) Test(org.junit.Test)

Example 5 with InvalidRequestEventException

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());
}
Also used : AwsProxyResponse(com.amazonaws.serverless.proxy.model.AwsProxyResponse) InvalidRequestEventException(com.amazonaws.serverless.exceptions.InvalidRequestEventException) Test(org.junit.Test)

Aggregations

InvalidRequestEventException (com.amazonaws.serverless.exceptions.InvalidRequestEventException)20 Test (org.junit.Test)19 AwsProxyRequestBuilder (com.amazonaws.serverless.proxy.internal.testutils.AwsProxyRequestBuilder)13 AwsProxyRequest (com.amazonaws.serverless.proxy.model.AwsProxyRequest)12 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 AwsProxyResponse (com.amazonaws.serverless.proxy.model.AwsProxyResponse)6 ContainerInitializationException (com.amazonaws.serverless.exceptions.ContainerInitializationException)2 MockLambdaContext (com.amazonaws.serverless.proxy.internal.testutils.MockLambdaContext)2 ErrorModel (com.amazonaws.serverless.proxy.model.ErrorModel)2 IOException (java.io.IOException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ServletException (javax.servlet.ServletException)2 HttpApiV2ProxyRequest (com.amazonaws.serverless.proxy.model.HttpApiV2ProxyRequest)1 UriRoute (io.micronaut.web.router.UriRoute)1 UriRouteMatch (io.micronaut.web.router.UriRouteMatch)1