mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 10:48:46 +00:00
Merge pull request #89 from ClaytonWWilson/master
Merge code from master
This commit is contained in:
commit
33d60d20f6
@ -40,7 +40,7 @@ public class TestListAdder {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assert (((Integer) rawIDReturn) == 1);
|
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) {
|
} catch (SQLException throwables) {
|
||||||
assert shouldThrow;
|
assert shouldThrow;
|
||||||
throwables.printStackTrace();
|
throwables.printStackTrace();
|
||||||
|
|||||||
57
Lambdas/Lists/List/test/TestListDelete.java
Normal file
57
Lambdas/Lists/List/test/TestListDelete.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
45
Lambdas/Lists/ListShare/test/TestListSharer.java
Normal file
45
Lambdas/Lists/ListShare/test/TestListSharer.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,14 +1,17 @@
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.nio.file.NoSuchFileException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
public class TestUserDeleter {
|
public class TestUserDeleter {
|
||||||
@Test
|
@Test
|
||||||
public void TestUserDelete(){
|
public void testUserDeleteFileUsage(){
|
||||||
try {
|
testUserDeleter(false);
|
||||||
testUserDeleter(false);
|
}
|
||||||
assert(false);
|
|
||||||
} catch (Exception e) {}
|
@Test
|
||||||
|
public void testUserDeleteInvalid(){
|
||||||
|
testUserDeleter(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testUserDeleter(boolean shouldThrow) {
|
public void testUserDeleter(boolean shouldThrow) {
|
||||||
@ -24,7 +27,9 @@ public class TestUserDeleter {
|
|||||||
try {
|
try {
|
||||||
userDeleter.conductAction(null, null, cognitoID);
|
userDeleter.conductAction(null, null, cognitoID);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
assert shouldThrow;
|
||||||
|
} catch (Exception e) {
|
||||||
|
assert e.getClass().equals(NoSuchFileException.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user