diff options
| author | Jesse Morgan <jesse@jesterpm.net> | 2018-07-08 22:03:53 -0700 | 
|---|---|---|
| committer | Jesse Morgan <jesse@jesterpm.net> | 2018-07-08 22:03:53 -0700 | 
| commit | 3dac0195d484bebd1c604e175bcddd2edb994f82 (patch) | |
| tree | 825e7819e1a0a3d1edb5b90627a15a4b65c62a31 /src | |
| parent | 151f74ffa870561bbb3c857c0f07aeb4b27968f5 (diff) | |
Add unit tests for groups models
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/java/com/p4square/ccbapi/model/GroupProfile.java | 53 | ||||
| -rw-r--r-- | src/test/java/com/p4square/ccbapi/model/GetGroupProfilesResponseTest.java | 106 | 
2 files changed, 138 insertions, 21 deletions
| 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<Address> 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 | 
