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.PersonJAXBSchema;
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.PersonAuthorityClient;
39 import org.collectionspace.services.client.PersonAuthorityClientUtils;
40 import org.collectionspace.services.client.PoxPayloadIn;
41 import org.collectionspace.services.client.PoxPayloadOut;
42 import org.collectionspace.services.contact.ContactsCommon;
43 import org.collectionspace.services.contact.ContactsCommonList;
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.OrgauthoritiesCommonList;
51 import org.collectionspace.services.organization.OrganizationsCommon;
52 import org.collectionspace.services.organization.OrganizationsCommonList;
54 import org.jboss.resteasy.client.ClientResponse;
56 import org.slf4j.Logger;
57 import org.slf4j.LoggerFactory;
58 import org.testng.Assert;
59 import org.testng.annotations.AfterClass;
60 import org.testng.annotations.Test;
63 * OrgAuthorityServiceTest, carries out tests against a
64 * deployed and running OrgAuthority Service.
66 * $LastChangedRevision$
69 public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: Test classes for Vocab, Person, Org, and Location should have a base class!
72 private final String CLASS_NAME = OrgAuthorityServiceTest.class.getName();
73 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
76 public String getServicePathComponent() {
77 return OrgAuthorityClient.SERVICE_PATH_COMPONENT;
81 protected String getServiceName() {
82 return OrgAuthorityClient.SERVICE_NAME;
85 /** The test organization shortname. */
86 private final String TEST_ORG_SHORTNAME = "Test Org";
88 /** The test organization founding place. */
89 private final String TEST_ORG_FOUNDING_PLACE = "Anytown, USA";
91 // Hold some values for a recently created item to verify upon read.
92 private String knownResourceId = null;
93 private String knownResourceShortIdentifer = null;
94 private String knownResourceRefName = null;
95 private String knownItemResourceId = null;
96 private String knownItemResourceShortIdentifer = null;
98 /** The known contact resource id. */
99 private String knownContactResourceId = null;
101 /** The n items to create in list. */
102 private int nItemsToCreateInList = 3;
104 /** The all item resource ids created. */
105 private Map<String, String> allItemResourceIdsCreated =
106 new HashMap<String, String>();
108 /** The all contact resource ids created. */
109 private Map<String, String> allContactResourceIdsCreated =
110 new HashMap<String, String>();
112 protected void setKnownResource( String id, String shortIdentifer,
114 knownResourceId = id;
115 knownResourceShortIdentifer = shortIdentifer;
116 knownResourceRefName = refName;
119 protected void setKnownItemResource( String id, String shortIdentifer ) {
120 knownItemResourceId = id;
121 knownItemResourceShortIdentifer = shortIdentifer;
125 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
128 protected CollectionSpaceClient getClientInstance() {
129 return new OrgAuthorityClient();
133 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
136 protected AbstractCommonList getAbstractCommonList(
137 ClientResponse<AbstractCommonList> response) {
138 return response.getEntity(OrganizationsCommonList.class);
141 // ---------------------------------------------------------------
142 // CRUD tests : CREATE tests
143 // ---------------------------------------------------------------
146 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
149 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
151 public void create(String testName) throws Exception {
153 if (logger.isDebugEnabled()) {
154 logger.debug(testBanner(testName, CLASS_NAME));
156 // Perform setup, such as initializing the type of service request
157 // (e.g. CREATE, DELETE), its valid and expected status codes, and
158 // its associated HTTP method name (e.g. POST, DELETE).
161 // Submit the request to the service and store the response.
162 OrgAuthorityClient client = new OrgAuthorityClient();
163 String shortId = createIdentifier();
164 String displayName = "displayName-" + shortId;
165 String baseRefName = OrgAuthorityClientUtils.createOrgAuthRefName(shortId, null);
166 PoxPayloadOut multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance(
167 displayName, shortId, client.getCommonPartName());
170 ClientResponse<Response> res = client.create(multipart);
172 int statusCode = res.getStatus();
174 // Check the status code of the response: does it match
175 // the expected response(s)?
178 // Does it fall within the set of valid status codes?
179 // Does it exactly match the expected status code?
180 if(logger.isDebugEnabled()){
181 logger.debug(testName + ": status = " + statusCode);
183 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
184 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
185 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
187 newID = OrgAuthorityClientUtils.extractId(res);
189 res.releaseConnection();
192 // Store the ID returned from the first resource created
193 // for additional tests below.
194 if (knownResourceId == null){
195 setKnownResource( newID, shortId, baseRefName );
196 if (logger.isDebugEnabled()) {
197 logger.debug(testName + ": knownResourceId=" + knownResourceId);
200 // Store the IDs from every resource created by tests,
201 // so they can be deleted after tests have been run.
202 allResourceIdsCreated.add(newID);
206 protected PoxPayloadOut createInstance(String identifier) {
207 OrgAuthorityClient client = new OrgAuthorityClient();
208 String displayName = "displayName-" + identifier;
209 PoxPayloadOut multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance(
210 displayName, identifier, client.getCommonPartName());
215 protected PoxPayloadOut createItemInstance(String parentCsid, String identifier) {
216 String headerLabel = new OrgAuthorityClient().getItemCommonPartName();
217 String shortId = "testOrg";
218 Map<String, String> testOrgMap = new HashMap<String,String>();
219 testOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId);
220 testOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, TEST_ORG_SHORTNAME);
221 testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "The real official test organization");
222 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "May 26, 1907");
223 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, TEST_ORG_FOUNDING_PLACE);
225 return OrgAuthorityClientUtils.createOrganizationInstance(identifier, testOrgMap, headerLabel);
231 * @param testName the test name
233 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
234 groups = {"create"}, dependsOnMethods = {"create"})
235 public void createItem(String testName) {
237 String newID = createItemInAuthority(knownResourceId, knownResourceRefName);
241 * Creates the item in authority.
243 * @param vcsid the vcsid
244 * @param authRefName the auth ref name
247 private String createItemInAuthority(String vcsid, String authRefName) {
249 final String testName = "createItemInAuthority";
250 if(logger.isDebugEnabled()){
251 logger.debug(testName + ":...");
254 // Submit the request to the service and store the response.
255 OrgAuthorityClient client = new OrgAuthorityClient();
256 String shortId = "testOrg";
257 Map<String, String> testOrgMap = new HashMap<String,String>();
258 testOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId);
259 testOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, TEST_ORG_SHORTNAME);
260 testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "The real official test organization");
261 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "May 26, 1907");
262 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, TEST_ORG_FOUNDING_PLACE);
264 Map<String, List<String>> testOrgRepeatablesMap = new HashMap<String,List<String>>();
265 List<String> testOrgContactNames = new ArrayList<String>();
266 testOrgContactNames.add("joe@example.org");
267 testOrgContactNames.add("sally@example.org");
268 testOrgRepeatablesMap.put(OrganizationJAXBSchema.CONTACT_NAMES, testOrgContactNames);
270 MainBodyGroupList mainBodyList = new MainBodyGroupList();
271 List<MainBodyGroup> mainBodyGroups = mainBodyList.getMainBodyGroup();
272 MainBodyGroup mainBodyGroup = new MainBodyGroup();
273 mainBodyGroup.setShortName(TEST_ORG_SHORTNAME);
274 mainBodyGroup.setLongName("The real official test organization");
275 mainBodyGroups.add(mainBodyGroup);
277 String newID = OrgAuthorityClientUtils.createItemInAuthority(
278 vcsid, authRefName, testOrgMap, testOrgRepeatablesMap, mainBodyList, client);
280 // Store the ID returned from the first item resource created
281 // for additional tests below.
282 if (knownItemResourceId == null){
283 setKnownItemResource(newID, shortId);
284 if (logger.isDebugEnabled()) {
285 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
289 // Store the IDs from any item resources created
290 // by tests, along with the IDs of their parents, so these items
291 // can be deleted after all tests have been run.
292 allItemResourceIdsCreated.put(newID, vcsid);
298 * Creates the contact.
300 * @param testName the test name
302 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
303 groups = {"create"}, dependsOnMethods = {"createItem"})
304 public void createContact(String testName) {
306 String newID = createContactInItem(knownResourceId, knownItemResourceId);
310 * Creates the contact in item.
312 * @param parentcsid the parentcsid
313 * @param itemcsid the itemcsid
316 private String createContactInItem(String parentcsid, String itemcsid) {
318 final String testName = "createContactInItem";
319 if (logger.isDebugEnabled()) {
320 logger.debug(testBanner(testName, CLASS_NAME));
324 // Submit the request to the service and store the response.
325 OrgAuthorityClient client = new OrgAuthorityClient();
326 String identifier = createIdentifier();
327 PoxPayloadOut multipart =
328 ContactClientUtils.createContactInstance(parentcsid,
329 itemcsid, identifier, new ContactClient().getCommonPartName());
332 ClientResponse<Response> res =
333 client.createContact(parentcsid, itemcsid, multipart);
335 int statusCode = res.getStatus();
336 // Check the status code of the response: does it match
337 // the expected response(s)?
338 if(logger.isDebugEnabled()){
339 logger.debug(testName + ": status = " + statusCode);
341 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
342 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
343 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
345 newID = OrgAuthorityClientUtils.extractId(res);
347 res.releaseConnection();
350 // Store the ID returned from the first contact resource created
351 // for additional tests below.
352 if (knownContactResourceId == null){
353 knownContactResourceId = newID;
354 if (logger.isDebugEnabled()) {
355 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
359 // Store the IDs from any contact resources created
360 // by tests, along with the IDs of their parent items,
361 // so these items can be deleted after all tests have been run.
362 allContactResourceIdsCreated.put(newID, itemcsid);
369 // Placeholders until the three tests below can be uncommented.
370 // See Issue CSPACE-401.
372 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
375 public void createWithEmptyEntityBody(String testName) throws Exception {
376 //Should this really be empty?
380 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
383 public void createWithMalformedXml(String testName) throws Exception {
384 //Should this really be empty?
388 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
391 public void createWithWrongXmlSchema(String testName) throws Exception {
392 //Should this really be empty?
397 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
398 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
399 public void createWithEmptyEntityBody(String testName) throws Exception {
401 if (logger.isDebugEnabled()) {
402 logger.debug(testBanner(testName, CLASS_NAME));
405 setupCreateWithEmptyEntityBody();
407 // Submit the request to the service and store the response.
408 String method = REQUEST_TYPE.httpMethodName();
409 String url = getServiceRootURL();
410 String mediaType = MediaType.APPLICATION_XML;
411 final String entity = "";
412 int statusCode = submitRequest(method, url, mediaType, entity);
414 // Check the status code of the response: does it match
415 // the expected response(s)?
416 if(logger.isDebugEnabled()) {
417 logger.debug(testName + ": url=" + url +
418 " status=" + statusCode);
420 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
421 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
422 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
426 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
427 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
428 public void createWithMalformedXml(String testName) throws Exception {
430 if (logger.isDebugEnabled()) {
431 logger.debug(testBanner(testName, CLASS_NAME));
434 setupCreateWithMalformedXml();
436 // Submit the request to the service and store the response.
437 String method = REQUEST_TYPE.httpMethodName();
438 String url = getServiceRootURL();
439 String mediaType = MediaType.APPLICATION_XML;
440 final String entity = MALFORMED_XML_DATA; // Constant from base class.
441 int statusCode = submitRequest(method, url, mediaType, entity);
443 // Check the status code of the response: does it match
444 // the expected response(s)?
445 if(logger.isDebugEnabled()){
446 logger.debug(testName + ": url=" + url +
447 " status=" + statusCode);
449 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
450 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
451 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
455 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
456 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
457 public void createWithWrongXmlSchema(String testName) throws Exception {
459 if (logger.isDebugEnabled()) {
460 logger.debug(testBanner(testName, CLASS_NAME));
463 setupCreateWithWrongXmlSchema();
465 // Submit the request to the service and store the response.
466 String method = REQUEST_TYPE.httpMethodName();
467 String url = getServiceRootURL();
468 String mediaType = MediaType.APPLICATION_XML;
469 final String entity = WRONG_XML_SCHEMA_DATA;
470 int statusCode = submitRequest(method, url, mediaType, entity);
472 // Check the status code of the response: does it match
473 // the expected response(s)?
474 if(logger.isDebugEnabled()){
475 logger.debug(testName + ": url=" + url +
476 " status=" + statusCode);
478 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
479 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
480 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
484 // ---------------------------------------------------------------
485 // CRUD tests : CREATE LIST tests
486 // ---------------------------------------------------------------
489 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
492 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
493 groups = {"createList"}, dependsOnGroups = {"create"})
494 public void createList(String testName) throws Exception {
495 for (int i = 0; i < nItemsToCreateInList; i++) {
501 * Creates the item list.
503 * @param testName the test name
504 * @throws Exception the exception
506 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
507 groups = {"createList"}, dependsOnMethods = {"createList"})
508 public void createItemList(String testName) throws Exception {
509 // Add items to the initially-created, known parent record.
510 for (int j = 0; j < nItemsToCreateInList; j++) {
511 createItem(testName);
516 * Creates the contact list.
518 * @param testName the test name
519 * @throws Exception the exception
521 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
522 groups = {"createList"}, dependsOnMethods = {"createItemList"})
523 public void createContactList(String testName) throws Exception {
524 // Add contacts to the initially-created, known item record.
525 for (int j = 0; j < nItemsToCreateInList; j++) {
526 createContact(testName);
530 // ---------------------------------------------------------------
531 // CRUD tests : READ tests
532 // ---------------------------------------------------------------
535 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
538 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
539 groups = {"read"}, dependsOnGroups = {"create"})
540 public void read(String testName) throws Exception {
541 readInternal(testName, knownResourceId, null);
547 * @param testName the test name
548 * @throws Exception the exception
550 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
551 groups = {"read"}, dependsOnGroups = {"create"})
552 public void readByName(String testName) throws Exception {
553 readInternal(testName, null, knownResourceShortIdentifer);
556 protected void readInternal(String testName, String CSID, String shortId) {
558 if (logger.isDebugEnabled()) {
559 logger.debug(testBanner(testName, CLASS_NAME));
564 // Submit the request to the service and store the response.
565 OrgAuthorityClient client = new OrgAuthorityClient();
566 ClientResponse<String> res = null;
568 res = client.read(CSID);
569 } else if(shortId!=null) {
570 res = client.readByName(shortId);
572 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
575 int statusCode = res.getStatus();
577 // Check the status code of the response: does it match
578 // the expected response(s)?
579 if(logger.isDebugEnabled()){
580 logger.debug(testName + ": status = " + statusCode);
582 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
583 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
584 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
585 //FIXME: remove the following try catch once Aron fixes signatures
587 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
588 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
589 new OrgAuthorityClient().getCommonPartName(), OrgauthoritiesCommon.class);
590 Assert.assertNotNull(orgAuthority);
591 } catch (Exception e) {
592 throw new RuntimeException(e);
595 res.releaseConnection();
602 * @param testName the test name
603 * @throws Exception the exception
605 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
606 groups = {"readItem"}, dependsOnGroups = {"read"})
607 public void readItem(String testName) throws Exception {
608 readItemInternal(testName, knownResourceId, null, knownItemResourceId, null);
612 * Read item in Named Auth.
614 * TODO Enable this if we really need this - it is a funky case, where we would have
615 * the shortId of the item, but the CSID of the parent authority!? Unlikely.
617 * @param testName the test name
618 * @throws Exception the exception
619 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
620 groups = {"readItem"}, dependsOnGroups = {"read"})
621 public void readItemInNamedAuth(String testName) throws Exception {
622 readItemInternal(testName, null, knownResourceShortIdentifer, knownItemResourceId, null);
629 * @param testName the test name
630 * @throws Exception the exception
632 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
633 groups = {"readItem"}, dependsOnGroups = {"read"})
634 public void readNamedItem(String testName) throws Exception {
635 readItemInternal(testName, knownResourceId, null, null, knownItemResourceShortIdentifer);
639 * Read Named item in Named Auth.
641 * @param testName the test name
642 * @throws Exception the exception
644 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
645 groups = {"readItem"}, dependsOnGroups = {"read"})
646 public void readNamedItemInNamedAuth(String testName) throws Exception {
647 readItemInternal(testName, null, knownResourceShortIdentifer, null, knownItemResourceShortIdentifer);
650 protected void readItemInternal(String testName,
651 String authCSID, String authShortId, String itemCSID, String itemShortId)
654 if (logger.isDebugEnabled()) {
655 logger.debug(testBanner(testName, CLASS_NAME));
660 // Submit the request to the service and store the response.
661 OrgAuthorityClient client = new OrgAuthorityClient();
662 ClientResponse<String> res = null;
665 res = client.readItem(authCSID, itemCSID);
666 } else if(itemShortId!=null) {
667 res = client.readNamedItem(authCSID, itemShortId);
669 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
671 } else if(authShortId!=null) {
673 res = client.readItemInNamedAuthority(authShortId, itemCSID);
674 } else if(itemShortId!=null) {
675 res = client.readNamedItemInNamedAuthority(authShortId, itemShortId);
677 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
680 Assert.fail("readInternal: Internal error. One of authCSID or authShortId must be non-null");
683 int statusCode = res.getStatus();
685 // Check the status code of the response: does it match
686 // the expected response(s)?
687 if(logger.isDebugEnabled()){
688 logger.debug(testName + ": status = " + statusCode);
690 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
691 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
692 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
694 // Check whether we've received a organization.
695 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
696 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
697 client.getItemCommonPartName(), OrganizationsCommon.class);
698 Assert.assertNotNull(organization);
699 boolean showFull = true;
700 if(showFull && logger.isDebugEnabled()){
701 logger.debug(testName + ": returned payload:");
702 logger.debug(objectAsXmlString(organization, OrganizationsCommon.class));
705 // Check that the organization item is within the expected OrgAuthority.
706 Assert.assertEquals(organization.getInAuthority(), knownResourceId);
708 // Verify the number and contents of values in a repeatable field,
709 // as created in the instance record used for testing.
710 List<String> contactNames = organization.getContactNames().getContactName();
711 Assert.assertTrue(contactNames.size() > 0);
712 Assert.assertNotNull(contactNames.get(0));
715 res.releaseConnection();
720 * Verify item display name.
722 * @param testName the test name
723 * @throws Exception the exception
725 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
726 dependsOnMethods = {"readItem", "updateItem"})
727 public void verifyItemDisplayName(String testName) throws Exception {
729 if (logger.isDebugEnabled()) {
730 logger.debug(testBanner(testName, CLASS_NAME));
735 // Submit the request to the service and store the response.
736 OrgAuthorityClient client = new OrgAuthorityClient();
737 PoxPayloadIn input = null;
738 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
740 int statusCode = res.getStatus();
742 // Check the status code of the response: does it match
743 // the expected response(s)?
744 if(logger.isDebugEnabled()){
745 logger.debug(testName + ": status = " + statusCode);
747 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
748 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
749 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
751 // Check whether organization has expected displayName.
752 input = new PoxPayloadIn(res.getEntity());
754 res.releaseConnection();
757 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
758 client.getItemCommonPartName(), OrganizationsCommon.class);
759 Assert.assertNotNull(organization);
760 String displayName = organization.getDisplayName();
761 // Make sure displayName matches computed form
762 String expectedDisplayName =
763 OrgAuthorityClientUtils.prepareDefaultDisplayName(
764 TEST_ORG_SHORTNAME, TEST_ORG_FOUNDING_PLACE);
765 Assert.assertNotNull(displayName, expectedDisplayName);
767 // Update the shortName and verify the computed name is updated.
768 organization.setCsid(null);
769 organization.setDisplayNameComputed(true);
771 MainBodyGroupList mainBodyList = organization.getMainBodyGroupList();
772 List<MainBodyGroup> mainBodyGroups = mainBodyList.getMainBodyGroup();
773 MainBodyGroup mainBodyGroup = new MainBodyGroup();
774 String updatedShortName = "updated-" + TEST_ORG_SHORTNAME;
775 mainBodyGroup.setShortName(updatedShortName);
776 mainBodyGroups.add(mainBodyGroup);
777 organization.setMainBodyGroupList(mainBodyList);
779 expectedDisplayName =
780 OrgAuthorityClientUtils.prepareDefaultDisplayName(
781 updatedShortName, TEST_ORG_FOUNDING_PLACE);
783 // Submit the updated resource to the service and store the response.
784 PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
785 PayloadOutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
786 commonPart.setLabel(client.getItemCommonPartName());
787 res = client.updateItem(knownResourceId, knownItemResourceId, output);
789 int statusCode = res.getStatus();
791 // Check the status code of the response: does it match the expected response(s)?
792 if(logger.isDebugEnabled()){
793 logger.debug("updateItem: status = " + statusCode);
795 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
796 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
797 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
799 // Retrieve the updated resource and verify that its contents exist.
800 input = new PoxPayloadIn(res.getEntity());
802 res.releaseConnection();
805 OrganizationsCommon updatedOrganization =
806 (OrganizationsCommon) extractPart(input,
807 client.getItemCommonPartName(), OrganizationsCommon.class);
808 Assert.assertNotNull(updatedOrganization);
810 // Verify that the updated resource received the correct data.
811 mainBodyList = organization.getMainBodyGroupList();
812 Assert.assertNotNull(mainBodyList);
813 Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0);
814 Assert.assertEquals(updatedOrganization.getMainBodyGroupList().getMainBodyGroup().get(0).getShortName(),
815 updatedShortName, "Updated ShortName in Organization did not match submitted data.");
817 // Verify that the updated resource computes the right displayName.
818 Assert.assertEquals(updatedOrganization.getDisplayName(), expectedDisplayName,
819 "Updated ShortName in Organization not reflected in computed DisplayName.");
821 // Now Update the displayName, not computed and verify the computed name is overriden.
822 organization.setDisplayNameComputed(false);
823 expectedDisplayName = "TestName";
824 organization.setDisplayName(expectedDisplayName);
826 // Submit the updated resource to the service and store the response.
827 output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
828 commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
829 commonPart.setLabel(client.getItemCommonPartName());
830 res = client.updateItem(knownResourceId, knownItemResourceId, output);
832 int statusCode = res.getStatus();
834 // Check the status code of the response: does it match the expected response(s)?
835 if(logger.isDebugEnabled()){
836 logger.debug("updateItem: status = " + statusCode);
838 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
839 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
840 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
842 // Retrieve the updated resource and verify that its contents exist.
843 input = new PoxPayloadIn(res.getEntity());
845 res.releaseConnection();
848 updatedOrganization =
849 (OrganizationsCommon) extractPart(input,
850 client.getItemCommonPartName(), OrganizationsCommon.class);
851 Assert.assertNotNull(updatedOrganization);
853 // Verify that the updated resource received the correct data.
854 Assert.assertEquals(updatedOrganization.isDisplayNameComputed(), false,
855 "Updated displayNameComputed in Organization did not match submitted data.");
856 // Verify that the updated resource computes the right displayName.
857 Assert.assertEquals(updatedOrganization.getDisplayName(),
859 "Updated DisplayName (not computed) in Organization not stored.");
863 * Verify illegal item display name.
865 * @param testName the test name
866 * @throws Exception the exception
868 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
869 dependsOnMethods = {"verifyItemDisplayName"})
870 public void verifyIllegalItemDisplayName(String testName) throws Exception {
872 if (logger.isDebugEnabled()) {
873 logger.debug(testBanner(testName, CLASS_NAME));
876 testSetup(STATUS_BAD_REQUEST, ServiceRequestType.UPDATE);
877 // setupUpdateWithWrongXmlSchema(testName, logger);
879 // Submit the request to the service and store the response.
880 OrgAuthorityClient client = new OrgAuthorityClient();
881 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
883 int statusCode = res.getStatus();
885 // Check the status code of the response: does it match
886 // the expected response(s)?
887 if(logger.isDebugEnabled()){
888 logger.debug(testName + ": status = " + statusCode);
890 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
891 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
892 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
894 // Check whether organization has expected displayName.
895 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
896 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
897 client.getItemCommonPartName(), OrganizationsCommon.class);
898 Assert.assertNotNull(organization);
899 // Try to Update with computed false and no displayName
900 organization.setDisplayNameComputed(false);
901 organization.setDisplayName(null);
903 // Submit the updated resource to the service and store the response.
904 PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
905 PayloadOutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
906 commonPart.setLabel(client.getItemCommonPartName());
907 res.releaseConnection();
908 res = client.updateItem(knownResourceId, knownItemResourceId, output);
909 statusCode = res.getStatus();
911 // Check the status code of the response: does it match the expected response(s)?
912 if(logger.isDebugEnabled()){
913 logger.debug("updateItem: status = " + statusCode);
915 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
916 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
917 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
919 res.releaseConnection();
926 * @param testName the test name
927 * @throws Exception the exception
929 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
930 groups = {"readItem"}, dependsOnMethods = {"readItem"})
931 public void readContact(String testName) throws Exception {
933 if (logger.isDebugEnabled()) {
934 logger.debug(testBanner(testName, CLASS_NAME));
939 // Submit the request to the service and store the response.
940 OrgAuthorityClient client = new OrgAuthorityClient();
941 ClientResponse<String> res =
942 client.readContact(knownResourceId, knownItemResourceId,
943 knownContactResourceId);
945 int statusCode = res.getStatus();
947 // Check the status code of the response: does it match
948 // the expected response(s)?
949 if(logger.isDebugEnabled()){
950 logger.debug(testName + ": status = " + statusCode);
952 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
953 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
954 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
956 // Check whether we've received a contact.
957 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
958 ContactsCommon contact = (ContactsCommon) extractPart(input,
959 new ContactClient().getCommonPartName(), ContactsCommon.class);
960 Assert.assertNotNull(contact);
961 boolean showFull = true;
962 if(showFull && logger.isDebugEnabled()){
963 logger.debug(testName + ": returned payload:");
964 logger.debug(objectAsXmlString(contact, ContactsCommon.class));
966 Assert.assertEquals(contact.getInAuthority(), knownResourceId);
967 Assert.assertEquals(contact.getInItem(), knownItemResourceId);
969 res.releaseConnection();
975 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
978 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
979 groups = {"read"}, dependsOnMethods = {"read"})
980 public void readNonExistent(String testName) {
982 if (logger.isDebugEnabled()) {
983 logger.debug(testBanner(testName, CLASS_NAME));
986 setupReadNonExistent();
988 // Submit the request to the service and store the response.
989 OrgAuthorityClient client = new OrgAuthorityClient();
990 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
992 int statusCode = res.getStatus();
994 // Check the status code of the response: does it match
995 // the expected response(s)?
996 if(logger.isDebugEnabled()){
997 logger.debug(testName + ": status = " + statusCode);
999 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1000 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1001 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1003 res.releaseConnection();
1008 * Read item non existent.
1010 * @param testName the test name
1012 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1013 groups = {"readItem"}, dependsOnMethods = {"readItem"})
1014 public void readItemNonExistent(String testName) {
1016 if (logger.isDebugEnabled()) {
1017 logger.debug(testBanner(testName, CLASS_NAME));
1020 setupReadNonExistent();
1022 // Submit the request to the service and store the response.
1023 OrgAuthorityClient client = new OrgAuthorityClient();
1024 ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
1026 int statusCode = res.getStatus();
1028 // Check the status code of the response: does it match
1029 // the expected response(s)?
1030 if(logger.isDebugEnabled()){
1031 logger.debug(testName + ": status = " + statusCode);
1033 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1034 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1035 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1037 res.releaseConnection();
1042 * Read contact non existent.
1044 * @param testName the test name
1046 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1047 groups = {"readItem"}, dependsOnMethods = {"readContact"})
1048 public void readContactNonExistent(String testName) {
1050 if (logger.isDebugEnabled()) {
1051 logger.debug(testBanner(testName, CLASS_NAME));
1054 setupReadNonExistent();
1056 // Submit the request to the service and store the response.
1057 OrgAuthorityClient client = new OrgAuthorityClient();
1058 ClientResponse<String> res =
1059 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1061 int statusCode = res.getStatus();
1063 // Check the status code of the response: does it match
1064 // the expected response(s)?
1065 if(logger.isDebugEnabled()){
1066 logger.debug(testName + ": status = " + statusCode);
1068 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1069 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1070 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1072 res.releaseConnection();
1076 // ---------------------------------------------------------------
1077 // CRUD tests : READ_LIST tests
1078 // ---------------------------------------------------------------
1082 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
1085 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1086 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
1087 public void readList(String testName) throws Exception {
1089 if (logger.isDebugEnabled()) {
1090 logger.debug(testBanner(testName, CLASS_NAME));
1095 // Submit the request to the service and store the response.
1096 OrgAuthorityClient client = new OrgAuthorityClient();
1097 ClientResponse<OrgauthoritiesCommonList> res = client.readList();
1099 OrgauthoritiesCommonList list = res.getEntity();
1100 int statusCode = res.getStatus();
1102 // Check the status code of the response: does it match
1103 // the expected response(s)?
1104 if(logger.isDebugEnabled()){
1105 logger.debug(testName + ": status = " + statusCode);
1107 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1108 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1109 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1111 // Optionally output additional data about list members for debugging.
1112 boolean iterateThroughList = false;
1113 if (iterateThroughList && logger.isDebugEnabled()) {
1114 List<OrgauthoritiesCommonList.OrgauthorityListItem> items =
1115 list.getOrgauthorityListItem();
1117 for (OrgauthoritiesCommonList.OrgauthorityListItem item : items) {
1118 String csid = item.getCsid();
1119 logger.debug(testName + ": list-item[" + i + "] csid=" +
1121 logger.debug(testName + ": list-item[" + i + "] displayName=" +
1122 item.getDisplayName());
1123 logger.debug(testName + ": list-item[" + i + "] URI=" +
1125 readItemList(csid, null);
1130 res.releaseConnection();
1137 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
1138 public void readItemList() {
1139 readItemList(knownResourceId, null);
1143 * Read item list by authority name.
1145 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1146 public void readItemListByAuthorityName() {
1147 readItemList(null, knownResourceShortIdentifer);
1153 * @param vcsid the vcsid
1154 * @param name the name
1156 private void readItemList(String vcsid, String name) {
1158 final String testName = "readItemList";
1160 if (logger.isDebugEnabled()) {
1161 logger.debug(testBanner(testName, CLASS_NAME));
1166 // Submit the request to the service and store the response.
1167 OrgAuthorityClient client = new OrgAuthorityClient();
1168 ClientResponse<OrganizationsCommonList> res = null;
1170 res = client.readItemList(vcsid, null, null);
1171 } else if(name!= null) {
1172 res = client.readItemListForNamedAuthority(name, null, null);
1174 Assert.fail("readItemList passed null csid and name!");
1177 OrganizationsCommonList list = res.getEntity();
1178 int statusCode = res.getStatus();
1180 // Check the status code of the response: does it match
1181 // the expected response(s)?
1182 if(logger.isDebugEnabled()){
1183 logger.debug(testName + ": status = " + statusCode);
1185 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1186 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1187 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1189 List<OrganizationsCommonList.OrganizationListItem> items =
1190 list.getOrganizationListItem();
1191 int nItemsReturned = items.size();
1192 // There will be one item created, associated with a
1193 // known parent resource, by the createItem test.
1195 // In addition, there will be 'nItemsToCreateInList'
1196 // additional items created by the createItemList test,
1197 // all associated with the same parent resource.
1198 int nExpectedItems = nItemsToCreateInList + 1;
1199 if(logger.isDebugEnabled()){
1200 logger.debug(testName + ": Expected "
1201 + nExpectedItems +" items; got: "+nItemsReturned);
1203 Assert.assertEquals(nItemsReturned, nExpectedItems);
1206 for (OrganizationsCommonList.OrganizationListItem item : items) {
1207 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
1208 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
1209 // Optionally output additional data about list members for debugging.
1210 boolean showDetails = true;
1211 if (showDetails && logger.isDebugEnabled()) {
1212 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1214 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
1216 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
1217 item.getDisplayName());
1218 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1224 res.releaseConnection();
1229 * Read contact list.
1231 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1232 public void readContactList() {
1233 readContactList(knownResourceId, knownItemResourceId);
1237 * Read contact list.
1239 * @param parentcsid the parentcsid
1240 * @param itemcsid the itemcsid
1242 private void readContactList(String parentcsid, String itemcsid) {
1243 final String testName = "readContactList";
1245 if (logger.isDebugEnabled()) {
1246 logger.debug(testBanner(testName, CLASS_NAME));
1251 // Submit the request to the service and store the response.
1252 OrgAuthorityClient client = new OrgAuthorityClient();
1253 ContactsCommonList list = null;
1254 ClientResponse<ContactsCommonList> res =
1255 client.readContactList(parentcsid, itemcsid);
1257 list = res.getEntity();
1258 int statusCode = res.getStatus();
1260 // Check the status code of the response: does it match
1261 // the expected response(s)?
1262 if(logger.isDebugEnabled()){
1263 logger.debug(testName + ": status = " + statusCode);
1265 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1266 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1267 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1269 List<ContactsCommonList.ContactListItem> listitems =
1270 list.getContactListItem();
1271 int nItemsReturned = listitems.size();
1272 // There will be one item created, associated with a
1273 // known parent resource, by the createItem test.
1275 // In addition, there will be 'nItemsToCreateInList'
1276 // additional items created by the createItemList test,
1277 // all associated with the same parent resource.
1278 int nExpectedItems = nItemsToCreateInList + 1;
1279 if(logger.isDebugEnabled()){
1280 logger.debug(testName + ": Expected "
1281 + nExpectedItems +" items; got: "+nItemsReturned);
1283 Assert.assertEquals(nItemsReturned, nExpectedItems);
1286 for (ContactsCommonList.ContactListItem listitem : listitems) {
1287 // Optionally output additional data about list members for debugging.
1288 boolean showDetails = false;
1289 if (showDetails && logger.isDebugEnabled()) {
1290 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1291 listitem.getCsid());
1292 logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" +
1293 listitem.getAddressPlace());
1294 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1300 res.releaseConnection();
1307 // ---------------------------------------------------------------
1308 // CRUD tests : UPDATE tests
1309 // ---------------------------------------------------------------
1312 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
1315 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1316 groups = {"update"}, dependsOnGroups = {"read", "readList"})
1317 public void update(String testName) throws Exception {
1319 if (logger.isDebugEnabled()) {
1320 logger.debug(testBanner(testName, CLASS_NAME));
1325 // Retrieve the contents of a resource to update.
1326 OrgAuthorityClient client = new OrgAuthorityClient();
1327 ClientResponse<String> res =
1328 client.read(knownResourceId);
1330 if(logger.isDebugEnabled()){
1331 logger.debug(testName + ": read status = " + res.getStatus());
1333 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1335 if(logger.isDebugEnabled()){
1336 logger.debug("got OrgAuthority to update with ID: " + knownResourceId);
1338 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
1339 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
1340 client.getCommonPartName(), OrgauthoritiesCommon.class);
1341 Assert.assertNotNull(orgAuthority);
1343 // Update the contents of this resource.
1344 orgAuthority.setDisplayName("updated-" + orgAuthority.getDisplayName());
1345 orgAuthority.setVocabType("updated-" + orgAuthority.getVocabType());
1346 if(logger.isDebugEnabled()){
1347 logger.debug("to be updated OrgAuthority");
1348 logger.debug(objectAsXmlString(orgAuthority, OrgauthoritiesCommon.class));
1351 // Submit the updated resource to the service and store the response.
1352 PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_PAYLOAD_NAME);
1353 PayloadOutputPart commonPart = output.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE);
1354 commonPart.setLabel(client.getCommonPartName());
1355 res.releaseConnection();
1356 res = client.update(knownResourceId, output);
1357 int statusCode = res.getStatus();
1359 // Check the status code of the response: does it match the expected response(s)?
1360 if(logger.isDebugEnabled()){
1361 logger.debug(testName + ": status = " + statusCode);
1363 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1364 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1365 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1367 // Retrieve the updated resource and verify that its contents exist.
1368 input = new PoxPayloadIn(res.getEntity());
1369 OrgauthoritiesCommon updatedOrgAuthority =
1370 (OrgauthoritiesCommon) extractPart(input,
1371 client.getCommonPartName(), OrgauthoritiesCommon.class);
1372 Assert.assertNotNull(updatedOrgAuthority);
1374 // Verify that the updated resource received the correct data.
1375 Assert.assertEquals(updatedOrgAuthority.getDisplayName(),
1376 orgAuthority.getDisplayName(),
1377 "Data in updated object did not match submitted data.");
1379 res.releaseConnection();
1386 * @param testName the test name
1387 * @throws Exception the exception
1389 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1390 groups = {"update"}, dependsOnMethods = {"update"})
1391 public void updateItem(String testName) throws Exception {
1393 if (logger.isDebugEnabled()) {
1394 logger.debug(testBanner(testName, CLASS_NAME));
1399 // Retrieve the contents of a resource to update.
1400 OrgAuthorityClient client = new OrgAuthorityClient();
1401 ClientResponse<String> res =
1402 client.readItem(knownResourceId, knownItemResourceId);
1404 if(logger.isDebugEnabled()){
1405 logger.debug(testName + ": read status = " + res.getStatus());
1407 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1409 if(logger.isDebugEnabled()){
1410 logger.debug("got Organization to update with ID: " +
1411 knownItemResourceId +
1412 " in OrgAuthority: " + knownResourceId );
1414 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
1415 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
1416 client.getItemCommonPartName(), OrganizationsCommon.class);
1417 Assert.assertNotNull(organization);
1419 // Update the contents of this resource.
1420 organization.setCsid(null);
1422 MainBodyGroupList mainBodyList = organization.getMainBodyGroupList();
1423 Assert.assertNotNull(mainBodyList);
1424 List<MainBodyGroup> mainBodyGroups = mainBodyList.getMainBodyGroup();
1425 Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0);
1426 String updatedShortName = "updated-" + mainBodyGroups.get(0).getShortName();
1427 mainBodyGroups.get(0).setShortName(updatedShortName);
1429 if(logger.isDebugEnabled()){
1430 logger.debug("to be updated Organization");
1431 logger.debug(objectAsXmlString(organization,
1432 OrganizationsCommon.class));
1435 // Submit the updated resource to the service and store the response.
1436 PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1437 PayloadOutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
1438 commonPart.setLabel(client.getItemCommonPartName());
1439 res.releaseConnection();
1440 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1441 int statusCode = res.getStatus();
1443 // Check the status code of the response: does it match the expected response(s)?
1444 if(logger.isDebugEnabled()){
1445 logger.debug(testName + ": status = " + statusCode);
1447 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1448 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1449 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1451 // Retrieve the updated resource and verify that its contents exist.
1452 input = new PoxPayloadIn(res.getEntity());
1453 OrganizationsCommon updatedOrganization =
1454 (OrganizationsCommon) extractPart(input,
1455 client.getItemCommonPartName(), OrganizationsCommon.class);
1456 Assert.assertNotNull(updatedOrganization);
1458 // Verify that the updated resource received the correct data.
1459 mainBodyList = organization.getMainBodyGroupList();
1460 Assert.assertNotNull(mainBodyList);
1461 Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0);
1462 Assert.assertEquals(updatedOrganization.getMainBodyGroupList().getMainBodyGroup().get(0).getShortName(),
1463 updatedShortName, "Data in updated Organization did not match submitted data.");
1465 res.releaseConnection();
1472 * @param testName the test name
1473 * @throws Exception the exception
1475 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1476 groups = {"update"}, dependsOnMethods = {"updateItem"})
1477 public void updateContact(String testName) throws Exception {
1479 if (logger.isDebugEnabled()) {
1480 logger.debug(testBanner(testName, CLASS_NAME));
1485 // Retrieve the contents of a resource to update.
1486 OrgAuthorityClient client = new OrgAuthorityClient();
1487 ClientResponse<String> res =
1488 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1490 if(logger.isDebugEnabled()){
1491 logger.debug(testName + ": read status = " + res.getStatus());
1493 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1495 if(logger.isDebugEnabled()){
1496 logger.debug("got Contact to update with ID: " +
1497 knownContactResourceId +
1498 " in item: " + knownItemResourceId +
1499 " in parent: " + knownResourceId );
1501 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
1502 ContactsCommon contact = (ContactsCommon) extractPart(input,
1503 new ContactClient().getCommonPartName(), ContactsCommon.class);
1504 Assert.assertNotNull(contact);
1506 // Update the contents of this resource.
1507 contact.setAddressPlace("updated-" + contact.getAddressPlace());
1508 if(logger.isDebugEnabled()){
1509 logger.debug("to be updated Contact");
1510 logger.debug(objectAsXmlString(contact,
1511 ContactsCommon.class));
1514 // Submit the updated resource to the service and store the response.
1515 PoxPayloadOut output = new PoxPayloadOut(ContactClient.SERVICE_PAYLOAD_NAME);
1516 PayloadOutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1517 commonPart.setLabel(new ContactClient().getCommonPartName());
1518 res.releaseConnection();
1519 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1520 int statusCode = res.getStatus();
1522 // Check the status code of the response: does it match the expected response(s)?
1523 if(logger.isDebugEnabled()){
1524 logger.debug(testName + ": status = " + statusCode);
1526 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1527 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1528 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1530 // Retrieve the updated resource and verify that its contents exist.
1531 input = new PoxPayloadIn(res.getEntity());
1532 ContactsCommon updatedContact =
1533 (ContactsCommon) extractPart(input,
1534 new ContactClient().getCommonPartName(), ContactsCommon.class);
1535 Assert.assertNotNull(updatedContact);
1537 // Verify that the updated resource received the correct data.
1538 Assert.assertEquals(updatedContact.getAddressPlace(),
1539 contact.getAddressPlace(),
1540 "Data in updated Contact did not match submitted data.");
1542 res.releaseConnection();
1547 // Placeholders until the three tests below can be uncommented.
1548 // See Issue CSPACE-401.
1550 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1553 public void updateWithEmptyEntityBody(String testName) throws Exception {
1554 //Should this really be empty?
1558 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1561 public void updateWithMalformedXml(String testName) throws Exception {
1562 //Should this really be empty?
1566 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1569 public void updateWithWrongXmlSchema(String testName) throws Exception {
1570 //Should this really be empty?
1575 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1576 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1577 public void updateWithEmptyEntityBody(String testName) throws Exception {
1579 if (logger.isDebugEnabled()) {
1580 logger.debug(testBanner(testName, CLASS_NAME));
1583 setupUpdateWithEmptyEntityBody();
1585 // Submit the request to the service and store the response.
1586 String method = REQUEST_TYPE.httpMethodName();
1587 String url = getResourceURL(knownResourceId);
1588 String mediaType = MediaType.APPLICATION_XML;
1589 final String entity = "";
1590 int statusCode = submitRequest(method, url, mediaType, entity);
1592 // Check the status code of the response: does it match
1593 // the expected response(s)?
1594 if(logger.isDebugEnabled()){
1595 logger.debug(testName + ": url=" + url +
1596 " status=" + statusCode);
1598 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1599 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1600 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1604 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1605 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1606 public void updateWithMalformedXml(String testName) throws Exception {
1608 if (logger.isDebugEnabled()) {
1609 logger.debug(testBanner(testName, CLASS_NAME));
1612 setupUpdateWithMalformedXml();
1614 // Submit the request to the service and store the response.
1615 String method = REQUEST_TYPE.httpMethodName();
1616 String url = getResourceURL(knownResourceId);
1617 String mediaType = MediaType.APPLICATION_XML;
1618 final String entity = MALFORMED_XML_DATA;
1619 int statusCode = submitRequest(method, url, mediaType, entity);
1621 // Check the status code of the response: does it match
1622 // the expected response(s)?
1623 if(logger.isDebugEnabled()){
1624 logger.debug(testName + ": url=" + url +
1625 " status=" + statusCode);
1627 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1628 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1629 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1633 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1634 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1635 public void updateWithWrongXmlSchema(String testName) throws Exception {
1638 setupUpdateWithWrongXmlSchema(testName, logger);
1640 // Submit the request to the service and store the response.
1641 String method = REQUEST_TYPE.httpMethodName();
1642 String url = getResourceURL(knownResourceId);
1643 String mediaType = MediaType.APPLICATION_XML;
1644 final String entity = WRONG_XML_SCHEMA_DATA;
1645 int statusCode = submitRequest(method, url, mediaType, entity);
1647 // Check the status code of the response: does it match
1648 // the expected response(s)?
1649 if(logger.isDebugEnabled()){
1650 logger.debug("updateWithWrongXmlSchema: url=" + url +
1651 " status=" + statusCode);
1653 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1654 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1655 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1660 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1663 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1664 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1665 public void updateNonExistent(String testName) throws Exception {
1667 if (logger.isDebugEnabled()) {
1668 logger.debug(testBanner(testName, CLASS_NAME));
1671 setupUpdateNonExistent();
1673 // Submit the request to the service and store the response.
1674 // Note: The ID used in this 'create' call may be arbitrary.
1675 // The only relevant ID may be the one used in update(), below.
1676 OrgAuthorityClient client = new OrgAuthorityClient();
1677 PoxPayloadOut multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance(
1678 NON_EXISTENT_ID, NON_EXISTENT_ID,
1679 new OrgAuthorityClient().getCommonPartName());
1680 ClientResponse<String> res =
1681 client.update(NON_EXISTENT_ID, multipart);
1683 int statusCode = res.getStatus();
1685 // Check the status code of the response: does it match
1686 // the expected response(s)?
1687 if(logger.isDebugEnabled()){
1688 logger.debug(testName + ": status = " + statusCode);
1690 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1691 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1692 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1694 res.releaseConnection();
1699 * Update non existent item.
1701 * @param testName the test name
1702 * @throws Exception the exception
1704 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1705 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1706 public void updateNonExistentItem(String testName) throws Exception {
1708 if (logger.isDebugEnabled()) {
1709 logger.debug(testBanner(testName, CLASS_NAME));
1712 setupUpdateNonExistent();
1714 // Submit the request to the service and store the response.
1715 // Note: The ID(s) used when creating the request payload may be arbitrary.
1716 // The only relevant ID may be the one used in update(), below.
1717 OrgAuthorityClient client = new OrgAuthorityClient();
1718 Map<String, String> nonexOrgMap = new HashMap<String,String>();
1719 nonexOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, "nonExistent");
1720 nonexOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Non-existent");
1721 PoxPayloadOut multipart =
1722 OrgAuthorityClientUtils.createOrganizationInstance(
1723 knownResourceRefName,
1724 nonexOrgMap, client.getItemCommonPartName() );
1725 ClientResponse<String> res =
1726 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1728 int statusCode = res.getStatus();
1730 // Check the status code of the response: does it match
1731 // the expected response(s)?
1732 if(logger.isDebugEnabled()){
1733 logger.debug(testName + ": status = " + statusCode);
1735 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1736 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1737 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1739 res.releaseConnection();
1744 * Update non existent contact.
1746 * @param testName the test name
1747 * @throws Exception the exception
1749 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1750 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1751 public void updateNonExistentContact(String testName) throws Exception {
1752 // Currently a no-op test
1755 // ---------------------------------------------------------------
1756 // CRUD tests : DELETE tests
1757 // ---------------------------------------------------------------
1760 // Note: delete sub-resources in ascending hierarchical order,
1761 // before deleting their parents.
1766 * @param testName the test name
1767 * @throws Exception the exception
1769 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1770 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1771 public void deleteContact(String testName) throws Exception {
1773 if (logger.isDebugEnabled()) {
1774 logger.debug(testBanner(testName, CLASS_NAME));
1779 if(logger.isDebugEnabled()){
1780 logger.debug("parentcsid =" + knownResourceId +
1781 " itemcsid = " + knownItemResourceId +
1782 " csid = " + knownContactResourceId);
1785 // Submit the request to the service and store the response.
1786 OrgAuthorityClient client = new OrgAuthorityClient();
1787 ClientResponse<Response> res =
1788 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1790 int statusCode = res.getStatus();
1792 // Check the status code of the response: does it match
1793 // the expected response(s)?
1794 if(logger.isDebugEnabled()){
1795 logger.debug(testName + ": status = " + statusCode);
1797 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1798 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1799 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1801 res.releaseConnection();
1808 * @param testName the test name
1809 * @throws Exception the exception
1811 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1812 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1813 public void deleteItem(String testName) throws Exception {
1815 if (logger.isDebugEnabled()) {
1816 logger.debug(testBanner(testName, CLASS_NAME));
1821 if(logger.isDebugEnabled()){
1822 logger.debug("parentcsid =" + knownResourceId +
1823 " itemcsid = " + knownItemResourceId);
1826 // Submit the request to the service and store the response.
1827 OrgAuthorityClient client = new OrgAuthorityClient();
1828 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1830 int statusCode = res.getStatus();
1832 // Check the status code of the response: does it match
1833 // the expected response(s)?
1834 if(logger.isDebugEnabled()){
1835 logger.debug(testName + ": status = " + statusCode);
1837 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1838 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1839 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1841 res.releaseConnection();
1846 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1849 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1850 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1851 public void delete(String testName) throws Exception {
1853 if (logger.isDebugEnabled()) {
1854 logger.debug(testBanner(testName, CLASS_NAME));
1859 if(logger.isDebugEnabled()){
1860 logger.debug("parentcsid =" + knownResourceId);
1863 // Submit the request to the service and store the response.
1864 OrgAuthorityClient client = new OrgAuthorityClient();
1865 ClientResponse<Response> res = client.delete(knownResourceId);
1867 int statusCode = res.getStatus();
1869 // Check the status code of the response: does it match
1870 // the expected response(s)?
1871 if(logger.isDebugEnabled()){
1872 logger.debug(testName + ": status = " + statusCode);
1874 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1875 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1876 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1878 res.releaseConnection();
1884 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1887 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1888 groups = {"delete"}, dependsOnMethods = {"delete"})
1889 public void deleteNonExistent(String testName) throws Exception {
1891 if (logger.isDebugEnabled()) {
1892 logger.debug(testBanner(testName, CLASS_NAME));
1895 setupDeleteNonExistent();
1897 // Submit the request to the service and store the response.
1898 OrgAuthorityClient client = new OrgAuthorityClient();
1899 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1901 int statusCode = res.getStatus();
1903 // Check the status code of the response: does it match
1904 // the expected response(s)?
1905 if(logger.isDebugEnabled()){
1906 logger.debug(testName + ": status = " + statusCode);
1908 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1909 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1910 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1912 res.releaseConnection();
1917 * Delete non existent item.
1919 * @param testName the test name
1921 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1922 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1923 public void deleteNonExistentItem(String testName) {
1925 if (logger.isDebugEnabled()) {
1926 logger.debug(testBanner(testName, CLASS_NAME));
1929 setupDeleteNonExistent();
1931 // Submit the request to the service and store the response.
1932 OrgAuthorityClient client = new OrgAuthorityClient();
1933 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1935 int statusCode = res.getStatus();
1937 // Check the status code of the response: does it match
1938 // the expected response(s)?
1939 if(logger.isDebugEnabled()){
1940 logger.debug(testName + ": status = " + statusCode);
1942 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1943 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1944 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1946 res.releaseConnection();
1951 * Delete non existent contact.
1953 * @param testName the test name
1955 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1956 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1957 public void deleteNonExistentContact(String testName) {
1959 if (logger.isDebugEnabled()) {
1960 logger.debug(testBanner(testName, CLASS_NAME));
1963 setupDeleteNonExistent();
1965 // Submit the request to the service and store the response.
1966 OrgAuthorityClient client = new OrgAuthorityClient();
1967 ClientResponse<Response> res =
1968 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1970 int statusCode = res.getStatus();
1972 // Check the status code of the response: does it match
1973 // the expected response(s)?
1974 if(logger.isDebugEnabled()){
1975 logger.debug(testName + ": status = " + statusCode);
1977 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1978 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1979 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1981 res.releaseConnection();
1985 // ---------------------------------------------------------------
1986 // Utility tests : tests of code used in tests above
1987 // ---------------------------------------------------------------
1989 * Tests the code for manually submitting data that is used by several
1990 * of the methods above.
1992 @Test(dependsOnMethods = {"create", "read"})
1993 public void testSubmitRequest() {
1995 // Expected status code: 200 OK
1996 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1998 // Submit the request to the service and store the response.
1999 String method = ServiceRequestType.READ.httpMethodName();
2000 String url = getResourceURL(knownResourceId);
2001 int statusCode = submitRequest(method, url);
2003 // Check the status code of the response: does it match
2004 // the expected response(s)?
2005 if(logger.isDebugEnabled()){
2006 logger.debug("testSubmitRequest: url=" + url +
2007 " status=" + statusCode);
2009 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2014 * Test item submit request.
2016 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
2017 public void testItemSubmitRequest() {
2019 // Expected status code: 200 OK
2020 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2022 // Submit the request to the service and store the response.
2023 String method = ServiceRequestType.READ.httpMethodName();
2024 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
2025 int statusCode = submitRequest(method, url);
2027 // Check the status code of the response: does it match
2028 // the expected response(s)?
2029 if(logger.isDebugEnabled()){
2030 logger.debug("testItemSubmitRequest: url=" + url +
2031 " status=" + statusCode);
2033 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2038 * Test contact submit request.
2040 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
2041 public void testContactSubmitRequest() {
2043 // Expected status code: 200 OK
2044 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2046 // Submit the request to the service and store the response.
2047 String method = ServiceRequestType.READ.httpMethodName();
2048 String url = getContactResourceURL(knownResourceId,
2049 knownItemResourceId, knownContactResourceId);
2050 int statusCode = submitRequest(method, url);
2052 // Check the status code of the response: does it match
2053 // the expected response(s)?
2054 if(logger.isDebugEnabled()){
2055 logger.debug("testItemSubmitRequest: url=" + url +
2056 " status=" + statusCode);
2058 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2063 // ---------------------------------------------------------------
2064 // Cleanup of resources created during testing
2065 // ---------------------------------------------------------------
2068 * Deletes all resources created by tests, after all tests have been run.
2070 * This cleanup method will always be run, even if one or more tests fail.
2071 * For this reason, it attempts to remove all resources created
2072 * at any point during testing, even if some of those resources
2073 * may be expected to be deleted by certain tests.
2076 @AfterClass(alwaysRun=true)
2078 public void cleanUp() {
2079 String noTest = System.getProperty("noTestCleanup");
2080 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
2081 if (logger.isDebugEnabled()) {
2082 logger.debug("Skipping Cleanup phase ...");
2086 if (logger.isDebugEnabled()) {
2087 logger.debug("Cleaning up temporary resources created for testing ...");
2090 String parentResourceId;
2091 String itemResourceId;
2092 String contactResourceId;
2093 // Clean up contact resources.
2094 parentResourceId = knownResourceId;
2095 OrgAuthorityClient client = new OrgAuthorityClient();
2096 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
2097 contactResourceId = entry.getKey();
2098 itemResourceId = entry.getValue();
2099 // Note: Any non-success responses from the delete operation
2100 // below are ignored and not reported.
2101 ClientResponse<Response> res =
2102 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
2103 res.releaseConnection();
2105 // Clean up item resources.
2106 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
2107 itemResourceId = entry.getKey();
2108 parentResourceId = entry.getValue();
2109 // Note: Any non-success responses from the delete operation
2110 // below are ignored and not reported.
2111 ClientResponse<Response> res =
2112 client.deleteItem(parentResourceId, itemResourceId);
2113 res.releaseConnection();
2115 // Clean up parent resources.
2120 // ---------------------------------------------------------------
2121 // Utility methods used by tests above
2122 // ---------------------------------------------------------------
2124 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
2127 * Gets the item service path component.
2129 * @return the item service path component
2131 public String getItemServicePathComponent() {
2132 return OrgAuthorityClient.SERVICE_PATH_ITEMS_COMPONENT;
2136 * Gets the contact service path component.
2138 * @return the contact service path component
2140 public String getContactServicePathComponent() {
2141 return ContactClient.SERVICE_PATH_COMPONENT;
2145 * Returns the root URL for the item service.
2147 * This URL consists of a base URL for all services, followed by
2148 * a path component for the owning parent, followed by the
2149 * path component for the items.
2151 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2152 * parent authority resource of the relevant item resource.
2154 * @return The root URL for the item service.
2156 protected String getItemServiceRootURL(String parentResourceIdentifier) {
2157 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
2161 * Returns the URL of a specific item resource managed by a service, and
2162 * designated by an identifier (such as a universally unique ID, or UUID).
2164 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2165 * parent authority resource of the relevant item resource.
2167 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2170 * @return The URL of a specific item resource managed by a service.
2172 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
2173 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
2178 * Returns the root URL for the contact service.
2180 * This URL consists of a base URL for all services, followed by
2181 * a path component for the owning authority, followed by the
2182 * path component for the owning item, followed by the path component
2183 * for the contact service.
2185 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2186 * parent authority resource of the relevant item resource.
2188 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2191 * @return The root URL for the contact service.
2193 protected String getContactServiceRootURL(String parentResourceIdentifier,
2194 String itemResourceIdentifier) {
2195 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
2196 getContactServicePathComponent();
2200 * Returns the URL of a specific contact resource managed by a service, and
2201 * designated by an identifier (such as a universally unique ID, or UUID).
2203 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2204 * parent resource of the relevant item resource.
2206 * @param resourceIdentifier An identifier (such as a UUID) for an
2209 * @return The URL of a specific resource managed by a service.
2211 protected String getContactResourceURL(String parentResourceIdentifier,
2212 String itemResourceIdentifier, String contactResourceIdentifier) {
2213 return getContactServiceRootURL(parentResourceIdentifier,
2214 itemResourceIdentifier) + "/" + contactResourceIdentifier;