Skip to content

Commit 262e55c

Browse files
authored
Merge pull request #9 from zeroae/i/7-npe-content-type
Remove Content-Type check
2 parents f1e78dd + a357e5f commit 262e55c

File tree

2 files changed

+45
-30
lines changed

2 files changed

+45
-30
lines changed

src/main/java/co/zeroae/gate/App.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent in
4040
.withHeaders(new HashMap<>());
4141
response.getHeaders().put("Content-Type", "text/plain");
4242

43-
if (!input.getHeaders().get("Content-Type").equalsIgnoreCase("text/plain")) {
44-
return response.withBody("We only support text/plain input.").withStatusCode(400);
45-
}
46-
4743
try {
4844
final Document doc = Factory.newDocument(input.getBody());
4945
final Corpus corpus = application.getCorpus();

src/test/java/co/zeroae/gate/AppTest.java

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
44
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
5+
import org.junit.Before;
6+
import org.junit.BeforeClass;
57
import org.junit.Test;
68

79
import java.util.Collections;
@@ -12,30 +14,47 @@
1214
import static com.github.stefanbirkner.systemlambda.SystemLambda.*;
1315

1416
public class AppTest {
15-
@Test
16-
public void successfulResponse() throws Exception {
17-
App app = withEnvironmentVariable("GATE_APP_NAME", "annie")
18-
.execute(App::new);
19-
20-
// Create the Input
21-
final HashMap<String, String> input_headers = new HashMap<>();
22-
input_headers.put("Content-Type", "text/plain");
23-
APIGatewayProxyRequestEvent input = new APIGatewayProxyRequestEvent()
24-
.withHttpMethod("POST")
25-
.withHeaders(Collections.unmodifiableMap(input_headers))
26-
.withBody("This is a test. My name is LambdaTestFunction, and I just watched the T.V. show Wanda Vision.");
27-
28-
// Context
29-
final TestContext context = new TestContext();
30-
31-
// Invoke the App
32-
final APIGatewayProxyResponseEvent result = app.handleRequest(input, context);
33-
34-
// Assert Results
35-
assertEquals(result.getStatusCode().intValue(), 200);
36-
assertEquals(result.getHeaders().get("Content-Type"), "application/xml");
37-
final String content = result.getBody();
38-
assertNotNull(content);
39-
assertTrue(content.contains("GateDocument version=\"3\""));
40-
}
17+
18+
@BeforeClass
19+
public static void setUpClass() throws Exception {
20+
app = withEnvironmentVariable("GATE_APP_NAME", "annie")
21+
.execute(App::new);
22+
}
23+
24+
private static App app = null;
25+
26+
@Test
27+
public void successfulResponse() throws Exception {
28+
// Create the Input
29+
final HashMap<String, String> input_headers = new HashMap<>();
30+
input_headers.put("Content-Type", "text/plain");
31+
APIGatewayProxyRequestEvent input = new APIGatewayProxyRequestEvent()
32+
.withHttpMethod("POST")
33+
.withHeaders(Collections.unmodifiableMap(input_headers))
34+
.withBody("This is a test. My name is LambdaTestFunction, and I just watched the T.V. show Wanda Vision.");
35+
36+
// Context
37+
final TestContext context = new TestContext();
38+
39+
// Invoke the App
40+
final APIGatewayProxyResponseEvent result = app.handleRequest(input, context);
41+
42+
// Assert Results
43+
assertEquals(result.getStatusCode().intValue(), 200);
44+
assertEquals(result.getHeaders().get("Content-Type"), "application/xml");
45+
final String content = result.getBody();
46+
assertNotNull(content);
47+
assertTrue(content.contains("GateDocument version=\"3\""));
48+
}
49+
50+
@Test
51+
public void testMissingContentType() throws Exception {
52+
APIGatewayProxyRequestEvent input = new APIGatewayProxyRequestEvent()
53+
.withHttpMethod("POST")
54+
.withHeaders(Collections.unmodifiableMap(new HashMap<>()))
55+
.withBody("I am still valid text...");
56+
final TestContext context = new TestContext();
57+
final APIGatewayProxyResponseEvent result = app.handleRequest(input, context);
58+
assertEquals(result.getStatusCode().intValue(), 200);
59+
}
4160
}

0 commit comments

Comments
 (0)