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.AuthorityClient;
34 import org.collectionspace.services.client.CollectionSpaceClient;
35 import org.collectionspace.services.client.ContactClient;
36 import org.collectionspace.services.client.ContactClientUtils;
37 import org.collectionspace.services.client.PayloadOutputPart;
38 import org.collectionspace.services.client.PoxPayloadIn;
39 import org.collectionspace.services.client.PoxPayloadOut;
40 import org.collectionspace.services.common.AbstractCommonListUtils;
41 import org.collectionspace.services.contact.ContactsCommon;
42 import org.collectionspace.services.contact.ContactsCommonList;
43 import org.collectionspace.services.client.OrgAuthorityClient;
44 import org.collectionspace.services.client.OrgAuthorityClientUtils;
45 import org.collectionspace.services.jaxb.AbstractCommonList;
46 import org.collectionspace.services.organization.MainBodyGroup;
47 import org.collectionspace.services.organization.MainBodyGroupList;
48 import org.collectionspace.services.organization.OrgauthoritiesCommon;
49 import org.collectionspace.services.organization.OrganizationsCommon;
51 import org.jboss.resteasy.client.ClientResponse;
53 import org.slf4j.Logger;
54 import org.slf4j.LoggerFactory;
55 import org.testng.Assert;
56 import org.testng.annotations.AfterClass;
57 import org.testng.annotations.Test;
60 * OrgAuthorityServiceTest, carries out tests against a
61 * deployed and running OrgAuthority Service.
63 * $LastChangedRevision$
66 public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: Test classes for Vocab, Person, Org, and Location should have a base class!
69 private final String CLASS_NAME = OrgAuthorityServiceTest.class.getName();
70 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
71 private final String REFNAME = "refName";
72 private final String DISPLAYNAME = "displayName";
75 public String getServicePathComponent() {
76 return OrgAuthorityClient.SERVICE_PATH_COMPONENT;
80 protected String getServiceName() {
81 return OrgAuthorityClient.SERVICE_NAME;
84 /** The test organization shortname. */
85 private final String TEST_ORG_SHORTNAME = "Test Org";
87 /** The test organization founding place. */
88 private final String TEST_ORG_FOUNDING_PLACE = "Anytown, USA";
90 // Hold some values for a recently created item to verify upon read.
91 private String knownResourceId = null;
92 private String knownResourceShortIdentifer = null;
93 private String knownResourceRefName = null;
94 private String knownItemResourceId = null;
95 private String knownItemResourceShortIdentifer = null;
97 /** The known contact resource id. */
98 private String knownContactResourceId = null;
100 /** The n items to create in list. */
101 private int nItemsToCreateInList = 3;
103 /** The all item resource ids created. */
104 private Map<String, String> allItemResourceIdsCreated =
105 new HashMap<String, String>();
107 /** The all contact resource ids created. */
108 private Map<String, String> allContactResourceIdsCreated =
109 new HashMap<String, String>();
111 protected void setKnownResource( String id, String shortIdentifer,
113 knownResourceId = id;
114 knownResourceShortIdentifer = shortIdentifer;
115 knownResourceRefName = refName;
118 protected void setKnownItemResource( String id, String shortIdentifer ) {
119 knownItemResourceId = id;
120 knownItemResourceShortIdentifer = shortIdentifer;
124 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
127 protected CollectionSpaceClient getClientInstance() {
128 return new OrgAuthorityClient();
131 // ---------------------------------------------------------------
132 // CRUD tests : CREATE tests
133 // ---------------------------------------------------------------
136 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
139 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
141 public void create(String testName) throws Exception {
143 if (logger.isDebugEnabled()) {
144 logger.debug(testBanner(testName, CLASS_NAME));
146 // Perform setup, such as initializing the type of service request
147 // (e.g. CREATE, DELETE), its valid and expected status codes, and
148 // its associated HTTP method name (e.g. POST, DELETE).
151 // Submit the request to the service and store the response.
152 OrgAuthorityClient client = new OrgAuthorityClient();
153 String shortId = createIdentifier();
154 String displayName = "displayName-" + shortId;
155 String baseRefName = OrgAuthorityClientUtils.createOrgAuthRefName(shortId, null);
156 PoxPayloadOut multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance(
157 displayName, shortId, client.getCommonPartName());
160 ClientResponse<Response> res = client.create(multipart);
162 int statusCode = res.getStatus();
164 // Check the status code of the response: does it match
165 // the expected response(s)?
168 // Does it fall within the set of valid status codes?
169 // Does it exactly match the expected status code?
170 if(logger.isDebugEnabled()){
171 logger.debug(testName + ": status = " + statusCode);
173 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
174 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
175 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
177 newID = OrgAuthorityClientUtils.extractId(res);
179 res.releaseConnection();
182 // Store the ID returned from the first resource created
183 // for additional tests below.
184 if (knownResourceId == null){
185 setKnownResource( newID, shortId, baseRefName );
186 if (logger.isDebugEnabled()) {
187 logger.debug(testName + ": knownResourceId=" + knownResourceId);
190 // Store the IDs from every resource created by tests,
191 // so they can be deleted after tests have been run.
192 allResourceIdsCreated.add(newID);
196 protected PoxPayloadOut createInstance(String identifier) {
197 OrgAuthorityClient client = new OrgAuthorityClient();
198 String displayName = "displayName-" + identifier;
199 PoxPayloadOut multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance(
200 displayName, identifier, client.getCommonPartName());
205 protected PoxPayloadOut createItemInstance(String parentCsid, String identifier) {
206 String headerLabel = new OrgAuthorityClient().getItemCommonPartName();
207 String shortId = "testOrg";
208 Map<String, String> testOrgMap = new HashMap<String,String>();
209 testOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId);
210 testOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, TEST_ORG_SHORTNAME);
211 testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "The real official test organization");
212 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "May 26, 1907");
213 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, TEST_ORG_FOUNDING_PLACE);
215 return OrgAuthorityClientUtils.createOrganizationInstance(identifier, testOrgMap, headerLabel);
221 * @param testName the test name
223 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
224 groups = {"create"}, dependsOnMethods = {"create"})
225 public void createItem(String testName) {
227 String newID = createItemInAuthority(knownResourceId, knownResourceRefName);
231 * Creates the item in authority.
233 * @param vcsid the vcsid
234 * @param authRefName the auth ref name
237 private String createItemInAuthority(String vcsid, String authRefName) {
239 final String testName = "createItemInAuthority";
240 if(logger.isDebugEnabled()){
241 logger.debug(testName + ":...");
244 // Submit the request to the service and store the response.
245 OrgAuthorityClient client = new OrgAuthorityClient();
246 String shortId = "testOrg";
247 Map<String, String> testOrgMap = new HashMap<String,String>();
248 testOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId);
249 testOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, TEST_ORG_SHORTNAME);
250 testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "The real official test organization");
251 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "May 26, 1907");
252 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, TEST_ORG_FOUNDING_PLACE);
254 Map<String, List<String>> testOrgRepeatablesMap = new HashMap<String,List<String>>();
255 List<String> testOrgContactNames = new ArrayList<String>();
256 testOrgContactNames.add("joe@example.org");
257 testOrgContactNames.add("sally@example.org");
258 testOrgRepeatablesMap.put(OrganizationJAXBSchema.CONTACT_NAMES, testOrgContactNames);
260 MainBodyGroupList mainBodyList = new MainBodyGroupList();
261 List<MainBodyGroup> mainBodyGroups = mainBodyList.getMainBodyGroup();
262 MainBodyGroup mainBodyGroup = new MainBodyGroup();
263 mainBodyGroup.setShortName(TEST_ORG_SHORTNAME);
264 mainBodyGroup.setLongName("The real official test organization");
265 mainBodyGroups.add(mainBodyGroup);
267 String newID = OrgAuthorityClientUtils.createItemInAuthority(
268 vcsid, authRefName, testOrgMap, testOrgRepeatablesMap, mainBodyList, client);
270 // Store the ID returned from the first item resource created
271 // for additional tests below.
272 if (knownItemResourceId == null){
273 setKnownItemResource(newID, shortId);
274 if (logger.isDebugEnabled()) {
275 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
279 // Store the IDs from any item resources created
280 // by tests, along with the IDs of their parents, so these items
281 // can be deleted after all tests have been run.
282 allItemResourceIdsCreated.put(newID, vcsid);
288 * Creates the contact.
290 * @param testName the test name
292 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
293 groups = {"create"}, dependsOnMethods = {"createItem"})
294 public void createContact(String testName) {
296 String newID = createContactInItem(knownResourceId, knownItemResourceId);
300 * Creates the contact in item.
302 * @param parentcsid the parentcsid
303 * @param itemcsid the itemcsid
306 private String createContactInItem(String parentcsid, String itemcsid) {
308 final String testName = "createContactInItem";
309 if (logger.isDebugEnabled()) {
310 logger.debug(testBanner(testName, CLASS_NAME));
314 // Submit the request to the service and store the response.
315 OrgAuthorityClient client = new OrgAuthorityClient();
316 String identifier = createIdentifier();
317 PoxPayloadOut multipart =
318 ContactClientUtils.createContactInstance(parentcsid,
319 itemcsid, identifier, new ContactClient().getCommonPartName());
322 ClientResponse<Response> res =
323 client.createContact(parentcsid, itemcsid, multipart);
325 int statusCode = res.getStatus();
326 // Check the status code of the response: does it match
327 // the expected response(s)?
328 if(logger.isDebugEnabled()){
329 logger.debug(testName + ": status = " + statusCode);
331 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
332 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
333 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
335 newID = OrgAuthorityClientUtils.extractId(res);
337 res.releaseConnection();
340 // Store the ID returned from the first contact resource created
341 // for additional tests below.
342 if (knownContactResourceId == null){
343 knownContactResourceId = newID;
344 if (logger.isDebugEnabled()) {
345 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
349 // Store the IDs from any contact resources created
350 // by tests, along with the IDs of their parent items,
351 // so these items can be deleted after all tests have been run.
352 allContactResourceIdsCreated.put(newID, itemcsid);
359 // Placeholders until the three tests below can be uncommented.
360 // See Issue CSPACE-401.
362 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
365 public void createWithEmptyEntityBody(String testName) throws Exception {
366 //Should this really be empty?
370 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
373 public void createWithMalformedXml(String testName) throws Exception {
374 //Should this really be empty?
378 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
381 public void createWithWrongXmlSchema(String testName) throws Exception {
382 //Should this really be empty?
387 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
388 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
389 public void createWithEmptyEntityBody(String testName) throws Exception {
391 if (logger.isDebugEnabled()) {
392 logger.debug(testBanner(testName, CLASS_NAME));
395 setupCreateWithEmptyEntityBody();
397 // Submit the request to the service and store the response.
398 String method = REQUEST_TYPE.httpMethodName();
399 String url = getServiceRootURL();
400 String mediaType = MediaType.APPLICATION_XML;
401 final String entity = "";
402 int statusCode = submitRequest(method, url, mediaType, entity);
404 // Check the status code of the response: does it match
405 // the expected response(s)?
406 if(logger.isDebugEnabled()) {
407 logger.debug(testName + ": url=" + url +
408 " status=" + statusCode);
410 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
411 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
412 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
416 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
417 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
418 public void createWithMalformedXml(String testName) throws Exception {
420 if (logger.isDebugEnabled()) {
421 logger.debug(testBanner(testName, CLASS_NAME));
424 setupCreateWithMalformedXml();
426 // Submit the request to the service and store the response.
427 String method = REQUEST_TYPE.httpMethodName();
428 String url = getServiceRootURL();
429 String mediaType = MediaType.APPLICATION_XML;
430 final String entity = MALFORMED_XML_DATA; // Constant from base class.
431 int statusCode = submitRequest(method, url, mediaType, entity);
433 // Check the status code of the response: does it match
434 // the expected response(s)?
435 if(logger.isDebugEnabled()){
436 logger.debug(testName + ": url=" + url +
437 " status=" + statusCode);
439 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
440 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
441 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
445 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
446 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
447 public void createWithWrongXmlSchema(String testName) throws Exception {
449 if (logger.isDebugEnabled()) {
450 logger.debug(testBanner(testName, CLASS_NAME));
453 setupCreateWithWrongXmlSchema();
455 // Submit the request to the service and store the response.
456 String method = REQUEST_TYPE.httpMethodName();
457 String url = getServiceRootURL();
458 String mediaType = MediaType.APPLICATION_XML;
459 final String entity = WRONG_XML_SCHEMA_DATA;
460 int statusCode = submitRequest(method, url, mediaType, entity);
462 // Check the status code of the response: does it match
463 // the expected response(s)?
464 if(logger.isDebugEnabled()){
465 logger.debug(testName + ": url=" + url +
466 " status=" + statusCode);
468 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
469 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
470 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
474 // ---------------------------------------------------------------
475 // CRUD tests : CREATE LIST tests
476 // ---------------------------------------------------------------
479 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
482 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
483 groups = {"createList"}, dependsOnGroups = {"create"})
484 public void createList(String testName) throws Exception {
485 for (int i = 0; i < nItemsToCreateInList; i++) {
491 * Creates the item list.
493 * @param testName the test name
494 * @throws Exception the exception
496 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
497 groups = {"createList"}, dependsOnMethods = {"createList"})
498 public void createItemList(String testName) throws Exception {
499 // Add items to the initially-created, known parent record.
500 for (int j = 0; j < nItemsToCreateInList; j++) {
501 createItem(testName);
506 * Creates the contact list.
508 * @param testName the test name
509 * @throws Exception the exception
511 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
512 groups = {"createList"}, dependsOnMethods = {"createItemList"})
513 public void createContactList(String testName) throws Exception {
514 // Add contacts to the initially-created, known item record.
515 for (int j = 0; j < nItemsToCreateInList; j++) {
516 createContact(testName);
520 // ---------------------------------------------------------------
521 // CRUD tests : READ tests
522 // ---------------------------------------------------------------
525 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
528 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
529 groups = {"read"}, dependsOnGroups = {"create"})
530 public void read(String testName) throws Exception {
531 readInternal(testName, knownResourceId, null);
537 * @param testName the test name
538 * @throws Exception the exception
540 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
541 groups = {"read"}, dependsOnGroups = {"create"})
542 public void readByName(String testName) throws Exception {
543 readInternal(testName, null, knownResourceShortIdentifer);
546 protected void readInternal(String testName, String CSID, String shortId) {
548 if (logger.isDebugEnabled()) {
549 logger.debug(testBanner(testName, CLASS_NAME));
554 // Submit the request to the service and store the response.
555 OrgAuthorityClient client = new OrgAuthorityClient();
556 ClientResponse<String> res = null;
558 res = client.read(CSID);
559 } else if(shortId!=null) {
560 res = client.readByName(shortId);
562 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
565 int statusCode = res.getStatus();
567 // Check the status code of the response: does it match
568 // the expected response(s)?
569 if(logger.isDebugEnabled()){
570 logger.debug(testName + ": status = " + statusCode);
572 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
573 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
574 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
575 //FIXME: remove the following try catch once Aron fixes signatures
577 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
578 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
579 new OrgAuthorityClient().getCommonPartName(), OrgauthoritiesCommon.class);
580 Assert.assertNotNull(orgAuthority);
581 } catch (Exception e) {
582 throw new RuntimeException(e);
585 res.releaseConnection();
592 * @param testName the test name
593 * @throws Exception the exception
595 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
596 groups = {"readItem"}, dependsOnGroups = {"read"})
597 public void readItem(String testName) throws Exception {
598 readItemInternal(testName, knownResourceId, null, knownItemResourceId, null);
602 * Read item in Named Auth.
604 * TODO Enable this if we really need this - it is a funky case, where we would have
605 * the shortId of the item, but the CSID of the parent authority!? Unlikely.
607 * @param testName the test name
608 * @throws Exception the exception
609 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
610 groups = {"readItem"}, dependsOnGroups = {"read"})
611 public void readItemInNamedAuth(String testName) throws Exception {
612 readItemInternal(testName, null, knownResourceShortIdentifer, knownItemResourceId, null);
619 * @param testName the test name
620 * @throws Exception the exception
622 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
623 groups = {"readItem"}, dependsOnGroups = {"read"})
624 public void readNamedItem(String testName) throws Exception {
625 readItemInternal(testName, knownResourceId, null, null, knownItemResourceShortIdentifer);
629 * Read Named item in Named Auth.
631 * @param testName the test name
632 * @throws Exception the exception
634 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
635 groups = {"readItem"}, dependsOnGroups = {"read"})
636 public void readNamedItemInNamedAuth(String testName) throws Exception {
637 readItemInternal(testName, null, knownResourceShortIdentifer, null, knownItemResourceShortIdentifer);
640 protected void readItemInternal(String testName,
641 String authCSID, String authShortId, String itemCSID, String itemShortId)
644 if (logger.isDebugEnabled()) {
645 logger.debug(testBanner(testName, CLASS_NAME));
650 // Submit the request to the service and store the response.
651 OrgAuthorityClient client = new OrgAuthorityClient();
652 ClientResponse<String> res = null;
655 res = client.readItem(authCSID, itemCSID);
656 } else if(itemShortId!=null) {
657 res = client.readNamedItem(authCSID, itemShortId);
659 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
661 } else if(authShortId!=null) {
663 res = client.readItemInNamedAuthority(authShortId, itemCSID);
664 } else if(itemShortId!=null) {
665 res = client.readNamedItemInNamedAuthority(authShortId, itemShortId);
667 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
670 Assert.fail("readInternal: Internal error. One of authCSID or authShortId must be non-null");
673 int statusCode = res.getStatus();
675 // Check the status code of the response: does it match
676 // the expected response(s)?
677 if(logger.isDebugEnabled()){
678 logger.debug(testName + ": status = " + statusCode);
680 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
681 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
682 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
684 // Check whether we've received a organization.
685 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
686 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
687 client.getItemCommonPartName(), OrganizationsCommon.class);
688 Assert.assertNotNull(organization);
689 boolean showFull = true;
690 if(showFull && logger.isDebugEnabled()){
691 logger.debug(testName + ": returned payload:");
692 logger.debug(objectAsXmlString(organization, OrganizationsCommon.class));
695 // Check that the organization item is within the expected OrgAuthority.
696 Assert.assertEquals(organization.getInAuthority(), knownResourceId);
698 // Verify the number and contents of values in a repeatable field,
699 // as created in the instance record used for testing.
700 List<String> contactNames = organization.getContactNames().getContactName();
701 Assert.assertTrue(contactNames.size() > 0);
702 Assert.assertNotNull(contactNames.get(0));
705 res.releaseConnection();
710 * Verify item display name.
712 * @param testName the test name
713 * @throws Exception the exception
715 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
716 dependsOnMethods = {"readItem", "updateItem"})
717 public void verifyItemDisplayName(String testName) throws Exception {
719 if (logger.isDebugEnabled()) {
720 logger.debug(testBanner(testName, CLASS_NAME));
725 // Submit the request to the service and store the response.
726 OrgAuthorityClient client = new OrgAuthorityClient();
727 PoxPayloadIn input = null;
728 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
730 int statusCode = res.getStatus();
732 // Check the status code of the response: does it match
733 // the expected response(s)?
734 if(logger.isDebugEnabled()){
735 logger.debug(testName + ": status = " + statusCode);
737 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
738 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
739 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
741 // Check whether organization has expected displayName.
742 input = new PoxPayloadIn(res.getEntity());
744 res.releaseConnection();
747 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
748 client.getItemCommonPartName(), OrganizationsCommon.class);
749 Assert.assertNotNull(organization);
750 String displayName = organization.getDisplayName();
751 // Make sure displayName matches computed form
752 String expectedDisplayName =
753 OrgAuthorityClientUtils.prepareDefaultDisplayName(
754 TEST_ORG_SHORTNAME, TEST_ORG_FOUNDING_PLACE);
755 Assert.assertNotNull(displayName, expectedDisplayName);
757 // Update the shortName and verify the computed name is updated.
758 organization.setCsid(null);
759 organization.setDisplayNameComputed(true);
761 MainBodyGroupList mainBodyList = organization.getMainBodyGroupList();
762 List<MainBodyGroup> mainBodyGroups = mainBodyList.getMainBodyGroup();
763 MainBodyGroup mainBodyGroup = new MainBodyGroup();
764 String updatedShortName = "updated-" + TEST_ORG_SHORTNAME;
765 mainBodyGroup.setShortName(updatedShortName);
766 mainBodyGroups.add(mainBodyGroup);
767 organization.setMainBodyGroupList(mainBodyList);
769 expectedDisplayName =
770 OrgAuthorityClientUtils.prepareDefaultDisplayName(
771 updatedShortName, TEST_ORG_FOUNDING_PLACE);
773 // Submit the updated resource to the service and store the response.
774 PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
775 PayloadOutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
776 commonPart.setLabel(client.getItemCommonPartName());
777 res = client.updateItem(knownResourceId, knownItemResourceId, output);
779 int statusCode = res.getStatus();
781 // Check the status code of the response: does it match the expected response(s)?
782 if(logger.isDebugEnabled()){
783 logger.debug("updateItem: status = " + statusCode);
785 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
786 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
787 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
789 // Retrieve the updated resource and verify that its contents exist.
790 input = new PoxPayloadIn(res.getEntity());
792 res.releaseConnection();
795 OrganizationsCommon updatedOrganization =
796 (OrganizationsCommon) extractPart(input,
797 client.getItemCommonPartName(), OrganizationsCommon.class);
798 Assert.assertNotNull(updatedOrganization);
800 // Verify that the updated resource received the correct data.
801 mainBodyList = organization.getMainBodyGroupList();
802 Assert.assertNotNull(mainBodyList);
803 Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0);
804 Assert.assertEquals(updatedOrganization.getMainBodyGroupList().getMainBodyGroup().get(0).getShortName(),
805 updatedShortName, "Updated ShortName in Organization did not match submitted data.");
807 // Verify that the updated resource computes the right displayName.
808 Assert.assertEquals(updatedOrganization.getDisplayName(), expectedDisplayName,
809 "Updated ShortName in Organization not reflected in computed DisplayName.");
811 // Now Update the displayName, not computed and verify the computed name is overriden.
812 organization.setDisplayNameComputed(false);
813 expectedDisplayName = "TestName";
814 organization.setDisplayName(expectedDisplayName);
816 // Submit the updated resource to the service and store the response.
817 output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
818 commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
819 commonPart.setLabel(client.getItemCommonPartName());
820 res = client.updateItem(knownResourceId, knownItemResourceId, output);
822 int statusCode = res.getStatus();
824 // Check the status code of the response: does it match the expected response(s)?
825 if(logger.isDebugEnabled()){
826 logger.debug("updateItem: status = " + statusCode);
828 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
829 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
830 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
832 // Retrieve the updated resource and verify that its contents exist.
833 input = new PoxPayloadIn(res.getEntity());
835 res.releaseConnection();
838 updatedOrganization =
839 (OrganizationsCommon) extractPart(input,
840 client.getItemCommonPartName(), OrganizationsCommon.class);
841 Assert.assertNotNull(updatedOrganization);
843 // Verify that the updated resource received the correct data.
844 Assert.assertEquals(updatedOrganization.isDisplayNameComputed(), false,
845 "Updated displayNameComputed in Organization did not match submitted data.");
846 // Verify that the updated resource computes the right displayName.
847 Assert.assertEquals(updatedOrganization.getDisplayName(),
849 "Updated DisplayName (not computed) in Organization not stored.");
853 * Verify illegal item display name.
855 * @param testName the test name
856 * @throws Exception the exception
858 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
859 dependsOnMethods = {"verifyItemDisplayName"})
860 public void verifyIllegalItemDisplayName(String testName) throws Exception {
862 if (logger.isDebugEnabled()) {
863 logger.debug(testBanner(testName, CLASS_NAME));
866 testSetup(STATUS_BAD_REQUEST, ServiceRequestType.UPDATE);
867 // setupUpdateWithWrongXmlSchema(testName, logger);
869 // Submit the request to the service and store the response.
870 OrgAuthorityClient client = new OrgAuthorityClient();
871 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
873 int statusCode = res.getStatus();
875 // Check the status code of the response: does it match
876 // the expected response(s)?
877 if(logger.isDebugEnabled()){
878 logger.debug(testName + ": status = " + statusCode);
880 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
881 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
882 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
884 // Check whether organization has expected displayName.
885 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
886 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
887 client.getItemCommonPartName(), OrganizationsCommon.class);
888 Assert.assertNotNull(organization);
889 // Try to Update with computed false and no displayName
890 organization.setDisplayNameComputed(false);
891 organization.setDisplayName(null);
893 // Submit the updated resource to the service and store the response.
894 PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
895 PayloadOutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
896 commonPart.setLabel(client.getItemCommonPartName());
897 res.releaseConnection();
898 res = client.updateItem(knownResourceId, knownItemResourceId, output);
899 statusCode = res.getStatus();
901 // Check the status code of the response: does it match the expected response(s)?
902 if(logger.isDebugEnabled()){
903 logger.debug("updateItem: status = " + statusCode);
905 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
906 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
907 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
909 res.releaseConnection();
916 * @param testName the test name
917 * @throws Exception the exception
919 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
920 groups = {"readItem"}, dependsOnMethods = {"readItem"})
921 public void readContact(String testName) throws Exception {
923 if (logger.isDebugEnabled()) {
924 logger.debug(testBanner(testName, CLASS_NAME));
929 // Submit the request to the service and store the response.
930 OrgAuthorityClient client = new OrgAuthorityClient();
931 ClientResponse<String> res =
932 client.readContact(knownResourceId, knownItemResourceId,
933 knownContactResourceId);
935 int statusCode = res.getStatus();
937 // Check the status code of the response: does it match
938 // the expected response(s)?
939 if(logger.isDebugEnabled()){
940 logger.debug(testName + ": status = " + statusCode);
942 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
943 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
944 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
946 // Check whether we've received a contact.
947 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
948 ContactsCommon contact = (ContactsCommon) extractPart(input,
949 new ContactClient().getCommonPartName(), ContactsCommon.class);
950 Assert.assertNotNull(contact);
951 boolean showFull = true;
952 if(showFull && logger.isDebugEnabled()){
953 logger.debug(testName + ": returned payload:");
954 logger.debug(objectAsXmlString(contact, ContactsCommon.class));
956 Assert.assertEquals(contact.getInAuthority(), knownResourceId);
957 Assert.assertEquals(contact.getInItem(), knownItemResourceId);
959 res.releaseConnection();
965 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
968 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
969 groups = {"read"}, dependsOnMethods = {"read"})
970 public void readNonExistent(String testName) {
972 if (logger.isDebugEnabled()) {
973 logger.debug(testBanner(testName, CLASS_NAME));
976 setupReadNonExistent();
978 // Submit the request to the service and store the response.
979 OrgAuthorityClient client = new OrgAuthorityClient();
980 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
982 int statusCode = res.getStatus();
984 // Check the status code of the response: does it match
985 // the expected response(s)?
986 if(logger.isDebugEnabled()){
987 logger.debug(testName + ": status = " + statusCode);
989 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
990 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
991 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
993 res.releaseConnection();
998 * Read item non existent.
1000 * @param testName the test name
1002 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1003 groups = {"readItem"}, dependsOnMethods = {"readItem"})
1004 public void readItemNonExistent(String testName) {
1006 if (logger.isDebugEnabled()) {
1007 logger.debug(testBanner(testName, CLASS_NAME));
1010 setupReadNonExistent();
1012 // Submit the request to the service and store the response.
1013 OrgAuthorityClient client = new OrgAuthorityClient();
1014 ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
1016 int statusCode = res.getStatus();
1018 // Check the status code of the response: does it match
1019 // the expected response(s)?
1020 if(logger.isDebugEnabled()){
1021 logger.debug(testName + ": status = " + statusCode);
1023 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1024 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1025 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1027 res.releaseConnection();
1032 * Read contact non existent.
1034 * @param testName the test name
1036 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1037 groups = {"readItem"}, dependsOnMethods = {"readContact"})
1038 public void readContactNonExistent(String testName) {
1040 if (logger.isDebugEnabled()) {
1041 logger.debug(testBanner(testName, CLASS_NAME));
1044 setupReadNonExistent();
1046 // Submit the request to the service and store the response.
1047 OrgAuthorityClient client = new OrgAuthorityClient();
1048 ClientResponse<String> res =
1049 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1051 int statusCode = res.getStatus();
1053 // Check the status code of the response: does it match
1054 // the expected response(s)?
1055 if(logger.isDebugEnabled()){
1056 logger.debug(testName + ": status = " + statusCode);
1058 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1059 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1060 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1062 res.releaseConnection();
1066 // ---------------------------------------------------------------
1067 // CRUD tests : READ_LIST tests
1068 // ---------------------------------------------------------------
1072 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
1075 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1076 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
1077 public void readList(String testName) throws Exception {
1079 if (logger.isDebugEnabled()) {
1080 logger.debug(testBanner(testName, CLASS_NAME));
1085 // Submit the request to the service and store the response.
1086 OrgAuthorityClient client = new OrgAuthorityClient();
1087 ClientResponse<AbstractCommonList> res = client.readList();
1089 AbstractCommonList list = res.getEntity();
1090 int statusCode = res.getStatus();
1092 // Check the status code of the response: does it match
1093 // the expected response(s)?
1094 if(logger.isDebugEnabled()){
1095 logger.debug(testName + ": status = " + statusCode);
1097 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1098 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1099 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1101 // Optionally output additional data about list members for debugging.
1102 if(logger.isTraceEnabled()){
1103 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
1106 res.releaseConnection();
1113 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
1114 public void readItemList() {
1115 readItemList(knownResourceId, null);
1119 * Read item list by authority name.
1121 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1122 public void readItemListByAuthorityName() {
1123 readItemList(null, knownResourceShortIdentifer);
1129 * @param vcsid the vcsid
1130 * @param name the name
1132 private void readItemList(String vcsid, String name) {
1134 final String testName = "readItemList";
1136 if (logger.isDebugEnabled()) {
1137 logger.debug(testBanner(testName, CLASS_NAME));
1142 // Submit the request to the service and store the response.
1143 OrgAuthorityClient client = new OrgAuthorityClient();
1144 ClientResponse<AbstractCommonList> res = null;
1146 res = client.readItemList(vcsid, null, null);
1147 } else if(name!= null) {
1148 res = client.readItemListForNamedAuthority(name, null, null);
1150 Assert.fail("readItemList passed null csid and name!");
1153 AbstractCommonList list = res.getEntity();
1154 int statusCode = res.getStatus();
1156 // Check the status code of the response: does it match
1157 // the expected response(s)?
1158 if(logger.isDebugEnabled()){
1159 logger.debug(testName + ": status = " + statusCode);
1161 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1162 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1163 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1165 List<AbstractCommonList.ListItem> items =
1167 int nItemsReturned = items.size();
1168 // There will be one item created, associated with a
1169 // known parent resource, by the createItem test.
1171 // In addition, there will be 'nItemsToCreateInList'
1172 // additional items created by the createItemList test,
1173 // all associated with the same parent resource.
1174 int nExpectedItems = nItemsToCreateInList + 1;
1175 if(logger.isDebugEnabled()){
1176 logger.debug(testName + ": Expected "
1177 + nExpectedItems +" items; got: "+nItemsReturned);
1179 Assert.assertEquals(nItemsReturned, nExpectedItems);
1181 for (AbstractCommonList.ListItem item : items) {
1183 AbstractCommonListUtils.ListItemGetElementValue(item, REFNAME);
1184 Assert.assertTrue((null != value), "Item refName is null!");
1186 AbstractCommonListUtils.ListItemGetElementValue(item, DISPLAYNAME);
1187 Assert.assertTrue((null != value), "Item displayName is null!");
1189 if(logger.isTraceEnabled()){
1190 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
1193 res.releaseConnection();
1198 * Read contact list.
1200 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1201 public void readContactList() {
1202 readContactList(knownResourceId, knownItemResourceId);
1206 * Read contact list.
1208 * @param parentcsid the parentcsid
1209 * @param itemcsid the itemcsid
1211 private void readContactList(String parentcsid, String itemcsid) {
1212 final String testName = "readContactList";
1214 if (logger.isDebugEnabled()) {
1215 logger.debug(testBanner(testName, CLASS_NAME));
1220 // Submit the request to the service and store the response.
1221 OrgAuthorityClient client = new OrgAuthorityClient();
1222 ContactsCommonList list = null;
1223 ClientResponse<ContactsCommonList> res =
1224 client.readContactList(parentcsid, itemcsid);
1226 list = res.getEntity();
1227 int statusCode = res.getStatus();
1229 // Check the status code of the response: does it match
1230 // the expected response(s)?
1231 if(logger.isDebugEnabled()){
1232 logger.debug(testName + ": status = " + statusCode);
1234 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1235 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1236 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1238 List<ContactsCommonList.ContactListItem> listitems =
1239 list.getContactListItem();
1240 int nItemsReturned = listitems.size();
1241 // There will be one item created, associated with a
1242 // known parent resource, by the createItem test.
1244 // In addition, there will be 'nItemsToCreateInList'
1245 // additional items created by the createItemList test,
1246 // all associated with the same parent resource.
1247 int nExpectedItems = nItemsToCreateInList + 1;
1248 if(logger.isDebugEnabled()){
1249 logger.debug(testName + ": Expected "
1250 + nExpectedItems +" items; got: "+nItemsReturned);
1252 Assert.assertEquals(nItemsReturned, nExpectedItems);
1255 for (ContactsCommonList.ContactListItem listitem : listitems) {
1256 // Optionally output additional data about list members for debugging.
1257 boolean showDetails = false;
1258 if (showDetails && logger.isDebugEnabled()) {
1259 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1260 listitem.getCsid());
1261 logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" +
1262 listitem.getAddressPlace());
1263 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1269 res.releaseConnection();
1276 // ---------------------------------------------------------------
1277 // CRUD tests : UPDATE tests
1278 // ---------------------------------------------------------------
1281 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
1284 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1285 groups = {"update"}, dependsOnGroups = {"read", "readList"})
1286 public void update(String testName) throws Exception {
1288 if (logger.isDebugEnabled()) {
1289 logger.debug(testBanner(testName, CLASS_NAME));
1294 // Retrieve the contents of a resource to update.
1295 OrgAuthorityClient client = new OrgAuthorityClient();
1296 ClientResponse<String> res =
1297 client.read(knownResourceId);
1299 if(logger.isDebugEnabled()){
1300 logger.debug(testName + ": read status = " + res.getStatus());
1302 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1304 if(logger.isDebugEnabled()){
1305 logger.debug("got OrgAuthority to update with ID: " + knownResourceId);
1307 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
1308 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
1309 client.getCommonPartName(), OrgauthoritiesCommon.class);
1310 Assert.assertNotNull(orgAuthority);
1312 // Update the contents of this resource.
1313 orgAuthority.setDisplayName("updated-" + orgAuthority.getDisplayName());
1314 orgAuthority.setVocabType("updated-" + orgAuthority.getVocabType());
1315 if(logger.isDebugEnabled()){
1316 logger.debug("to be updated OrgAuthority");
1317 logger.debug(objectAsXmlString(orgAuthority, OrgauthoritiesCommon.class));
1320 // Submit the updated resource to the service and store the response.
1321 PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_PAYLOAD_NAME);
1322 PayloadOutputPart commonPart = output.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE);
1323 commonPart.setLabel(client.getCommonPartName());
1324 res.releaseConnection();
1325 res = client.update(knownResourceId, output);
1326 int statusCode = res.getStatus();
1328 // Check the status code of the response: does it match the expected response(s)?
1329 if(logger.isDebugEnabled()){
1330 logger.debug(testName + ": status = " + statusCode);
1332 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1333 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1334 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1336 // Retrieve the updated resource and verify that its contents exist.
1337 input = new PoxPayloadIn(res.getEntity());
1338 OrgauthoritiesCommon updatedOrgAuthority =
1339 (OrgauthoritiesCommon) extractPart(input,
1340 client.getCommonPartName(), OrgauthoritiesCommon.class);
1341 Assert.assertNotNull(updatedOrgAuthority);
1343 // Verify that the updated resource received the correct data.
1344 Assert.assertEquals(updatedOrgAuthority.getDisplayName(),
1345 orgAuthority.getDisplayName(),
1346 "Data in updated object did not match submitted data.");
1348 res.releaseConnection();
1355 * @param testName the test name
1356 * @throws Exception the exception
1358 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1359 groups = {"update"}, dependsOnMethods = {"update"})
1360 public void updateItem(String testName) throws Exception {
1362 if (logger.isDebugEnabled()) {
1363 logger.debug(testBanner(testName, CLASS_NAME));
1368 // Retrieve the contents of a resource to update.
1369 OrgAuthorityClient client = new OrgAuthorityClient();
1370 ClientResponse<String> res =
1371 client.readItem(knownResourceId, knownItemResourceId);
1373 if(logger.isDebugEnabled()){
1374 logger.debug(testName + ": read status = " + res.getStatus());
1376 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1378 if(logger.isDebugEnabled()){
1379 logger.debug("got Organization to update with ID: " +
1380 knownItemResourceId +
1381 " in OrgAuthority: " + knownResourceId );
1383 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
1384 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
1385 client.getItemCommonPartName(), OrganizationsCommon.class);
1386 Assert.assertNotNull(organization);
1388 // Update the contents of this resource.
1389 organization.setCsid(null);
1391 MainBodyGroupList mainBodyList = organization.getMainBodyGroupList();
1392 Assert.assertNotNull(mainBodyList);
1393 List<MainBodyGroup> mainBodyGroups = mainBodyList.getMainBodyGroup();
1394 Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0);
1395 String updatedShortName = "updated-" + mainBodyGroups.get(0).getShortName();
1396 mainBodyGroups.get(0).setShortName(updatedShortName);
1398 if(logger.isDebugEnabled()){
1399 logger.debug("to be updated Organization");
1400 logger.debug(objectAsXmlString(organization,
1401 OrganizationsCommon.class));
1404 // Submit the updated resource to the service and store the response.
1405 PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1406 PayloadOutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
1407 commonPart.setLabel(client.getItemCommonPartName());
1408 res.releaseConnection();
1409 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1410 int statusCode = res.getStatus();
1412 // Check the status code of the response: does it match the expected response(s)?
1413 if(logger.isDebugEnabled()){
1414 logger.debug(testName + ": status = " + statusCode);
1416 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1417 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1418 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1420 // Retrieve the updated resource and verify that its contents exist.
1421 input = new PoxPayloadIn(res.getEntity());
1422 OrganizationsCommon updatedOrganization =
1423 (OrganizationsCommon) extractPart(input,
1424 client.getItemCommonPartName(), OrganizationsCommon.class);
1425 Assert.assertNotNull(updatedOrganization);
1427 // Verify that the updated resource received the correct data.
1428 mainBodyList = organization.getMainBodyGroupList();
1429 Assert.assertNotNull(mainBodyList);
1430 Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0);
1431 Assert.assertEquals(updatedOrganization.getMainBodyGroupList().getMainBodyGroup().get(0).getShortName(),
1432 updatedShortName, "Data in updated Organization did not match submitted data.");
1434 res.releaseConnection();
1441 * @param testName the test name
1442 * @throws Exception the exception
1444 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1445 groups = {"update"}, dependsOnMethods = {"updateItem"})
1446 public void updateContact(String testName) throws Exception {
1448 if (logger.isDebugEnabled()) {
1449 logger.debug(testBanner(testName, CLASS_NAME));
1454 // Retrieve the contents of a resource to update.
1455 OrgAuthorityClient client = new OrgAuthorityClient();
1456 ClientResponse<String> res =
1457 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1459 if(logger.isDebugEnabled()){
1460 logger.debug(testName + ": read status = " + res.getStatus());
1462 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1464 if(logger.isDebugEnabled()){
1465 logger.debug("got Contact to update with ID: " +
1466 knownContactResourceId +
1467 " in item: " + knownItemResourceId +
1468 " in parent: " + knownResourceId );
1470 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
1471 ContactsCommon contact = (ContactsCommon) extractPart(input,
1472 new ContactClient().getCommonPartName(), ContactsCommon.class);
1473 Assert.assertNotNull(contact);
1475 // Update the contents of this resource.
1476 contact.setAddressPlace("updated-" + contact.getAddressPlace());
1477 if(logger.isDebugEnabled()){
1478 logger.debug("to be updated Contact");
1479 logger.debug(objectAsXmlString(contact,
1480 ContactsCommon.class));
1483 // Submit the updated resource to the service and store the response.
1484 PoxPayloadOut output = new PoxPayloadOut(ContactClient.SERVICE_PAYLOAD_NAME);
1485 PayloadOutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1486 commonPart.setLabel(new ContactClient().getCommonPartName());
1487 res.releaseConnection();
1488 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1489 int statusCode = res.getStatus();
1491 // Check the status code of the response: does it match the expected response(s)?
1492 if(logger.isDebugEnabled()){
1493 logger.debug(testName + ": status = " + statusCode);
1495 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1496 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1497 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1499 // Retrieve the updated resource and verify that its contents exist.
1500 input = new PoxPayloadIn(res.getEntity());
1501 ContactsCommon updatedContact =
1502 (ContactsCommon) extractPart(input,
1503 new ContactClient().getCommonPartName(), ContactsCommon.class);
1504 Assert.assertNotNull(updatedContact);
1506 // Verify that the updated resource received the correct data.
1507 Assert.assertEquals(updatedContact.getAddressPlace(),
1508 contact.getAddressPlace(),
1509 "Data in updated Contact did not match submitted data.");
1511 res.releaseConnection();
1516 // Placeholders until the three tests below can be uncommented.
1517 // See Issue CSPACE-401.
1519 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1522 public void updateWithEmptyEntityBody(String testName) throws Exception {
1523 //Should this really be empty?
1527 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1530 public void updateWithMalformedXml(String testName) throws Exception {
1531 //Should this really be empty?
1535 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1538 public void updateWithWrongXmlSchema(String testName) throws Exception {
1539 //Should this really be empty?
1544 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1545 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1546 public void updateWithEmptyEntityBody(String testName) throws Exception {
1548 if (logger.isDebugEnabled()) {
1549 logger.debug(testBanner(testName, CLASS_NAME));
1552 setupUpdateWithEmptyEntityBody();
1554 // Submit the request to the service and store the response.
1555 String method = REQUEST_TYPE.httpMethodName();
1556 String url = getResourceURL(knownResourceId);
1557 String mediaType = MediaType.APPLICATION_XML;
1558 final String entity = "";
1559 int statusCode = submitRequest(method, url, mediaType, entity);
1561 // Check the status code of the response: does it match
1562 // the expected response(s)?
1563 if(logger.isDebugEnabled()){
1564 logger.debug(testName + ": url=" + url +
1565 " status=" + statusCode);
1567 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1568 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1569 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1573 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1574 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1575 public void updateWithMalformedXml(String testName) throws Exception {
1577 if (logger.isDebugEnabled()) {
1578 logger.debug(testBanner(testName, CLASS_NAME));
1581 setupUpdateWithMalformedXml();
1583 // Submit the request to the service and store the response.
1584 String method = REQUEST_TYPE.httpMethodName();
1585 String url = getResourceURL(knownResourceId);
1586 String mediaType = MediaType.APPLICATION_XML;
1587 final String entity = MALFORMED_XML_DATA;
1588 int statusCode = submitRequest(method, url, mediaType, entity);
1590 // Check the status code of the response: does it match
1591 // the expected response(s)?
1592 if(logger.isDebugEnabled()){
1593 logger.debug(testName + ": url=" + url +
1594 " status=" + statusCode);
1596 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1597 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1598 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1602 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1603 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1604 public void updateWithWrongXmlSchema(String testName) throws Exception {
1607 setupUpdateWithWrongXmlSchema(testName, logger);
1609 // Submit the request to the service and store the response.
1610 String method = REQUEST_TYPE.httpMethodName();
1611 String url = getResourceURL(knownResourceId);
1612 String mediaType = MediaType.APPLICATION_XML;
1613 final String entity = WRONG_XML_SCHEMA_DATA;
1614 int statusCode = submitRequest(method, url, mediaType, entity);
1616 // Check the status code of the response: does it match
1617 // the expected response(s)?
1618 if(logger.isDebugEnabled()){
1619 logger.debug("updateWithWrongXmlSchema: url=" + url +
1620 " status=" + statusCode);
1622 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1623 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1624 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1629 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1632 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1633 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1634 public void updateNonExistent(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 used in this 'create' call may be arbitrary.
1644 // The only relevant ID may be the one used in update(), below.
1645 OrgAuthorityClient client = new OrgAuthorityClient();
1646 PoxPayloadOut multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance(
1647 NON_EXISTENT_ID, NON_EXISTENT_ID,
1648 new OrgAuthorityClient().getCommonPartName());
1649 ClientResponse<String> res =
1650 client.update(NON_EXISTENT_ID, multipart);
1652 int statusCode = res.getStatus();
1654 // Check the status code of the response: does it match
1655 // the expected response(s)?
1656 if(logger.isDebugEnabled()){
1657 logger.debug(testName + ": status = " + statusCode);
1659 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1660 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1661 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1663 res.releaseConnection();
1668 * Update non existent item.
1670 * @param testName the test name
1671 * @throws Exception the exception
1673 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1674 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1675 public void updateNonExistentItem(String testName) throws Exception {
1677 if (logger.isDebugEnabled()) {
1678 logger.debug(testBanner(testName, CLASS_NAME));
1681 setupUpdateNonExistent();
1683 // Submit the request to the service and store the response.
1684 // Note: The ID(s) used when creating the request payload may be arbitrary.
1685 // The only relevant ID may be the one used in update(), below.
1686 OrgAuthorityClient client = new OrgAuthorityClient();
1687 Map<String, String> nonexOrgMap = new HashMap<String,String>();
1688 nonexOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, "nonExistent");
1689 nonexOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Non-existent");
1690 PoxPayloadOut multipart =
1691 OrgAuthorityClientUtils.createOrganizationInstance(
1692 knownResourceRefName,
1693 nonexOrgMap, client.getItemCommonPartName() );
1694 ClientResponse<String> res =
1695 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1697 int statusCode = res.getStatus();
1699 // Check the status code of the response: does it match
1700 // the expected response(s)?
1701 if(logger.isDebugEnabled()){
1702 logger.debug(testName + ": status = " + statusCode);
1704 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1705 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1706 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1708 res.releaseConnection();
1713 * Update non existent contact.
1715 * @param testName the test name
1716 * @throws Exception the exception
1718 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1719 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1720 public void updateNonExistentContact(String testName) throws Exception {
1721 // Currently a no-op test
1724 // ---------------------------------------------------------------
1725 // CRUD tests : DELETE tests
1726 // ---------------------------------------------------------------
1729 // Note: delete sub-resources in ascending hierarchical order,
1730 // before deleting their parents.
1735 * @param testName the test name
1736 * @throws Exception the exception
1738 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1739 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1740 public void deleteContact(String testName) throws Exception {
1742 if (logger.isDebugEnabled()) {
1743 logger.debug(testBanner(testName, CLASS_NAME));
1748 if(logger.isDebugEnabled()){
1749 logger.debug("parentcsid =" + knownResourceId +
1750 " itemcsid = " + knownItemResourceId +
1751 " csid = " + knownContactResourceId);
1754 // Submit the request to the service and store the response.
1755 OrgAuthorityClient client = new OrgAuthorityClient();
1756 ClientResponse<Response> res =
1757 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1759 int statusCode = res.getStatus();
1761 // Check the status code of the response: does it match
1762 // the expected response(s)?
1763 if(logger.isDebugEnabled()){
1764 logger.debug(testName + ": status = " + statusCode);
1766 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1767 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1768 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1770 res.releaseConnection();
1777 * @param testName the test name
1778 * @throws Exception the exception
1780 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1781 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1782 public void deleteItem(String testName) throws Exception {
1784 if (logger.isDebugEnabled()) {
1785 logger.debug(testBanner(testName, CLASS_NAME));
1790 if(logger.isDebugEnabled()){
1791 logger.debug("parentcsid =" + knownResourceId +
1792 " itemcsid = " + knownItemResourceId);
1795 // Submit the request to the service and store the response.
1796 OrgAuthorityClient client = new OrgAuthorityClient();
1797 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1799 int statusCode = res.getStatus();
1801 // Check the status code of the response: does it match
1802 // the expected response(s)?
1803 if(logger.isDebugEnabled()){
1804 logger.debug(testName + ": status = " + statusCode);
1806 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1807 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1808 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1810 res.releaseConnection();
1815 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1818 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1819 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1820 public void delete(String testName) throws Exception {
1822 if (logger.isDebugEnabled()) {
1823 logger.debug(testBanner(testName, CLASS_NAME));
1828 if(logger.isDebugEnabled()){
1829 logger.debug("parentcsid =" + knownResourceId);
1832 // Submit the request to the service and store the response.
1833 OrgAuthorityClient client = new OrgAuthorityClient();
1834 ClientResponse<Response> res = client.delete(knownResourceId);
1836 int statusCode = res.getStatus();
1838 // Check the status code of the response: does it match
1839 // the expected response(s)?
1840 if(logger.isDebugEnabled()){
1841 logger.debug(testName + ": status = " + statusCode);
1843 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1844 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1845 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1847 res.releaseConnection();
1853 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1856 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1857 groups = {"delete"}, dependsOnMethods = {"delete"})
1858 public void deleteNonExistent(String testName) throws Exception {
1860 if (logger.isDebugEnabled()) {
1861 logger.debug(testBanner(testName, CLASS_NAME));
1864 setupDeleteNonExistent();
1866 // Submit the request to the service and store the response.
1867 OrgAuthorityClient client = new OrgAuthorityClient();
1868 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1870 int statusCode = res.getStatus();
1872 // Check the status code of the response: does it match
1873 // the expected response(s)?
1874 if(logger.isDebugEnabled()){
1875 logger.debug(testName + ": status = " + statusCode);
1877 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1878 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1879 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1881 res.releaseConnection();
1886 * Delete non existent item.
1888 * @param testName the test name
1890 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1891 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1892 public void deleteNonExistentItem(String testName) {
1894 if (logger.isDebugEnabled()) {
1895 logger.debug(testBanner(testName, CLASS_NAME));
1898 setupDeleteNonExistent();
1900 // Submit the request to the service and store the response.
1901 OrgAuthorityClient client = new OrgAuthorityClient();
1902 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1904 int statusCode = res.getStatus();
1906 // Check the status code of the response: does it match
1907 // the expected response(s)?
1908 if(logger.isDebugEnabled()){
1909 logger.debug(testName + ": status = " + statusCode);
1911 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1912 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1913 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1915 res.releaseConnection();
1920 * Delete non existent contact.
1922 * @param testName the test name
1924 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1925 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1926 public void deleteNonExistentContact(String testName) {
1928 if (logger.isDebugEnabled()) {
1929 logger.debug(testBanner(testName, CLASS_NAME));
1932 setupDeleteNonExistent();
1934 // Submit the request to the service and store the response.
1935 OrgAuthorityClient client = new OrgAuthorityClient();
1936 ClientResponse<Response> res =
1937 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1939 int statusCode = res.getStatus();
1941 // Check the status code of the response: does it match
1942 // the expected response(s)?
1943 if(logger.isDebugEnabled()){
1944 logger.debug(testName + ": status = " + statusCode);
1946 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1947 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1948 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1950 res.releaseConnection();
1954 // ---------------------------------------------------------------
1955 // Utility tests : tests of code used in tests above
1956 // ---------------------------------------------------------------
1958 * Tests the code for manually submitting data that is used by several
1959 * of the methods above.
1961 @Test(dependsOnMethods = {"create", "read"})
1962 public void testSubmitRequest() {
1964 // Expected status code: 200 OK
1965 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1967 // Submit the request to the service and store the response.
1968 String method = ServiceRequestType.READ.httpMethodName();
1969 String url = getResourceURL(knownResourceId);
1970 int statusCode = submitRequest(method, url);
1972 // Check the status code of the response: does it match
1973 // the expected response(s)?
1974 if(logger.isDebugEnabled()){
1975 logger.debug("testSubmitRequest: url=" + url +
1976 " status=" + statusCode);
1978 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1983 * Test item submit request.
1985 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1986 public void testItemSubmitRequest() {
1988 // Expected status code: 200 OK
1989 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1991 // Submit the request to the service and store the response.
1992 String method = ServiceRequestType.READ.httpMethodName();
1993 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1994 int statusCode = submitRequest(method, url);
1996 // Check the status code of the response: does it match
1997 // the expected response(s)?
1998 if(logger.isDebugEnabled()){
1999 logger.debug("testItemSubmitRequest: url=" + url +
2000 " status=" + statusCode);
2002 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2007 * Test contact submit request.
2009 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
2010 public void testContactSubmitRequest() {
2012 // Expected status code: 200 OK
2013 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2015 // Submit the request to the service and store the response.
2016 String method = ServiceRequestType.READ.httpMethodName();
2017 String url = getContactResourceURL(knownResourceId,
2018 knownItemResourceId, knownContactResourceId);
2019 int statusCode = submitRequest(method, url);
2021 // Check the status code of the response: does it match
2022 // the expected response(s)?
2023 if(logger.isDebugEnabled()){
2024 logger.debug("testItemSubmitRequest: url=" + url +
2025 " status=" + statusCode);
2027 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2032 // ---------------------------------------------------------------
2033 // Cleanup of resources created during testing
2034 // ---------------------------------------------------------------
2037 * Deletes all resources created by tests, after all tests have been run.
2039 * This cleanup method will always be run, even if one or more tests fail.
2040 * For this reason, it attempts to remove all resources created
2041 * at any point during testing, even if some of those resources
2042 * may be expected to be deleted by certain tests.
2045 @AfterClass(alwaysRun=true)
2047 public void cleanUp() {
2048 String noTest = System.getProperty("noTestCleanup");
2049 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
2050 if (logger.isDebugEnabled()) {
2051 logger.debug("Skipping Cleanup phase ...");
2055 if (logger.isDebugEnabled()) {
2056 logger.debug("Cleaning up temporary resources created for testing ...");
2059 String parentResourceId;
2060 String itemResourceId;
2061 String contactResourceId;
2062 // Clean up contact resources.
2063 parentResourceId = knownResourceId;
2064 OrgAuthorityClient client = new OrgAuthorityClient();
2065 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
2066 contactResourceId = entry.getKey();
2067 itemResourceId = entry.getValue();
2068 // Note: Any non-success responses from the delete operation
2069 // below are ignored and not reported.
2070 ClientResponse<Response> res =
2071 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
2072 res.releaseConnection();
2074 // Clean up item resources.
2075 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
2076 itemResourceId = entry.getKey();
2077 parentResourceId = entry.getValue();
2078 // Note: Any non-success responses from the delete operation
2079 // below are ignored and not reported.
2080 ClientResponse<Response> res =
2081 client.deleteItem(parentResourceId, itemResourceId);
2082 res.releaseConnection();
2084 // Clean up parent resources.
2089 // ---------------------------------------------------------------
2090 // Utility methods used by tests above
2091 // ---------------------------------------------------------------
2093 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
2096 * Gets the item service path component.
2098 * @return the item service path component
2100 public String getItemServicePathComponent() {
2101 return AuthorityClient.ITEMS;
2105 * Gets the contact service path component.
2107 * @return the contact service path component
2109 public String getContactServicePathComponent() {
2110 return ContactClient.SERVICE_PATH_COMPONENT;
2114 * Returns the root URL for the item service.
2116 * This URL consists of a base URL for all services, followed by
2117 * a path component for the owning parent, followed by the
2118 * path component for the items.
2120 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2121 * parent authority resource of the relevant item resource.
2123 * @return The root URL for the item service.
2125 protected String getItemServiceRootURL(String parentResourceIdentifier) {
2126 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
2130 * Returns the URL of a specific item resource managed by a service, and
2131 * designated by an identifier (such as a universally unique ID, or UUID).
2133 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2134 * parent authority resource of the relevant item resource.
2136 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2139 * @return The URL of a specific item resource managed by a service.
2141 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
2142 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
2147 * Returns the root URL for the contact service.
2149 * This URL consists of a base URL for all services, followed by
2150 * a path component for the owning authority, followed by the
2151 * path component for the owning item, followed by the path component
2152 * for the contact service.
2154 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2155 * parent authority resource of the relevant item resource.
2157 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2160 * @return The root URL for the contact service.
2162 protected String getContactServiceRootURL(String parentResourceIdentifier,
2163 String itemResourceIdentifier) {
2164 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
2165 getContactServicePathComponent();
2169 * Returns the URL of a specific contact resource managed by a service, and
2170 * designated by an identifier (such as a universally unique ID, or UUID).
2172 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2173 * parent resource of the relevant item resource.
2175 * @param resourceIdentifier An identifier (such as a UUID) for an
2178 * @return The URL of a specific resource managed by a service.
2180 protected String getContactResourceURL(String parentResourceIdentifier,
2181 String itemResourceIdentifier, String contactResourceIdentifier) {
2182 return getContactServiceRootURL(parentResourceIdentifier,
2183 itemResourceIdentifier) + "/" + contactResourceIdentifier;