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);
820 int statusCode = res.getStatus();
822 // Check the status code of the response: does it match
823 // the expected response(s)?
824 if(logger.isDebugEnabled()){
825 logger.debug(testName + ": status = " + statusCode);
827 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
828 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
829 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
831 // Check whether organization has expected displayName.
832 MultipartInput input = (MultipartInput) res.getEntity();
833 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
834 client.getItemCommonPartName(), OrganizationsCommon.class);
835 Assert.assertNotNull(organization);
836 // Try to Update with computed false and no displayName
837 organization.setDisplayNameComputed(false);
838 organization.setDisplayName(null);
840 // Submit the updated resource to the service and store the response.
841 MultipartOutput output = new MultipartOutput();
842 OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
843 commonPart.getHeaders().add("label", client.getItemCommonPartName());
844 res.releaseConnection();
845 res = client.updateItem(knownResourceId, knownItemResourceId, output);
846 statusCode = res.getStatus();
848 // Check the status code of the response: does it match the expected response(s)?
849 if(logger.isDebugEnabled()){
850 logger.debug("updateItem: status = " + statusCode);
852 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
853 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
854 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
856 res.releaseConnection();
863 * @param testName the test name
864 * @throws Exception the exception
866 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
867 groups = {"readItem"}, dependsOnMethods = {"readItem"})
868 public void readContact(String testName) throws Exception {
870 if (logger.isDebugEnabled()) {
871 logger.debug(testBanner(testName, CLASS_NAME));
876 // Submit the request to the service and store the response.
877 OrgAuthorityClient client = new OrgAuthorityClient();
878 ClientResponse<MultipartInput> res =
879 client.readContact(knownResourceId, knownItemResourceId,
880 knownContactResourceId);
882 int statusCode = res.getStatus();
884 // Check the status code of the response: does it match
885 // the expected response(s)?
886 if(logger.isDebugEnabled()){
887 logger.debug(testName + ": status = " + statusCode);
889 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
890 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
891 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
893 // Check whether we've received a contact.
894 MultipartInput input = (MultipartInput) res.getEntity();
895 ContactsCommon contact = (ContactsCommon) extractPart(input,
896 new ContactClient().getCommonPartName(), ContactsCommon.class);
897 Assert.assertNotNull(contact);
898 boolean showFull = true;
899 if(showFull && logger.isDebugEnabled()){
900 logger.debug(testName + ": returned payload:");
901 logger.debug(objectAsXmlString(contact, ContactsCommon.class));
903 Assert.assertEquals(contact.getInAuthority(), knownResourceId);
904 Assert.assertEquals(contact.getInItem(), knownItemResourceId);
906 res.releaseConnection();
912 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
915 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
916 groups = {"read"}, dependsOnMethods = {"read"})
917 public void readNonExistent(String testName) {
919 if (logger.isDebugEnabled()) {
920 logger.debug(testBanner(testName, CLASS_NAME));
923 setupReadNonExistent();
925 // Submit the request to the service and store the response.
926 OrgAuthorityClient client = new OrgAuthorityClient();
927 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
929 int statusCode = res.getStatus();
931 // Check the status code of the response: does it match
932 // the expected response(s)?
933 if(logger.isDebugEnabled()){
934 logger.debug(testName + ": status = " + statusCode);
936 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
937 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
938 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
940 res.releaseConnection();
945 * Read item non existent.
947 * @param testName the test name
949 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
950 groups = {"readItem"}, dependsOnMethods = {"readItem"})
951 public void readItemNonExistent(String testName) {
953 if (logger.isDebugEnabled()) {
954 logger.debug(testBanner(testName, CLASS_NAME));
957 setupReadNonExistent();
959 // Submit the request to the service and store the response.
960 OrgAuthorityClient client = new OrgAuthorityClient();
961 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
963 int statusCode = res.getStatus();
965 // Check the status code of the response: does it match
966 // the expected response(s)?
967 if(logger.isDebugEnabled()){
968 logger.debug(testName + ": status = " + statusCode);
970 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
971 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
972 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
974 res.releaseConnection();
979 * Read contact non existent.
981 * @param testName the test name
983 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
984 groups = {"readItem"}, dependsOnMethods = {"readContact"})
985 public void readContactNonExistent(String testName) {
987 if (logger.isDebugEnabled()) {
988 logger.debug(testBanner(testName, CLASS_NAME));
991 setupReadNonExistent();
993 // Submit the request to the service and store the response.
994 OrgAuthorityClient client = new OrgAuthorityClient();
995 ClientResponse<MultipartInput> res =
996 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
998 int statusCode = res.getStatus();
1000 // Check the status code of the response: does it match
1001 // the expected response(s)?
1002 if(logger.isDebugEnabled()){
1003 logger.debug(testName + ": status = " + statusCode);
1005 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1006 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1007 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1009 res.releaseConnection();
1013 // ---------------------------------------------------------------
1014 // CRUD tests : READ_LIST tests
1015 // ---------------------------------------------------------------
1019 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
1022 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1023 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
1024 public void readList(String testName) throws Exception {
1026 if (logger.isDebugEnabled()) {
1027 logger.debug(testBanner(testName, CLASS_NAME));
1032 // Submit the request to the service and store the response.
1033 OrgAuthorityClient client = new OrgAuthorityClient();
1034 ClientResponse<OrgauthoritiesCommonList> res = client.readList();
1036 OrgauthoritiesCommonList list = res.getEntity();
1037 int statusCode = res.getStatus();
1039 // Check the status code of the response: does it match
1040 // the expected response(s)?
1041 if(logger.isDebugEnabled()){
1042 logger.debug(testName + ": status = " + statusCode);
1044 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1045 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1046 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1048 // Optionally output additional data about list members for debugging.
1049 boolean iterateThroughList = false;
1050 if (iterateThroughList && logger.isDebugEnabled()) {
1051 List<OrgauthoritiesCommonList.OrgauthorityListItem> items =
1052 list.getOrgauthorityListItem();
1054 for (OrgauthoritiesCommonList.OrgauthorityListItem item : items) {
1055 String csid = item.getCsid();
1056 logger.debug(testName + ": list-item[" + i + "] csid=" +
1058 logger.debug(testName + ": list-item[" + i + "] displayName=" +
1059 item.getDisplayName());
1060 logger.debug(testName + ": list-item[" + i + "] URI=" +
1062 readItemList(csid, null);
1067 res.releaseConnection();
1074 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
1075 public void readItemList() {
1076 readItemList(knownResourceId, null);
1080 * Read item list by authority name.
1082 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1083 public void readItemListByAuthorityName() {
1084 readItemList(null, knownResourceShortIdentifer);
1090 * @param vcsid the vcsid
1091 * @param name the name
1093 private void readItemList(String vcsid, String name) {
1095 final String testName = "readItemList";
1097 if (logger.isDebugEnabled()) {
1098 logger.debug(testBanner(testName, CLASS_NAME));
1103 // Submit the request to the service and store the response.
1104 OrgAuthorityClient client = new OrgAuthorityClient();
1105 ClientResponse<OrganizationsCommonList> res = null;
1107 res = client.readItemList(vcsid, null, null);
1108 } else if(name!= null) {
1109 res = client.readItemListForNamedAuthority(name, null, null);
1111 Assert.fail("readItemList passed null csid and name!");
1114 OrganizationsCommonList list = res.getEntity();
1115 int statusCode = res.getStatus();
1117 // Check the status code of the response: does it match
1118 // the expected response(s)?
1119 if(logger.isDebugEnabled()){
1120 logger.debug(testName + ": status = " + statusCode);
1122 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1123 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1124 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1126 List<OrganizationsCommonList.OrganizationListItem> items =
1127 list.getOrganizationListItem();
1128 int nItemsReturned = items.size();
1129 // There will be one item created, associated with a
1130 // known parent resource, by the createItem test.
1132 // In addition, there will be 'nItemsToCreateInList'
1133 // additional items created by the createItemList test,
1134 // all associated with the same parent resource.
1135 int nExpectedItems = nItemsToCreateInList + 1;
1136 if(logger.isDebugEnabled()){
1137 logger.debug(testName + ": Expected "
1138 + nExpectedItems +" items; got: "+nItemsReturned);
1140 Assert.assertEquals(nItemsReturned, nExpectedItems);
1143 for (OrganizationsCommonList.OrganizationListItem item : items) {
1144 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
1145 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
1146 // Optionally output additional data about list members for debugging.
1147 boolean showDetails = true;
1148 if (showDetails && logger.isDebugEnabled()) {
1149 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1151 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
1153 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
1154 item.getDisplayName());
1155 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1161 res.releaseConnection();
1166 * Read contact list.
1168 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1169 public void readContactList() {
1170 readContactList(knownResourceId, knownItemResourceId);
1174 * Read contact list.
1176 * @param parentcsid the parentcsid
1177 * @param itemcsid the itemcsid
1179 private void readContactList(String parentcsid, String itemcsid) {
1180 final String testName = "readContactList";
1182 if (logger.isDebugEnabled()) {
1183 logger.debug(testBanner(testName, CLASS_NAME));
1188 // Submit the request to the service and store the response.
1189 OrgAuthorityClient client = new OrgAuthorityClient();
1190 ContactsCommonList list = null;
1191 ClientResponse<ContactsCommonList> res =
1192 client.readContactList(parentcsid, itemcsid);
1194 list = res.getEntity();
1195 int statusCode = res.getStatus();
1197 // Check the status code of the response: does it match
1198 // the expected response(s)?
1199 if(logger.isDebugEnabled()){
1200 logger.debug(testName + ": status = " + statusCode);
1202 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1203 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1204 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1206 List<ContactsCommonList.ContactListItem> listitems =
1207 list.getContactListItem();
1208 int nItemsReturned = listitems.size();
1209 // There will be one item created, associated with a
1210 // known parent resource, by the createItem test.
1212 // In addition, there will be 'nItemsToCreateInList'
1213 // additional items created by the createItemList test,
1214 // all associated with the same parent resource.
1215 int nExpectedItems = nItemsToCreateInList + 1;
1216 if(logger.isDebugEnabled()){
1217 logger.debug(testName + ": Expected "
1218 + nExpectedItems +" items; got: "+nItemsReturned);
1220 Assert.assertEquals(nItemsReturned, nExpectedItems);
1223 for (ContactsCommonList.ContactListItem listitem : listitems) {
1224 // Optionally output additional data about list members for debugging.
1225 boolean showDetails = false;
1226 if (showDetails && logger.isDebugEnabled()) {
1227 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1228 listitem.getCsid());
1229 logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" +
1230 listitem.getAddressPlace());
1231 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1237 res.releaseConnection();
1244 // ---------------------------------------------------------------
1245 // CRUD tests : UPDATE tests
1246 // ---------------------------------------------------------------
1249 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
1252 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1253 groups = {"update"}, dependsOnGroups = {"read", "readList"})
1254 public void update(String testName) throws Exception {
1256 if (logger.isDebugEnabled()) {
1257 logger.debug(testBanner(testName, CLASS_NAME));
1262 // Retrieve the contents of a resource to update.
1263 OrgAuthorityClient client = new OrgAuthorityClient();
1264 ClientResponse<MultipartInput> res =
1265 client.read(knownResourceId);
1267 if(logger.isDebugEnabled()){
1268 logger.debug(testName + ": read status = " + res.getStatus());
1270 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1272 if(logger.isDebugEnabled()){
1273 logger.debug("got OrgAuthority to update with ID: " + knownResourceId);
1275 MultipartInput input = (MultipartInput) res.getEntity();
1276 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
1277 client.getCommonPartName(), OrgauthoritiesCommon.class);
1278 Assert.assertNotNull(orgAuthority);
1280 // Update the contents of this resource.
1281 orgAuthority.setDisplayName("updated-" + orgAuthority.getDisplayName());
1282 orgAuthority.setVocabType("updated-" + orgAuthority.getVocabType());
1283 if(logger.isDebugEnabled()){
1284 logger.debug("to be updated OrgAuthority");
1285 logger.debug(objectAsXmlString(orgAuthority, OrgauthoritiesCommon.class));
1288 // Submit the updated resource to the service and store the response.
1289 MultipartOutput output = new MultipartOutput();
1290 OutputPart commonPart = output.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE);
1291 commonPart.getHeaders().add("label", client.getCommonPartName());
1292 res.releaseConnection();
1293 res = client.update(knownResourceId, output);
1294 int statusCode = res.getStatus();
1296 // Check the status code of the response: does it match the expected response(s)?
1297 if(logger.isDebugEnabled()){
1298 logger.debug(testName + ": status = " + statusCode);
1300 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1301 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1302 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1304 // Retrieve the updated resource and verify that its contents exist.
1305 input = (MultipartInput) res.getEntity();
1306 OrgauthoritiesCommon updatedOrgAuthority =
1307 (OrgauthoritiesCommon) extractPart(input,
1308 client.getCommonPartName(), OrgauthoritiesCommon.class);
1309 Assert.assertNotNull(updatedOrgAuthority);
1311 // Verify that the updated resource received the correct data.
1312 Assert.assertEquals(updatedOrgAuthority.getDisplayName(),
1313 orgAuthority.getDisplayName(),
1314 "Data in updated object did not match submitted data.");
1316 res.releaseConnection();
1323 * @param testName the test name
1324 * @throws Exception the exception
1326 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1327 groups = {"update"}, dependsOnMethods = {"update"})
1328 public void updateItem(String testName) throws Exception {
1330 if (logger.isDebugEnabled()) {
1331 logger.debug(testBanner(testName, CLASS_NAME));
1336 // Retrieve the contents of a resource to update.
1337 OrgAuthorityClient client = new OrgAuthorityClient();
1338 ClientResponse<MultipartInput> res =
1339 client.readItem(knownResourceId, knownItemResourceId);
1341 if(logger.isDebugEnabled()){
1342 logger.debug(testName + ": read status = " + res.getStatus());
1344 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1346 if(logger.isDebugEnabled()){
1347 logger.debug("got Organization to update with ID: " +
1348 knownItemResourceId +
1349 " in OrgAuthority: " + knownResourceId );
1351 MultipartInput input = (MultipartInput) res.getEntity();
1352 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
1353 client.getItemCommonPartName(), OrganizationsCommon.class);
1354 Assert.assertNotNull(organization);
1356 // Update the contents of this resource.
1357 organization.setCsid(null);
1358 organization.setShortName("updated-" + organization.getShortName());
1359 if(logger.isDebugEnabled()){
1360 logger.debug("to be updated Organization");
1361 logger.debug(objectAsXmlString(organization,
1362 OrganizationsCommon.class));
1365 // Submit the updated resource to the service and store the response.
1366 MultipartOutput output = new MultipartOutput();
1367 OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
1368 commonPart.getHeaders().add("label", client.getItemCommonPartName());
1369 res.releaseConnection();
1370 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1371 int statusCode = res.getStatus();
1373 // Check the status code of the response: does it match the expected response(s)?
1374 if(logger.isDebugEnabled()){
1375 logger.debug(testName + ": status = " + statusCode);
1377 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1378 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1379 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1381 // Retrieve the updated resource and verify that its contents exist.
1382 input = (MultipartInput) res.getEntity();
1383 OrganizationsCommon updatedOrganization =
1384 (OrganizationsCommon) extractPart(input,
1385 client.getItemCommonPartName(), OrganizationsCommon.class);
1386 Assert.assertNotNull(updatedOrganization);
1388 // Verify that the updated resource received the correct data.
1389 Assert.assertEquals(updatedOrganization.getShortName(),
1390 organization.getShortName(),
1391 "Data in updated Organization did not match submitted data.");
1393 res.releaseConnection();
1400 * @param testName the test name
1401 * @throws Exception the exception
1403 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1404 groups = {"update"}, dependsOnMethods = {"updateItem"})
1405 public void updateContact(String testName) throws Exception {
1407 if (logger.isDebugEnabled()) {
1408 logger.debug(testBanner(testName, CLASS_NAME));
1413 // Retrieve the contents of a resource to update.
1414 OrgAuthorityClient client = new OrgAuthorityClient();
1415 ClientResponse<MultipartInput> res =
1416 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1418 if(logger.isDebugEnabled()){
1419 logger.debug(testName + ": read status = " + res.getStatus());
1421 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1423 if(logger.isDebugEnabled()){
1424 logger.debug("got Contact to update with ID: " +
1425 knownContactResourceId +
1426 " in item: " + knownItemResourceId +
1427 " in parent: " + knownResourceId );
1429 MultipartInput input = (MultipartInput) res.getEntity();
1430 ContactsCommon contact = (ContactsCommon) extractPart(input,
1431 new ContactClient().getCommonPartName(), ContactsCommon.class);
1432 Assert.assertNotNull(contact);
1434 // Update the contents of this resource.
1435 contact.setAddressPlace("updated-" + contact.getAddressPlace());
1436 if(logger.isDebugEnabled()){
1437 logger.debug("to be updated Contact");
1438 logger.debug(objectAsXmlString(contact,
1439 ContactsCommon.class));
1442 // Submit the updated resource to the service and store the response.
1443 MultipartOutput output = new MultipartOutput();
1444 OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1445 commonPart.getHeaders().add("label", new ContactClient().getCommonPartName());
1446 res.releaseConnection();
1447 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1448 int statusCode = res.getStatus();
1450 // Check the status code of the response: does it match the expected response(s)?
1451 if(logger.isDebugEnabled()){
1452 logger.debug(testName + ": status = " + statusCode);
1454 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1455 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1456 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1458 // Retrieve the updated resource and verify that its contents exist.
1459 input = (MultipartInput) res.getEntity();
1460 ContactsCommon updatedContact =
1461 (ContactsCommon) extractPart(input,
1462 new ContactClient().getCommonPartName(), ContactsCommon.class);
1463 Assert.assertNotNull(updatedContact);
1465 // Verify that the updated resource received the correct data.
1466 Assert.assertEquals(updatedContact.getAddressPlace(),
1467 contact.getAddressPlace(),
1468 "Data in updated Contact did not match submitted data.");
1470 res.releaseConnection();
1475 // Placeholders until the three tests below can be uncommented.
1476 // See Issue CSPACE-401.
1478 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1481 public void updateWithEmptyEntityBody(String testName) throws Exception {
1482 //Should this really be empty?
1486 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1489 public void updateWithMalformedXml(String testName) throws Exception {
1490 //Should this really be empty?
1494 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1497 public void updateWithWrongXmlSchema(String testName) throws Exception {
1498 //Should this really be empty?
1503 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1504 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1505 public void updateWithEmptyEntityBody(String testName) throws Exception {
1507 if (logger.isDebugEnabled()) {
1508 logger.debug(testBanner(testName, CLASS_NAME));
1511 setupUpdateWithEmptyEntityBody();
1513 // Submit the request to the service and store the response.
1514 String method = REQUEST_TYPE.httpMethodName();
1515 String url = getResourceURL(knownResourceId);
1516 String mediaType = MediaType.APPLICATION_XML;
1517 final String entity = "";
1518 int statusCode = submitRequest(method, url, mediaType, entity);
1520 // Check the status code of the response: does it match
1521 // the expected response(s)?
1522 if(logger.isDebugEnabled()){
1523 logger.debug(testName + ": url=" + url +
1524 " status=" + statusCode);
1526 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1527 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1528 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1532 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1533 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1534 public void updateWithMalformedXml(String testName) throws Exception {
1536 if (logger.isDebugEnabled()) {
1537 logger.debug(testBanner(testName, CLASS_NAME));
1540 setupUpdateWithMalformedXml();
1542 // Submit the request to the service and store the response.
1543 String method = REQUEST_TYPE.httpMethodName();
1544 String url = getResourceURL(knownResourceId);
1545 String mediaType = MediaType.APPLICATION_XML;
1546 final String entity = MALFORMED_XML_DATA;
1547 int statusCode = submitRequest(method, url, mediaType, entity);
1549 // Check the status code of the response: does it match
1550 // the expected response(s)?
1551 if(logger.isDebugEnabled()){
1552 logger.debug(testName + ": url=" + url +
1553 " status=" + statusCode);
1555 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1556 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1557 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1561 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1562 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1563 public void updateWithWrongXmlSchema(String testName) throws Exception {
1566 setupUpdateWithWrongXmlSchema(testName, logger);
1568 // Submit the request to the service and store the response.
1569 String method = REQUEST_TYPE.httpMethodName();
1570 String url = getResourceURL(knownResourceId);
1571 String mediaType = MediaType.APPLICATION_XML;
1572 final String entity = WRONG_XML_SCHEMA_DATA;
1573 int statusCode = submitRequest(method, url, mediaType, entity);
1575 // Check the status code of the response: does it match
1576 // the expected response(s)?
1577 if(logger.isDebugEnabled()){
1578 logger.debug("updateWithWrongXmlSchema: url=" + url +
1579 " status=" + statusCode);
1581 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1582 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1583 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1588 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1591 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1592 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1593 public void updateNonExistent(String testName) throws Exception {
1595 if (logger.isDebugEnabled()) {
1596 logger.debug(testBanner(testName, CLASS_NAME));
1599 setupUpdateNonExistent();
1601 // Submit the request to the service and store the response.
1602 // Note: The ID used in this 'create' call may be arbitrary.
1603 // The only relevant ID may be the one used in update(), below.
1604 OrgAuthorityClient client = new OrgAuthorityClient();
1605 MultipartOutput multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance(
1606 NON_EXISTENT_ID, NON_EXISTENT_ID,
1607 new OrgAuthorityClient().getCommonPartName());
1608 ClientResponse<MultipartInput> res =
1609 client.update(NON_EXISTENT_ID, multipart);
1611 int statusCode = res.getStatus();
1613 // Check the status code of the response: does it match
1614 // the expected response(s)?
1615 if(logger.isDebugEnabled()){
1616 logger.debug(testName + ": status = " + statusCode);
1618 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1619 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1620 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1622 res.releaseConnection();
1627 * Update non existent item.
1629 * @param testName the test name
1630 * @throws Exception the exception
1632 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1633 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1634 public void updateNonExistentItem(String testName) throws Exception {
1636 if (logger.isDebugEnabled()) {
1637 logger.debug(testBanner(testName, CLASS_NAME));
1640 setupUpdateNonExistent();
1642 // Submit the request to the service and store the response.
1643 // Note: The ID(s) used when creating the request payload may be arbitrary.
1644 // The only relevant ID may be the one used in update(), below.
1645 OrgAuthorityClient client = new OrgAuthorityClient();
1646 Map<String, String> nonexOrgMap = new HashMap<String,String>();
1647 nonexOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, "nonExistent");
1648 nonexOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Non-existent");
1649 MultipartOutput multipart =
1650 OrgAuthorityClientUtils.createOrganizationInstance(
1651 NON_EXISTENT_ID, knownResourceRefName,
1652 nonexOrgMap, client.getItemCommonPartName() );
1653 ClientResponse<MultipartInput> res =
1654 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1656 int statusCode = res.getStatus();
1658 // Check the status code of the response: does it match
1659 // the expected response(s)?
1660 if(logger.isDebugEnabled()){
1661 logger.debug(testName + ": status = " + statusCode);
1663 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1664 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1665 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1667 res.releaseConnection();
1672 * Update non existent contact.
1674 * @param testName the test name
1675 * @throws Exception the exception
1677 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1678 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1679 public void updateNonExistentContact(String testName) throws Exception {
1680 // Currently a no-op test
1683 // ---------------------------------------------------------------
1684 // CRUD tests : DELETE tests
1685 // ---------------------------------------------------------------
1688 // Note: delete sub-resources in ascending hierarchical order,
1689 // before deleting their parents.
1694 * @param testName the test name
1695 * @throws Exception the exception
1697 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1698 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1699 public void deleteContact(String testName) throws Exception {
1701 if (logger.isDebugEnabled()) {
1702 logger.debug(testBanner(testName, CLASS_NAME));
1707 if(logger.isDebugEnabled()){
1708 logger.debug("parentcsid =" + knownResourceId +
1709 " itemcsid = " + knownItemResourceId +
1710 " csid = " + knownContactResourceId);
1713 // Submit the request to the service and store the response.
1714 OrgAuthorityClient client = new OrgAuthorityClient();
1715 ClientResponse<Response> res =
1716 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1718 int statusCode = res.getStatus();
1720 // Check the status code of the response: does it match
1721 // the expected response(s)?
1722 if(logger.isDebugEnabled()){
1723 logger.debug(testName + ": status = " + statusCode);
1725 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1726 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1727 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1729 res.releaseConnection();
1736 * @param testName the test name
1737 * @throws Exception the exception
1739 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1740 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1741 public void deleteItem(String testName) throws Exception {
1743 if (logger.isDebugEnabled()) {
1744 logger.debug(testBanner(testName, CLASS_NAME));
1749 if(logger.isDebugEnabled()){
1750 logger.debug("parentcsid =" + knownResourceId +
1751 " itemcsid = " + knownItemResourceId);
1754 // Submit the request to the service and store the response.
1755 OrgAuthorityClient client = new OrgAuthorityClient();
1756 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1758 int statusCode = res.getStatus();
1760 // Check the status code of the response: does it match
1761 // the expected response(s)?
1762 if(logger.isDebugEnabled()){
1763 logger.debug(testName + ": status = " + statusCode);
1765 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1766 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1767 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1769 res.releaseConnection();
1774 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1777 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1778 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1779 public void delete(String testName) throws Exception {
1781 if (logger.isDebugEnabled()) {
1782 logger.debug(testBanner(testName, CLASS_NAME));
1787 if(logger.isDebugEnabled()){
1788 logger.debug("parentcsid =" + knownResourceId);
1791 // Submit the request to the service and store the response.
1792 OrgAuthorityClient client = new OrgAuthorityClient();
1793 ClientResponse<Response> res = client.delete(knownResourceId);
1795 int statusCode = res.getStatus();
1797 // Check the status code of the response: does it match
1798 // the expected response(s)?
1799 if(logger.isDebugEnabled()){
1800 logger.debug(testName + ": status = " + statusCode);
1802 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1803 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1804 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1806 res.releaseConnection();
1812 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1815 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1816 groups = {"delete"}, dependsOnMethods = {"delete"})
1817 public void deleteNonExistent(String testName) throws Exception {
1819 if (logger.isDebugEnabled()) {
1820 logger.debug(testBanner(testName, CLASS_NAME));
1823 setupDeleteNonExistent();
1825 // Submit the request to the service and store the response.
1826 OrgAuthorityClient client = new OrgAuthorityClient();
1827 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1829 int statusCode = res.getStatus();
1831 // Check the status code of the response: does it match
1832 // the expected response(s)?
1833 if(logger.isDebugEnabled()){
1834 logger.debug(testName + ": status = " + statusCode);
1836 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1837 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1838 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1840 res.releaseConnection();
1845 * Delete non existent item.
1847 * @param testName the test name
1849 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1850 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1851 public void deleteNonExistentItem(String testName) {
1853 if (logger.isDebugEnabled()) {
1854 logger.debug(testBanner(testName, CLASS_NAME));
1857 setupDeleteNonExistent();
1859 // Submit the request to the service and store the response.
1860 OrgAuthorityClient client = new OrgAuthorityClient();
1861 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1863 int statusCode = res.getStatus();
1865 // Check the status code of the response: does it match
1866 // the expected response(s)?
1867 if(logger.isDebugEnabled()){
1868 logger.debug(testName + ": status = " + statusCode);
1870 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1871 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1872 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1874 res.releaseConnection();
1879 * Delete non existent contact.
1881 * @param testName the test name
1883 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1884 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1885 public void deleteNonExistentContact(String testName) {
1887 if (logger.isDebugEnabled()) {
1888 logger.debug(testBanner(testName, CLASS_NAME));
1891 setupDeleteNonExistent();
1893 // Submit the request to the service and store the response.
1894 OrgAuthorityClient client = new OrgAuthorityClient();
1895 ClientResponse<Response> res =
1896 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1898 int statusCode = res.getStatus();
1900 // Check the status code of the response: does it match
1901 // the expected response(s)?
1902 if(logger.isDebugEnabled()){
1903 logger.debug(testName + ": status = " + statusCode);
1905 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1906 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1907 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1909 res.releaseConnection();
1913 // ---------------------------------------------------------------
1914 // Utility tests : tests of code used in tests above
1915 // ---------------------------------------------------------------
1917 * Tests the code for manually submitting data that is used by several
1918 * of the methods above.
1920 @Test(dependsOnMethods = {"create", "read"})
1921 public void testSubmitRequest() {
1923 // Expected status code: 200 OK
1924 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1926 // Submit the request to the service and store the response.
1927 String method = ServiceRequestType.READ.httpMethodName();
1928 String url = getResourceURL(knownResourceId);
1929 int statusCode = submitRequest(method, url);
1931 // Check the status code of the response: does it match
1932 // the expected response(s)?
1933 if(logger.isDebugEnabled()){
1934 logger.debug("testSubmitRequest: url=" + url +
1935 " status=" + statusCode);
1937 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1942 * Test item submit request.
1944 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1945 public void testItemSubmitRequest() {
1947 // Expected status code: 200 OK
1948 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1950 // Submit the request to the service and store the response.
1951 String method = ServiceRequestType.READ.httpMethodName();
1952 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1953 int statusCode = submitRequest(method, url);
1955 // Check the status code of the response: does it match
1956 // the expected response(s)?
1957 if(logger.isDebugEnabled()){
1958 logger.debug("testItemSubmitRequest: url=" + url +
1959 " status=" + statusCode);
1961 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1966 * Test contact submit request.
1968 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
1969 public void testContactSubmitRequest() {
1971 // Expected status code: 200 OK
1972 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1974 // Submit the request to the service and store the response.
1975 String method = ServiceRequestType.READ.httpMethodName();
1976 String url = getContactResourceURL(knownResourceId,
1977 knownItemResourceId, knownContactResourceId);
1978 int statusCode = submitRequest(method, url);
1980 // Check the status code of the response: does it match
1981 // the expected response(s)?
1982 if(logger.isDebugEnabled()){
1983 logger.debug("testItemSubmitRequest: url=" + url +
1984 " status=" + statusCode);
1986 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1991 // ---------------------------------------------------------------
1992 // Cleanup of resources created during testing
1993 // ---------------------------------------------------------------
1996 * Deletes all resources created by tests, after all tests have been run.
1998 * This cleanup method will always be run, even if one or more tests fail.
1999 * For this reason, it attempts to remove all resources created
2000 * at any point during testing, even if some of those resources
2001 * may be expected to be deleted by certain tests.
2004 @AfterClass(alwaysRun=true)
2006 public void cleanUp() {
2007 String noTest = System.getProperty("noTestCleanup");
2008 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
2009 if (logger.isDebugEnabled()) {
2010 logger.debug("Skipping Cleanup phase ...");
2014 if (logger.isDebugEnabled()) {
2015 logger.debug("Cleaning up temporary resources created for testing ...");
2018 String parentResourceId;
2019 String itemResourceId;
2020 String contactResourceId;
2021 // Clean up contact resources.
2022 parentResourceId = knownResourceId;
2023 OrgAuthorityClient client = new OrgAuthorityClient();
2024 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
2025 contactResourceId = entry.getKey();
2026 itemResourceId = entry.getValue();
2027 // Note: Any non-success responses from the delete operation
2028 // below are ignored and not reported.
2029 ClientResponse<Response> res =
2030 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
2031 res.releaseConnection();
2033 // Clean up item resources.
2034 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
2035 itemResourceId = entry.getKey();
2036 parentResourceId = entry.getValue();
2037 // Note: Any non-success responses from the delete operation
2038 // below are ignored and not reported.
2039 ClientResponse<Response> res =
2040 client.deleteItem(parentResourceId, itemResourceId);
2041 res.releaseConnection();
2043 // Clean up parent resources.
2048 // ---------------------------------------------------------------
2049 // Utility methods used by tests above
2050 // ---------------------------------------------------------------
2052 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
2055 public String getServicePathComponent() {
2056 return SERVICE_PATH_COMPONENT;
2060 * Gets the item service path component.
2062 * @return the item service path component
2064 public String getItemServicePathComponent() {
2065 return ITEM_SERVICE_PATH_COMPONENT;
2069 * Gets the contact service path component.
2071 * @return the contact service path component
2073 public String getContactServicePathComponent() {
2074 return CONTACT_SERVICE_PATH_COMPONENT;
2078 * Returns the root URL for the item service.
2080 * This URL consists of a base URL for all services, followed by
2081 * a path component for the owning parent, followed by the
2082 * path component for the items.
2084 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2085 * parent authority resource of the relevant item resource.
2087 * @return The root URL for the item service.
2089 protected String getItemServiceRootURL(String parentResourceIdentifier) {
2090 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
2094 * Returns the URL of a specific item resource managed by a service, and
2095 * designated by an identifier (such as a universally unique ID, or UUID).
2097 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2098 * parent authority resource of the relevant item resource.
2100 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2103 * @return The URL of a specific item resource managed by a service.
2105 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
2106 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
2111 * Returns the root URL for the contact service.
2113 * This URL consists of a base URL for all services, followed by
2114 * a path component for the owning authority, followed by the
2115 * path component for the owning item, followed by the path component
2116 * for the contact service.
2118 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2119 * parent authority resource of the relevant item resource.
2121 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2124 * @return The root URL for the contact service.
2126 protected String getContactServiceRootURL(String parentResourceIdentifier,
2127 String itemResourceIdentifier) {
2128 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
2129 getContactServicePathComponent();
2133 * Returns the URL of a specific contact resource managed by a service, and
2134 * designated by an identifier (such as a universally unique ID, or UUID).
2136 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2137 * parent resource of the relevant item resource.
2139 * @param resourceIdentifier An identifier (such as a UUID) for an
2142 * @return The URL of a specific resource managed by a service.
2144 protected String getContactResourceURL(String parentResourceIdentifier,
2145 String itemResourceIdentifier, String contactResourceIdentifier) {
2146 return getContactServiceRootURL(parentResourceIdentifier,
2147 itemResourceIdentifier) + "/" + contactResourceIdentifier;