Update lambda tests

Update lambda tests for new and altered lambdas
This commit is contained in:
NMerz 2020-11-01 12:46:03 -05:00
parent aeb6433a87
commit a12b1ae870
4 changed files with 114 additions and 7 deletions

View File

@ -40,7 +40,7 @@ public class TestListAdder {
return;
}
assert (((Integer) rawIDReturn) == 1);
assert (injector.getStatementString().contains("INSERT INTO List (name, owner, lastUpdated) VALUES (?, ?, ?)[aname, cognitoID,"));
assert (injector.getStatementString().contains("INSERT INTO List (name, owner, lastUpdated) VALUES (?, ?, ?);INSERT INTO ListSharee(listID, userID) VALUES(?, ?);[1, cognitoID]"));
} catch (SQLException throwables) {
assert shouldThrow;
throwables.printStackTrace();

View File

@ -0,0 +1,57 @@
import org.junit.Test;
import java.security.AccessControlException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class TestListDelete {
@Test
public void testListDeleterValid() {
testListDeleterCore(false, true);
}
@Test
public void testListDeleterWOAccess() {
testListDeleterCore(false, false);
}
@Test
public void testListDeleterError() {
testListDeleterCore(true, true);
}
public void testListDeleterCore(boolean shouldThrow, boolean hasAccess) {
StatementInjector injector;
ArrayList<Object> rsReturns = new ArrayList<>();
rsReturns.add("cognitoID");
try {
if (!hasAccess) {
rsReturns = null;
}
injector = new StatementInjector(null, rsReturns, shouldThrow);
} catch (SQLException throwables) {
throwables.printStackTrace();
assert false; //Error in test infrastructure
return;
}
ListDeleter listDeleter = new ListDeleter(injector, "cognitoID");
Map<String, Object> body = (Map<String, Object>) TestBasicHandler.buildFullSampleMap().get("body");
HashMap<String, String> queryParams = (HashMap<String, String>) TestBasicHandler.buildFullSampleMap().get("body");
queryParams.put("id", "30");
try {
Object rawIDReturn = listDeleter.conductAction(body, queryParams, "cognitoID");
assert !shouldThrow;
assert (rawIDReturn == null);
System.out.println(injector.getStatementString());
assert (injector.getStatementString().equals("SELECT * FROM List WHERE (owner = ? AND listID = ?);DELETE FROM ListSharee where listID = ?;DELETE FROM ListProduct where listID = ?;DELETE FROM List WHERE listID = ?;[30]"));
} catch (SQLException throwables) {
assert shouldThrow ;
} catch (AccessControlException accessControlException) {
assert !hasAccess;
}
}
}

View File

@ -0,0 +1,45 @@
import org.junit.Test;
import java.security.AccessControlException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
public class TestListSharer {
@Test
public void testListSharerWOAccess() {
testListEntryAdderCore(false, false);
}
@Test
public void testListSharerError() {
testListEntryAdderCore(true, true);
}
public void testListEntryAdderCore(boolean shouldThrow, boolean hasAccess) {
StatementInjector injector;
try {
injector = new StatementInjector(null, null, shouldThrow);
} catch (SQLException throwables) {
throwables.printStackTrace();
assert false; //Error in test infrastructure
return;
}
ListSharer listSharer = new ListSharer(injector, "cognitoID");
Map<String, Object> ignore = new HashMap<>();
Map<String, Object> body = TestInputUtils.addBody(ignore);
body.put("listID", 49);
try {
listSharer.conductAction(body, TestInputUtils.addQueryParams(ignore), "cognitoID");
assert !shouldThrow;
assert (injector.getStatementString().contains("INSERT INTO ListProduct (productID, listID, quantity, addedDate, purchased) VALUES (?, ?, ?, ?, ?)[16, 15, 14, "));
assert (injector.getStatementString().contains(", false]"));
} catch (SQLException throwables) {
assert shouldThrow;
} catch (AccessControlException accessControlException) {
assert !hasAccess;
}
}
}

View File

@ -1,14 +1,17 @@
import org.junit.Test;
import java.nio.file.NoSuchFileException;
import java.sql.SQLException;
public class TestUserDeleter {
@Test
public void TestUserDelete(){
try {
testUserDeleter(false);
assert(false);
} catch (Exception e) {}
public void testUserDeleteFileUsage(){
testUserDeleter(false);
}
@Test
public void testUserDeleteInvalid(){
testUserDeleter(true);
}
public void testUserDeleter(boolean shouldThrow) {
@ -24,7 +27,9 @@ public class TestUserDeleter {
try {
userDeleter.conductAction(null, null, cognitoID);
} catch (SQLException e) {
e.printStackTrace();
assert shouldThrow;
} catch (Exception e) {
assert e.getClass().equals(NoSuchFileException.class);
}
}
}