From 151f74ffa870561bbb3c857c0f07aeb4b27968f5 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Sun, 8 Jul 2018 09:34:59 -0700 Subject: Add Groups Service APIs --- .../java/com/p4square/ccbapi/CCBAPIClientTest.java | 65 ++++++++++++ .../model/ccb_group_profile_from_id_response.xml | 113 +++++++++++++++++++++ 2 files changed, 178 insertions(+) create mode 100644 src/test/resources/com/p4square/ccbapi/model/ccb_group_profile_from_id_response.xml (limited to 'src/test') 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/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 @@ + + + + + + + + + + group_profile_from_id + execute + public + + + Adamant by Lisa Bevere Book Study + What is the truth? + + 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. + + Truth has a name. + + 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. + + 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. + Every Other Tuesday Beginning in September 2018 + + Example Church + + Jane + Doe + Jane Doe + jane.doe@example.com + + +12068675309 + + + + + John + Doe + John Doe + john.doe@example.com + + + + + + Jeff + Doe + Jeff Doe + jeff.doe@example.com + + + + + + Community + Adults + Puyallup + webcal://example.ccbchurch.com/group_calendar.ics?id=750&tk=764EFA883DDA1E11DB47671C4A3BBD9E + + 1 + Unlimited + +
+ + 1234 Example St + Puyallup + WA + + -122.000000 + 47.000000 + 1234 Example St + Puyallup, WA +
+
+ Tuesday + 7:00 pm + false + Members Interact + Invitation or Request Required + true + + + udf_1 + + Female only + false + + + udf_2 + + Marrieds & Single + false + + + udf_3 + + Learning + false + + + true + true + false + Larry Cucumber + Larry Cucumber + 2018-06-28 22:43:40 + 2018-06-28 22:44:25 +
+
+
+
\ No newline at end of file -- cgit v1.2.3 From 3dac0195d484bebd1c604e175bcddd2edb994f82 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Sun, 8 Jul 2018 22:03:53 -0700 Subject: Add unit tests for groups models --- .../com/p4square/ccbapi/model/GroupProfile.java | 53 +++++++---- .../ccbapi/model/GetGroupProfilesResponseTest.java | 106 +++++++++++++++++++++ 2 files changed, 138 insertions(+), 21 deletions(-) create mode 100644 src/test/java/com/p4square/ccbapi/model/GetGroupProfilesResponseTest.java (limited to 'src/test') diff --git a/src/main/java/com/p4square/ccbapi/model/GroupProfile.java b/src/main/java/com/p4square/ccbapi/model/GroupProfile.java index 6140200..cf826e6 100644 --- a/src/main/java/com/p4square/ccbapi/model/GroupProfile.java +++ b/src/main/java/com/p4square/ccbapi/model/GroupProfile.java @@ -1,7 +1,6 @@ package com.p4square.ccbapi.model; import javax.xml.bind.annotation.*; -import java.net.URL; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -23,10 +22,10 @@ public class GroupProfile { private String description; @XmlElement(name="image") - private URL imageUrl; + private String imageUrl; @XmlElement(name="calendar_feed") - private URL calendarFeedUrl; + private String calendarFeedUrl; @XmlElement(name="main_leader") private IndividualProfile mainLeader; @@ -93,10 +92,10 @@ public class GroupProfile { private Reference area; @XmlElement(name="meeting_day") - private Reference meeting_day; + private Reference meetingDay; @XmlElement(name="meeting_time") - private Reference meeting_time; + private Reference meetingTime; @XmlElement(name="creator") private IndividualReference createdBy; @@ -141,19 +140,19 @@ public class GroupProfile { this.description = description; } - public URL getImageUrl() { + public String getImageUrl() { return imageUrl; } - public void setImageUrl(URL imageUrl) { + public void setImageUrl(String imageUrl) { this.imageUrl = imageUrl; } - public URL getCalendarFeedUrl() { + public String getCalendarFeedUrl() { return calendarFeedUrl; } - public void setCalendarFeedUrl(URL calendarFeedUrl) { + public void setCalendarFeedUrl(String calendarFeedUrl) { this.calendarFeedUrl = calendarFeedUrl; } @@ -205,12 +204,24 @@ public class GroupProfile { this.currentMembers = currentMembers; } - public String getGroupCapacity() { - return groupCapacity; + public Integer getGroupCapacity() { + if (isGroupCapacityUnlimited()) { + return null; + } else { + return Integer.valueOf(this.groupCapacity); + } } - public void setGroupCapacity(String groupCapacity) { - this.groupCapacity = groupCapacity; + public boolean isGroupCapacityUnlimited() { + return this.groupCapacity == null || "Unlimited".equals(this.groupCapacity); + } + + public void setGroupCapacity(Integer groupCapacity) { + if (groupCapacity == null) { + this.groupCapacity = "Unlimited"; + } else { + this.groupCapacity = groupCapacity.toString(); + } } public List
getAddresses() { @@ -317,20 +328,20 @@ public class GroupProfile { this.area = area; } - public Reference getMeeting_day() { - return meeting_day; + public Reference getMeetingDay() { + return meetingDay; } - public void setMeeting_day(Reference meeting_day) { - this.meeting_day = meeting_day; + public void setMeetingDay(Reference meetingDay) { + this.meetingDay = meetingDay; } - public Reference getMeeting_time() { - return meeting_time; + public Reference getMeetingTime() { + return meetingTime; } - public void setMeeting_time(Reference meeting_time) { - this.meeting_time = meeting_time; + public void setMeetingTime(Reference meetingTime) { + this.meetingTime = meetingTime; } public IndividualReference getCreatedBy() { 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..b20aa09 --- /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(false, group.isInactive()); + 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 -- cgit v1.2.3 From 633d0cebff548b6a54ac33e464447d93e800bf12 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Sat, 14 Jul 2018 12:11:53 -0700 Subject: Invert GroupProfile active/inactive flag. The flag in CCB is called inactive, but I'm renaming it to active to avoid the negative. --- src/main/java/com/p4square/ccbapi/model/GroupProfile.java | 8 ++++---- .../com/p4square/ccbapi/model/GetGroupProfilesResponseTest.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/test') diff --git a/src/main/java/com/p4square/ccbapi/model/GroupProfile.java b/src/main/java/com/p4square/ccbapi/model/GroupProfile.java index cf826e6..4da03fb 100644 --- a/src/main/java/com/p4square/ccbapi/model/GroupProfile.java +++ b/src/main/java/com/p4square/ccbapi/model/GroupProfile.java @@ -256,12 +256,12 @@ public class GroupProfile { this.publicSearchListed = publicSearchListed; } - public boolean isInactive() { - return inactive; + public boolean isActive() { + return !inactive; } - public void setInactive(boolean inactive) { - this.inactive = inactive; + public void setActive(boolean active) { + this.inactive = !inactive; } public boolean isNotification() { diff --git a/src/test/java/com/p4square/ccbapi/model/GetGroupProfilesResponseTest.java b/src/test/java/com/p4square/ccbapi/model/GetGroupProfilesResponseTest.java index b20aa09..c62844c 100644 --- a/src/test/java/com/p4square/ccbapi/model/GetGroupProfilesResponseTest.java +++ b/src/test/java/com/p4square/ccbapi/model/GetGroupProfilesResponseTest.java @@ -79,7 +79,7 @@ public class GetGroupProfilesResponseTest extends XmlBinderTestBase { assertEquals(false, group.isChildcareProvided()); assertEquals(true, group.isListed()); assertEquals(true, group.isPublicSearchListed()); - assertEquals(false, group.isInactive()); + assertEquals(true, group.isActive()); assertEquals(true, group.isNotification()); assertEquals(InteractionType.MEMBERS_INTERACT, group.getInteractionType()); assertEquals(MembershipType.MODERATED, group.getMembershipType()); -- cgit v1.2.3