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.AuthorityClient;
35 import org.collectionspace.services.client.CollectionSpaceClient;
36 import org.collectionspace.services.client.ContactClient;
37 import org.collectionspace.services.client.ContactClientUtils;
38 import org.collectionspace.services.client.PayloadOutputPart;
39 import org.collectionspace.services.client.PersonAuthorityClient;
40 import org.collectionspace.services.client.PersonAuthorityClientUtils;
41 import org.collectionspace.services.client.PoxPayloadIn;
42 import org.collectionspace.services.client.PoxPayloadOut;
43 import org.collectionspace.services.contact.ContactsCommon;
44 import org.collectionspace.services.contact.ContactsCommonList;
45 import org.collectionspace.services.client.OrgAuthorityClient;
46 import org.collectionspace.services.client.OrgAuthorityClientUtils;
47 import org.collectionspace.services.jaxb.AbstractCommonList;
48 import org.collectionspace.services.organization.MainBodyGroup;
49 import org.collectionspace.services.organization.MainBodyGroupList;
50 import org.collectionspace.services.organization.OrgauthoritiesCommon;
51 import org.collectionspace.services.organization.OrgauthoritiesCommonList;
52 import org.collectionspace.services.organization.OrganizationsCommon;
53 import org.collectionspace.services.organization.OrganizationsCommonList;
55 import org.jboss.resteasy.client.ClientResponse;
57 import org.slf4j.Logger;
58 import org.slf4j.LoggerFactory;
59 import org.testng.Assert;
60 import org.testng.annotations.AfterClass;
61 import org.testng.annotations.Test;
64 * OrgAuthorityServiceTest, carries out tests against a
65 * deployed and running OrgAuthority Service.
67 * $LastChangedRevision$
70 public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: Test classes for Vocab, Person, Org, and Location should have a base class!
73 private final String CLASS_NAME = OrgAuthorityServiceTest.class.getName();
74 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
77 public String getServicePathComponent() {
78 return OrgAuthorityClient.SERVICE_PATH_COMPONENT;
82 protected String getServiceName() {
83 return OrgAuthorityClient.SERVICE_NAME;
86 /** The test organization shortname. */
87 private final String TEST_ORG_SHORTNAME = "Test Org";
89 /** The test organization founding place. */
90 private final String TEST_ORG_FOUNDING_PLACE = "Anytown, USA";
92 // Hold some values for a recently created item to verify upon read.
93 private String knownResourceId = null;
94 private String knownResourceShortIdentifer = null;
95 private String knownResourceRefName = null;
96 private String knownItemResourceId = null;
97 private String knownItemResourceShortIdentifer = null;
99 /** The known contact resource id. */
100 private String knownContactResourceId = null;
102 /** The n items to create in list. */
103 private int nItemsToCreateInList = 3;
105 /** The all item resource ids created. */
106 private Map<String, String> allItemResourceIdsCreated =
107 new HashMap<String, String>();
109 /** The all contact resource ids created. */
110 private Map<String, String> allContactResourceIdsCreated =
111 new HashMap<String, String>();
113 protected void setKnownResource( String id, String shortIdentifer,
115 knownResourceId = id;
116 knownResourceShortIdentifer = shortIdentifer;
117 knownResourceRefName = refName;
120 protected void setKnownItemResource( String id, String shortIdentifer ) {
121 knownItemResourceId = id;
122 knownItemResourceShortIdentifer = shortIdentifer;
126 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
129 protected CollectionSpaceClient getClientInstance() {
130 return new OrgAuthorityClient();
134 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
137 protected AbstractCommonList getAbstractCommonList(
138 ClientResponse<AbstractCommonList> response) {
139 return response.getEntity(OrganizationsCommonList.class);
142 // ---------------------------------------------------------------
143 // CRUD tests : CREATE tests
144 // ---------------------------------------------------------------
147 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
150 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
152 public void create(String testName) throws Exception {
154 if (logger.isDebugEnabled()) {
155 logger.debug(testBanner(testName, CLASS_NAME));
157 // Perform setup, such as initializing the type of service request
158 // (e.g. CREATE, DELETE), its valid and expected status codes, and
159 // its associated HTTP method name (e.g. POST, DELETE).
162 // Submit the request to the service and store the response.
163 OrgAuthorityClient client = new OrgAuthorityClient();
164 String shortId = createIdentifier();
165 String displayName = "displayName-" + shortId;
166 String baseRefName = OrgAuthorityClientUtils.createOrgAuthRefName(shortId, null);
167 PoxPayloadOut multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance(
168 displayName, shortId, client.getCommonPartName());
171 ClientResponse<Response> res = client.create(multipart);
173 int statusCode = res.getStatus();
175 // Check the status code of the response: does it match
176 // the expected response(s)?
179 // Does it fall within the set of valid status codes?
180 // Does it exactly match the expected status code?
181 if(logger.isDebugEnabled()){
182 logger.debug(testName + ": status = " + statusCode);
184 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
185 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
186 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
188 newID = OrgAuthorityClientUtils.extractId(res);
190 res.releaseConnection();
193 // Store the ID returned from the first resource created
194 // for additional tests below.
195 if (knownResourceId == null){
196 setKnownResource( newID, shortId, baseRefName );
197 if (logger.isDebugEnabled()) {
198 logger.debug(testName + ": knownResourceId=" + knownResourceId);
201 // Store the IDs from every resource created by tests,
202 // so they can be deleted after tests have been run.
203 allResourceIdsCreated.add(newID);
207 protected PoxPayloadOut createInstance(String identifier) {
208 OrgAuthorityClient client = new OrgAuthorityClient();
209 String displayName = "displayName-" + identifier;
210 PoxPayloadOut multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance(
211 displayName, identifier, client.getCommonPartName());
216 protected PoxPayloadOut createItemInstance(String parentCsid, String identifier) {
217 String headerLabel = new OrgAuthorityClient().getItemCommonPartName();
218 String shortId = "testOrg";
219 Map<String, String> testOrgMap = new HashMap<String,String>();
220 testOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId);
221 testOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, TEST_ORG_SHORTNAME);
222 testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "The real official test organization");
223 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "May 26, 1907");
224 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, TEST_ORG_FOUNDING_PLACE);
226 return OrgAuthorityClientUtils.createOrganizationInstance(identifier, testOrgMap, headerLabel);
232 * @param testName the test name
234 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
235 groups = {"create"}, dependsOnMethods = {"create"})
236 public void createItem(String testName) {
238 String newID = createItemInAuthority(knownResourceId, knownResourceRefName);
242 * Creates the item in authority.
244 * @param vcsid the vcsid
245 * @param authRefName the auth ref name
248 private String createItemInAuthority(String vcsid, String authRefName) {
250 final String testName = "createItemInAuthority";
251 if(logger.isDebugEnabled()){
252 logger.debug(testName + ":...");
255 // Submit the request to the service and store the response.
256 OrgAuthorityClient client = new OrgAuthorityClient();
257 String shortId = "testOrg";
258 Map<String, String> testOrgMap = new HashMap<String,String>();
259 testOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId);
260 testOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, TEST_ORG_SHORTNAME);
261 testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "The real official test organization");
262 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "May 26, 1907");
263 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, TEST_ORG_FOUNDING_PLACE);
265 Map<String, List<String>> testOrgRepeatablesMap = new HashMap<String,List<String>>();
266 List<String> testOrgContactNames = new ArrayList<String>();
267 testOrgContactNames.add("joe@example.org");
268 testOrgContactNames.add("sally@example.org");
269 testOrgRepeatablesMap.put(OrganizationJAXBSchema.CONTACT_NAMES, testOrgContactNames);
271 MainBodyGroupList mainBodyList = new MainBodyGroupList();
272 List<MainBodyGroup> mainBodyGroups = mainBodyList.getMainBodyGroup();
273 MainBodyGroup mainBodyGroup = new MainBodyGroup();
274 mainBodyGroup.setShortName(TEST_ORG_SHORTNAME);
275 mainBodyGroup.setLongName("The real official test organization");
276 mainBodyGroups.add(mainBodyGroup);
278 String newID = OrgAuthorityClientUtils.createItemInAuthority(
279 vcsid, authRefName, testOrgMap, testOrgRepeatablesMap, mainBodyList, client);
281 // Store the ID returned from the first item resource created
282 // for additional tests below.
283 if (knownItemResourceId == null){
284 setKnownItemResource(newID, shortId);
285 if (logger.isDebugEnabled()) {
286 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
290 // Store the IDs from any item resources created
291 // by tests, along with the IDs of their parents, so these items
292 // can be deleted after all tests have been run.
293 allItemResourceIdsCreated.put(newID, vcsid);
299 * Creates the contact.
301 * @param testName the test name
303 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
304 groups = {"create"}, dependsOnMethods = {"createItem"})
305 public void createContact(String testName) {
307 String newID = createContactInItem(knownResourceId, knownItemResourceId);
311 * Creates the contact in item.
313 * @param parentcsid the parentcsid
314 * @param itemcsid the itemcsid
317 private String createContactInItem(String parentcsid, String itemcsid) {
319 final String testName = "createContactInItem";
320 if (logger.isDebugEnabled()) {
321 logger.debug(testBanner(testName, CLASS_NAME));
325 // Submit the request to the service and store the response.
326 OrgAuthorityClient client = new OrgAuthorityClient();
327 String identifier = createIdentifier();
328 PoxPayloadOut multipart =
329 ContactClientUtils.createContactInstance(parentcsid,
330 itemcsid, identifier, new ContactClient().getCommonPartName());
333 ClientResponse<Response> res =
334 client.createContact(parentcsid, itemcsid, multipart);
336 int statusCode = res.getStatus();
337 // Check the status code of the response: does it match
338 // the expected response(s)?
339 if(logger.isDebugEnabled()){
340 logger.debug(testName + ": status = " + statusCode);
342 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
343 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
344 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
346 newID = OrgAuthorityClientUtils.extractId(res);
348 res.releaseConnection();
351 // Store the ID returned from the first contact resource created
352 // for additional tests below.
353 if (knownContactResourceId == null){
354 knownContactResourceId = newID;
355 if (logger.isDebugEnabled()) {
356 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
360 // Store the IDs from any contact resources created
361 // by tests, along with the IDs of their parent items,
362 // so these items can be deleted after all tests have been run.
363 allContactResourceIdsCreated.put(newID, itemcsid);
370 // Placeholders until the three tests below can be uncommented.
371 // See Issue CSPACE-401.
373 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
376 public void createWithEmptyEntityBody(String testName) throws Exception {
377 //Should this really be empty?
381 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
384 public void createWithMalformedXml(String testName) throws Exception {
385 //Should this really be empty?
389 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
392 public void createWithWrongXmlSchema(String testName) throws Exception {
393 //Should this really be empty?
398 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
399 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
400 public void createWithEmptyEntityBody(String testName) throws Exception {
402 if (logger.isDebugEnabled()) {
403 logger.debug(testBanner(testName, CLASS_NAME));
406 setupCreateWithEmptyEntityBody();
408 // Submit the request to the service and store the response.
409 String method = REQUEST_TYPE.httpMethodName();
410 String url = getServiceRootURL();
411 String mediaType = MediaType.APPLICATION_XML;
412 final String entity = "";
413 int statusCode = submitRequest(method, url, mediaType, entity);
415 // Check the status code of the response: does it match
416 // the expected response(s)?
417 if(logger.isDebugEnabled()) {
418 logger.debug(testName + ": url=" + url +
419 " status=" + statusCode);
421 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
422 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
423 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
427 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
428 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
429 public void createWithMalformedXml(String testName) throws Exception {
431 if (logger.isDebugEnabled()) {
432 logger.debug(testBanner(testName, CLASS_NAME));
435 setupCreateWithMalformedXml();
437 // Submit the request to the service and store the response.
438 String method = REQUEST_TYPE.httpMethodName();
439 String url = getServiceRootURL();
440 String mediaType = MediaType.APPLICATION_XML;
441 final String entity = MALFORMED_XML_DATA; // Constant from base class.
442 int statusCode = submitRequest(method, url, mediaType, entity);
444 // Check the status code of the response: does it match
445 // the expected response(s)?
446 if(logger.isDebugEnabled()){
447 logger.debug(testName + ": url=" + url +
448 " status=" + statusCode);
450 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
451 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
452 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
456 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
457 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
458 public void createWithWrongXmlSchema(String testName) throws Exception {
460 if (logger.isDebugEnabled()) {
461 logger.debug(testBanner(testName, CLASS_NAME));
464 setupCreateWithWrongXmlSchema();
466 // Submit the request to the service and store the response.
467 String method = REQUEST_TYPE.httpMethodName();
468 String url = getServiceRootURL();
469 String mediaType = MediaType.APPLICATION_XML;
470 final String entity = WRONG_XML_SCHEMA_DATA;
471 int statusCode = submitRequest(method, url, mediaType, entity);
473 // Check the status code of the response: does it match
474 // the expected response(s)?
475 if(logger.isDebugEnabled()){
476 logger.debug(testName + ": url=" + url +
477 " status=" + statusCode);
479 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
480 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
481 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
485 // ---------------------------------------------------------------
486 // CRUD tests : CREATE LIST tests
487 // ---------------------------------------------------------------
490 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
493 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
494 groups = {"createList"}, dependsOnGroups = {"create"})
495 public void createList(String testName) throws Exception {
496 for (int i = 0; i < nItemsToCreateInList; i++) {
502 * Creates the item list.
504 * @param testName the test name
505 * @throws Exception the exception
507 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
508 groups = {"createList"}, dependsOnMethods = {"createList"})
509 public void createItemList(String testName) throws Exception {
510 // Add items to the initially-created, known parent record.
511 for (int j = 0; j < nItemsToCreateInList; j++) {
512 createItem(testName);
517 * Creates the contact list.
519 * @param testName the test name
520 * @throws Exception the exception
522 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
523 groups = {"createList"}, dependsOnMethods = {"createItemList"})
524 public void createContactList(String testName) throws Exception {
525 // Add contacts to the initially-created, known item record.
526 for (int j = 0; j < nItemsToCreateInList; j++) {
527 createContact(testName);
531 // ---------------------------------------------------------------
532 // CRUD tests : READ tests
533 // ---------------------------------------------------------------
536 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
539 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
540 groups = {"read"}, dependsOnGroups = {"create"})
541 public void read(String testName) throws Exception {
542 readInternal(testName, knownResourceId, null);
548 * @param testName the test name
549 * @throws Exception the exception
551 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
552 groups = {"read"}, dependsOnGroups = {"create"})
553 public void readByName(String testName) throws Exception {
554 readInternal(testName, null, knownResourceShortIdentifer);
557 protected void readInternal(String testName, String CSID, String shortId) {
559 if (logger.isDebugEnabled()) {
560 logger.debug(testBanner(testName, CLASS_NAME));
565 // Submit the request to the service and store the response.
566 OrgAuthorityClient client = new OrgAuthorityClient();
567 ClientResponse<String> res = null;
569 res = client.read(CSID);
570 } else if(shortId!=null) {
571 res = client.readByName(shortId);
573 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
576 int statusCode = res.getStatus();
578 // Check the status code of the response: does it match
579 // the expected response(s)?
580 if(logger.isDebugEnabled()){
581 logger.debug(testName + ": status = " + statusCode);
583 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
584 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
585 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
586 //FIXME: remove the following try catch once Aron fixes signatures
588 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
589 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
590 new OrgAuthorityClient().getCommonPartName(), OrgauthoritiesCommon.class);
591 Assert.assertNotNull(orgAuthority);
592 } catch (Exception e) {
593 throw new RuntimeException(e);
596 res.releaseConnection();
603 * @param testName the test name
604 * @throws Exception the exception
606 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
607 groups = {"readItem"}, dependsOnGroups = {"read"})
608 public void readItem(String testName) throws Exception {
609 readItemInternal(testName, knownResourceId, null, knownItemResourceId, null);
613 * Read item in Named Auth.
615 * TODO Enable this if we really need this - it is a funky case, where we would have
616 * the shortId of the item, but the CSID of the parent authority!? Unlikely.
618 * @param testName the test name
619 * @throws Exception the exception
620 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
621 groups = {"readItem"}, dependsOnGroups = {"read"})
622 public void readItemInNamedAuth(String testName) throws Exception {
623 readItemInternal(testName, null, knownResourceShortIdentifer, knownItemResourceId, null);
630 * @param testName the test name
631 * @throws Exception the exception
633 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
634 groups = {"readItem"}, dependsOnGroups = {"read"})
635 public void readNamedItem(String testName) throws Exception {
636 readItemInternal(testName, knownResourceId, null, null, knownItemResourceShortIdentifer);
640 * Read Named item in Named Auth.
642 * @param testName the test name
643 * @throws Exception the exception
645 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
646 groups = {"readItem"}, dependsOnGroups = {"read"})
647 public void readNamedItemInNamedAuth(String testName) throws Exception {
648 readItemInternal(testName, null, knownResourceShortIdentifer, null, knownItemResourceShortIdentifer);
651 protected void readItemInternal(String testName,
652 String authCSID, String authShortId, String itemCSID, String itemShortId)
655 if (logger.isDebugEnabled()) {
656 logger.debug(testBanner(testName, CLASS_NAME));
661 // Submit the request to the service and store the response.
662 OrgAuthorityClient client = new OrgAuthorityClient();
663 ClientResponse<String> res = null;
666 res = client.readItem(authCSID, itemCSID);
667 } else if(itemShortId!=null) {
668 res = client.readNamedItem(authCSID, itemShortId);
670 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
672 } else if(authShortId!=null) {
674 res = client.readItemInNamedAuthority(authShortId, itemCSID);
675 } else if(itemShortId!=null) {
676 res = client.readNamedItemInNamedAuthority(authShortId, itemShortId);
678 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
681 Assert.fail("readInternal: Internal error. One of authCSID or authShortId must be non-null");
684 int statusCode = res.getStatus();
686 // Check the status code of the response: does it match
687 // the expected response(s)?
688 if(logger.isDebugEnabled()){
689 logger.debug(testName + ": status = " + statusCode);
691 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
692 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
693 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
695 // Check whether we've received a organization.
696 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
697 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
698 client.getItemCommonPartName(), OrganizationsCommon.class);
699 Assert.assertNotNull(organization);
700 boolean showFull = true;
701 if(showFull && logger.isDebugEnabled()){
702 logger.debug(testName + ": returned payload:");
703 logger.debug(objectAsXmlString(organization, OrganizationsCommon.class));
706 // Check that the organization item is within the expected OrgAuthority.
707 Assert.assertEquals(organization.getInAuthority(), knownResourceId);
709 // Verify the number and contents of values in a repeatable field,
710 // as created in the instance record used for testing.
711 List<String> contactNames = organization.getContactNames().getContactName();
712 Assert.assertTrue(contactNames.size() > 0);
713 Assert.assertNotNull(contactNames.get(0));
716 res.releaseConnection();
721 * Verify item display name.
723 * @param testName the test name
724 * @throws Exception the exception
726 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
727 dependsOnMethods = {"readItem", "updateItem"})
728 public void verifyItemDisplayName(String testName) throws Exception {
730 if (logger.isDebugEnabled()) {
731 logger.debug(testBanner(testName, CLASS_NAME));
736 // Submit the request to the service and store the response.
737 OrgAuthorityClient client = new OrgAuthorityClient();
738 PoxPayloadIn input = null;
739 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
741 int statusCode = res.getStatus();
743 // Check the status code of the response: does it match
744 // the expected response(s)?
745 if(logger.isDebugEnabled()){
746 logger.debug(testName + ": status = " + statusCode);
748 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
749 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
750 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
752 // Check whether organization has expected displayName.
753 input = new PoxPayloadIn(res.getEntity());
755 res.releaseConnection();
758 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
759 client.getItemCommonPartName(), OrganizationsCommon.class);
760 Assert.assertNotNull(organization);
761 String displayName = organization.getDisplayName();
762 // Make sure displayName matches computed form
763 String expectedDisplayName =
764 OrgAuthorityClientUtils.prepareDefaultDisplayName(
765 TEST_ORG_SHORTNAME, TEST_ORG_FOUNDING_PLACE);
766 Assert.assertNotNull(displayName, expectedDisplayName);
768 // Update the shortName and verify the computed name is updated.
769 organization.setCsid(null);
770 organization.setDisplayNameComputed(true);
772 MainBodyGroupList mainBodyList = organization.getMainBodyGroupList();
773 List<MainBodyGroup> mainBodyGroups = mainBodyList.getMainBodyGroup();
774 MainBodyGroup mainBodyGroup = new MainBodyGroup();
775 String updatedShortName = "updated-" + TEST_ORG_SHORTNAME;
776 mainBodyGroup.setShortName(updatedShortName);
777 mainBodyGroups.add(mainBodyGroup);
778 organization.setMainBodyGroupList(mainBodyList);
780 expectedDisplayName =
781 OrgAuthorityClientUtils.prepareDefaultDisplayName(
782 updatedShortName, TEST_ORG_FOUNDING_PLACE);
784 // Submit the updated resource to the service and store the response.
785 PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
786 PayloadOutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
787 commonPart.setLabel(client.getItemCommonPartName());
788 res = client.updateItem(knownResourceId, knownItemResourceId, output);
790 int statusCode = res.getStatus();
792 // Check the status code of the response: does it match the expected response(s)?
793 if(logger.isDebugEnabled()){
794 logger.debug("updateItem: status = " + statusCode);
796 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
797 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
798 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
800 // Retrieve the updated resource and verify that its contents exist.
801 input = new PoxPayloadIn(res.getEntity());
803 res.releaseConnection();
806 OrganizationsCommon updatedOrganization =
807 (OrganizationsCommon) extractPart(input,
808 client.getItemCommonPartName(), OrganizationsCommon.class);
809 Assert.assertNotNull(updatedOrganization);
811 // Verify that the updated resource received the correct data.
812 mainBodyList = organization.getMainBodyGroupList();
813 Assert.assertNotNull(mainBodyList);
814 Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0);
815 Assert.assertEquals(updatedOrganization.getMainBodyGroupList().getMainBodyGroup().get(0).getShortName(),
816 updatedShortName, "Updated ShortName in Organization did not match submitted data.");
818 // Verify that the updated resource computes the right displayName.
819 Assert.assertEquals(updatedOrganization.getDisplayName(), expectedDisplayName,
820 "Updated ShortName in Organization not reflected in computed DisplayName.");
822 // Now Update the displayName, not computed and verify the computed name is overriden.
823 organization.setDisplayNameComputed(false);
824 expectedDisplayName = "TestName";
825 organization.setDisplayName(expectedDisplayName);
827 // Submit the updated resource to the service and store the response.
828 output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
829 commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
830 commonPart.setLabel(client.getItemCommonPartName());
831 res = client.updateItem(knownResourceId, knownItemResourceId, output);
833 int statusCode = res.getStatus();
835 // Check the status code of the response: does it match the expected response(s)?
836 if(logger.isDebugEnabled()){
837 logger.debug("updateItem: status = " + statusCode);
839 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
840 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
841 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
843 // Retrieve the updated resource and verify that its contents exist.
844 input = new PoxPayloadIn(res.getEntity());
846 res.releaseConnection();
849 updatedOrganization =
850 (OrganizationsCommon) extractPart(input,
851 client.getItemCommonPartName(), OrganizationsCommon.class);
852 Assert.assertNotNull(updatedOrganization);
854 // Verify that the updated resource received the correct data.
855 Assert.assertEquals(updatedOrganization.isDisplayNameComputed(), false,
856 "Updated displayNameComputed in Organization did not match submitted data.");
857 // Verify that the updated resource computes the right displayName.
858 Assert.assertEquals(updatedOrganization.getDisplayName(),
860 "Updated DisplayName (not computed) in Organization not stored.");
864 * Verify illegal item display name.
866 * @param testName the test name
867 * @throws Exception the exception
869 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
870 dependsOnMethods = {"verifyItemDisplayName"})
871 public void verifyIllegalItemDisplayName(String testName) throws Exception {
873 if (logger.isDebugEnabled()) {
874 logger.debug(testBanner(testName, CLASS_NAME));
877 testSetup(STATUS_BAD_REQUEST, ServiceRequestType.UPDATE);
878 // setupUpdateWithWrongXmlSchema(testName, logger);
880 // Submit the request to the service and store the response.
881 OrgAuthorityClient client = new OrgAuthorityClient();
882 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
884 int statusCode = res.getStatus();
886 // Check the status code of the response: does it match
887 // the expected response(s)?
888 if(logger.isDebugEnabled()){
889 logger.debug(testName + ": status = " + statusCode);
891 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
892 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
893 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
895 // Check whether organization has expected displayName.
896 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
897 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
898 client.getItemCommonPartName(), OrganizationsCommon.class);
899 Assert.assertNotNull(organization);
900 // Try to Update with computed false and no displayName
901 organization.setDisplayNameComputed(false);
902 organization.setDisplayName(null);
904 // Submit the updated resource to the service and store the response.
905 PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
906 PayloadOutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
907 commonPart.setLabel(client.getItemCommonPartName());
908 res.releaseConnection();
909 res = client.updateItem(knownResourceId, knownItemResourceId, output);
910 statusCode = res.getStatus();
912 // Check the status code of the response: does it match the expected response(s)?
913 if(logger.isDebugEnabled()){
914 logger.debug("updateItem: status = " + statusCode);
916 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
917 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
918 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
920 res.releaseConnection();
927 * @param testName the test name
928 * @throws Exception the exception
930 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
931 groups = {"readItem"}, dependsOnMethods = {"readItem"})
932 public void readContact(String testName) throws Exception {
934 if (logger.isDebugEnabled()) {
935 logger.debug(testBanner(testName, CLASS_NAME));
940 // Submit the request to the service and store the response.
941 OrgAuthorityClient client = new OrgAuthorityClient();
942 ClientResponse<String> res =
943 client.readContact(knownResourceId, knownItemResourceId,
944 knownContactResourceId);
946 int statusCode = res.getStatus();
948 // Check the status code of the response: does it match
949 // the expected response(s)?
950 if(logger.isDebugEnabled()){
951 logger.debug(testName + ": status = " + statusCode);
953 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
954 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
955 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
957 // Check whether we've received a contact.
958 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
959 ContactsCommon contact = (ContactsCommon) extractPart(input,
960 new ContactClient().getCommonPartName(), ContactsCommon.class);
961 Assert.assertNotNull(contact);
962 boolean showFull = true;
963 if(showFull && logger.isDebugEnabled()){
964 logger.debug(testName + ": returned payload:");
965 logger.debug(objectAsXmlString(contact, ContactsCommon.class));
967 Assert.assertEquals(contact.getInAuthority(), knownResourceId);
968 Assert.assertEquals(contact.getInItem(), knownItemResourceId);
970 res.releaseConnection();
976 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
979 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
980 groups = {"read"}, dependsOnMethods = {"read"})
981 public void readNonExistent(String testName) {
983 if (logger.isDebugEnabled()) {
984 logger.debug(testBanner(testName, CLASS_NAME));
987 setupReadNonExistent();
989 // Submit the request to the service and store the response.
990 OrgAuthorityClient client = new OrgAuthorityClient();
991 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
993 int statusCode = res.getStatus();
995 // Check the status code of the response: does it match
996 // the expected response(s)?
997 if(logger.isDebugEnabled()){
998 logger.debug(testName + ": status = " + statusCode);
1000 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1001 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1002 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1004 res.releaseConnection();
1009 * Read item non existent.
1011 * @param testName the test name
1013 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1014 groups = {"readItem"}, dependsOnMethods = {"readItem"})
1015 public void readItemNonExistent(String testName) {
1017 if (logger.isDebugEnabled()) {
1018 logger.debug(testBanner(testName, CLASS_NAME));
1021 setupReadNonExistent();
1023 // Submit the request to the service and store the response.
1024 OrgAuthorityClient client = new OrgAuthorityClient();
1025 ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
1027 int statusCode = res.getStatus();
1029 // Check the status code of the response: does it match
1030 // the expected response(s)?
1031 if(logger.isDebugEnabled()){
1032 logger.debug(testName + ": status = " + statusCode);
1034 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1035 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1036 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1038 res.releaseConnection();
1043 * Read contact non existent.
1045 * @param testName the test name
1047 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1048 groups = {"readItem"}, dependsOnMethods = {"readContact"})
1049 public void readContactNonExistent(String testName) {
1051 if (logger.isDebugEnabled()) {
1052 logger.debug(testBanner(testName, CLASS_NAME));
1055 setupReadNonExistent();
1057 // Submit the request to the service and store the response.
1058 OrgAuthorityClient client = new OrgAuthorityClient();
1059 ClientResponse<String> res =
1060 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1062 int statusCode = res.getStatus();
1064 // Check the status code of the response: does it match
1065 // the expected response(s)?
1066 if(logger.isDebugEnabled()){
1067 logger.debug(testName + ": status = " + statusCode);
1069 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1070 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1071 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1073 res.releaseConnection();
1077 // ---------------------------------------------------------------
1078 // CRUD tests : READ_LIST tests
1079 // ---------------------------------------------------------------
1083 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
1086 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1087 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
1088 public void readList(String testName) throws Exception {
1090 if (logger.isDebugEnabled()) {
1091 logger.debug(testBanner(testName, CLASS_NAME));
1096 // Submit the request to the service and store the response.
1097 OrgAuthorityClient client = new OrgAuthorityClient();
1098 ClientResponse<OrgauthoritiesCommonList> res = client.readList();
1100 OrgauthoritiesCommonList list = res.getEntity();
1101 int statusCode = res.getStatus();
1103 // Check the status code of the response: does it match
1104 // the expected response(s)?
1105 if(logger.isDebugEnabled()){
1106 logger.debug(testName + ": status = " + statusCode);
1108 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1109 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1110 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1112 // Optionally output additional data about list members for debugging.
1113 boolean iterateThroughList = false;
1114 if (iterateThroughList && logger.isDebugEnabled()) {
1115 List<OrgauthoritiesCommonList.OrgauthorityListItem> items =
1116 list.getOrgauthorityListItem();
1118 for (OrgauthoritiesCommonList.OrgauthorityListItem item : items) {
1119 String csid = item.getCsid();
1120 logger.debug(testName + ": list-item[" + i + "] csid=" +
1122 logger.debug(testName + ": list-item[" + i + "] displayName=" +
1123 item.getDisplayName());
1124 logger.debug(testName + ": list-item[" + i + "] URI=" +
1126 readItemList(csid, null);
1131 res.releaseConnection();
1138 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
1139 public void readItemList() {
1140 readItemList(knownResourceId, null);
1144 * Read item list by authority name.
1146 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1147 public void readItemListByAuthorityName() {
1148 readItemList(null, knownResourceShortIdentifer);
1154 * @param vcsid the vcsid
1155 * @param name the name
1157 private void readItemList(String vcsid, String name) {
1159 final String testName = "readItemList";
1161 if (logger.isDebugEnabled()) {
1162 logger.debug(testBanner(testName, CLASS_NAME));
1167 // Submit the request to the service and store the response.
1168 OrgAuthorityClient client = new OrgAuthorityClient();
1169 ClientResponse<OrganizationsCommonList> res = null;
1171 res = client.readItemList(vcsid, null, null);
1172 } else if(name!= null) {
1173 res = client.readItemListForNamedAuthority(name, null, null);
1175 Assert.fail("readItemList passed null csid and name!");
1178 OrganizationsCommonList list = res.getEntity();
1179 int statusCode = res.getStatus();
1181 // Check the status code of the response: does it match
1182 // the expected response(s)?
1183 if(logger.isDebugEnabled()){
1184 logger.debug(testName + ": status = " + statusCode);
1186 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1187 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1188 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1190 List<OrganizationsCommonList.OrganizationListItem> items =
1191 list.getOrganizationListItem();
1192 int nItemsReturned = items.size();
1193 // There will be one item created, associated with a
1194 // known parent resource, by the createItem test.
1196 // In addition, there will be 'nItemsToCreateInList'
1197 // additional items created by the createItemList test,
1198 // all associated with the same parent resource.
1199 int nExpectedItems = nItemsToCreateInList + 1;
1200 if(logger.isDebugEnabled()){
1201 logger.debug(testName + ": Expected "
1202 + nExpectedItems +" items; got: "+nItemsReturned);
1204 Assert.assertEquals(nItemsReturned, nExpectedItems);
1207 for (OrganizationsCommonList.OrganizationListItem item : items) {
1208 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
1209 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
1210 // Optionally output additional data about list members for debugging.
1211 boolean showDetails = true;
1212 if (showDetails && logger.isDebugEnabled()) {
1213 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1215 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
1217 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
1218 item.getDisplayName());
1219 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1225 res.releaseConnection();
1230 * Read contact list.
1232 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1233 public void readContactList() {
1234 readContactList(knownResourceId, knownItemResourceId);
1238 * Read contact list.
1240 * @param parentcsid the parentcsid
1241 * @param itemcsid the itemcsid
1243 private void readContactList(String parentcsid, String itemcsid) {
1244 final String testName = "readContactList";
1246 if (logger.isDebugEnabled()) {
1247 logger.debug(testBanner(testName, CLASS_NAME));
1252 // Submit the request to the service and store the response.
1253 OrgAuthorityClient client = new OrgAuthorityClient();
1254 ContactsCommonList list = null;
1255 ClientResponse<ContactsCommonList> res =
1256 client.readContactList(parentcsid, itemcsid);
1258 list = res.getEntity();
1259 int statusCode = res.getStatus();
1261 // Check the status code of the response: does it match
1262 // the expected response(s)?
1263 if(logger.isDebugEnabled()){
1264 logger.debug(testName + ": status = " + statusCode);
1266 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1267 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1268 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1270 List<ContactsCommonList.ContactListItem> listitems =
1271 list.getContactListItem();
1272 int nItemsReturned = listitems.size();
1273 // There will be one item created, associated with a
1274 // known parent resource, by the createItem test.
1276 // In addition, there will be 'nItemsToCreateInList'
1277 // additional items created by the createItemList test,
1278 // all associated with the same parent resource.
1279 int nExpectedItems = nItemsToCreateInList + 1;
1280 if(logger.isDebugEnabled()){
1281 logger.debug(testName + ": Expected "
1282 + nExpectedItems +" items; got: "+nItemsReturned);
1284 Assert.assertEquals(nItemsReturned, nExpectedItems);
1287 for (ContactsCommonList.ContactListItem listitem : listitems) {
1288 // Optionally output additional data about list members for debugging.
1289 boolean showDetails = false;
1290 if (showDetails && logger.isDebugEnabled()) {
1291 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1292 listitem.getCsid());
1293 logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" +
1294 listitem.getAddressPlace());
1295 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1301 res.releaseConnection();
1308 // ---------------------------------------------------------------
1309 // CRUD tests : UPDATE tests
1310 // ---------------------------------------------------------------
1313 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
1316 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1317 groups = {"update"}, dependsOnGroups = {"read", "readList"})
1318 public void update(String testName) throws Exception {
1320 if (logger.isDebugEnabled()) {
1321 logger.debug(testBanner(testName, CLASS_NAME));
1326 // Retrieve the contents of a resource to update.
1327 OrgAuthorityClient client = new OrgAuthorityClient();
1328 ClientResponse<String> res =
1329 client.read(knownResourceId);
1331 if(logger.isDebugEnabled()){
1332 logger.debug(testName + ": read status = " + res.getStatus());
1334 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1336 if(logger.isDebugEnabled()){
1337 logger.debug("got OrgAuthority to update with ID: " + knownResourceId);
1339 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
1340 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
1341 client.getCommonPartName(), OrgauthoritiesCommon.class);
1342 Assert.assertNotNull(orgAuthority);
1344 // Update the contents of this resource.
1345 orgAuthority.setDisplayName("updated-" + orgAuthority.getDisplayName());
1346 orgAuthority.setVocabType("updated-" + orgAuthority.getVocabType());
1347 if(logger.isDebugEnabled()){
1348 logger.debug("to be updated OrgAuthority");
1349 logger.debug(objectAsXmlString(orgAuthority, OrgauthoritiesCommon.class));
1352 // Submit the updated resource to the service and store the response.
1353 PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_PAYLOAD_NAME);
1354 PayloadOutputPart commonPart = output.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE);
1355 commonPart.setLabel(client.getCommonPartName());
1356 res.releaseConnection();
1357 res = client.update(knownResourceId, output);
1358 int statusCode = res.getStatus();
1360 // Check the status code of the response: does it match the expected response(s)?
1361 if(logger.isDebugEnabled()){
1362 logger.debug(testName + ": status = " + statusCode);
1364 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1365 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1366 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1368 // Retrieve the updated resource and verify that its contents exist.
1369 input = new PoxPayloadIn(res.getEntity());
1370 OrgauthoritiesCommon updatedOrgAuthority =
1371 (OrgauthoritiesCommon) extractPart(input,
1372 client.getCommonPartName(), OrgauthoritiesCommon.class);
1373 Assert.assertNotNull(updatedOrgAuthority);
1375 // Verify that the updated resource received the correct data.
1376 Assert.assertEquals(updatedOrgAuthority.getDisplayName(),
1377 orgAuthority.getDisplayName(),
1378 "Data in updated object did not match submitted data.");
1380 res.releaseConnection();
1387 * @param testName the test name
1388 * @throws Exception the exception
1390 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1391 groups = {"update"}, dependsOnMethods = {"update"})
1392 public void updateItem(String testName) throws Exception {
1394 if (logger.isDebugEnabled()) {
1395 logger.debug(testBanner(testName, CLASS_NAME));
1400 // Retrieve the contents of a resource to update.
1401 OrgAuthorityClient client = new OrgAuthorityClient();
1402 ClientResponse<String> res =
1403 client.readItem(knownResourceId, knownItemResourceId);
1405 if(logger.isDebugEnabled()){
1406 logger.debug(testName + ": read status = " + res.getStatus());
1408 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1410 if(logger.isDebugEnabled()){
1411 logger.debug("got Organization to update with ID: " +
1412 knownItemResourceId +
1413 " in OrgAuthority: " + knownResourceId );
1415 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
1416 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
1417 client.getItemCommonPartName(), OrganizationsCommon.class);
1418 Assert.assertNotNull(organization);
1420 // Update the contents of this resource.
1421 organization.setCsid(null);
1423 MainBodyGroupList mainBodyList = organization.getMainBodyGroupList();
1424 Assert.assertNotNull(mainBodyList);
1425 List<MainBodyGroup> mainBodyGroups = mainBodyList.getMainBodyGroup();
1426 Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0);
1427 String updatedShortName = "updated-" + mainBodyGroups.get(0).getShortName();
1428 mainBodyGroups.get(0).setShortName(updatedShortName);
1430 if(logger.isDebugEnabled()){
1431 logger.debug("to be updated Organization");
1432 logger.debug(objectAsXmlString(organization,
1433 OrganizationsCommon.class));
1436 // Submit the updated resource to the service and store the response.
1437 PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1438 PayloadOutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
1439 commonPart.setLabel(client.getItemCommonPartName());
1440 res.releaseConnection();
1441 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1442 int statusCode = res.getStatus();
1444 // Check the status code of the response: does it match the expected response(s)?
1445 if(logger.isDebugEnabled()){
1446 logger.debug(testName + ": status = " + statusCode);
1448 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1449 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1450 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1452 // Retrieve the updated resource and verify that its contents exist.
1453 input = new PoxPayloadIn(res.getEntity());
1454 OrganizationsCommon updatedOrganization =
1455 (OrganizationsCommon) extractPart(input,
1456 client.getItemCommonPartName(), OrganizationsCommon.class);
1457 Assert.assertNotNull(updatedOrganization);
1459 // Verify that the updated resource received the correct data.
1460 mainBodyList = organization.getMainBodyGroupList();
1461 Assert.assertNotNull(mainBodyList);
1462 Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0);
1463 Assert.assertEquals(updatedOrganization.getMainBodyGroupList().getMainBodyGroup().get(0).getShortName(),
1464 updatedShortName, "Data in updated Organization did not match submitted data.");
1466 res.releaseConnection();
1473 * @param testName the test name
1474 * @throws Exception the exception
1476 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1477 groups = {"update"}, dependsOnMethods = {"updateItem"})
1478 public void updateContact(String testName) throws Exception {
1480 if (logger.isDebugEnabled()) {
1481 logger.debug(testBanner(testName, CLASS_NAME));
1486 // Retrieve the contents of a resource to update.
1487 OrgAuthorityClient client = new OrgAuthorityClient();
1488 ClientResponse<String> res =
1489 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1491 if(logger.isDebugEnabled()){
1492 logger.debug(testName + ": read status = " + res.getStatus());
1494 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1496 if(logger.isDebugEnabled()){
1497 logger.debug("got Contact to update with ID: " +
1498 knownContactResourceId +
1499 " in item: " + knownItemResourceId +
1500 " in parent: " + knownResourceId );
1502 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
1503 ContactsCommon contact = (ContactsCommon) extractPart(input,
1504 new ContactClient().getCommonPartName(), ContactsCommon.class);
1505 Assert.assertNotNull(contact);
1507 // Update the contents of this resource.
1508 contact.setAddressPlace("updated-" + contact.getAddressPlace());
1509 if(logger.isDebugEnabled()){
1510 logger.debug("to be updated Contact");
1511 logger.debug(objectAsXmlString(contact,
1512 ContactsCommon.class));
1515 // Submit the updated resource to the service and store the response.
1516 PoxPayloadOut output = new PoxPayloadOut(ContactClient.SERVICE_PAYLOAD_NAME);
1517 PayloadOutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1518 commonPart.setLabel(new ContactClient().getCommonPartName());
1519 res.releaseConnection();
1520 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1521 int statusCode = res.getStatus();
1523 // Check the status code of the response: does it match the expected response(s)?
1524 if(logger.isDebugEnabled()){
1525 logger.debug(testName + ": status = " + statusCode);
1527 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1528 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1529 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1531 // Retrieve the updated resource and verify that its contents exist.
1532 input = new PoxPayloadIn(res.getEntity());
1533 ContactsCommon updatedContact =
1534 (ContactsCommon) extractPart(input,
1535 new ContactClient().getCommonPartName(), ContactsCommon.class);
1536 Assert.assertNotNull(updatedContact);
1538 // Verify that the updated resource received the correct data.
1539 Assert.assertEquals(updatedContact.getAddressPlace(),
1540 contact.getAddressPlace(),
1541 "Data in updated Contact did not match submitted data.");
1543 res.releaseConnection();
1548 // Placeholders until the three tests below can be uncommented.
1549 // See Issue CSPACE-401.
1551 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1554 public void updateWithEmptyEntityBody(String testName) throws Exception {
1555 //Should this really be empty?
1559 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1562 public void updateWithMalformedXml(String testName) throws Exception {
1563 //Should this really be empty?
1567 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1570 public void updateWithWrongXmlSchema(String testName) throws Exception {
1571 //Should this really be empty?
1576 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1577 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1578 public void updateWithEmptyEntityBody(String testName) throws Exception {
1580 if (logger.isDebugEnabled()) {
1581 logger.debug(testBanner(testName, CLASS_NAME));
1584 setupUpdateWithEmptyEntityBody();
1586 // Submit the request to the service and store the response.
1587 String method = REQUEST_TYPE.httpMethodName();
1588 String url = getResourceURL(knownResourceId);
1589 String mediaType = MediaType.APPLICATION_XML;
1590 final String entity = "";
1591 int statusCode = submitRequest(method, url, mediaType, entity);
1593 // Check the status code of the response: does it match
1594 // the expected response(s)?
1595 if(logger.isDebugEnabled()){
1596 logger.debug(testName + ": url=" + url +
1597 " status=" + statusCode);
1599 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1600 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1601 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1605 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1606 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1607 public void updateWithMalformedXml(String testName) throws Exception {
1609 if (logger.isDebugEnabled()) {
1610 logger.debug(testBanner(testName, CLASS_NAME));
1613 setupUpdateWithMalformedXml();
1615 // Submit the request to the service and store the response.
1616 String method = REQUEST_TYPE.httpMethodName();
1617 String url = getResourceURL(knownResourceId);
1618 String mediaType = MediaType.APPLICATION_XML;
1619 final String entity = MALFORMED_XML_DATA;
1620 int statusCode = submitRequest(method, url, mediaType, entity);
1622 // Check the status code of the response: does it match
1623 // the expected response(s)?
1624 if(logger.isDebugEnabled()){
1625 logger.debug(testName + ": url=" + url +
1626 " status=" + statusCode);
1628 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1629 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1630 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1634 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1635 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1636 public void updateWithWrongXmlSchema(String testName) throws Exception {
1639 setupUpdateWithWrongXmlSchema(testName, logger);
1641 // Submit the request to the service and store the response.
1642 String method = REQUEST_TYPE.httpMethodName();
1643 String url = getResourceURL(knownResourceId);
1644 String mediaType = MediaType.APPLICATION_XML;
1645 final String entity = WRONG_XML_SCHEMA_DATA;
1646 int statusCode = submitRequest(method, url, mediaType, entity);
1648 // Check the status code of the response: does it match
1649 // the expected response(s)?
1650 if(logger.isDebugEnabled()){
1651 logger.debug("updateWithWrongXmlSchema: url=" + url +
1652 " status=" + statusCode);
1654 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1655 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1656 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1661 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1664 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1665 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1666 public void updateNonExistent(String testName) throws Exception {
1668 if (logger.isDebugEnabled()) {
1669 logger.debug(testBanner(testName, CLASS_NAME));
1672 setupUpdateNonExistent();
1674 // Submit the request to the service and store the response.
1675 // Note: The ID used in this 'create' call may be arbitrary.
1676 // The only relevant ID may be the one used in update(), below.
1677 OrgAuthorityClient client = new OrgAuthorityClient();
1678 PoxPayloadOut multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance(
1679 NON_EXISTENT_ID, NON_EXISTENT_ID,
1680 new OrgAuthorityClient().getCommonPartName());
1681 ClientResponse<String> res =
1682 client.update(NON_EXISTENT_ID, multipart);
1684 int statusCode = res.getStatus();
1686 // Check the status code of the response: does it match
1687 // the expected response(s)?
1688 if(logger.isDebugEnabled()){
1689 logger.debug(testName + ": status = " + statusCode);
1691 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1692 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1693 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1695 res.releaseConnection();
1700 * Update non existent item.
1702 * @param testName the test name
1703 * @throws Exception the exception
1705 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1706 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1707 public void updateNonExistentItem(String testName) throws Exception {
1709 if (logger.isDebugEnabled()) {
1710 logger.debug(testBanner(testName, CLASS_NAME));
1713 setupUpdateNonExistent();
1715 // Submit the request to the service and store the response.
1716 // Note: The ID(s) used when creating the request payload may be arbitrary.
1717 // The only relevant ID may be the one used in update(), below.
1718 OrgAuthorityClient client = new OrgAuthorityClient();
1719 Map<String, String> nonexOrgMap = new HashMap<String,String>();
1720 nonexOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, "nonExistent");
1721 nonexOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Non-existent");
1722 PoxPayloadOut multipart =
1723 OrgAuthorityClientUtils.createOrganizationInstance(
1724 knownResourceRefName,
1725 nonexOrgMap, client.getItemCommonPartName() );
1726 ClientResponse<String> res =
1727 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1729 int statusCode = res.getStatus();
1731 // Check the status code of the response: does it match
1732 // the expected response(s)?
1733 if(logger.isDebugEnabled()){
1734 logger.debug(testName + ": status = " + statusCode);
1736 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1737 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1738 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1740 res.releaseConnection();
1745 * Update non existent contact.
1747 * @param testName the test name
1748 * @throws Exception the exception
1750 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1751 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1752 public void updateNonExistentContact(String testName) throws Exception {
1753 // Currently a no-op test
1756 // ---------------------------------------------------------------
1757 // CRUD tests : DELETE tests
1758 // ---------------------------------------------------------------
1761 // Note: delete sub-resources in ascending hierarchical order,
1762 // before deleting their parents.
1767 * @param testName the test name
1768 * @throws Exception the exception
1770 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1771 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1772 public void deleteContact(String testName) throws Exception {
1774 if (logger.isDebugEnabled()) {
1775 logger.debug(testBanner(testName, CLASS_NAME));
1780 if(logger.isDebugEnabled()){
1781 logger.debug("parentcsid =" + knownResourceId +
1782 " itemcsid = " + knownItemResourceId +
1783 " csid = " + knownContactResourceId);
1786 // Submit the request to the service and store the response.
1787 OrgAuthorityClient client = new OrgAuthorityClient();
1788 ClientResponse<Response> res =
1789 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1791 int statusCode = res.getStatus();
1793 // Check the status code of the response: does it match
1794 // the expected response(s)?
1795 if(logger.isDebugEnabled()){
1796 logger.debug(testName + ": status = " + statusCode);
1798 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1799 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1800 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1802 res.releaseConnection();
1809 * @param testName the test name
1810 * @throws Exception the exception
1812 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1813 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1814 public void deleteItem(String testName) throws Exception {
1816 if (logger.isDebugEnabled()) {
1817 logger.debug(testBanner(testName, CLASS_NAME));
1822 if(logger.isDebugEnabled()){
1823 logger.debug("parentcsid =" + knownResourceId +
1824 " itemcsid = " + knownItemResourceId);
1827 // Submit the request to the service and store the response.
1828 OrgAuthorityClient client = new OrgAuthorityClient();
1829 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1831 int statusCode = res.getStatus();
1833 // Check the status code of the response: does it match
1834 // the expected response(s)?
1835 if(logger.isDebugEnabled()){
1836 logger.debug(testName + ": status = " + statusCode);
1838 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1839 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1840 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1842 res.releaseConnection();
1847 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1850 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1851 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1852 public void delete(String testName) throws Exception {
1854 if (logger.isDebugEnabled()) {
1855 logger.debug(testBanner(testName, CLASS_NAME));
1860 if(logger.isDebugEnabled()){
1861 logger.debug("parentcsid =" + knownResourceId);
1864 // Submit the request to the service and store the response.
1865 OrgAuthorityClient client = new OrgAuthorityClient();
1866 ClientResponse<Response> res = client.delete(knownResourceId);
1868 int statusCode = res.getStatus();
1870 // Check the status code of the response: does it match
1871 // the expected response(s)?
1872 if(logger.isDebugEnabled()){
1873 logger.debug(testName + ": status = " + statusCode);
1875 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1876 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1877 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1879 res.releaseConnection();
1885 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1888 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1889 groups = {"delete"}, dependsOnMethods = {"delete"})
1890 public void deleteNonExistent(String testName) throws Exception {
1892 if (logger.isDebugEnabled()) {
1893 logger.debug(testBanner(testName, CLASS_NAME));
1896 setupDeleteNonExistent();
1898 // Submit the request to the service and store the response.
1899 OrgAuthorityClient client = new OrgAuthorityClient();
1900 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1902 int statusCode = res.getStatus();
1904 // Check the status code of the response: does it match
1905 // the expected response(s)?
1906 if(logger.isDebugEnabled()){
1907 logger.debug(testName + ": status = " + statusCode);
1909 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1910 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1911 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1913 res.releaseConnection();
1918 * Delete non existent item.
1920 * @param testName the test name
1922 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1923 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1924 public void deleteNonExistentItem(String testName) {
1926 if (logger.isDebugEnabled()) {
1927 logger.debug(testBanner(testName, CLASS_NAME));
1930 setupDeleteNonExistent();
1932 // Submit the request to the service and store the response.
1933 OrgAuthorityClient client = new OrgAuthorityClient();
1934 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1936 int statusCode = res.getStatus();
1938 // Check the status code of the response: does it match
1939 // the expected response(s)?
1940 if(logger.isDebugEnabled()){
1941 logger.debug(testName + ": status = " + statusCode);
1943 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1944 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1945 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1947 res.releaseConnection();
1952 * Delete non existent contact.
1954 * @param testName the test name
1956 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1957 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1958 public void deleteNonExistentContact(String testName) {
1960 if (logger.isDebugEnabled()) {
1961 logger.debug(testBanner(testName, CLASS_NAME));
1964 setupDeleteNonExistent();
1966 // Submit the request to the service and store the response.
1967 OrgAuthorityClient client = new OrgAuthorityClient();
1968 ClientResponse<Response> res =
1969 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1971 int statusCode = res.getStatus();
1973 // Check the status code of the response: does it match
1974 // the expected response(s)?
1975 if(logger.isDebugEnabled()){
1976 logger.debug(testName + ": status = " + statusCode);
1978 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1979 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1980 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1982 res.releaseConnection();
1986 // ---------------------------------------------------------------
1987 // Utility tests : tests of code used in tests above
1988 // ---------------------------------------------------------------
1990 * Tests the code for manually submitting data that is used by several
1991 * of the methods above.
1993 @Test(dependsOnMethods = {"create", "read"})
1994 public void testSubmitRequest() {
1996 // Expected status code: 200 OK
1997 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1999 // Submit the request to the service and store the response.
2000 String method = ServiceRequestType.READ.httpMethodName();
2001 String url = getResourceURL(knownResourceId);
2002 int statusCode = submitRequest(method, url);
2004 // Check the status code of the response: does it match
2005 // the expected response(s)?
2006 if(logger.isDebugEnabled()){
2007 logger.debug("testSubmitRequest: url=" + url +
2008 " status=" + statusCode);
2010 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2015 * Test item submit request.
2017 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
2018 public void testItemSubmitRequest() {
2020 // Expected status code: 200 OK
2021 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2023 // Submit the request to the service and store the response.
2024 String method = ServiceRequestType.READ.httpMethodName();
2025 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
2026 int statusCode = submitRequest(method, url);
2028 // Check the status code of the response: does it match
2029 // the expected response(s)?
2030 if(logger.isDebugEnabled()){
2031 logger.debug("testItemSubmitRequest: url=" + url +
2032 " status=" + statusCode);
2034 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2039 * Test contact submit request.
2041 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
2042 public void testContactSubmitRequest() {
2044 // Expected status code: 200 OK
2045 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2047 // Submit the request to the service and store the response.
2048 String method = ServiceRequestType.READ.httpMethodName();
2049 String url = getContactResourceURL(knownResourceId,
2050 knownItemResourceId, knownContactResourceId);
2051 int statusCode = submitRequest(method, url);
2053 // Check the status code of the response: does it match
2054 // the expected response(s)?
2055 if(logger.isDebugEnabled()){
2056 logger.debug("testItemSubmitRequest: url=" + url +
2057 " status=" + statusCode);
2059 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2064 // ---------------------------------------------------------------
2065 // Cleanup of resources created during testing
2066 // ---------------------------------------------------------------
2069 * Deletes all resources created by tests, after all tests have been run.
2071 * This cleanup method will always be run, even if one or more tests fail.
2072 * For this reason, it attempts to remove all resources created
2073 * at any point during testing, even if some of those resources
2074 * may be expected to be deleted by certain tests.
2077 @AfterClass(alwaysRun=true)
2079 public void cleanUp() {
2080 String noTest = System.getProperty("noTestCleanup");
2081 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
2082 if (logger.isDebugEnabled()) {
2083 logger.debug("Skipping Cleanup phase ...");
2087 if (logger.isDebugEnabled()) {
2088 logger.debug("Cleaning up temporary resources created for testing ...");
2091 String parentResourceId;
2092 String itemResourceId;
2093 String contactResourceId;
2094 // Clean up contact resources.
2095 parentResourceId = knownResourceId;
2096 OrgAuthorityClient client = new OrgAuthorityClient();
2097 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
2098 contactResourceId = entry.getKey();
2099 itemResourceId = entry.getValue();
2100 // Note: Any non-success responses from the delete operation
2101 // below are ignored and not reported.
2102 ClientResponse<Response> res =
2103 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
2104 res.releaseConnection();
2106 // Clean up item resources.
2107 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
2108 itemResourceId = entry.getKey();
2109 parentResourceId = entry.getValue();
2110 // Note: Any non-success responses from the delete operation
2111 // below are ignored and not reported.
2112 ClientResponse<Response> res =
2113 client.deleteItem(parentResourceId, itemResourceId);
2114 res.releaseConnection();
2116 // Clean up parent resources.
2121 // ---------------------------------------------------------------
2122 // Utility methods used by tests above
2123 // ---------------------------------------------------------------
2125 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
2128 * Gets the item service path component.
2130 * @return the item service path component
2132 public String getItemServicePathComponent() {
2133 return AuthorityClient.ITEMS;
2137 * Gets the contact service path component.
2139 * @return the contact service path component
2141 public String getContactServicePathComponent() {
2142 return ContactClient.SERVICE_PATH_COMPONENT;
2146 * Returns the root URL for the item service.
2148 * This URL consists of a base URL for all services, followed by
2149 * a path component for the owning parent, followed by the
2150 * path component for the items.
2152 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2153 * parent authority resource of the relevant item resource.
2155 * @return The root URL for the item service.
2157 protected String getItemServiceRootURL(String parentResourceIdentifier) {
2158 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
2162 * Returns the URL of a specific item resource managed by a service, and
2163 * designated by an identifier (such as a universally unique ID, or UUID).
2165 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2166 * parent authority resource of the relevant item resource.
2168 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2171 * @return The URL of a specific item resource managed by a service.
2173 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
2174 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
2179 * Returns the root URL for the contact service.
2181 * This URL consists of a base URL for all services, followed by
2182 * a path component for the owning authority, followed by the
2183 * path component for the owning item, followed by the path component
2184 * for the contact service.
2186 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2187 * parent authority resource of the relevant item resource.
2189 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2192 * @return The root URL for the contact service.
2194 protected String getContactServiceRootURL(String parentResourceIdentifier,
2195 String itemResourceIdentifier) {
2196 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
2197 getContactServicePathComponent();
2201 * Returns the URL of a specific contact resource managed by a service, and
2202 * designated by an identifier (such as a universally unique ID, or UUID).
2204 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2205 * parent resource of the relevant item resource.
2207 * @param resourceIdentifier An identifier (such as a UUID) for an
2210 * @return The URL of a specific resource managed by a service.
2212 protected String getContactResourceURL(String parentResourceIdentifier,
2213 String itemResourceIdentifier, String contactResourceIdentifier) {
2214 return getContactServiceRootURL(parentResourceIdentifier,
2215 itemResourceIdentifier) + "/" + contactResourceIdentifier;