diff options
author | Jesse Morgan <jesse@jesterpm.net> | 2018-08-19 15:57:06 -0700 |
---|---|---|
committer | Jesse Morgan <jesse@jesterpm.net> | 2018-08-19 15:57:06 -0700 |
commit | 54a7a3184dc565fe513aa520e1344b2303ea6834 (patch) | |
tree | 5f66d23cdbec36b4e9e9935688780f216caf4da7 | |
parent | 9cbf7a7a27977e32c8e275d2bc660787b20ce345 (diff) |
-rw-r--r-- | LICENSE.md | 2 | ||||
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | src/main/java/com/p4square/ccbapi/CCBAPI.java | 8 | ||||
-rw-r--r-- | src/main/java/com/p4square/ccbapi/CCBAPIClient.java | 5 | ||||
-rw-r--r-- | src/main/java/com/p4square/ccbapi/model/Campus.java | 78 | ||||
-rw-r--r-- | src/main/java/com/p4square/ccbapi/model/GetCampusListResponse.java | 37 | ||||
-rw-r--r-- | src/test/java/com/p4square/ccbapi/CCBAPIClientTest.java | 18 | ||||
-rw-r--r-- | src/test/java/com/p4square/ccbapi/model/GetCampusListResponseTest.java | 30 | ||||
-rw-r--r-- | src/test/resources/com/p4square/ccbapi/model/ccb_campus_list_response.xml | 22 |
9 files changed, 201 insertions, 2 deletions
@@ -1,4 +1,4 @@ -Copyright (c) 2016 Jesse Morgan +Copyright (c) 2016-2018 Jesse Morgan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: @@ -17,6 +17,7 @@ Only a few services are currently supported. The client currently supports: * `update_individual` * `group_profiles` * `group_profile_from_id` +* `campus_list` * List Lookup Tables Adding new services is relatively easy. Skip down to the Contributing section @@ -97,7 +98,7 @@ CCBAPIClient is thread-safe and manages its own pool of HTTP connections. ## License -Copyright (c) 2016 Jesse Morgan +Copyright (c) 2016-2018 Jesse Morgan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/src/main/java/com/p4square/ccbapi/CCBAPI.java b/src/main/java/com/p4square/ccbapi/CCBAPI.java index 6b9ba2e..86bc8ea 100644 --- a/src/main/java/com/p4square/ccbapi/CCBAPI.java +++ b/src/main/java/com/p4square/ccbapi/CCBAPI.java @@ -29,6 +29,14 @@ public interface CCBAPI extends Closeable { GetLookupTableResponse getLookupTable(GetLookupTableRequest request) throws IOException; /** + * Retrieve the list of campuses. + * + * @return A {@link GetCampusListResponse} containing the campus ids and names. + * @throws IOException on failure. + */ + GetCampusListResponse getCampusList() throws IOException; + + /** * Retrieve one or more {@link IndividualProfile}s. * * If any of the following properties are set on the request, diff --git a/src/main/java/com/p4square/ccbapi/CCBAPIClient.java b/src/main/java/com/p4square/ccbapi/CCBAPIClient.java index a0335ba..2c75d62 100644 --- a/src/main/java/com/p4square/ccbapi/CCBAPIClient.java +++ b/src/main/java/com/p4square/ccbapi/CCBAPIClient.java @@ -151,6 +151,11 @@ public class CCBAPIClient implements CCBAPI { } @Override + public GetCampusListResponse getCampusList() throws IOException { + return makeRequest("campus_list", EMPTY_MAP, null, GetCampusListResponse.class); + } + + @Override public UpdateIndividualProfileResponse updateIndividualProfile(UpdateIndividualProfileRequest request) throws IOException { diff --git a/src/main/java/com/p4square/ccbapi/model/Campus.java b/src/main/java/com/p4square/ccbapi/model/Campus.java new file mode 100644 index 0000000..9d3288f --- /dev/null +++ b/src/main/java/com/p4square/ccbapi/model/Campus.java @@ -0,0 +1,78 @@ +package com.p4square.ccbapi.model; + +import javax.xml.bind.annotation.*; +import java.time.LocalDateTime; + +/** + * Representation of a Campus. + */ +@XmlRootElement(name="campus") +@XmlAccessorType(XmlAccessType.NONE) +public class Campus { + + @XmlAttribute(name="id") + private int id; + + @XmlElement(name="name") + private String name; + + @XmlElement(name="active") + private boolean active; + + @XmlElement(name="creator") + private IndividualReference createdBy; + + @XmlElement(name="created") + private LocalDateTime createdTime; + + @XmlElement(name="modifier") + private IndividualReference modifiedBy; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public boolean isActive() { + return active; + } + + public void setActive(boolean active) { + this.active = active; + } + + public IndividualReference getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(IndividualReference createdBy) { + this.createdBy = createdBy; + } + + public LocalDateTime getCreatedTime() { + return createdTime; + } + + public void setCreatedTime(LocalDateTime createdTime) { + this.createdTime = createdTime; + } + + public IndividualReference getModifiedBy() { + return modifiedBy; + } + + public void setModifiedBy(IndividualReference modifiedBy) { + this.modifiedBy = modifiedBy; + } +} diff --git a/src/main/java/com/p4square/ccbapi/model/GetCampusListResponse.java b/src/main/java/com/p4square/ccbapi/model/GetCampusListResponse.java new file mode 100644 index 0000000..e5cbcaa --- /dev/null +++ b/src/main/java/com/p4square/ccbapi/model/GetCampusListResponse.java @@ -0,0 +1,37 @@ +package com.p4square.ccbapi.model; + +import javax.xml.bind.annotation.*; +import java.util.ArrayList; +import java.util.List; + +/** + * A GetCampusListResponse contains a list of campuses. + */ +@XmlRootElement(name="response") +@XmlAccessorType(XmlAccessType.NONE) +public class GetCampusListResponse extends CCBAPIResponse { + + @XmlElementWrapper(name = "campuses") + @XmlElement(name="campus") + private List<Campus> campuses; + + public GetCampusListResponse() { + campuses = new ArrayList<>(); + } + + /** + * @return The list of campuses. + */ + public List<Campus> getCampuses() { + return campuses; + } + + /** + * Set the list of campuses. + * + * @param campuses The list of campuses. + */ + public void setCampuses(final List<Campus> campuses) { + this.campuses = campuses; + } +}
\ No newline at end of file diff --git a/src/test/java/com/p4square/ccbapi/CCBAPIClientTest.java b/src/test/java/com/p4square/ccbapi/CCBAPIClientTest.java index 9c7bbd6..22f9046 100644 --- a/src/test/java/com/p4square/ccbapi/CCBAPIClientTest.java +++ b/src/test/java/com/p4square/ccbapi/CCBAPIClientTest.java @@ -129,6 +129,24 @@ public class CCBAPIClientTest { assertEquals("High School Graduation", response.getItems().get(0).getName()); } + @Test + public void testGetCampusList() throws Exception { + // Set expectation. + URI expectedURI = new URI("https://localhost:8080/api.php?srv=campus_list"); + InputStream is = getClass().getResourceAsStream("model/ccb_campus_list_response.xml"); + EasyMock.expect(mockHttpClient.sendPostRequest(expectedURI, null)) + .andReturn(is); + EasyMock.replay(mockHttpClient); + + // Test significant_event_list. + GetCampusListResponse response = client.getCampusList(); + + // Verify results. + EasyMock.verify(mockHttpClient); + assertNull(response.getErrors()); + assertEquals(1, response.getCampuses().size()); + } + @Test(expected = IllegalArgumentException.class) public void testGetLookupTableListWithNullType() throws Exception { // This should throw an IllegalArgumentException. diff --git a/src/test/java/com/p4square/ccbapi/model/GetCampusListResponseTest.java b/src/test/java/com/p4square/ccbapi/model/GetCampusListResponseTest.java new file mode 100644 index 0000000..9b635db --- /dev/null +++ b/src/test/java/com/p4square/ccbapi/model/GetCampusListResponseTest.java @@ -0,0 +1,30 @@ +package com.p4square.ccbapi.model; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Tests for parsing GetCampusListResponseTest. + */ +public class GetCampusListResponseTest extends XmlBinderTestBase { + + /** + * Assert that all of the fields bind appropriately. + */ + @Test + public void testGetCampusListResponse() throws Exception { + final GetCampusListResponse response = parseFile("ccb_campus_list_response.xml", + GetCampusListResponse.class); + + assertNull("Response should not have errors", response.getErrors()); + assertNotNull(response.getCampuses()); + assertEquals(1, response.getCampuses().size()); + + final Campus campus = response.getCampuses().get(0); + + assertEquals(1, campus.getId()); + assertEquals("Sample Church", campus.getName()); + assertEquals(true, campus.isActive()); + } +}
\ No newline at end of file diff --git a/src/test/resources/com/p4square/ccbapi/model/ccb_campus_list_response.xml b/src/test/resources/com/p4square/ccbapi/model/ccb_campus_list_response.xml new file mode 100644 index 0000000..d50d00e --- /dev/null +++ b/src/test/resources/com/p4square/ccbapi/model/ccb_campus_list_response.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ccb_api> + <request> + <parameters> + <argument value="campus_list" name="srv"/> + </parameters> + </request> + <response> + <service>campus_list</service> + <service_action>execute</service_action> + <availability>public</availability> + <campuses count="1"> + <campus id="1"> + <name>Sample Church</name> + <active>1</active> + <creator id="0">System User</creator> + <modifier id="12">System User</modifier> + <created>2015-10-22 16:52:44</created> + </campus> + </campuses> + </response> +</ccb_api> |