mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2026-03-11 02:55:04 +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();
|
||||
|
||||
Reference in New Issue
Block a user