summaryrefslogtreecommitdiff
path: root/tst/com/p4square/grow/ccb
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2016-04-09 14:22:20 -0700
committerJesse Morgan <jesse@jesterpm.net>2016-04-09 15:48:01 -0700
commit3102d8bce3426d9cf41aeaf201c360d342677770 (patch)
tree38c4f1e8828f9af9c4b77a173bee0d312b321698 /tst/com/p4square/grow/ccb
parentbbf907e51dfcf157bdee24dead1d531122aa25db (diff)
Switching from Ivy+Ant to Maven.
Diffstat (limited to 'tst/com/p4square/grow/ccb')
-rw-r--r--tst/com/p4square/grow/ccb/CCBProgressReporterTest.java231
-rw-r--r--tst/com/p4square/grow/ccb/CCBUserVerifierTest.java139
-rw-r--r--tst/com/p4square/grow/ccb/CustomFieldCacheTest.java241
3 files changed, 0 insertions, 611 deletions
diff --git a/tst/com/p4square/grow/ccb/CCBProgressReporterTest.java b/tst/com/p4square/grow/ccb/CCBProgressReporterTest.java
deleted file mode 100644
index 63a973a..0000000
--- a/tst/com/p4square/grow/ccb/CCBProgressReporterTest.java
+++ /dev/null
@@ -1,231 +0,0 @@
-package com.p4square.grow.ccb;
-
-import com.p4square.ccbapi.CCBAPI;
-import com.p4square.ccbapi.model.*;
-import org.easymock.Capture;
-import org.easymock.EasyMock;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.time.LocalDate;
-import java.util.Date;
-
-import static org.junit.Assert.*;
-
-/**
- * Tests for the CCBProgressReporter.
- */
-public class CCBProgressReporterTest {
-
- private static final String GROW_LEVEL = "GrowLevelTrain";
- private static final String ASSESSMENT_LEVEL = "GrowLevelAsmnt";
-
- private CCBProgressReporter reporter;
-
- private CCBAPI api;
- private CustomFieldCache cache;
-
- private CCBUser user;
- private Date date;
-
- @Before
- public void setUp() {
- // Setup some data for testing.
- IndividualProfile profile = new IndividualProfile();
- profile.setId(123);
- profile.setFirstName("Larry");
- profile.setLastName("Cucumber");
- profile.setEmail("larry.cucumber@example.com");
-
- user = new CCBUser(profile);
- date = new Date(1427889600000L); // 2015-04-01
-
- // Setup the mocks.
- api = EasyMock.mock(CCBAPI.class);
- cache = EasyMock.mock(CustomFieldCache.class);
- reporter = new CCBProgressReporter(api, cache);
- }
-
- private void setupCacheMocks() {
- // Setup the Grow Level field.
- CustomField growLevelDate = new CustomField();
- growLevelDate.setName("udf_ind_date_1");
- growLevelDate.setLabel(GROW_LEVEL);
-
- CustomField growLevelPulldown = new CustomField();
- growLevelPulldown.setName("udf_ind_pulldown_1");
- growLevelPulldown.setLabel(GROW_LEVEL);
-
- LookupTableItem believer = new LookupTableItem();
- believer.setId(1);
- believer.setOrder(2);
- believer.setName("Believer");
-
- EasyMock.expect(cache.getDateFieldByLabel(GROW_LEVEL))
- .andReturn(growLevelDate).anyTimes();
- EasyMock.expect(cache.getIndividualPulldownByLabel(GROW_LEVEL))
- .andReturn(growLevelPulldown).anyTimes();
- EasyMock.expect(cache.getPulldownItemByName(LookupTableType.UDF_IND_PULLDOWN_1, "Believer"))
- .andReturn(believer).anyTimes();
-
- // Setup the Grow Assessment field.
- CustomField growAssessmentDate = new CustomField();
- growAssessmentDate.setName("udf_ind_date_2");
- growAssessmentDate.setLabel(ASSESSMENT_LEVEL);
-
- CustomField growAssessmentPulldown = new CustomField();
- growAssessmentPulldown.setName("udf_ind_pulldown_2");
- growAssessmentPulldown.setLabel(ASSESSMENT_LEVEL);
-
- EasyMock.expect(cache.getDateFieldByLabel(ASSESSMENT_LEVEL))
- .andReturn(growAssessmentDate).anyTimes();
- EasyMock.expect(cache.getIndividualPulldownByLabel(ASSESSMENT_LEVEL))
- .andReturn(growAssessmentPulldown).anyTimes();
- EasyMock.expect(cache.getPulldownItemByName(LookupTableType.UDF_IND_PULLDOWN_2, "Believer"))
- .andReturn(believer).anyTimes();
- }
-
- @Test
- public void reportAssessmentComplete() throws Exception {
- // Setup mocks
- setupCacheMocks();
- Capture<UpdateIndividualProfileRequest> reqCapture = EasyMock.newCapture();
- EasyMock.expect(api.updateIndividualProfile(EasyMock.capture(reqCapture)))
- .andReturn(EasyMock.mock(UpdateIndividualProfileResponse.class));
- replay();
-
- // Test reporter
- reporter.reportAssessmentComplete(user, "Believer", date, "Data");
-
- // Assert that the profile was updated.
- verify();
- assertTrue(reqCapture.hasCaptured());
- UpdateIndividualProfileRequest req = reqCapture.getValue();
- assertEquals(1, req.getCustomPulldownFields().get("udf_pulldown_2").intValue());
- assertEquals("2015-04-01", req.getCustomDateFields().get("udf_date_2").toString());
- }
-
- @Test
- public void testReportChapterCompleteNoPreviousChapter() throws Exception {
- // Setup mocks
- setupCacheMocks();
- Capture<UpdateIndividualProfileRequest> reqCapture = EasyMock.newCapture();
- EasyMock.expect(api.updateIndividualProfile(EasyMock.capture(reqCapture)))
- .andReturn(EasyMock.mock(UpdateIndividualProfileResponse.class));
- replay();
-
- // Test reporter
- reporter.reportChapterComplete(user, "Believer", date);
-
- // Assert that the profile was updated.
- verify();
- assertTrue(reqCapture.hasCaptured());
- UpdateIndividualProfileRequest req = reqCapture.getValue();
- assertEquals(1, req.getCustomPulldownFields().get("udf_pulldown_1").intValue());
- assertEquals("2015-04-01", req.getCustomDateFields().get("udf_date_1").toString());
- }
-
- @Test
- public void testReportChapterCompleteLowerPreviousChapter() throws Exception {
- // Setup mocks
- setupCacheMocks();
- Capture<UpdateIndividualProfileRequest> reqCapture = EasyMock.newCapture();
- EasyMock.expect(api.updateIndividualProfile(EasyMock.capture(reqCapture)))
- .andReturn(EasyMock.mock(UpdateIndividualProfileResponse.class));
-
- setUserPulldownSelection(GROW_LEVEL, "Seeker");
-
- replay();
-
- // Test reporter
- reporter.reportChapterComplete(user, "Believer", date);
-
- // Assert that the profile was updated.
- verify();
- assertTrue(reqCapture.hasCaptured());
- UpdateIndividualProfileRequest req = reqCapture.getValue();
- assertEquals(1, req.getCustomPulldownFields().get("udf_pulldown_1").intValue());
- assertEquals("2015-04-01", req.getCustomDateFields().get("udf_date_1").toString());
- }
-
- @Test
- public void testReportChapterCompleteHigherPreviousChapter() throws Exception {
- // Setup mocks
- setupCacheMocks();
- setUserPulldownSelection(GROW_LEVEL, "Disciple");
-
- replay();
-
- // Test reporter
- reporter.reportChapterComplete(user, "Believer", date);
-
- // Assert that the profile was updated.
- verify();
- }
-
- @Test
- public void testReportChapterCompleteNoCustomField() throws Exception {
- // Setup mocks
- EasyMock.expect(cache.getDateFieldByLabel(EasyMock.anyString())).andReturn(null).anyTimes();
- EasyMock.expect(cache.getIndividualPulldownByLabel(EasyMock.anyString())).andReturn(null).anyTimes();
- EasyMock.expect(cache.getPulldownItemByName(EasyMock.anyObject(), EasyMock.anyString()))
- .andReturn(null).anyTimes();
- replay();
-
- // Test reporter
- reporter.reportChapterComplete(user, "Believer", date);
-
- // Assert that the profile was updated.
- verify();
- }
-
- @Test
- public void testReportChapterCompleteNoSuchValue() throws Exception {
- // Setup mocks
- setupCacheMocks();
- EasyMock.expect(cache.getPulldownItemByName(LookupTableType.UDF_IND_PULLDOWN_1, "Foo"))
- .andReturn(null).anyTimes();
- Capture<UpdateIndividualProfileRequest> reqCapture = EasyMock.newCapture();
- EasyMock.expect(api.updateIndividualProfile(EasyMock.capture(reqCapture)))
- .andReturn(EasyMock.mock(UpdateIndividualProfileResponse.class));
- replay();
-
- // Test reporter
- reporter.reportChapterComplete(user, "Foo", date);
-
- // Assert that the profile was updated.
- verify();
- assertTrue(reqCapture.hasCaptured());
- UpdateIndividualProfileRequest req = reqCapture.getValue();
- assertNull(req.getCustomPulldownFields().get("udf_pulldown_1"));
- assertEquals("2015-04-01", req.getCustomDateFields().get("udf_date_1").toString());
- }
-
- private void setUserPulldownSelection(final String field, final String value) {
- // Get the pulldown field collection for the user.
- CustomFieldCollection<CustomPulldownFieldValue> pulldowns = user.getProfile().getCustomPulldownFields();
- if (pulldowns == null) {
- pulldowns = new CustomFieldCollection<>();
- user.getProfile().setCustomPulldownFields(pulldowns);
- }
-
- // Create the selection for the value.
- PulldownSelection selection = new PulldownSelection();
- selection.setLabel(value);
-
- // Create the field/value pair and add it to the collection.
- CustomPulldownFieldValue fieldValue = new CustomPulldownFieldValue();
- fieldValue.setName(field); // This is unused by the test, but it should be a udf_ identifier.
- fieldValue.setLabel(field);
- fieldValue.setSelection(selection);
- pulldowns.add(fieldValue);
- }
-
- private void replay() {
- EasyMock.replay(api, cache);
- }
-
- private void verify() {
- EasyMock.verify(api, cache);
- }
-} \ No newline at end of file
diff --git a/tst/com/p4square/grow/ccb/CCBUserVerifierTest.java b/tst/com/p4square/grow/ccb/CCBUserVerifierTest.java
deleted file mode 100644
index d17b698..0000000
--- a/tst/com/p4square/grow/ccb/CCBUserVerifierTest.java
+++ /dev/null
@@ -1,139 +0,0 @@
-package com.p4square.grow.ccb;
-
-import com.p4square.ccbapi.CCBAPI;
-import com.p4square.ccbapi.model.GetIndividualProfilesRequest;
-import com.p4square.ccbapi.model.GetIndividualProfilesResponse;
-import com.p4square.ccbapi.model.IndividualProfile;
-import org.easymock.EasyMock;
-import org.junit.Before;
-import org.junit.Test;
-import org.restlet.Request;
-import org.restlet.Response;
-import org.restlet.data.ChallengeResponse;
-import org.restlet.data.ChallengeScheme;
-import org.restlet.data.ClientInfo;
-import org.restlet.security.Verifier;
-
-import java.io.IOException;
-import java.util.Collections;
-
-import static org.junit.Assert.*;
-
-/**
- * Tests for CCBUserVerifier.
- */
-public class CCBUserVerifierTest {
-
- private IndividualProfile mProfile = new IndividualProfile();
-
- private CCBAPI mAPI;
- private CCBUserVerifier verifier;
-
- private ClientInfo mClientInfo;
- private Request mMockRequest;
- private Response mMockResponse;
-
- @Before
- public void setUp() {
- mAPI = EasyMock.mock(CCBAPI.class);
- verifier = new CCBUserVerifier(mAPI);
-
- mClientInfo = new ClientInfo();
- mMockRequest = EasyMock.mock(Request.class);
- EasyMock.expect(mMockRequest.getClientInfo()).andReturn(mClientInfo).anyTimes();
-
- mMockResponse = EasyMock.mock(Response.class);
-
- mProfile.setId(48);
- mProfile.setFirstName("Larry");
- mProfile.setLastName("Bob");
- mProfile.setEmail("larry.bob@example.com");
- }
-
- private void replay() {
- EasyMock.replay(mAPI, mMockRequest, mMockResponse);
- }
-
- private void verify() {
- EasyMock.verify(mAPI, mMockRequest, mMockResponse);
- }
-
-
- @Test
- public void testVerifyNoCredentials() throws Exception {
- // Prepare mocks
- EasyMock.expect(mMockRequest.getChallengeResponse()).andReturn(null).anyTimes();
- replay();
-
- // Test
- int result = verifier.verify(mMockRequest, mMockResponse);
-
- // Verify
- verify();
- assertEquals(Verifier.RESULT_MISSING, result);
- assertNull(mClientInfo.getUser());
- }
-
- @Test
- public void testVerifyAuthFailure() throws Exception {
- // Prepare mocks
- ChallengeResponse challenge = new ChallengeResponse(ChallengeScheme.HTTP_BASIC, "user", "pass");
- EasyMock.expect(mMockRequest.getChallengeResponse()).andReturn(challenge).anyTimes();
- GetIndividualProfilesResponse response = new GetIndividualProfilesResponse();
- response.setIndividuals(Collections.<IndividualProfile>emptyList());
- EasyMock.expect(mAPI.getIndividualProfiles(new GetIndividualProfilesRequest()
- .withLoginPassword("user", "pass".toCharArray()))).andReturn(response);
- replay();
-
- // Test
- int result = verifier.verify(mMockRequest, mMockResponse);
-
- // Verify
- verify();
- assertEquals(Verifier.RESULT_INVALID, result);
- assertNull(mClientInfo.getUser());
- }
-
- @Test
- public void testVerifyAuthException() throws Exception {
- // Prepare mocks
- ChallengeResponse challenge = new ChallengeResponse(ChallengeScheme.HTTP_BASIC, "user", "pass");
- EasyMock.expect(mMockRequest.getChallengeResponse()).andReturn(challenge).anyTimes();
- EasyMock.expect(mAPI.getIndividualProfiles(EasyMock.anyObject(GetIndividualProfilesRequest.class)))
- .andThrow(new IOException());
- replay();
-
- // Test
- int result = verifier.verify(mMockRequest, mMockResponse);
-
- // Verify
- verify();
- assertEquals(Verifier.RESULT_INVALID, result);
- assertNull(mClientInfo.getUser());
- }
-
- @Test
- public void testVerifyAuthSuccess() throws Exception {
- // Prepare mocks
- ChallengeResponse challenge = new ChallengeResponse(ChallengeScheme.HTTP_BASIC, "user", "pass");
- EasyMock.expect(mMockRequest.getChallengeResponse()).andReturn(challenge).anyTimes();
- GetIndividualProfilesResponse response = new GetIndividualProfilesResponse();
- response.setIndividuals(Collections.singletonList(mProfile));
- EasyMock.expect(mAPI.getIndividualProfiles(new GetIndividualProfilesRequest()
- .withLoginPassword("user", "pass".toCharArray()))).andReturn(response);
-
- replay();
-
- // Test
- int result = verifier.verify(mMockRequest, mMockResponse);
-
- // Verify
- verify();
- assertEquals(Verifier.RESULT_VALID, result);
- assertNotNull(mClientInfo.getUser());
- assertEquals("CCB-48", mClientInfo.getUser().getIdentifier());
- assertEquals("Larry", mClientInfo.getUser().getFirstName());
- assertEquals("Bob", mClientInfo.getUser().getLastName());
- assertEquals("larry.bob@example.com", mClientInfo.getUser().getEmail());
- }
-} \ No newline at end of file
diff --git a/tst/com/p4square/grow/ccb/CustomFieldCacheTest.java b/tst/com/p4square/grow/ccb/CustomFieldCacheTest.java
deleted file mode 100644
index bcfd260..0000000
--- a/tst/com/p4square/grow/ccb/CustomFieldCacheTest.java
+++ /dev/null
@@ -1,241 +0,0 @@
-package com.p4square.grow.ccb;
-
-import com.p4square.ccbapi.CCBAPI;
-import com.p4square.ccbapi.model.*;
-import org.easymock.Capture;
-import org.easymock.EasyMock;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.util.Arrays;
-
-import static org.junit.Assert.*;
-
-/**
- * Tests for the CustomFieldCache.
- */
-public class CustomFieldCacheTest {
-
- private CustomFieldCache cache;
-
- private CCBAPI api;
- private GetCustomFieldLabelsResponse customFieldsResponse;
- private GetLookupTableResponse lookupTableResponse;
-
- @Before
- public void setUp() {
- api = EasyMock.mock(CCBAPI.class);
- cache = new CustomFieldCache(api);
-
- // Prepare some custom fields for the test.
- CustomField textField = new CustomField();
- textField.setName("udf_ind_text_6");
- textField.setLabel("Grow Level");
-
- CustomField dateField = new CustomField();
- dateField.setName("udf_ind_date_6");
- dateField.setLabel("Grow Level");
-
- CustomField pullDown = new CustomField();
- pullDown.setName("udf_ind_pulldown_6");
- pullDown.setLabel("Grow Level");
-
- customFieldsResponse = new GetCustomFieldLabelsResponse();
- customFieldsResponse.setCustomFields(Arrays.asList(textField, dateField, pullDown));
-
- // Prepare some pulldown items for the tests.
- LookupTableItem seeker = new LookupTableItem();
- seeker.setId(1);
- seeker.setOrder(1);
- seeker.setName("Seeker");
-
- LookupTableItem believer = new LookupTableItem();
- believer.setId(2);
- believer.setOrder(2);
- believer.setName("Believer");
-
- lookupTableResponse = new GetLookupTableResponse();
- lookupTableResponse.setItems(Arrays.asList(seeker, believer));
- }
-
- @Test
- public void testGetTextFieldByLabel() throws Exception {
- // Setup mocks
- EasyMock.expect(api.getCustomFieldLabels()).andReturn(customFieldsResponse);
- EasyMock.replay(api);
-
- // Test the cache
- CustomField field = cache.getTextFieldByLabel("Grow Level");
-
- // Verify result.
- EasyMock.verify(api);
- assertEquals("udf_ind_text_6", field.getName());
- assertEquals("Grow Level", field.getLabel());
- }
-
- @Test
- public void testGetDateFieldByLabel() throws Exception {
- // Setup mocks
- EasyMock.expect(api.getCustomFieldLabels()).andReturn(customFieldsResponse);
- EasyMock.replay(api);
-
- // Test the cache
- CustomField field = cache.getDateFieldByLabel("Grow Level");
-
- // Verify result.
- EasyMock.verify(api);
- assertEquals("udf_ind_date_6", field.getName());
- assertEquals("Grow Level", field.getLabel());
- }
-
- @Test
- public void testGetPullDownFieldByLabel() throws Exception {
- // Setup mocks
- EasyMock.expect(api.getCustomFieldLabels()).andReturn(customFieldsResponse);
- EasyMock.replay(api);
-
- // Test the cache
- CustomField field = cache.getIndividualPulldownByLabel("Grow Level");
-
- // Verify result.
- EasyMock.verify(api);
- assertEquals("udf_ind_pulldown_6", field.getName());
- assertEquals("Grow Level", field.getLabel());
- }
-
- @Test
- public void testGetPullDownFieldByLabelMissing() throws Exception {
- // Setup mocks
- EasyMock.expect(api.getCustomFieldLabels()).andReturn(customFieldsResponse);
- EasyMock.replay(api);
-
- // Test the cache
- CustomField field = cache.getIndividualPulldownByLabel("Missing Label");
-
- // Verify result.
- EasyMock.verify(api);
- assertNull(field);
- }
-
- @Test
- public void testGetPullDownFieldByLabelException() throws Exception {
- // Setup mocks
- EasyMock.expect(api.getCustomFieldLabels()).andThrow(new IOException());
- EasyMock.expect(api.getCustomFieldLabels()).andReturn(customFieldsResponse);
- EasyMock.replay(api);
-
- // Test the cache
- CustomField field1 = cache.getIndividualPulldownByLabel("Grow Level");
- CustomField field2 = cache.getIndividualPulldownByLabel("Grow Level");
-
- // Verify result.
- EasyMock.verify(api);
- assertNull(field1);
- assertNotNull(field2);
- }
-
- @Test
- public void testGetMultipleFields() throws Exception {
- // Setup mocks
- // Note: only one API call.
- EasyMock.expect(api.getCustomFieldLabels()).andReturn(customFieldsResponse);
- EasyMock.replay(api);
-
- // Test the cache
- CustomField field1 = cache.getTextFieldByLabel("Grow Level");
- CustomField field2 = cache.getIndividualPulldownByLabel("Grow Level");
-
- // Verify result.
- EasyMock.verify(api);
- assertEquals("udf_ind_text_6", field1.getName());
- assertEquals("Grow Level", field1.getLabel());
- assertEquals("udf_ind_pulldown_6", field2.getName());
- assertEquals("Grow Level", field2.getLabel());
- }
-
- @Test
- public void testGetPullDownOptions() throws Exception {
- // Setup mocks
- Capture<GetLookupTableRequest> requestCapture = EasyMock.newCapture();
- EasyMock.expect(api.getLookupTable(EasyMock.capture(requestCapture))).andReturn(lookupTableResponse);
- EasyMock.replay(api);
-
- // Test the cache
- LookupTableItem item = cache.getPulldownItemByName(
- LookupTableType.valueOf("udf_ind_pulldown_6".toUpperCase()),
- "Believer");
-
- // Verify result.
- EasyMock.verify(api);
- assertEquals(LookupTableType.UDF_IND_PULLDOWN_6, requestCapture.getValue().getType());
- assertEquals(2, item.getId());
- assertEquals(2, item.getOrder());
- assertEquals("Believer", item.getName());
- }
-
- @Test
- public void testGetPullDownOptionsMixedCase() throws Exception {
- // Setup mocks
- Capture<GetLookupTableRequest> requestCapture = EasyMock.newCapture();
- EasyMock.expect(api.getLookupTable(EasyMock.capture(requestCapture))).andReturn(lookupTableResponse);
- EasyMock.replay(api);
-
- // Test the cache
- LookupTableItem item = cache.getPulldownItemByName(
- LookupTableType.valueOf("udf_ind_pulldown_6".toUpperCase()),
- "BeLiEvEr");
-
- // Verify result.
- EasyMock.verify(api);
- assertEquals(LookupTableType.UDF_IND_PULLDOWN_6, requestCapture.getValue().getType());
- assertEquals(2, item.getId());
- assertEquals(2, item.getOrder());
- assertEquals("Believer", item.getName());
- }
-
- @Test
- public void testGetPullDownOptionMissing() throws Exception {
- // Setup mocks
- EasyMock.expect(api.getLookupTable(EasyMock.anyObject())).andReturn(lookupTableResponse);
- EasyMock.replay(api);
-
- // Test the cache
- LookupTableItem item = cache.getPulldownItemByName(LookupTableType.UDF_IND_PULLDOWN_6, "Something else");
-
- // Verify result.
- EasyMock.verify(api);
- assertNull(item);
- }
-
- @Test
- public void testGetPullDownMissing() throws Exception {
- // Setup mocks
- EasyMock.expect(api.getLookupTable(EasyMock.anyObject())).andReturn(new GetLookupTableResponse());
- EasyMock.replay(api);
-
- // Test the cache
- LookupTableItem item = cache.getPulldownItemByName(LookupTableType.UDF_IND_PULLDOWN_6, "Believer");
-
- // Verify result.
- EasyMock.verify(api);
- assertNull(item);
- }
-
- @Test
- public void testGetPullDownException() throws Exception {
- // Setup mocks
- EasyMock.expect(api.getLookupTable(EasyMock.anyObject())).andThrow(new IOException());
- EasyMock.expect(api.getLookupTable(EasyMock.anyObject())).andReturn(lookupTableResponse);
- EasyMock.replay(api);
-
- // Test the cache
- LookupTableItem item1 = cache.getPulldownItemByName(LookupTableType.UDF_IND_PULLDOWN_6, "Believer");
- LookupTableItem item2 = cache.getPulldownItemByName(LookupTableType.UDF_IND_PULLDOWN_6, "Believer");
-
- // Verify result.
- EasyMock.verify(api);
- assertNull(item1);
- assertNotNull(item2);
- }
-} \ No newline at end of file