diff options
Diffstat (limited to 'src/test/java/com/p4square/ccbapi/model')
3 files changed, 138 insertions, 0 deletions
diff --git a/src/test/java/com/p4square/ccbapi/model/GetCustomFieldLabelsResponseTest.java b/src/test/java/com/p4square/ccbapi/model/GetCustomFieldLabelsResponseTest.java new file mode 100644 index 0000000..549b8e9 --- /dev/null +++ b/src/test/java/com/p4square/ccbapi/model/GetCustomFieldLabelsResponseTest.java @@ -0,0 +1,39 @@ +package com.p4square.ccbapi.model; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Tests for parsing GetCustomFieldLabelsResponse. + */ +public class GetCustomFieldLabelsResponseTest extends XmlBinderTestBase { + + /** + * Assert that all of the fields bind appropriately in a GetCustomFieldLabelsResponse. + */ + @Test + public void testGetCustomFieldLabelsResponse() throws Exception { + final GetCustomFieldLabelsResponse response = parseFile("ccb_custom_labels_response.xml", + GetCustomFieldLabelsResponse.class); + + assertNull("Response should not have errors", response.getErrors()); + + assertNotNull(response.getCustomFields()); + assertEquals(27, response.getCustomFields().size()); + + // Check the first field. + CustomField field = response.getCustomFields().get(0); + assertEquals("udf_ind_text_1", field.getName()); + assertEquals("Favorite Movie", field.getLabel()); + assertEquals(false, field.isAdminOnly()); + + // And the second. + field = response.getCustomFields().get(1); + assertEquals("udf_ind_text_2", field.getName()); + assertEquals("Another Field", field.getLabel()); + assertEquals(true, field.isAdminOnly()); + + // And that's probably enough for now... + } +}
\ No newline at end of file diff --git a/src/test/java/com/p4square/ccbapi/model/GetIndividualProfilesResponseTest.java b/src/test/java/com/p4square/ccbapi/model/GetIndividualProfilesResponseTest.java new file mode 100644 index 0000000..743a9f7 --- /dev/null +++ b/src/test/java/com/p4square/ccbapi/model/GetIndividualProfilesResponseTest.java @@ -0,0 +1,60 @@ +package com.p4square.ccbapi.model; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Tests for parsing GetIndividualProfilesResponse. + */ +public class GetIndividualProfilesResponseTest extends XmlBinderTestBase { + + /** + * Assert that all of the fields bind appropriately for a single profile response. + */ + @Test + public void testGetIndividualProfilesResponse() throws Exception { + final GetIndividualProfilesResponse response = parseFile("ccb_individual_profile_response.xml", + GetIndividualProfilesResponse.class); + + assertNull("Response should not have errors", response.getErrors()); + assertNotNull(response.getIndividuals()); + assertEquals(1, response.getIndividuals().size()); + + final IndividualProfile profile = response.getIndividuals().get(0); + + // IDs + assertEquals(48, profile.getId()); + assertEquals(123, profile.getSyncId()); + assertEquals(456, profile.getOtherId()); + + // Family + assertEquals(36, profile.getFamily().getFamilyId()); + assertEquals("The Bob Family", profile.getFamily().getName()); + assertEquals("https://cdn3.ccbchurch.com/preSTABLE/images/group-default.gif", profile.getFamilyImageUrl()); + assertEquals(FamilyPosition.PRIMARY_CONTACT, profile.getFamilyPosition()); + assertEquals(1, profile.getFamilyMembers().size()); + + // Mrs. Bob + assertEquals(49, profile.getFamilyMembers().get(0).getIndividualReference().getIndividualId()); + assertEquals("Mrs. Bob", profile.getFamilyMembers().get(0).getIndividualReference().getName()); + assertEquals(FamilyPosition.SPOUSE, profile.getFamilyMembers().get(0).getFamilyPosition()); + + // Names + assertEquals("Mr.", profile.getSalutation()); + assertEquals("Larry", profile.getFirstName()); + assertEquals("", profile.getMiddleName()); + assertEquals("Bob", profile.getLastName()); + assertEquals("", profile.getSuffix()); + assertEquals("Larabar", profile.getLegalFirstName()); + assertEquals("Larry Bob", profile.getFullName()); + + // Other Attributes + assertEquals("https://cdn3.ccbchurch.com/preSTABLE/images/profile-default.gif", profile.getImageUrl()); + assertEquals("tsebastian@churchcommunitybuilder.com", profile.getEmail()); + assertEquals("", profile.getAllergies()); + assertEquals(true, profile.isConfirmedNoAllergies()); + assertEquals(Gender.MALE, profile.getGender()); + assertEquals("1990-04-05", profile.getBirthday().toString()); + } +}
\ No newline at end of file diff --git a/src/test/java/com/p4square/ccbapi/model/XmlBinderTestBase.java b/src/test/java/com/p4square/ccbapi/model/XmlBinderTestBase.java new file mode 100644 index 0000000..2422d39 --- /dev/null +++ b/src/test/java/com/p4square/ccbapi/model/XmlBinderTestBase.java @@ -0,0 +1,39 @@ +package com.p4square.ccbapi.model; + +import java.io.InputStream; +import com.p4square.ccbapi.CCBXmlBinder; +import org.junit.Before; + +/** + * Created by jesterpm on 3/14/16. + */ +public class XmlBinderTestBase { + + private CCBXmlBinder binder; + + @Before + public void setUp() { + binder = new CCBXmlBinder(); + } + + /** + * Helper to test the response stored in a file. + * + * @param filename The name of the xml file containing the response. + * @param clazz The class to bind to. + * @param <T> The type of the return value. + * @return The parsed response. + * @throws Exception If something fails. + */ + protected <T extends CCBAPIResponse> T parseFile(final String filename, final Class<T> clazz) throws Exception { + InputStream in = getClass().getResourceAsStream(filename); + if (in == null) { + throw new AssertionError("Could not find file " + filename); + } + try { + return binder.bindResponseXML(in, clazz); + } finally { + in.close(); + } + } +} |