2 * This document is a part of the source code and related artifacts
3 * for CollectionSpace, an open source collections management system
4 * for museums and related institutions:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright (c)) 2009 Regents of the University of California
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
15 * https://source.collectionspace.org/collection-space/LICENSE.txt
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 package org.collectionspace.services.client.test;
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.List;
29 import javax.ws.rs.core.MediaType;
30 import javax.ws.rs.core.Response;
32 import org.collectionspace.services.OrganizationJAXBSchema;
33 import org.collectionspace.services.client.CollectionSpaceClient;
34 import org.collectionspace.services.client.ContactClient;
35 import org.collectionspace.services.client.ContactClientUtils;
36 import org.collectionspace.services.contact.ContactsCommon;
37 import org.collectionspace.services.contact.ContactsCommonList;
38 import org.collectionspace.services.client.OrgAuthorityClient;
39 import org.collectionspace.services.client.OrgAuthorityClientUtils;
40 import org.collectionspace.services.jaxb.AbstractCommonList;
41 import org.collectionspace.services.organization.MainBodyGroup;
42 import org.collectionspace.services.organization.MainBodyGroupList;
43 import org.collectionspace.services.organization.OrgauthoritiesCommon;
44 import org.collectionspace.services.organization.OrgauthoritiesCommonList;
45 import org.collectionspace.services.organization.OrganizationsCommon;
46 import org.collectionspace.services.organization.OrganizationsCommonList;
48 import org.jboss.resteasy.client.ClientResponse;
49 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
50 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
51 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
52 import org.slf4j.Logger;
53 import org.slf4j.LoggerFactory;
54 import org.testng.Assert;
55 import org.testng.annotations.AfterClass;
56 import org.testng.annotations.Test;
59 * OrgAuthorityServiceTest, carries out tests against a
60 * deployed and running OrgAuthority Service.
62 * $LastChangedRevision$
65 public class OrgAuthorityServiceTest extends AbstractServiceTestImpl {
68 private final String CLASS_NAME = OrgAuthorityServiceTest.class.getName();
69 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
71 // Instance variables specific to this test.
72 /** The service path component. */
73 final String SERVICE_PATH_COMPONENT = "orgauthorities";
75 /** The item service path component. */
76 final String ITEM_SERVICE_PATH_COMPONENT = "items";
78 /** The contact service path component. */
79 final String CONTACT_SERVICE_PATH_COMPONENT = "contacts";
81 /** The test organization shortname. */
82 private final String TEST_ORG_SHORTNAME = "Test Org";
84 /** The test organization founding place. */
85 private final String TEST_ORG_FOUNDING_PLACE = "Anytown, USA";
87 // Hold some values for a recently created item to verify upon read.
88 private String knownResourceId = null;
89 private String knownResourceShortIdentifer = null;
90 private String knownResourceRefName = null;
91 private String knownItemResourceId = null;
92 private String knownItemResourceShortIdentifer = null;
94 /** The known contact resource id. */
95 private String knownContactResourceId = null;
97 /** The n items to create in list. */
98 private int nItemsToCreateInList = 3;
100 /** The all item resource ids created. */
101 private Map<String, String> allItemResourceIdsCreated =
102 new HashMap<String, String>();
104 /** The all contact resource ids created. */
105 private Map<String, String> allContactResourceIdsCreated =
106 new HashMap<String, String>();
108 protected void setKnownResource( String id, String shortIdentifer,
110 knownResourceId = id;
111 knownResourceShortIdentifer = shortIdentifer;
112 knownResourceRefName = refName;
115 protected void setKnownItemResource( String id, String shortIdentifer ) {
116 knownItemResourceId = id;
117 knownItemResourceShortIdentifer = shortIdentifer;
121 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
124 protected CollectionSpaceClient getClientInstance() {
125 return new OrgAuthorityClient();
129 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
132 protected AbstractCommonList getAbstractCommonList(
133 ClientResponse<AbstractCommonList> response) {
134 return response.getEntity(OrganizationsCommonList.class);
137 // ---------------------------------------------------------------
138 // CRUD tests : CREATE tests
139 // ---------------------------------------------------------------
142 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
145 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
147 public void create(String testName) throws Exception {
149 if (logger.isDebugEnabled()) {
150 logger.debug(testBanner(testName, CLASS_NAME));
152 // Perform setup, such as initializing the type of service request
153 // (e.g. CREATE, DELETE), its valid and expected status codes, and
154 // its associated HTTP method name (e.g. POST, DELETE).
157 // Submit the request to the service and store the response.
158 OrgAuthorityClient client = new OrgAuthorityClient();
159 String shortId = createIdentifier();
160 String displayName = "displayName-" + shortId;
161 String baseRefName = OrgAuthorityClientUtils.createOrgAuthRefName(shortId, null);
162 MultipartOutput multipart =
163 OrgAuthorityClientUtils.createOrgAuthorityInstance(
164 displayName, shortId, client.getCommonPartName());
167 ClientResponse<Response> res = client.create(multipart);
169 int statusCode = res.getStatus();
171 // Check the status code of the response: does it match
172 // the expected response(s)?
175 // Does it fall within the set of valid status codes?
176 // Does it exactly match the expected status code?
177 if(logger.isDebugEnabled()){
178 logger.debug(testName + ": status = " + statusCode);
180 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
181 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
182 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
184 newID = OrgAuthorityClientUtils.extractId(res);
186 res.releaseConnection();
189 // Store the ID returned from the first resource created
190 // for additional tests below.
191 if (knownResourceId == null){
192 setKnownResource( newID, shortId, baseRefName );
193 if (logger.isDebugEnabled()) {
194 logger.debug(testName + ": knownResourceId=" + knownResourceId);
197 // Store the IDs from every resource created by tests,
198 // so they can be deleted after tests have been run.
199 allResourceIdsCreated.add(newID);
205 * @param testName the test name
207 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
208 groups = {"create"}, dependsOnMethods = {"create"})
209 public void createItem(String testName) {
211 String newID = createItemInAuthority(knownResourceId, knownResourceRefName);
215 * Creates the item in authority.
217 * @param vcsid the vcsid
218 * @param authRefName the auth ref name
221 private String createItemInAuthority(String vcsid, String authRefName) {
223 final String testName = "createItemInAuthority";
224 if(logger.isDebugEnabled()){
225 logger.debug(testName + ":...");
228 // Submit the request to the service and store the response.
229 OrgAuthorityClient client = new OrgAuthorityClient();
230 String shortId = "testOrg";
231 Map<String, String> testOrgMap = new HashMap<String,String>();
232 testOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId);
233 testOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, TEST_ORG_SHORTNAME);
234 testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "The real official test organization");
235 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "May 26, 1907");
236 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, TEST_ORG_FOUNDING_PLACE);
238 Map<String, List<String>> testOrgRepeatablesMap = new HashMap<String,List<String>>();
239 List<String> testOrgContactNames = new ArrayList<String>();
240 testOrgContactNames.add("joe@example.org");
241 testOrgContactNames.add("sally@example.org");
242 testOrgRepeatablesMap.put(OrganizationJAXBSchema.CONTACT_NAMES, testOrgContactNames);
244 MainBodyGroupList mainBodyList = new MainBodyGroupList();
245 List<MainBodyGroup> mainBodyGroups = mainBodyList.getMainBodyGroup();
246 MainBodyGroup mainBodyGroup = new MainBodyGroup();
247 mainBodyGroup.setShortName(TEST_ORG_SHORTNAME);
248 mainBodyGroup.setLongName("The real official test organization");
249 mainBodyGroups.add(mainBodyGroup);
251 String newID = OrgAuthorityClientUtils.createItemInAuthority(
252 vcsid, authRefName, testOrgMap, testOrgRepeatablesMap, mainBodyList, client);
254 // Store the ID returned from the first item resource created
255 // for additional tests below.
256 if (knownItemResourceId == null){
257 setKnownItemResource(newID, shortId);
258 if (logger.isDebugEnabled()) {
259 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
263 // Store the IDs from any item resources created
264 // by tests, along with the IDs of their parents, so these items
265 // can be deleted after all tests have been run.
266 allItemResourceIdsCreated.put(newID, vcsid);
272 * Creates the contact.
274 * @param testName the test name
276 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
277 groups = {"create"}, dependsOnMethods = {"createItem"})
278 public void createContact(String testName) {
280 String newID = createContactInItem(knownResourceId, knownItemResourceId);
284 * Creates the contact in item.
286 * @param parentcsid the parentcsid
287 * @param itemcsid the itemcsid
290 private String createContactInItem(String parentcsid, String itemcsid) {
292 final String testName = "createContactInItem";
293 if (logger.isDebugEnabled()) {
294 logger.debug(testBanner(testName, CLASS_NAME));
298 // Submit the request to the service and store the response.
299 OrgAuthorityClient client = new OrgAuthorityClient();
300 String identifier = createIdentifier();
301 MultipartOutput multipart =
302 ContactClientUtils.createContactInstance(parentcsid,
303 itemcsid, identifier, new ContactClient().getCommonPartName());
306 ClientResponse<Response> res =
307 client.createContact(parentcsid, itemcsid, multipart);
309 int statusCode = res.getStatus();
310 // Check the status code of the response: does it match
311 // the expected response(s)?
312 if(logger.isDebugEnabled()){
313 logger.debug(testName + ": status = " + statusCode);
315 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
316 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
317 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
319 newID = OrgAuthorityClientUtils.extractId(res);
321 res.releaseConnection();
324 // Store the ID returned from the first contact resource created
325 // for additional tests below.
326 if (knownContactResourceId == null){
327 knownContactResourceId = newID;
328 if (logger.isDebugEnabled()) {
329 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
333 // Store the IDs from any contact resources created
334 // by tests, along with the IDs of their parent items,
335 // so these items can be deleted after all tests have been run.
336 allContactResourceIdsCreated.put(newID, itemcsid);
343 // Placeholders until the three tests below can be uncommented.
344 // See Issue CSPACE-401.
346 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
349 public void createWithEmptyEntityBody(String testName) throws Exception {
350 //Should this really be empty?
354 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
357 public void createWithMalformedXml(String testName) throws Exception {
358 //Should this really be empty?
362 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
365 public void createWithWrongXmlSchema(String testName) throws Exception {
366 //Should this really be empty?
371 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
372 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
373 public void createWithEmptyEntityBody(String testName) throws Exception {
375 if (logger.isDebugEnabled()) {
376 logger.debug(testBanner(testName, CLASS_NAME));
379 setupCreateWithEmptyEntityBody();
381 // Submit the request to the service and store the response.
382 String method = REQUEST_TYPE.httpMethodName();
383 String url = getServiceRootURL();
384 String mediaType = MediaType.APPLICATION_XML;
385 final String entity = "";
386 int statusCode = submitRequest(method, url, mediaType, entity);
388 // Check the status code of the response: does it match
389 // the expected response(s)?
390 if(logger.isDebugEnabled()) {
391 logger.debug(testName + ": url=" + url +
392 " status=" + statusCode);
394 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
395 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
396 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
400 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
401 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
402 public void createWithMalformedXml(String testName) throws Exception {
404 if (logger.isDebugEnabled()) {
405 logger.debug(testBanner(testName, CLASS_NAME));
408 setupCreateWithMalformedXml();
410 // Submit the request to the service and store the response.
411 String method = REQUEST_TYPE.httpMethodName();
412 String url = getServiceRootURL();
413 String mediaType = MediaType.APPLICATION_XML;
414 final String entity = MALFORMED_XML_DATA; // Constant from base class.
415 int statusCode = submitRequest(method, url, mediaType, entity);
417 // Check the status code of the response: does it match
418 // the expected response(s)?
419 if(logger.isDebugEnabled()){
420 logger.debug(testName + ": url=" + url +
421 " status=" + statusCode);
423 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
424 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
425 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
429 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
430 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
431 public void createWithWrongXmlSchema(String testName) throws Exception {
433 if (logger.isDebugEnabled()) {
434 logger.debug(testBanner(testName, CLASS_NAME));
437 setupCreateWithWrongXmlSchema();
439 // Submit the request to the service and store the response.
440 String method = REQUEST_TYPE.httpMethodName();
441 String url = getServiceRootURL();
442 String mediaType = MediaType.APPLICATION_XML;
443 final String entity = WRONG_XML_SCHEMA_DATA;
444 int statusCode = submitRequest(method, url, mediaType, entity);
446 // Check the status code of the response: does it match
447 // the expected response(s)?
448 if(logger.isDebugEnabled()){
449 logger.debug(testName + ": url=" + url +
450 " status=" + statusCode);
452 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
453 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
454 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
458 // ---------------------------------------------------------------
459 // CRUD tests : CREATE LIST tests
460 // ---------------------------------------------------------------
463 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
466 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
467 groups = {"createList"}, dependsOnGroups = {"create"})
468 public void createList(String testName) throws Exception {
469 for (int i = 0; i < nItemsToCreateInList; i++) {
475 * Creates the item list.
477 * @param testName the test name
478 * @throws Exception the exception
480 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
481 groups = {"createList"}, dependsOnMethods = {"createList"})
482 public void createItemList(String testName) throws Exception {
483 // Add items to the initially-created, known parent record.
484 for (int j = 0; j < nItemsToCreateInList; j++) {
485 createItem(testName);
490 * Creates the contact list.
492 * @param testName the test name
493 * @throws Exception the exception
495 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
496 groups = {"createList"}, dependsOnMethods = {"createItemList"})
497 public void createContactList(String testName) throws Exception {
498 // Add contacts to the initially-created, known item record.
499 for (int j = 0; j < nItemsToCreateInList; j++) {
500 createContact(testName);
504 // ---------------------------------------------------------------
505 // CRUD tests : READ tests
506 // ---------------------------------------------------------------
509 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
512 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
513 groups = {"read"}, dependsOnGroups = {"create"})
514 public void read(String testName) throws Exception {
515 readInternal(testName, knownResourceId, null);
521 * @param testName the test name
522 * @throws Exception the exception
524 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
525 groups = {"read"}, dependsOnGroups = {"create"})
526 public void readByName(String testName) throws Exception {
527 readInternal(testName, null, knownResourceShortIdentifer);
530 protected void readInternal(String testName, String CSID, String shortId) {
532 if (logger.isDebugEnabled()) {
533 logger.debug(testBanner(testName, CLASS_NAME));
538 // Submit the request to the service and store the response.
539 OrgAuthorityClient client = new OrgAuthorityClient();
540 ClientResponse<MultipartInput> res = null;
542 res = client.read(CSID);
543 } else if(shortId!=null) {
544 res = client.readByName(shortId);
546 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
549 int statusCode = res.getStatus();
551 // Check the status code of the response: does it match
552 // the expected response(s)?
553 if(logger.isDebugEnabled()){
554 logger.debug(testName + ": status = " + statusCode);
556 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
557 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
558 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
559 //FIXME: remove the following try catch once Aron fixes signatures
561 MultipartInput input = (MultipartInput) res.getEntity();
562 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
563 new OrgAuthorityClient().getCommonPartName(), OrgauthoritiesCommon.class);
564 Assert.assertNotNull(orgAuthority);
565 } catch (Exception e) {
566 throw new RuntimeException(e);
569 res.releaseConnection();
576 * @param testName the test name
577 * @throws Exception the exception
579 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
580 groups = {"readItem"}, dependsOnGroups = {"read"})
581 public void readItem(String testName) throws Exception {
582 readItemInternal(testName, knownResourceId, null, knownItemResourceId, null);
586 * Read item in Named Auth.
588 * TODO Enable this if we really need this - it is a funky case, where we would have
589 * the shortId of the item, but the CSID of the parent authority!? Unlikely.
591 * @param testName the test name
592 * @throws Exception the exception
593 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
594 groups = {"readItem"}, dependsOnGroups = {"read"})
595 public void readItemInNamedAuth(String testName) throws Exception {
596 readItemInternal(testName, null, knownResourceShortIdentifer, knownItemResourceId, null);
603 * @param testName the test name
604 * @throws Exception the exception
606 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
607 groups = {"readItem"}, dependsOnGroups = {"read"})
608 public void readNamedItem(String testName) throws Exception {
609 readItemInternal(testName, knownResourceId, null, null, knownItemResourceShortIdentifer);
613 * Read Named item in Named Auth.
615 * @param testName the test name
616 * @throws Exception the exception
618 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
619 groups = {"readItem"}, dependsOnGroups = {"read"})
620 public void readNamedItemInNamedAuth(String testName) throws Exception {
621 readItemInternal(testName, null, knownResourceShortIdentifer, null, knownItemResourceShortIdentifer);
624 protected void readItemInternal(String testName,
625 String authCSID, String authShortId, String itemCSID, String itemShortId)
628 if (logger.isDebugEnabled()) {
629 logger.debug(testBanner(testName, CLASS_NAME));
634 // Submit the request to the service and store the response.
635 OrgAuthorityClient client = new OrgAuthorityClient();
636 ClientResponse<MultipartInput> res = null;
639 res = client.readItem(authCSID, itemCSID);
640 } else if(itemShortId!=null) {
641 res = client.readNamedItem(authCSID, itemShortId);
643 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
645 } else if(authShortId!=null) {
647 res = client.readItemInNamedAuthority(authShortId, itemCSID);
648 } else if(itemShortId!=null) {
649 res = client.readNamedItemInNamedAuthority(authShortId, itemShortId);
651 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
654 Assert.fail("readInternal: Internal error. One of authCSID or authShortId must be non-null");
657 int statusCode = res.getStatus();
659 // Check the status code of the response: does it match
660 // the expected response(s)?
661 if(logger.isDebugEnabled()){
662 logger.debug(testName + ": status = " + statusCode);
664 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
665 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
666 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
668 // Check whether we've received a organization.
669 MultipartInput input = (MultipartInput) res.getEntity();
670 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
671 client.getItemCommonPartName(), OrganizationsCommon.class);
672 Assert.assertNotNull(organization);
673 boolean showFull = true;
674 if(showFull && logger.isDebugEnabled()){
675 logger.debug(testName + ": returned payload:");
676 logger.debug(objectAsXmlString(organization, OrganizationsCommon.class));
679 // Check that the organization item is within the expected OrgAuthority.
680 Assert.assertEquals(organization.getInAuthority(), knownResourceId);
682 // Verify the number and contents of values in a repeatable field,
683 // as created in the instance record used for testing.
684 List<String> contactNames = organization.getContactNames().getContactName();
685 Assert.assertTrue(contactNames.size() > 0);
686 Assert.assertNotNull(contactNames.get(0));
689 res.releaseConnection();
694 * Verify item display name.
696 * @param testName the test name
697 * @throws Exception the exception
699 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
700 dependsOnMethods = {"readItem", "updateItem"})
701 public void verifyItemDisplayName(String testName) throws Exception {
703 if (logger.isDebugEnabled()) {
704 logger.debug(testBanner(testName, CLASS_NAME));
709 // Submit the request to the service and store the response.
710 OrgAuthorityClient client = new OrgAuthorityClient();
711 MultipartInput input = null;
712 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
714 int statusCode = res.getStatus();
716 // Check the status code of the response: does it match
717 // the expected response(s)?
718 if(logger.isDebugEnabled()){
719 logger.debug(testName + ": status = " + statusCode);
721 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
722 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
723 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
725 // Check whether organization has expected displayName.
726 input = res.getEntity();
728 res.releaseConnection();
731 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
732 client.getItemCommonPartName(), OrganizationsCommon.class);
733 Assert.assertNotNull(organization);
734 String displayName = organization.getDisplayName();
735 // Make sure displayName matches computed form
736 String expectedDisplayName =
737 OrgAuthorityClientUtils.prepareDefaultDisplayName(
738 TEST_ORG_SHORTNAME, TEST_ORG_FOUNDING_PLACE);
739 Assert.assertNotNull(displayName, expectedDisplayName);
741 // Update the shortName and verify the computed name is updated.
742 organization.setCsid(null);
743 organization.setDisplayNameComputed(true);
745 MainBodyGroupList mainBodyList = organization.getMainBodyGroupList();
746 List<MainBodyGroup> mainBodyGroups = mainBodyList.getMainBodyGroup();
747 MainBodyGroup mainBodyGroup = new MainBodyGroup();
748 String updatedShortName = "updated-" + TEST_ORG_SHORTNAME;
749 mainBodyGroup.setShortName(updatedShortName);
750 mainBodyGroups.add(mainBodyGroup);
751 organization.setMainBodyGroupList(mainBodyList);
753 expectedDisplayName =
754 OrgAuthorityClientUtils.prepareDefaultDisplayName(
755 updatedShortName, TEST_ORG_FOUNDING_PLACE);
757 // Submit the updated resource to the service and store the response.
758 MultipartOutput output = new MultipartOutput();
759 OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
760 commonPart.getHeaders().add("label", client.getItemCommonPartName());
761 res = client.updateItem(knownResourceId, knownItemResourceId, output);
763 int statusCode = res.getStatus();
765 // Check the status code of the response: does it match the expected response(s)?
766 if(logger.isDebugEnabled()){
767 logger.debug("updateItem: status = " + statusCode);
769 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
770 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
771 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
773 // Retrieve the updated resource and verify that its contents exist.
774 input = (MultipartInput) res.getEntity();
776 res.releaseConnection();
779 OrganizationsCommon updatedOrganization =
780 (OrganizationsCommon) extractPart(input,
781 client.getItemCommonPartName(), OrganizationsCommon.class);
782 Assert.assertNotNull(updatedOrganization);
784 // Verify that the updated resource received the correct data.
785 mainBodyList = organization.getMainBodyGroupList();
786 Assert.assertNotNull(mainBodyList);
787 Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0);
788 Assert.assertEquals(updatedOrganization.getMainBodyGroupList().getMainBodyGroup().get(0).getShortName(),
789 updatedShortName, "Updated ShortName in Organization did not match submitted data.");
791 // Verify that the updated resource computes the right displayName.
792 Assert.assertEquals(updatedOrganization.getDisplayName(), expectedDisplayName,
793 "Updated ShortName in Organization not reflected in computed DisplayName.");
795 // Now Update the displayName, not computed and verify the computed name is overriden.
796 organization.setDisplayNameComputed(false);
797 expectedDisplayName = "TestName";
798 organization.setDisplayName(expectedDisplayName);
800 // Submit the updated resource to the service and store the response.
801 output = new MultipartOutput();
802 commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
803 commonPart.getHeaders().add("label", client.getItemCommonPartName());
804 res = client.updateItem(knownResourceId, knownItemResourceId, output);
806 int statusCode = res.getStatus();
808 // Check the status code of the response: does it match the expected response(s)?
809 if(logger.isDebugEnabled()){
810 logger.debug("updateItem: status = " + statusCode);
812 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
813 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
814 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
816 // Retrieve the updated resource and verify that its contents exist.
817 input = (MultipartInput) res.getEntity();
819 res.releaseConnection();
822 updatedOrganization =
823 (OrganizationsCommon) extractPart(input,
824 client.getItemCommonPartName(), OrganizationsCommon.class);
825 Assert.assertNotNull(updatedOrganization);
827 // Verify that the updated resource received the correct data.
828 Assert.assertEquals(updatedOrganization.isDisplayNameComputed(), false,
829 "Updated displayNameComputed in Organization did not match submitted data.");
830 // Verify that the updated resource computes the right displayName.
831 Assert.assertEquals(updatedOrganization.getDisplayName(),
833 "Updated DisplayName (not computed) in Organization not stored.");
837 * Verify illegal item display name.
839 * @param testName the test name
840 * @throws Exception the exception
842 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
843 dependsOnMethods = {"verifyItemDisplayName"})
844 public void verifyIllegalItemDisplayName(String testName) throws Exception {
846 if (logger.isDebugEnabled()) {
847 logger.debug(testBanner(testName, CLASS_NAME));
850 testSetup(STATUS_BAD_REQUEST, ServiceRequestType.UPDATE);
851 // setupUpdateWithWrongXmlSchema(testName, logger);
853 // Submit the request to the service and store the response.
854 OrgAuthorityClient client = new OrgAuthorityClient();
855 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
857 int statusCode = res.getStatus();
859 // Check the status code of the response: does it match
860 // the expected response(s)?
861 if(logger.isDebugEnabled()){
862 logger.debug(testName + ": status = " + statusCode);
864 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
865 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
866 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
868 // Check whether organization has expected displayName.
869 MultipartInput input = (MultipartInput) res.getEntity();
870 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
871 client.getItemCommonPartName(), OrganizationsCommon.class);
872 Assert.assertNotNull(organization);
873 // Try to Update with computed false and no displayName
874 organization.setDisplayNameComputed(false);
875 organization.setDisplayName(null);
877 // Submit the updated resource to the service and store the response.
878 MultipartOutput output = new MultipartOutput();
879 OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
880 commonPart.getHeaders().add("label", client.getItemCommonPartName());
881 res.releaseConnection();
882 res = client.updateItem(knownResourceId, knownItemResourceId, output);
883 statusCode = res.getStatus();
885 // Check the status code of the response: does it match the expected response(s)?
886 if(logger.isDebugEnabled()){
887 logger.debug("updateItem: status = " + statusCode);
889 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
890 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
891 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
893 res.releaseConnection();
900 * @param testName the test name
901 * @throws Exception the exception
903 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
904 groups = {"readItem"}, dependsOnMethods = {"readItem"})
905 public void readContact(String testName) throws Exception {
907 if (logger.isDebugEnabled()) {
908 logger.debug(testBanner(testName, CLASS_NAME));
913 // Submit the request to the service and store the response.
914 OrgAuthorityClient client = new OrgAuthorityClient();
915 ClientResponse<MultipartInput> res =
916 client.readContact(knownResourceId, knownItemResourceId,
917 knownContactResourceId);
919 int statusCode = res.getStatus();
921 // Check the status code of the response: does it match
922 // the expected response(s)?
923 if(logger.isDebugEnabled()){
924 logger.debug(testName + ": status = " + statusCode);
926 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
927 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
928 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
930 // Check whether we've received a contact.
931 MultipartInput input = (MultipartInput) res.getEntity();
932 ContactsCommon contact = (ContactsCommon) extractPart(input,
933 new ContactClient().getCommonPartName(), ContactsCommon.class);
934 Assert.assertNotNull(contact);
935 boolean showFull = true;
936 if(showFull && logger.isDebugEnabled()){
937 logger.debug(testName + ": returned payload:");
938 logger.debug(objectAsXmlString(contact, ContactsCommon.class));
940 Assert.assertEquals(contact.getInAuthority(), knownResourceId);
941 Assert.assertEquals(contact.getInItem(), knownItemResourceId);
943 res.releaseConnection();
949 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
952 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
953 groups = {"read"}, dependsOnMethods = {"read"})
954 public void readNonExistent(String testName) {
956 if (logger.isDebugEnabled()) {
957 logger.debug(testBanner(testName, CLASS_NAME));
960 setupReadNonExistent();
962 // Submit the request to the service and store the response.
963 OrgAuthorityClient client = new OrgAuthorityClient();
964 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
966 int statusCode = res.getStatus();
968 // Check the status code of the response: does it match
969 // the expected response(s)?
970 if(logger.isDebugEnabled()){
971 logger.debug(testName + ": status = " + statusCode);
973 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
974 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
975 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
977 res.releaseConnection();
982 * Read item non existent.
984 * @param testName the test name
986 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
987 groups = {"readItem"}, dependsOnMethods = {"readItem"})
988 public void readItemNonExistent(String testName) {
990 if (logger.isDebugEnabled()) {
991 logger.debug(testBanner(testName, CLASS_NAME));
994 setupReadNonExistent();
996 // Submit the request to the service and store the response.
997 OrgAuthorityClient client = new OrgAuthorityClient();
998 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
1000 int statusCode = res.getStatus();
1002 // Check the status code of the response: does it match
1003 // the expected response(s)?
1004 if(logger.isDebugEnabled()){
1005 logger.debug(testName + ": status = " + statusCode);
1007 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1008 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1009 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1011 res.releaseConnection();
1016 * Read contact non existent.
1018 * @param testName the test name
1020 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1021 groups = {"readItem"}, dependsOnMethods = {"readContact"})
1022 public void readContactNonExistent(String testName) {
1024 if (logger.isDebugEnabled()) {
1025 logger.debug(testBanner(testName, CLASS_NAME));
1028 setupReadNonExistent();
1030 // Submit the request to the service and store the response.
1031 OrgAuthorityClient client = new OrgAuthorityClient();
1032 ClientResponse<MultipartInput> res =
1033 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1035 int statusCode = res.getStatus();
1037 // Check the status code of the response: does it match
1038 // the expected response(s)?
1039 if(logger.isDebugEnabled()){
1040 logger.debug(testName + ": status = " + statusCode);
1042 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1043 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1044 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1046 res.releaseConnection();
1050 // ---------------------------------------------------------------
1051 // CRUD tests : READ_LIST tests
1052 // ---------------------------------------------------------------
1056 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
1059 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1060 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
1061 public void readList(String testName) throws Exception {
1063 if (logger.isDebugEnabled()) {
1064 logger.debug(testBanner(testName, CLASS_NAME));
1069 // Submit the request to the service and store the response.
1070 OrgAuthorityClient client = new OrgAuthorityClient();
1071 ClientResponse<OrgauthoritiesCommonList> res = client.readList();
1073 OrgauthoritiesCommonList list = res.getEntity();
1074 int statusCode = res.getStatus();
1076 // Check the status code of the response: does it match
1077 // the expected response(s)?
1078 if(logger.isDebugEnabled()){
1079 logger.debug(testName + ": status = " + statusCode);
1081 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1082 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1083 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1085 // Optionally output additional data about list members for debugging.
1086 boolean iterateThroughList = false;
1087 if (iterateThroughList && logger.isDebugEnabled()) {
1088 List<OrgauthoritiesCommonList.OrgauthorityListItem> items =
1089 list.getOrgauthorityListItem();
1091 for (OrgauthoritiesCommonList.OrgauthorityListItem item : items) {
1092 String csid = item.getCsid();
1093 logger.debug(testName + ": list-item[" + i + "] csid=" +
1095 logger.debug(testName + ": list-item[" + i + "] displayName=" +
1096 item.getDisplayName());
1097 logger.debug(testName + ": list-item[" + i + "] URI=" +
1099 readItemList(csid, null);
1104 res.releaseConnection();
1111 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
1112 public void readItemList() {
1113 readItemList(knownResourceId, null);
1117 * Read item list by authority name.
1119 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1120 public void readItemListByAuthorityName() {
1121 readItemList(null, knownResourceShortIdentifer);
1127 * @param vcsid the vcsid
1128 * @param name the name
1130 private void readItemList(String vcsid, String name) {
1132 final String testName = "readItemList";
1134 if (logger.isDebugEnabled()) {
1135 logger.debug(testBanner(testName, CLASS_NAME));
1140 // Submit the request to the service and store the response.
1141 OrgAuthorityClient client = new OrgAuthorityClient();
1142 ClientResponse<OrganizationsCommonList> res = null;
1144 res = client.readItemList(vcsid, null, null);
1145 } else if(name!= null) {
1146 res = client.readItemListForNamedAuthority(name, null, null);
1148 Assert.fail("readItemList passed null csid and name!");
1151 OrganizationsCommonList list = res.getEntity();
1152 int statusCode = res.getStatus();
1154 // Check the status code of the response: does it match
1155 // the expected response(s)?
1156 if(logger.isDebugEnabled()){
1157 logger.debug(testName + ": status = " + statusCode);
1159 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1160 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1161 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1163 List<OrganizationsCommonList.OrganizationListItem> items =
1164 list.getOrganizationListItem();
1165 int nItemsReturned = items.size();
1166 // There will be one item created, associated with a
1167 // known parent resource, by the createItem test.
1169 // In addition, there will be 'nItemsToCreateInList'
1170 // additional items created by the createItemList test,
1171 // all associated with the same parent resource.
1172 int nExpectedItems = nItemsToCreateInList + 1;
1173 if(logger.isDebugEnabled()){
1174 logger.debug(testName + ": Expected "
1175 + nExpectedItems +" items; got: "+nItemsReturned);
1177 Assert.assertEquals(nItemsReturned, nExpectedItems);
1180 for (OrganizationsCommonList.OrganizationListItem item : items) {
1181 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
1182 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
1183 // Optionally output additional data about list members for debugging.
1184 boolean showDetails = true;
1185 if (showDetails && logger.isDebugEnabled()) {
1186 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1188 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
1190 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
1191 item.getDisplayName());
1192 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1198 res.releaseConnection();
1203 * Read contact list.
1205 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1206 public void readContactList() {
1207 readContactList(knownResourceId, knownItemResourceId);
1211 * Read contact list.
1213 * @param parentcsid the parentcsid
1214 * @param itemcsid the itemcsid
1216 private void readContactList(String parentcsid, String itemcsid) {
1217 final String testName = "readContactList";
1219 if (logger.isDebugEnabled()) {
1220 logger.debug(testBanner(testName, CLASS_NAME));
1225 // Submit the request to the service and store the response.
1226 OrgAuthorityClient client = new OrgAuthorityClient();
1227 ContactsCommonList list = null;
1228 ClientResponse<ContactsCommonList> res =
1229 client.readContactList(parentcsid, itemcsid);
1231 list = res.getEntity();
1232 int statusCode = res.getStatus();
1234 // Check the status code of the response: does it match
1235 // the expected response(s)?
1236 if(logger.isDebugEnabled()){
1237 logger.debug(testName + ": status = " + statusCode);
1239 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1240 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1241 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1243 List<ContactsCommonList.ContactListItem> listitems =
1244 list.getContactListItem();
1245 int nItemsReturned = listitems.size();
1246 // There will be one item created, associated with a
1247 // known parent resource, by the createItem test.
1249 // In addition, there will be 'nItemsToCreateInList'
1250 // additional items created by the createItemList test,
1251 // all associated with the same parent resource.
1252 int nExpectedItems = nItemsToCreateInList + 1;
1253 if(logger.isDebugEnabled()){
1254 logger.debug(testName + ": Expected "
1255 + nExpectedItems +" items; got: "+nItemsReturned);
1257 Assert.assertEquals(nItemsReturned, nExpectedItems);
1260 for (ContactsCommonList.ContactListItem listitem : listitems) {
1261 // Optionally output additional data about list members for debugging.
1262 boolean showDetails = false;
1263 if (showDetails && logger.isDebugEnabled()) {
1264 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1265 listitem.getCsid());
1266 logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" +
1267 listitem.getAddressPlace());
1268 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1274 res.releaseConnection();
1281 // ---------------------------------------------------------------
1282 // CRUD tests : UPDATE tests
1283 // ---------------------------------------------------------------
1286 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
1289 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1290 groups = {"update"}, dependsOnGroups = {"read", "readList"})
1291 public void update(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.read(knownResourceId);
1304 if(logger.isDebugEnabled()){
1305 logger.debug(testName + ": read status = " + res.getStatus());
1307 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1309 if(logger.isDebugEnabled()){
1310 logger.debug("got OrgAuthority to update with ID: " + knownResourceId);
1312 MultipartInput input = (MultipartInput) res.getEntity();
1313 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
1314 client.getCommonPartName(), OrgauthoritiesCommon.class);
1315 Assert.assertNotNull(orgAuthority);
1317 // Update the contents of this resource.
1318 orgAuthority.setDisplayName("updated-" + orgAuthority.getDisplayName());
1319 orgAuthority.setVocabType("updated-" + orgAuthority.getVocabType());
1320 if(logger.isDebugEnabled()){
1321 logger.debug("to be updated OrgAuthority");
1322 logger.debug(objectAsXmlString(orgAuthority, OrgauthoritiesCommon.class));
1325 // Submit the updated resource to the service and store the response.
1326 MultipartOutput output = new MultipartOutput();
1327 OutputPart commonPart = output.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE);
1328 commonPart.getHeaders().add("label", client.getCommonPartName());
1329 res.releaseConnection();
1330 res = client.update(knownResourceId, output);
1331 int statusCode = res.getStatus();
1333 // Check the status code of the response: does it match the expected response(s)?
1334 if(logger.isDebugEnabled()){
1335 logger.debug(testName + ": status = " + statusCode);
1337 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1338 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1339 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1341 // Retrieve the updated resource and verify that its contents exist.
1342 input = (MultipartInput) res.getEntity();
1343 OrgauthoritiesCommon updatedOrgAuthority =
1344 (OrgauthoritiesCommon) extractPart(input,
1345 client.getCommonPartName(), OrgauthoritiesCommon.class);
1346 Assert.assertNotNull(updatedOrgAuthority);
1348 // Verify that the updated resource received the correct data.
1349 Assert.assertEquals(updatedOrgAuthority.getDisplayName(),
1350 orgAuthority.getDisplayName(),
1351 "Data in updated object did not match submitted data.");
1353 res.releaseConnection();
1360 * @param testName the test name
1361 * @throws Exception the exception
1363 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1364 groups = {"update"}, dependsOnMethods = {"update"})
1365 public void updateItem(String testName) throws Exception {
1367 if (logger.isDebugEnabled()) {
1368 logger.debug(testBanner(testName, CLASS_NAME));
1373 // Retrieve the contents of a resource to update.
1374 OrgAuthorityClient client = new OrgAuthorityClient();
1375 ClientResponse<MultipartInput> res =
1376 client.readItem(knownResourceId, knownItemResourceId);
1378 if(logger.isDebugEnabled()){
1379 logger.debug(testName + ": read status = " + res.getStatus());
1381 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1383 if(logger.isDebugEnabled()){
1384 logger.debug("got Organization to update with ID: " +
1385 knownItemResourceId +
1386 " in OrgAuthority: " + knownResourceId );
1388 MultipartInput input = (MultipartInput) res.getEntity();
1389 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
1390 client.getItemCommonPartName(), OrganizationsCommon.class);
1391 Assert.assertNotNull(organization);
1393 // Update the contents of this resource.
1394 organization.setCsid(null);
1396 MainBodyGroupList mainBodyList = organization.getMainBodyGroupList();
1397 Assert.assertNotNull(mainBodyList);
1398 List<MainBodyGroup> mainBodyGroups = mainBodyList.getMainBodyGroup();
1399 Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0);
1400 String updatedShortName = "updated-" + mainBodyGroups.get(0).getShortName();
1401 mainBodyGroups.get(0).setShortName(updatedShortName);
1403 if(logger.isDebugEnabled()){
1404 logger.debug("to be updated Organization");
1405 logger.debug(objectAsXmlString(organization,
1406 OrganizationsCommon.class));
1409 // Submit the updated resource to the service and store the response.
1410 MultipartOutput output = new MultipartOutput();
1411 OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
1412 commonPart.getHeaders().add("label", client.getItemCommonPartName());
1413 res.releaseConnection();
1414 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1415 int statusCode = res.getStatus();
1417 // Check the status code of the response: does it match the expected response(s)?
1418 if(logger.isDebugEnabled()){
1419 logger.debug(testName + ": status = " + statusCode);
1421 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1422 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1423 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1425 // Retrieve the updated resource and verify that its contents exist.
1426 input = (MultipartInput) res.getEntity();
1427 OrganizationsCommon updatedOrganization =
1428 (OrganizationsCommon) extractPart(input,
1429 client.getItemCommonPartName(), OrganizationsCommon.class);
1430 Assert.assertNotNull(updatedOrganization);
1432 // Verify that the updated resource received the correct data.
1433 mainBodyList = organization.getMainBodyGroupList();
1434 Assert.assertNotNull(mainBodyList);
1435 Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0);
1436 Assert.assertEquals(updatedOrganization.getMainBodyGroupList().getMainBodyGroup().get(0).getShortName(),
1437 updatedShortName, "Data in updated Organization did not match submitted data.");
1439 res.releaseConnection();
1446 * @param testName the test name
1447 * @throws Exception the exception
1449 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1450 groups = {"update"}, dependsOnMethods = {"updateItem"})
1451 public void updateContact(String testName) throws Exception {
1453 if (logger.isDebugEnabled()) {
1454 logger.debug(testBanner(testName, CLASS_NAME));
1459 // Retrieve the contents of a resource to update.
1460 OrgAuthorityClient client = new OrgAuthorityClient();
1461 ClientResponse<MultipartInput> res =
1462 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1464 if(logger.isDebugEnabled()){
1465 logger.debug(testName + ": read status = " + res.getStatus());
1467 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1469 if(logger.isDebugEnabled()){
1470 logger.debug("got Contact to update with ID: " +
1471 knownContactResourceId +
1472 " in item: " + knownItemResourceId +
1473 " in parent: " + knownResourceId );
1475 MultipartInput input = (MultipartInput) res.getEntity();
1476 ContactsCommon contact = (ContactsCommon) extractPart(input,
1477 new ContactClient().getCommonPartName(), ContactsCommon.class);
1478 Assert.assertNotNull(contact);
1480 // Update the contents of this resource.
1481 contact.setAddressPlace("updated-" + contact.getAddressPlace());
1482 if(logger.isDebugEnabled()){
1483 logger.debug("to be updated Contact");
1484 logger.debug(objectAsXmlString(contact,
1485 ContactsCommon.class));
1488 // Submit the updated resource to the service and store the response.
1489 MultipartOutput output = new MultipartOutput();
1490 OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1491 commonPart.getHeaders().add("label", new ContactClient().getCommonPartName());
1492 res.releaseConnection();
1493 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1494 int statusCode = res.getStatus();
1496 // Check the status code of the response: does it match the expected response(s)?
1497 if(logger.isDebugEnabled()){
1498 logger.debug(testName + ": status = " + statusCode);
1500 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1501 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1502 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1504 // Retrieve the updated resource and verify that its contents exist.
1505 input = (MultipartInput) res.getEntity();
1506 ContactsCommon updatedContact =
1507 (ContactsCommon) extractPart(input,
1508 new ContactClient().getCommonPartName(), ContactsCommon.class);
1509 Assert.assertNotNull(updatedContact);
1511 // Verify that the updated resource received the correct data.
1512 Assert.assertEquals(updatedContact.getAddressPlace(),
1513 contact.getAddressPlace(),
1514 "Data in updated Contact did not match submitted data.");
1516 res.releaseConnection();
1521 // Placeholders until the three tests below can be uncommented.
1522 // See Issue CSPACE-401.
1524 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1527 public void updateWithEmptyEntityBody(String testName) throws Exception {
1528 //Should this really be empty?
1532 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1535 public void updateWithMalformedXml(String testName) throws Exception {
1536 //Should this really be empty?
1540 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1543 public void updateWithWrongXmlSchema(String testName) throws Exception {
1544 //Should this really be empty?
1549 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1550 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1551 public void updateWithEmptyEntityBody(String testName) throws Exception {
1553 if (logger.isDebugEnabled()) {
1554 logger.debug(testBanner(testName, CLASS_NAME));
1557 setupUpdateWithEmptyEntityBody();
1559 // Submit the request to the service and store the response.
1560 String method = REQUEST_TYPE.httpMethodName();
1561 String url = getResourceURL(knownResourceId);
1562 String mediaType = MediaType.APPLICATION_XML;
1563 final String entity = "";
1564 int statusCode = submitRequest(method, url, mediaType, entity);
1566 // Check the status code of the response: does it match
1567 // the expected response(s)?
1568 if(logger.isDebugEnabled()){
1569 logger.debug(testName + ": url=" + url +
1570 " status=" + statusCode);
1572 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1573 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1574 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1578 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1579 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1580 public void updateWithMalformedXml(String testName) throws Exception {
1582 if (logger.isDebugEnabled()) {
1583 logger.debug(testBanner(testName, CLASS_NAME));
1586 setupUpdateWithMalformedXml();
1588 // Submit the request to the service and store the response.
1589 String method = REQUEST_TYPE.httpMethodName();
1590 String url = getResourceURL(knownResourceId);
1591 String mediaType = MediaType.APPLICATION_XML;
1592 final String entity = MALFORMED_XML_DATA;
1593 int statusCode = submitRequest(method, url, mediaType, entity);
1595 // Check the status code of the response: does it match
1596 // the expected response(s)?
1597 if(logger.isDebugEnabled()){
1598 logger.debug(testName + ": url=" + url +
1599 " status=" + statusCode);
1601 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1602 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1603 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1607 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1608 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1609 public void updateWithWrongXmlSchema(String testName) throws Exception {
1612 setupUpdateWithWrongXmlSchema(testName, logger);
1614 // Submit the request to the service and store the response.
1615 String method = REQUEST_TYPE.httpMethodName();
1616 String url = getResourceURL(knownResourceId);
1617 String mediaType = MediaType.APPLICATION_XML;
1618 final String entity = WRONG_XML_SCHEMA_DATA;
1619 int statusCode = submitRequest(method, url, mediaType, entity);
1621 // Check the status code of the response: does it match
1622 // the expected response(s)?
1623 if(logger.isDebugEnabled()){
1624 logger.debug("updateWithWrongXmlSchema: url=" + url +
1625 " status=" + statusCode);
1627 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1628 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1629 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1634 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1637 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1638 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1639 public void updateNonExistent(String testName) throws Exception {
1641 if (logger.isDebugEnabled()) {
1642 logger.debug(testBanner(testName, CLASS_NAME));
1645 setupUpdateNonExistent();
1647 // Submit the request to the service and store the response.
1648 // Note: The ID used in this 'create' call may be arbitrary.
1649 // The only relevant ID may be the one used in update(), below.
1650 OrgAuthorityClient client = new OrgAuthorityClient();
1651 MultipartOutput multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance(
1652 NON_EXISTENT_ID, NON_EXISTENT_ID,
1653 new OrgAuthorityClient().getCommonPartName());
1654 ClientResponse<MultipartInput> res =
1655 client.update(NON_EXISTENT_ID, multipart);
1657 int statusCode = res.getStatus();
1659 // Check the status code of the response: does it match
1660 // the expected response(s)?
1661 if(logger.isDebugEnabled()){
1662 logger.debug(testName + ": status = " + statusCode);
1664 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1665 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1666 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1668 res.releaseConnection();
1673 * Update non existent item.
1675 * @param testName the test name
1676 * @throws Exception the exception
1678 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1679 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1680 public void updateNonExistentItem(String testName) throws Exception {
1682 if (logger.isDebugEnabled()) {
1683 logger.debug(testBanner(testName, CLASS_NAME));
1686 setupUpdateNonExistent();
1688 // Submit the request to the service and store the response.
1689 // Note: The ID(s) used when creating the request payload may be arbitrary.
1690 // The only relevant ID may be the one used in update(), below.
1691 OrgAuthorityClient client = new OrgAuthorityClient();
1692 Map<String, String> nonexOrgMap = new HashMap<String,String>();
1693 nonexOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, "nonExistent");
1694 nonexOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Non-existent");
1695 MultipartOutput multipart =
1696 OrgAuthorityClientUtils.createOrganizationInstance(
1697 knownResourceRefName,
1698 nonexOrgMap, client.getItemCommonPartName() );
1699 ClientResponse<MultipartInput> res =
1700 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1702 int statusCode = res.getStatus();
1704 // Check the status code of the response: does it match
1705 // the expected response(s)?
1706 if(logger.isDebugEnabled()){
1707 logger.debug(testName + ": status = " + statusCode);
1709 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1710 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1711 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1713 res.releaseConnection();
1718 * Update non existent contact.
1720 * @param testName the test name
1721 * @throws Exception the exception
1723 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1724 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1725 public void updateNonExistentContact(String testName) throws Exception {
1726 // Currently a no-op test
1729 // ---------------------------------------------------------------
1730 // CRUD tests : DELETE tests
1731 // ---------------------------------------------------------------
1734 // Note: delete sub-resources in ascending hierarchical order,
1735 // before deleting their parents.
1740 * @param testName the test name
1741 * @throws Exception the exception
1743 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1744 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1745 public void deleteContact(String testName) throws Exception {
1747 if (logger.isDebugEnabled()) {
1748 logger.debug(testBanner(testName, CLASS_NAME));
1753 if(logger.isDebugEnabled()){
1754 logger.debug("parentcsid =" + knownResourceId +
1755 " itemcsid = " + knownItemResourceId +
1756 " csid = " + knownContactResourceId);
1759 // Submit the request to the service and store the response.
1760 OrgAuthorityClient client = new OrgAuthorityClient();
1761 ClientResponse<Response> res =
1762 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1764 int statusCode = res.getStatus();
1766 // Check the status code of the response: does it match
1767 // the expected response(s)?
1768 if(logger.isDebugEnabled()){
1769 logger.debug(testName + ": status = " + statusCode);
1771 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1772 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1773 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1775 res.releaseConnection();
1782 * @param testName the test name
1783 * @throws Exception the exception
1785 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1786 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1787 public void deleteItem(String testName) throws Exception {
1789 if (logger.isDebugEnabled()) {
1790 logger.debug(testBanner(testName, CLASS_NAME));
1795 if(logger.isDebugEnabled()){
1796 logger.debug("parentcsid =" + knownResourceId +
1797 " itemcsid = " + knownItemResourceId);
1800 // Submit the request to the service and store the response.
1801 OrgAuthorityClient client = new OrgAuthorityClient();
1802 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1804 int statusCode = res.getStatus();
1806 // Check the status code of the response: does it match
1807 // the expected response(s)?
1808 if(logger.isDebugEnabled()){
1809 logger.debug(testName + ": status = " + statusCode);
1811 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1812 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1813 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1815 res.releaseConnection();
1820 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1823 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1824 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1825 public void delete(String testName) throws Exception {
1827 if (logger.isDebugEnabled()) {
1828 logger.debug(testBanner(testName, CLASS_NAME));
1833 if(logger.isDebugEnabled()){
1834 logger.debug("parentcsid =" + knownResourceId);
1837 // Submit the request to the service and store the response.
1838 OrgAuthorityClient client = new OrgAuthorityClient();
1839 ClientResponse<Response> res = client.delete(knownResourceId);
1841 int statusCode = res.getStatus();
1843 // Check the status code of the response: does it match
1844 // the expected response(s)?
1845 if(logger.isDebugEnabled()){
1846 logger.debug(testName + ": status = " + statusCode);
1848 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1849 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1850 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1852 res.releaseConnection();
1858 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1861 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1862 groups = {"delete"}, dependsOnMethods = {"delete"})
1863 public void deleteNonExistent(String testName) throws Exception {
1865 if (logger.isDebugEnabled()) {
1866 logger.debug(testBanner(testName, CLASS_NAME));
1869 setupDeleteNonExistent();
1871 // Submit the request to the service and store the response.
1872 OrgAuthorityClient client = new OrgAuthorityClient();
1873 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1875 int statusCode = res.getStatus();
1877 // Check the status code of the response: does it match
1878 // the expected response(s)?
1879 if(logger.isDebugEnabled()){
1880 logger.debug(testName + ": status = " + statusCode);
1882 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1883 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1884 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1886 res.releaseConnection();
1891 * Delete non existent item.
1893 * @param testName the test name
1895 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1896 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1897 public void deleteNonExistentItem(String testName) {
1899 if (logger.isDebugEnabled()) {
1900 logger.debug(testBanner(testName, CLASS_NAME));
1903 setupDeleteNonExistent();
1905 // Submit the request to the service and store the response.
1906 OrgAuthorityClient client = new OrgAuthorityClient();
1907 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1909 int statusCode = res.getStatus();
1911 // Check the status code of the response: does it match
1912 // the expected response(s)?
1913 if(logger.isDebugEnabled()){
1914 logger.debug(testName + ": status = " + statusCode);
1916 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1917 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1918 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1920 res.releaseConnection();
1925 * Delete non existent contact.
1927 * @param testName the test name
1929 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1930 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1931 public void deleteNonExistentContact(String testName) {
1933 if (logger.isDebugEnabled()) {
1934 logger.debug(testBanner(testName, CLASS_NAME));
1937 setupDeleteNonExistent();
1939 // Submit the request to the service and store the response.
1940 OrgAuthorityClient client = new OrgAuthorityClient();
1941 ClientResponse<Response> res =
1942 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1944 int statusCode = res.getStatus();
1946 // Check the status code of the response: does it match
1947 // the expected response(s)?
1948 if(logger.isDebugEnabled()){
1949 logger.debug(testName + ": status = " + statusCode);
1951 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1952 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1953 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1955 res.releaseConnection();
1959 // ---------------------------------------------------------------
1960 // Utility tests : tests of code used in tests above
1961 // ---------------------------------------------------------------
1963 * Tests the code for manually submitting data that is used by several
1964 * of the methods above.
1966 @Test(dependsOnMethods = {"create", "read"})
1967 public void testSubmitRequest() {
1969 // Expected status code: 200 OK
1970 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1972 // Submit the request to the service and store the response.
1973 String method = ServiceRequestType.READ.httpMethodName();
1974 String url = getResourceURL(knownResourceId);
1975 int statusCode = submitRequest(method, url);
1977 // Check the status code of the response: does it match
1978 // the expected response(s)?
1979 if(logger.isDebugEnabled()){
1980 logger.debug("testSubmitRequest: url=" + url +
1981 " status=" + statusCode);
1983 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1988 * Test item submit request.
1990 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1991 public void testItemSubmitRequest() {
1993 // Expected status code: 200 OK
1994 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1996 // Submit the request to the service and store the response.
1997 String method = ServiceRequestType.READ.httpMethodName();
1998 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1999 int statusCode = submitRequest(method, url);
2001 // Check the status code of the response: does it match
2002 // the expected response(s)?
2003 if(logger.isDebugEnabled()){
2004 logger.debug("testItemSubmitRequest: url=" + url +
2005 " status=" + statusCode);
2007 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2012 * Test contact submit request.
2014 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
2015 public void testContactSubmitRequest() {
2017 // Expected status code: 200 OK
2018 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2020 // Submit the request to the service and store the response.
2021 String method = ServiceRequestType.READ.httpMethodName();
2022 String url = getContactResourceURL(knownResourceId,
2023 knownItemResourceId, knownContactResourceId);
2024 int statusCode = submitRequest(method, url);
2026 // Check the status code of the response: does it match
2027 // the expected response(s)?
2028 if(logger.isDebugEnabled()){
2029 logger.debug("testItemSubmitRequest: url=" + url +
2030 " status=" + statusCode);
2032 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2037 // ---------------------------------------------------------------
2038 // Cleanup of resources created during testing
2039 // ---------------------------------------------------------------
2042 * Deletes all resources created by tests, after all tests have been run.
2044 * This cleanup method will always be run, even if one or more tests fail.
2045 * For this reason, it attempts to remove all resources created
2046 * at any point during testing, even if some of those resources
2047 * may be expected to be deleted by certain tests.
2050 @AfterClass(alwaysRun=true)
2052 public void cleanUp() {
2053 String noTest = System.getProperty("noTestCleanup");
2054 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
2055 if (logger.isDebugEnabled()) {
2056 logger.debug("Skipping Cleanup phase ...");
2060 if (logger.isDebugEnabled()) {
2061 logger.debug("Cleaning up temporary resources created for testing ...");
2064 String parentResourceId;
2065 String itemResourceId;
2066 String contactResourceId;
2067 // Clean up contact resources.
2068 parentResourceId = knownResourceId;
2069 OrgAuthorityClient client = new OrgAuthorityClient();
2070 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
2071 contactResourceId = entry.getKey();
2072 itemResourceId = entry.getValue();
2073 // Note: Any non-success responses from the delete operation
2074 // below are ignored and not reported.
2075 ClientResponse<Response> res =
2076 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
2077 res.releaseConnection();
2079 // Clean up item resources.
2080 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
2081 itemResourceId = entry.getKey();
2082 parentResourceId = entry.getValue();
2083 // Note: Any non-success responses from the delete operation
2084 // below are ignored and not reported.
2085 ClientResponse<Response> res =
2086 client.deleteItem(parentResourceId, itemResourceId);
2087 res.releaseConnection();
2089 // Clean up parent resources.
2094 // ---------------------------------------------------------------
2095 // Utility methods used by tests above
2096 // ---------------------------------------------------------------
2098 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
2101 public String getServicePathComponent() {
2102 return SERVICE_PATH_COMPONENT;
2106 * Gets the item service path component.
2108 * @return the item service path component
2110 public String getItemServicePathComponent() {
2111 return ITEM_SERVICE_PATH_COMPONENT;
2115 * Gets the contact service path component.
2117 * @return the contact service path component
2119 public String getContactServicePathComponent() {
2120 return CONTACT_SERVICE_PATH_COMPONENT;
2124 * Returns the root URL for the item service.
2126 * This URL consists of a base URL for all services, followed by
2127 * a path component for the owning parent, followed by the
2128 * path component for the items.
2130 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2131 * parent authority resource of the relevant item resource.
2133 * @return The root URL for the item service.
2135 protected String getItemServiceRootURL(String parentResourceIdentifier) {
2136 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
2140 * Returns the URL of a specific item resource managed by a service, and
2141 * designated by an identifier (such as a universally unique ID, or UUID).
2143 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2144 * parent authority resource of the relevant item resource.
2146 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2149 * @return The URL of a specific item resource managed by a service.
2151 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
2152 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
2157 * Returns the root URL for the contact service.
2159 * This URL consists of a base URL for all services, followed by
2160 * a path component for the owning authority, followed by the
2161 * path component for the owning item, followed by the path component
2162 * for the contact service.
2164 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2165 * parent authority resource of the relevant item resource.
2167 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2170 * @return The root URL for the contact service.
2172 protected String getContactServiceRootURL(String parentResourceIdentifier,
2173 String itemResourceIdentifier) {
2174 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
2175 getContactServicePathComponent();
2179 * Returns the URL of a specific contact resource managed by a service, and
2180 * designated by an identifier (such as a universally unique ID, or UUID).
2182 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2183 * parent resource of the relevant item resource.
2185 * @param resourceIdentifier An identifier (such as a UUID) for an
2188 * @return The URL of a specific resource managed by a service.
2190 protected String getContactResourceURL(String parentResourceIdentifier,
2191 String itemResourceIdentifier, String contactResourceIdentifier) {
2192 return getContactServiceRootURL(parentResourceIdentifier,
2193 itemResourceIdentifier) + "/" + contactResourceIdentifier;