From 4b1f06cdcd891c7dfb6c5c17af4167fe15bc1b09 Mon Sep 17 00:00:00 2001 From: Adam Ding Date: Tue, 1 Dec 2020 20:09:08 -0500 Subject: [PATCH 1/8] ListDuplicate tests added --- Lambdas/Lists/List/src/List.java | 22 +++++----- Lambdas/Lists/List/src/ListGetter.java | 2 +- .../ListDuplicate/test/TestListDuplicate.java | 43 +++++++++++++++++++ 3 files changed, 55 insertions(+), 12 deletions(-) create mode 100644 Lambdas/Lists/ListDuplicate/test/TestListDuplicate.java diff --git a/Lambdas/Lists/List/src/List.java b/Lambdas/Lists/List/src/List.java index 659a212..7e0b6ae 100644 --- a/Lambdas/Lists/List/src/List.java +++ b/Lambdas/Lists/List/src/List.java @@ -83,15 +83,15 @@ public class List { return uiPosition; } - public void setUiPosition(Integer uiPosition) { - this.uiPosition = uiPosition; - } - - public ItemEntry[] getEntries() { - return entries.toArray(new ItemEntry[entries.size()]); - } - - public void addItemEntry(ItemEntry entry) { - entries.add(entry); - } +// public void setUiPosition(Integer uiPosition) { +// this.uiPosition = uiPosition; +// } +// +// public ItemEntry[] getEntries() { +// return entries.toArray(new ItemEntry[entries.size()]); +// } +// +// public void addItemEntry(ItemEntry entry) { +// entries.add(entry); +// } } diff --git a/Lambdas/Lists/List/src/ListGetter.java b/Lambdas/Lists/List/src/ListGetter.java index 98fbc5c..953e8dd 100644 --- a/Lambdas/Lists/List/src/ListGetter.java +++ b/Lambdas/Lists/List/src/ListGetter.java @@ -78,7 +78,7 @@ public class ListGetter implements CallHandler{ getListEntries.setInt(1, id); ResultSet getEntryResults = getListEntries.executeQuery(); while (getEntryResults.next()) { - retrievedList.addItemEntry(new ItemEntry(id, getEntryResults)); + //retrievedList.addItemEntry(new ItemEntry(id, getEntryResults)); } System.out.println(retrievedList); return retrievedList; diff --git a/Lambdas/Lists/ListDuplicate/test/TestListDuplicate.java b/Lambdas/Lists/ListDuplicate/test/TestListDuplicate.java new file mode 100644 index 0000000..658db04 --- /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 testListEntryAdderValid() { + testListEntryAdderCoreMock(false); + } + + @Test + public void testListEntryAdderError() { + testListEntryAdderCoreMock(true); + } + + public void testListEntryAdderCoreMock(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(); + } + } +} From 0c3839cec35cc879c14bdb3c91429aa1ad780304 Mon Sep 17 00:00:00 2001 From: Adam Ding Date: Tue, 1 Dec 2020 20:09:49 -0500 Subject: [PATCH 2/8] ListDuplicate tests added --- Lambdas/Lists/ListDuplicate/test/TestListDuplicate.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lambdas/Lists/ListDuplicate/test/TestListDuplicate.java b/Lambdas/Lists/ListDuplicate/test/TestListDuplicate.java index 658db04..277ba98 100644 --- a/Lambdas/Lists/ListDuplicate/test/TestListDuplicate.java +++ b/Lambdas/Lists/ListDuplicate/test/TestListDuplicate.java @@ -9,15 +9,15 @@ public class TestListDuplicate { @Test public void testListEntryAdderValid() { - testListEntryAdderCoreMock(false); + testListDuplicaterMock(false); } @Test public void testListEntryAdderError() { - testListEntryAdderCoreMock(true); + testListDuplicaterMock(true); } - public void testListEntryAdderCoreMock(boolean shouldThrow) { + public void testListDuplicaterMock(boolean shouldThrow) { StatementInjector injector; try { injector = new StatementInjector(null, null, shouldThrow); From 16e4805d2c1551136975f24e5aabb2d40489cb09 Mon Sep 17 00:00:00 2001 From: Adam Ding Date: Tue, 1 Dec 2020 20:26:36 -0500 Subject: [PATCH 3/8] ListReposition tests added --- .../ListDuplicate/test/TestListDuplicate.java | 4 +- .../test/TestListReposition.java | 43 +++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 Lambdas/Lists/ListReposition/test/TestListReposition.java diff --git a/Lambdas/Lists/ListDuplicate/test/TestListDuplicate.java b/Lambdas/Lists/ListDuplicate/test/TestListDuplicate.java index 277ba98..ced76fb 100644 --- a/Lambdas/Lists/ListDuplicate/test/TestListDuplicate.java +++ b/Lambdas/Lists/ListDuplicate/test/TestListDuplicate.java @@ -8,12 +8,12 @@ import java.util.Map; public class TestListDuplicate { @Test - public void testListEntryAdderValid() { + public void testListDuplicateValid() { testListDuplicaterMock(false); } @Test - public void testListEntryAdderError() { + public void testListDuplicateError() { testListDuplicaterMock(true); } 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(); + } + } +} From 9e22d5388dd7b0a1a4809dfbd49558e639a5971b Mon Sep 17 00:00:00 2001 From: Adam Ding Date: Tue, 1 Dec 2020 20:42:50 -0500 Subject: [PATCH 4/8] ListItemSearcher tests added --- .../ItemSearch/test/TestItemSearcher.java | 43 +++++++++++++++++++ .../ListEntry/test/TestListEntryAdder.java | 1 - 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 Lambdas/Lists/ItemSearch/test/TestItemSearcher.java 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/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; From e3d4e931b093cf92de0db8be0ab128522c39b5a5 Mon Sep 17 00:00:00 2001 From: Adam Ding Date: Tue, 1 Dec 2020 20:53:32 -0500 Subject: [PATCH 5/8] TestSearchHistory tests added --- .../test/TestSearchHistoryGetter.java | 42 +++++++++++++++++++ .../test/TestSearchHistoryUpdater.java | 41 ++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 Lambdas/Lists/SearchHistory/test/TestSearchHistoryGetter.java create mode 100644 Lambdas/Lists/SearchHistory/test/TestSearchHistoryUpdater.java 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(); + } + } +} From 8385888075b8ddb17279ced8a754c0c26ce3341f Mon Sep 17 00:00:00 2001 From: Adam Ding Date: Tue, 1 Dec 2020 21:00:10 -0500 Subject: [PATCH 6/8] ChainGetter tests added --- Lambdas/Lists/Chain/test/TestChainGetter.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Lambdas/Lists/Chain/test/TestChainGetter.java 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(); + } + } +} From 337c2e117b9b886ec6b022b8fc7ebfbea18840cf Mon Sep 17 00:00:00 2001 From: Adam Ding Date: Tue, 1 Dec 2020 21:11:25 -0500 Subject: [PATCH 7/8] Picture tests addec --- Lambdas/Lists/Picture/src/PictureGetter.java | 2 +- Lambdas/Lists/Picture/src/PicturePutter.java | 3 ++ .../Lists/Picture/test/TestPictureGetter.java | 43 +++++++++++++++++++ .../Lists/Picture/test/TestPicturePutter.java | 40 +++++++++++++++++ 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 Lambdas/Lists/Picture/test/TestPictureGetter.java create mode 100644 Lambdas/Lists/Picture/test/TestPicturePutter.java 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(); + } + } +} From 7bdd65b1224861d7ba2090494eb922094c557421 Mon Sep 17 00:00:00 2001 From: Adam Ding Date: Tue, 1 Dec 2020 21:12:42 -0500 Subject: [PATCH 8/8] Uncommented code in List.java and ListGetter.java to prevent merge conflict --- Lambdas/Lists/List/src/List.java | 22 +++++++++++----------- Lambdas/Lists/List/src/ListGetter.java | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Lambdas/Lists/List/src/List.java b/Lambdas/Lists/List/src/List.java index 7e0b6ae..659a212 100644 --- a/Lambdas/Lists/List/src/List.java +++ b/Lambdas/Lists/List/src/List.java @@ -83,15 +83,15 @@ public class List { return uiPosition; } -// public void setUiPosition(Integer uiPosition) { -// this.uiPosition = uiPosition; -// } -// -// public ItemEntry[] getEntries() { -// return entries.toArray(new ItemEntry[entries.size()]); -// } -// -// public void addItemEntry(ItemEntry entry) { -// entries.add(entry); -// } + public void setUiPosition(Integer uiPosition) { + this.uiPosition = uiPosition; + } + + public ItemEntry[] getEntries() { + return entries.toArray(new ItemEntry[entries.size()]); + } + + public void addItemEntry(ItemEntry entry) { + entries.add(entry); + } } diff --git a/Lambdas/Lists/List/src/ListGetter.java b/Lambdas/Lists/List/src/ListGetter.java index 953e8dd..98fbc5c 100644 --- a/Lambdas/Lists/List/src/ListGetter.java +++ b/Lambdas/Lists/List/src/ListGetter.java @@ -78,7 +78,7 @@ public class ListGetter implements CallHandler{ getListEntries.setInt(1, id); ResultSet getEntryResults = getListEntries.executeQuery(); while (getEntryResults.next()) { - //retrievedList.addItemEntry(new ItemEntry(id, getEntryResults)); + retrievedList.addItemEntry(new ItemEntry(id, getEntryResults)); } System.out.println(retrievedList); return retrievedList;