Lambda unit test infrastructure

Unit test infrastructure for testing GET and POST Lambdas
This commit is contained in:
NMerz
2020-10-08 18:34:06 -04:00
parent c9751d4f95
commit 508818c700
19 changed files with 1890 additions and 103 deletions

View File

@@ -1,5 +1,3 @@
import com.google.gson.Gson;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -7,30 +5,25 @@ import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
public class ItemGetter implements CallHandler{
private final DBConnector connector;
public class ItemGetter implements CallHandler {
private final Connection connection;
private final String GET_ITEM = "SELECT * FROM Product WHERE productID = ?;";
public ItemGetter(DBConnector connector, String cognitoID) {
this.connector = connector;
public ItemGetter(Connection connection, String cognitoID) {
this.connection = connection;
}
@Override
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryMap, String cognitoID) throws SQLException {
Connection connection = connector.getConnection();
try {
PreparedStatement statement = connection.prepareStatement(GET_ITEM);
statement.setInt(1, Integer.parseInt(queryMap.get("id")));
System.out.println(statement);
ResultSet queryResults = statement.executeQuery();
queryResults.first();
System.out.println(queryResults);
Item retrievedItem = new Item(queryResults);
System.out.println(retrievedItem);
return retrievedItem;
} finally {
connection.close();
}
PreparedStatement statement = connection.prepareStatement(GET_ITEM);
statement.setInt(1, Integer.parseInt(queryMap.get("id")));
System.out.println(statement);
ResultSet queryResults = statement.executeQuery();
queryResults.first();
System.out.println(queryResults);
Item retrievedItem = new Item(queryResults);
System.out.println(retrievedItem);
return retrievedItem;
}
}