Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/main/java/co/zeroae/gate/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
71 changes: 45 additions & 26 deletions src/test/java/co/zeroae/gate/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, String> 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<String, String> 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);
}
}