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.AddressGroup;
42 import org.collectionspace.services.contact.AddressGroupList;
43 import org.collectionspace.services.contact.ContactsCommon;
44 import org.collectionspace.services.client.OrgAuthorityClient;
45 import org.collectionspace.services.client.OrgAuthorityClientUtils;
46 import org.collectionspace.services.jaxb.AbstractCommonList;
47 import org.collectionspace.services.organization.MainBodyGroup;
48 import org.collectionspace.services.organization.MainBodyGroupList;
49 import org.collectionspace.services.organization.OrgauthoritiesCommon;
50 import org.collectionspace.services.organization.OrganizationsCommon;
52 import org.jboss.resteasy.client.ClientResponse;
54 import org.slf4j.Logger;
55 import org.slf4j.LoggerFactory;
56 import org.testng.Assert;
57 import org.testng.annotations.AfterClass;
58 import org.testng.annotations.Test;
61 * OrgAuthorityServiceTest, carries out tests against a
62 * deployed and running OrgAuthority Service.
64 * $LastChangedRevision$
67 public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: Test classes for Vocab, Person, Org, and Location should have a base class!
70 private final String CLASS_NAME = OrgAuthorityServiceTest.class.getName();
71 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
72 private final String REFNAME = "refName";
73 private final String DISPLAYNAME = "displayName";
76 public String getServicePathComponent() {
77 return OrgAuthorityClient.SERVICE_PATH_COMPONENT;
81 protected String getServiceName() {
82 return OrgAuthorityClient.SERVICE_NAME;
84 /** The test organization shortname. */
85 private final String TEST_ORG_SHORTNAME = "Test Org";
86 /** The test organization founding place. */
87 private final String TEST_ORG_FOUNDING_PLACE = "Anytown, USA";
88 // Hold some values for a recently created item to verify upon read.
89 private String knownResourceId = null;
90 private String knownResourceShortIdentifer = null;
91 private String knownResourceRefName = null;
92 private String knownItemResourceId = null;
93 private String knownItemResourceShortIdentifer = null;
94 /** The known contact resource id. */
95 private String knownContactResourceId = null;
96 /** The n items to create in list. */
97 private int nItemsToCreateInList = 3;
98 /** The all item resource ids created. */
99 private Map<String, String> allItemResourceIdsCreated =
100 new HashMap<String, String>();
101 /** The all contact resource ids created. */
102 private Map<String, String> allContactResourceIdsCreated =
103 new HashMap<String, String>();
105 protected void setKnownResource(String id, String shortIdentifer,
107 knownResourceId = id;
108 knownResourceShortIdentifer = shortIdentifer;
109 knownResourceRefName = refName;
112 protected void setKnownItemResource(String id, String shortIdentifer) {
113 knownItemResourceId = id;
114 knownItemResourceShortIdentifer = shortIdentifer;
118 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
121 protected CollectionSpaceClient getClientInstance() {
122 return new OrgAuthorityClient();
125 // ---------------------------------------------------------------
126 // CRUD tests : CREATE tests
127 // ---------------------------------------------------------------
130 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
133 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
135 public void create(String testName) throws Exception {
137 if (logger.isDebugEnabled()) {
138 logger.debug(testBanner(testName, CLASS_NAME));
140 // Perform setup, such as initializing the type of service request
141 // (e.g. CREATE, DELETE), its valid and expected status codes, and
142 // its associated HTTP method name (e.g. POST, DELETE).
145 // Submit the request to the service and store the response.
146 OrgAuthorityClient client = new OrgAuthorityClient();
147 String shortId = createIdentifier();
148 String displayName = "displayName-" + shortId;
149 //String baseRefName = OrgAuthorityClientUtils.createOrgAuthRefName(shortId, null);
150 PoxPayloadOut multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance(
151 displayName, shortId, client.getCommonPartName());
154 ClientResponse<Response> res = client.create(multipart);
156 int statusCode = res.getStatus();
158 // Check the status code of the response: does it match
159 // the expected response(s)?
162 // Does it fall within the set of valid status codes?
163 // Does it exactly match the expected status code?
164 if (logger.isDebugEnabled()) {
165 logger.debug(testName + ": status = " + statusCode);
167 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
168 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
169 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
171 newID = OrgAuthorityClientUtils.extractId(res);
173 res.releaseConnection();
176 // Store the ID returned from the first resource created
177 // for additional tests below.
178 if (knownResourceId == null) {
179 setKnownResource(newID, shortId, null ); //baseRefName);
180 if (logger.isDebugEnabled()) {
181 logger.debug(testName + ": knownResourceId=" + knownResourceId);
184 // Store the IDs from every resource created by tests,
185 // so they can be deleted after tests have been run.
186 allResourceIdsCreated.add(newID);
190 protected PoxPayloadOut createInstance(String identifier) {
191 OrgAuthorityClient client = new OrgAuthorityClient();
192 String displayName = "displayName-" + identifier;
193 PoxPayloadOut multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance(
194 displayName, identifier, client.getCommonPartName());
199 protected PoxPayloadOut createItemInstance(String parentCsid, String identifier) {
200 String headerLabel = new OrgAuthorityClient().getItemCommonPartName();
201 String shortId = "testOrg";
202 Map<String, String> testOrgMap = new HashMap<String, String>();
203 testOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId);
204 testOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, TEST_ORG_SHORTNAME);
205 testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "The real official test organization");
206 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "May 26, 1907");
207 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, TEST_ORG_FOUNDING_PLACE);
209 return OrgAuthorityClientUtils.createOrganizationInstance(identifier, testOrgMap, headerLabel);
215 * @param testName the test name
217 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
218 groups = {"create"}, dependsOnMethods = {"create"})
219 public void createItem(String testName) {
221 String newID = createItemInAuthority(knownResourceId, knownResourceRefName);
225 * Creates the item in authority.
227 * @param vcsid the vcsid
228 * @param authRefName the auth ref name
231 private String createItemInAuthority(String vcsid, String authRefName) {
233 final String testName = "createItemInAuthority";
234 if (logger.isDebugEnabled()) {
235 logger.debug(testName + ":...");
238 // Submit the request to the service and store the response.
239 OrgAuthorityClient client = new OrgAuthorityClient();
240 String shortId = "testOrg";
241 Map<String, String> testOrgMap = new HashMap<String, String>();
242 testOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId);
243 testOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, TEST_ORG_SHORTNAME);
244 testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "The real official test organization");
245 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "May 26, 1907");
246 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, TEST_ORG_FOUNDING_PLACE);
248 Map<String, List<String>> testOrgRepeatablesMap = new HashMap<String, List<String>>();
249 List<String> testOrgContactNames = new ArrayList<String>();
250 testOrgContactNames.add("joe@example.org");
251 testOrgContactNames.add("sally@example.org");
252 testOrgRepeatablesMap.put(OrganizationJAXBSchema.CONTACT_NAMES, testOrgContactNames);
254 MainBodyGroupList mainBodyList = new MainBodyGroupList();
255 List<MainBodyGroup> mainBodyGroups = mainBodyList.getMainBodyGroup();
256 MainBodyGroup mainBodyGroup = new MainBodyGroup();
257 mainBodyGroup.setShortName(TEST_ORG_SHORTNAME);
258 mainBodyGroup.setLongName("The real official test organization");
259 mainBodyGroups.add(mainBodyGroup);
261 String newID = OrgAuthorityClientUtils.createItemInAuthority(
262 vcsid, authRefName, testOrgMap, testOrgRepeatablesMap, mainBodyList, client);
264 // Store the ID returned from the first item resource created
265 // for additional tests below.
266 if (knownItemResourceId == null) {
267 setKnownItemResource(newID, shortId);
268 if (logger.isDebugEnabled()) {
269 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
273 // Store the IDs from any item resources created
274 // by tests, along with the IDs of their parents, so these items
275 // can be deleted after all tests have been run.
276 allItemResourceIdsCreated.put(newID, vcsid);
282 * Creates the contact.
284 * @param testName the test name
286 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
287 groups = {"create"}, dependsOnMethods = {"createItem"})
288 public void createContact(String testName) {
290 String newID = createContactInItem(knownResourceId, knownItemResourceId);
294 * Creates the contact in item.
296 * @param parentcsid the parentcsid
297 * @param itemcsid the itemcsid
300 private String createContactInItem(String parentcsid, String itemcsid) {
302 final String testName = "createContactInItem";
303 if (logger.isDebugEnabled()) {
304 logger.debug(testBanner(testName, CLASS_NAME));
308 // Submit the request to the service and store the response.
309 OrgAuthorityClient client = new OrgAuthorityClient();
310 String identifier = createIdentifier();
311 PoxPayloadOut multipart =
312 ContactClientUtils.createContactInstance(parentcsid,
313 itemcsid, identifier, new ContactClient().getCommonPartName());
316 ClientResponse<Response> res =
317 client.createContact(parentcsid, itemcsid, multipart);
319 int statusCode = res.getStatus();
320 // Check the status code of the response: does it match
321 // the expected response(s)?
322 if (logger.isDebugEnabled()) {
323 logger.debug(testName + ": status = " + statusCode);
325 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
326 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
327 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
329 newID = OrgAuthorityClientUtils.extractId(res);
331 res.releaseConnection();
334 // Store the ID returned from the first contact resource created
335 // for additional tests below.
336 if (knownContactResourceId == null) {
337 knownContactResourceId = newID;
338 if (logger.isDebugEnabled()) {
339 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
343 // Store the IDs from any contact resources created
344 // by tests, along with the IDs of their parent items,
345 // so these items can be deleted after all tests have been run.
346 allContactResourceIdsCreated.put(newID, itemcsid);
352 // Placeholders until the three tests below can be uncommented.
353 // See Issue CSPACE-401.
355 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
358 public void createWithEmptyEntityBody(String testName) throws Exception {
359 //Should this really be empty?
363 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
366 public void createWithMalformedXml(String testName) throws Exception {
367 //Should this really be empty?
371 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
374 public void createWithWrongXmlSchema(String testName) throws Exception {
375 //Should this really be empty?
380 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
381 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
382 public void createWithEmptyEntityBody(String testName) throws Exception {
384 if (logger.isDebugEnabled()) {
385 logger.debug(testBanner(testName, CLASS_NAME));
388 setupCreateWithEmptyEntityBody();
390 // Submit the request to the service and store the response.
391 String method = REQUEST_TYPE.httpMethodName();
392 String url = getServiceRootURL();
393 String mediaType = MediaType.APPLICATION_XML;
394 final String entity = "";
395 int statusCode = submitRequest(method, url, mediaType, entity);
397 // Check the status code of the response: does it match
398 // the expected response(s)?
399 if(logger.isDebugEnabled()) {
400 logger.debug(testName + ": url=" + url +
401 " status=" + statusCode);
403 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
404 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
405 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
409 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
410 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
411 public void createWithMalformedXml(String testName) throws Exception {
413 if (logger.isDebugEnabled()) {
414 logger.debug(testBanner(testName, CLASS_NAME));
417 setupCreateWithMalformedXml();
419 // Submit the request to the service and store the response.
420 String method = REQUEST_TYPE.httpMethodName();
421 String url = getServiceRootURL();
422 String mediaType = MediaType.APPLICATION_XML;
423 final String entity = MALFORMED_XML_DATA; // Constant from base class.
424 int statusCode = submitRequest(method, url, mediaType, entity);
426 // Check the status code of the response: does it match
427 // the expected response(s)?
428 if(logger.isDebugEnabled()){
429 logger.debug(testName + ": url=" + url +
430 " status=" + statusCode);
432 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
433 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
434 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
438 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
439 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
440 public void createWithWrongXmlSchema(String testName) throws Exception {
442 if (logger.isDebugEnabled()) {
443 logger.debug(testBanner(testName, CLASS_NAME));
446 setupCreateWithWrongXmlSchema();
448 // Submit the request to the service and store the response.
449 String method = REQUEST_TYPE.httpMethodName();
450 String url = getServiceRootURL();
451 String mediaType = MediaType.APPLICATION_XML;
452 final String entity = WRONG_XML_SCHEMA_DATA;
453 int statusCode = submitRequest(method, url, mediaType, entity);
455 // Check the status code of the response: does it match
456 // the expected response(s)?
457 if(logger.isDebugEnabled()){
458 logger.debug(testName + ": url=" + url +
459 " status=" + statusCode);
461 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
462 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
463 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
466 // ---------------------------------------------------------------
467 // CRUD tests : CREATE LIST tests
468 // ---------------------------------------------------------------
471 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
474 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
475 groups = {"createList"}, dependsOnGroups = {"create"})
476 public void createList(String testName) throws Exception {
477 for (int i = 0; i < nItemsToCreateInList; i++) {
483 * Creates the item list.
485 * @param testName the test name
486 * @throws Exception the exception
488 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
489 groups = {"createList"}, dependsOnMethods = {"createList"})
490 public void createItemList(String testName) throws Exception {
491 // Add items to the initially-created, known parent record.
492 for (int j = 0; j < nItemsToCreateInList; j++) {
493 createItem(testName);
498 * Creates the contact list.
500 * @param testName the test name
501 * @throws Exception the exception
503 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
504 groups = {"createList"}, dependsOnMethods = {"createItemList"})
505 public void createContactList(String testName) throws Exception {
506 // Add contacts to the initially-created, known item record.
507 for (int j = 0; j < nItemsToCreateInList; j++) {
508 createContact(testName);
512 // ---------------------------------------------------------------
513 // CRUD tests : READ tests
514 // ---------------------------------------------------------------
517 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
520 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
521 groups = {"read"}, dependsOnGroups = {"create"})
522 public void read(String testName) throws Exception {
523 readInternal(testName, knownResourceId, null);
529 * @param testName the test name
530 * @throws Exception the exception
532 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
533 groups = {"read"}, dependsOnGroups = {"create"})
534 public void readByName(String testName) throws Exception {
535 readInternal(testName, null, knownResourceShortIdentifer);
538 protected void readInternal(String testName, String CSID, String shortId) {
540 if (logger.isDebugEnabled()) {
541 logger.debug(testBanner(testName, CLASS_NAME));
546 // Submit the request to the service and store the response.
547 OrgAuthorityClient client = new OrgAuthorityClient();
548 ClientResponse<String> res = null;
550 res = client.read(CSID);
551 } else if (shortId != null) {
552 res = client.readByName(shortId);
554 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
557 int statusCode = res.getStatus();
559 // Check the status code of the response: does it match
560 // the expected response(s)?
561 if (logger.isDebugEnabled()) {
562 logger.debug(testName + ": status = " + statusCode);
564 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
565 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
566 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
567 //FIXME: remove the following try catch once Aron fixes signatures
569 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
570 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
571 new OrgAuthorityClient().getCommonPartName(), OrgauthoritiesCommon.class);
572 if (logger.isDebugEnabled()) {
573 logger.debug(objectAsXmlString(orgAuthority, OrgauthoritiesCommon.class));
575 Assert.assertNotNull(orgAuthority);
576 } catch (Exception e) {
577 throw new RuntimeException(e);
580 res.releaseConnection();
587 * @param testName the test name
588 * @throws Exception the exception
590 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
591 groups = {"readItem"}, dependsOnGroups = {"read"})
592 public void readItem(String testName) throws Exception {
593 readItemInternal(testName, knownResourceId, null, knownItemResourceId, null);
597 * Read item in Named Auth.
599 * TODO Enable this if we really need this - it is a funky case, where we would have
600 * the shortId of the item, but the CSID of the parent authority!? Unlikely.
602 * @param testName the test name
603 * @throws Exception the exception
604 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
605 groups = {"readItem"}, dependsOnGroups = {"read"})
606 public void readItemInNamedAuth(String testName) throws Exception {
607 readItemInternal(testName, null, knownResourceShortIdentifer, knownItemResourceId, null);
613 * @param testName the test name
614 * @throws Exception the exception
616 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
617 groups = {"readItem"}, dependsOnGroups = {"read"})
618 public void readNamedItem(String testName) throws Exception {
619 readItemInternal(testName, knownResourceId, null, null, knownItemResourceShortIdentifer);
623 * Read Named item in Named Auth.
625 * @param testName the test name
626 * @throws Exception the exception
628 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
629 groups = {"readItem"}, dependsOnGroups = {"read"})
630 public void readNamedItemInNamedAuth(String testName) throws Exception {
631 readItemInternal(testName, null, knownResourceShortIdentifer, null, knownItemResourceShortIdentifer);
634 protected void readItemInternal(String testName,
635 String authCSID, String authShortId, String itemCSID, String itemShortId)
638 if (logger.isDebugEnabled()) {
639 logger.debug(testBanner(testName, CLASS_NAME));
644 // Submit the request to the service and store the response.
645 OrgAuthorityClient client = new OrgAuthorityClient();
646 ClientResponse<String> res = null;
647 if (authCSID != null) {
648 if (itemCSID != null) {
649 res = client.readItem(authCSID, itemCSID);
650 } else if (itemShortId != null) {
651 res = client.readNamedItem(authCSID, itemShortId);
653 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
655 } else if (authShortId != null) {
656 if (itemCSID != null) {
657 res = client.readItemInNamedAuthority(authShortId, itemCSID);
658 } else if (itemShortId != null) {
659 res = client.readNamedItemInNamedAuthority(authShortId, itemShortId);
661 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
664 Assert.fail("readInternal: Internal error. One of authCSID or authShortId must be non-null");
667 int statusCode = res.getStatus();
669 // Check the status code of the response: does it match
670 // the expected response(s)?
671 if (logger.isDebugEnabled()) {
672 logger.debug(testName + ": status = " + statusCode);
674 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
675 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
676 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
678 // Check whether we've received a organization.
679 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
680 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
681 client.getItemCommonPartName(), OrganizationsCommon.class);
682 Assert.assertNotNull(organization);
683 boolean showFull = true;
684 if (showFull && logger.isDebugEnabled()) {
685 logger.debug(testName + ": returned payload:");
686 logger.debug(objectAsXmlString(organization, OrganizationsCommon.class));
689 // Check that the organization item is within the expected OrgAuthority.
690 Assert.assertEquals(organization.getInAuthority(), knownResourceId);
692 // Verify the number and contents of values in a repeatable field,
693 // as created in the instance record used for testing.
694 List<String> contactNames = organization.getContactNames().getContactName();
695 Assert.assertTrue(contactNames.size() > 0);
696 Assert.assertNotNull(contactNames.get(0));
699 res.releaseConnection();
704 * Verify item display name.
706 * @param testName the test name
707 * @throws Exception the exception
709 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
710 dependsOnMethods = {"readItem", "updateItem"})
711 public void verifyItemDisplayName(String testName) throws Exception {
713 if (logger.isDebugEnabled()) {
714 logger.debug(testBanner(testName, CLASS_NAME));
719 // Submit the request to the service and store the response.
720 OrgAuthorityClient client = new OrgAuthorityClient();
721 PoxPayloadIn input = null;
722 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
724 int statusCode = res.getStatus();
726 // Check the status code of the response: does it match
727 // the expected response(s)?
728 if (logger.isDebugEnabled()) {
729 logger.debug(testName + ": status = " + statusCode);
731 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
732 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
733 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
735 // Check whether organization has expected displayName.
736 input = new PoxPayloadIn(res.getEntity());
738 res.releaseConnection();
741 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
742 client.getItemCommonPartName(), OrganizationsCommon.class);
743 Assert.assertNotNull(organization);
744 String displayName = organization.getDisplayName();
745 // Make sure displayName matches computed form
746 String expectedDisplayName =
747 OrgAuthorityClientUtils.prepareDefaultDisplayName(
748 TEST_ORG_SHORTNAME, TEST_ORG_FOUNDING_PLACE);
749 Assert.assertNotNull(displayName, expectedDisplayName);
751 // Update the shortName and verify the computed name is updated.
752 organization.setCsid(null);
753 organization.setDisplayNameComputed(true);
755 MainBodyGroupList mainBodyList = organization.getMainBodyGroupList();
756 List<MainBodyGroup> mainBodyGroups = mainBodyList.getMainBodyGroup();
757 MainBodyGroup mainBodyGroup = new MainBodyGroup();
758 String updatedShortName = "updated-" + TEST_ORG_SHORTNAME;
759 mainBodyGroup.setShortName(updatedShortName);
760 mainBodyGroups.add(mainBodyGroup);
761 organization.setMainBodyGroupList(mainBodyList);
763 expectedDisplayName =
764 OrgAuthorityClientUtils.prepareDefaultDisplayName(
765 updatedShortName, TEST_ORG_FOUNDING_PLACE);
767 // Submit the updated resource to the service and store the response.
768 PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
769 PayloadOutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
770 commonPart.setLabel(client.getItemCommonPartName());
771 res = client.updateItem(knownResourceId, knownItemResourceId, output);
773 int statusCode = res.getStatus();
775 // Check the status code of the response: does it match the expected response(s)?
776 if (logger.isDebugEnabled()) {
777 logger.debug("updateItem: status = " + statusCode);
779 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
780 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
781 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
783 // Retrieve the updated resource and verify that its contents exist.
784 input = new PoxPayloadIn(res.getEntity());
786 res.releaseConnection();
789 OrganizationsCommon updatedOrganization =
790 (OrganizationsCommon) extractPart(input,
791 client.getItemCommonPartName(), OrganizationsCommon.class);
792 Assert.assertNotNull(updatedOrganization);
794 // Verify that the updated resource received the correct data.
795 mainBodyList = organization.getMainBodyGroupList();
796 Assert.assertNotNull(mainBodyList);
797 Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0);
798 Assert.assertEquals(updatedOrganization.getMainBodyGroupList().getMainBodyGroup().get(0).getShortName(),
799 updatedShortName, "Updated ShortName in Organization did not match submitted data.");
801 // Verify that the updated resource computes the right displayName.
802 Assert.assertEquals(updatedOrganization.getDisplayName(), expectedDisplayName,
803 "Updated ShortName in Organization not reflected in computed DisplayName.");
805 // Now Update the displayName, not computed and verify the computed name is overriden.
806 organization.setDisplayNameComputed(false);
807 expectedDisplayName = "TestName";
808 organization.setDisplayName(expectedDisplayName);
810 // Submit the updated resource to the service and store the response.
811 output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
812 commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
813 commonPart.setLabel(client.getItemCommonPartName());
814 res = client.updateItem(knownResourceId, knownItemResourceId, output);
816 int statusCode = res.getStatus();
818 // Check the status code of the response: does it match the expected response(s)?
819 if (logger.isDebugEnabled()) {
820 logger.debug("updateItem: status = " + statusCode);
822 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
823 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
824 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
826 // Retrieve the updated resource and verify that its contents exist.
827 input = new PoxPayloadIn(res.getEntity());
829 res.releaseConnection();
832 updatedOrganization =
833 (OrganizationsCommon) extractPart(input,
834 client.getItemCommonPartName(), OrganizationsCommon.class);
835 Assert.assertNotNull(updatedOrganization);
837 // Verify that the updated resource received the correct data.
838 Assert.assertEquals(updatedOrganization.isDisplayNameComputed(), false,
839 "Updated displayNameComputed in Organization did not match submitted data.");
840 // Verify that the updated resource computes the right displayName.
841 Assert.assertEquals(updatedOrganization.getDisplayName(),
843 "Updated DisplayName (not computed) in Organization not stored.");
847 * Verify illegal item display name.
849 * @param testName the test name
850 * @throws Exception the exception
852 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
853 dependsOnMethods = {"verifyItemDisplayName"})
854 public void verifyIllegalItemDisplayName(String testName) throws Exception {
856 if (logger.isDebugEnabled()) {
857 logger.debug(testBanner(testName, CLASS_NAME));
860 testSetup(STATUS_BAD_REQUEST, ServiceRequestType.UPDATE);
861 // setupUpdateWithWrongXmlSchema(testName, logger);
863 // Submit the request to the service and store the response.
864 OrgAuthorityClient client = new OrgAuthorityClient();
865 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
867 int statusCode = res.getStatus();
869 // Check the status code of the response: does it match
870 // the expected response(s)?
871 if (logger.isDebugEnabled()) {
872 logger.debug(testName + ": status = " + statusCode);
874 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
875 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
876 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
878 // Check whether organization has expected displayName.
879 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
880 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
881 client.getItemCommonPartName(), OrganizationsCommon.class);
882 Assert.assertNotNull(organization);
883 // Try to Update with computed false and no displayName
884 organization.setDisplayNameComputed(false);
885 organization.setDisplayName(null);
887 // Submit the updated resource to the service and store the response.
888 PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
889 PayloadOutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
890 commonPart.setLabel(client.getItemCommonPartName());
891 res.releaseConnection();
892 res = client.updateItem(knownResourceId, knownItemResourceId, output);
893 statusCode = res.getStatus();
895 // Check the status code of the response: does it match the expected response(s)?
896 if (logger.isDebugEnabled()) {
897 logger.debug("updateItem: status = " + statusCode);
899 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
900 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
901 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
903 res.releaseConnection();
910 * @param testName the test name
911 * @throws Exception the exception
913 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
914 groups = {"readItem"}, dependsOnMethods = {"readItem"})
915 public void readContact(String testName) throws Exception {
917 if (logger.isDebugEnabled()) {
918 logger.debug(testBanner(testName, CLASS_NAME));
923 // Submit the request to the service and store the response.
924 OrgAuthorityClient client = new OrgAuthorityClient();
925 ClientResponse<String> res =
926 client.readContact(knownResourceId, knownItemResourceId,
927 knownContactResourceId);
929 int statusCode = res.getStatus();
931 // Check the status code of the response: does it match
932 // the expected response(s)?
933 if (logger.isDebugEnabled()) {
934 logger.debug(testName + ": status = " + statusCode);
936 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
937 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
938 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
940 // Check whether we've received a contact.
941 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
942 ContactsCommon contact = (ContactsCommon) extractPart(input,
943 new ContactClient().getCommonPartName(), ContactsCommon.class);
944 Assert.assertNotNull(contact);
945 boolean showFull = true;
946 if (showFull && logger.isDebugEnabled()) {
947 logger.debug(testName + ": returned payload:");
948 logger.debug(objectAsXmlString(contact, ContactsCommon.class));
950 Assert.assertEquals(contact.getInAuthority(), knownResourceId);
951 Assert.assertEquals(contact.getInItem(), knownItemResourceId);
953 res.releaseConnection();
959 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
962 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
963 groups = {"read"}, dependsOnMethods = {"read"})
964 public void readNonExistent(String testName) {
966 if (logger.isDebugEnabled()) {
967 logger.debug(testBanner(testName, CLASS_NAME));
970 setupReadNonExistent();
972 // Submit the request to the service and store the response.
973 OrgAuthorityClient client = new OrgAuthorityClient();
974 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
976 int statusCode = res.getStatus();
978 // Check the status code of the response: does it match
979 // the expected response(s)?
980 if (logger.isDebugEnabled()) {
981 logger.debug(testName + ": status = " + statusCode);
983 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
984 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
985 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
987 res.releaseConnection();
992 * Read item non existent.
994 * @param testName the test name
996 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
997 groups = {"readItem"}, dependsOnMethods = {"readItem"})
998 public void readItemNonExistent(String testName) {
1000 if (logger.isDebugEnabled()) {
1001 logger.debug(testBanner(testName, CLASS_NAME));
1004 setupReadNonExistent();
1006 // Submit the request to the service and store the response.
1007 OrgAuthorityClient client = new OrgAuthorityClient();
1008 ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
1010 int statusCode = res.getStatus();
1012 // Check the status code of the response: does it match
1013 // the expected response(s)?
1014 if (logger.isDebugEnabled()) {
1015 logger.debug(testName + ": status = " + statusCode);
1017 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1018 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1019 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1021 res.releaseConnection();
1026 * Read contact non existent.
1028 * @param testName the test name
1030 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1031 groups = {"readItem"}, dependsOnMethods = {"readContact"})
1032 public void readContactNonExistent(String testName) {
1034 if (logger.isDebugEnabled()) {
1035 logger.debug(testBanner(testName, CLASS_NAME));
1038 setupReadNonExistent();
1040 // Submit the request to the service and store the response.
1041 OrgAuthorityClient client = new OrgAuthorityClient();
1042 ClientResponse<String> res =
1043 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1045 int statusCode = res.getStatus();
1047 // Check the status code of the response: does it match
1048 // the expected response(s)?
1049 if (logger.isDebugEnabled()) {
1050 logger.debug(testName + ": status = " + statusCode);
1052 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1053 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1054 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1056 res.releaseConnection();
1060 // ---------------------------------------------------------------
1061 // CRUD tests : READ_LIST tests
1062 // ---------------------------------------------------------------
1066 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
1069 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1070 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
1071 public void readList(String testName) throws Exception {
1073 if (logger.isDebugEnabled()) {
1074 logger.debug(testBanner(testName, CLASS_NAME));
1079 // Submit the request to the service and store the response.
1080 OrgAuthorityClient client = new OrgAuthorityClient();
1081 ClientResponse<AbstractCommonList> res = client.readList();
1083 AbstractCommonList list = res.getEntity();
1084 int statusCode = res.getStatus();
1086 // Check the status code of the response: does it match
1087 // the expected response(s)?
1088 if (logger.isDebugEnabled()) {
1089 logger.debug(testName + ": status = " + statusCode);
1091 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1092 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1093 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1095 // Optionally output additional data about list members for debugging.
1096 if (logger.isTraceEnabled()) {
1097 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
1100 res.releaseConnection();
1107 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
1108 public void readItemList() {
1109 readItemList(knownResourceId, null);
1113 * Read item list by authority name.
1115 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1116 public void readItemListByAuthorityName() {
1117 readItemList(null, knownResourceShortIdentifer);
1123 * @param vcsid the vcsid
1124 * @param name the name
1126 private void readItemList(String vcsid, String name) {
1128 final String testName = "readItemList";
1130 if (logger.isDebugEnabled()) {
1131 logger.debug(testBanner(testName, CLASS_NAME));
1136 // Submit the request to the service and store the response.
1137 OrgAuthorityClient client = new OrgAuthorityClient();
1138 ClientResponse<AbstractCommonList> res = null;
1139 if (vcsid != null) {
1140 res = client.readItemList(vcsid, null, null);
1141 } else if (name != null) {
1142 res = client.readItemListForNamedAuthority(name, null, null);
1144 Assert.fail("readItemList passed null csid and name!");
1147 AbstractCommonList list = res.getEntity();
1148 int statusCode = res.getStatus();
1150 // Check the status code of the response: does it match
1151 // the expected response(s)?
1152 if (logger.isDebugEnabled()) {
1153 logger.debug(testName + ": status = " + statusCode);
1155 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1156 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1157 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1159 List<AbstractCommonList.ListItem> items =
1161 int nItemsReturned = items.size();
1162 // There will be one item created, associated with a
1163 // known parent resource, by the createItem test.
1165 // In addition, there will be 'nItemsToCreateInList'
1166 // additional items created by the createItemList test,
1167 // all associated with the same parent resource.
1168 int nExpectedItems = nItemsToCreateInList + 1;
1169 if (logger.isDebugEnabled()) {
1170 logger.debug(testName + ": Expected "
1171 + nExpectedItems + " items; got: " + nItemsReturned);
1173 Assert.assertEquals(nItemsReturned, nExpectedItems);
1175 for (AbstractCommonList.ListItem item : items) {
1177 AbstractCommonListUtils.ListItemGetElementValue(item, REFNAME);
1178 Assert.assertTrue((null != value), "Item refName is null!");
1180 AbstractCommonListUtils.ListItemGetElementValue(item, DISPLAYNAME);
1181 Assert.assertTrue((null != value), "Item displayName is null!");
1183 if (logger.isTraceEnabled()) {
1184 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
1187 res.releaseConnection();
1192 * Read contact list.
1194 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1195 public void readContactList() {
1196 readContactList(knownResourceId, knownItemResourceId);
1200 * Read contact list.
1202 * @param parentcsid the parentcsid
1203 * @param itemcsid the itemcsid
1205 private void readContactList(String parentcsid, String itemcsid) {
1206 final String testName = "readContactList";
1208 if (logger.isDebugEnabled()) {
1209 logger.debug(testBanner(testName, CLASS_NAME));
1214 // Submit the request to the service and store the response.
1215 OrgAuthorityClient client = new OrgAuthorityClient();
1216 AbstractCommonList list = null;
1217 ClientResponse<AbstractCommonList> res =
1218 client.readContactList(parentcsid, itemcsid);
1220 list = res.getEntity();
1221 int statusCode = res.getStatus();
1223 // Check the status code of the response: does it match
1224 // the expected response(s)?
1225 if (logger.isDebugEnabled()) {
1226 logger.debug(testName + ": status = " + statusCode);
1228 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1229 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1230 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1232 List<AbstractCommonList.ListItem> listitems =
1234 int nItemsReturned = listitems.size();
1235 // There will be one item created, associated with a
1236 // known parent resource, by the createItem test.
1238 // In addition, there will be 'nItemsToCreateInList'
1239 // additional items created by the createItemList test,
1240 // all associated with the same parent resource.
1241 int nExpectedItems = nItemsToCreateInList + 1;
1242 if (logger.isDebugEnabled()) {
1243 logger.debug(testName + ": Expected "
1244 + nExpectedItems + " items; got: " + nItemsReturned);
1246 Assert.assertEquals(nItemsReturned, nExpectedItems);
1248 // Optionally output additional data about list members for debugging.
1249 boolean iterateThroughList = false;
1250 if (iterateThroughList && logger.isDebugEnabled()) {
1251 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
1254 res.releaseConnection();
1260 // ---------------------------------------------------------------
1261 // CRUD tests : UPDATE tests
1262 // ---------------------------------------------------------------
1265 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
1268 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1269 groups = {"update"}, dependsOnGroups = {"read", "readList"})
1270 public void update(String testName) throws Exception {
1272 if (logger.isDebugEnabled()) {
1273 logger.debug(testBanner(testName, CLASS_NAME));
1278 // Retrieve the contents of a resource to update.
1279 OrgAuthorityClient client = new OrgAuthorityClient();
1280 ClientResponse<String> res =
1281 client.read(knownResourceId);
1283 if (logger.isDebugEnabled()) {
1284 logger.debug(testName + ": read status = " + res.getStatus());
1286 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1288 if (logger.isDebugEnabled()) {
1289 logger.debug("got OrgAuthority to update with ID: " + knownResourceId);
1291 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
1292 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
1293 client.getCommonPartName(), OrgauthoritiesCommon.class);
1294 Assert.assertNotNull(orgAuthority);
1296 // Update the contents of this resource.
1297 orgAuthority.setDisplayName("updated-" + orgAuthority.getDisplayName());
1298 orgAuthority.setVocabType("updated-" + orgAuthority.getVocabType());
1299 if (logger.isDebugEnabled()) {
1300 logger.debug("to be updated OrgAuthority");
1301 logger.debug(objectAsXmlString(orgAuthority, OrgauthoritiesCommon.class));
1304 // Submit the updated resource to the service and store the response.
1305 PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_PAYLOAD_NAME);
1306 PayloadOutputPart commonPart = output.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE);
1307 commonPart.setLabel(client.getCommonPartName());
1308 res.releaseConnection();
1309 res = client.update(knownResourceId, output);
1310 int statusCode = res.getStatus();
1312 // Check the status code of the response: does it match the expected response(s)?
1313 if (logger.isDebugEnabled()) {
1314 logger.debug(testName + ": status = " + statusCode);
1316 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1317 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1318 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1320 // Retrieve the updated resource and verify that its contents exist.
1321 input = new PoxPayloadIn(res.getEntity());
1322 OrgauthoritiesCommon updatedOrgAuthority =
1323 (OrgauthoritiesCommon) extractPart(input,
1324 client.getCommonPartName(), OrgauthoritiesCommon.class);
1325 Assert.assertNotNull(updatedOrgAuthority);
1327 // Verify that the updated resource received the correct data.
1328 Assert.assertEquals(updatedOrgAuthority.getDisplayName(),
1329 orgAuthority.getDisplayName(),
1330 "Data in updated object did not match submitted data.");
1332 res.releaseConnection();
1339 * @param testName the test name
1340 * @throws Exception the exception
1342 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1343 groups = {"update"}, dependsOnMethods = {"update"})
1344 public void updateItem(String testName) throws Exception {
1346 if (logger.isDebugEnabled()) {
1347 logger.debug(testBanner(testName, CLASS_NAME));
1352 // Retrieve the contents of a resource to update.
1353 OrgAuthorityClient client = new OrgAuthorityClient();
1354 ClientResponse<String> res =
1355 client.readItem(knownResourceId, knownItemResourceId);
1357 if (logger.isDebugEnabled()) {
1358 logger.debug(testName + ": read status = " + res.getStatus());
1360 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1362 if (logger.isDebugEnabled()) {
1363 logger.debug("got Organization to update with ID: "
1364 + knownItemResourceId
1365 + " in OrgAuthority: " + knownResourceId);
1367 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
1368 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
1369 client.getItemCommonPartName(), OrganizationsCommon.class);
1370 Assert.assertNotNull(organization);
1372 // Update the contents of this resource.
1373 organization.setCsid(null);
1375 MainBodyGroupList mainBodyList = organization.getMainBodyGroupList();
1376 Assert.assertNotNull(mainBodyList);
1377 List<MainBodyGroup> mainBodyGroups = mainBodyList.getMainBodyGroup();
1378 Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0);
1379 String updatedShortName = "updated-" + mainBodyGroups.get(0).getShortName();
1380 mainBodyGroups.get(0).setShortName(updatedShortName);
1382 if (logger.isDebugEnabled()) {
1383 logger.debug("to be updated Organization");
1384 logger.debug(objectAsXmlString(organization,
1385 OrganizationsCommon.class));
1388 // Submit the updated resource to the service and store the response.
1389 PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1390 PayloadOutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
1391 commonPart.setLabel(client.getItemCommonPartName());
1392 res.releaseConnection();
1393 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1394 int statusCode = res.getStatus();
1396 // Check the status code of the response: does it match the expected response(s)?
1397 if (logger.isDebugEnabled()) {
1398 logger.debug(testName + ": status = " + statusCode);
1400 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1401 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1402 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1404 // Retrieve the updated resource and verify that its contents exist.
1405 input = new PoxPayloadIn(res.getEntity());
1406 OrganizationsCommon updatedOrganization =
1407 (OrganizationsCommon) extractPart(input,
1408 client.getItemCommonPartName(), OrganizationsCommon.class);
1409 Assert.assertNotNull(updatedOrganization);
1411 // Verify that the updated resource received the correct data.
1412 mainBodyList = organization.getMainBodyGroupList();
1413 Assert.assertNotNull(mainBodyList);
1414 Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0);
1415 Assert.assertEquals(updatedOrganization.getMainBodyGroupList().getMainBodyGroup().get(0).getShortName(),
1416 updatedShortName, "Data in updated Organization did not match submitted data.");
1418 res.releaseConnection();
1425 * @param testName the test name
1426 * @throws Exception the exception
1428 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1429 groups = {"update"}, dependsOnMethods = {"updateItem"})
1430 public void updateContact(String testName) throws Exception {
1432 if (logger.isDebugEnabled()) {
1433 logger.debug(testBanner(testName, CLASS_NAME));
1438 // Retrieve the contents of a resource to update.
1439 OrgAuthorityClient client = new OrgAuthorityClient();
1440 ClientResponse<String> res =
1441 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1443 if (logger.isDebugEnabled()) {
1444 logger.debug(testName + ": read status = " + res.getStatus());
1446 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1448 if (logger.isDebugEnabled()) {
1449 logger.debug("got Contact to update with ID: "
1450 + knownContactResourceId
1451 + " in item: " + knownItemResourceId
1452 + " in parent: " + knownResourceId);
1454 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
1455 ContactsCommon contact = (ContactsCommon) extractPart(input,
1456 new ContactClient().getCommonPartName(), ContactsCommon.class);
1457 Assert.assertNotNull(contact);
1459 // Verify the contents of this resource
1460 AddressGroupList addressGroupList = contact.getAddressGroupList();
1461 Assert.assertNotNull(addressGroupList);
1462 List<AddressGroup> addressGroups = addressGroupList.getAddressGroup();
1463 Assert.assertNotNull(addressGroups);
1464 Assert.assertTrue(addressGroups.size() > 0);
1465 String addressPlace1 = addressGroups.get(0).getAddressPlace1();
1466 Assert.assertNotNull(addressPlace1);
1468 // Update the contents of this resource.
1469 addressGroups.get(0).setAddressPlace1("updated-" + addressPlace1);
1470 contact.setAddressGroupList(addressGroupList);
1471 if (logger.isDebugEnabled()) {
1472 logger.debug("to be updated Contact");
1473 logger.debug(objectAsXmlString(contact,
1474 ContactsCommon.class));
1477 // Submit the updated resource to the service and store the response.
1478 PoxPayloadOut output = new PoxPayloadOut(ContactClient.SERVICE_PAYLOAD_NAME);
1479 PayloadOutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1480 commonPart.setLabel(new ContactClient().getCommonPartName());
1481 res.releaseConnection();
1482 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1483 int statusCode = res.getStatus();
1485 // Check the status code of the response: does it match the expected response(s)?
1486 if (logger.isDebugEnabled()) {
1487 logger.debug(testName + ": status = " + statusCode);
1489 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1490 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1491 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1493 // Retrieve the updated resource and verify that its contents exist.
1494 input = new PoxPayloadIn(res.getEntity());
1495 ContactsCommon updatedContact =
1496 (ContactsCommon) extractPart(input,
1497 new ContactClient().getCommonPartName(), ContactsCommon.class);
1498 Assert.assertNotNull(updatedContact);
1500 // Verify that the updated resource received the correct data.
1501 Assert.assertEquals(updatedContact.getAddressGroupList().getAddressGroup().get(0).getAddressPlace1(),
1502 contact.getAddressGroupList().getAddressGroup().get(0).getAddressPlace1(),
1503 "Data in updated object did not match submitted data.");
1506 res.releaseConnection();
1511 // Placeholders until the three tests below can be uncommented.
1512 // See Issue CSPACE-401.
1514 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1517 public void updateWithEmptyEntityBody(String testName) throws Exception {
1518 //Should this really be empty?
1522 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1525 public void updateWithMalformedXml(String testName) throws Exception {
1526 //Should this really be empty?
1530 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1533 public void updateWithWrongXmlSchema(String testName) throws Exception {
1534 //Should this really be empty?
1539 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1540 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1541 public void updateWithEmptyEntityBody(String testName) throws Exception {
1543 if (logger.isDebugEnabled()) {
1544 logger.debug(testBanner(testName, CLASS_NAME));
1547 setupUpdateWithEmptyEntityBody();
1549 // Submit the request to the service and store the response.
1550 String method = REQUEST_TYPE.httpMethodName();
1551 String url = getResourceURL(knownResourceId);
1552 String mediaType = MediaType.APPLICATION_XML;
1553 final String entity = "";
1554 int statusCode = submitRequest(method, url, mediaType, entity);
1556 // Check the status code of the response: does it match
1557 // the expected response(s)?
1558 if(logger.isDebugEnabled()){
1559 logger.debug(testName + ": url=" + url +
1560 " status=" + statusCode);
1562 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1563 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1564 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1568 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1569 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1570 public void updateWithMalformedXml(String testName) throws Exception {
1572 if (logger.isDebugEnabled()) {
1573 logger.debug(testBanner(testName, CLASS_NAME));
1576 setupUpdateWithMalformedXml();
1578 // Submit the request to the service and store the response.
1579 String method = REQUEST_TYPE.httpMethodName();
1580 String url = getResourceURL(knownResourceId);
1581 String mediaType = MediaType.APPLICATION_XML;
1582 final String entity = MALFORMED_XML_DATA;
1583 int statusCode = submitRequest(method, url, mediaType, entity);
1585 // Check the status code of the response: does it match
1586 // the expected response(s)?
1587 if(logger.isDebugEnabled()){
1588 logger.debug(testName + ": url=" + url +
1589 " status=" + statusCode);
1591 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1592 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1593 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1597 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1598 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1599 public void updateWithWrongXmlSchema(String testName) throws Exception {
1602 setupUpdateWithWrongXmlSchema(testName, logger);
1604 // Submit the request to the service and store the response.
1605 String method = REQUEST_TYPE.httpMethodName();
1606 String url = getResourceURL(knownResourceId);
1607 String mediaType = MediaType.APPLICATION_XML;
1608 final String entity = WRONG_XML_SCHEMA_DATA;
1609 int statusCode = submitRequest(method, url, mediaType, entity);
1611 // Check the status code of the response: does it match
1612 // the expected response(s)?
1613 if(logger.isDebugEnabled()){
1614 logger.debug("updateWithWrongXmlSchema: url=" + url +
1615 " status=" + statusCode);
1617 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1618 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1619 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1624 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1627 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1628 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1629 public void updateNonExistent(String testName) throws Exception {
1631 if (logger.isDebugEnabled()) {
1632 logger.debug(testBanner(testName, CLASS_NAME));
1635 setupUpdateNonExistent();
1637 // Submit the request to the service and store the response.
1638 // Note: The ID used in this 'create' call may be arbitrary.
1639 // The only relevant ID may be the one used in update(), below.
1640 OrgAuthorityClient client = new OrgAuthorityClient();
1641 PoxPayloadOut multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance(
1642 NON_EXISTENT_ID, NON_EXISTENT_ID,
1643 new OrgAuthorityClient().getCommonPartName());
1644 ClientResponse<String> res =
1645 client.update(NON_EXISTENT_ID, multipart);
1647 int statusCode = res.getStatus();
1649 // Check the status code of the response: does it match
1650 // the expected response(s)?
1651 if (logger.isDebugEnabled()) {
1652 logger.debug(testName + ": status = " + statusCode);
1654 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1655 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1656 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1658 res.releaseConnection();
1663 * Update non existent item.
1665 * @param testName the test name
1666 * @throws Exception the exception
1668 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1669 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1670 public void updateNonExistentItem(String testName) throws Exception {
1672 if (logger.isDebugEnabled()) {
1673 logger.debug(testBanner(testName, CLASS_NAME));
1676 setupUpdateNonExistent();
1678 // Submit the request to the service and store the response.
1679 // Note: The ID(s) used when creating the request payload may be arbitrary.
1680 // The only relevant ID may be the one used in update(), below.
1681 OrgAuthorityClient client = new OrgAuthorityClient();
1682 Map<String, String> nonexOrgMap = new HashMap<String, String>();
1683 nonexOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, "nonExistent");
1684 nonexOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Non-existent");
1685 PoxPayloadOut multipart =
1686 OrgAuthorityClientUtils.createOrganizationInstance(
1687 knownResourceRefName,
1688 nonexOrgMap, client.getItemCommonPartName());
1689 ClientResponse<String> res =
1690 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1692 int statusCode = res.getStatus();
1694 // Check the status code of the response: does it match
1695 // the expected response(s)?
1696 if (logger.isDebugEnabled()) {
1697 logger.debug(testName + ": status = " + statusCode);
1699 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1700 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1701 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1703 res.releaseConnection();
1708 * Update non existent contact.
1710 * @param testName the test name
1711 * @throws Exception the exception
1713 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1714 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1715 public void updateNonExistentContact(String testName) throws Exception {
1716 // Currently a no-op test
1719 // ---------------------------------------------------------------
1720 // CRUD tests : DELETE tests
1721 // ---------------------------------------------------------------
1723 // Note: delete sub-resources in ascending hierarchical order,
1724 // before deleting their parents.
1728 * @param testName the test name
1729 * @throws Exception the exception
1731 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1732 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1733 public void deleteContact(String testName) throws Exception {
1735 if (logger.isDebugEnabled()) {
1736 logger.debug(testBanner(testName, CLASS_NAME));
1741 if (logger.isDebugEnabled()) {
1742 logger.debug("parentcsid =" + knownResourceId
1743 + " itemcsid = " + knownItemResourceId
1744 + " csid = " + knownContactResourceId);
1747 // Submit the request to the service and store the response.
1748 OrgAuthorityClient client = new OrgAuthorityClient();
1749 ClientResponse<Response> res =
1750 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1752 int statusCode = res.getStatus();
1754 // Check the status code of the response: does it match
1755 // the expected response(s)?
1756 if (logger.isDebugEnabled()) {
1757 logger.debug(testName + ": status = " + statusCode);
1759 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1760 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1761 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1763 res.releaseConnection();
1770 * @param testName the test name
1771 * @throws Exception the exception
1773 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1774 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1775 public void deleteItem(String testName) throws Exception {
1777 if (logger.isDebugEnabled()) {
1778 logger.debug(testBanner(testName, CLASS_NAME));
1783 if (logger.isDebugEnabled()) {
1784 logger.debug("parentcsid =" + knownResourceId
1785 + " itemcsid = " + knownItemResourceId);
1788 // Submit the request to the service and store the response.
1789 OrgAuthorityClient client = new OrgAuthorityClient();
1790 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1792 int statusCode = res.getStatus();
1794 // Check the status code of the response: does it match
1795 // the expected response(s)?
1796 if (logger.isDebugEnabled()) {
1797 logger.debug(testName + ": status = " + statusCode);
1799 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1800 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1801 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1803 res.releaseConnection();
1808 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1811 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1812 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1813 public void delete(String testName) throws Exception {
1815 if (logger.isDebugEnabled()) {
1816 logger.debug(testBanner(testName, CLASS_NAME));
1821 if (logger.isDebugEnabled()) {
1822 logger.debug("parentcsid =" + knownResourceId);
1825 // Submit the request to the service and store the response.
1826 OrgAuthorityClient client = new OrgAuthorityClient();
1827 ClientResponse<Response> res = client.delete(knownResourceId);
1829 int statusCode = res.getStatus();
1831 // Check the status code of the response: does it match
1832 // the expected response(s)?
1833 if (logger.isDebugEnabled()) {
1834 logger.debug(testName + ": status = " + statusCode);
1836 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1837 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1838 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1840 res.releaseConnection();
1846 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1849 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1850 groups = {"delete"}, dependsOnMethods = {"delete"})
1851 public void deleteNonExistent(String testName) throws Exception {
1853 if (logger.isDebugEnabled()) {
1854 logger.debug(testBanner(testName, CLASS_NAME));
1857 setupDeleteNonExistent();
1859 // Submit the request to the service and store the response.
1860 OrgAuthorityClient client = new OrgAuthorityClient();
1861 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1863 int statusCode = res.getStatus();
1865 // Check the status code of the response: does it match
1866 // the expected response(s)?
1867 if (logger.isDebugEnabled()) {
1868 logger.debug(testName + ": status = " + statusCode);
1870 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1871 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1872 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1874 res.releaseConnection();
1879 * Delete non existent item.
1881 * @param testName the test name
1883 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1884 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1885 public void deleteNonExistentItem(String testName) {
1887 if (logger.isDebugEnabled()) {
1888 logger.debug(testBanner(testName, CLASS_NAME));
1891 setupDeleteNonExistent();
1893 // Submit the request to the service and store the response.
1894 OrgAuthorityClient client = new OrgAuthorityClient();
1895 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1897 int statusCode = res.getStatus();
1899 // Check the status code of the response: does it match
1900 // the expected response(s)?
1901 if (logger.isDebugEnabled()) {
1902 logger.debug(testName + ": status = " + statusCode);
1904 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1905 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1906 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1908 res.releaseConnection();
1913 * Delete non existent contact.
1915 * @param testName the test name
1917 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1918 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1919 public void deleteNonExistentContact(String testName) {
1921 if (logger.isDebugEnabled()) {
1922 logger.debug(testBanner(testName, CLASS_NAME));
1925 setupDeleteNonExistent();
1927 // Submit the request to the service and store the response.
1928 OrgAuthorityClient client = new OrgAuthorityClient();
1929 ClientResponse<Response> res =
1930 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1932 int statusCode = res.getStatus();
1934 // Check the status code of the response: does it match
1935 // the expected response(s)?
1936 if (logger.isDebugEnabled()) {
1937 logger.debug(testName + ": status = " + statusCode);
1939 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1940 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1941 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1943 res.releaseConnection();
1947 // ---------------------------------------------------------------
1948 // Utility tests : tests of code used in tests above
1949 // ---------------------------------------------------------------
1951 * Tests the code for manually submitting data that is used by several
1952 * of the methods above.
1954 @Test(dependsOnMethods = {"create", "read"})
1955 public void testSubmitRequest() {
1957 // Expected status code: 200 OK
1958 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1960 // Submit the request to the service and store the response.
1961 String method = ServiceRequestType.READ.httpMethodName();
1962 String url = getResourceURL(knownResourceId);
1963 int statusCode = submitRequest(method, url);
1965 // Check the status code of the response: does it match
1966 // the expected response(s)?
1967 if (logger.isDebugEnabled()) {
1968 logger.debug("testSubmitRequest: url=" + url
1969 + " status=" + statusCode);
1971 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1976 * Test item submit request.
1978 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1979 public void testItemSubmitRequest() {
1981 // Expected status code: 200 OK
1982 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1984 // Submit the request to the service and store the response.
1985 String method = ServiceRequestType.READ.httpMethodName();
1986 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1987 int statusCode = submitRequest(method, url);
1989 // Check the status code of the response: does it match
1990 // the expected response(s)?
1991 if (logger.isDebugEnabled()) {
1992 logger.debug("testItemSubmitRequest: url=" + url
1993 + " status=" + statusCode);
1995 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2000 * Test contact submit request.
2002 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
2003 public void testContactSubmitRequest() {
2005 // Expected status code: 200 OK
2006 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2008 // Submit the request to the service and store the response.
2009 String method = ServiceRequestType.READ.httpMethodName();
2010 String url = getContactResourceURL(knownResourceId,
2011 knownItemResourceId, knownContactResourceId);
2012 int statusCode = submitRequest(method, url);
2014 // Check the status code of the response: does it match
2015 // the expected response(s)?
2016 if (logger.isDebugEnabled()) {
2017 logger.debug("testItemSubmitRequest: url=" + url
2018 + " status=" + statusCode);
2020 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2024 // ---------------------------------------------------------------
2025 // Cleanup of resources created during testing
2026 // ---------------------------------------------------------------
2028 * Deletes all resources created by tests, after all tests have been run.
2030 * This cleanup method will always be run, even if one or more tests fail.
2031 * For this reason, it attempts to remove all resources created
2032 * at any point during testing, even if some of those resources
2033 * may be expected to be deleted by certain tests.
2035 @AfterClass(alwaysRun = true)
2037 public void cleanUp() {
2038 String noTest = System.getProperty("noTestCleanup");
2039 if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
2040 if (logger.isDebugEnabled()) {
2041 logger.debug("Skipping Cleanup phase ...");
2045 if (logger.isDebugEnabled()) {
2046 logger.debug("Cleaning up temporary resources created for testing ...");
2049 String parentResourceId;
2050 String itemResourceId;
2051 String contactResourceId;
2052 // Clean up contact resources.
2053 parentResourceId = knownResourceId;
2054 OrgAuthorityClient client = new OrgAuthorityClient();
2055 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
2056 contactResourceId = entry.getKey();
2057 itemResourceId = entry.getValue();
2058 // Note: Any non-success responses from the delete operation
2059 // below are ignored and not reported.
2060 ClientResponse<Response> res =
2061 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
2062 res.releaseConnection();
2064 // Clean up item resources.
2065 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
2066 itemResourceId = entry.getKey();
2067 parentResourceId = 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.deleteItem(parentResourceId, itemResourceId);
2072 res.releaseConnection();
2074 // Clean up parent resources.
2079 // ---------------------------------------------------------------
2080 // Utility methods used by tests above
2081 // ---------------------------------------------------------------
2083 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
2086 * Gets the item service path component.
2088 * @return the item service path component
2090 public String getItemServicePathComponent() {
2091 return AuthorityClient.ITEMS;
2095 * Gets the contact service path component.
2097 * @return the contact service path component
2099 public String getContactServicePathComponent() {
2100 return ContactClient.SERVICE_PATH_COMPONENT;
2104 * Returns the root URL for the item service.
2106 * This URL consists of a base URL for all services, followed by
2107 * a path component for the owning parent, followed by the
2108 * path component for the items.
2110 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2111 * parent authority resource of the relevant item resource.
2113 * @return The root URL for the item service.
2115 protected String getItemServiceRootURL(String parentResourceIdentifier) {
2116 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
2120 * Returns the URL of a specific item resource managed by a service, and
2121 * designated by an identifier (such as a universally unique ID, or UUID).
2123 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2124 * parent authority resource of the relevant item resource.
2126 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2129 * @return The URL of a specific item resource managed by a service.
2131 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
2132 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
2136 * Returns the root URL for the contact service.
2138 * This URL consists of a base URL for all services, followed by
2139 * a path component for the owning authority, followed by the
2140 * path component for the owning item, followed by the path component
2141 * for the contact service.
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 root URL for the contact service.
2151 protected String getContactServiceRootURL(String parentResourceIdentifier,
2152 String itemResourceIdentifier) {
2153 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/"
2154 + getContactServicePathComponent();
2158 * Returns the URL of a specific contact resource managed by a service, and
2159 * designated by an identifier (such as a universally unique ID, or UUID).
2161 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2162 * parent resource of the relevant item resource.
2164 * @param resourceIdentifier An identifier (such as a UUID) for an
2167 * @return The URL of a specific resource managed by a service.
2169 protected String getContactResourceURL(String parentResourceIdentifier,
2170 String itemResourceIdentifier, String contactResourceIdentifier) {
2171 return getContactServiceRootURL(parentResourceIdentifier,
2172 itemResourceIdentifier) + "/" + contactResourceIdentifier;