2 * This document is a part of the source code and related artifacts
3 * for CollectionSpace, an open source collections management system
4 * for museums and related institutions:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright (c)) 2009 Regents of the University of California
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
15 * https://source.collectionspace.org/collection-space/LICENSE.txt
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 package org.collectionspace.services.client.test;
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.List;
29 import javax.ws.rs.core.MediaType;
30 import javax.ws.rs.core.Response;
32 import org.collectionspace.services.OrganizationJAXBSchema;
33 import org.collectionspace.services.client.AuthorityClient;
34 import org.collectionspace.services.client.CollectionSpaceClient;
35 import org.collectionspace.services.client.ContactClient;
36 import org.collectionspace.services.client.ContactClientUtils;
37 import org.collectionspace.services.client.PayloadOutputPart;
38 import org.collectionspace.services.client.PoxPayloadIn;
39 import org.collectionspace.services.client.PoxPayloadOut;
40 import org.collectionspace.services.common.AbstractCommonListUtils;
41 import org.collectionspace.services.contact.AddressGroup;
42 import org.collectionspace.services.contact.AddressGroupList;
43 import org.collectionspace.services.contact.ContactsCommon;
44 import org.collectionspace.services.client.OrgAuthorityClient;
45 import org.collectionspace.services.client.OrgAuthorityClientUtils;
46 import org.collectionspace.services.jaxb.AbstractCommonList;
47 import org.collectionspace.services.organization.MainBodyGroup;
48 import org.collectionspace.services.organization.MainBodyGroupList;
49 import org.collectionspace.services.organization.OrgauthoritiesCommon;
50 import org.collectionspace.services.organization.OrganizationsCommon;
52 import org.jboss.resteasy.client.ClientResponse;
54 import org.slf4j.Logger;
55 import org.slf4j.LoggerFactory;
56 import org.testng.Assert;
57 import org.testng.annotations.AfterClass;
58 import org.testng.annotations.Test;
61 * OrgAuthorityServiceTest, carries out tests against a
62 * deployed and running OrgAuthority Service.
64 * $LastChangedRevision$
67 public class OrgAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: Test classes for Vocab, Person, Org, and Location should have a base class!
70 private final String CLASS_NAME = OrgAuthorityServiceTest.class.getName();
71 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
72 private final String REFNAME = "refName";
73 private final String DISPLAYNAME = "displayName";
76 public String getServicePathComponent() {
77 return OrgAuthorityClient.SERVICE_PATH_COMPONENT;
81 protected String getServiceName() {
82 return OrgAuthorityClient.SERVICE_NAME;
84 /** The test organization shortname. */
85 private final String TEST_ORG_SHORTNAME = "Test Org";
86 /** The test organization founding place. */
87 private final String TEST_ORG_FOUNDING_PLACE = "Anytown, USA";
88 // Hold some values for a recently created item to verify upon read.
89 private String knownResourceId = null;
90 private String knownResourceShortIdentifer = null;
91 private String knownResourceRefName = null;
92 private String knownItemResourceId = null;
93 private String knownItemResourceShortIdentifer = null;
94 /** The known contact resource id. */
95 private String knownContactResourceId = null;
96 /** The n items to create in list. */
97 private int nItemsToCreateInList = 3;
98 /** The all item resource ids created. */
99 private Map<String, String> allItemResourceIdsCreated =
100 new HashMap<String, String>();
101 /** The all contact resource ids created. */
102 private Map<String, String> allContactResourceIdsCreated =
103 new HashMap<String, String>();
105 protected void setKnownResource(String id, String shortIdentifer,
107 knownResourceId = id;
108 knownResourceShortIdentifer = shortIdentifer;
109 knownResourceRefName = refName;
112 protected void setKnownItemResource(String id, String shortIdentifer) {
113 knownItemResourceId = id;
114 knownItemResourceShortIdentifer = shortIdentifer;
118 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
121 protected CollectionSpaceClient getClientInstance() {
122 return new OrgAuthorityClient();
125 // ---------------------------------------------------------------
126 // CRUD tests : CREATE tests
127 // ---------------------------------------------------------------
130 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
133 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
135 public void create(String testName) throws Exception {
137 if (logger.isDebugEnabled()) {
138 logger.debug(testBanner(testName, CLASS_NAME));
140 // Perform setup, such as initializing the type of service request
141 // (e.g. CREATE, DELETE), its valid and expected status codes, and
142 // its associated HTTP method name (e.g. POST, DELETE).
145 // Submit the request to the service and store the response.
146 OrgAuthorityClient client = new OrgAuthorityClient();
147 String shortId = createIdentifier();
148 String displayName = "displayName-" + shortId;
149 //String baseRefName = OrgAuthorityClientUtils.createOrgAuthRefName(shortId, null);
150 PoxPayloadOut multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance(
151 displayName, shortId, client.getCommonPartName());
154 ClientResponse<Response> res = client.create(multipart);
156 int statusCode = res.getStatus();
158 // Check the status code of the response: does it match
159 // the expected response(s)?
162 // Does it fall within the set of valid status codes?
163 // Does it exactly match the expected status code?
164 if (logger.isDebugEnabled()) {
165 logger.debug(testName + ": status = " + statusCode);
167 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
168 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
169 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
171 newID = OrgAuthorityClientUtils.extractId(res);
173 res.releaseConnection();
176 // Store the ID returned from the first resource created
177 // for additional tests below.
178 if (knownResourceId == null) {
179 setKnownResource(newID, shortId, null ); //baseRefName);
180 if (logger.isDebugEnabled()) {
181 logger.debug(testName + ": knownResourceId=" + knownResourceId);
184 // Store the IDs from every resource created by tests,
185 // so they can be deleted after tests have been run.
186 allResourceIdsCreated.add(newID);
190 protected PoxPayloadOut createInstance(String identifier) {
191 OrgAuthorityClient client = new OrgAuthorityClient();
192 String displayName = "displayName-" + identifier;
193 PoxPayloadOut multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance(
194 displayName, identifier, client.getCommonPartName());
199 protected PoxPayloadOut createItemInstance(String parentCsid, String identifier) {
200 String headerLabel = new OrgAuthorityClient().getItemCommonPartName();
201 String shortId = "testOrg";
202 Map<String, String> testOrgMap = new HashMap<String, String>();
203 testOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId);
204 testOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, TEST_ORG_SHORTNAME);
205 testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "The real official test organization");
206 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "May 26, 1907");
207 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, TEST_ORG_FOUNDING_PLACE);
209 return OrgAuthorityClientUtils.createOrganizationInstance(identifier, testOrgMap, headerLabel);
215 * @param testName the test name
217 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
218 groups = {"create"}, dependsOnMethods = {"create"})
219 public void createItem(String testName) {
221 String newID = createItemInAuthority(knownResourceId, knownResourceRefName);
225 * Creates the item in authority.
227 * @param vcsid the vcsid
228 * @param authRefName the auth ref name
231 private String createItemInAuthority(String vcsid, String authRefName) {
233 final String testName = "createItemInAuthority";
234 if (logger.isDebugEnabled()) {
235 logger.debug(testName + ":...");
238 // Submit the request to the service and store the response.
239 OrgAuthorityClient client = new OrgAuthorityClient();
240 String shortId = "testOrg";
241 Map<String, String> testOrgMap = new HashMap<String, String>();
242 testOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, shortId);
243 testOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, TEST_ORG_SHORTNAME);
244 testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "The real official test organization");
245 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "May 26, 1907");
246 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, TEST_ORG_FOUNDING_PLACE);
248 Map<String, List<String>> testOrgRepeatablesMap = new HashMap<String, List<String>>();
249 List<String> testOrgContactNames = new ArrayList<String>();
250 testOrgContactNames.add("joe@example.org");
251 testOrgContactNames.add("sally@example.org");
252 testOrgRepeatablesMap.put(OrganizationJAXBSchema.CONTACT_NAMES, testOrgContactNames);
254 MainBodyGroupList mainBodyList = new MainBodyGroupList();
255 List<MainBodyGroup> mainBodyGroups = mainBodyList.getMainBodyGroup();
256 MainBodyGroup mainBodyGroup = new MainBodyGroup();
257 mainBodyGroup.setShortName(TEST_ORG_SHORTNAME);
258 mainBodyGroup.setLongName("The real official test organization");
259 mainBodyGroups.add(mainBodyGroup);
261 String newID = OrgAuthorityClientUtils.createItemInAuthority(
262 vcsid, authRefName, testOrgMap, testOrgRepeatablesMap, mainBodyList, client);
264 // Store the ID returned from the first item resource created
265 // for additional tests below.
266 if (knownItemResourceId == null) {
267 setKnownItemResource(newID, shortId);
268 if (logger.isDebugEnabled()) {
269 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
273 // Store the IDs from any item resources created
274 // by tests, along with the IDs of their parents, so these items
275 // can be deleted after all tests have been run.
276 allItemResourceIdsCreated.put(newID, vcsid);
282 * Creates the contact.
284 * @param testName the test name
286 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
287 groups = {"create"}, dependsOnMethods = {"createItem"})
288 public void createContact(String testName) {
290 String newID = createContactInItem(knownResourceId, knownItemResourceId);
294 * Creates the contact in item.
296 * @param parentcsid the parentcsid
297 * @param itemcsid the itemcsid
300 private String createContactInItem(String parentcsid, String itemcsid) {
302 final String testName = "createContactInItem";
303 if (logger.isDebugEnabled()) {
304 logger.debug(testBanner(testName, CLASS_NAME));
308 // Submit the request to the service and store the response.
309 OrgAuthorityClient client = new OrgAuthorityClient();
310 String identifier = createIdentifier();
311 PoxPayloadOut multipart =
312 ContactClientUtils.createContactInstance(parentcsid,
313 itemcsid, identifier, new ContactClient().getCommonPartName());
316 ClientResponse<Response> res =
317 client.createContact(parentcsid, itemcsid, multipart);
319 int statusCode = res.getStatus();
320 // Check the status code of the response: does it match
321 // the expected response(s)?
322 if (logger.isDebugEnabled()) {
323 logger.debug(testName + ": status = " + statusCode);
325 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
326 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
327 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
329 newID = OrgAuthorityClientUtils.extractId(res);
331 res.releaseConnection();
334 // Store the ID returned from the first contact resource created
335 // for additional tests below.
336 if (knownContactResourceId == null) {
337 knownContactResourceId = newID;
338 if (logger.isDebugEnabled()) {
339 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
343 // Store the IDs from any contact resources created
344 // by tests, along with the IDs of their parent items,
345 // so these items can be deleted after all tests have been run.
346 allContactResourceIdsCreated.put(newID, itemcsid);
352 // Placeholders until the three tests below can be uncommented.
353 // See Issue CSPACE-401.
355 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
358 public void createWithEmptyEntityBody(String testName) throws Exception {
359 //Should this really be empty?
363 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
366 public void createWithMalformedXml(String testName) throws Exception {
367 //Should this really be empty?
371 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
374 public void createWithWrongXmlSchema(String testName) throws Exception {
375 //Should this really be empty?
380 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
381 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
382 public void createWithEmptyEntityBody(String testName) throws Exception {
384 if (logger.isDebugEnabled()) {
385 logger.debug(testBanner(testName, CLASS_NAME));
388 setupCreateWithEmptyEntityBody();
390 // Submit the request to the service and store the response.
391 String method = REQUEST_TYPE.httpMethodName();
392 String url = getServiceRootURL();
393 String mediaType = MediaType.APPLICATION_XML;
394 final String entity = "";
395 int statusCode = submitRequest(method, url, mediaType, entity);
397 // Check the status code of the response: does it match
398 // the expected response(s)?
399 if(logger.isDebugEnabled()) {
400 logger.debug(testName + ": url=" + url +
401 " status=" + statusCode);
403 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
404 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
405 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
409 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
410 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
411 public void createWithMalformedXml(String testName) throws Exception {
413 if (logger.isDebugEnabled()) {
414 logger.debug(testBanner(testName, CLASS_NAME));
417 setupCreateWithMalformedXml();
419 // Submit the request to the service and store the response.
420 String method = REQUEST_TYPE.httpMethodName();
421 String url = getServiceRootURL();
422 String mediaType = MediaType.APPLICATION_XML;
423 final String entity = MALFORMED_XML_DATA; // Constant from base class.
424 int statusCode = submitRequest(method, url, mediaType, entity);
426 // Check the status code of the response: does it match
427 // the expected response(s)?
428 if(logger.isDebugEnabled()){
429 logger.debug(testName + ": url=" + url +
430 " status=" + statusCode);
432 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
433 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
434 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
438 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
439 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
440 public void createWithWrongXmlSchema(String testName) throws Exception {
442 if (logger.isDebugEnabled()) {
443 logger.debug(testBanner(testName, CLASS_NAME));
446 setupCreateWithWrongXmlSchema();
448 // Submit the request to the service and store the response.
449 String method = REQUEST_TYPE.httpMethodName();
450 String url = getServiceRootURL();
451 String mediaType = MediaType.APPLICATION_XML;
452 final String entity = WRONG_XML_SCHEMA_DATA;
453 int statusCode = submitRequest(method, url, mediaType, entity);
455 // Check the status code of the response: does it match
456 // the expected response(s)?
457 if(logger.isDebugEnabled()){
458 logger.debug(testName + ": url=" + url +
459 " status=" + statusCode);
461 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
462 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
463 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
466 // ---------------------------------------------------------------
467 // CRUD tests : CREATE LIST tests
468 // ---------------------------------------------------------------
471 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
474 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
475 groups = {"createList"}, dependsOnGroups = {"create"})
476 public void createList(String testName) throws Exception {
477 for (int i = 0; i < nItemsToCreateInList; i++) {
483 * Creates the item list.
485 * @param testName the test name
486 * @throws Exception the exception
488 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
489 groups = {"createList"}, dependsOnMethods = {"createList"})
490 public void createItemList(String testName) throws Exception {
491 // Add items to the initially-created, known parent record.
492 for (int j = 0; j < nItemsToCreateInList; j++) {
493 createItem(testName);
498 * Creates the contact list.
500 * @param testName the test name
501 * @throws Exception the exception
503 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
504 groups = {"createList"}, dependsOnMethods = {"createItemList"})
505 public void createContactList(String testName) throws Exception {
506 // Add contacts to the initially-created, known item record.
507 for (int j = 0; j < nItemsToCreateInList; j++) {
508 createContact(testName);
512 // ---------------------------------------------------------------
513 // CRUD tests : READ tests
514 // ---------------------------------------------------------------
517 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
520 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
521 groups = {"read"}, dependsOnGroups = {"create"})
522 public void read(String testName) throws Exception {
523 readInternal(testName, knownResourceId, null);
529 * @param testName the test name
530 * @throws Exception the exception
532 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
533 groups = {"read"}, dependsOnGroups = {"create"})
534 public void readByName(String testName) throws Exception {
535 readInternal(testName, null, knownResourceShortIdentifer);
538 protected void readInternal(String testName, String CSID, String shortId) {
540 if (logger.isDebugEnabled()) {
541 logger.debug(testBanner(testName, CLASS_NAME));
546 // Submit the request to the service and store the response.
547 OrgAuthorityClient client = new OrgAuthorityClient();
548 ClientResponse<String> res = null;
550 res = client.read(CSID);
551 } else if (shortId != null) {
552 res = client.readByName(shortId);
554 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
556 assertStatusCode(res, testName);
558 //FIXME: remove the following try catch once Aron fixes signatures
560 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
561 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
562 new OrgAuthorityClient().getCommonPartName(), OrgauthoritiesCommon.class);
563 if (logger.isDebugEnabled()) {
564 logger.debug(objectAsXmlString(orgAuthority, OrgauthoritiesCommon.class));
566 Assert.assertNotNull(orgAuthority);
567 } catch (Exception e) {
568 throw new RuntimeException(e);
571 res.releaseConnection();
578 * @param testName the test name
579 * @throws Exception the exception
581 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
582 groups = {"readItem"}, dependsOnGroups = {"read"})
583 public void readItem(String testName) throws Exception {
584 readItemInternal(testName, knownResourceId, null, knownItemResourceId, null);
588 * Read item in Named Auth.
590 * TODO Enable this if we really need this - it is a funky case, where we would have
591 * the shortId of the item, but the CSID of the parent authority!? Unlikely.
593 * @param testName the test name
594 * @throws Exception the exception
595 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
596 groups = {"readItem"}, dependsOnGroups = {"read"})
597 public void readItemInNamedAuth(String testName) throws Exception {
598 readItemInternal(testName, null, knownResourceShortIdentifer, knownItemResourceId, null);
604 * @param testName the test name
605 * @throws Exception the exception
607 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
608 groups = {"readItem"}, dependsOnGroups = {"read"})
609 public void readNamedItem(String testName) throws Exception {
610 readItemInternal(testName, knownResourceId, null, null, knownItemResourceShortIdentifer);
614 * Read Named item in Named Auth.
616 * @param testName the test name
617 * @throws Exception the exception
619 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
620 groups = {"readItem"}, dependsOnGroups = {"read"})
621 public void readNamedItemInNamedAuth(String testName) throws Exception {
622 readItemInternal(testName, null, knownResourceShortIdentifer, null, knownItemResourceShortIdentifer);
625 protected void readItemInternal(String testName,
626 String authCSID, String authShortId, String itemCSID, String itemShortId)
629 if (logger.isDebugEnabled()) {
630 logger.debug(testBanner(testName, CLASS_NAME));
635 // Submit the request to the service and store the response.
636 OrgAuthorityClient client = new OrgAuthorityClient();
637 ClientResponse<String> res = null;
638 if (authCSID != null) {
639 if (itemCSID != null) {
640 res = client.readItem(authCSID, itemCSID);
641 } else if (itemShortId != null) {
642 res = client.readNamedItem(authCSID, itemShortId);
644 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
646 } else if (authShortId != null) {
647 if (itemCSID != null) {
648 res = client.readItemInNamedAuthority(authShortId, itemCSID);
649 } else if (itemShortId != null) {
650 res = client.readNamedItemInNamedAuthority(authShortId, itemShortId);
652 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
655 Assert.fail("readInternal: Internal error. One of authCSID or authShortId must be non-null");
657 assertStatusCode(res, testName);
659 // Check whether we've received a organization.
660 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
661 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
662 client.getItemCommonPartName(), OrganizationsCommon.class);
663 Assert.assertNotNull(organization);
664 boolean showFull = true;
665 if (showFull && logger.isDebugEnabled()) {
666 logger.debug(testName + ": returned payload:");
667 logger.debug(objectAsXmlString(organization, OrganizationsCommon.class));
670 // Check that the organization item is within the expected OrgAuthority.
671 Assert.assertEquals(organization.getInAuthority(), knownResourceId);
673 // Verify the number and contents of values in a repeatable field,
674 // as created in the instance record used for testing.
675 List<String> contactNames = organization.getContactNames().getContactName();
676 Assert.assertTrue(contactNames.size() > 0);
677 Assert.assertNotNull(contactNames.get(0));
680 res.releaseConnection();
685 * Verify item display name.
687 * @param testName the test name
688 * @throws Exception the exception
690 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
691 dependsOnMethods = {"readItem", "updateItem"})
692 public void verifyItemDisplayName(String testName) throws Exception {
694 if (logger.isDebugEnabled()) {
695 logger.debug(testBanner(testName, CLASS_NAME));
700 // Submit the request to the service and store the response.
701 OrgAuthorityClient client = new OrgAuthorityClient();
702 PoxPayloadIn input = null;
703 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
704 assertStatusCode(res, testName);
706 input = new PoxPayloadIn(res.getEntity());
708 res.releaseConnection();
711 // Check whether organization has expected displayName.
712 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
713 client.getItemCommonPartName(), OrganizationsCommon.class);
714 Assert.assertNotNull(organization);
715 String displayName = organization.getDisplayName();
716 // Make sure displayName matches computed form
717 String expectedDisplayName =
718 OrgAuthorityClientUtils.prepareDefaultDisplayName(
719 TEST_ORG_SHORTNAME, TEST_ORG_FOUNDING_PLACE);
720 Assert.assertNotNull(displayName, expectedDisplayName);
722 // Update the shortName and verify the computed name is updated.
723 organization.setCsid(null);
724 organization.setDisplayNameComputed(true);
726 MainBodyGroupList mainBodyList = organization.getMainBodyGroupList();
727 List<MainBodyGroup> mainBodyGroups = mainBodyList.getMainBodyGroup();
728 MainBodyGroup mainBodyGroup = new MainBodyGroup();
729 String updatedShortName = "updated-" + TEST_ORG_SHORTNAME;
730 mainBodyGroup.setShortName(updatedShortName);
731 mainBodyGroups.add(mainBodyGroup);
732 organization.setMainBodyGroupList(mainBodyList);
734 expectedDisplayName =
735 OrgAuthorityClientUtils.prepareDefaultDisplayName(
736 updatedShortName, TEST_ORG_FOUNDING_PLACE);
738 // Submit the updated resource to the service and store the response.
739 PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
740 PayloadOutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
741 commonPart.setLabel(client.getItemCommonPartName());
742 res = client.updateItem(knownResourceId, knownItemResourceId, output);
743 assertStatusCode(res, testName);
745 // Retrieve the updated resource and verify that its contents exist.
746 input = new PoxPayloadIn(res.getEntity());
748 res.releaseConnection();
751 OrganizationsCommon updatedOrganization =
752 (OrganizationsCommon) extractPart(input,
753 client.getItemCommonPartName(), OrganizationsCommon.class);
754 Assert.assertNotNull(updatedOrganization);
756 // Verify that the updated resource received the correct data.
757 mainBodyList = organization.getMainBodyGroupList();
758 Assert.assertNotNull(mainBodyList);
759 Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0);
760 Assert.assertEquals(updatedOrganization.getMainBodyGroupList().getMainBodyGroup().get(0).getShortName(),
761 updatedShortName, "Updated ShortName in Organization did not match submitted data.");
763 // Verify that the updated resource computes the right displayName.
764 Assert.assertEquals(updatedOrganization.getDisplayName(), expectedDisplayName,
765 "Updated ShortName in Organization not reflected in computed DisplayName.");
767 // Now Update the displayName, not computed and verify the computed name is overriden.
768 organization.setDisplayNameComputed(false);
769 expectedDisplayName = "TestName";
770 organization.setDisplayName(expectedDisplayName);
772 // Submit the updated resource to the service and store the response.
773 output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
774 commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
775 commonPart.setLabel(client.getItemCommonPartName());
776 res = client.updateItem(knownResourceId, knownItemResourceId, output);
777 assertStatusCode(res, testName);
779 // Retrieve the updated resource and verify that its contents exist.
780 input = new PoxPayloadIn(res.getEntity());
782 res.releaseConnection();
785 updatedOrganization =
786 (OrganizationsCommon) extractPart(input,
787 client.getItemCommonPartName(), OrganizationsCommon.class);
788 Assert.assertNotNull(updatedOrganization);
790 // Verify that the updated resource received the correct data.
791 Assert.assertEquals(updatedOrganization.isDisplayNameComputed(), false,
792 "Updated displayNameComputed in Organization did not match submitted data.");
793 // Verify that the updated resource computes the right displayName.
794 Assert.assertEquals(updatedOrganization.getDisplayName(),
796 "Updated DisplayName (not computed) in Organization not stored.");
800 * Verify illegal item display name.
802 * @param testName the test name
803 * @throws Exception the exception
805 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
806 dependsOnMethods = {"verifyItemDisplayName"})
807 public void verifyIllegalItemDisplayName(String testName) throws Exception {
809 if (logger.isDebugEnabled()) {
810 logger.debug(testBanner(testName, CLASS_NAME));
813 // Perform setup for read.
816 // Submit the request to the service and store the response.
817 OrgAuthorityClient client = new OrgAuthorityClient();
818 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
819 assertStatusCode(res, testName);
821 // Perform setup for update.
822 testSetup(STATUS_BAD_REQUEST, ServiceRequestType.UPDATE);
825 // Check whether organization has expected displayName.
826 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
827 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
828 client.getItemCommonPartName(), OrganizationsCommon.class);
829 Assert.assertNotNull(organization);
830 // Try to Update with computed false and no displayName
831 organization.setDisplayNameComputed(false);
832 organization.setDisplayName(null);
834 // Submit the updated resource to the service and store the response.
835 PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
836 PayloadOutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
837 commonPart.setLabel(client.getItemCommonPartName());
838 res = client.updateItem(knownResourceId, knownItemResourceId, output);
839 assertStatusCode(res, testName);
841 res.releaseConnection();
848 * @param testName the test name
849 * @throws Exception the exception
851 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
852 groups = {"readItem"}, dependsOnMethods = {"readItem"})
853 public void readContact(String testName) throws Exception {
855 if (logger.isDebugEnabled()) {
856 logger.debug(testBanner(testName, CLASS_NAME));
861 // Submit the request to the service and store the response.
862 OrgAuthorityClient client = new OrgAuthorityClient();
863 ClientResponse<String> res =
864 client.readContact(knownResourceId, knownItemResourceId,
865 knownContactResourceId);
866 assertStatusCode(res, testName);
868 // Check whether we've received a contact.
869 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
870 ContactsCommon contact = (ContactsCommon) extractPart(input,
871 new ContactClient().getCommonPartName(), ContactsCommon.class);
872 Assert.assertNotNull(contact);
873 boolean showFull = true;
874 if (showFull && logger.isDebugEnabled()) {
875 logger.debug(testName + ": returned payload:");
876 logger.debug(objectAsXmlString(contact, ContactsCommon.class));
878 Assert.assertEquals(contact.getInAuthority(), knownResourceId);
879 Assert.assertEquals(contact.getInItem(), knownItemResourceId);
881 res.releaseConnection();
887 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
890 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
891 groups = {"read"}, dependsOnMethods = {"read"})
892 public void readNonExistent(String testName) {
894 if (logger.isDebugEnabled()) {
895 logger.debug(testBanner(testName, CLASS_NAME));
898 setupReadNonExistent();
900 // Submit the request to the service and store the response.
901 OrgAuthorityClient client = new OrgAuthorityClient();
902 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
904 int statusCode = res.getStatus();
906 // Check the status code of the response: does it match
907 // the expected response(s)?
908 if (logger.isDebugEnabled()) {
909 logger.debug(testName + ": status = " + statusCode);
911 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
912 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
913 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
915 res.releaseConnection();
920 * Read item non existent.
922 * @param testName the test name
924 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
925 groups = {"readItem"}, dependsOnMethods = {"readItem"})
926 public void readItemNonExistent(String testName) {
928 if (logger.isDebugEnabled()) {
929 logger.debug(testBanner(testName, CLASS_NAME));
932 setupReadNonExistent();
934 // Submit the request to the service and store the response.
935 OrgAuthorityClient client = new OrgAuthorityClient();
936 ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
938 int statusCode = res.getStatus();
940 // Check the status code of the response: does it match
941 // the expected response(s)?
942 if (logger.isDebugEnabled()) {
943 logger.debug(testName + ": status = " + statusCode);
945 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
946 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
947 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
949 res.releaseConnection();
954 * Read contact non existent.
956 * @param testName the test name
958 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
959 groups = {"readItem"}, dependsOnMethods = {"readContact"})
960 public void readContactNonExistent(String testName) {
962 if (logger.isDebugEnabled()) {
963 logger.debug(testBanner(testName, CLASS_NAME));
966 setupReadNonExistent();
968 // Submit the request to the service and store the response.
969 OrgAuthorityClient client = new OrgAuthorityClient();
970 ClientResponse<String> res =
971 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
973 int statusCode = res.getStatus();
975 // Check the status code of the response: does it match
976 // the expected response(s)?
977 if (logger.isDebugEnabled()) {
978 logger.debug(testName + ": status = " + statusCode);
980 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
981 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
982 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
984 res.releaseConnection();
988 // ---------------------------------------------------------------
989 // CRUD tests : READ_LIST tests
990 // ---------------------------------------------------------------
994 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
997 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
998 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
999 public void readList(String testName) throws Exception {
1001 if (logger.isDebugEnabled()) {
1002 logger.debug(testBanner(testName, CLASS_NAME));
1007 // Submit the request to the service and store the response.
1008 OrgAuthorityClient client = new OrgAuthorityClient();
1009 ClientResponse<AbstractCommonList> res = client.readList();
1010 assertStatusCode(res, testName);
1012 AbstractCommonList list = res.getEntity();
1013 // Optionally output additional data about list members for debugging.
1014 if (logger.isTraceEnabled()) {
1015 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
1018 res.releaseConnection();
1025 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
1026 public void readItemList() {
1027 readItemList(knownResourceId, null);
1031 * Read item list by authority name.
1033 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1034 public void readItemListByAuthorityName() {
1035 readItemList(null, knownResourceShortIdentifer);
1041 * @param vcsid the vcsid
1042 * @param name the name
1044 private void readItemList(String vcsid, String name) {
1046 final String testName = "readItemList";
1048 if (logger.isDebugEnabled()) {
1049 logger.debug(testBanner(testName, CLASS_NAME));
1054 // Submit the request to the service and store the response.
1055 OrgAuthorityClient client = new OrgAuthorityClient();
1056 ClientResponse<AbstractCommonList> res = null;
1057 if (vcsid != null) {
1058 res = client.readItemList(vcsid, null, null);
1059 } else if (name != null) {
1060 res = client.readItemListForNamedAuthority(name, null, null);
1062 Assert.fail("readItemList passed null csid and name!");
1064 assertStatusCode(res, testName);
1066 AbstractCommonList list = res.getEntity();
1067 List<AbstractCommonList.ListItem> items =
1069 int nItemsReturned = items.size();
1070 // There will be one item created, associated with a
1071 // known parent resource, by the createItem test.
1073 // In addition, there will be 'nItemsToCreateInList'
1074 // additional items created by the createItemList test,
1075 // all associated with the same parent resource.
1076 int nExpectedItems = nItemsToCreateInList + 1;
1077 if (logger.isDebugEnabled()) {
1078 logger.debug(testName + ": Expected "
1079 + nExpectedItems + " items; got: " + nItemsReturned);
1081 Assert.assertEquals(nItemsReturned, nExpectedItems);
1083 for (AbstractCommonList.ListItem item : items) {
1085 AbstractCommonListUtils.ListItemGetElementValue(item, REFNAME);
1086 Assert.assertTrue((null != value), "Item refName is null!");
1088 AbstractCommonListUtils.ListItemGetElementValue(item, DISPLAYNAME);
1089 Assert.assertTrue((null != value), "Item displayName is null!");
1091 if (logger.isTraceEnabled()) {
1092 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
1095 res.releaseConnection();
1100 * Read contact list.
1102 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1103 public void readContactList() {
1104 readContactList(knownResourceId, knownItemResourceId);
1108 * Read contact list.
1110 * @param parentcsid the parentcsid
1111 * @param itemcsid the itemcsid
1113 private void readContactList(String parentcsid, String itemcsid) {
1114 final String testName = "readContactList";
1116 if (logger.isDebugEnabled()) {
1117 logger.debug(testBanner(testName, CLASS_NAME));
1122 // Submit the request to the service and store the response.
1123 OrgAuthorityClient client = new OrgAuthorityClient();
1124 AbstractCommonList list = null;
1125 ClientResponse<AbstractCommonList> res =
1126 client.readContactList(parentcsid, itemcsid);
1127 assertStatusCode(res, testName);
1129 list = res.getEntity();
1131 List<AbstractCommonList.ListItem> listitems =
1133 int nItemsReturned = listitems.size();
1134 // There will be one item created, associated with a
1135 // known parent resource, by the createItem test.
1137 // In addition, there will be 'nItemsToCreateInList'
1138 // additional items created by the createItemList test,
1139 // all associated with the same parent resource.
1140 int nExpectedItems = nItemsToCreateInList + 1;
1141 if (logger.isDebugEnabled()) {
1142 logger.debug(testName + ": Expected "
1143 + nExpectedItems + " items; got: " + nItemsReturned);
1145 Assert.assertEquals(nItemsReturned, nExpectedItems);
1147 // Optionally output additional data about list members for debugging.
1148 boolean iterateThroughList = false;
1149 if (iterateThroughList && logger.isDebugEnabled()) {
1150 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
1153 res.releaseConnection();
1159 // ---------------------------------------------------------------
1160 // CRUD tests : UPDATE tests
1161 // ---------------------------------------------------------------
1164 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
1167 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1168 groups = {"update"}, dependsOnGroups = {"read", "readList"})
1169 public void update(String testName) throws Exception {
1171 if (logger.isDebugEnabled()) {
1172 logger.debug(testBanner(testName, CLASS_NAME));
1177 // Retrieve the contents of a resource to update.
1178 OrgAuthorityClient client = new OrgAuthorityClient();
1179 ClientResponse<String> res =
1180 client.read(knownResourceId);
1181 assertStatusCode(res, testName);
1183 if (logger.isDebugEnabled()) {
1184 logger.debug("got OrgAuthority to update with ID: " + knownResourceId);
1186 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
1187 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
1188 client.getCommonPartName(), OrgauthoritiesCommon.class);
1189 Assert.assertNotNull(orgAuthority);
1191 // Update the contents of this resource.
1192 orgAuthority.setDisplayName("updated-" + orgAuthority.getDisplayName());
1193 orgAuthority.setVocabType("updated-" + orgAuthority.getVocabType());
1194 if (logger.isDebugEnabled()) {
1195 logger.debug("to be updated OrgAuthority");
1196 logger.debug(objectAsXmlString(orgAuthority, OrgauthoritiesCommon.class));
1199 // Submit the updated resource to the service and store the response.
1200 PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_PAYLOAD_NAME);
1201 PayloadOutputPart commonPart = output.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE);
1202 commonPart.setLabel(client.getCommonPartName());
1203 res.releaseConnection();
1204 res = client.update(knownResourceId, output);
1205 assertStatusCode(res, testName);
1207 // Retrieve the updated resource and verify that its contents exist.
1208 input = new PoxPayloadIn(res.getEntity());
1209 OrgauthoritiesCommon updatedOrgAuthority =
1210 (OrgauthoritiesCommon) extractPart(input,
1211 client.getCommonPartName(), OrgauthoritiesCommon.class);
1212 Assert.assertNotNull(updatedOrgAuthority);
1214 // Verify that the updated resource received the correct data.
1215 Assert.assertEquals(updatedOrgAuthority.getDisplayName(),
1216 orgAuthority.getDisplayName(),
1217 "Data in updated object did not match submitted data.");
1219 res.releaseConnection();
1226 * @param testName the test name
1227 * @throws Exception the exception
1229 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1230 groups = {"update"}, dependsOnMethods = {"update"})
1231 public void updateItem(String testName) throws Exception {
1233 if (logger.isDebugEnabled()) {
1234 logger.debug(testBanner(testName, CLASS_NAME));
1239 // Retrieve the contents of a resource to update.
1240 OrgAuthorityClient client = new OrgAuthorityClient();
1241 ClientResponse<String> res =
1242 client.readItem(knownResourceId, knownItemResourceId);
1243 assertStatusCode(res, testName);
1245 if (logger.isDebugEnabled()) {
1246 logger.debug("got Organization to update with ID: "
1247 + knownItemResourceId
1248 + " in OrgAuthority: " + knownResourceId);
1250 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
1251 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
1252 client.getItemCommonPartName(), OrganizationsCommon.class);
1253 Assert.assertNotNull(organization);
1255 // Update the contents of this resource.
1256 organization.setCsid(null);
1258 MainBodyGroupList mainBodyList = organization.getMainBodyGroupList();
1259 Assert.assertNotNull(mainBodyList);
1260 List<MainBodyGroup> mainBodyGroups = mainBodyList.getMainBodyGroup();
1261 Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0);
1262 String updatedShortName = "updated-" + mainBodyGroups.get(0).getShortName();
1263 mainBodyGroups.get(0).setShortName(updatedShortName);
1265 if (logger.isDebugEnabled()) {
1266 logger.debug("to be updated Organization");
1267 logger.debug(objectAsXmlString(organization,
1268 OrganizationsCommon.class));
1271 // Submit the updated resource to the service and store the response.
1272 PoxPayloadOut output = new PoxPayloadOut(OrgAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1273 PayloadOutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
1274 commonPart.setLabel(client.getItemCommonPartName());
1275 res.releaseConnection();
1276 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1277 assertStatusCode(res, testName);
1279 // Retrieve the updated resource and verify that its contents exist.
1280 input = new PoxPayloadIn(res.getEntity());
1281 OrganizationsCommon updatedOrganization =
1282 (OrganizationsCommon) extractPart(input,
1283 client.getItemCommonPartName(), OrganizationsCommon.class);
1284 Assert.assertNotNull(updatedOrganization);
1286 // Verify that the updated resource received the correct data.
1287 mainBodyList = organization.getMainBodyGroupList();
1288 Assert.assertNotNull(mainBodyList);
1289 Assert.assertTrue(mainBodyList.getMainBodyGroup().size() > 0);
1290 Assert.assertEquals(updatedOrganization.getMainBodyGroupList().getMainBodyGroup().get(0).getShortName(),
1291 updatedShortName, "Data in updated Organization did not match submitted data.");
1293 res.releaseConnection();
1300 * @param testName the test name
1301 * @throws Exception the exception
1303 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1304 groups = {"update"}, dependsOnMethods = {"updateItem"})
1305 public void updateContact(String testName) throws Exception {
1307 if (logger.isDebugEnabled()) {
1308 logger.debug(testBanner(testName, CLASS_NAME));
1313 // Retrieve the contents of a resource to update.
1314 OrgAuthorityClient client = new OrgAuthorityClient();
1315 ClientResponse<String> res =
1316 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1317 assertStatusCode(res, testName);
1319 if (logger.isDebugEnabled()) {
1320 logger.debug("got Contact to update with ID: "
1321 + knownContactResourceId
1322 + " in item: " + knownItemResourceId
1323 + " in parent: " + knownResourceId);
1325 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
1326 ContactsCommon contact = (ContactsCommon) extractPart(input,
1327 new ContactClient().getCommonPartName(), ContactsCommon.class);
1328 Assert.assertNotNull(contact);
1330 // Verify the contents of this resource
1331 AddressGroupList addressGroupList = contact.getAddressGroupList();
1332 Assert.assertNotNull(addressGroupList);
1333 List<AddressGroup> addressGroups = addressGroupList.getAddressGroup();
1334 Assert.assertNotNull(addressGroups);
1335 Assert.assertTrue(addressGroups.size() > 0);
1336 String addressPlace1 = addressGroups.get(0).getAddressPlace1();
1337 Assert.assertNotNull(addressPlace1);
1339 // Update the contents of this resource.
1340 addressGroups.get(0).setAddressPlace1("updated-" + addressPlace1);
1341 contact.setAddressGroupList(addressGroupList);
1342 if (logger.isDebugEnabled()) {
1343 logger.debug("to be updated Contact");
1344 logger.debug(objectAsXmlString(contact,
1345 ContactsCommon.class));
1348 // Submit the updated resource to the service and store the response.
1349 PoxPayloadOut output = new PoxPayloadOut(ContactClient.SERVICE_PAYLOAD_NAME);
1350 PayloadOutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1351 commonPart.setLabel(new ContactClient().getCommonPartName());
1352 res.releaseConnection();
1353 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1354 assertStatusCode(res, testName);
1356 // Retrieve the updated resource and verify that its contents exist.
1357 input = new PoxPayloadIn(res.getEntity());
1358 ContactsCommon updatedContact =
1359 (ContactsCommon) extractPart(input,
1360 new ContactClient().getCommonPartName(), ContactsCommon.class);
1361 Assert.assertNotNull(updatedContact);
1363 // Verify that the updated resource received the correct data.
1364 Assert.assertEquals(updatedContact.getAddressGroupList().getAddressGroup().get(0).getAddressPlace1(),
1365 contact.getAddressGroupList().getAddressGroup().get(0).getAddressPlace1(),
1366 "Data in updated object did not match submitted data.");
1369 res.releaseConnection();
1374 // Placeholders until the three tests below can be uncommented.
1375 // See Issue CSPACE-401.
1377 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1380 public void updateWithEmptyEntityBody(String testName) throws Exception {
1381 //Should this really be empty?
1385 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1388 public void updateWithMalformedXml(String testName) throws Exception {
1389 //Should this really be empty?
1393 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1396 public void updateWithWrongXmlSchema(String testName) throws Exception {
1397 //Should this really be empty?
1402 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1403 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1404 public void updateWithEmptyEntityBody(String testName) throws Exception {
1406 if (logger.isDebugEnabled()) {
1407 logger.debug(testBanner(testName, CLASS_NAME));
1410 setupUpdateWithEmptyEntityBody();
1412 // Submit the request to the service and store the response.
1413 String method = REQUEST_TYPE.httpMethodName();
1414 String url = getResourceURL(knownResourceId);
1415 String mediaType = MediaType.APPLICATION_XML;
1416 final String entity = "";
1417 int statusCode = submitRequest(method, url, mediaType, entity);
1419 // Check the status code of the response: does it match
1420 // the expected response(s)?
1421 if(logger.isDebugEnabled()){
1422 logger.debug(testName + ": url=" + url +
1423 " status=" + statusCode);
1425 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1426 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1427 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1431 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1432 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1433 public void updateWithMalformedXml(String testName) throws Exception {
1435 if (logger.isDebugEnabled()) {
1436 logger.debug(testBanner(testName, CLASS_NAME));
1439 setupUpdateWithMalformedXml();
1441 // Submit the request to the service and store the response.
1442 String method = REQUEST_TYPE.httpMethodName();
1443 String url = getResourceURL(knownResourceId);
1444 String mediaType = MediaType.APPLICATION_XML;
1445 final String entity = MALFORMED_XML_DATA;
1446 int statusCode = submitRequest(method, url, mediaType, entity);
1448 // Check the status code of the response: does it match
1449 // the expected response(s)?
1450 if(logger.isDebugEnabled()){
1451 logger.debug(testName + ": url=" + url +
1452 " status=" + statusCode);
1454 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1455 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1456 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1460 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1461 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1462 public void updateWithWrongXmlSchema(String testName) throws Exception {
1465 setupUpdateWithWrongXmlSchema(testName, logger);
1467 // Submit the request to the service and store the response.
1468 String method = REQUEST_TYPE.httpMethodName();
1469 String url = getResourceURL(knownResourceId);
1470 String mediaType = MediaType.APPLICATION_XML;
1471 final String entity = WRONG_XML_SCHEMA_DATA;
1472 int statusCode = submitRequest(method, url, mediaType, entity);
1474 // Check the status code of the response: does it match
1475 // the expected response(s)?
1476 if(logger.isDebugEnabled()){
1477 logger.debug("updateWithWrongXmlSchema: url=" + url +
1478 " status=" + statusCode);
1480 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1481 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1482 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1487 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1490 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1491 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1492 public void updateNonExistent(String testName) throws Exception {
1494 if (logger.isDebugEnabled()) {
1495 logger.debug(testBanner(testName, CLASS_NAME));
1498 setupUpdateNonExistent();
1500 // Submit the request to the service and store the response.
1501 // Note: The ID used in this 'create' call may be arbitrary.
1502 // The only relevant ID may be the one used in update(), below.
1503 OrgAuthorityClient client = new OrgAuthorityClient();
1504 PoxPayloadOut multipart = OrgAuthorityClientUtils.createOrgAuthorityInstance(
1505 NON_EXISTENT_ID, NON_EXISTENT_ID,
1506 new OrgAuthorityClient().getCommonPartName());
1507 ClientResponse<String> res =
1508 client.update(NON_EXISTENT_ID, multipart);
1510 int statusCode = res.getStatus();
1512 // Check the status code of the response: does it match
1513 // the expected response(s)?
1514 if (logger.isDebugEnabled()) {
1515 logger.debug(testName + ": status = " + statusCode);
1517 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1518 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1519 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1521 res.releaseConnection();
1526 * Update non existent item.
1528 * @param testName the test name
1529 * @throws Exception the exception
1531 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1532 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1533 public void updateNonExistentItem(String testName) throws Exception {
1535 if (logger.isDebugEnabled()) {
1536 logger.debug(testBanner(testName, CLASS_NAME));
1539 setupUpdateNonExistent();
1541 // Submit the request to the service and store the response.
1542 // Note: The ID(s) used when creating the request payload may be arbitrary.
1543 // The only relevant ID may be the one used in update(), below.
1544 OrgAuthorityClient client = new OrgAuthorityClient();
1545 Map<String, String> nonexOrgMap = new HashMap<String, String>();
1546 nonexOrgMap.put(OrganizationJAXBSchema.SHORT_IDENTIFIER, "nonExistent");
1547 nonexOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Non-existent");
1548 PoxPayloadOut multipart =
1549 OrgAuthorityClientUtils.createOrganizationInstance(
1550 knownResourceRefName,
1551 nonexOrgMap, client.getItemCommonPartName());
1552 ClientResponse<String> res =
1553 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1555 int statusCode = res.getStatus();
1557 // Check the status code of the response: does it match
1558 // the expected response(s)?
1559 if (logger.isDebugEnabled()) {
1560 logger.debug(testName + ": status = " + statusCode);
1562 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1563 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1564 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1566 res.releaseConnection();
1571 * Update non existent contact.
1573 * @param testName the test name
1574 * @throws Exception the exception
1576 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1577 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1578 public void updateNonExistentContact(String testName) throws Exception {
1579 // Currently a no-op test
1582 // ---------------------------------------------------------------
1583 // CRUD tests : DELETE tests
1584 // ---------------------------------------------------------------
1586 // Note: delete sub-resources in ascending hierarchical order,
1587 // before deleting their parents.
1591 * @param testName the test name
1592 * @throws Exception the exception
1594 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1595 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1596 public void deleteContact(String testName) throws Exception {
1598 if (logger.isDebugEnabled()) {
1599 logger.debug(testBanner(testName, CLASS_NAME));
1604 if (logger.isDebugEnabled()) {
1605 logger.debug("parentcsid =" + knownResourceId
1606 + " itemcsid = " + knownItemResourceId
1607 + " csid = " + knownContactResourceId);
1610 // Submit the request to the service and store the response.
1611 OrgAuthorityClient client = new OrgAuthorityClient();
1612 ClientResponse<Response> res =
1613 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1615 int statusCode = res.getStatus();
1617 // Check the status code of the response: does it match
1618 // the expected response(s)?
1619 if (logger.isDebugEnabled()) {
1620 logger.debug(testName + ": status = " + statusCode);
1622 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1623 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1624 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1626 res.releaseConnection();
1633 * @param testName the test name
1634 * @throws Exception the exception
1636 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1637 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1638 public void deleteItem(String testName) throws Exception {
1640 if (logger.isDebugEnabled()) {
1641 logger.debug(testBanner(testName, CLASS_NAME));
1646 if (logger.isDebugEnabled()) {
1647 logger.debug("parentcsid =" + knownResourceId
1648 + " itemcsid = " + knownItemResourceId);
1651 // Submit the request to the service and store the response.
1652 OrgAuthorityClient client = new OrgAuthorityClient();
1653 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1655 int statusCode = res.getStatus();
1657 // Check the status code of the response: does it match
1658 // the expected response(s)?
1659 if (logger.isDebugEnabled()) {
1660 logger.debug(testName + ": status = " + statusCode);
1662 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1663 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1664 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1666 res.releaseConnection();
1671 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1674 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1675 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1676 public void delete(String testName) throws Exception {
1678 if (logger.isDebugEnabled()) {
1679 logger.debug(testBanner(testName, CLASS_NAME));
1684 if (logger.isDebugEnabled()) {
1685 logger.debug("parentcsid =" + knownResourceId);
1688 // Submit the request to the service and store the response.
1689 OrgAuthorityClient client = new OrgAuthorityClient();
1690 ClientResponse<Response> res = client.delete(knownResourceId);
1692 int statusCode = res.getStatus();
1694 // Check the status code of the response: does it match
1695 // the expected response(s)?
1696 if (logger.isDebugEnabled()) {
1697 logger.debug(testName + ": status = " + statusCode);
1699 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1700 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1701 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1703 res.releaseConnection();
1709 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1712 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1713 groups = {"delete"}, dependsOnMethods = {"delete"})
1714 public void deleteNonExistent(String testName) throws Exception {
1716 if (logger.isDebugEnabled()) {
1717 logger.debug(testBanner(testName, CLASS_NAME));
1720 setupDeleteNonExistent();
1722 // Submit the request to the service and store the response.
1723 OrgAuthorityClient client = new OrgAuthorityClient();
1724 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1726 int statusCode = res.getStatus();
1728 // Check the status code of the response: does it match
1729 // the expected response(s)?
1730 if (logger.isDebugEnabled()) {
1731 logger.debug(testName + ": status = " + statusCode);
1733 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1734 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1735 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1737 res.releaseConnection();
1742 * Delete non existent item.
1744 * @param testName the test name
1746 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1747 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1748 public void deleteNonExistentItem(String testName) {
1750 if (logger.isDebugEnabled()) {
1751 logger.debug(testBanner(testName, CLASS_NAME));
1754 setupDeleteNonExistent();
1756 // Submit the request to the service and store the response.
1757 OrgAuthorityClient client = new OrgAuthorityClient();
1758 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1760 int statusCode = res.getStatus();
1762 // Check the status code of the response: does it match
1763 // the expected response(s)?
1764 if (logger.isDebugEnabled()) {
1765 logger.debug(testName + ": status = " + statusCode);
1767 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1768 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1769 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1771 res.releaseConnection();
1776 * Delete non existent contact.
1778 * @param testName the test name
1780 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1781 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1782 public void deleteNonExistentContact(String testName) {
1784 if (logger.isDebugEnabled()) {
1785 logger.debug(testBanner(testName, CLASS_NAME));
1788 setupDeleteNonExistent();
1790 // Submit the request to the service and store the response.
1791 OrgAuthorityClient client = new OrgAuthorityClient();
1792 ClientResponse<Response> res =
1793 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1795 int statusCode = res.getStatus();
1797 // Check the status code of the response: does it match
1798 // the expected response(s)?
1799 if (logger.isDebugEnabled()) {
1800 logger.debug(testName + ": status = " + statusCode);
1802 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1803 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1804 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1806 res.releaseConnection();
1810 // ---------------------------------------------------------------
1811 // Utility tests : tests of code used in tests above
1812 // ---------------------------------------------------------------
1814 * Tests the code for manually submitting data that is used by several
1815 * of the methods above.
1817 @Test(dependsOnMethods = {"create", "read"})
1818 public void testSubmitRequest() {
1820 // Expected status code: 200 OK
1821 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1823 // Submit the request to the service and store the response.
1824 String method = ServiceRequestType.READ.httpMethodName();
1825 String url = getResourceURL(knownResourceId);
1826 int statusCode = submitRequest(method, url);
1828 // Check the status code of the response: does it match
1829 // the expected response(s)?
1830 if (logger.isDebugEnabled()) {
1831 logger.debug("testSubmitRequest: url=" + url
1832 + " status=" + statusCode);
1834 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1839 * Test item submit request.
1841 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1842 public void testItemSubmitRequest() {
1844 // Expected status code: 200 OK
1845 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1847 // Submit the request to the service and store the response.
1848 String method = ServiceRequestType.READ.httpMethodName();
1849 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1850 int statusCode = submitRequest(method, url);
1852 // Check the status code of the response: does it match
1853 // the expected response(s)?
1854 if (logger.isDebugEnabled()) {
1855 logger.debug("testItemSubmitRequest: url=" + url
1856 + " status=" + statusCode);
1858 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1863 * Test contact submit request.
1865 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
1866 public void testContactSubmitRequest() {
1868 // Expected status code: 200 OK
1869 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1871 // Submit the request to the service and store the response.
1872 String method = ServiceRequestType.READ.httpMethodName();
1873 String url = getContactResourceURL(knownResourceId,
1874 knownItemResourceId, knownContactResourceId);
1875 int statusCode = submitRequest(method, url);
1877 // Check the status code of the response: does it match
1878 // the expected response(s)?
1879 if (logger.isDebugEnabled()) {
1880 logger.debug("testItemSubmitRequest: url=" + url
1881 + " status=" + statusCode);
1883 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1887 // ---------------------------------------------------------------
1888 // Cleanup of resources created during testing
1889 // ---------------------------------------------------------------
1891 * Deletes all resources created by tests, after all tests have been run.
1893 * This cleanup method will always be run, even if one or more tests fail.
1894 * For this reason, it attempts to remove all resources created
1895 * at any point during testing, even if some of those resources
1896 * may be expected to be deleted by certain tests.
1898 @AfterClass(alwaysRun = true)
1900 public void cleanUp() {
1901 String noTest = System.getProperty("noTestCleanup");
1902 if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1903 if (logger.isDebugEnabled()) {
1904 logger.debug("Skipping Cleanup phase ...");
1908 if (logger.isDebugEnabled()) {
1909 logger.debug("Cleaning up temporary resources created for testing ...");
1912 String parentResourceId;
1913 String itemResourceId;
1914 String contactResourceId;
1915 // Clean up contact resources.
1916 parentResourceId = knownResourceId;
1917 OrgAuthorityClient client = new OrgAuthorityClient();
1918 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
1919 contactResourceId = entry.getKey();
1920 itemResourceId = entry.getValue();
1921 // Note: Any non-success responses from the delete operation
1922 // below are ignored and not reported.
1923 ClientResponse<Response> res =
1924 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
1925 res.releaseConnection();
1927 // Clean up item resources.
1928 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1929 itemResourceId = entry.getKey();
1930 parentResourceId = entry.getValue();
1931 // Note: Any non-success responses from the delete operation
1932 // below are ignored and not reported.
1933 ClientResponse<Response> res =
1934 client.deleteItem(parentResourceId, itemResourceId);
1935 res.releaseConnection();
1937 // Clean up parent resources.
1942 // ---------------------------------------------------------------
1943 // Utility methods used by tests above
1944 // ---------------------------------------------------------------
1946 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
1949 * Gets the item service path component.
1951 * @return the item service path component
1953 public String getItemServicePathComponent() {
1954 return AuthorityClient.ITEMS;
1958 * Gets the contact service path component.
1960 * @return the contact service path component
1962 public String getContactServicePathComponent() {
1963 return ContactClient.SERVICE_PATH_COMPONENT;
1967 * Returns the root URL for the item service.
1969 * This URL consists of a base URL for all services, followed by
1970 * a path component for the owning parent, followed by the
1971 * path component for the items.
1973 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1974 * parent authority resource of the relevant item resource.
1976 * @return The root URL for the item service.
1978 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1979 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1983 * Returns the URL of a specific item resource managed by a service, and
1984 * designated by an identifier (such as a universally unique ID, or UUID).
1986 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1987 * parent authority resource of the relevant item resource.
1989 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1992 * @return The URL of a specific item resource managed by a service.
1994 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1995 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
1999 * Returns the root URL for the contact service.
2001 * This URL consists of a base URL for all services, followed by
2002 * a path component for the owning authority, followed by the
2003 * path component for the owning item, followed by the path component
2004 * for the contact service.
2006 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2007 * parent authority resource of the relevant item resource.
2009 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2012 * @return The root URL for the contact service.
2014 protected String getContactServiceRootURL(String parentResourceIdentifier,
2015 String itemResourceIdentifier) {
2016 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/"
2017 + getContactServicePathComponent();
2021 * Returns the URL of a specific contact resource managed by a service, and
2022 * designated by an identifier (such as a universally unique ID, or UUID).
2024 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2025 * parent resource of the relevant item resource.
2027 * @param resourceIdentifier An identifier (such as a UUID) for an
2030 * @return The URL of a specific resource managed by a service.
2032 protected String getContactResourceURL(String parentResourceIdentifier,
2033 String itemResourceIdentifier, String contactResourceIdentifier) {
2034 return getContactServiceRootURL(parentResourceIdentifier,
2035 itemResourceIdentifier) + "/" + contactResourceIdentifier;