mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-15 18:28:47 +00:00
Merge pull request #148 from ClaytonWWilson/test-new-lambdas
Adding new lambda tests
This commit is contained in:
commit
167b369749
43
Lambdas/Lists/Chain/test/TestChainGetter.java
Normal file
43
Lambdas/Lists/Chain/test/TestChainGetter.java
Normal file
@ -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<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
|
||||||
|
|
||||||
|
try {
|
||||||
|
Object rawIDReturn = chainGetter.conductAction(body, TestInputUtils.addQueryParams(ignore), "cognitoID");
|
||||||
|
assert !shouldThrow;
|
||||||
|
assert (rawIDReturn != null);
|
||||||
|
} catch (SQLException throwables) {
|
||||||
|
assert shouldThrow;
|
||||||
|
throwables.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
43
Lambdas/Lists/ItemSearch/test/TestItemSearcher.java
Normal file
43
Lambdas/Lists/ItemSearch/test/TestItemSearcher.java
Normal file
@ -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<String, Object> ignore = new HashMap<>();
|
||||||
|
Map<String, Object> 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
43
Lambdas/Lists/ListDuplicate/test/TestListDuplicate.java
Normal file
43
Lambdas/Lists/ListDuplicate/test/TestListDuplicate.java
Normal file
@ -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<String, Object> ignore = new HashMap<>();
|
||||||
|
Map<String, Object> 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,5 @@
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.mockito.Mockito.*;
|
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|||||||
43
Lambdas/Lists/ListReposition/test/TestListReposition.java
Normal file
43
Lambdas/Lists/ListReposition/test/TestListReposition.java
Normal file
@ -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<String, Object> ignore = new HashMap<>();
|
||||||
|
Map<String, Object> 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -19,7 +19,7 @@ public class PictureGetter implements CallHandler {
|
|||||||
@Override
|
@Override
|
||||||
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryMap, String cognitoID) throws SQLException {
|
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryMap, String cognitoID) throws SQLException {
|
||||||
PreparedStatement statement = connection.prepareStatement(GET_ITEM);
|
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.");
|
throw new IllegalArgumentException("Only profile pictures are currently supported.");
|
||||||
}
|
}
|
||||||
statement.setString(1, cognitoID);
|
statement.setString(1, cognitoID);
|
||||||
|
|||||||
@ -18,6 +18,9 @@ public class PicturePutter implements CallHandler {
|
|||||||
|
|
||||||
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryString, String cognitoID) throws SQLException {
|
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> queryString, String cognitoID) throws SQLException {
|
||||||
PreparedStatement storePicture = connection.prepareStatement(STORE_PICTURE_SQL);
|
PreparedStatement storePicture = connection.prepareStatement(STORE_PICTURE_SQL);
|
||||||
|
if(!bodyMap.containsKey("base64EncodedImage")) {
|
||||||
|
throw new IllegalArgumentException("Base64EncodedImage not found");
|
||||||
|
}
|
||||||
storePicture.setString(1, cognitoID);
|
storePicture.setString(1, cognitoID);
|
||||||
storePicture.setString(2, bodyMap.get("base64EncodedImage").toString());
|
storePicture.setString(2, bodyMap.get("base64EncodedImage").toString());
|
||||||
System.out.println(storePicture);
|
System.out.println(storePicture);
|
||||||
|
|||||||
43
Lambdas/Lists/Picture/test/TestPictureGetter.java
Normal file
43
Lambdas/Lists/Picture/test/TestPictureGetter.java
Normal file
@ -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<String, Object> ignore = new HashMap<>();
|
||||||
|
Map<String, Object> 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
40
Lambdas/Lists/Picture/test/TestPicturePutter.java
Normal file
40
Lambdas/Lists/Picture/test/TestPicturePutter.java
Normal file
@ -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<String, Object> ignore = new HashMap<>();
|
||||||
|
Map<String, Object> body = TestInputUtils.addBody(ignore);
|
||||||
|
try {
|
||||||
|
Object rawIDReturn = picturePutter.conductAction(body, TestInputUtils.addQueryParams(ignore), "cognitoID");
|
||||||
|
assert (rawIDReturn == null);
|
||||||
|
} catch (SQLException throwables) {
|
||||||
|
assert shouldThrow;
|
||||||
|
throwables.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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<String, Object> ignore = new HashMap<>();
|
||||||
|
Map<String, Object> body = TestInputUtils.addBody(ignore);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Object rawIDReturn = searchHistoryGetter.conductAction(body, TestInputUtils.addQueryParams(ignore), "cognitoID");
|
||||||
|
assert (rawIDReturn != null);
|
||||||
|
} catch (SQLException throwables) {
|
||||||
|
assert shouldThrow;
|
||||||
|
throwables.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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<String, Object> ignore = new HashMap<>();
|
||||||
|
Map<String, Object> body = TestInputUtils.addBody(ignore);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Object rawIDReturn = testSearchHistoryUpdater.conductAction(body, TestInputUtils.addQueryParams(ignore), "cognitoID");
|
||||||
|
assert (rawIDReturn == null);
|
||||||
|
} catch (SQLException throwables) {
|
||||||
|
assert shouldThrow;
|
||||||
|
throwables.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user