mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2026-03-10 18:55:03 +00:00
Lambda unit test infrastructure
Unit test infrastructure for testing GET and POST Lambdas
This commit is contained in:
@@ -3,6 +3,7 @@ import com.amazonaws.services.lambda.runtime.Context;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -13,14 +14,16 @@ public class BasicHandler {
|
||||
HashMap<String, String> queryMap = InputUtils.getQueryParams(inputMap);
|
||||
try {
|
||||
DBConnector connector = new DBConnector();
|
||||
try {
|
||||
Constructor<T> constructor = toCall.getConstructor(DBConnector.class, String.class);
|
||||
CallHandler callHandler = constructor.newInstance(connector, cognitoID);
|
||||
return callHandler.conductAction(InputUtils.getBody(inputMap), queryMap, cognitoID);
|
||||
} catch (SQLException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
connector.close();
|
||||
try (Connection connection = connector.getConnection()) {
|
||||
try {
|
||||
Constructor<T> constructor = toCall.getConstructor(Connection.class, String.class);
|
||||
CallHandler callHandler = constructor.newInstance(connection, cognitoID);
|
||||
return callHandler.conductAction(InputUtils.getBody(inputMap), queryMap, cognitoID);
|
||||
} catch (SQLException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
connector.close();
|
||||
}
|
||||
}
|
||||
} catch (IOException |SQLException|ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -8,8 +9,8 @@ public class BadCallListener extends CallListener {
|
||||
static RuntimeException toThrowRuntime = null;
|
||||
|
||||
|
||||
public BadCallListener(DBConnector connector, String cognitoID) {
|
||||
super(connector, cognitoID);
|
||||
public BadCallListener(Connection connection, String cognitoID) {
|
||||
super(connection, cognitoID);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -8,7 +9,7 @@ public class CallListener implements CallHandler {
|
||||
|
||||
static int creates = 0;
|
||||
|
||||
public CallListener(DBConnector connector, String cognitoID) {
|
||||
public CallListener(Connection connection, String cognitoID) {
|
||||
creates++;
|
||||
}
|
||||
|
||||
|
||||
1627
Lambdas/Lists/src/test/java/StatementInjector.java
Normal file
1627
Lambdas/Lists/src/test/java/StatementInjector.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -38,7 +38,7 @@ public class TestBasicHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, Object> buildFullSampleMap() {
|
||||
public static Map<String, Object> buildFullSampleMap() {
|
||||
Map<String, Object> testMap = new HashMap<>();
|
||||
TestInputUtils.addBody(testMap);
|
||||
TestInputUtils.addCognitoID(testMap);
|
||||
|
||||
@@ -9,7 +9,7 @@ public class TestInputUtils {
|
||||
@Test
|
||||
public void testGetBody() {
|
||||
Map<String, Object> testMap = new HashMap<>();
|
||||
Map<String, String> bodyMap = addBody(testMap);
|
||||
Map<String, Object> bodyMap = addBody(testMap);
|
||||
assert (InputUtils.getBody(testMap).equals(bodyMap));
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class TestInputUtils {
|
||||
return cognitoID;
|
||||
}
|
||||
|
||||
public static Map<String, String> addQueryParams(Map<String, Object> testMap) {
|
||||
public static HashMap<String, String> addQueryParams(Map<String, Object> testMap) {
|
||||
HashMap<String, Object> paramsMap = new HashMap<>();
|
||||
HashMap<String, String> queryMap = new HashMap<>();
|
||||
paramsMap.put("querystring", queryMap);
|
||||
@@ -54,8 +54,8 @@ public class TestInputUtils {
|
||||
return queryMap;
|
||||
}
|
||||
|
||||
public static Map<String, String> addBody(Map<String, Object> testMap) {
|
||||
HashMap<String, String> bodyMap = new HashMap<>();
|
||||
public static Map<String, Object> addBody(Map<String, Object> testMap) {
|
||||
HashMap<String, Object> bodyMap = new HashMap<>();
|
||||
testMap.put("body", bodyMap);
|
||||
return bodyMap;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user