mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-15 18:28:47 +00:00
Removed old tests
This commit is contained in:
parent
b04be3a3c7
commit
cff2bee7a5
@ -1,4 +1,5 @@
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.configuration.IMockitoConfiguration;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
@ -11,8 +12,8 @@ import java.util.Map;
|
||||
public class TestListAdder {
|
||||
|
||||
@Test
|
||||
public void testListAdderValid() {
|
||||
testListAdderCore(false);
|
||||
public void testListAdderValid() throws SQLException {
|
||||
testListAdderCoreMock(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -20,7 +21,7 @@ public class TestListAdder {
|
||||
testListAdderCoreMock(true);
|
||||
}
|
||||
|
||||
public void testListAdderCore(boolean shouldThrow) {
|
||||
public void testListAdderCoreMock(boolean shouldThrow) throws SQLException {
|
||||
StatementInjector injector;
|
||||
ArrayList<Object> rsReturns = new ArrayList<>();
|
||||
rsReturns.add(1); //new listID
|
||||
@ -31,35 +32,8 @@ public class TestListAdder {
|
||||
assert false; //Error in test infrastructure
|
||||
return;
|
||||
}
|
||||
ListAdder listAdder = new ListAdder(injector, "cognitoID");
|
||||
Map<String, Object> ignore = new HashMap<>();
|
||||
Map<String, Object> body = TestInputUtils.addBody(ignore);
|
||||
body.put("name", "aname");
|
||||
try {
|
||||
Object rawIDReturn = listAdder.conductAction(body, TestInputUtils.addQueryParams(ignore), "cognitoID");
|
||||
assert !shouldThrow;
|
||||
if (!(rawIDReturn.getClass() == Integer.class)) {
|
||||
assert false;
|
||||
return;
|
||||
}
|
||||
assert (((Integer) rawIDReturn) == 1);
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
public void testListAdderCoreMock(boolean shouldThrow) throws SQLException {
|
||||
StatementInjector injector;
|
||||
ArrayList<Object> rsReturns = new ArrayList<>();
|
||||
rsReturns.add(1); //new listID
|
||||
injector = mock(StatementInjector.class);
|
||||
injector.returnedStatement = null;
|
||||
injector.rsReturns = new ArrayList(rsReturns);
|
||||
injector.shouldThrow = shouldThrow;
|
||||
|
||||
ListAdder listAdder = new ListAdder(injector, "cognitoID");
|
||||
ListAdder listAdder = Mockito.spy(new ListAdder(injector, "cognitoID"));
|
||||
Map<String, Object> ignore = new HashMap<>();
|
||||
Map<String, Object> body = TestInputUtils.addBody(ignore);
|
||||
body.put("name", "aname");
|
||||
|
||||
@ -16,7 +16,7 @@ public class TestListDelete {
|
||||
|
||||
@Test
|
||||
public void testListDeleterWOAccess() {
|
||||
testListDeleterCore(false, false);
|
||||
testListDeleterCoreMock(false, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -24,38 +24,6 @@ public class TestListDelete {
|
||||
testListDeleterCoreMock(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;
|
||||
}
|
||||
}
|
||||
|
||||
public void testListDeleterCoreMock(boolean shouldThrow, boolean hasAccess) {
|
||||
StatementInjector injector;
|
||||
ArrayList<Object> rsReturns = new ArrayList<>();
|
||||
|
||||
@ -27,79 +27,6 @@ public class TestListGetter {
|
||||
@Test
|
||||
public void testListGetterError() { conductListGetterTestMock(true); }
|
||||
|
||||
public void conductListGetterTest(boolean shouldThrow) {
|
||||
Integer listID = 1;
|
||||
String name = "aname";
|
||||
String owner = "anowner";
|
||||
Timestamp lastUpdated = Timestamp.from(Instant.ofEpochMilli(1602192528688L));
|
||||
|
||||
Integer productID = 2;
|
||||
Integer quantity = 3;
|
||||
Timestamp addedDate = Timestamp.from(Instant.ofEpochMilli(1602192528689L));;
|
||||
Boolean purchased = false;
|
||||
|
||||
ArrayList<Object> rsReturns = new ArrayList<>();
|
||||
rsReturns.add(listID);
|
||||
rsReturns.add(name);
|
||||
rsReturns.add(owner);
|
||||
rsReturns.add(lastUpdated);
|
||||
rsReturns.add(productID);
|
||||
rsReturns.add(quantity);
|
||||
rsReturns.add(addedDate);
|
||||
rsReturns.add(purchased);
|
||||
StatementInjector injector = null;
|
||||
try {
|
||||
injector = new StatementInjector(null, rsReturns, shouldThrow);
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
ListGetter getter = new ListGetter(injector, "id");
|
||||
Map<String, Object> ignore = new HashMap<>();
|
||||
HashMap<String, String> queryParams = TestInputUtils.addQueryParams(ignore);
|
||||
queryParams.put("id", "1");
|
||||
try {
|
||||
Object conductReturn = getter.conductAction(TestInputUtils.addBody(ignore), queryParams, "cognitoID");
|
||||
assert !shouldThrow;
|
||||
assert (conductReturn.getClass() == List.class);
|
||||
List listReturn = (List) conductReturn;
|
||||
assert (listReturn.toString().equals("List{itemID=1, name='aname', owner='anowner', lastUpdated=1602192528688, entries=[ItemEntry{listID=1, productID=2, quantity=3, addedDate=1602192528689, purchased=false}]}"));
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
assert shouldThrow;
|
||||
}
|
||||
}
|
||||
|
||||
public void conductListIDGetterTest(boolean shouldThrow) {
|
||||
|
||||
ArrayList<Object> rsReturns = new ArrayList<>();
|
||||
rsReturns.add(1);
|
||||
rsReturns.add(2);
|
||||
rsReturns.add(3);
|
||||
rsReturns.add(4);
|
||||
|
||||
StatementInjector injector = null;
|
||||
try {
|
||||
injector = new StatementInjector(null, rsReturns, shouldThrow);
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
ListGetter getter = new ListGetter(injector, "id");
|
||||
Map<String, Object> ignore = new HashMap<>();
|
||||
HashMap<String, String> queryParams = TestInputUtils.addQueryParams(ignore);
|
||||
queryParams.put("id", "-1");
|
||||
try {
|
||||
Object conductReturn = getter.conductAction(TestInputUtils.addBody(ignore), queryParams, "cognitoID");
|
||||
assert !shouldThrow;
|
||||
assert (conductReturn.getClass() == ArrayList.class);
|
||||
ArrayList<Integer> listIDsReturn = (ArrayList<Integer>) conductReturn;
|
||||
System.out.println(listIDsReturn.toString());
|
||||
assert (listIDsReturn.toString().equals("[1, 2, 3, 4]"));
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
assert shouldThrow;
|
||||
}
|
||||
}
|
||||
|
||||
public void conductListGetterTestMock(boolean shouldThrow) {
|
||||
Integer listID = 1;
|
||||
String name = "aname";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user