diff --git a/Lambdas/Lists/Chain/test/TestChainGetter.java b/Lambdas/Lists/Chain/test/TestChainGetter.java new file mode 100644 index 0000000..b217e2f --- /dev/null +++ b/Lambdas/Lists/Chain/test/TestChainGetter.java @@ -0,0 +1,43 @@ +import org.junit.Test; +import org.mockito.Mockito; + +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + +public class TestChainGetter { + + @Test + public void testChainGetterValid() { + testChainGetter(false); + } + + @Test + public void testChainGetterError() { + testChainGetter(true); + } + + public void testChainGetter(boolean shouldThrow) { + StatementInjector injector; + try { + injector = new StatementInjector(null, null, shouldThrow); + } catch (SQLException throwables) { + throwables.printStackTrace(); + assert false; //Error in test infrastructure + return; + } + ChainGetter chainGetter = Mockito.spy(new ChainGetter(injector, "cognitoID")); + Map ignore = new HashMap<>(); + Map body = TestInputUtils.addBody(ignore); + ignore.put("id", 1); //in ChainGetter.java uses ignore map for id parameter + + try { + Object rawIDReturn = chainGetter.conductAction(body, TestInputUtils.addQueryParams(ignore), "cognitoID"); + assert !shouldThrow; + assert (rawIDReturn != null); + } catch (SQLException throwables) { + assert shouldThrow; + throwables.printStackTrace(); + } + } +} diff --git a/Lambdas/Lists/ItemSearch/test/TestItemSearcher.java b/Lambdas/Lists/ItemSearch/test/TestItemSearcher.java new file mode 100644 index 0000000..fb11224 --- /dev/null +++ b/Lambdas/Lists/ItemSearch/test/TestItemSearcher.java @@ -0,0 +1,43 @@ +import org.junit.Test; +import org.mockito.Mockito; + +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + +public class TestItemSearcher { + + @Test + public void testItemSearcherValid() { + testItemSearcherMock(false); + } + + @Test + public void testItemSearcherError() { + testItemSearcherMock(true); + } + + public void testItemSearcherMock(boolean shouldThrow) { + StatementInjector injector; + try { + injector = new StatementInjector(null, null, shouldThrow); + } catch (SQLException throwables) { + throwables.printStackTrace(); + assert false; //Error in test infrastructure + return; + } + ItemSearcher listItemSearcher = Mockito.spy(new ItemSearcher(injector, "cognitoID")); + Map ignore = new HashMap<>(); + Map body = TestInputUtils.addBody(ignore); + body.put("id", 1); + + try { + Object rawIDReturn = listItemSearcher.conductAction(body, TestInputUtils.addQueryParams(ignore), "cognitoID"); + assert !shouldThrow; + assert (rawIDReturn != null); + } catch (SQLException throwables) { + assert shouldThrow; + throwables.printStackTrace(); + } + } +} diff --git a/Lambdas/Lists/ListDuplicate/test/TestListDuplicate.java b/Lambdas/Lists/ListDuplicate/test/TestListDuplicate.java new file mode 100644 index 0000000..ced76fb --- /dev/null +++ b/Lambdas/Lists/ListDuplicate/test/TestListDuplicate.java @@ -0,0 +1,43 @@ +import org.junit.Test; +import org.mockito.Mockito; + +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + +public class TestListDuplicate { + + @Test + public void testListDuplicateValid() { + testListDuplicaterMock(false); + } + + @Test + public void testListDuplicateError() { + testListDuplicaterMock(true); + } + + public void testListDuplicaterMock(boolean shouldThrow) { + StatementInjector injector; + try { + injector = new StatementInjector(null, null, shouldThrow); + } catch (SQLException throwables) { + throwables.printStackTrace(); + assert false; //Error in test infrastructure + return; + } + ListDuplicater listDuplicater = Mockito.spy(new ListDuplicater(injector, "cognitoID")); + Map ignore = new HashMap<>(); + Map body = TestInputUtils.addBody(ignore); + body.put("name", "list1"); + body.put("listID", 1); + + try { + Object rawIDReturn = listDuplicater.conductAction(body, TestInputUtils.addQueryParams(ignore), "cognitoID"); + assert (rawIDReturn != null); + } catch (SQLException throwables) { + assert shouldThrow; + throwables.printStackTrace(); + } + } +} diff --git a/Lambdas/Lists/ListEntry/test/TestListEntryAdder.java b/Lambdas/Lists/ListEntry/test/TestListEntryAdder.java index a68bb15..4c424fa 100644 --- a/Lambdas/Lists/ListEntry/test/TestListEntryAdder.java +++ b/Lambdas/Lists/ListEntry/test/TestListEntryAdder.java @@ -1,6 +1,5 @@ import org.junit.Test; import org.mockito.Mockito; -import org.mockito.Mockito.*; import java.sql.SQLException; import java.util.HashMap; diff --git a/Lambdas/Lists/ListReposition/test/TestListReposition.java b/Lambdas/Lists/ListReposition/test/TestListReposition.java new file mode 100644 index 0000000..8212fdb --- /dev/null +++ b/Lambdas/Lists/ListReposition/test/TestListReposition.java @@ -0,0 +1,43 @@ +import org.junit.Test; +import org.mockito.Mockito; + +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + +public class TestListReposition { + + @Test + public void testListRepositionValid() { + testListRepositioneMock(false); + } + + @Test + public void testListRepositionError() { + testListRepositioneMock(true); + } + + public void testListRepositioneMock(boolean shouldThrow) { + StatementInjector injector; + try { + injector = new StatementInjector(null, null, shouldThrow); + } catch (SQLException throwables) { + throwables.printStackTrace(); + assert false; //Error in test infrastructure + return; + } + ListRepositionActor listRepositionActor = Mockito.spy(new ListRepositionActor(injector, "cognitoID")); + Map ignore = new HashMap<>(); + Map body = TestInputUtils.addBody(ignore); + body.put("listID", 1); + body.put("newPosition", 2); + + try { + Object rawIDReturn = listRepositionActor.conductAction(body, TestInputUtils.addQueryParams(ignore), "cognitoID"); + assert (rawIDReturn == null); + } catch (SQLException throwables) { + assert shouldThrow; + throwables.printStackTrace(); + } + } +} diff --git a/Lambdas/Lists/Picture/src/PictureGetter.java b/Lambdas/Lists/Picture/src/PictureGetter.java index 136e926..33a331f 100644 --- a/Lambdas/Lists/Picture/src/PictureGetter.java +++ b/Lambdas/Lists/Picture/src/PictureGetter.java @@ -19,7 +19,7 @@ public class PictureGetter implements CallHandler { @Override public Object conductAction(Map bodyMap, HashMap queryMap, String cognitoID) throws SQLException { PreparedStatement statement = connection.prepareStatement(GET_ITEM); - if (!queryMap.get("id").toString().equals("profile")) { + if (!queryMap.containsKey("id") || !queryMap.get("id").toString().equals("profile")) { throw new IllegalArgumentException("Only profile pictures are currently supported."); } statement.setString(1, cognitoID); diff --git a/Lambdas/Lists/Picture/src/PicturePutter.java b/Lambdas/Lists/Picture/src/PicturePutter.java index fadff15..3f14a87 100644 --- a/Lambdas/Lists/Picture/src/PicturePutter.java +++ b/Lambdas/Lists/Picture/src/PicturePutter.java @@ -18,6 +18,9 @@ public class PicturePutter implements CallHandler { public Object conductAction(Map bodyMap, HashMap queryString, String cognitoID) throws SQLException { PreparedStatement storePicture = connection.prepareStatement(STORE_PICTURE_SQL); + if(!bodyMap.containsKey("base64EncodedImage")) { + throw new IllegalArgumentException("Base64EncodedImage not found"); + } storePicture.setString(1, cognitoID); storePicture.setString(2, bodyMap.get("base64EncodedImage").toString()); System.out.println(storePicture); diff --git a/Lambdas/Lists/Picture/test/TestPictureGetter.java b/Lambdas/Lists/Picture/test/TestPictureGetter.java new file mode 100644 index 0000000..2af43e3 --- /dev/null +++ b/Lambdas/Lists/Picture/test/TestPictureGetter.java @@ -0,0 +1,43 @@ +import org.junit.Test; +import org.mockito.Mockito; + +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + +public class TestPictureGetter { + + @Test + public void testPictureGetterValid() { + testPictureGetter(false); + } + + @Test + public void testPictureGetterError() { + testPictureGetter(true); + } + + public void testPictureGetter(boolean shouldThrow) { + StatementInjector injector; + try { + injector = new StatementInjector(null, null, shouldThrow); + } catch (SQLException throwables) { + throwables.printStackTrace(); + assert false; //Error in test infrastructure + return; + } + PictureGetter pictureGetter = Mockito.spy(new PictureGetter(injector, "cognitoID")); + Map ignore = new HashMap<>(); + Map body = TestInputUtils.addBody(ignore); + body.put("id", 1); + body.put("profile", 1); + + try { + Object rawIDReturn = pictureGetter.conductAction(body, TestInputUtils.addQueryParams(ignore), "cognitoID"); + assert (rawIDReturn != null); + } catch (SQLException throwables) { + assert shouldThrow; + throwables.printStackTrace(); + } + } +} diff --git a/Lambdas/Lists/Picture/test/TestPicturePutter.java b/Lambdas/Lists/Picture/test/TestPicturePutter.java new file mode 100644 index 0000000..fc30141 --- /dev/null +++ b/Lambdas/Lists/Picture/test/TestPicturePutter.java @@ -0,0 +1,40 @@ +import org.junit.Test; +import org.mockito.Mockito; + +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + +public class TestPicturePutter { + + @Test + public void testPicturePutterValid() { + testPicturePutter(false); + } + + @Test + public void testPicturePutterError() { + testPicturePutter(true); + } + + public void testPicturePutter(boolean shouldThrow) { + StatementInjector injector; + try { + injector = new StatementInjector(null, null, shouldThrow); + } catch (SQLException throwables) { + throwables.printStackTrace(); + assert false; //Error in test infrastructure + return; + } + PicturePutter picturePutter = Mockito.spy(new PicturePutter(injector, "cognitoID")); + Map ignore = new HashMap<>(); + Map body = TestInputUtils.addBody(ignore); + try { + Object rawIDReturn = picturePutter.conductAction(body, TestInputUtils.addQueryParams(ignore), "cognitoID"); + assert (rawIDReturn == null); + } catch (SQLException throwables) { + assert shouldThrow; + throwables.printStackTrace(); + } + } +} diff --git a/Lambdas/Lists/SearchHistory/test/TestSearchHistoryGetter.java b/Lambdas/Lists/SearchHistory/test/TestSearchHistoryGetter.java new file mode 100644 index 0000000..20e0cea --- /dev/null +++ b/Lambdas/Lists/SearchHistory/test/TestSearchHistoryGetter.java @@ -0,0 +1,42 @@ +import org.junit.Test; +import org.mockito.Mockito; + +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + + +public class TestSearchHistoryGetter { + + @Test + public void testSearchHistoryValid() { + testSearchHistoryGetterMock(false); + } + + @Test + public void testSearchHistoryError() { + testSearchHistoryGetterMock(true); + } + + public void testSearchHistoryGetterMock(boolean shouldThrow) { + StatementInjector injector; + try { + injector = new StatementInjector(null, null, shouldThrow); + } catch (SQLException throwables) { + throwables.printStackTrace(); + assert false; //Error in test infrastructure + return; + } + SearchHistoryGetter searchHistoryGetter = Mockito.spy(new SearchHistoryGetter(injector, "cognitoID")); + Map ignore = new HashMap<>(); + Map body = TestInputUtils.addBody(ignore); + + try { + Object rawIDReturn = searchHistoryGetter.conductAction(body, TestInputUtils.addQueryParams(ignore), "cognitoID"); + assert (rawIDReturn != null); + } catch (SQLException throwables) { + assert shouldThrow; + throwables.printStackTrace(); + } + } +} diff --git a/Lambdas/Lists/SearchHistory/test/TestSearchHistoryUpdater.java b/Lambdas/Lists/SearchHistory/test/TestSearchHistoryUpdater.java new file mode 100644 index 0000000..99e9d8c --- /dev/null +++ b/Lambdas/Lists/SearchHistory/test/TestSearchHistoryUpdater.java @@ -0,0 +1,41 @@ +import org.junit.Test; +import org.mockito.Mockito; + +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + +public class TestSearchHistoryUpdater { + + @Test + public void testSearchHistoryUpdaterValid() { + testSearchHistoryUpdater(false); + } + + @Test + public void testSearchHistoryUpdaterError() { + testSearchHistoryUpdater(true); + } + + public void testSearchHistoryUpdater(boolean shouldThrow) { + StatementInjector injector; + try { + injector = new StatementInjector(null, null, shouldThrow); + } catch (SQLException throwables) { + throwables.printStackTrace(); + assert false; //Error in test infrastructure + return; + } + SearchHistoryUpdater testSearchHistoryUpdater = Mockito.spy(new SearchHistoryUpdater(injector, "cognitoID")); + Map ignore = new HashMap<>(); + Map body = TestInputUtils.addBody(ignore); + + try { + Object rawIDReturn = testSearchHistoryUpdater.conductAction(body, TestInputUtils.addQueryParams(ignore), "cognitoID"); + assert (rawIDReturn == null); + } catch (SQLException throwables) { + assert shouldThrow; + throwables.printStackTrace(); + } + } +}