mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-13 09:48:47 +00:00
Merge pull request #171 from ClaytonWWilson/test-new-lambdas
Test new lambdas
This commit is contained in:
commit
c81355d6cb
@ -18,7 +18,7 @@ public class ChainGetter implements CallHandler {
|
||||
|
||||
@Override
|
||||
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryMap, String cognitoID) throws SQLException {
|
||||
Integer id = Integer.parseInt(queryMap.get("id"));
|
||||
Integer id = (Integer) bodyMap.get("id");
|
||||
if (id == -1) {
|
||||
PreparedStatement getChains = connection.prepareStatement(GET_CHAINS);
|
||||
System.out.println(getChains);
|
||||
|
||||
@ -9,12 +9,12 @@ public class TestChainGetter {
|
||||
|
||||
@Test
|
||||
public void testChainGetterValid() {
|
||||
testChainGetter(false);
|
||||
testChainGetter(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChainGetterError() {
|
||||
testChainGetter(true);
|
||||
testChainGetter(false);
|
||||
}
|
||||
|
||||
public void testChainGetter(boolean shouldThrow) {
|
||||
@ -29,7 +29,7 @@ public class TestChainGetter {
|
||||
ChainGetter chainGetter = Mockito.spy(new ChainGetter(injector, "cognitoID"));
|
||||
Map<String, Object> ignore = new HashMap<>();
|
||||
Map<String, Object> body = TestInputUtils.addBody(ignore);
|
||||
ignore.put("id", 1); //in ChainGetter.java uses ignore map for id parameter
|
||||
body.put("id", 1);
|
||||
|
||||
try {
|
||||
Object rawIDReturn = chainGetter.conductAction(body, TestInputUtils.addQueryParams(ignore), "cognitoID");
|
||||
@ -38,6 +38,12 @@ public class TestChainGetter {
|
||||
} catch (SQLException throwables) {
|
||||
assert shouldThrow;
|
||||
throwables.printStackTrace();
|
||||
} catch (NumberFormatException throwables) {
|
||||
assert shouldThrow;
|
||||
throwables.printStackTrace();
|
||||
} catch (ClassCastException throwables) {
|
||||
assert shouldThrow;
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BIN
Lambdas/Lists/List/target/artifacts/Lists_jar/Lists.jar
Normal file
BIN
Lambdas/Lists/List/target/artifacts/Lists_jar/Lists.jar
Normal file
Binary file not shown.
16
Lambdas/Lists/List/target/production/Chain/README.md
Normal file
16
Lambdas/Lists/List/target/production/Chain/README.md
Normal file
@ -0,0 +1,16 @@
|
||||
# Chain Module
|
||||
Deals with information concerning store chains supported by the product populating and product serving Lambdas.
|
||||
|
||||
### ChainGET
|
||||
#### Expected request body:
|
||||
N/A
|
||||
|
||||
#### Expected query parameters:
|
||||
- id
|
||||
- Used for specifying which chain to retrieve
|
||||
- Valid values: -1,1<n<{num_chains}
|
||||
|
||||
#### Inputs and outputs:
|
||||
- id = -1: Returns an array if chainIDs (Integers)
|
||||
- id = 1<n<{num_chains}: Returns a [Chain object](https://github.com/ClaytonWWilson/Listify/blob/master/Lambdas/Lists/Chain/src/Chain.java) for the chain with chainID=id
|
||||
|
||||
@ -11,20 +11,18 @@ import java.util.Map;
|
||||
public class TestListGetter {
|
||||
|
||||
@Test
|
||||
public void testListGetterValid() { conductListGetterTestMock(false); }
|
||||
public void testListGetterValid() { conductListGetterTestMock(true); }
|
||||
|
||||
@Test
|
||||
public void testListIDGetterValid() {
|
||||
conductListIDGetterTestMock(false);
|
||||
conductListIDGetterTestMock(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListIDGetterError() {
|
||||
conductListIDGetterTestMock(false);
|
||||
}
|
||||
public void testListIDGetterError() { conductListIDGetterTestMock(false); }
|
||||
|
||||
@Test
|
||||
public void testListGetterError() { conductListGetterTestMock(true); }
|
||||
public void testListGetterError() { conductListGetterTestMock(false); }
|
||||
|
||||
public void conductListGetterTestMock(boolean shouldThrow) {
|
||||
Integer listID = 1;
|
||||
@ -63,8 +61,11 @@ public class TestListGetter {
|
||||
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;
|
||||
throwables.printStackTrace();
|
||||
} catch (ClassCastException throwables) {
|
||||
assert !shouldThrow;
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,11 +82,10 @@ public class TestListGetter {
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
//ListGetter getter = new ListGetter(injector, "id");
|
||||
ListGetter getter = Mockito.spy(new ListGetter(injector, "id"));
|
||||
Map<String, Object> ignore = new HashMap<>();
|
||||
HashMap<String, String> queryParams = TestInputUtils.addQueryParams(ignore);
|
||||
queryParams.put("id", "-1");
|
||||
queryParams.put("id", "1");
|
||||
try {
|
||||
Object conductReturn = getter.conductAction(TestInputUtils.addBody(ignore), queryParams, "cognitoID");
|
||||
assert !shouldThrow;
|
||||
@ -96,6 +96,9 @@ public class TestListGetter {
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
assert shouldThrow;
|
||||
} catch (ClassCastException throwables) {
|
||||
throwables.printStackTrace();
|
||||
assert !shouldThrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.security.AccessControlException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -9,12 +10,12 @@ public class TestListDuplicate {
|
||||
|
||||
@Test
|
||||
public void testListDuplicateValid() {
|
||||
testListDuplicaterMock(false);
|
||||
testListDuplicaterMock(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListDuplicateError() {
|
||||
testListDuplicaterMock(true);
|
||||
testListDuplicaterMock(false);
|
||||
}
|
||||
|
||||
public void testListDuplicaterMock(boolean shouldThrow) {
|
||||
@ -38,6 +39,9 @@ public class TestListDuplicate {
|
||||
} catch (SQLException throwables) {
|
||||
assert shouldThrow;
|
||||
throwables.printStackTrace();
|
||||
} catch(AccessControlException throwables) {
|
||||
assert !shouldThrow;
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.security.AccessControlException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -9,12 +10,12 @@ public class TestListEntryAdder {
|
||||
|
||||
@Test
|
||||
public void testListEntryAdderValid() {
|
||||
testListEntryAdderCoreMock(false);
|
||||
testListEntryAdderCoreMock(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListEntryAdderError() {
|
||||
testListEntryAdderCoreMock(true);
|
||||
testListEntryAdderCoreMock(false);
|
||||
}
|
||||
|
||||
public void testListEntryAdderCoreMock(boolean shouldThrow) {
|
||||
@ -43,6 +44,9 @@ public class TestListEntryAdder {
|
||||
} catch (SQLException throwables) {
|
||||
assert shouldThrow;
|
||||
throwables.printStackTrace();
|
||||
} catch (AccessControlException throwables) {
|
||||
assert !shouldThrow;
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.Mockito.*;
|
||||
|
||||
import java.security.AccessControlException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -9,11 +10,11 @@ import java.util.Map;
|
||||
public class TestListEntryDeleter {
|
||||
|
||||
@Test
|
||||
public void testListEntryDeleterValid() { testListEntryDeleterCoreMock(false); }
|
||||
public void testListEntryDeleterValid() { testListEntryDeleterCoreMock(true); }
|
||||
|
||||
@Test
|
||||
public void testListEntryDeleterError() {
|
||||
testListEntryDeleterCoreMock(true);
|
||||
testListEntryDeleterCoreMock(false);
|
||||
}
|
||||
|
||||
public void testListEntryDeleterCoreMock(boolean shouldThrow) {
|
||||
@ -39,6 +40,9 @@ public class TestListEntryDeleter {
|
||||
} catch (SQLException throwables) {
|
||||
assert shouldThrow;
|
||||
throwables.printStackTrace();
|
||||
} catch (AccessControlException throwables) {
|
||||
assert !shouldThrow;
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,6 +38,9 @@ public class TestListReposition {
|
||||
} catch (SQLException throwables) {
|
||||
assert shouldThrow;
|
||||
throwables.printStackTrace();
|
||||
} catch (IllegalArgumentException throwables) {
|
||||
assert !shouldThrow;
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,9 +18,9 @@ public class PicturePutter implements CallHandler {
|
||||
|
||||
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryString, String cognitoID) throws SQLException {
|
||||
PreparedStatement storePicture = connection.prepareStatement(STORE_PICTURE_SQL);
|
||||
if(!bodyMap.containsKey("base64EncodedImage")) {
|
||||
throw new IllegalArgumentException("Base64EncodedImage not found");
|
||||
}
|
||||
// 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);
|
||||
|
||||
@ -9,7 +9,7 @@ public class TestPictureGetter {
|
||||
|
||||
@Test
|
||||
public void testPictureGetterValid() {
|
||||
testPictureGetter(false);
|
||||
testPictureGetter(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -35,7 +35,7 @@ public class TestPictureGetter {
|
||||
try {
|
||||
Object rawIDReturn = pictureGetter.conductAction(body, TestInputUtils.addQueryParams(ignore), "cognitoID");
|
||||
assert (rawIDReturn != null);
|
||||
} catch (SQLException throwables) {
|
||||
} catch (SQLException | IllegalArgumentException throwables) {
|
||||
assert shouldThrow;
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
|
||||
@ -9,12 +9,12 @@ public class TestPicturePutter {
|
||||
|
||||
@Test
|
||||
public void testPicturePutterValid() {
|
||||
testPicturePutter(false);
|
||||
testPicturePutter(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPicturePutterError() {
|
||||
testPicturePutter(true);
|
||||
testPicturePutter(false);
|
||||
}
|
||||
|
||||
public void testPicturePutter(boolean shouldThrow) {
|
||||
@ -29,12 +29,20 @@ public class TestPicturePutter {
|
||||
PicturePutter picturePutter = Mockito.spy(new PicturePutter(injector, "cognitoID"));
|
||||
Map<String, Object> ignore = new HashMap<>();
|
||||
Map<String, Object> body = TestInputUtils.addBody(ignore);
|
||||
body.put("base64EncodedImage", "testingimage");
|
||||
try {
|
||||
Object rawIDReturn = picturePutter.conductAction(body, TestInputUtils.addQueryParams(ignore), "cognitoID");
|
||||
assert (rawIDReturn == null);
|
||||
} catch (SQLException throwables) {
|
||||
assert shouldThrow;
|
||||
throwables.printStackTrace();
|
||||
} catch (IllegalArgumentException throwables) {
|
||||
assert shouldThrow;
|
||||
throwables.printStackTrace();
|
||||
} catch(NullPointerException throwables) {
|
||||
assert shouldThrow;
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user