diff --git a/src/main/java/co/zeroae/gate/App.java b/src/main/java/co/zeroae/gate/App.java index 42aa9a7..49e4ac9 100644 --- a/src/main/java/co/zeroae/gate/App.java +++ b/src/main/java/co/zeroae/gate/App.java @@ -40,10 +40,6 @@ public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent in .withHeaders(new HashMap<>()); response.getHeaders().put("Content-Type", "text/plain"); - if (!input.getHeaders().get("Content-Type").equalsIgnoreCase("text/plain")) { - return response.withBody("We only support text/plain input.").withStatusCode(400); - } - try { final Document doc = Factory.newDocument(input.getBody()); final Corpus corpus = application.getCorpus(); diff --git a/src/test/java/co/zeroae/gate/AppTest.java b/src/test/java/co/zeroae/gate/AppTest.java index eedf5d9..2d814a0 100644 --- a/src/test/java/co/zeroae/gate/AppTest.java +++ b/src/test/java/co/zeroae/gate/AppTest.java @@ -2,6 +2,8 @@ import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent; import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent; +import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import java.util.Collections; @@ -12,30 +14,47 @@ import static com.github.stefanbirkner.systemlambda.SystemLambda.*; public class AppTest { - @Test - public void successfulResponse() throws Exception { - App app = withEnvironmentVariable("GATE_APP_NAME", "annie") - .execute(App::new); - - // Create the Input - final HashMap input_headers = new HashMap<>(); - input_headers.put("Content-Type", "text/plain"); - APIGatewayProxyRequestEvent input = new APIGatewayProxyRequestEvent() - .withHttpMethod("POST") - .withHeaders(Collections.unmodifiableMap(input_headers)) - .withBody("This is a test. My name is LambdaTestFunction, and I just watched the T.V. show Wanda Vision."); - - // Context - final TestContext context = new TestContext(); - - // Invoke the App - final APIGatewayProxyResponseEvent result = app.handleRequest(input, context); - - // Assert Results - assertEquals(result.getStatusCode().intValue(), 200); - assertEquals(result.getHeaders().get("Content-Type"), "application/xml"); - final String content = result.getBody(); - assertNotNull(content); - assertTrue(content.contains("GateDocument version=\"3\"")); - } + + @BeforeClass + public static void setUpClass() throws Exception { + app = withEnvironmentVariable("GATE_APP_NAME", "annie") + .execute(App::new); + } + + private static App app = null; + + @Test + public void successfulResponse() throws Exception { + // Create the Input + final HashMap input_headers = new HashMap<>(); + input_headers.put("Content-Type", "text/plain"); + APIGatewayProxyRequestEvent input = new APIGatewayProxyRequestEvent() + .withHttpMethod("POST") + .withHeaders(Collections.unmodifiableMap(input_headers)) + .withBody("This is a test. My name is LambdaTestFunction, and I just watched the T.V. show Wanda Vision."); + + // Context + final TestContext context = new TestContext(); + + // Invoke the App + final APIGatewayProxyResponseEvent result = app.handleRequest(input, context); + + // Assert Results + assertEquals(result.getStatusCode().intValue(), 200); + assertEquals(result.getHeaders().get("Content-Type"), "application/xml"); + final String content = result.getBody(); + assertNotNull(content); + assertTrue(content.contains("GateDocument version=\"3\"")); + } + + @Test + public void testMissingContentType() throws Exception { + APIGatewayProxyRequestEvent input = new APIGatewayProxyRequestEvent() + .withHttpMethod("POST") + .withHeaders(Collections.unmodifiableMap(new HashMap<>())) + .withBody("I am still valid text..."); + final TestContext context = new TestContext(); + final APIGatewayProxyResponseEvent result = app.handleRequest(input, context); + assertEquals(result.getStatusCode().intValue(), 200); + } }