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.HashMap;
26 import java.util.List;
28 import javax.ws.rs.core.MediaType;
29 import javax.ws.rs.core.Response;
31 import org.collectionspace.services.OrganizationJAXBSchema;
32 import org.collectionspace.services.client.CollectionSpaceClient;
33 import org.collectionspace.services.client.ContactClient;
34 import org.collectionspace.services.client.ContactClientUtils;
35 import org.collectionspace.services.contact.ContactsCommon;
36 import org.collectionspace.services.contact.ContactsCommonList;
37 import org.collectionspace.services.client.OrgAuthorityClient;
38 import org.collectionspace.services.client.OrgAuthorityClientUtils;
39 import org.collectionspace.services.jaxb.AbstractCommonList;
40 import org.collectionspace.services.organization.OrgauthoritiesCommon;
41 import org.collectionspace.services.organization.OrgauthoritiesCommonList;
42 import org.collectionspace.services.organization.OrganizationsCommon;
43 import org.collectionspace.services.organization.OrganizationsCommonList;
45 import org.jboss.resteasy.client.ClientResponse;
46 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
47 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
48 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
49 import org.slf4j.Logger;
50 import org.slf4j.LoggerFactory;
51 import org.testng.Assert;
52 import org.testng.annotations.AfterClass;
53 import org.testng.annotations.Test;
56 * OrgAuthorityServiceTest, carries out tests against a
57 * deployed and running OrgAuthority Service.
59 * $LastChangedRevision: 753 $
60 * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
62 public class OrgAuthorityServiceTest extends AbstractServiceTestImpl {
65 private final Logger logger =
66 LoggerFactory.getLogger(OrgAuthorityServiceTest.class);
68 // Instance variables specific to this test.
69 /** The SERVIC e_ pat h_ component. */
70 final String SERVICE_PATH_COMPONENT = "orgauthorities";
72 /** The ITE m_ servic e_ pat h_ component. */
73 final String ITEM_SERVICE_PATH_COMPONENT = "items";
75 /** The CONTAC t_ servic e_ pat h_ component. */
76 final String CONTACT_SERVICE_PATH_COMPONENT = "contacts";
78 /** The TES t_ or g_ shortname. */
79 private final String TEST_ORG_SHORTNAME = "Test Org";
81 /** The TES t_ or g_ foundin g_ place. */
82 private final String TEST_ORG_FOUNDING_PLACE = "Anytown, USA";
84 /** The known resource id. */
85 private String knownResourceId = null;
87 /** The known resource display name. */
88 private String knownResourceDisplayName = null;
90 /** The known resource ref name. */
91 private String knownResourceRefName = null;
93 /** The known item resource id. */
94 private String knownItemResourceId = null;
96 /** The known contact resource id. */
97 private String knownContactResourceId = null;
99 /** The n items to create in list. */
100 private int nItemsToCreateInList = 3;
102 /** The all item resource ids created. */
103 private Map<String, String> allItemResourceIdsCreated =
104 new HashMap<String, String>();
106 /** The all contact resource ids created. */
107 private Map<String, String> allContactResourceIdsCreated =
108 new HashMap<String, String>();
111 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
114 protected CollectionSpaceClient getClientInstance() {
115 return new OrgAuthorityClient();
119 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
122 protected AbstractCommonList getAbstractCommonList(
123 ClientResponse<AbstractCommonList> response) {
124 return response.getEntity(OrganizationsCommonList.class);
127 // ---------------------------------------------------------------
128 // CRUD tests : CREATE tests
129 // ---------------------------------------------------------------
132 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
135 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
137 public void create(String testName) throws Exception {
139 // Perform setup, such as initializing the type of service request
140 // (e.g. CREATE, DELETE), its valid and expected status codes, and
141 // its associated HTTP method name (e.g. POST, DELETE).
142 setupCreate(testName);
144 // Submit the request to the service and store the response.
145 OrgAuthorityClient client = new OrgAuthorityClient();
146 String identifier = createIdentifier();
147 String displayName = "displayName-" + identifier;
148 String refName = OrgAuthorityClientUtils.createOrgAuthRefName(displayName, true);
149 MultipartOutput multipart =
150 OrgAuthorityClientUtils.createOrgAuthorityInstance(
151 displayName, refName, 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 // Store the refname from the first resource created
172 // for additional tests below.
173 knownResourceRefName = refName;
175 newID = OrgAuthorityClientUtils.extractId(res);
177 res.releaseConnection();
180 // Store the ID returned from the first resource created
181 // for additional tests below.
182 if (knownResourceId == null){
183 knownResourceId = newID;
184 knownResourceDisplayName = displayName;
185 if (logger.isDebugEnabled()) {
186 logger.debug(testName + ": knownResourceId=" + knownResourceId);
189 // Store the IDs from every resource created by tests,
190 // so they can be deleted after tests have been run.
191 allResourceIdsCreated.add(newID);
197 * @param testName the test name
199 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
200 groups = {"create"}, dependsOnMethods = {"create"})
201 public void createItem(String testName) {
202 setupCreate(testName);
203 String newID = createItemInAuthority(knownResourceId, knownResourceRefName);
207 * Creates the item in authority.
209 * @param vcsid the vcsid
210 * @param authRefName the auth ref name
213 private String createItemInAuthority(String vcsid, String authRefName) {
215 final String testName = "createItemInAuthority";
216 if(logger.isDebugEnabled()){
217 logger.debug(testName + ":...");
220 // Submit the request to the service and store the response.
221 OrgAuthorityClient client = new OrgAuthorityClient();
222 String identifier = createIdentifier();
223 String refName = OrgAuthorityClientUtils.createOrganizationRefName(knownResourceRefName, identifier, true);
224 Map<String, String> testOrgMap = new HashMap<String,String>();
225 testOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, TEST_ORG_SHORTNAME);
226 testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "The real official test organization");
227 testOrgMap.put(OrganizationJAXBSchema.CONTACT_NAME, "joe@test.org");
228 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "May 26, 1907");
229 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, TEST_ORG_FOUNDING_PLACE);
230 testOrgMap.put(OrganizationJAXBSchema.FUNCTION, "For testing");
231 String newID = OrgAuthorityClientUtils.createItemInAuthority(
232 vcsid, authRefName, testOrgMap, client);
233 // Store the ID returned from the first item resource created
234 // for additional tests below.
235 if (knownItemResourceId == null){
236 knownItemResourceId = newID;
237 if (logger.isDebugEnabled()) {
238 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
242 // Store the IDs from any item resources created
243 // by tests, along with the IDs of their parents, so these items
244 // can be deleted after all tests have been run.
245 allItemResourceIdsCreated.put(newID, vcsid);
251 * Creates the contact.
253 * @param testName the test name
255 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
256 groups = {"create"}, dependsOnMethods = {"createItem"})
257 public void createContact(String testName) {
258 setupCreate(testName);
259 String newID = createContactInItem(knownResourceId, knownItemResourceId);
263 * Creates the contact in item.
265 * @param parentcsid the parentcsid
266 * @param itemcsid the itemcsid
269 private String createContactInItem(String parentcsid, String itemcsid) {
271 final String testName = "createContactInItem";
272 setupCreate(testName);
273 if(logger.isDebugEnabled()){
274 logger.debug(testName + ":...");
277 // Submit the request to the service and store the response.
278 OrgAuthorityClient client = new OrgAuthorityClient();
279 String identifier = createIdentifier();
280 MultipartOutput multipart =
281 ContactClientUtils.createContactInstance(parentcsid,
282 itemcsid, identifier, new ContactClient().getCommonPartName());
285 ClientResponse<Response> res =
286 client.createContact(parentcsid, itemcsid, multipart);
288 int statusCode = res.getStatus();
289 // Check the status code of the response: does it match
290 // the expected response(s)?
291 if(logger.isDebugEnabled()){
292 logger.debug(testName + ": status = " + statusCode);
294 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
295 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
296 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
298 newID = OrgAuthorityClientUtils.extractId(res);
300 res.releaseConnection();
303 // Store the ID returned from the first contact resource created
304 // for additional tests below.
305 if (knownContactResourceId == null){
306 knownContactResourceId = newID;
307 if (logger.isDebugEnabled()) {
308 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
312 // Store the IDs from any contact resources created
313 // by tests, along with the IDs of their parent items,
314 // so these items can be deleted after all tests have been run.
315 allContactResourceIdsCreated.put(newID, itemcsid);
322 // Placeholders until the three tests below can be uncommented.
323 // See Issue CSPACE-401.
325 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
328 public void createWithEmptyEntityBody(String testName) throws Exception {
329 //Should this really be empty?
333 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
336 public void createWithMalformedXml(String testName) throws Exception {
337 //Should this really be empty?
341 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
344 public void createWithWrongXmlSchema(String testName) throws Exception {
345 //Should this really be empty?
350 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
351 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
352 public void createWithEmptyEntityBody(String testName) throws Exception {
355 setupCreateWithEmptyEntityBody(testName);
357 // Submit the request to the service and store the response.
358 String method = REQUEST_TYPE.httpMethodName();
359 String url = getServiceRootURL();
360 String mediaType = MediaType.APPLICATION_XML;
361 final String entity = "";
362 int statusCode = submitRequest(method, url, mediaType, entity);
364 // Check the status code of the response: does it match
365 // the expected response(s)?
366 if(logger.isDebugEnabled()) {
367 logger.debug(testName + ": url=" + url +
368 " status=" + statusCode);
370 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
371 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
372 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
376 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
377 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
378 public void createWithMalformedXml(String testName) throws Exception {
381 setupCreateWithMalformedXml(testName);
383 // Submit the request to the service and store the response.
384 String method = REQUEST_TYPE.httpMethodName();
385 String url = getServiceRootURL();
386 String mediaType = MediaType.APPLICATION_XML;
387 final String entity = MALFORMED_XML_DATA; // Constant from base class.
388 int statusCode = submitRequest(method, url, mediaType, entity);
390 // Check the status code of the response: does it match
391 // the expected response(s)?
392 if(logger.isDebugEnabled()){
393 logger.debug(testName + ": url=" + url +
394 " status=" + statusCode);
396 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
397 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
398 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
402 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
403 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
404 public void createWithWrongXmlSchema(String testName) throws Exception {
407 setupCreateWithWrongXmlSchema(testName);
409 // Submit the request to the service and store the response.
410 String method = REQUEST_TYPE.httpMethodName();
411 String url = getServiceRootURL();
412 String mediaType = MediaType.APPLICATION_XML;
413 final String entity = WRONG_XML_SCHEMA_DATA;
414 int statusCode = submitRequest(method, url, mediaType, entity);
416 // Check the status code of the response: does it match
417 // the expected response(s)?
418 if(logger.isDebugEnabled()){
419 logger.debug(testName + ": url=" + url +
420 " status=" + statusCode);
422 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
423 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
424 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
428 // ---------------------------------------------------------------
429 // CRUD tests : CREATE LIST tests
430 // ---------------------------------------------------------------
433 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
436 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
437 groups = {"createList"}, dependsOnGroups = {"create"})
438 public void createList(String testName) throws Exception {
439 for (int i = 0; i < nItemsToCreateInList; i++) {
445 * Creates the item list.
447 * @param testName the test name
448 * @throws Exception the exception
450 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
451 groups = {"createList"}, dependsOnMethods = {"createList"})
452 public void createItemList(String testName) throws Exception {
453 // Add items to the initially-created, known parent record.
454 for (int j = 0; j < nItemsToCreateInList; j++) {
455 createItem(testName);
460 * Creates the contact list.
462 * @param testName the test name
463 * @throws Exception the exception
465 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
466 groups = {"createList"}, dependsOnMethods = {"createItemList"})
467 public void createContactList(String testName) throws Exception {
468 // Add contacts to the initially-created, known item record.
469 for (int j = 0; j < nItemsToCreateInList; j++) {
470 createContact(testName);
474 // ---------------------------------------------------------------
475 // CRUD tests : READ tests
476 // ---------------------------------------------------------------
479 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
482 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
483 groups = {"read"}, dependsOnGroups = {"create"})
484 public void read(String testName) throws Exception {
489 // Submit the request to the service and store the response.
490 OrgAuthorityClient client = new OrgAuthorityClient();
491 ClientResponse<MultipartInput> res = client.read(knownResourceId);
493 int statusCode = res.getStatus();
495 // Check the status code of the response: does it match
496 // the expected response(s)?
497 if(logger.isDebugEnabled()){
498 logger.debug(testName + ": status = " + statusCode);
500 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
501 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
502 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
503 //FIXME: remove the following try catch once Aron fixes signatures
505 MultipartInput input = (MultipartInput) res.getEntity();
506 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
507 client.getCommonPartName(), OrgauthoritiesCommon.class);
508 Assert.assertNotNull(orgAuthority);
509 } catch (Exception e) {
510 throw new RuntimeException(e);
513 res.releaseConnection();
520 * @param testName the test name
521 * @throws Exception the exception
523 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
524 groups = {"read"}, dependsOnGroups = {"create"})
525 public void readByName(String testName) throws Exception {
530 // Submit the request to the service and store the response.
531 OrgAuthorityClient client = new OrgAuthorityClient();
532 ClientResponse<MultipartInput> res = client.readByName(knownResourceDisplayName);
534 int statusCode = res.getStatus();
536 // Check the status code of the response: does it match
537 // the expected response(s)?
538 if(logger.isDebugEnabled()){
539 logger.debug(testName + ": status = " + statusCode);
541 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
542 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
543 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
544 //FIXME: remove the following try catch once Aron fixes signatures
546 MultipartInput input = (MultipartInput) res.getEntity();
547 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
548 new OrgAuthorityClient().getCommonPartName(), OrgauthoritiesCommon.class);
549 Assert.assertNotNull(orgAuthority);
550 } catch (Exception e) {
551 throw new RuntimeException(e);
554 res.releaseConnection();
559 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
560 groups = {"read"}, dependsOnMethods = {"read"})
561 public void readByName(String testName) throws Exception {
566 // Submit the request to the service and store the response.
567 ClientResponse<MultipartInput> res = client.read(knownResourceId);
568 int statusCode = res.getStatus();
570 // Check the status code of the response: does it match
571 // the expected response(s)?
572 if(logger.isDebugEnabled()){
573 logger.debug(testName + ": status = " + statusCode);
575 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
576 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
577 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
578 //FIXME: remove the following try catch once Aron fixes signatures
580 MultipartInput input = (MultipartInput) res.getEntity();
581 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
582 client.getCommonPartName(), OrgauthoritiesCommon.class);
583 Assert.assertNotNull(orgAuthority);
584 } catch (Exception e) {
585 throw new RuntimeException(e);
593 * @param testName the test name
594 * @throws Exception the exception
596 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
597 groups = {"read"}, dependsOnMethods = {"read"})
598 public void readItem(String testName) throws Exception {
603 // Submit the request to the service and store the response.
604 OrgAuthorityClient client = new OrgAuthorityClient();
605 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
607 int statusCode = res.getStatus();
609 // Check the status code of the response: does it match
610 // the expected response(s)?
611 if(logger.isDebugEnabled()){
612 logger.debug(testName + ": status = " + statusCode);
614 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
615 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
616 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
618 // Check whether we've received a organization.
619 MultipartInput input = (MultipartInput) res.getEntity();
620 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
621 client.getItemCommonPartName(), OrganizationsCommon.class);
622 Assert.assertNotNull(organization);
623 boolean showFull = true;
624 if(showFull && logger.isDebugEnabled()){
625 logger.debug(testName + ": returned payload:");
626 logger.debug(objectAsXmlString(organization,
627 OrganizationsCommon.class));
629 Assert.assertEquals(organization.getInAuthority(), knownResourceId);
631 res.releaseConnection();
636 * Verify item display name.
638 * @param testName the test name
639 * @throws Exception the exception
641 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
642 dependsOnMethods = {"readItem", "updateItem"})
643 public void verifyItemDisplayName(String testName) throws Exception {
646 setupUpdate(testName);
648 // Submit the request to the service and store the response.
649 OrgAuthorityClient client = new OrgAuthorityClient();
650 MultipartInput input = null;
651 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
653 int statusCode = res.getStatus();
655 // Check the status code of the response: does it match
656 // the expected response(s)?
657 if(logger.isDebugEnabled()){
658 logger.debug(testName + ": status = " + statusCode);
660 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
661 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
662 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
664 // Check whether organization has expected displayName.
665 input = res.getEntity();
667 res.releaseConnection();
670 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
671 client.getItemCommonPartName(), OrganizationsCommon.class);
672 Assert.assertNotNull(organization);
673 String displayName = organization.getDisplayName();
674 // Make sure displayName matches computed form
675 String expectedDisplayName =
676 OrgAuthorityClientUtils.prepareDefaultDisplayName(
677 TEST_ORG_SHORTNAME, TEST_ORG_FOUNDING_PLACE);
678 Assert.assertNotNull(displayName, expectedDisplayName);
680 // Update the shortName and verify the computed name is updated.
681 organization.setCsid(null);
682 organization.setDisplayNameComputed(true);
683 organization.setShortName("updated-" + TEST_ORG_SHORTNAME);
684 expectedDisplayName =
685 OrgAuthorityClientUtils.prepareDefaultDisplayName(
686 "updated-" + TEST_ORG_SHORTNAME, TEST_ORG_FOUNDING_PLACE);
688 // Submit the updated resource to the service and store the response.
689 MultipartOutput output = new MultipartOutput();
690 OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
691 commonPart.getHeaders().add("label", client.getItemCommonPartName());
692 res = client.updateItem(knownResourceId, knownItemResourceId, output);
694 int statusCode = res.getStatus();
696 // Check the status code of the response: does it match the expected response(s)?
697 if(logger.isDebugEnabled()){
698 logger.debug("updateItem: status = " + statusCode);
700 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
701 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
702 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
704 // Retrieve the updated resource and verify that its contents exist.
705 input = (MultipartInput) res.getEntity();
707 res.releaseConnection();
710 OrganizationsCommon updatedOrganization =
711 (OrganizationsCommon) extractPart(input,
712 client.getItemCommonPartName(), OrganizationsCommon.class);
713 Assert.assertNotNull(updatedOrganization);
715 // Verify that the updated resource received the correct data.
716 Assert.assertEquals(updatedOrganization.getShortName(), organization.getShortName(),
717 "Updated ShortName in Organization did not match submitted data.");
718 // Verify that the updated resource computes the right displayName.
719 Assert.assertEquals(updatedOrganization.getDisplayName(), expectedDisplayName,
720 "Updated ShortName in Organization not reflected in computed DisplayName.");
722 // Now Update the displayName, not computed and verify the computed name is overriden.
723 organization.setDisplayNameComputed(false);
724 expectedDisplayName = "TestName";
725 organization.setDisplayName(expectedDisplayName);
727 // Submit the updated resource to the service and store the response.
728 output = new MultipartOutput();
729 commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
730 commonPart.getHeaders().add("label", client.getItemCommonPartName());
731 res = client.updateItem(knownResourceId, knownItemResourceId, output);
733 int statusCode = res.getStatus();
735 // Check the status code of the response: does it match the expected response(s)?
736 if(logger.isDebugEnabled()){
737 logger.debug("updateItem: status = " + statusCode);
739 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
740 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
741 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
743 // Retrieve the updated resource and verify that its contents exist.
744 input = (MultipartInput) res.getEntity();
746 res.releaseConnection();
749 updatedOrganization =
750 (OrganizationsCommon) extractPart(input,
751 client.getItemCommonPartName(), OrganizationsCommon.class);
752 Assert.assertNotNull(updatedOrganization);
754 // Verify that the updated resource received the correct data.
755 Assert.assertEquals(updatedOrganization.isDisplayNameComputed(), false,
756 "Updated displayNameComputed in Organization did not match submitted data.");
757 // Verify that the updated resource computes the right displayName.
758 Assert.assertEquals(updatedOrganization.getDisplayName(),
760 "Updated DisplayName (not computed) in Organization not stored.");
764 * Verify illegal item display name.
766 * @param testName the test name
767 * @throws Exception the exception
769 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
770 dependsOnMethods = {"verifyItemDisplayName"})
771 public void verifyIllegalItemDisplayName(String testName) throws Exception {
774 setupUpdateWithWrongXmlSchema(testName);
776 // Submit the request to the service and store the response.
777 OrgAuthorityClient client = new OrgAuthorityClient();
778 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
779 int statusCode = res.getStatus();
781 // Check the status code of the response: does it match
782 // the expected response(s)?
783 if(logger.isDebugEnabled()){
784 logger.debug(testName + ": status = " + statusCode);
786 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
787 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
788 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
790 // Check whether organization has expected displayName.
791 MultipartInput input = (MultipartInput) res.getEntity();
792 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
793 client.getItemCommonPartName(), OrganizationsCommon.class);
794 Assert.assertNotNull(organization);
795 // Try to Update with computed false and no displayName
796 organization.setDisplayNameComputed(false);
797 organization.setDisplayName(null);
799 // Submit the updated resource to the service and store the response.
800 MultipartOutput output = new MultipartOutput();
801 OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
802 commonPart.getHeaders().add("label", client.getItemCommonPartName());
803 res = client.updateItem(knownResourceId, knownItemResourceId, output);
804 statusCode = res.getStatus();
806 // Check the status code of the response: does it match the expected response(s)?
807 if(logger.isDebugEnabled()){
808 logger.debug("updateItem: status = " + statusCode);
810 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
811 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
812 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
818 * @param testName the test name
819 * @throws Exception the exception
821 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
822 groups = {"read"}, dependsOnMethods = {"readItem"})
823 public void readContact(String testName) throws Exception {
828 // Submit the request to the service and store the response.
829 OrgAuthorityClient client = new OrgAuthorityClient();
830 ClientResponse<MultipartInput> res =
831 client.readContact(knownResourceId, knownItemResourceId,
832 knownContactResourceId);
833 int statusCode = res.getStatus();
835 // Check the status code of the response: does it match
836 // the expected response(s)?
837 if(logger.isDebugEnabled()){
838 logger.debug(testName + ": status = " + statusCode);
840 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
841 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
842 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
844 // Check whether we've received a contact.
845 MultipartInput input = (MultipartInput) res.getEntity();
846 ContactsCommon contact = (ContactsCommon) extractPart(input,
847 new ContactClient().getCommonPartName(), ContactsCommon.class);
848 Assert.assertNotNull(contact);
849 boolean showFull = true;
850 if(showFull && logger.isDebugEnabled()){
851 logger.debug(testName + ": returned payload:");
852 logger.debug(objectAsXmlString(contact, ContactsCommon.class));
854 Assert.assertEquals(contact.getInAuthority(), knownResourceId);
855 Assert.assertEquals(contact.getInItem(), knownItemResourceId);
861 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
864 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
865 groups = {"read"}, dependsOnMethods = {"read"})
866 public void readNonExistent(String testName) {
869 setupReadNonExistent(testName);
871 // Submit the request to the service and store the response.
872 OrgAuthorityClient client = new OrgAuthorityClient();
873 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
874 int statusCode = res.getStatus();
876 // Check the status code of the response: does it match
877 // the expected response(s)?
878 if(logger.isDebugEnabled()){
879 logger.debug(testName + ": status = " + statusCode);
881 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
882 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
883 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
887 * Read item non existent.
889 * @param testName the test name
891 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
892 groups = {"read"}, dependsOnMethods = {"readItem"})
893 public void readItemNonExistent(String testName) {
896 setupReadNonExistent(testName);
898 // Submit the request to the service and store the response.
899 OrgAuthorityClient client = new OrgAuthorityClient();
900 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
901 int statusCode = res.getStatus();
903 // Check the status code of the response: does it match
904 // the expected response(s)?
905 if(logger.isDebugEnabled()){
906 logger.debug(testName + ": status = " + statusCode);
908 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
909 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
910 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
914 * Read contact non existent.
916 * @param testName the test name
918 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
919 groups = {"read"}, dependsOnMethods = {"readContact"})
920 public void readContactNonExistent(String testName) {
923 setupReadNonExistent(testName);
925 // Submit the request to the service and store the response.
926 OrgAuthorityClient client = new OrgAuthorityClient();
927 ClientResponse<MultipartInput> res =
928 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
929 int statusCode = res.getStatus();
931 // Check the status code of the response: does it match
932 // the expected response(s)?
933 if(logger.isDebugEnabled()){
934 logger.debug(testName + ": status = " + statusCode);
936 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
937 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
938 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
941 // ---------------------------------------------------------------
942 // CRUD tests : READ_LIST tests
943 // ---------------------------------------------------------------
947 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
950 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
951 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
952 public void readList(String testName) throws Exception {
955 setupReadList(testName);
957 // Submit the request to the service and store the response.
958 OrgAuthorityClient client = new OrgAuthorityClient();
959 ClientResponse<OrgauthoritiesCommonList> res = client.readList();
960 OrgauthoritiesCommonList list = res.getEntity();
961 int statusCode = res.getStatus();
963 // Check the status code of the response: does it match
964 // the expected response(s)?
965 if(logger.isDebugEnabled()){
966 logger.debug(testName + ": status = " + statusCode);
968 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
969 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
970 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
972 // Optionally output additional data about list members for debugging.
973 boolean iterateThroughList = false;
974 if (iterateThroughList && logger.isDebugEnabled()) {
975 List<OrgauthoritiesCommonList.OrgauthorityListItem> items =
976 list.getOrgauthorityListItem();
978 for (OrgauthoritiesCommonList.OrgauthorityListItem item : items) {
979 String csid = item.getCsid();
980 logger.debug(testName + ": list-item[" + i + "] csid=" +
982 logger.debug(testName + ": list-item[" + i + "] displayName=" +
983 item.getDisplayName());
984 logger.debug(testName + ": list-item[" + i + "] URI=" +
986 readItemList(csid, null);
995 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
996 public void readItemList() {
997 readItemList(knownResourceId, null);
1001 * Read item list by authority name.
1003 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1004 public void readItemListByAuthorityName() {
1005 readItemList(null, knownResourceDisplayName);
1011 * @param vcsid the vcsid
1012 * @param name the name
1014 private void readItemList(String vcsid, String name) {
1016 final String testName = "readItemList";
1019 setupReadList(testName);
1021 // Submit the request to the service and store the response.
1022 OrgAuthorityClient client = new OrgAuthorityClient();
1023 ClientResponse<OrganizationsCommonList> res = null;
1025 res = client.readItemList(vcsid);
1026 } else if(name!= null) {
1027 res = client.readItemListForNamedAuthority(name);
1029 Assert.fail("readItemList passed null csid and name!");
1031 OrganizationsCommonList list = res.getEntity();
1032 int statusCode = res.getStatus();
1034 // Check the status code of the response: does it match
1035 // the expected response(s)?
1036 if(logger.isDebugEnabled()){
1037 logger.debug(testName + ": status = " + statusCode);
1039 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1040 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1041 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1043 List<OrganizationsCommonList.OrganizationListItem> items =
1044 list.getOrganizationListItem();
1045 int nItemsReturned = items.size();
1046 // There will be one item created, associated with a
1047 // known parent resource, by the createItem test.
1049 // In addition, there will be 'nItemsToCreateInList'
1050 // additional items created by the createItemList test,
1051 // all associated with the same parent resource.
1052 int nExpectedItems = nItemsToCreateInList + 1;
1053 if(logger.isDebugEnabled()){
1054 logger.debug(testName + ": Expected "
1055 + nExpectedItems +" items; got: "+nItemsReturned);
1057 Assert.assertEquals(nItemsReturned, nExpectedItems);
1060 for (OrganizationsCommonList.OrganizationListItem item : items) {
1061 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
1062 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
1063 // Optionally output additional data about list members for debugging.
1064 boolean showDetails = true;
1065 if (showDetails && logger.isDebugEnabled()) {
1066 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1068 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
1070 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
1071 item.getDisplayName());
1072 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1080 * Read contact list.
1082 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1083 public void readContactList() {
1084 readContactList(knownResourceId, knownItemResourceId);
1088 * Read contact list.
1090 * @param parentcsid the parentcsid
1091 * @param itemcsid the itemcsid
1093 private void readContactList(String parentcsid, String itemcsid) {
1094 final String testName = "readContactList";
1097 setupReadList(testName);
1099 // Submit the request to the service and store the response.
1100 OrgAuthorityClient client = new OrgAuthorityClient();
1101 ClientResponse<ContactsCommonList> res =
1102 client.readContactList(parentcsid, itemcsid);
1103 ContactsCommonList list = res.getEntity();
1104 int statusCode = res.getStatus();
1106 // Check the status code of the response: does it match
1107 // the expected response(s)?
1108 if(logger.isDebugEnabled()){
1109 logger.debug(testName + ": status = " + statusCode);
1111 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1112 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1113 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1115 List<ContactsCommonList.ContactListItem> listitems =
1116 list.getContactListItem();
1117 int nItemsReturned = listitems.size();
1118 // There will be one item created, associated with a
1119 // known parent resource, by the createItem test.
1121 // In addition, there will be 'nItemsToCreateInList'
1122 // additional items created by the createItemList test,
1123 // all associated with the same parent resource.
1124 int nExpectedItems = nItemsToCreateInList + 1;
1125 if(logger.isDebugEnabled()){
1126 logger.debug(testName + ": Expected "
1127 + nExpectedItems +" items; got: "+nItemsReturned);
1129 Assert.assertEquals(nItemsReturned, nExpectedItems);
1132 for (ContactsCommonList.ContactListItem listitem : listitems) {
1133 // Optionally output additional data about list members for debugging.
1134 boolean showDetails = false;
1135 if (showDetails && logger.isDebugEnabled()) {
1136 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1137 listitem.getCsid());
1138 logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" +
1139 listitem.getAddressPlace());
1140 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1150 // ---------------------------------------------------------------
1151 // CRUD tests : UPDATE tests
1152 // ---------------------------------------------------------------
1155 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
1158 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1159 groups = {"update"}, dependsOnGroups = {"read", "readList"})
1160 public void update(String testName) throws Exception {
1163 setupUpdate(testName);
1165 // Retrieve the contents of a resource to update.
1166 OrgAuthorityClient client = new OrgAuthorityClient();
1167 ClientResponse<MultipartInput> res =
1168 client.read(knownResourceId);
1169 if(logger.isDebugEnabled()){
1170 logger.debug(testName + ": read status = " + res.getStatus());
1172 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1174 if(logger.isDebugEnabled()){
1175 logger.debug("got OrgAuthority to update with ID: " + knownResourceId);
1177 MultipartInput input = (MultipartInput) res.getEntity();
1178 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
1179 client.getCommonPartName(), OrgauthoritiesCommon.class);
1180 Assert.assertNotNull(orgAuthority);
1182 // Update the contents of this resource.
1183 orgAuthority.setDisplayName("updated-" + orgAuthority.getDisplayName());
1184 orgAuthority.setVocabType("updated-" + orgAuthority.getVocabType());
1185 if(logger.isDebugEnabled()){
1186 logger.debug("to be updated OrgAuthority");
1187 logger.debug(objectAsXmlString(orgAuthority, OrgauthoritiesCommon.class));
1190 // Submit the updated resource to the service and store the response.
1191 MultipartOutput output = new MultipartOutput();
1192 OutputPart commonPart = output.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE);
1193 commonPart.getHeaders().add("label", client.getCommonPartName());
1194 res = client.update(knownResourceId, output);
1195 int statusCode = res.getStatus();
1197 // Check the status code of the response: does it match the expected response(s)?
1198 if(logger.isDebugEnabled()){
1199 logger.debug(testName + ": status = " + statusCode);
1201 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1202 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1203 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1205 // Retrieve the updated resource and verify that its contents exist.
1206 input = (MultipartInput) res.getEntity();
1207 OrgauthoritiesCommon updatedOrgAuthority =
1208 (OrgauthoritiesCommon) extractPart(input,
1209 client.getCommonPartName(), OrgauthoritiesCommon.class);
1210 Assert.assertNotNull(updatedOrgAuthority);
1212 // Verify that the updated resource received the correct data.
1213 Assert.assertEquals(updatedOrgAuthority.getDisplayName(),
1214 orgAuthority.getDisplayName(),
1215 "Data in updated object did not match submitted data.");
1221 * @param testName the test name
1222 * @throws Exception the exception
1224 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1225 groups = {"update"}, dependsOnMethods = {"update"})
1226 public void updateItem(String testName) throws Exception {
1229 setupUpdate(testName);
1231 // Retrieve the contents of a resource to update.
1232 OrgAuthorityClient client = new OrgAuthorityClient();
1233 ClientResponse<MultipartInput> res =
1234 client.readItem(knownResourceId, knownItemResourceId);
1235 if(logger.isDebugEnabled()){
1236 logger.debug(testName + ": read status = " + res.getStatus());
1238 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1240 if(logger.isDebugEnabled()){
1241 logger.debug("got Organization to update with ID: " +
1242 knownItemResourceId +
1243 " in OrgAuthority: " + knownResourceId );
1245 MultipartInput input = (MultipartInput) res.getEntity();
1246 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
1247 client.getItemCommonPartName(), OrganizationsCommon.class);
1248 Assert.assertNotNull(organization);
1250 // Update the contents of this resource.
1251 organization.setCsid(null);
1252 organization.setShortName("updated-" + organization.getShortName());
1253 if(logger.isDebugEnabled()){
1254 logger.debug("to be updated Organization");
1255 logger.debug(objectAsXmlString(organization,
1256 OrganizationsCommon.class));
1259 // Submit the updated resource to the service and store the response.
1260 MultipartOutput output = new MultipartOutput();
1261 OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
1262 commonPart.getHeaders().add("label", client.getItemCommonPartName());
1263 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1264 int statusCode = res.getStatus();
1266 // Check the status code of the response: does it match the expected response(s)?
1267 if(logger.isDebugEnabled()){
1268 logger.debug(testName + ": status = " + statusCode);
1270 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1271 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1272 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1274 // Retrieve the updated resource and verify that its contents exist.
1275 input = (MultipartInput) res.getEntity();
1276 OrganizationsCommon updatedOrganization =
1277 (OrganizationsCommon) extractPart(input,
1278 client.getItemCommonPartName(), OrganizationsCommon.class);
1279 Assert.assertNotNull(updatedOrganization);
1281 // Verify that the updated resource received the correct data.
1282 Assert.assertEquals(updatedOrganization.getShortName(),
1283 organization.getShortName(),
1284 "Data in updated Organization did not match submitted data.");
1290 * @param testName the test name
1291 * @throws Exception the exception
1293 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1294 groups = {"update"}, dependsOnMethods = {"updateItem"})
1295 public void updateContact(String testName) throws Exception {
1298 setupUpdate(testName);
1300 // Retrieve the contents of a resource to update.
1301 OrgAuthorityClient client = new OrgAuthorityClient();
1302 ClientResponse<MultipartInput> res =
1303 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1304 if(logger.isDebugEnabled()){
1305 logger.debug(testName + ": read status = " + res.getStatus());
1307 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1309 if(logger.isDebugEnabled()){
1310 logger.debug("got Contact to update with ID: " +
1311 knownContactResourceId +
1312 " in item: " + knownItemResourceId +
1313 " in parent: " + knownResourceId );
1315 MultipartInput input = (MultipartInput) res.getEntity();
1316 ContactsCommon contact = (ContactsCommon) extractPart(input,
1317 new ContactClient().getCommonPartName(), ContactsCommon.class);
1318 Assert.assertNotNull(contact);
1320 // Update the contents of this resource.
1321 contact.setAddressPlace("updated-" + contact.getAddressPlace());
1322 if(logger.isDebugEnabled()){
1323 logger.debug("to be updated Contact");
1324 logger.debug(objectAsXmlString(contact,
1325 ContactsCommon.class));
1328 // Submit the updated resource to the service and store the response.
1329 MultipartOutput output = new MultipartOutput();
1330 OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1331 commonPart.getHeaders().add("label", new ContactClient().getCommonPartName());
1332 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1333 int statusCode = res.getStatus();
1335 // Check the status code of the response: does it match the expected response(s)?
1336 if(logger.isDebugEnabled()){
1337 logger.debug(testName + ": status = " + statusCode);
1339 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1340 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1341 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1343 // Retrieve the updated resource and verify that its contents exist.
1344 input = (MultipartInput) res.getEntity();
1345 ContactsCommon updatedContact =
1346 (ContactsCommon) extractPart(input,
1347 new ContactClient().getCommonPartName(), ContactsCommon.class);
1348 Assert.assertNotNull(updatedContact);
1350 // Verify that the updated resource received the correct data.
1351 Assert.assertEquals(updatedContact.getAddressPlace(),
1352 contact.getAddressPlace(),
1353 "Data in updated Contact did not match submitted data.");
1357 // Placeholders until the three tests below can be uncommented.
1358 // See Issue CSPACE-401.
1360 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1363 public void updateWithEmptyEntityBody(String testName) throws Exception {
1364 //Should this really be empty?
1368 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1371 public void updateWithMalformedXml(String testName) throws Exception {
1372 //Should this really be empty?
1376 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1379 public void updateWithWrongXmlSchema(String testName) throws Exception {
1380 //Should this really be empty?
1385 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1386 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1387 public void updateWithEmptyEntityBody(String testName) throws Exception {
1390 setupUpdateWithEmptyEntityBody(testName);
1392 // Submit the request to the service and store the response.
1393 String method = REQUEST_TYPE.httpMethodName();
1394 String url = getResourceURL(knownResourceId);
1395 String mediaType = MediaType.APPLICATION_XML;
1396 final String entity = "";
1397 int statusCode = submitRequest(method, url, mediaType, entity);
1399 // Check the status code of the response: does it match
1400 // the expected response(s)?
1401 if(logger.isDebugEnabled()){
1402 logger.debug(testName + ": url=" + url +
1403 " status=" + statusCode);
1405 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1406 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1407 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1411 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1412 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1413 public void updateWithMalformedXml(String testName) throws Exception {
1416 setupUpdateWithMalformedXml(testName);
1418 // Submit the request to the service and store the response.
1419 String method = REQUEST_TYPE.httpMethodName();
1420 String url = getResourceURL(knownResourceId);
1421 String mediaType = MediaType.APPLICATION_XML;
1422 final String entity = MALFORMED_XML_DATA;
1423 int statusCode = submitRequest(method, url, mediaType, entity);
1425 // Check the status code of the response: does it match
1426 // the expected response(s)?
1427 if(logger.isDebugEnabled()){
1428 logger.debug(testName + ": url=" + url +
1429 " status=" + statusCode);
1431 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1432 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1433 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1437 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1438 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1439 public void updateWithWrongXmlSchema(String testName) throws Exception {
1442 setupUpdateWithWrongXmlSchema(testName);
1444 // Submit the request to the service and store the response.
1445 String method = REQUEST_TYPE.httpMethodName();
1446 String url = getResourceURL(knownResourceId);
1447 String mediaType = MediaType.APPLICATION_XML;
1448 final String entity = WRONG_XML_SCHEMA_DATA;
1449 int statusCode = submitRequest(method, url, mediaType, entity);
1451 // Check the status code of the response: does it match
1452 // the expected response(s)?
1453 if(logger.isDebugEnabled()){
1454 logger.debug("updateWithWrongXmlSchema: url=" + url +
1455 " status=" + statusCode);
1457 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1458 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1459 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1464 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1467 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1468 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1469 public void updateNonExistent(String testName) throws Exception {
1472 setupUpdateNonExistent(testName);
1474 // Submit the request to the service and store the response.
1475 // Note: The ID used in this 'create' call may be arbitrary.
1476 // The only relevant ID may be the one used in update(), below.
1477 OrgAuthorityClient client = new OrgAuthorityClient();
1478 MultipartOutput multipart = createOrgAuthorityInstance(NON_EXISTENT_ID);
1479 ClientResponse<MultipartInput> res =
1480 client.update(NON_EXISTENT_ID, multipart);
1481 int statusCode = res.getStatus();
1483 // Check the status code of the response: does it match
1484 // the expected response(s)?
1485 if(logger.isDebugEnabled()){
1486 logger.debug(testName + ": status = " + statusCode);
1488 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1489 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1490 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1494 * Update non existent item.
1496 * @param testName the test name
1497 * @throws Exception the exception
1499 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1500 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1501 public void updateNonExistentItem(String testName) throws Exception {
1504 setupUpdateNonExistent(testName);
1506 // Submit the request to the service and store the response.
1507 // Note: The ID(s) used when creating the request payload may be arbitrary.
1508 // The only relevant ID may be the one used in update(), below.
1509 OrgAuthorityClient client = new OrgAuthorityClient();
1510 Map<String, String> nonexOrgMap = new HashMap<String,String>();
1511 nonexOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Non-existent");
1512 String refName = OrgAuthorityClientUtils.createOrganizationRefName(knownResourceRefName, NON_EXISTENT_ID, true);
1513 MultipartOutput multipart =
1514 OrgAuthorityClientUtils.createOrganizationInstance(
1515 NON_EXISTENT_ID, refName,
1516 nonexOrgMap, client.getItemCommonPartName() );
1517 ClientResponse<MultipartInput> res =
1518 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1519 int statusCode = res.getStatus();
1521 // Check the status code of the response: does it match
1522 // the expected response(s)?
1523 if(logger.isDebugEnabled()){
1524 logger.debug(testName + ": status = " + statusCode);
1526 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1527 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1528 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1532 * Update non existent contact.
1534 * @param testName the test name
1535 * @throws Exception the exception
1537 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1538 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1539 public void updateNonExistentContact(String testName) throws Exception {
1540 // Currently a no-op test
1543 // ---------------------------------------------------------------
1544 // CRUD tests : DELETE tests
1545 // ---------------------------------------------------------------
1548 // Note: delete sub-resources in ascending hierarchical order,
1549 // before deleting their parents.
1554 * @param testName the test name
1555 * @throws Exception the exception
1557 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1558 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1559 public void deleteContact(String testName) throws Exception {
1562 setupDelete(testName);
1564 if(logger.isDebugEnabled()){
1565 logger.debug("parentcsid =" + knownResourceId +
1566 " itemcsid = " + knownItemResourceId +
1567 " csid = " + knownContactResourceId);
1570 // Submit the request to the service and store the response.
1571 OrgAuthorityClient client = new OrgAuthorityClient();
1572 ClientResponse<Response> res =
1573 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1574 int statusCode = res.getStatus();
1576 // Check the status code of the response: does it match
1577 // the expected response(s)?
1578 if(logger.isDebugEnabled()){
1579 logger.debug(testName + ": status = " + statusCode);
1581 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1582 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1583 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1589 * @param testName the test name
1590 * @throws Exception the exception
1592 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1593 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1594 public void deleteItem(String testName) throws Exception {
1597 setupDelete(testName);
1599 if(logger.isDebugEnabled()){
1600 logger.debug("parentcsid =" + knownResourceId +
1601 " itemcsid = " + knownItemResourceId);
1604 // Submit the request to the service and store the response.
1605 OrgAuthorityClient client = new OrgAuthorityClient();
1606 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1607 int statusCode = res.getStatus();
1609 // Check the status code of the response: does it match
1610 // the expected response(s)?
1611 if(logger.isDebugEnabled()){
1612 logger.debug(testName + ": status = " + statusCode);
1614 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1615 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1616 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1620 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1623 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1624 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1625 public void delete(String testName) throws Exception {
1628 setupDelete(testName);
1630 if(logger.isDebugEnabled()){
1631 logger.debug("parentcsid =" + knownResourceId);
1634 // Submit the request to the service and store the response.
1635 OrgAuthorityClient client = new OrgAuthorityClient();
1636 ClientResponse<Response> res = client.delete(knownResourceId);
1637 int statusCode = res.getStatus();
1639 // Check the status code of the response: does it match
1640 // the expected response(s)?
1641 if(logger.isDebugEnabled()){
1642 logger.debug(testName + ": status = " + statusCode);
1644 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1645 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1646 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1651 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1654 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1655 groups = {"delete"}, dependsOnMethods = {"delete"})
1656 public void deleteNonExistent(String testName) throws Exception {
1659 setupDeleteNonExistent(testName);
1661 // Submit the request to the service and store the response.
1662 OrgAuthorityClient client = new OrgAuthorityClient();
1663 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1664 int statusCode = res.getStatus();
1666 // Check the status code of the response: does it match
1667 // the expected response(s)?
1668 if(logger.isDebugEnabled()){
1669 logger.debug(testName + ": status = " + statusCode);
1671 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1672 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1673 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1677 * Delete non existent item.
1679 * @param testName the test name
1681 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1682 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1683 public void deleteNonExistentItem(String testName) {
1686 setupDeleteNonExistent(testName);
1688 // Submit the request to the service and store the response.
1689 OrgAuthorityClient client = new OrgAuthorityClient();
1690 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1691 int statusCode = res.getStatus();
1693 // Check the status code of the response: does it match
1694 // the expected response(s)?
1695 if(logger.isDebugEnabled()){
1696 logger.debug(testName + ": status = " + statusCode);
1698 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1699 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1700 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1704 * Delete non existent contact.
1706 * @param testName the test name
1708 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1709 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1710 public void deleteNonExistentContact(String testName) {
1713 setupDeleteNonExistent(testName);
1715 // Submit the request to the service and store the response.
1716 OrgAuthorityClient client = new OrgAuthorityClient();
1717 ClientResponse<Response> res =
1718 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1719 int statusCode = res.getStatus();
1721 // Check the status code of the response: does it match
1722 // the expected response(s)?
1723 if(logger.isDebugEnabled()){
1724 logger.debug(testName + ": status = " + statusCode);
1726 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1727 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1728 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1731 // ---------------------------------------------------------------
1732 // Utility tests : tests of code used in tests above
1733 // ---------------------------------------------------------------
1735 * Tests the code for manually submitting data that is used by several
1736 * of the methods above.
1738 @Test(dependsOnMethods = {"create", "read"})
1739 public void testSubmitRequest() {
1741 // Expected status code: 200 OK
1742 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1744 // Submit the request to the service and store the response.
1745 String method = ServiceRequestType.READ.httpMethodName();
1746 String url = getResourceURL(knownResourceId);
1747 int statusCode = submitRequest(method, url);
1749 // Check the status code of the response: does it match
1750 // the expected response(s)?
1751 if(logger.isDebugEnabled()){
1752 logger.debug("testSubmitRequest: url=" + url +
1753 " status=" + statusCode);
1755 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1760 * Test item submit request.
1762 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1763 public void testItemSubmitRequest() {
1765 // Expected status code: 200 OK
1766 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1768 // Submit the request to the service and store the response.
1769 String method = ServiceRequestType.READ.httpMethodName();
1770 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1771 int statusCode = submitRequest(method, url);
1773 // Check the status code of the response: does it match
1774 // the expected response(s)?
1775 if(logger.isDebugEnabled()){
1776 logger.debug("testItemSubmitRequest: url=" + url +
1777 " status=" + statusCode);
1779 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1784 * Test contact submit request.
1786 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
1787 public void testContactSubmitRequest() {
1789 // Expected status code: 200 OK
1790 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1792 // Submit the request to the service and store the response.
1793 String method = ServiceRequestType.READ.httpMethodName();
1794 String url = getContactResourceURL(knownResourceId,
1795 knownItemResourceId, knownContactResourceId);
1796 int statusCode = submitRequest(method, url);
1798 // Check the status code of the response: does it match
1799 // the expected response(s)?
1800 if(logger.isDebugEnabled()){
1801 logger.debug("testItemSubmitRequest: url=" + url +
1802 " status=" + statusCode);
1804 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1809 // ---------------------------------------------------------------
1810 // Cleanup of resources created during testing
1811 // ---------------------------------------------------------------
1814 * Deletes all resources created by tests, after all tests have been run.
1816 * This cleanup method will always be run, even if one or more tests fail.
1817 * For this reason, it attempts to remove all resources created
1818 * at any point during testing, even if some of those resources
1819 * may be expected to be deleted by certain tests.
1822 @AfterClass(alwaysRun=true)
1824 public void cleanUp() {
1825 String noTest = System.getProperty("noTestCleanup");
1826 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1827 if (logger.isDebugEnabled()) {
1828 logger.debug("Skipping Cleanup phase ...");
1832 if (logger.isDebugEnabled()) {
1833 logger.debug("Cleaning up temporary resources created for testing ...");
1836 String parentResourceId;
1837 String itemResourceId;
1838 String contactResourceId;
1839 // Clean up contact resources.
1840 parentResourceId = knownResourceId;
1841 OrgAuthorityClient client = new OrgAuthorityClient();
1842 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
1843 contactResourceId = entry.getKey();
1844 itemResourceId = entry.getValue();
1845 // Note: Any non-success responses from the delete operation
1846 // below are ignored and not reported.
1847 ClientResponse<Response> res =
1848 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
1849 res.releaseConnection();
1851 // Clean up item resources.
1852 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1853 itemResourceId = entry.getKey();
1854 parentResourceId = entry.getValue();
1855 // Note: Any non-success responses from the delete operation
1856 // below are ignored and not reported.
1857 ClientResponse<Response> res =
1858 client.deleteItem(parentResourceId, itemResourceId);
1859 res.releaseConnection();
1861 // Clean up parent resources.
1866 // ---------------------------------------------------------------
1867 // Utility methods used by tests above
1868 // ---------------------------------------------------------------
1870 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
1873 public String getServicePathComponent() {
1874 return SERVICE_PATH_COMPONENT;
1878 * Gets the item service path component.
1880 * @return the item service path component
1882 public String getItemServicePathComponent() {
1883 return ITEM_SERVICE_PATH_COMPONENT;
1887 * Gets the contact service path component.
1889 * @return the contact service path component
1891 public String getContactServicePathComponent() {
1892 return CONTACT_SERVICE_PATH_COMPONENT;
1896 * Returns the root URL for the item service.
1898 * This URL consists of a base URL for all services, followed by
1899 * a path component for the owning parent, followed by the
1900 * path component for the items.
1902 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1903 * parent authority resource of the relevant item resource.
1905 * @return The root URL for the item service.
1907 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1908 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1912 * Returns the URL of a specific item resource managed by a service, and
1913 * designated by an identifier (such as a universally unique ID, or UUID).
1915 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1916 * parent authority resource of the relevant item resource.
1918 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1921 * @return The URL of a specific item resource managed by a service.
1923 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1924 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
1929 * Returns the root URL for the contact service.
1931 * This URL consists of a base URL for all services, followed by
1932 * a path component for the owning authority, followed by the
1933 * path component for the owning item, followed by the path component
1934 * for the contact service.
1936 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1937 * parent authority resource of the relevant item resource.
1939 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1942 * @return The root URL for the contact service.
1944 protected String getContactServiceRootURL(String parentResourceIdentifier,
1945 String itemResourceIdentifier) {
1946 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
1947 getContactServicePathComponent();
1951 * Returns the URL of a specific contact resource managed by a service, and
1952 * designated by an identifier (such as a universally unique ID, or UUID).
1954 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1955 * parent resource of the relevant item resource.
1957 * @param resourceIdentifier An identifier (such as a UUID) for an
1960 * @return The URL of a specific resource managed by a service.
1962 protected String getContactResourceURL(String parentResourceIdentifier,
1963 String itemResourceIdentifier, String contactResourceIdentifier) {
1964 return getContactServiceRootURL(parentResourceIdentifier,
1965 itemResourceIdentifier) + "/" + contactResourceIdentifier;
1969 * Creates the org authority instance.
1971 * @param identifier the identifier
1972 * @return the multipart output
1974 private MultipartOutput createOrgAuthorityInstance(String identifier) {
1975 String displayName = "displayName-" + identifier;
1976 String refName = OrgAuthorityClientUtils.createOrgAuthRefName(displayName, true);
1977 return OrgAuthorityClientUtils.createOrgAuthorityInstance(
1978 displayName, refName,
1979 new OrgAuthorityClient().getCommonPartName());