Merge pull request #148 from ClaytonWWilson/test-new-lambdas

Adding new lambda tests
This commit is contained in:
Adam Ding 2020-12-01 21:13:10 -05:00 committed by GitHub
commit 167b369749
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 342 additions and 2 deletions

View 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();
}
}
}

View 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();
}
}
}

View 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();
}
}
}

View File

@ -1,6 +1,5 @@
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.Mockito.*;
import java.sql.SQLException;
import java.util.HashMap;

View 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();
}
}
}

View File

@ -19,7 +19,7 @@ public class PictureGetter implements CallHandler {
@Override
public Object conductAction(Map<String, Object> bodyMap, HashMap<String, String> 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);

View File

@ -18,6 +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");
}
storePicture.setString(1, cognitoID);
storePicture.setString(2, bodyMap.get("base64EncodedImage").toString());
System.out.println(storePicture);

View 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();
}
}
}

View 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();
}
}
}

View File

@ -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();
}
}
}

View File

@ -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();
}
}
}