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:
@@ -1,7 +1,6 @@
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class Item {
|
||||
Integer productID;
|
||||
@@ -11,7 +10,7 @@ public class Item {
|
||||
BigDecimal price;
|
||||
String imageURL;
|
||||
String department;
|
||||
LocalDateTime retrievedDate;
|
||||
long retrievedDate;
|
||||
Integer fetchCounts;
|
||||
|
||||
Item(ResultSet itemRow) throws SQLException {
|
||||
@@ -29,7 +28,7 @@ public class Item {
|
||||
System.out.println(imageURL);
|
||||
this.department = itemRow.getString(7);
|
||||
System.out.println(department);
|
||||
this.retrievedDate = itemRow.getObject(8, LocalDateTime.class);
|
||||
this.retrievedDate = itemRow.getTimestamp(8).toInstant().toEpochMilli();
|
||||
System.out.println(retrievedDate);
|
||||
this.fetchCounts = itemRow.getInt(9);
|
||||
System.out.println(fetchCounts);
|
||||
@@ -106,11 +105,11 @@ public class Item {
|
||||
this.department = department;
|
||||
}
|
||||
|
||||
public LocalDateTime getRetrievedDate() {
|
||||
public long getRetrievedDate() {
|
||||
return retrievedDate;
|
||||
}
|
||||
|
||||
public void setRetrievedDate(LocalDateTime retrievedDate) {
|
||||
public void setRetrievedDate(long retrievedDate) {
|
||||
this.retrievedDate = retrievedDate;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user