2 * This document is a part of the source code and related artifacts
3 * for CollectionSpace, an open source collections management system
4 * for museums and related institutions:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright (c)) 2009 Regents of the University of California
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
15 * https://source.collectionspace.org/collection-space/LICENSE.txt
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 package org.collectionspace.services.client.test;
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.List;
29 import javax.ws.rs.core.MediaType;
30 import javax.ws.rs.core.Response;
32 import org.collectionspace.services.OrganizationJAXBSchema;
33 import org.collectionspace.services.client.CollectionSpaceClient;
34 import org.collectionspace.services.client.ContactClient;
35 import org.collectionspace.services.client.ContactClientUtils;
36 import org.collectionspace.services.contact.ContactsCommon;
37 import org.collectionspace.services.contact.ContactsCommonList;
38 import org.collectionspace.services.client.OrgAuthorityClient;
39 import org.collectionspace.services.client.OrgAuthorityClientUtils;
40 import org.collectionspace.services.jaxb.AbstractCommonList;
41 import org.collectionspace.services.organization.OrgauthoritiesCommon;
42 import org.collectionspace.services.organization.OrgauthoritiesCommonList;
43 import org.collectionspace.services.organization.OrganizationsCommon;
44 import org.collectionspace.services.organization.OrganizationsCommonList;
46 import org.jboss.resteasy.client.ClientResponse;
47 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
48 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
49 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
50 import org.slf4j.Logger;
51 import org.slf4j.LoggerFactory;
52 import org.testng.Assert;
53 import org.testng.annotations.AfterClass;
54 import org.testng.annotations.Test;
57 * OrgAuthorityServiceTest, carries out tests against a
58 * deployed and running OrgAuthority Service.
60 * $LastChangedRevision: 753 $
61 * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
63 public class OrgAuthorityServiceTest extends AbstractServiceTestImpl {
66 private final String CLASS_NAME = OrgAuthorityServiceTest.class.getName();
67 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
69 // Instance variables specific to this test.
70 /** The service path component. */
71 final String SERVICE_PATH_COMPONENT = "orgauthorities";
73 /** The item service path component. */
74 final String ITEM_SERVICE_PATH_COMPONENT = "items";
76 /** The contact service path component. */
77 final String CONTACT_SERVICE_PATH_COMPONENT = "contacts";
79 /** The test organization shortname. */
80 private final String TEST_ORG_SHORTNAME = "Test Org";
82 /** The test organization founding place. */
83 private final String TEST_ORG_FOUNDING_PLACE = "Anytown, USA";
85 // Hold some values for a recently created item to verify upon read.
86 private String knownResourceId = null;
87 private String knownResourceShortIdentifer = null;
88 private String knownResourceRefName = null;
89 private String knownItemResourceId = null;
90 private String knownItemResourceShortIdentifer = null;
92 /** The known contact resource id. */
93 private String knownContactResourceId = null;
95 /** The n items to create in list. */
96 private int nItemsToCreateInList = 3;
98 /** The all item resource ids created. */
99 private Map<String, String> allItemResourceIdsCreated =
100 new HashMap<String, String>();
102 /** The all contact resource ids created. */
103 private Map<String, String> allContactResourceIdsCreated =
104 new HashMap<String, String>();
106 protected void setKnownResource( String id, String shortIdentifer,
108 knownResourceId = id;
109 knownResourceShortIdentifer = shortIdentifer;
110 knownResourceRefName = refName;
113 protected void setKnownItemResource( String id, String shortIdentifer ) {
114 knownItemResourceId = id;
115 knownItemResourceShortIdentifer = shortIdentifer;
119 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
122 protected CollectionSpaceClient getClientInstance() {
123 return new OrgAuthorityClient();
127 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
130 protected AbstractCommonList getAbstractCommonList(
131 ClientResponse<AbstractCommonList> response) {
132 return response.getEntity(OrganizationsCommonList.class);
135 // ---------------------------------------------------------------
136 // CRUD tests : CREATE tests
137 // ---------------------------------------------------------------
140 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
143 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
145 public void create(String testName) throws Exception {
147 if (logger.isDebugEnabled()) {
148 logger.debug(testBanner(testName, CLASS_NAME));
150 // Perform setup, such as initializing the type of service request
151 // (e.g. CREATE, DELETE), its valid and expected status codes, and
152 // its associated HTTP method name (e.g. POST, DELETE).
155 // Submit the request to the service and store the response.
156 OrgAuthorityClient client = new OrgAuthorityClient();
157 String shortId = createIdentifier();
158 String displayName = "displayName-" + shortId;
159 String baseRefName = OrgAuthorityClientUtils.createOrgAuthRefName(shortId, null);
160 MultipartOutput multipart =
161 OrgAuthorityClientUtils.createOrgAuthorityInstance(
162 displayName, shortId, client.getCommonPartName());
165 ClientResponse<Response> res = client.create(multipart);
167 int statusCode = res.getStatus();
169 // Check the status code of the response: does it match
170 // the expected response(s)?
173 // Does it fall within the set of valid status codes?
174 // Does it exactly match the expected status code?
175 if(logger.isDebugEnabled()){
176 logger.debug(testName + ": status = " + statusCode);
178 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
179 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
180 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
182 newID = OrgAuthorityClientUtils.extractId(res);
184 res.releaseConnection();
187 // Store the ID returned from the first resource created
188 // for additional tests below.
189 if (knownResourceId == null){
190 setKnownResource( newID, shortId, baseRefName );
191 if (logger.isDebugEnabled()) {
192 logger.debug(testName + ": knownResourceId=" + knownResourceId);
195 // Store the IDs from every resource created by tests,
196 // so they can be deleted after tests have been run.
197 allResourceIdsCreated.add(newID);
203 * @param testName the test name
205 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
206 groups = {"create"}, dependsOnMethods = {"create"})
207 public void createItem(String testName) {
209 String newID = createItemInAuthority(knownResourceId, knownResourceRefName);
213 * Creates the item in authority.
215 * @param vcsid the vcsid
216 * @param authRefName the auth ref name
219 private String createItemInAuthority(String vcsid, String authRefName) {
221 final String testName = "createItemInAuthority";
222 if(logger.isDebugEnabled()){
223 logger.debug(testName + ":...");
226 // Submit the request to the service and store the response.
227 OrgAuthorityClient client = new OrgAuthorityClient();
228 String shortId = "testOrg";
229 Map<String, String> testOrgMap = new HashMap<String,String>();
230 testOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId);
231 testOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, TEST_ORG_SHORTNAME);
232 testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "The real official test organization");
233 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "May 26, 1907");
234 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, TEST_ORG_FOUNDING_PLACE);
236 Map<String, List<String>> testOrgRepeatablesMap = new HashMap<String,List<String>>();
237 List<String> testOrgContacts = new ArrayList<String>();
238 testOrgContacts.add("joe@example.org");
239 testOrgContacts.add("sally@example.org");
240 testOrgRepeatablesMap.put(OrganizationJAXBSchema.CONTACT_NAMES, testOrgContacts);
242 String newID = OrgAuthorityClientUtils.createItemInAuthority(
243 vcsid, authRefName, testOrgMap, testOrgRepeatablesMap, client);
245 // Store the ID returned from the first item resource created
246 // for additional tests below.
247 if (knownItemResourceId == null){
248 setKnownItemResource(newID, shortId);
249 if (logger.isDebugEnabled()) {
250 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
254 // Store the IDs from any item resources created
255 // by tests, along with the IDs of their parents, so these items
256 // can be deleted after all tests have been run.
257 allItemResourceIdsCreated.put(newID, vcsid);
263 * Creates the contact.
265 * @param testName the test name
267 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
268 groups = {"create"}, dependsOnMethods = {"createItem"})
269 public void createContact(String testName) {
271 String newID = createContactInItem(knownResourceId, knownItemResourceId);
275 * Creates the contact in item.
277 * @param parentcsid the parentcsid
278 * @param itemcsid the itemcsid
281 private String createContactInItem(String parentcsid, String itemcsid) {
283 final String testName = "createContactInItem";
284 if (logger.isDebugEnabled()) {
285 logger.debug(testBanner(testName, CLASS_NAME));
289 // Submit the request to the service and store the response.
290 OrgAuthorityClient client = new OrgAuthorityClient();
291 String identifier = createIdentifier();
292 MultipartOutput multipart =
293 ContactClientUtils.createContactInstance(parentcsid,
294 itemcsid, identifier, new ContactClient().getCommonPartName());
297 ClientResponse<Response> res =
298 client.createContact(parentcsid, itemcsid, multipart);
300 int statusCode = res.getStatus();
301 // Check the status code of the response: does it match
302 // the expected response(s)?
303 if(logger.isDebugEnabled()){
304 logger.debug(testName + ": status = " + statusCode);
306 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
307 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
308 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
310 newID = OrgAuthorityClientUtils.extractId(res);
312 res.releaseConnection();
315 // Store the ID returned from the first contact resource created
316 // for additional tests below.
317 if (knownContactResourceId == null){
318 knownContactResourceId = newID;
319 if (logger.isDebugEnabled()) {
320 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
324 // Store the IDs from any contact resources created
325 // by tests, along with the IDs of their parent items,
326 // so these items can be deleted after all tests have been run.
327 allContactResourceIdsCreated.put(newID, itemcsid);
334 // Placeholders until the three tests below can be uncommented.
335 // See Issue CSPACE-401.
337 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
340 public void createWithEmptyEntityBody(String testName) throws Exception {
341 //Should this really be empty?
345 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
348 public void createWithMalformedXml(String testName) throws Exception {
349 //Should this really be empty?
353 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
356 public void createWithWrongXmlSchema(String testName) throws Exception {
357 //Should this really be empty?
362 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
363 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
364 public void createWithEmptyEntityBody(String testName) throws Exception {
366 if (logger.isDebugEnabled()) {
367 logger.debug(testBanner(testName, CLASS_NAME));
370 setupCreateWithEmptyEntityBody();
372 // Submit the request to the service and store the response.
373 String method = REQUEST_TYPE.httpMethodName();
374 String url = getServiceRootURL();
375 String mediaType = MediaType.APPLICATION_XML;
376 final String entity = "";
377 int statusCode = submitRequest(method, url, mediaType, entity);
379 // Check the status code of the response: does it match
380 // the expected response(s)?
381 if(logger.isDebugEnabled()) {
382 logger.debug(testName + ": url=" + url +
383 " status=" + statusCode);
385 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
386 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
387 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
391 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
392 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
393 public void createWithMalformedXml(String testName) throws Exception {
395 if (logger.isDebugEnabled()) {
396 logger.debug(testBanner(testName, CLASS_NAME));
399 setupCreateWithMalformedXml();
401 // Submit the request to the service and store the response.
402 String method = REQUEST_TYPE.httpMethodName();
403 String url = getServiceRootURL();
404 String mediaType = MediaType.APPLICATION_XML;
405 final String entity = MALFORMED_XML_DATA; // Constant from base class.
406 int statusCode = submitRequest(method, url, mediaType, entity);
408 // Check the status code of the response: does it match
409 // the expected response(s)?
410 if(logger.isDebugEnabled()){
411 logger.debug(testName + ": url=" + url +
412 " status=" + statusCode);
414 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
415 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
416 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
420 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
421 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
422 public void createWithWrongXmlSchema(String testName) throws Exception {
424 if (logger.isDebugEnabled()) {
425 logger.debug(testBanner(testName, CLASS_NAME));
428 setupCreateWithWrongXmlSchema();
430 // Submit the request to the service and store the response.
431 String method = REQUEST_TYPE.httpMethodName();
432 String url = getServiceRootURL();
433 String mediaType = MediaType.APPLICATION_XML;
434 final String entity = WRONG_XML_SCHEMA_DATA;
435 int statusCode = submitRequest(method, url, mediaType, entity);
437 // Check the status code of the response: does it match
438 // the expected response(s)?
439 if(logger.isDebugEnabled()){
440 logger.debug(testName + ": url=" + url +
441 " status=" + statusCode);
443 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
444 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
445 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
449 // ---------------------------------------------------------------
450 // CRUD tests : CREATE LIST tests
451 // ---------------------------------------------------------------
454 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
457 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
458 groups = {"createList"}, dependsOnGroups = {"create"})
459 public void createList(String testName) throws Exception {
460 for (int i = 0; i < nItemsToCreateInList; i++) {
466 * Creates the item list.
468 * @param testName the test name
469 * @throws Exception the exception
471 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
472 groups = {"createList"}, dependsOnMethods = {"createList"})
473 public void createItemList(String testName) throws Exception {
474 // Add items to the initially-created, known parent record.
475 for (int j = 0; j < nItemsToCreateInList; j++) {
476 createItem(testName);
481 * Creates the contact list.
483 * @param testName the test name
484 * @throws Exception the exception
486 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
487 groups = {"createList"}, dependsOnMethods = {"createItemList"})
488 public void createContactList(String testName) throws Exception {
489 // Add contacts to the initially-created, known item record.
490 for (int j = 0; j < nItemsToCreateInList; j++) {
491 createContact(testName);
495 // ---------------------------------------------------------------
496 // CRUD tests : READ tests
497 // ---------------------------------------------------------------
500 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
503 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
504 groups = {"read"}, dependsOnGroups = {"create"})
505 public void read(String testName) throws Exception {
506 readInternal(testName, knownResourceId, null);
512 * @param testName the test name
513 * @throws Exception the exception
515 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
516 groups = {"read"}, dependsOnGroups = {"create"})
517 public void readByName(String testName) throws Exception {
518 readInternal(testName, null, knownResourceShortIdentifer);
521 protected void readInternal(String testName, String CSID, String shortId) {
523 if (logger.isDebugEnabled()) {
524 logger.debug(testBanner(testName, CLASS_NAME));
529 // Submit the request to the service and store the response.
530 OrgAuthorityClient client = new OrgAuthorityClient();
531 ClientResponse<MultipartInput> res = null;
533 res = client.read(CSID);
534 } else if(shortId!=null) {
535 res = client.readByName(shortId);
537 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
540 int statusCode = res.getStatus();
542 // Check the status code of the response: does it match
543 // the expected response(s)?
544 if(logger.isDebugEnabled()){
545 logger.debug(testName + ": status = " + statusCode);
547 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
548 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
549 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
550 //FIXME: remove the following try catch once Aron fixes signatures
552 MultipartInput input = (MultipartInput) res.getEntity();
553 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
554 new OrgAuthorityClient().getCommonPartName(), OrgauthoritiesCommon.class);
555 Assert.assertNotNull(orgAuthority);
556 } catch (Exception e) {
557 throw new RuntimeException(e);
560 res.releaseConnection();
567 * @param testName the test name
568 * @throws Exception the exception
570 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
571 groups = {"readItem"}, dependsOnGroups = {"read"})
572 public void readItem(String testName) throws Exception {
573 readItemInternal(testName, knownResourceId, null, knownItemResourceId, null);
577 * Read item in Named Auth.
579 * TODO Enable this if we really need this - it is a funky case, where we would have
580 * the shortId of the item, but the CSID of the parent authority!? Unlikely.
582 * @param testName the test name
583 * @throws Exception the exception
584 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
585 groups = {"readItem"}, dependsOnGroups = {"read"})
586 public void readItemInNamedAuth(String testName) throws Exception {
587 readItemInternal(testName, null, knownResourceShortIdentifer, knownItemResourceId, null);
594 * @param testName the test name
595 * @throws Exception the exception
597 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
598 groups = {"readItem"}, dependsOnGroups = {"read"})
599 public void readNamedItem(String testName) throws Exception {
600 readItemInternal(testName, knownResourceId, null, null, knownItemResourceShortIdentifer);
604 * Read Named item in Named Auth.
606 * @param testName the test name
607 * @throws Exception the exception
609 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
610 groups = {"readItem"}, dependsOnGroups = {"read"})
611 public void readNamedItemInNamedAuth(String testName) throws Exception {
612 readItemInternal(testName, null, knownResourceShortIdentifer, null, knownItemResourceShortIdentifer);
615 protected void readItemInternal(String testName,
616 String authCSID, String authShortId, String itemCSID, String itemShortId)
619 if (logger.isDebugEnabled()) {
620 logger.debug(testBanner(testName, CLASS_NAME));
625 // Submit the request to the service and store the response.
626 OrgAuthorityClient client = new OrgAuthorityClient();
627 ClientResponse<MultipartInput> res = null;
630 res = client.readItem(authCSID, itemCSID);
631 } else if(itemShortId!=null) {
632 res = client.readNamedItem(authCSID, itemShortId);
634 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
636 } else if(authShortId!=null) {
638 res = client.readItemInNamedAuthority(authShortId, itemCSID);
639 } else if(itemShortId!=null) {
640 res = client.readNamedItemInNamedAuthority(authShortId, itemShortId);
642 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
645 Assert.fail("readInternal: Internal error. One of authCSID or authShortId must be non-null");
648 int statusCode = res.getStatus();
650 // Check the status code of the response: does it match
651 // the expected response(s)?
652 if(logger.isDebugEnabled()){
653 logger.debug(testName + ": status = " + statusCode);
655 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
656 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
657 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
659 // Check whether we've received a organization.
660 MultipartInput input = (MultipartInput) res.getEntity();
661 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
662 client.getItemCommonPartName(), OrganizationsCommon.class);
663 Assert.assertNotNull(organization);
664 boolean showFull = true;
665 if(showFull && logger.isDebugEnabled()){
666 logger.debug(testName + ": returned payload:");
667 logger.debug(objectAsXmlString(organization, OrganizationsCommon.class));
670 // Check that the organization item is within the expected OrgAuthority.
671 Assert.assertEquals(organization.getInAuthority(), knownResourceId);
673 // Verify the number and contents of values in a repeatable field,
674 // as created in the instance record used for testing.
675 List<String> contactNames = organization.getContactNames().getContactName();
676 Assert.assertTrue(contactNames.size() > 0);
677 Assert.assertNotNull(contactNames.get(0));
680 res.releaseConnection();
685 * Verify item display name.
687 * @param testName the test name
688 * @throws Exception the exception
690 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
691 dependsOnMethods = {"readItem", "updateItem"})
692 public void verifyItemDisplayName(String testName) throws Exception {
694 if (logger.isDebugEnabled()) {
695 logger.debug(testBanner(testName, CLASS_NAME));
700 // Submit the request to the service and store the response.
701 OrgAuthorityClient client = new OrgAuthorityClient();
702 MultipartInput input = null;
703 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
705 int statusCode = res.getStatus();
707 // Check the status code of the response: does it match
708 // the expected response(s)?
709 if(logger.isDebugEnabled()){
710 logger.debug(testName + ": status = " + statusCode);
712 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
713 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
714 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
716 // Check whether organization has expected displayName.
717 input = res.getEntity();
719 res.releaseConnection();
722 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
723 client.getItemCommonPartName(), OrganizationsCommon.class);
724 Assert.assertNotNull(organization);
725 String displayName = organization.getDisplayName();
726 // Make sure displayName matches computed form
727 String expectedDisplayName =
728 OrgAuthorityClientUtils.prepareDefaultDisplayName(
729 TEST_ORG_SHORTNAME, TEST_ORG_FOUNDING_PLACE);
730 Assert.assertNotNull(displayName, expectedDisplayName);
732 // Update the shortName and verify the computed name is updated.
733 organization.setCsid(null);
734 organization.setDisplayNameComputed(true);
735 organization.setShortName("updated-" + TEST_ORG_SHORTNAME);
736 expectedDisplayName =
737 OrgAuthorityClientUtils.prepareDefaultDisplayName(
738 "updated-" + TEST_ORG_SHORTNAME, TEST_ORG_FOUNDING_PLACE);
740 // Submit the updated resource to the service and store the response.
741 MultipartOutput output = new MultipartOutput();
742 OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
743 commonPart.getHeaders().add("label", client.getItemCommonPartName());
744 res = client.updateItem(knownResourceId, knownItemResourceId, output);
746 int statusCode = res.getStatus();
748 // Check the status code of the response: does it match the expected response(s)?
749 if(logger.isDebugEnabled()){
750 logger.debug("updateItem: status = " + statusCode);
752 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
753 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
754 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
756 // Retrieve the updated resource and verify that its contents exist.
757 input = (MultipartInput) res.getEntity();
759 res.releaseConnection();
762 OrganizationsCommon updatedOrganization =
763 (OrganizationsCommon) extractPart(input,
764 client.getItemCommonPartName(), OrganizationsCommon.class);
765 Assert.assertNotNull(updatedOrganization);
767 // Verify that the updated resource received the correct data.
768 Assert.assertEquals(updatedOrganization.getShortName(), organization.getShortName(),
769 "Updated ShortName in Organization did not match submitted data.");
770 // Verify that the updated resource computes the right displayName.
771 Assert.assertEquals(updatedOrganization.getDisplayName(), expectedDisplayName,
772 "Updated ShortName in Organization not reflected in computed DisplayName.");
774 // Now Update the displayName, not computed and verify the computed name is overriden.
775 organization.setDisplayNameComputed(false);
776 expectedDisplayName = "TestName";
777 organization.setDisplayName(expectedDisplayName);
779 // Submit the updated resource to the service and store the response.
780 output = new MultipartOutput();
781 commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
782 commonPart.getHeaders().add("label", client.getItemCommonPartName());
783 res = client.updateItem(knownResourceId, knownItemResourceId, output);
785 int statusCode = res.getStatus();
787 // Check the status code of the response: does it match the expected response(s)?
788 if(logger.isDebugEnabled()){
789 logger.debug("updateItem: status = " + statusCode);
791 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
792 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
793 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
795 // Retrieve the updated resource and verify that its contents exist.
796 input = (MultipartInput) res.getEntity();
798 res.releaseConnection();
801 updatedOrganization =
802 (OrganizationsCommon) extractPart(input,
803 client.getItemCommonPartName(), OrganizationsCommon.class);
804 Assert.assertNotNull(updatedOrganization);
806 // Verify that the updated resource received the correct data.
807 Assert.assertEquals(updatedOrganization.isDisplayNameComputed(), false,
808 "Updated displayNameComputed in Organization did not match submitted data.");
809 // Verify that the updated resource computes the right displayName.
810 Assert.assertEquals(updatedOrganization.getDisplayName(),
812 "Updated DisplayName (not computed) in Organization not stored.");
816 * Verify illegal item display name.
818 * @param testName the test name
819 * @throws Exception the exception
821 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
822 dependsOnMethods = {"verifyItemDisplayName"})
823 public void verifyIllegalItemDisplayName(String testName) throws Exception {
825 if (logger.isDebugEnabled()) {
826 logger.debug(testBanner(testName, CLASS_NAME));
829 testSetup(STATUS_BAD_REQUEST, ServiceRequestType.UPDATE);
830 // setupUpdateWithWrongXmlSchema(testName, logger);
832 // Submit the request to the service and store the response.
833 OrgAuthorityClient client = new OrgAuthorityClient();
834 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
836 int statusCode = res.getStatus();
838 // Check the status code of the response: does it match
839 // the expected response(s)?
840 if(logger.isDebugEnabled()){
841 logger.debug(testName + ": status = " + statusCode);
843 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
844 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
845 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
847 // Check whether organization has expected displayName.
848 MultipartInput input = (MultipartInput) res.getEntity();
849 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
850 client.getItemCommonPartName(), OrganizationsCommon.class);
851 Assert.assertNotNull(organization);
852 // Try to Update with computed false and no displayName
853 organization.setDisplayNameComputed(false);
854 organization.setDisplayName(null);
856 // Submit the updated resource to the service and store the response.
857 MultipartOutput output = new MultipartOutput();
858 OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
859 commonPart.getHeaders().add("label", client.getItemCommonPartName());
860 res.releaseConnection();
861 res = client.updateItem(knownResourceId, knownItemResourceId, output);
862 statusCode = res.getStatus();
864 // Check the status code of the response: does it match the expected response(s)?
865 if(logger.isDebugEnabled()){
866 logger.debug("updateItem: status = " + statusCode);
868 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
869 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
870 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
872 res.releaseConnection();
879 * @param testName the test name
880 * @throws Exception the exception
882 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
883 groups = {"readItem"}, dependsOnMethods = {"readItem"})
884 public void readContact(String testName) throws Exception {
886 if (logger.isDebugEnabled()) {
887 logger.debug(testBanner(testName, CLASS_NAME));
892 // Submit the request to the service and store the response.
893 OrgAuthorityClient client = new OrgAuthorityClient();
894 ClientResponse<MultipartInput> res =
895 client.readContact(knownResourceId, knownItemResourceId,
896 knownContactResourceId);
898 int statusCode = res.getStatus();
900 // Check the status code of the response: does it match
901 // the expected response(s)?
902 if(logger.isDebugEnabled()){
903 logger.debug(testName + ": status = " + statusCode);
905 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
906 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
907 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
909 // Check whether we've received a contact.
910 MultipartInput input = (MultipartInput) res.getEntity();
911 ContactsCommon contact = (ContactsCommon) extractPart(input,
912 new ContactClient().getCommonPartName(), ContactsCommon.class);
913 Assert.assertNotNull(contact);
914 boolean showFull = true;
915 if(showFull && logger.isDebugEnabled()){
916 logger.debug(testName + ": returned payload:");
917 logger.debug(objectAsXmlString(contact, ContactsCommon.class));
919 Assert.assertEquals(contact.getInAuthority(), knownResourceId);
920 Assert.assertEquals(contact.getInItem(), knownItemResourceId);
922 res.releaseConnection();
928 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
931 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
932 groups = {"read"}, dependsOnMethods = {"read"})
933 public void readNonExistent(String testName) {
935 if (logger.isDebugEnabled()) {
936 logger.debug(testBanner(testName, CLASS_NAME));
939 setupReadNonExistent();
941 // Submit the request to the service and store the response.
942 OrgAuthorityClient client = new OrgAuthorityClient();
943 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
945 int statusCode = res.getStatus();
947 // Check the status code of the response: does it match
948 // the expected response(s)?
949 if(logger.isDebugEnabled()){
950 logger.debug(testName + ": status = " + statusCode);
952 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
953 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
954 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
956 res.releaseConnection();
961 * Read item non existent.
963 * @param testName the test name
965 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
966 groups = {"readItem"}, dependsOnMethods = {"readItem"})
967 public void readItemNonExistent(String testName) {
969 if (logger.isDebugEnabled()) {
970 logger.debug(testBanner(testName, CLASS_NAME));
973 setupReadNonExistent();
975 // Submit the request to the service and store the response.
976 OrgAuthorityClient client = new OrgAuthorityClient();
977 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
979 int statusCode = res.getStatus();
981 // Check the status code of the response: does it match
982 // the expected response(s)?
983 if(logger.isDebugEnabled()){
984 logger.debug(testName + ": status = " + statusCode);
986 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
987 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
988 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
990 res.releaseConnection();
995 * Read contact non existent.
997 * @param testName the test name
999 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1000 groups = {"readItem"}, dependsOnMethods = {"readContact"})
1001 public void readContactNonExistent(String testName) {
1003 if (logger.isDebugEnabled()) {
1004 logger.debug(testBanner(testName, CLASS_NAME));
1007 setupReadNonExistent();
1009 // Submit the request to the service and store the response.
1010 OrgAuthorityClient client = new OrgAuthorityClient();
1011 ClientResponse<MultipartInput> res =
1012 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1014 int statusCode = res.getStatus();
1016 // Check the status code of the response: does it match
1017 // the expected response(s)?
1018 if(logger.isDebugEnabled()){
1019 logger.debug(testName + ": status = " + statusCode);
1021 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1022 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1023 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1025 res.releaseConnection();
1029 // ---------------------------------------------------------------
1030 // CRUD tests : READ_LIST tests
1031 // ---------------------------------------------------------------
1035 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
1038 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1039 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
1040 public void readList(String testName) throws Exception {
1042 if (logger.isDebugEnabled()) {
1043 logger.debug(testBanner(testName, CLASS_NAME));
1048 // Submit the request to the service and store the response.
1049 OrgAuthorityClient client = new OrgAuthorityClient();
1050 ClientResponse<OrgauthoritiesCommonList> res = client.readList();
1052 OrgauthoritiesCommonList list = res.getEntity();
1053 int statusCode = res.getStatus();
1055 // Check the status code of the response: does it match
1056 // the expected response(s)?
1057 if(logger.isDebugEnabled()){
1058 logger.debug(testName + ": status = " + statusCode);
1060 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1061 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1062 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1064 // Optionally output additional data about list members for debugging.
1065 boolean iterateThroughList = false;
1066 if (iterateThroughList && logger.isDebugEnabled()) {
1067 List<OrgauthoritiesCommonList.OrgauthorityListItem> items =
1068 list.getOrgauthorityListItem();
1070 for (OrgauthoritiesCommonList.OrgauthorityListItem item : items) {
1071 String csid = item.getCsid();
1072 logger.debug(testName + ": list-item[" + i + "] csid=" +
1074 logger.debug(testName + ": list-item[" + i + "] displayName=" +
1075 item.getDisplayName());
1076 logger.debug(testName + ": list-item[" + i + "] URI=" +
1078 readItemList(csid, null);
1083 res.releaseConnection();
1090 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
1091 public void readItemList() {
1092 readItemList(knownResourceId, null);
1096 * Read item list by authority name.
1098 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1099 public void readItemListByAuthorityName() {
1100 readItemList(null, knownResourceShortIdentifer);
1106 * @param vcsid the vcsid
1107 * @param name the name
1109 private void readItemList(String vcsid, String name) {
1111 final String testName = "readItemList";
1113 if (logger.isDebugEnabled()) {
1114 logger.debug(testBanner(testName, CLASS_NAME));
1119 // Submit the request to the service and store the response.
1120 OrgAuthorityClient client = new OrgAuthorityClient();
1121 ClientResponse<OrganizationsCommonList> res = null;
1123 res = client.readItemList(vcsid, null, null);
1124 } else if(name!= null) {
1125 res = client.readItemListForNamedAuthority(name, null, null);
1127 Assert.fail("readItemList passed null csid and name!");
1130 OrganizationsCommonList list = res.getEntity();
1131 int statusCode = res.getStatus();
1133 // Check the status code of the response: does it match
1134 // the expected response(s)?
1135 if(logger.isDebugEnabled()){
1136 logger.debug(testName + ": status = " + statusCode);
1138 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1139 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1140 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1142 List<OrganizationsCommonList.OrganizationListItem> items =
1143 list.getOrganizationListItem();
1144 int nItemsReturned = items.size();
1145 // There will be one item created, associated with a
1146 // known parent resource, by the createItem test.
1148 // In addition, there will be 'nItemsToCreateInList'
1149 // additional items created by the createItemList test,
1150 // all associated with the same parent resource.
1151 int nExpectedItems = nItemsToCreateInList + 1;
1152 if(logger.isDebugEnabled()){
1153 logger.debug(testName + ": Expected "
1154 + nExpectedItems +" items; got: "+nItemsReturned);
1156 Assert.assertEquals(nItemsReturned, nExpectedItems);
1159 for (OrganizationsCommonList.OrganizationListItem item : items) {
1160 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
1161 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
1162 // Optionally output additional data about list members for debugging.
1163 boolean showDetails = true;
1164 if (showDetails && logger.isDebugEnabled()) {
1165 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1167 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
1169 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
1170 item.getDisplayName());
1171 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1177 res.releaseConnection();
1182 * Read contact list.
1184 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1185 public void readContactList() {
1186 readContactList(knownResourceId, knownItemResourceId);
1190 * Read contact list.
1192 * @param parentcsid the parentcsid
1193 * @param itemcsid the itemcsid
1195 private void readContactList(String parentcsid, String itemcsid) {
1196 final String testName = "readContactList";
1198 if (logger.isDebugEnabled()) {
1199 logger.debug(testBanner(testName, CLASS_NAME));
1204 // Submit the request to the service and store the response.
1205 OrgAuthorityClient client = new OrgAuthorityClient();
1206 ContactsCommonList list = null;
1207 ClientResponse<ContactsCommonList> res =
1208 client.readContactList(parentcsid, itemcsid);
1210 list = res.getEntity();
1211 int statusCode = res.getStatus();
1213 // Check the status code of the response: does it match
1214 // the expected response(s)?
1215 if(logger.isDebugEnabled()){
1216 logger.debug(testName + ": status = " + statusCode);
1218 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1219 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1220 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1222 List<ContactsCommonList.ContactListItem> listitems =
1223 list.getContactListItem();
1224 int nItemsReturned = listitems.size();
1225 // There will be one item created, associated with a
1226 // known parent resource, by the createItem test.
1228 // In addition, there will be 'nItemsToCreateInList'
1229 // additional items created by the createItemList test,
1230 // all associated with the same parent resource.
1231 int nExpectedItems = nItemsToCreateInList + 1;
1232 if(logger.isDebugEnabled()){
1233 logger.debug(testName + ": Expected "
1234 + nExpectedItems +" items; got: "+nItemsReturned);
1236 Assert.assertEquals(nItemsReturned, nExpectedItems);
1239 for (ContactsCommonList.ContactListItem listitem : listitems) {
1240 // Optionally output additional data about list members for debugging.
1241 boolean showDetails = false;
1242 if (showDetails && logger.isDebugEnabled()) {
1243 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1244 listitem.getCsid());
1245 logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" +
1246 listitem.getAddressPlace());
1247 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1253 res.releaseConnection();
1260 // ---------------------------------------------------------------
1261 // CRUD tests : UPDATE tests
1262 // ---------------------------------------------------------------
1265 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
1268 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1269 groups = {"update"}, dependsOnGroups = {"read", "readList"})
1270 public void update(String testName) throws Exception {
1272 if (logger.isDebugEnabled()) {
1273 logger.debug(testBanner(testName, CLASS_NAME));
1278 // Retrieve the contents of a resource to update.
1279 OrgAuthorityClient client = new OrgAuthorityClient();
1280 ClientResponse<MultipartInput> res =
1281 client.read(knownResourceId);
1283 if(logger.isDebugEnabled()){
1284 logger.debug(testName + ": read status = " + res.getStatus());
1286 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1288 if(logger.isDebugEnabled()){
1289 logger.debug("got OrgAuthority to update with ID: " + knownResourceId);
1291 MultipartInput input = (MultipartInput) res.getEntity();
1292 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
1293 client.getCommonPartName(), OrgauthoritiesCommon.class);
1294 Assert.assertNotNull(orgAuthority);
1296 // Update the contents of this resource.
1297 orgAuthority.setDisplayName("updated-" + orgAuthority.getDisplayName());
1298 orgAuthority.setVocabType("updated-" + orgAuthority.getVocabType());
1299 if(logger.isDebugEnabled()){
1300 logger.debug("to be updated OrgAuthority");
1301 logger.debug(objectAsXmlString(orgAuthority, OrgauthoritiesCommon.class));
1304 // Submit the updated resource to the service and store the response.
1305 MultipartOutput output = new MultipartOutput();
1306 OutputPart commonPart = output.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE);
1307 commonPart.getHeaders().add("label", client.getCommonPartName());
1308 res.releaseConnection();
1309 res = client.update(knownResourceId, output);
1310 int statusCode = res.getStatus();
1312 // Check the status code of the response: does it match the expected response(s)?
1313 if(logger.isDebugEnabled()){
1314 logger.debug(testName + ": status = " + statusCode);
1316 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1317 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1318 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1320 // Retrieve the updated resource and verify that its contents exist.
1321 input = (MultipartInput) res.getEntity();
1322 OrgauthoritiesCommon updatedOrgAuthority =
1323 (OrgauthoritiesCommon) extractPart(input,
1324 client.getCommonPartName(), OrgauthoritiesCommon.class);
1325 Assert.assertNotNull(updatedOrgAuthority);
1327 // Verify that the updated resource received the correct data.
1328 Assert.assertEquals(updatedOrgAuthority.getDisplayName(),
1329 orgAuthority.getDisplayName(),
1330 "Data in updated object did not match submitted data.");
1332 res.releaseConnection();
1339 * @param testName the test name
1340 * @throws Exception the exception
1342 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1343 groups = {"update"}, dependsOnMethods = {"update"})
1344 public void updateItem(String testName) throws Exception {
1346 if (logger.isDebugEnabled()) {
1347 logger.debug(testBanner(testName, CLASS_NAME));
1352 // Retrieve the contents of a resource to update.
1353 OrgAuthorityClient client = new OrgAuthorityClient();
1354 ClientResponse<MultipartInput> res =
1355 client.readItem(knownResourceId, knownItemResourceId);
1357 if(logger.isDebugEnabled()){
1358 logger.debug(testName + ": read status = " + res.getStatus());
1360 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1362 if(logger.isDebugEnabled()){
1363 logger.debug("got Organization to update with ID: " +
1364 knownItemResourceId +
1365 " in OrgAuthority: " + knownResourceId );
1367 MultipartInput input = (MultipartInput) res.getEntity();
1368 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
1369 client.getItemCommonPartName(), OrganizationsCommon.class);
1370 Assert.assertNotNull(organization);
1372 // Update the contents of this resource.
1373 organization.setCsid(null);
1374 organization.setShortName("updated-" + organization.getShortName());
1375 if(logger.isDebugEnabled()){
1376 logger.debug("to be updated Organization");
1377 logger.debug(objectAsXmlString(organization,
1378 OrganizationsCommon.class));
1381 // Submit the updated resource to the service and store the response.
1382 MultipartOutput output = new MultipartOutput();
1383 OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
1384 commonPart.getHeaders().add("label", client.getItemCommonPartName());
1385 res.releaseConnection();
1386 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1387 int statusCode = res.getStatus();
1389 // Check the status code of the response: does it match the expected response(s)?
1390 if(logger.isDebugEnabled()){
1391 logger.debug(testName + ": status = " + statusCode);
1393 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1394 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1395 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1397 // Retrieve the updated resource and verify that its contents exist.
1398 input = (MultipartInput) res.getEntity();
1399 OrganizationsCommon updatedOrganization =
1400 (OrganizationsCommon) extractPart(input,
1401 client.getItemCommonPartName(), OrganizationsCommon.class);
1402 Assert.assertNotNull(updatedOrganization);
1404 // Verify that the updated resource received the correct data.
1405 Assert.assertEquals(updatedOrganization.getShortName(),
1406 organization.getShortName(),
1407 "Data in updated Organization did not match submitted data.");
1409 res.releaseConnection();
1416 * @param testName the test name
1417 * @throws Exception the exception
1419 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1420 groups = {"update"}, dependsOnMethods = {"updateItem"})
1421 public void updateContact(String testName) throws Exception {
1423 if (logger.isDebugEnabled()) {
1424 logger.debug(testBanner(testName, CLASS_NAME));
1429 // Retrieve the contents of a resource to update.
1430 OrgAuthorityClient client = new OrgAuthorityClient();
1431 ClientResponse<MultipartInput> res =
1432 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1434 if(logger.isDebugEnabled()){
1435 logger.debug(testName + ": read status = " + res.getStatus());
1437 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1439 if(logger.isDebugEnabled()){
1440 logger.debug("got Contact to update with ID: " +
1441 knownContactResourceId +
1442 " in item: " + knownItemResourceId +
1443 " in parent: " + knownResourceId );
1445 MultipartInput input = (MultipartInput) res.getEntity();
1446 ContactsCommon contact = (ContactsCommon) extractPart(input,
1447 new ContactClient().getCommonPartName(), ContactsCommon.class);
1448 Assert.assertNotNull(contact);
1450 // Update the contents of this resource.
1451 contact.setAddressPlace("updated-" + contact.getAddressPlace());
1452 if(logger.isDebugEnabled()){
1453 logger.debug("to be updated Contact");
1454 logger.debug(objectAsXmlString(contact,
1455 ContactsCommon.class));
1458 // Submit the updated resource to the service and store the response.
1459 MultipartOutput output = new MultipartOutput();
1460 OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1461 commonPart.getHeaders().add("label", new ContactClient().getCommonPartName());
1462 res.releaseConnection();
1463 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1464 int statusCode = res.getStatus();
1466 // Check the status code of the response: does it match the expected response(s)?
1467 if(logger.isDebugEnabled()){
1468 logger.debug(testName + ": status = " + statusCode);
1470 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1471 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1472 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1474 // Retrieve the updated resource and verify that its contents exist.
1475 input = (MultipartInput) res.getEntity();
1476 ContactsCommon updatedContact =
1477 (ContactsCommon) extractPart(input,
1478 new ContactClient().getCommonPartName(), ContactsCommon.class);
1479 Assert.assertNotNull(updatedContact);
1481 // Verify that the updated resource received the correct data.
1482 Assert.assertEquals(updatedContact.getAddressPlace(),
1483 contact.getAddressPlace(),
1484 "Data in updated Contact did not match submitted data.");
1486 res.releaseConnection();
1491 // Placeholders until the three tests below can be uncommented.
1492 // See Issue CSPACE-401.
1494 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1497 public void updateWithEmptyEntityBody(String testName) throws Exception {
1498 //Should this really be empty?
1502 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1505 public void updateWithMalformedXml(String testName) throws Exception {
1506 //Should this really be empty?
1510 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1513 public void updateWithWrongXmlSchema(String testName) throws Exception {
1514 //Should this really be empty?
1519 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1520 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1521 public void updateWithEmptyEntityBody(String testName) throws Exception {
1523 if (logger.isDebugEnabled()) {
1524 logger.debug(testBanner(testName, CLASS_NAME));
1527 setupUpdateWithEmptyEntityBody();
1529 // Submit the request to the service and store the response.
1530 String method = REQUEST_TYPE.httpMethodName();
1531 String url = getResourceURL(knownResourceId);
1532 String mediaType = MediaType.APPLICATION_XML;
1533 final String entity = "";
1534 int statusCode = submitRequest(method, url, mediaType, entity);
1536 // Check the status code of the response: does it match
1537 // the expected response(s)?
1538 if(logger.isDebugEnabled()){
1539 logger.debug(testName + ": url=" + url +
1540 " status=" + statusCode);
1542 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1543 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1544 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1548 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1549 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1550 public void updateWithMalformedXml(String testName) throws Exception {
1552 if (logger.isDebugEnabled()) {
1553 logger.debug(testBanner(testName, CLASS_NAME));
1556 setupUpdateWithMalformedXml();
1558 // Submit the request to the service and store the response.
1559 String method = REQUEST_TYPE.httpMethodName();
1560 String url = getResourceURL(knownResourceId);
1561 String mediaType = MediaType.APPLICATION_XML;
1562 final String entity = MALFORMED_XML_DATA;
1563 int statusCode = submitRequest(method, url, mediaType, entity);
1565 // Check the status code of the response: does it match
1566 // the expected response(s)?
1567 if(logger.isDebugEnabled()){
1568 logger.debug(testName + ": url=" + url +
1569 " status=" + statusCode);
1571 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1572 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1573 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1577 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1578 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1579 public void updateWithWrongXmlSchema(String testName) throws Exception {
1582 setupUpdateWithWrongXmlSchema(testName, logger);
1584 // Submit the request to the service and store the response.
1585 String method = REQUEST_TYPE.httpMethodName();
1586 String url = getResourceURL(knownResourceId);
1587 String mediaType = MediaType.APPLICATION_XML;
1588 final String entity = WRONG_XML_SCHEMA_DATA;
1589 int statusCode = submitRequest(method, url, mediaType, entity);
1591 // Check the status code of the response: does it match
1592 // the expected response(s)?
1593 if(logger.isDebugEnabled()){
1594 logger.debug("updateWithWrongXmlSchema: url=" + url +
1595 " status=" + statusCode);
1597 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1598 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1599 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1604 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1607 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1608 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1609 public void updateNonExistent(String testName) throws Exception {
1611 if (logger.isDebugEnabled()) {
1612 logger.debug(testBanner(testName, CLASS_NAME));
1615 setupUpdateNonExistent();
1617 // Submit the request to the service and store the response.
1618 // Note: The ID used in this 'create' call may be arbitrary.
1619 // The only relevant ID may be the one used in update(), below.
1620 OrgAuthorityClient client = new OrgAuthorityClient();
1621 MultipartOutput multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance(
1622 NON_EXISTENT_ID, NON_EXISTENT_ID,
1623 new OrgAuthorityClient().getCommonPartName());
1624 ClientResponse<MultipartInput> res =
1625 client.update(NON_EXISTENT_ID, multipart);
1627 int statusCode = res.getStatus();
1629 // Check the status code of the response: does it match
1630 // the expected response(s)?
1631 if(logger.isDebugEnabled()){
1632 logger.debug(testName + ": status = " + statusCode);
1634 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1635 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1636 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1638 res.releaseConnection();
1643 * Update non existent item.
1645 * @param testName the test name
1646 * @throws Exception the exception
1648 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1649 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1650 public void updateNonExistentItem(String testName) throws Exception {
1652 if (logger.isDebugEnabled()) {
1653 logger.debug(testBanner(testName, CLASS_NAME));
1656 setupUpdateNonExistent();
1658 // Submit the request to the service and store the response.
1659 // Note: The ID(s) used when creating the request payload may be arbitrary.
1660 // The only relevant ID may be the one used in update(), below.
1661 OrgAuthorityClient client = new OrgAuthorityClient();
1662 Map<String, String> nonexOrgMap = new HashMap<String,String>();
1663 nonexOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, "nonExistent");
1664 nonexOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Non-existent");
1665 MultipartOutput multipart =
1666 OrgAuthorityClientUtils.createOrganizationInstance(
1667 NON_EXISTENT_ID, knownResourceRefName,
1668 nonexOrgMap, client.getItemCommonPartName() );
1669 ClientResponse<MultipartInput> res =
1670 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1672 int statusCode = res.getStatus();
1674 // Check the status code of the response: does it match
1675 // the expected response(s)?
1676 if(logger.isDebugEnabled()){
1677 logger.debug(testName + ": status = " + statusCode);
1679 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1680 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1681 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1683 res.releaseConnection();
1688 * Update non existent contact.
1690 * @param testName the test name
1691 * @throws Exception the exception
1693 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1694 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1695 public void updateNonExistentContact(String testName) throws Exception {
1696 // Currently a no-op test
1699 // ---------------------------------------------------------------
1700 // CRUD tests : DELETE tests
1701 // ---------------------------------------------------------------
1704 // Note: delete sub-resources in ascending hierarchical order,
1705 // before deleting their parents.
1710 * @param testName the test name
1711 * @throws Exception the exception
1713 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1714 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1715 public void deleteContact(String testName) throws Exception {
1717 if (logger.isDebugEnabled()) {
1718 logger.debug(testBanner(testName, CLASS_NAME));
1723 if(logger.isDebugEnabled()){
1724 logger.debug("parentcsid =" + knownResourceId +
1725 " itemcsid = " + knownItemResourceId +
1726 " csid = " + knownContactResourceId);
1729 // Submit the request to the service and store the response.
1730 OrgAuthorityClient client = new OrgAuthorityClient();
1731 ClientResponse<Response> res =
1732 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1734 int statusCode = res.getStatus();
1736 // Check the status code of the response: does it match
1737 // the expected response(s)?
1738 if(logger.isDebugEnabled()){
1739 logger.debug(testName + ": status = " + statusCode);
1741 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1742 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1743 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1745 res.releaseConnection();
1752 * @param testName the test name
1753 * @throws Exception the exception
1755 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1756 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1757 public void deleteItem(String testName) throws Exception {
1759 if (logger.isDebugEnabled()) {
1760 logger.debug(testBanner(testName, CLASS_NAME));
1765 if(logger.isDebugEnabled()){
1766 logger.debug("parentcsid =" + knownResourceId +
1767 " itemcsid = " + knownItemResourceId);
1770 // Submit the request to the service and store the response.
1771 OrgAuthorityClient client = new OrgAuthorityClient();
1772 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1774 int statusCode = res.getStatus();
1776 // Check the status code of the response: does it match
1777 // the expected response(s)?
1778 if(logger.isDebugEnabled()){
1779 logger.debug(testName + ": status = " + statusCode);
1781 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1782 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1783 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1785 res.releaseConnection();
1790 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1793 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1794 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1795 public void delete(String testName) throws Exception {
1797 if (logger.isDebugEnabled()) {
1798 logger.debug(testBanner(testName, CLASS_NAME));
1803 if(logger.isDebugEnabled()){
1804 logger.debug("parentcsid =" + knownResourceId);
1807 // Submit the request to the service and store the response.
1808 OrgAuthorityClient client = new OrgAuthorityClient();
1809 ClientResponse<Response> res = client.delete(knownResourceId);
1811 int statusCode = res.getStatus();
1813 // Check the status code of the response: does it match
1814 // the expected response(s)?
1815 if(logger.isDebugEnabled()){
1816 logger.debug(testName + ": status = " + statusCode);
1818 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1819 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1820 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1822 res.releaseConnection();
1828 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1831 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1832 groups = {"delete"}, dependsOnMethods = {"delete"})
1833 public void deleteNonExistent(String testName) throws Exception {
1835 if (logger.isDebugEnabled()) {
1836 logger.debug(testBanner(testName, CLASS_NAME));
1839 setupDeleteNonExistent();
1841 // Submit the request to the service and store the response.
1842 OrgAuthorityClient client = new OrgAuthorityClient();
1843 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1845 int statusCode = res.getStatus();
1847 // Check the status code of the response: does it match
1848 // the expected response(s)?
1849 if(logger.isDebugEnabled()){
1850 logger.debug(testName + ": status = " + statusCode);
1852 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1853 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1854 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1856 res.releaseConnection();
1861 * Delete non existent item.
1863 * @param testName the test name
1865 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1866 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1867 public void deleteNonExistentItem(String testName) {
1869 if (logger.isDebugEnabled()) {
1870 logger.debug(testBanner(testName, CLASS_NAME));
1873 setupDeleteNonExistent();
1875 // Submit the request to the service and store the response.
1876 OrgAuthorityClient client = new OrgAuthorityClient();
1877 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1879 int statusCode = res.getStatus();
1881 // Check the status code of the response: does it match
1882 // the expected response(s)?
1883 if(logger.isDebugEnabled()){
1884 logger.debug(testName + ": status = " + statusCode);
1886 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1887 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1888 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1890 res.releaseConnection();
1895 * Delete non existent contact.
1897 * @param testName the test name
1899 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1900 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1901 public void deleteNonExistentContact(String testName) {
1903 if (logger.isDebugEnabled()) {
1904 logger.debug(testBanner(testName, CLASS_NAME));
1907 setupDeleteNonExistent();
1909 // Submit the request to the service and store the response.
1910 OrgAuthorityClient client = new OrgAuthorityClient();
1911 ClientResponse<Response> res =
1912 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1914 int statusCode = res.getStatus();
1916 // Check the status code of the response: does it match
1917 // the expected response(s)?
1918 if(logger.isDebugEnabled()){
1919 logger.debug(testName + ": status = " + statusCode);
1921 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1922 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1923 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1925 res.releaseConnection();
1929 // ---------------------------------------------------------------
1930 // Utility tests : tests of code used in tests above
1931 // ---------------------------------------------------------------
1933 * Tests the code for manually submitting data that is used by several
1934 * of the methods above.
1936 @Test(dependsOnMethods = {"create", "read"})
1937 public void testSubmitRequest() {
1939 // Expected status code: 200 OK
1940 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1942 // Submit the request to the service and store the response.
1943 String method = ServiceRequestType.READ.httpMethodName();
1944 String url = getResourceURL(knownResourceId);
1945 int statusCode = submitRequest(method, url);
1947 // Check the status code of the response: does it match
1948 // the expected response(s)?
1949 if(logger.isDebugEnabled()){
1950 logger.debug("testSubmitRequest: url=" + url +
1951 " status=" + statusCode);
1953 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1958 * Test item submit request.
1960 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1961 public void testItemSubmitRequest() {
1963 // Expected status code: 200 OK
1964 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1966 // Submit the request to the service and store the response.
1967 String method = ServiceRequestType.READ.httpMethodName();
1968 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1969 int statusCode = submitRequest(method, url);
1971 // Check the status code of the response: does it match
1972 // the expected response(s)?
1973 if(logger.isDebugEnabled()){
1974 logger.debug("testItemSubmitRequest: url=" + url +
1975 " status=" + statusCode);
1977 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1982 * Test contact submit request.
1984 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
1985 public void testContactSubmitRequest() {
1987 // Expected status code: 200 OK
1988 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1990 // Submit the request to the service and store the response.
1991 String method = ServiceRequestType.READ.httpMethodName();
1992 String url = getContactResourceURL(knownResourceId,
1993 knownItemResourceId, knownContactResourceId);
1994 int statusCode = submitRequest(method, url);
1996 // Check the status code of the response: does it match
1997 // the expected response(s)?
1998 if(logger.isDebugEnabled()){
1999 logger.debug("testItemSubmitRequest: url=" + url +
2000 " status=" + statusCode);
2002 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2007 // ---------------------------------------------------------------
2008 // Cleanup of resources created during testing
2009 // ---------------------------------------------------------------
2012 * Deletes all resources created by tests, after all tests have been run.
2014 * This cleanup method will always be run, even if one or more tests fail.
2015 * For this reason, it attempts to remove all resources created
2016 * at any point during testing, even if some of those resources
2017 * may be expected to be deleted by certain tests.
2020 @AfterClass(alwaysRun=true)
2022 public void cleanUp() {
2023 String noTest = System.getProperty("noTestCleanup");
2024 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
2025 if (logger.isDebugEnabled()) {
2026 logger.debug("Skipping Cleanup phase ...");
2030 if (logger.isDebugEnabled()) {
2031 logger.debug("Cleaning up temporary resources created for testing ...");
2034 String parentResourceId;
2035 String itemResourceId;
2036 String contactResourceId;
2037 // Clean up contact resources.
2038 parentResourceId = knownResourceId;
2039 OrgAuthorityClient client = new OrgAuthorityClient();
2040 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
2041 contactResourceId = entry.getKey();
2042 itemResourceId = entry.getValue();
2043 // Note: Any non-success responses from the delete operation
2044 // below are ignored and not reported.
2045 ClientResponse<Response> res =
2046 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
2047 res.releaseConnection();
2049 // Clean up item resources.
2050 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
2051 itemResourceId = entry.getKey();
2052 parentResourceId = entry.getValue();
2053 // Note: Any non-success responses from the delete operation
2054 // below are ignored and not reported.
2055 ClientResponse<Response> res =
2056 client.deleteItem(parentResourceId, itemResourceId);
2057 res.releaseConnection();
2059 // Clean up parent resources.
2064 // ---------------------------------------------------------------
2065 // Utility methods used by tests above
2066 // ---------------------------------------------------------------
2068 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
2071 public String getServicePathComponent() {
2072 return SERVICE_PATH_COMPONENT;
2076 * Gets the item service path component.
2078 * @return the item service path component
2080 public String getItemServicePathComponent() {
2081 return ITEM_SERVICE_PATH_COMPONENT;
2085 * Gets the contact service path component.
2087 * @return the contact service path component
2089 public String getContactServicePathComponent() {
2090 return CONTACT_SERVICE_PATH_COMPONENT;
2094 * Returns the root URL for the item service.
2096 * This URL consists of a base URL for all services, followed by
2097 * a path component for the owning parent, followed by the
2098 * path component for the items.
2100 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2101 * parent authority resource of the relevant item resource.
2103 * @return The root URL for the item service.
2105 protected String getItemServiceRootURL(String parentResourceIdentifier) {
2106 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
2110 * Returns the URL of a specific item resource managed by a service, and
2111 * designated by an identifier (such as a universally unique ID, or UUID).
2113 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2114 * parent authority resource of the relevant item resource.
2116 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2119 * @return The URL of a specific item resource managed by a service.
2121 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
2122 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
2127 * Returns the root URL for the contact service.
2129 * This URL consists of a base URL for all services, followed by
2130 * a path component for the owning authority, followed by the
2131 * path component for the owning item, followed by the path component
2132 * for the contact service.
2134 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2135 * parent authority resource of the relevant item resource.
2137 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2140 * @return The root URL for the contact service.
2142 protected String getContactServiceRootURL(String parentResourceIdentifier,
2143 String itemResourceIdentifier) {
2144 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
2145 getContactServicePathComponent();
2149 * Returns the URL of a specific contact resource managed by a service, and
2150 * designated by an identifier (such as a universally unique ID, or UUID).
2152 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2153 * parent resource of the relevant item resource.
2155 * @param resourceIdentifier An identifier (such as a UUID) for an
2158 * @return The URL of a specific resource managed by a service.
2160 protected String getContactResourceURL(String parentResourceIdentifier,
2161 String itemResourceIdentifier, String contactResourceIdentifier) {
2162 return getContactServiceRootURL(parentResourceIdentifier,
2163 itemResourceIdentifier) + "/" + contactResourceIdentifier;