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.HashMap;
26 import java.util.List;
28 import javax.ws.rs.core.MediaType;
29 import javax.ws.rs.core.Response;
31 import org.collectionspace.services.OrganizationJAXBSchema;
32 import org.collectionspace.services.client.CollectionSpaceClient;
33 import org.collectionspace.services.client.ContactClient;
34 import org.collectionspace.services.client.ContactClientUtils;
35 import org.collectionspace.services.contact.ContactsCommon;
36 import org.collectionspace.services.contact.ContactsCommonList;
37 import org.collectionspace.services.client.OrgAuthorityClient;
38 import org.collectionspace.services.client.OrgAuthorityClientUtils;
39 import org.collectionspace.services.jaxb.AbstractCommonList;
40 import org.collectionspace.services.organization.OrgauthoritiesCommon;
41 import org.collectionspace.services.organization.OrgauthoritiesCommonList;
42 import org.collectionspace.services.organization.OrganizationsCommon;
43 import org.collectionspace.services.organization.OrganizationsCommonList;
45 import org.jboss.resteasy.client.ClientResponse;
46 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
47 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
48 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
49 import org.slf4j.Logger;
50 import org.slf4j.LoggerFactory;
51 import org.testng.Assert;
52 import org.testng.annotations.AfterClass;
53 import org.testng.annotations.Test;
56 * OrgAuthorityServiceTest, carries out tests against a
57 * deployed and running OrgAuthority Service.
59 * $LastChangedRevision: 753 $
60 * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
62 public class OrgAuthorityServiceTest extends AbstractServiceTestImpl {
65 private final String CLASS_NAME = OrgAuthorityServiceTest.class.getName();
66 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
68 // Instance variables specific to this test.
69 /** The service path component. */
70 final String SERVICE_PATH_COMPONENT = "orgauthorities";
72 /** The item service path component. */
73 final String ITEM_SERVICE_PATH_COMPONENT = "items";
75 /** The contact service path component. */
76 final String CONTACT_SERVICE_PATH_COMPONENT = "contacts";
78 /** The test organization shortname. */
79 private final String TEST_ORG_SHORTNAME = "Test Org";
81 /** The test organization founding place. */
82 private final String TEST_ORG_FOUNDING_PLACE = "Anytown, USA";
84 // Hold some values for a recently created item to verify upon read.
85 private String knownResourceId = null;
86 private String knownResourceShortIdentifer = null;
87 private String knownResourceRefName = null;
88 private String knownItemResourceId = null;
89 private String knownItemResourceShortIdentifer = null;
91 /** The known contact resource id. */
92 private String knownContactResourceId = null;
94 /** The n items to create in list. */
95 private int nItemsToCreateInList = 3;
97 /** The all item resource ids created. */
98 private Map<String, String> allItemResourceIdsCreated =
99 new HashMap<String, String>();
101 /** The all contact resource ids created. */
102 private Map<String, String> allContactResourceIdsCreated =
103 new HashMap<String, String>();
105 protected void setKnownResource( String id, String shortIdentifer,
107 knownResourceId = id;
108 knownResourceShortIdentifer = shortIdentifer;
109 knownResourceRefName = refName;
112 protected void setKnownItemResource( String id, String shortIdentifer ) {
113 knownItemResourceId = id;
114 knownItemResourceShortIdentifer = shortIdentifer;
118 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
121 protected CollectionSpaceClient getClientInstance() {
122 return new OrgAuthorityClient();
126 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
129 protected AbstractCommonList getAbstractCommonList(
130 ClientResponse<AbstractCommonList> response) {
131 return response.getEntity(OrganizationsCommonList.class);
134 // ---------------------------------------------------------------
135 // CRUD tests : CREATE tests
136 // ---------------------------------------------------------------
139 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
142 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
144 public void create(String testName) throws Exception {
146 if (logger.isDebugEnabled()) {
147 logger.debug(testBanner(testName, CLASS_NAME));
149 // Perform setup, such as initializing the type of service request
150 // (e.g. CREATE, DELETE), its valid and expected status codes, and
151 // its associated HTTP method name (e.g. POST, DELETE).
154 // Submit the request to the service and store the response.
155 OrgAuthorityClient client = new OrgAuthorityClient();
156 String shortId = createIdentifier();
157 String displayName = "displayName-" + shortId;
158 String baseRefName = OrgAuthorityClientUtils.createOrgAuthRefName(shortId, null);
159 MultipartOutput multipart =
160 OrgAuthorityClientUtils.createOrgAuthorityInstance(
161 displayName, shortId, client.getCommonPartName());
164 ClientResponse<Response> res = client.create(multipart);
166 int statusCode = res.getStatus();
168 // Check the status code of the response: does it match
169 // the expected response(s)?
172 // Does it fall within the set of valid status codes?
173 // Does it exactly match the expected status code?
174 if(logger.isDebugEnabled()){
175 logger.debug(testName + ": status = " + statusCode);
177 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
178 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
179 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
181 newID = OrgAuthorityClientUtils.extractId(res);
183 res.releaseConnection();
186 // Store the ID returned from the first resource created
187 // for additional tests below.
188 if (knownResourceId == null){
189 setKnownResource( newID, shortId, baseRefName );
190 if (logger.isDebugEnabled()) {
191 logger.debug(testName + ": knownResourceId=" + knownResourceId);
194 // Store the IDs from every resource created by tests,
195 // so they can be deleted after tests have been run.
196 allResourceIdsCreated.add(newID);
202 * @param testName the test name
204 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
205 groups = {"create"}, dependsOnMethods = {"create"})
206 public void createItem(String testName) {
208 String newID = createItemInAuthority(knownResourceId, knownResourceRefName);
212 * Creates the item in authority.
214 * @param vcsid the vcsid
215 * @param authRefName the auth ref name
218 private String createItemInAuthority(String vcsid, String authRefName) {
220 final String testName = "createItemInAuthority";
221 if(logger.isDebugEnabled()){
222 logger.debug(testName + ":...");
225 // Submit the request to the service and store the response.
226 OrgAuthorityClient client = new OrgAuthorityClient();
227 String shortId = "testOrg";
228 Map<String, String> testOrgMap = new HashMap<String,String>();
229 testOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId);
230 testOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, TEST_ORG_SHORTNAME);
231 testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "The real official test organization");
232 testOrgMap.put(OrganizationJAXBSchema.CONTACT_NAME, "joe@test.org");
233 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "May 26, 1907");
234 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, TEST_ORG_FOUNDING_PLACE);
235 testOrgMap.put(OrganizationJAXBSchema.FUNCTION, "For testing");
236 String newID = OrgAuthorityClientUtils.createItemInAuthority(
237 vcsid, authRefName, testOrgMap, client);
238 // Store the ID returned from the first item resource created
239 // for additional tests below.
240 if (knownItemResourceId == null){
241 setKnownItemResource(newID, shortId);
242 if (logger.isDebugEnabled()) {
243 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
247 // Store the IDs from any item resources created
248 // by tests, along with the IDs of their parents, so these items
249 // can be deleted after all tests have been run.
250 allItemResourceIdsCreated.put(newID, vcsid);
256 * Creates the contact.
258 * @param testName the test name
260 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
261 groups = {"create"}, dependsOnMethods = {"createItem"})
262 public void createContact(String testName) {
264 String newID = createContactInItem(knownResourceId, knownItemResourceId);
268 * Creates the contact in item.
270 * @param parentcsid the parentcsid
271 * @param itemcsid the itemcsid
274 private String createContactInItem(String parentcsid, String itemcsid) {
276 final String testName = "createContactInItem";
277 if (logger.isDebugEnabled()) {
278 logger.debug(testBanner(testName, CLASS_NAME));
282 // Submit the request to the service and store the response.
283 OrgAuthorityClient client = new OrgAuthorityClient();
284 String identifier = createIdentifier();
285 MultipartOutput multipart =
286 ContactClientUtils.createContactInstance(parentcsid,
287 itemcsid, identifier, new ContactClient().getCommonPartName());
290 ClientResponse<Response> res =
291 client.createContact(parentcsid, itemcsid, multipart);
293 int statusCode = res.getStatus();
294 // Check the status code of the response: does it match
295 // the expected response(s)?
296 if(logger.isDebugEnabled()){
297 logger.debug(testName + ": status = " + statusCode);
299 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
300 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
301 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
303 newID = OrgAuthorityClientUtils.extractId(res);
305 res.releaseConnection();
308 // Store the ID returned from the first contact resource created
309 // for additional tests below.
310 if (knownContactResourceId == null){
311 knownContactResourceId = newID;
312 if (logger.isDebugEnabled()) {
313 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
317 // Store the IDs from any contact resources created
318 // by tests, along with the IDs of their parent items,
319 // so these items can be deleted after all tests have been run.
320 allContactResourceIdsCreated.put(newID, itemcsid);
327 // Placeholders until the three tests below can be uncommented.
328 // See Issue CSPACE-401.
330 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
333 public void createWithEmptyEntityBody(String testName) throws Exception {
334 //Should this really be empty?
338 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
341 public void createWithMalformedXml(String testName) throws Exception {
342 //Should this really be empty?
346 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
349 public void createWithWrongXmlSchema(String testName) throws Exception {
350 //Should this really be empty?
355 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
356 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
357 public void createWithEmptyEntityBody(String testName) throws Exception {
359 if (logger.isDebugEnabled()) {
360 logger.debug(testBanner(testName, CLASS_NAME));
363 setupCreateWithEmptyEntityBody();
365 // Submit the request to the service and store the response.
366 String method = REQUEST_TYPE.httpMethodName();
367 String url = getServiceRootURL();
368 String mediaType = MediaType.APPLICATION_XML;
369 final String entity = "";
370 int statusCode = submitRequest(method, url, mediaType, entity);
372 // Check the status code of the response: does it match
373 // the expected response(s)?
374 if(logger.isDebugEnabled()) {
375 logger.debug(testName + ": url=" + url +
376 " status=" + statusCode);
378 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
379 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
380 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
384 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
385 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
386 public void createWithMalformedXml(String testName) throws Exception {
388 if (logger.isDebugEnabled()) {
389 logger.debug(testBanner(testName, CLASS_NAME));
392 setupCreateWithMalformedXml();
394 // Submit the request to the service and store the response.
395 String method = REQUEST_TYPE.httpMethodName();
396 String url = getServiceRootURL();
397 String mediaType = MediaType.APPLICATION_XML;
398 final String entity = MALFORMED_XML_DATA; // Constant from base class.
399 int statusCode = submitRequest(method, url, mediaType, entity);
401 // Check the status code of the response: does it match
402 // the expected response(s)?
403 if(logger.isDebugEnabled()){
404 logger.debug(testName + ": url=" + url +
405 " status=" + statusCode);
407 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
408 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
409 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
413 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
414 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
415 public void createWithWrongXmlSchema(String testName) throws Exception {
417 if (logger.isDebugEnabled()) {
418 logger.debug(testBanner(testName, CLASS_NAME));
421 setupCreateWithWrongXmlSchema();
423 // Submit the request to the service and store the response.
424 String method = REQUEST_TYPE.httpMethodName();
425 String url = getServiceRootURL();
426 String mediaType = MediaType.APPLICATION_XML;
427 final String entity = WRONG_XML_SCHEMA_DATA;
428 int statusCode = submitRequest(method, url, mediaType, entity);
430 // Check the status code of the response: does it match
431 // the expected response(s)?
432 if(logger.isDebugEnabled()){
433 logger.debug(testName + ": url=" + url +
434 " status=" + statusCode);
436 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
437 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
438 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
442 // ---------------------------------------------------------------
443 // CRUD tests : CREATE LIST tests
444 // ---------------------------------------------------------------
447 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
450 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
451 groups = {"createList"}, dependsOnGroups = {"create"})
452 public void createList(String testName) throws Exception {
453 for (int i = 0; i < nItemsToCreateInList; i++) {
459 * Creates the item list.
461 * @param testName the test name
462 * @throws Exception the exception
464 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
465 groups = {"createList"}, dependsOnMethods = {"createList"})
466 public void createItemList(String testName) throws Exception {
467 // Add items to the initially-created, known parent record.
468 for (int j = 0; j < nItemsToCreateInList; j++) {
469 createItem(testName);
474 * Creates the contact list.
476 * @param testName the test name
477 * @throws Exception the exception
479 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
480 groups = {"createList"}, dependsOnMethods = {"createItemList"})
481 public void createContactList(String testName) throws Exception {
482 // Add contacts to the initially-created, known item record.
483 for (int j = 0; j < nItemsToCreateInList; j++) {
484 createContact(testName);
488 // ---------------------------------------------------------------
489 // CRUD tests : READ tests
490 // ---------------------------------------------------------------
493 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
496 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
497 groups = {"read"}, dependsOnGroups = {"create"})
498 public void read(String testName) throws Exception {
499 readInternal(testName, knownResourceId, null);
505 * @param testName the test name
506 * @throws Exception the exception
508 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
509 groups = {"read"}, dependsOnGroups = {"create"})
510 public void readByName(String testName) throws Exception {
511 readInternal(testName, null, knownResourceShortIdentifer);
514 protected void readInternal(String testName, String CSID, String shortId) {
516 if (logger.isDebugEnabled()) {
517 logger.debug(testBanner(testName, CLASS_NAME));
522 // Submit the request to the service and store the response.
523 OrgAuthorityClient client = new OrgAuthorityClient();
524 ClientResponse<MultipartInput> res = null;
526 res = client.read(CSID);
527 } else if(shortId!=null) {
528 res = client.readByName(shortId);
530 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
533 int statusCode = res.getStatus();
535 // Check the status code of the response: does it match
536 // the expected response(s)?
537 if(logger.isDebugEnabled()){
538 logger.debug(testName + ": status = " + statusCode);
540 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
541 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
542 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
543 //FIXME: remove the following try catch once Aron fixes signatures
545 MultipartInput input = (MultipartInput) res.getEntity();
546 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
547 new OrgAuthorityClient().getCommonPartName(), OrgauthoritiesCommon.class);
548 Assert.assertNotNull(orgAuthority);
549 } catch (Exception e) {
550 throw new RuntimeException(e);
553 res.releaseConnection();
560 * @param testName the test name
561 * @throws Exception the exception
563 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
564 groups = {"readItem"}, dependsOnGroups = {"read"})
565 public void readItem(String testName) throws Exception {
566 readItemInternal(testName, knownResourceId, null, knownItemResourceId, null);
570 * Read item in Named Auth.
572 * TODO Enable this if we really need this - it is a funky case, where we would have
573 * the shortId of the item, but the CSID of the parent authority!? Unlikely.
575 * @param testName the test name
576 * @throws Exception the exception
577 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
578 groups = {"readItem"}, dependsOnGroups = {"read"})
579 public void readItemInNamedAuth(String testName) throws Exception {
580 readItemInternal(testName, null, knownResourceShortIdentifer, knownItemResourceId, null);
587 * @param testName the test name
588 * @throws Exception the exception
590 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
591 groups = {"readItem"}, dependsOnGroups = {"read"})
592 public void readNamedItem(String testName) throws Exception {
593 readItemInternal(testName, knownResourceId, null, null, knownItemResourceShortIdentifer);
597 * Read Named item in Named Auth.
599 * @param testName the test name
600 * @throws Exception the exception
602 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
603 groups = {"readItem"}, dependsOnGroups = {"read"})
604 public void readNamedItemInNamedAuth(String testName) throws Exception {
605 readItemInternal(testName, null, knownResourceShortIdentifer, null, knownItemResourceShortIdentifer);
608 protected void readItemInternal(String testName,
609 String authCSID, String authShortId, String itemCSID, String itemShortId)
612 if (logger.isDebugEnabled()) {
613 logger.debug(testBanner(testName, CLASS_NAME));
618 // Submit the request to the service and store the response.
619 OrgAuthorityClient client = new OrgAuthorityClient();
620 ClientResponse<MultipartInput> res = null;
623 res = client.readItem(authCSID, itemCSID);
624 } else if(itemShortId!=null) {
625 res = client.readNamedItem(authCSID, itemShortId);
627 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
629 } else if(authShortId!=null) {
631 res = client.readItemInNamedAuthority(authShortId, itemCSID);
632 } else if(itemShortId!=null) {
633 res = client.readNamedItemInNamedAuthority(authShortId, itemShortId);
635 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
638 Assert.fail("readInternal: Internal error. One of authCSID or authShortId must be non-null");
641 int statusCode = res.getStatus();
643 // Check the status code of the response: does it match
644 // the expected response(s)?
645 if(logger.isDebugEnabled()){
646 logger.debug(testName + ": status = " + statusCode);
648 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
649 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
650 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
652 // Check whether we've received a organization.
653 MultipartInput input = (MultipartInput) res.getEntity();
654 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
655 client.getItemCommonPartName(), OrganizationsCommon.class);
656 Assert.assertNotNull(organization);
657 boolean showFull = true;
658 if(showFull && logger.isDebugEnabled()){
659 logger.debug(testName + ": returned payload:");
660 logger.debug(objectAsXmlString(organization, OrganizationsCommon.class));
662 Assert.assertEquals(organization.getInAuthority(), knownResourceId);
664 res.releaseConnection();
669 * Verify item display name.
671 * @param testName the test name
672 * @throws Exception the exception
674 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
675 dependsOnMethods = {"readItem", "updateItem"})
676 public void verifyItemDisplayName(String testName) throws Exception {
678 if (logger.isDebugEnabled()) {
679 logger.debug(testBanner(testName, CLASS_NAME));
684 // Submit the request to the service and store the response.
685 OrgAuthorityClient client = new OrgAuthorityClient();
686 MultipartInput input = null;
687 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
689 int statusCode = res.getStatus();
691 // Check the status code of the response: does it match
692 // the expected response(s)?
693 if(logger.isDebugEnabled()){
694 logger.debug(testName + ": status = " + statusCode);
696 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
697 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
698 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
700 // Check whether organization has expected displayName.
701 input = res.getEntity();
703 res.releaseConnection();
706 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
707 client.getItemCommonPartName(), OrganizationsCommon.class);
708 Assert.assertNotNull(organization);
709 String displayName = organization.getDisplayName();
710 // Make sure displayName matches computed form
711 String expectedDisplayName =
712 OrgAuthorityClientUtils.prepareDefaultDisplayName(
713 TEST_ORG_SHORTNAME, TEST_ORG_FOUNDING_PLACE);
714 Assert.assertNotNull(displayName, expectedDisplayName);
716 // Update the shortName and verify the computed name is updated.
717 organization.setCsid(null);
718 organization.setDisplayNameComputed(true);
719 organization.setShortName("updated-" + TEST_ORG_SHORTNAME);
720 expectedDisplayName =
721 OrgAuthorityClientUtils.prepareDefaultDisplayName(
722 "updated-" + TEST_ORG_SHORTNAME, TEST_ORG_FOUNDING_PLACE);
724 // Submit the updated resource to the service and store the response.
725 MultipartOutput output = new MultipartOutput();
726 OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
727 commonPart.getHeaders().add("label", client.getItemCommonPartName());
728 res = client.updateItem(knownResourceId, knownItemResourceId, output);
730 int statusCode = res.getStatus();
732 // Check the status code of the response: does it match the expected response(s)?
733 if(logger.isDebugEnabled()){
734 logger.debug("updateItem: status = " + statusCode);
736 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
737 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
738 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
740 // Retrieve the updated resource and verify that its contents exist.
741 input = (MultipartInput) res.getEntity();
743 res.releaseConnection();
746 OrganizationsCommon updatedOrganization =
747 (OrganizationsCommon) extractPart(input,
748 client.getItemCommonPartName(), OrganizationsCommon.class);
749 Assert.assertNotNull(updatedOrganization);
751 // Verify that the updated resource received the correct data.
752 Assert.assertEquals(updatedOrganization.getShortName(), organization.getShortName(),
753 "Updated ShortName in Organization did not match submitted data.");
754 // Verify that the updated resource computes the right displayName.
755 Assert.assertEquals(updatedOrganization.getDisplayName(), expectedDisplayName,
756 "Updated ShortName in Organization not reflected in computed DisplayName.");
758 // Now Update the displayName, not computed and verify the computed name is overriden.
759 organization.setDisplayNameComputed(false);
760 expectedDisplayName = "TestName";
761 organization.setDisplayName(expectedDisplayName);
763 // Submit the updated resource to the service and store the response.
764 output = new MultipartOutput();
765 commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
766 commonPart.getHeaders().add("label", client.getItemCommonPartName());
767 res = client.updateItem(knownResourceId, knownItemResourceId, output);
769 int statusCode = res.getStatus();
771 // Check the status code of the response: does it match the expected response(s)?
772 if(logger.isDebugEnabled()){
773 logger.debug("updateItem: status = " + statusCode);
775 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
776 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
777 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
779 // Retrieve the updated resource and verify that its contents exist.
780 input = (MultipartInput) res.getEntity();
782 res.releaseConnection();
785 updatedOrganization =
786 (OrganizationsCommon) extractPart(input,
787 client.getItemCommonPartName(), OrganizationsCommon.class);
788 Assert.assertNotNull(updatedOrganization);
790 // Verify that the updated resource received the correct data.
791 Assert.assertEquals(updatedOrganization.isDisplayNameComputed(), false,
792 "Updated displayNameComputed in Organization did not match submitted data.");
793 // Verify that the updated resource computes the right displayName.
794 Assert.assertEquals(updatedOrganization.getDisplayName(),
796 "Updated DisplayName (not computed) in Organization not stored.");
800 * Verify illegal item display name.
802 * @param testName the test name
803 * @throws Exception the exception
805 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
806 dependsOnMethods = {"verifyItemDisplayName"})
807 public void verifyIllegalItemDisplayName(String testName) throws Exception {
809 if (logger.isDebugEnabled()) {
810 logger.debug(testBanner(testName, CLASS_NAME));
813 testSetup(STATUS_BAD_REQUEST, ServiceRequestType.UPDATE);
814 // setupUpdateWithWrongXmlSchema(testName, logger);
816 // Submit the request to the service and store the response.
817 OrgAuthorityClient client = new OrgAuthorityClient();
818 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
819 int statusCode = res.getStatus();
821 // Check the status code of the response: does it match
822 // the expected response(s)?
823 if(logger.isDebugEnabled()){
824 logger.debug(testName + ": status = " + statusCode);
826 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
827 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
828 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
830 // Check whether organization has expected displayName.
831 MultipartInput input = (MultipartInput) res.getEntity();
832 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
833 client.getItemCommonPartName(), OrganizationsCommon.class);
834 Assert.assertNotNull(organization);
835 // Try to Update with computed false and no displayName
836 organization.setDisplayNameComputed(false);
837 organization.setDisplayName(null);
839 // Submit the updated resource to the service and store the response.
840 MultipartOutput output = new MultipartOutput();
841 OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
842 commonPart.getHeaders().add("label", client.getItemCommonPartName());
843 res = client.updateItem(knownResourceId, knownItemResourceId, output);
844 statusCode = res.getStatus();
846 // Check the status code of the response: does it match the expected response(s)?
847 if(logger.isDebugEnabled()){
848 logger.debug("updateItem: status = " + statusCode);
850 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
851 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
852 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
858 * @param testName the test name
859 * @throws Exception the exception
861 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
862 groups = {"readItem"}, dependsOnMethods = {"readItem"})
863 public void readContact(String testName) throws Exception {
865 if (logger.isDebugEnabled()) {
866 logger.debug(testBanner(testName, CLASS_NAME));
871 // Submit the request to the service and store the response.
872 OrgAuthorityClient client = new OrgAuthorityClient();
873 ClientResponse<MultipartInput> res =
874 client.readContact(knownResourceId, knownItemResourceId,
875 knownContactResourceId);
876 int statusCode = res.getStatus();
878 // Check the status code of the response: does it match
879 // the expected response(s)?
880 if(logger.isDebugEnabled()){
881 logger.debug(testName + ": status = " + statusCode);
883 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
884 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
885 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
887 // Check whether we've received a contact.
888 MultipartInput input = (MultipartInput) res.getEntity();
889 ContactsCommon contact = (ContactsCommon) extractPart(input,
890 new ContactClient().getCommonPartName(), ContactsCommon.class);
891 Assert.assertNotNull(contact);
892 boolean showFull = true;
893 if(showFull && logger.isDebugEnabled()){
894 logger.debug(testName + ": returned payload:");
895 logger.debug(objectAsXmlString(contact, ContactsCommon.class));
897 Assert.assertEquals(contact.getInAuthority(), knownResourceId);
898 Assert.assertEquals(contact.getInItem(), knownItemResourceId);
904 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
907 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
908 groups = {"read"}, dependsOnMethods = {"read"})
909 public void readNonExistent(String testName) {
911 if (logger.isDebugEnabled()) {
912 logger.debug(testBanner(testName, CLASS_NAME));
915 setupReadNonExistent();
917 // Submit the request to the service and store the response.
918 OrgAuthorityClient client = new OrgAuthorityClient();
919 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
920 int statusCode = res.getStatus();
922 // Check the status code of the response: does it match
923 // the expected response(s)?
924 if(logger.isDebugEnabled()){
925 logger.debug(testName + ": status = " + statusCode);
927 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
928 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
929 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
933 * Read item non existent.
935 * @param testName the test name
937 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
938 groups = {"readItem"}, dependsOnMethods = {"readItem"})
939 public void readItemNonExistent(String testName) {
941 if (logger.isDebugEnabled()) {
942 logger.debug(testBanner(testName, CLASS_NAME));
945 setupReadNonExistent();
947 // Submit the request to the service and store the response.
948 OrgAuthorityClient client = new OrgAuthorityClient();
949 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
950 int statusCode = res.getStatus();
952 // Check the status code of the response: does it match
953 // the expected response(s)?
954 if(logger.isDebugEnabled()){
955 logger.debug(testName + ": status = " + statusCode);
957 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
958 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
959 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
963 * Read contact non existent.
965 * @param testName the test name
967 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
968 groups = {"readItem"}, dependsOnMethods = {"readContact"})
969 public void readContactNonExistent(String testName) {
971 if (logger.isDebugEnabled()) {
972 logger.debug(testBanner(testName, CLASS_NAME));
975 setupReadNonExistent();
977 // Submit the request to the service and store the response.
978 OrgAuthorityClient client = new OrgAuthorityClient();
979 ClientResponse<MultipartInput> res =
980 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
981 int statusCode = res.getStatus();
983 // Check the status code of the response: does it match
984 // the expected response(s)?
985 if(logger.isDebugEnabled()){
986 logger.debug(testName + ": status = " + statusCode);
988 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
989 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
990 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
993 // ---------------------------------------------------------------
994 // CRUD tests : READ_LIST tests
995 // ---------------------------------------------------------------
999 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
1002 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1003 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
1004 public void readList(String testName) throws Exception {
1006 if (logger.isDebugEnabled()) {
1007 logger.debug(testBanner(testName, CLASS_NAME));
1012 // Submit the request to the service and store the response.
1013 OrgAuthorityClient client = new OrgAuthorityClient();
1014 ClientResponse<OrgauthoritiesCommonList> res = client.readList();
1015 OrgauthoritiesCommonList list = res.getEntity();
1016 int statusCode = res.getStatus();
1018 // Check the status code of the response: does it match
1019 // the expected response(s)?
1020 if(logger.isDebugEnabled()){
1021 logger.debug(testName + ": status = " + statusCode);
1023 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1024 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1025 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1027 // Optionally output additional data about list members for debugging.
1028 boolean iterateThroughList = false;
1029 if (iterateThroughList && logger.isDebugEnabled()) {
1030 List<OrgauthoritiesCommonList.OrgauthorityListItem> items =
1031 list.getOrgauthorityListItem();
1033 for (OrgauthoritiesCommonList.OrgauthorityListItem item : items) {
1034 String csid = item.getCsid();
1035 logger.debug(testName + ": list-item[" + i + "] csid=" +
1037 logger.debug(testName + ": list-item[" + i + "] displayName=" +
1038 item.getDisplayName());
1039 logger.debug(testName + ": list-item[" + i + "] URI=" +
1041 readItemList(csid, null);
1050 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
1051 public void readItemList() {
1052 readItemList(knownResourceId, null);
1056 * Read item list by authority name.
1058 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1059 public void readItemListByAuthorityName() {
1060 readItemList(null, knownResourceShortIdentifer);
1066 * @param vcsid the vcsid
1067 * @param name the name
1069 private void readItemList(String vcsid, String name) {
1071 final String testName = "readItemList";
1073 if (logger.isDebugEnabled()) {
1074 logger.debug(testBanner(testName, CLASS_NAME));
1079 // Submit the request to the service and store the response.
1080 OrgAuthorityClient client = new OrgAuthorityClient();
1081 ClientResponse<OrganizationsCommonList> res = null;
1083 res = client.readItemList(vcsid);
1084 } else if(name!= null) {
1085 res = client.readItemListForNamedAuthority(name);
1087 Assert.fail("readItemList passed null csid and name!");
1089 OrganizationsCommonList list = res.getEntity();
1090 int statusCode = res.getStatus();
1092 // Check the status code of the response: does it match
1093 // the expected response(s)?
1094 if(logger.isDebugEnabled()){
1095 logger.debug(testName + ": status = " + statusCode);
1097 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1098 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1099 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1101 List<OrganizationsCommonList.OrganizationListItem> items =
1102 list.getOrganizationListItem();
1103 int nItemsReturned = items.size();
1104 // There will be one item created, associated with a
1105 // known parent resource, by the createItem test.
1107 // In addition, there will be 'nItemsToCreateInList'
1108 // additional items created by the createItemList test,
1109 // all associated with the same parent resource.
1110 int nExpectedItems = nItemsToCreateInList + 1;
1111 if(logger.isDebugEnabled()){
1112 logger.debug(testName + ": Expected "
1113 + nExpectedItems +" items; got: "+nItemsReturned);
1115 Assert.assertEquals(nItemsReturned, nExpectedItems);
1118 for (OrganizationsCommonList.OrganizationListItem item : items) {
1119 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
1120 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
1121 // Optionally output additional data about list members for debugging.
1122 boolean showDetails = true;
1123 if (showDetails && logger.isDebugEnabled()) {
1124 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1126 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
1128 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
1129 item.getDisplayName());
1130 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1138 * Read contact list.
1140 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1141 public void readContactList() {
1142 readContactList(knownResourceId, knownItemResourceId);
1146 * Read contact list.
1148 * @param parentcsid the parentcsid
1149 * @param itemcsid the itemcsid
1151 private void readContactList(String parentcsid, String itemcsid) {
1152 final String testName = "readContactList";
1154 if (logger.isDebugEnabled()) {
1155 logger.debug(testBanner(testName, CLASS_NAME));
1160 // Submit the request to the service and store the response.
1161 OrgAuthorityClient client = new OrgAuthorityClient();
1162 ContactsCommonList list = null;
1163 ClientResponse<ContactsCommonList> res =
1164 client.readContactList(parentcsid, itemcsid);
1165 list = res.getEntity();
1166 int statusCode = res.getStatus();
1168 // Check the status code of the response: does it match
1169 // the expected response(s)?
1170 if(logger.isDebugEnabled()){
1171 logger.debug(testName + ": status = " + statusCode);
1173 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1174 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1175 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1177 List<ContactsCommonList.ContactListItem> listitems =
1178 list.getContactListItem();
1179 int nItemsReturned = listitems.size();
1180 // There will be one item created, associated with a
1181 // known parent resource, by the createItem test.
1183 // In addition, there will be 'nItemsToCreateInList'
1184 // additional items created by the createItemList test,
1185 // all associated with the same parent resource.
1186 int nExpectedItems = nItemsToCreateInList + 1;
1187 if(logger.isDebugEnabled()){
1188 logger.debug(testName + ": Expected "
1189 + nExpectedItems +" items; got: "+nItemsReturned);
1191 Assert.assertEquals(nItemsReturned, nExpectedItems);
1194 for (ContactsCommonList.ContactListItem listitem : listitems) {
1195 // Optionally output additional data about list members for debugging.
1196 boolean showDetails = false;
1197 if (showDetails && logger.isDebugEnabled()) {
1198 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1199 listitem.getCsid());
1200 logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" +
1201 listitem.getAddressPlace());
1202 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1212 // ---------------------------------------------------------------
1213 // CRUD tests : UPDATE tests
1214 // ---------------------------------------------------------------
1217 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
1220 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1221 groups = {"update"}, dependsOnGroups = {"read", "readList"})
1222 public void update(String testName) throws Exception {
1224 if (logger.isDebugEnabled()) {
1225 logger.debug(testBanner(testName, CLASS_NAME));
1230 // Retrieve the contents of a resource to update.
1231 OrgAuthorityClient client = new OrgAuthorityClient();
1232 ClientResponse<MultipartInput> res =
1233 client.read(knownResourceId);
1234 if(logger.isDebugEnabled()){
1235 logger.debug(testName + ": read status = " + res.getStatus());
1237 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1239 if(logger.isDebugEnabled()){
1240 logger.debug("got OrgAuthority to update with ID: " + knownResourceId);
1242 MultipartInput input = (MultipartInput) res.getEntity();
1243 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
1244 client.getCommonPartName(), OrgauthoritiesCommon.class);
1245 Assert.assertNotNull(orgAuthority);
1247 // Update the contents of this resource.
1248 orgAuthority.setDisplayName("updated-" + orgAuthority.getDisplayName());
1249 orgAuthority.setVocabType("updated-" + orgAuthority.getVocabType());
1250 if(logger.isDebugEnabled()){
1251 logger.debug("to be updated OrgAuthority");
1252 logger.debug(objectAsXmlString(orgAuthority, OrgauthoritiesCommon.class));
1255 // Submit the updated resource to the service and store the response.
1256 MultipartOutput output = new MultipartOutput();
1257 OutputPart commonPart = output.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE);
1258 commonPart.getHeaders().add("label", client.getCommonPartName());
1259 res = client.update(knownResourceId, output);
1260 int statusCode = res.getStatus();
1262 // Check the status code of the response: does it match the expected response(s)?
1263 if(logger.isDebugEnabled()){
1264 logger.debug(testName + ": status = " + statusCode);
1266 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1267 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1268 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1270 // Retrieve the updated resource and verify that its contents exist.
1271 input = (MultipartInput) res.getEntity();
1272 OrgauthoritiesCommon updatedOrgAuthority =
1273 (OrgauthoritiesCommon) extractPart(input,
1274 client.getCommonPartName(), OrgauthoritiesCommon.class);
1275 Assert.assertNotNull(updatedOrgAuthority);
1277 // Verify that the updated resource received the correct data.
1278 Assert.assertEquals(updatedOrgAuthority.getDisplayName(),
1279 orgAuthority.getDisplayName(),
1280 "Data in updated object did not match submitted data.");
1286 * @param testName the test name
1287 * @throws Exception the exception
1289 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1290 groups = {"update"}, dependsOnMethods = {"update"})
1291 public void updateItem(String testName) throws Exception {
1293 if (logger.isDebugEnabled()) {
1294 logger.debug(testBanner(testName, CLASS_NAME));
1299 // Retrieve the contents of a resource to update.
1300 OrgAuthorityClient client = new OrgAuthorityClient();
1301 ClientResponse<MultipartInput> res =
1302 client.readItem(knownResourceId, knownItemResourceId);
1303 if(logger.isDebugEnabled()){
1304 logger.debug(testName + ": read status = " + res.getStatus());
1306 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1308 if(logger.isDebugEnabled()){
1309 logger.debug("got Organization to update with ID: " +
1310 knownItemResourceId +
1311 " in OrgAuthority: " + knownResourceId );
1313 MultipartInput input = (MultipartInput) res.getEntity();
1314 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
1315 client.getItemCommonPartName(), OrganizationsCommon.class);
1316 Assert.assertNotNull(organization);
1318 // Update the contents of this resource.
1319 organization.setCsid(null);
1320 organization.setShortName("updated-" + organization.getShortName());
1321 if(logger.isDebugEnabled()){
1322 logger.debug("to be updated Organization");
1323 logger.debug(objectAsXmlString(organization,
1324 OrganizationsCommon.class));
1327 // Submit the updated resource to the service and store the response.
1328 MultipartOutput output = new MultipartOutput();
1329 OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
1330 commonPart.getHeaders().add("label", client.getItemCommonPartName());
1331 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1332 int statusCode = res.getStatus();
1334 // Check the status code of the response: does it match the expected response(s)?
1335 if(logger.isDebugEnabled()){
1336 logger.debug(testName + ": status = " + statusCode);
1338 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1339 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1340 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1342 // Retrieve the updated resource and verify that its contents exist.
1343 input = (MultipartInput) res.getEntity();
1344 OrganizationsCommon updatedOrganization =
1345 (OrganizationsCommon) extractPart(input,
1346 client.getItemCommonPartName(), OrganizationsCommon.class);
1347 Assert.assertNotNull(updatedOrganization);
1349 // Verify that the updated resource received the correct data.
1350 Assert.assertEquals(updatedOrganization.getShortName(),
1351 organization.getShortName(),
1352 "Data in updated Organization did not match submitted data.");
1358 * @param testName the test name
1359 * @throws Exception the exception
1361 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1362 groups = {"update"}, dependsOnMethods = {"updateItem"})
1363 public void updateContact(String testName) throws Exception {
1365 if (logger.isDebugEnabled()) {
1366 logger.debug(testBanner(testName, CLASS_NAME));
1371 // Retrieve the contents of a resource to update.
1372 OrgAuthorityClient client = new OrgAuthorityClient();
1373 ClientResponse<MultipartInput> res =
1374 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1375 if(logger.isDebugEnabled()){
1376 logger.debug(testName + ": read status = " + res.getStatus());
1378 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1380 if(logger.isDebugEnabled()){
1381 logger.debug("got Contact to update with ID: " +
1382 knownContactResourceId +
1383 " in item: " + knownItemResourceId +
1384 " in parent: " + knownResourceId );
1386 MultipartInput input = (MultipartInput) res.getEntity();
1387 ContactsCommon contact = (ContactsCommon) extractPart(input,
1388 new ContactClient().getCommonPartName(), ContactsCommon.class);
1389 Assert.assertNotNull(contact);
1391 // Update the contents of this resource.
1392 contact.setAddressPlace("updated-" + contact.getAddressPlace());
1393 if(logger.isDebugEnabled()){
1394 logger.debug("to be updated Contact");
1395 logger.debug(objectAsXmlString(contact,
1396 ContactsCommon.class));
1399 // Submit the updated resource to the service and store the response.
1400 MultipartOutput output = new MultipartOutput();
1401 OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1402 commonPart.getHeaders().add("label", new ContactClient().getCommonPartName());
1403 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1404 int statusCode = res.getStatus();
1406 // Check the status code of the response: does it match the expected response(s)?
1407 if(logger.isDebugEnabled()){
1408 logger.debug(testName + ": status = " + statusCode);
1410 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1411 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1412 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1414 // Retrieve the updated resource and verify that its contents exist.
1415 input = (MultipartInput) res.getEntity();
1416 ContactsCommon updatedContact =
1417 (ContactsCommon) extractPart(input,
1418 new ContactClient().getCommonPartName(), ContactsCommon.class);
1419 Assert.assertNotNull(updatedContact);
1421 // Verify that the updated resource received the correct data.
1422 Assert.assertEquals(updatedContact.getAddressPlace(),
1423 contact.getAddressPlace(),
1424 "Data in updated Contact did not match submitted data.");
1428 // Placeholders until the three tests below can be uncommented.
1429 // See Issue CSPACE-401.
1431 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1434 public void updateWithEmptyEntityBody(String testName) throws Exception {
1435 //Should this really be empty?
1439 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1442 public void updateWithMalformedXml(String testName) throws Exception {
1443 //Should this really be empty?
1447 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1450 public void updateWithWrongXmlSchema(String testName) throws Exception {
1451 //Should this really be empty?
1456 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1457 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1458 public void updateWithEmptyEntityBody(String testName) throws Exception {
1460 if (logger.isDebugEnabled()) {
1461 logger.debug(testBanner(testName, CLASS_NAME));
1464 setupUpdateWithEmptyEntityBody();
1466 // Submit the request to the service and store the response.
1467 String method = REQUEST_TYPE.httpMethodName();
1468 String url = getResourceURL(knownResourceId);
1469 String mediaType = MediaType.APPLICATION_XML;
1470 final String entity = "";
1471 int statusCode = submitRequest(method, url, mediaType, entity);
1473 // Check the status code of the response: does it match
1474 // the expected response(s)?
1475 if(logger.isDebugEnabled()){
1476 logger.debug(testName + ": url=" + url +
1477 " status=" + statusCode);
1479 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1480 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1481 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1485 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1486 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1487 public void updateWithMalformedXml(String testName) throws Exception {
1489 if (logger.isDebugEnabled()) {
1490 logger.debug(testBanner(testName, CLASS_NAME));
1493 setupUpdateWithMalformedXml();
1495 // Submit the request to the service and store the response.
1496 String method = REQUEST_TYPE.httpMethodName();
1497 String url = getResourceURL(knownResourceId);
1498 String mediaType = MediaType.APPLICATION_XML;
1499 final String entity = MALFORMED_XML_DATA;
1500 int statusCode = submitRequest(method, url, mediaType, entity);
1502 // Check the status code of the response: does it match
1503 // the expected response(s)?
1504 if(logger.isDebugEnabled()){
1505 logger.debug(testName + ": url=" + url +
1506 " status=" + statusCode);
1508 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1509 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1510 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1514 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1515 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1516 public void updateWithWrongXmlSchema(String testName) throws Exception {
1519 setupUpdateWithWrongXmlSchema(testName, logger);
1521 // Submit the request to the service and store the response.
1522 String method = REQUEST_TYPE.httpMethodName();
1523 String url = getResourceURL(knownResourceId);
1524 String mediaType = MediaType.APPLICATION_XML;
1525 final String entity = WRONG_XML_SCHEMA_DATA;
1526 int statusCode = submitRequest(method, url, mediaType, entity);
1528 // Check the status code of the response: does it match
1529 // the expected response(s)?
1530 if(logger.isDebugEnabled()){
1531 logger.debug("updateWithWrongXmlSchema: url=" + url +
1532 " status=" + statusCode);
1534 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1535 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1536 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1541 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1544 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1545 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1546 public void updateNonExistent(String testName) throws Exception {
1548 if (logger.isDebugEnabled()) {
1549 logger.debug(testBanner(testName, CLASS_NAME));
1552 setupUpdateNonExistent();
1554 // Submit the request to the service and store the response.
1555 // Note: The ID used in this 'create' call may be arbitrary.
1556 // The only relevant ID may be the one used in update(), below.
1557 OrgAuthorityClient client = new OrgAuthorityClient();
1558 MultipartOutput multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance(
1559 NON_EXISTENT_ID, NON_EXISTENT_ID,
1560 new OrgAuthorityClient().getCommonPartName());
1561 ClientResponse<MultipartInput> res =
1562 client.update(NON_EXISTENT_ID, multipart);
1563 int statusCode = res.getStatus();
1565 // Check the status code of the response: does it match
1566 // the expected response(s)?
1567 if(logger.isDebugEnabled()){
1568 logger.debug(testName + ": status = " + statusCode);
1570 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1571 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1572 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1576 * Update non existent item.
1578 * @param testName the test name
1579 * @throws Exception the exception
1581 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1582 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1583 public void updateNonExistentItem(String testName) throws Exception {
1585 if (logger.isDebugEnabled()) {
1586 logger.debug(testBanner(testName, CLASS_NAME));
1589 setupUpdateNonExistent();
1591 // Submit the request to the service and store the response.
1592 // Note: The ID(s) used when creating the request payload may be arbitrary.
1593 // The only relevant ID may be the one used in update(), below.
1594 OrgAuthorityClient client = new OrgAuthorityClient();
1595 Map<String, String> nonexOrgMap = new HashMap<String,String>();
1596 nonexOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, "nonExistent");
1597 nonexOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Non-existent");
1598 MultipartOutput multipart =
1599 OrgAuthorityClientUtils.createOrganizationInstance(
1600 NON_EXISTENT_ID, knownResourceRefName,
1601 nonexOrgMap, client.getItemCommonPartName() );
1602 ClientResponse<MultipartInput> res =
1603 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1604 int statusCode = res.getStatus();
1606 // Check the status code of the response: does it match
1607 // the expected response(s)?
1608 if(logger.isDebugEnabled()){
1609 logger.debug(testName + ": status = " + statusCode);
1611 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1612 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1613 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1617 * Update non existent contact.
1619 * @param testName the test name
1620 * @throws Exception the exception
1622 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1623 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1624 public void updateNonExistentContact(String testName) throws Exception {
1625 // Currently a no-op test
1628 // ---------------------------------------------------------------
1629 // CRUD tests : DELETE tests
1630 // ---------------------------------------------------------------
1633 // Note: delete sub-resources in ascending hierarchical order,
1634 // before deleting their parents.
1639 * @param testName the test name
1640 * @throws Exception the exception
1642 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1643 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1644 public void deleteContact(String testName) throws Exception {
1646 if (logger.isDebugEnabled()) {
1647 logger.debug(testBanner(testName, CLASS_NAME));
1652 if(logger.isDebugEnabled()){
1653 logger.debug("parentcsid =" + knownResourceId +
1654 " itemcsid = " + knownItemResourceId +
1655 " csid = " + knownContactResourceId);
1658 // Submit the request to the service and store the response.
1659 OrgAuthorityClient client = new OrgAuthorityClient();
1660 ClientResponse<Response> res =
1661 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1662 int statusCode = res.getStatus();
1664 // Check the status code of the response: does it match
1665 // the expected response(s)?
1666 if(logger.isDebugEnabled()){
1667 logger.debug(testName + ": status = " + statusCode);
1669 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1670 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1671 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1677 * @param testName the test name
1678 * @throws Exception the exception
1680 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1681 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1682 public void deleteItem(String testName) throws Exception {
1684 if (logger.isDebugEnabled()) {
1685 logger.debug(testBanner(testName, CLASS_NAME));
1690 if(logger.isDebugEnabled()){
1691 logger.debug("parentcsid =" + knownResourceId +
1692 " itemcsid = " + knownItemResourceId);
1695 // Submit the request to the service and store the response.
1696 OrgAuthorityClient client = new OrgAuthorityClient();
1697 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1698 int statusCode = res.getStatus();
1700 // Check the status code of the response: does it match
1701 // the expected response(s)?
1702 if(logger.isDebugEnabled()){
1703 logger.debug(testName + ": status = " + statusCode);
1705 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1706 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1707 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1711 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1714 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1715 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1716 public void delete(String testName) throws Exception {
1718 if (logger.isDebugEnabled()) {
1719 logger.debug(testBanner(testName, CLASS_NAME));
1724 if(logger.isDebugEnabled()){
1725 logger.debug("parentcsid =" + knownResourceId);
1728 // Submit the request to the service and store the response.
1729 OrgAuthorityClient client = new OrgAuthorityClient();
1730 ClientResponse<Response> res = client.delete(knownResourceId);
1731 int statusCode = res.getStatus();
1733 // Check the status code of the response: does it match
1734 // the expected response(s)?
1735 if(logger.isDebugEnabled()){
1736 logger.debug(testName + ": status = " + statusCode);
1738 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1739 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1740 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1745 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1748 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1749 groups = {"delete"}, dependsOnMethods = {"delete"})
1750 public void deleteNonExistent(String testName) throws Exception {
1752 if (logger.isDebugEnabled()) {
1753 logger.debug(testBanner(testName, CLASS_NAME));
1756 setupDeleteNonExistent();
1758 // Submit the request to the service and store the response.
1759 OrgAuthorityClient client = new OrgAuthorityClient();
1760 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1761 int statusCode = res.getStatus();
1763 // Check the status code of the response: does it match
1764 // the expected response(s)?
1765 if(logger.isDebugEnabled()){
1766 logger.debug(testName + ": status = " + statusCode);
1768 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1769 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1770 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1774 * Delete non existent item.
1776 * @param testName the test name
1778 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1779 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1780 public void deleteNonExistentItem(String testName) {
1782 if (logger.isDebugEnabled()) {
1783 logger.debug(testBanner(testName, CLASS_NAME));
1786 setupDeleteNonExistent();
1788 // Submit the request to the service and store the response.
1789 OrgAuthorityClient client = new OrgAuthorityClient();
1790 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1791 int statusCode = res.getStatus();
1793 // Check the status code of the response: does it match
1794 // the expected response(s)?
1795 if(logger.isDebugEnabled()){
1796 logger.debug(testName + ": status = " + statusCode);
1798 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1799 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1800 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1804 * Delete non existent contact.
1806 * @param testName the test name
1808 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1809 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1810 public void deleteNonExistentContact(String testName) {
1812 if (logger.isDebugEnabled()) {
1813 logger.debug(testBanner(testName, CLASS_NAME));
1816 setupDeleteNonExistent();
1818 // Submit the request to the service and store the response.
1819 OrgAuthorityClient client = new OrgAuthorityClient();
1820 ClientResponse<Response> res =
1821 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1822 int statusCode = res.getStatus();
1824 // Check the status code of the response: does it match
1825 // the expected response(s)?
1826 if(logger.isDebugEnabled()){
1827 logger.debug(testName + ": status = " + statusCode);
1829 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1830 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1831 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1834 // ---------------------------------------------------------------
1835 // Utility tests : tests of code used in tests above
1836 // ---------------------------------------------------------------
1838 * Tests the code for manually submitting data that is used by several
1839 * of the methods above.
1841 @Test(dependsOnMethods = {"create", "read"})
1842 public void testSubmitRequest() {
1844 // Expected status code: 200 OK
1845 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1847 // Submit the request to the service and store the response.
1848 String method = ServiceRequestType.READ.httpMethodName();
1849 String url = getResourceURL(knownResourceId);
1850 int statusCode = submitRequest(method, url);
1852 // Check the status code of the response: does it match
1853 // the expected response(s)?
1854 if(logger.isDebugEnabled()){
1855 logger.debug("testSubmitRequest: url=" + url +
1856 " status=" + statusCode);
1858 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1863 * Test item submit request.
1865 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1866 public void testItemSubmitRequest() {
1868 // Expected status code: 200 OK
1869 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1871 // Submit the request to the service and store the response.
1872 String method = ServiceRequestType.READ.httpMethodName();
1873 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1874 int statusCode = submitRequest(method, url);
1876 // Check the status code of the response: does it match
1877 // the expected response(s)?
1878 if(logger.isDebugEnabled()){
1879 logger.debug("testItemSubmitRequest: url=" + url +
1880 " status=" + statusCode);
1882 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1887 * Test contact submit request.
1889 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
1890 public void testContactSubmitRequest() {
1892 // Expected status code: 200 OK
1893 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1895 // Submit the request to the service and store the response.
1896 String method = ServiceRequestType.READ.httpMethodName();
1897 String url = getContactResourceURL(knownResourceId,
1898 knownItemResourceId, knownContactResourceId);
1899 int statusCode = submitRequest(method, url);
1901 // Check the status code of the response: does it match
1902 // the expected response(s)?
1903 if(logger.isDebugEnabled()){
1904 logger.debug("testItemSubmitRequest: url=" + url +
1905 " status=" + statusCode);
1907 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1912 // ---------------------------------------------------------------
1913 // Cleanup of resources created during testing
1914 // ---------------------------------------------------------------
1917 * Deletes all resources created by tests, after all tests have been run.
1919 * This cleanup method will always be run, even if one or more tests fail.
1920 * For this reason, it attempts to remove all resources created
1921 * at any point during testing, even if some of those resources
1922 * may be expected to be deleted by certain tests.
1925 @AfterClass(alwaysRun=true)
1927 public void cleanUp() {
1928 String noTest = System.getProperty("noTestCleanup");
1929 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1930 if (logger.isDebugEnabled()) {
1931 logger.debug("Skipping Cleanup phase ...");
1935 if (logger.isDebugEnabled()) {
1936 logger.debug("Cleaning up temporary resources created for testing ...");
1939 String parentResourceId;
1940 String itemResourceId;
1941 String contactResourceId;
1942 // Clean up contact resources.
1943 parentResourceId = knownResourceId;
1944 OrgAuthorityClient client = new OrgAuthorityClient();
1945 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
1946 contactResourceId = entry.getKey();
1947 itemResourceId = entry.getValue();
1948 // Note: Any non-success responses from the delete operation
1949 // below are ignored and not reported.
1950 ClientResponse<Response> res =
1951 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
1952 res.releaseConnection();
1954 // Clean up item resources.
1955 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1956 itemResourceId = entry.getKey();
1957 parentResourceId = entry.getValue();
1958 // Note: Any non-success responses from the delete operation
1959 // below are ignored and not reported.
1960 ClientResponse<Response> res =
1961 client.deleteItem(parentResourceId, itemResourceId);
1962 res.releaseConnection();
1964 // Clean up parent resources.
1969 // ---------------------------------------------------------------
1970 // Utility methods used by tests above
1971 // ---------------------------------------------------------------
1973 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
1976 public String getServicePathComponent() {
1977 return SERVICE_PATH_COMPONENT;
1981 * Gets the item service path component.
1983 * @return the item service path component
1985 public String getItemServicePathComponent() {
1986 return ITEM_SERVICE_PATH_COMPONENT;
1990 * Gets the contact service path component.
1992 * @return the contact service path component
1994 public String getContactServicePathComponent() {
1995 return CONTACT_SERVICE_PATH_COMPONENT;
1999 * Returns the root URL for the item service.
2001 * This URL consists of a base URL for all services, followed by
2002 * a path component for the owning parent, followed by the
2003 * path component for the items.
2005 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2006 * parent authority resource of the relevant item resource.
2008 * @return The root URL for the item service.
2010 protected String getItemServiceRootURL(String parentResourceIdentifier) {
2011 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
2015 * Returns the URL of a specific item resource managed by a service, and
2016 * designated by an identifier (such as a universally unique ID, or UUID).
2018 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2019 * parent authority resource of the relevant item resource.
2021 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2024 * @return The URL of a specific item resource managed by a service.
2026 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
2027 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
2032 * Returns the root URL for the contact service.
2034 * This URL consists of a base URL for all services, followed by
2035 * a path component for the owning authority, followed by the
2036 * path component for the owning item, followed by the path component
2037 * for the contact service.
2039 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2040 * parent authority resource of the relevant item resource.
2042 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2045 * @return The root URL for the contact service.
2047 protected String getContactServiceRootURL(String parentResourceIdentifier,
2048 String itemResourceIdentifier) {
2049 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
2050 getContactServicePathComponent();
2054 * Returns the URL of a specific contact resource managed by a service, and
2055 * designated by an identifier (such as a universally unique ID, or UUID).
2057 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2058 * parent resource of the relevant item resource.
2060 * @param resourceIdentifier An identifier (such as a UUID) for an
2063 * @return The URL of a specific resource managed by a service.
2065 protected String getContactResourceURL(String parentResourceIdentifier,
2066 String itemResourceIdentifier, String contactResourceIdentifier) {
2067 return getContactServiceRootURL(parentResourceIdentifier,
2068 itemResourceIdentifier) + "/" + contactResourceIdentifier;