summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2018-07-14 12:13:04 -0700
committerJesse Morgan <jesse@jesterpm.net>2018-07-14 12:13:04 -0700
commit808c6323049c1efff52f20d872813f86e21c5b37 (patch)
treeacf7ec4000631e5fa7d5d9a8155367070c23fffa /src/test
parent35887b81ac23a389f123df529e45fd9c49ce7459 (diff)
parent633d0cebff548b6a54ac33e464447d93e800bf12 (diff)
Merge branch 'groups-api'
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/p4square/ccbapi/CCBAPIClientTest.java65
-rw-r--r--src/test/java/com/p4square/ccbapi/model/GetGroupProfilesResponseTest.java106
-rw-r--r--src/test/resources/com/p4square/ccbapi/model/ccb_group_profile_from_id_response.xml113
3 files changed, 284 insertions, 0 deletions
diff --git a/src/test/java/com/p4square/ccbapi/CCBAPIClientTest.java b/src/test/java/com/p4square/ccbapi/CCBAPIClientTest.java
index 71427b5..9c7bbd6 100644
--- a/src/test/java/com/p4square/ccbapi/CCBAPIClientTest.java
+++ b/src/test/java/com/p4square/ccbapi/CCBAPIClientTest.java
@@ -283,6 +283,71 @@ public class CCBAPIClientTest {
// Expect exception.
}
+ @Test
+ public void testGetGroupProfilesById() throws Exception {
+ // Set expectation.
+ URI expectedURI = new URI("https://localhost:8080/api.php?srv=group_profile_from_id&id=750");
+ InputStream is = getClass().getResourceAsStream("model/ccb_group_profile_from_id_response.xml");
+ EasyMock.expect(mockHttpClient.sendPostRequest(expectedURI, null))
+ .andReturn(is);
+ EasyMock.replay(mockHttpClient);
+
+ // Test group_profile_from_id.
+ GetGroupProfilesRequest request = new GetGroupProfilesRequest().withGroupId(750);
+ GetGroupProfilesResponse response = client.getGroupProfiles(request);
+
+ // Verify results.
+ EasyMock.verify(mockHttpClient);
+ assertNull(response.getErrors());
+ assertEquals(1, response.getGroups().size());
+ assertEquals(750, response.getGroups().get(0).getId());
+ }
+
+ @Test
+ public void testGetAllGroupProfiles() throws Exception {
+ // Set expectation.
+ URI expectedURI = new URI("https://localhost:8080/api.php?srv=group_profiles");
+ InputStream is = getClass().getResourceAsStream("model/ccb_group_profile_from_id_response.xml");
+ EasyMock.expect(mockHttpClient.sendPostRequest(expectedURI, null))
+ .andReturn(is);
+ EasyMock.replay(mockHttpClient);
+
+ // Test group_profile_from_id.
+ GetGroupProfilesRequest request = new GetGroupProfilesRequest();
+ GetGroupProfilesResponse response = client.getGroupProfiles(request);
+
+ // Verify results.
+ EasyMock.verify(mockHttpClient);
+ assertNull(response.getErrors());
+ assertEquals(1, response.getGroups().size());
+ assertEquals(750, response.getGroups().get(0).getId());
+ }
+
+ @Test
+ public void testGetAllGroupProfilesWithOptions() throws Exception {
+ // Set expectation.
+ URI expectedURI = new URI("https://localhost:8080/api.php?srv=group_profiles&per_page=2&modified_since=2018-07-08&page=1&include_participants=false&include_image_link=true");
+ InputStream is = getClass().getResourceAsStream("model/ccb_group_profile_from_id_response.xml");
+ EasyMock.expect(mockHttpClient.sendPostRequest(expectedURI, null))
+ .andReturn(is);
+ EasyMock.replay(mockHttpClient);
+
+ // Test group_profile_from_id.
+ GetGroupProfilesRequest request = new GetGroupProfilesRequest()
+ .withIncludeParticipants(false)
+ .withIncludeImageUrl(true)
+ .withModifiedSince(LocalDate.parse("2018-07-08"))
+ .withPage(1)
+ .withPerPage(2);
+ GetGroupProfilesResponse response = client.getGroupProfiles(request);
+
+ // Verify results.
+ EasyMock.verify(mockHttpClient);
+ assertNull(response.getErrors());
+ assertEquals(1, response.getGroups().size());
+ assertEquals(750, response.getGroups().get(0).getId());
+ }
+
/**
* Simple extension of CCBAPIClient to swap out the HTTPInterface with a mock.
*/
diff --git a/src/test/java/com/p4square/ccbapi/model/GetGroupProfilesResponseTest.java b/src/test/java/com/p4square/ccbapi/model/GetGroupProfilesResponseTest.java
new file mode 100644
index 0000000..c62844c
--- /dev/null
+++ b/src/test/java/com/p4square/ccbapi/model/GetGroupProfilesResponseTest.java
@@ -0,0 +1,106 @@
+package com.p4square.ccbapi.model;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Tests for parsing GetGroupProfilesResponse.
+ */
+public class GetGroupProfilesResponseTest extends XmlBinderTestBase {
+
+ /**
+ * Assert that all of the fields bind appropriately for a single profile response.
+ */
+ @Test
+ public void testGetGroupProfilesResponse() throws Exception {
+ final GetGroupProfilesResponse response = parseFile("ccb_group_profile_from_id_response.xml",
+ GetGroupProfilesResponse.class);
+
+ assertNull("Response should not have errors", response.getErrors());
+ assertNotNull(response.getGroups());
+ assertEquals(1, response.getGroups().size());
+
+ final GroupProfile group = response.getGroups().get(0);
+
+ // IDs
+ assertEquals(750, group.getId());
+
+ assertEquals("Adamant by Lisa Bevere Book Study", group.getName());
+ assertTrue(group.getDescription().startsWith("What is the truth?"));
+ assertTrue(group.getImageUrl().isEmpty());
+ assertEquals("webcal://example.ccbchurch.com/group_calendar.ics?id=750&tk=764EFA883DDA1E11DB47671C4A3BBD9E",
+ group.getCalendarFeedUrl());
+
+ // Main Leader
+ assertEquals(26102, group.getMainLeader().getId());
+ assertEquals("Jane", group.getMainLeader().getFirstName());
+ assertEquals("Doe", group.getMainLeader().getLastName());
+ assertEquals("Jane Doe", group.getMainLeader().getFullName());
+ assertEquals("jane.doe@example.com", group.getMainLeader().getEmail());
+ assertEquals(Phone.Type.CONTACT, group.getMainLeader().getPhones().get(0).getType());
+ assertEquals("+12068675309", group.getMainLeader().getPhones().get(0).getNumber());
+
+ // Coach
+ assertEquals(29, group.getCoach().getId());
+ assertEquals("John", group.getCoach().getFirstName());
+ assertEquals("Doe", group.getCoach().getLastName());
+ assertEquals("John Doe", group.getCoach().getFullName());
+ assertEquals("john.doe@example.com", group.getCoach().getEmail());
+ assertEquals("", group.getCoach().getPhones().get(0).getNumber());
+
+ // Director
+ assertEquals(33082, group.getDirector().getId());
+ assertEquals("Jeff", group.getDirector().getFirstName());
+ assertEquals("Doe", group.getDirector().getLastName());
+ assertEquals("Jeff Doe", group.getDirector().getFullName());
+ assertEquals("jeff.doe@example.com", group.getDirector().getEmail());
+ assertEquals("", group.getDirector().getPhones().get(0).getNumber());
+
+ // Membership Capacity
+ assertEquals(0, group.getLeaders().size());
+ assertEquals(0, group.getParticipants().size());
+ assertEquals(1, group.getCurrentMembers());
+ assertNull(group.getGroupCapacity());
+ assertTrue(group.isGroupCapacityUnlimited());
+
+ // Address
+ assertEquals(Address.Type.MEETING, group.getAddresses().get(0).getType());
+ assertEquals("1234 Example St", group.getAddresses().get(0).getStreetAddress());
+ assertEquals("Puyallup", group.getAddresses().get(0).getCity());
+ assertEquals("WA", group.getAddresses().get(0).getState());
+ assertEquals("", group.getAddresses().get(0).getZip());
+ assertEquals("-122.000000", group.getAddresses().get(0).getLongitude());
+ assertEquals("47.000000", group.getAddresses().get(0).getLatitude());
+ assertEquals("1234 Example St", group.getAddresses().get(0).getLine_1());
+ assertEquals("Puyallup, WA", group.getAddresses().get(0).getLine_2());
+
+ // Attributes
+ assertEquals(false, group.isChildcareProvided());
+ assertEquals(true, group.isListed());
+ assertEquals(true, group.isPublicSearchListed());
+ assertEquals(true, group.isActive());
+ assertEquals(true, group.isNotification());
+ assertEquals(InteractionType.MEMBERS_INTERACT, group.getInteractionType());
+ assertEquals(MembershipType.MODERATED, group.getMembershipType());
+
+ // User Defined Fields
+ assertEquals("udf_1", group.getCustomPulldownFields().getByLabel("Gender").getName());
+ assertEquals("Gender", group.getCustomPulldownFields().getByLabel("Gender").getLabel());
+ assertEquals(2, group.getCustomPulldownFields().getByLabel("Gender").getSelection().getId());
+ assertEquals("Female only", group.getCustomPulldownFields().getByLabel("Gender").getSelection().getLabel());
+ assertEquals(false, group.getCustomPulldownFields().getByLabel("Gender").isAdminOnly());
+
+ // Reference Attributes
+ assertReferenceEquals(4, "Tuesday", group.getMeetingDay());
+ assertReferenceEquals(33, "7:00 pm", group.getMeetingTime());
+ assertReferenceEquals(4, "Community", group.getGroupType());
+ assertReferenceEquals(13, "Adults", group.getDepartment());
+ assertReferenceEquals(18, "Puyallup", group.getArea());
+ }
+
+ private void assertReferenceEquals(int id, String name, Reference ref) {
+ assertEquals(id, ref.getId());
+ assertEquals(name, ref.getName());
+ }
+} \ No newline at end of file
diff --git a/src/test/resources/com/p4square/ccbapi/model/ccb_group_profile_from_id_response.xml b/src/test/resources/com/p4square/ccbapi/model/ccb_group_profile_from_id_response.xml
new file mode 100644
index 0000000..566f656
--- /dev/null
+++ b/src/test/resources/com/p4square/ccbapi/model/ccb_group_profile_from_id_response.xml
@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ccb_api>
+ <request>
+ <parameters>
+ <argument value="group_profile_from_id" name="srv"/>
+ <argument value="750" name="id"/>
+ </parameters>
+ </request>
+ <response>
+ <service>group_profile_from_id</service>
+ <service_action>execute</service_action>
+ <availability>public</availability>
+ <groups count="1">
+ <group id="750">
+ <name>Adamant by Lisa Bevere Book Study</name>
+ <description>What is the truth?&#13;
+ &#13;
+ This has become the defining question of our time. But while everyone has an opinion, truth, it seems, is getting harder and harder to find. Perhaps that's because we are searching for something when we should be looking for someone. &#13;
+ &#13;
+ Truth has a name.&#13;
+ &#13;
+ More ancient than time and more present than this moment, the truth is not a river that changes with the cultural currents, but a rock--immovable, invincible, unshakeable--and the cornerstone of all we are and ever dream to be.&#13;
+ &#13;
+ Theologically deep yet intimately accessible. Adamant will be an anchor for your soul in a raging sea of opinions, giving you a clear sense of direction in a wandering world.&#13;
+ Every Other Tuesday Beginning in September 2018</description>
+ <image></image>
+ <campus id="1">Example Church</campus>
+ <main_leader id="26102">
+ <first_name>Jane</first_name>
+ <last_name>Doe</last_name>
+ <full_name>Jane Doe</full_name>
+ <email>jane.doe@example.com</email>
+ <phones>
+ <phone type="contact">+12068675309</phone>
+ </phones>
+ </main_leader>
+ <leaders/>
+ <coach id="29">
+ <first_name>John</first_name>
+ <last_name>Doe</last_name>
+ <full_name>John Doe</full_name>
+ <email>john.doe@example.com</email>
+ <phones type="contact">
+ <phone></phone>
+ </phones>
+ </coach>
+ <director id="33082">
+ <first_name>Jeff</first_name>
+ <last_name>Doe</last_name>
+ <full_name>Jeff Doe</full_name>
+ <email>jeff.doe@example.com</email>
+ <phones type="contact">
+ <phone></phone>
+ </phones>
+ </director>
+ <participants/>
+ <group_type id="4">Community</group_type>
+ <department id="13">Adults</department>
+ <area id="18">Puyallup</area>
+ <calendar_feed>webcal://example.ccbchurch.com/group_calendar.ics?id=750&amp;tk=764EFA883DDA1E11DB47671C4A3BBD9E</calendar_feed>
+ <registration_forms/>
+ <current_members>1</current_members>
+ <group_capacity>Unlimited</group_capacity>
+ <addresses>
+ <address type="meeting">
+ <name></name>
+ <street_address>1234 Example St</street_address>
+ <city>Puyallup</city>
+ <state>WA</state>
+ <zip></zip>
+ <longitude>-122.000000</longitude>
+ <latitude>47.000000</latitude>
+ <line_1>1234 Example St</line_1>
+ <line_2>Puyallup, WA</line_2>
+ </address>
+ </addresses>
+ <meeting_day id="4">Tuesday</meeting_day>
+ <meeting_time id="33">7:00 pm</meeting_time>
+ <childcare_provided>false</childcare_provided>
+ <interaction_type>Members Interact</interaction_type>
+ <membership_type>Invitation or Request Required</membership_type>
+ <notification>true</notification>
+ <user_defined_fields>
+ <user_defined_field>
+ <name>udf_1</name>
+ <label>Gender</label>
+ <selection id="2">Female only</selection>
+ <admin_only>false</admin_only>
+ </user_defined_field>
+ <user_defined_field>
+ <name>udf_2</name>
+ <label>Marital status</label>
+ <selection id="3">Marrieds &amp; Single</selection>
+ <admin_only>false</admin_only>
+ </user_defined_field>
+ <user_defined_field>
+ <name>udf_3</name>
+ <label>Group Category</label>
+ <selection id="1">Learning</selection>
+ <admin_only>false</admin_only>
+ </user_defined_field>
+ </user_defined_fields>
+ <listed>true</listed>
+ <public_search_listed>true</public_search_listed>
+ <inactive>false</inactive>
+ <creator id="12">Larry Cucumber</creator>
+ <modifier id="12">Larry Cucumber</modifier>
+ <created>2018-06-28 22:43:40</created>
+ <modified>2018-06-28 22:44:25</modified>
+ </group>
+ </groups>
+ </response>
+</ccb_api> \ No newline at end of file