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.PersonJAXBSchema;
33 import org.collectionspace.services.client.CollectionSpaceClient;
34 import org.collectionspace.services.client.ContactClient;
35 import org.collectionspace.services.client.ContactClientUtils;
36 import org.collectionspace.services.contact.ContactsCommon;
37 import org.collectionspace.services.contact.ContactsCommonList;
38 import org.collectionspace.services.client.PersonAuthorityClient;
39 import org.collectionspace.services.client.PersonAuthorityClientUtils;
40 import org.collectionspace.services.jaxb.AbstractCommonList;
41 import org.collectionspace.services.person.PersonauthoritiesCommon;
42 import org.collectionspace.services.person.PersonauthoritiesCommonList;
43 import org.collectionspace.services.person.PersonsCommon;
44 import org.collectionspace.services.person.PersonsCommonList;
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 * PersonAuthorityServiceTest, carries out tests against a
57 * deployed and running PersonAuthority Service.
59 * $LastChangedRevision: 753 $
60 * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
62 public class PersonAuthorityServiceTest extends AbstractServiceTestImpl {
65 private final Logger logger =
66 LoggerFactory.getLogger(PersonAuthorityServiceTest.class);
68 // Instance variables specific to this test.
69 /** The SERVIC e_ pat h_ component. */
70 final String SERVICE_PATH_COMPONENT = "personauthorities";
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_ for e_ name. */
79 final String TEST_FORE_NAME = "John";
81 /** The TES t_ middl e_ name. */
82 final String TEST_MIDDLE_NAME = null;
84 /** The TES t_ su r_ name. */
85 final String TEST_SUR_NAME = "Wayne";
87 /** The TES t_ birt h_ date. */
88 final String TEST_BIRTH_DATE = "May 26, 1907";
90 /** The TES t_ deat h_ date. */
91 final String TEST_DEATH_DATE = "June 11, 1979";
93 /** The known resource id. */
94 private String knownResourceId = null;
96 /** The known resource display name. */
97 private String knownResourceDisplayName = null;
99 /** The known resource ref name. */
100 private String knownResourceRefName = null;
102 /** The known item resource id. */
103 private String knownItemResourceId = null;
105 /** The known contact resource id. */
106 private String knownContactResourceId = null;
108 /** The n items to create in list. */
109 private int nItemsToCreateInList = 3;
111 /** The all resource ids created. */
112 private List<String> allResourceIdsCreated = new ArrayList<String>();
114 /** The all item resource ids created. */
115 private Map<String, String> allItemResourceIdsCreated =
116 new HashMap<String, String>();
118 /** The all contact resource ids created. */
119 private Map<String, String> allContactResourceIdsCreated =
120 new HashMap<String, String>();
123 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
126 protected CollectionSpaceClient getClientInstance() {
127 return new PersonAuthorityClient();
131 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
134 protected AbstractCommonList getAbstractCommonList(
135 ClientResponse<AbstractCommonList> response) {
136 return response.getEntity(PersonsCommonList.class);
139 // ---------------------------------------------------------------
140 // CRUD tests : CREATE tests
141 // ---------------------------------------------------------------
144 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
147 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
149 public void create(String testName) throws Exception {
151 // Perform setup, such as initializing the type of service request
152 // (e.g. CREATE, DELETE), its valid and expected status codes, and
153 // its associated HTTP method name (e.g. POST, DELETE).
154 setupCreate(testName);
156 // Submit the request to the service and store the response.
157 PersonAuthorityClient client = new PersonAuthorityClient();
158 String identifier = createIdentifier();
159 String displayName = "displayName-" + identifier;
160 String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, false);
161 String fullRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, true);
162 MultipartOutput multipart =
163 PersonAuthorityClientUtils.createPersonAuthorityInstance(
164 displayName, fullRefName, client.getCommonPartName());
165 ClientResponse<Response> res = client.create(multipart);
166 int statusCode = res.getStatus();
168 // Check the status code of the response: does it match
169 // the expected response(s)?
172 // Does it fall within the set of valid status codes?
173 // Does it exactly match the expected status code?
174 if(logger.isDebugEnabled()){
175 logger.debug(testName + ": status = " + statusCode);
177 Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
178 invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
179 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
181 // Store the refname from the first resource created
182 // for additional tests below.
183 knownResourceRefName = baseRefName;
185 String newID = PersonAuthorityClientUtils.extractId(res);
186 // Store the ID returned from the first resource created
187 // for additional tests below.
188 if (knownResourceId == null){
189 knownResourceId = newID;
190 knownResourceDisplayName = displayName;
191 if (logger.isDebugEnabled()) {
192 logger.debug(testName + ": knownResourceId=" + knownResourceId);
195 // Store the IDs from every resource created by tests,
196 // so they can be deleted after tests have been run.
197 allResourceIdsCreated.add(newID);
203 * @param testName the test name
205 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
206 groups = {"create"}, dependsOnMethods = {"create"})
207 public void createItem(String testName) {
208 setupCreate(testName);
209 String newID = createItemInAuthority(knownResourceId, knownResourceRefName);
213 * Creates the item in authority.
215 * @param vcsid the vcsid
216 * @param authRefName the auth ref name
219 private String createItemInAuthority(String vcsid, String authRefName) {
221 final String testName = "createItemInAuthority";
222 if(logger.isDebugEnabled()){
223 logger.debug(testName + ":...");
226 // Submit the request to the service and store the response.
227 PersonAuthorityClient client = new PersonAuthorityClient();
228 String identifier = createIdentifier();
229 String refName = PersonAuthorityClientUtils.createPersonRefName(authRefName, "John Wayne", true);
230 Map<String, String> johnWayneMap = new HashMap<String,String>();
231 johnWayneMap.put(PersonJAXBSchema.FORE_NAME, TEST_FORE_NAME);
232 johnWayneMap.put(PersonJAXBSchema.SUR_NAME, TEST_SUR_NAME);
233 johnWayneMap.put(PersonJAXBSchema.GENDER, "male");
234 johnWayneMap.put(PersonJAXBSchema.BIRTH_DATE, TEST_BIRTH_DATE);
235 johnWayneMap.put(PersonJAXBSchema.BIRTH_PLACE, "Winterset, Iowa");
236 johnWayneMap.put(PersonJAXBSchema.DEATH_DATE, TEST_DEATH_DATE);
237 johnWayneMap.put(PersonJAXBSchema.BIO_NOTE, "born Marion Robert Morrison and better" +
238 "known by his stage name John Wayne, was an American film actor, director " +
239 "and producer. He epitomized rugged masculinity and has become an enduring " +
240 "American icon. He is famous for his distinctive voice, walk and height. " +
241 "He was also known for his conservative political views and his support in " +
242 "the 1950s for anti-communist positions.");
243 MultipartOutput multipart =
244 PersonAuthorityClientUtils.createPersonInstance(vcsid, refName, johnWayneMap,
245 client.getItemCommonPartName() );
246 ClientResponse<Response> res = client.createItem(vcsid, multipart);
247 int statusCode = res.getStatus();
248 String newID = PersonAuthorityClientUtils.extractId(res);
250 // Check the status code of the response: does it match
251 // the expected response(s)?
252 if(logger.isDebugEnabled()){
253 logger.debug(testName + ": status = " + statusCode);
255 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
256 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
257 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
259 // Store the ID returned from the first item resource created
260 // for additional tests below.
261 if (knownItemResourceId == null){
262 knownItemResourceId = newID;
263 if (logger.isDebugEnabled()) {
264 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
268 // Store the IDs from any item resources created
269 // by tests, along with the IDs of their parents, so these items
270 // can be deleted after all tests have been run.
271 allItemResourceIdsCreated.put(newID, vcsid);
277 * Creates the contact.
279 * @param testName the test name
281 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
282 groups = {"create"}, dependsOnMethods = {"createItem"})
283 public void createContact(String testName) {
284 setupCreate(testName);
285 String newID = createContactInItem(knownResourceId, knownItemResourceId);
289 * Creates the contact in item.
291 * @param parentcsid the parentcsid
292 * @param itemcsid the itemcsid
295 private String createContactInItem(String parentcsid, String itemcsid) {
297 final String testName = "createContactInItem";
298 setupCreate(testName);
299 if(logger.isDebugEnabled()){
300 logger.debug(testName + ":...");
303 // Submit the request to the service and store the response.
304 PersonAuthorityClient client = new PersonAuthorityClient();
305 String identifier = createIdentifier();
306 MultipartOutput multipart =
307 ContactClientUtils.createContactInstance(parentcsid,
308 itemcsid, identifier, new ContactClient().getCommonPartName());
309 ClientResponse<Response> res =
310 client.createContact(parentcsid, itemcsid, multipart);
311 int statusCode = res.getStatus();
312 String newID = PersonAuthorityClientUtils.extractId(res);
314 // Check the status code of the response: does it match
315 // the expected response(s)?
316 if(logger.isDebugEnabled()){
317 logger.debug(testName + ": status = " + statusCode);
319 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
320 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
321 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
323 // Store the ID returned from the first contact resource created
324 // for additional tests below.
325 if (knownContactResourceId == null){
326 knownContactResourceId = newID;
327 if (logger.isDebugEnabled()) {
328 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
332 // Store the IDs from any contact resources created
333 // by tests, along with the IDs of their parent items,
334 // so these items can be deleted after all tests have been run.
335 allContactResourceIdsCreated.put(newID, itemcsid);
342 // Placeholders until the three tests below can be uncommented.
343 // See Issue CSPACE-401.
345 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
348 public void createWithEmptyEntityBody(String testName) throws Exception {
352 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
355 public void createWithMalformedXml(String testName) throws Exception {
359 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
362 public void createWithWrongXmlSchema(String testName) throws Exception {
367 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
368 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
369 public void createWithEmptyEntityBody(String testName) throws Exception {
372 setupCreateWithEmptyEntityBody(testName);
374 // Submit the request to the service and store the response.
375 String method = REQUEST_TYPE.httpMethodName();
376 String url = getServiceRootURL();
377 String mediaType = MediaType.APPLICATION_XML;
378 final String entity = "";
379 int statusCode = submitRequest(method, url, mediaType, entity);
381 // Check the status code of the response: does it match
382 // the expected response(s)?
383 if(logger.isDebugEnabled()) {
384 logger.debug(testName + ": url=" + url +
385 " status=" + statusCode);
387 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
388 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
389 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
393 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
394 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
395 public void createWithMalformedXml(String testName) throws Exception {
398 setupCreateWithMalformedXml(testName);
400 // Submit the request to the service and store the response.
401 String method = REQUEST_TYPE.httpMethodName();
402 String url = getServiceRootURL();
403 String mediaType = MediaType.APPLICATION_XML;
404 final String entity = MALFORMED_XML_DATA; // Constant from base class.
405 int statusCode = submitRequest(method, url, mediaType, entity);
407 // Check the status code of the response: does it match
408 // the expected response(s)?
409 if(logger.isDebugEnabled()){
410 logger.debug(testName + ": url=" + url +
411 " status=" + statusCode);
413 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
414 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
415 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
419 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
420 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
421 public void createWithWrongXmlSchema(String testName) throws Exception {
424 setupCreateWithWrongXmlSchema(testName);
426 // Submit the request to the service and store the response.
427 String method = REQUEST_TYPE.httpMethodName();
428 String url = getServiceRootURL();
429 String mediaType = MediaType.APPLICATION_XML;
430 final String entity = WRONG_XML_SCHEMA_DATA;
431 int statusCode = submitRequest(method, url, mediaType, entity);
433 // Check the status code of the response: does it match
434 // the expected response(s)?
435 if(logger.isDebugEnabled()){
436 logger.debug(testName + ": url=" + url +
437 " status=" + statusCode);
439 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
440 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
441 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
445 // ---------------------------------------------------------------
446 // CRUD tests : CREATE LIST tests
447 // ---------------------------------------------------------------
450 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
453 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
454 groups = {"createList"}, dependsOnGroups = {"create"})
455 public void createList(String testName) throws Exception {
456 for (int i = 0; i < nItemsToCreateInList; i++) {
462 * Creates the item list.
464 * @param testName the test name
465 * @throws Exception the exception
467 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
468 groups = {"createList"}, dependsOnMethods = {"createList"})
469 public void createItemList(String testName) throws Exception {
470 // Add items to the initially-created, known parent record.
471 for (int j = 0; j < nItemsToCreateInList; j++) {
472 createItem(testName);
477 * Creates the contact list.
479 * @param testName the test name
480 * @throws Exception the exception
482 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
483 groups = {"createList"}, dependsOnMethods = {"createItemList"})
484 public void createContactList(String testName) throws Exception {
485 // Add contacts to the initially-created, known item record.
486 for (int j = 0; j < nItemsToCreateInList; j++) {
487 createContact(testName);
491 // ---------------------------------------------------------------
492 // CRUD tests : READ tests
493 // ---------------------------------------------------------------
496 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
499 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
500 groups = {"read"}, dependsOnGroups = {"create"})
501 public void read(String testName) throws Exception {
506 // Submit the request to the service and store the response.
507 PersonAuthorityClient client = new PersonAuthorityClient();
508 ClientResponse<MultipartInput> res = client.read(knownResourceId);
509 int statusCode = res.getStatus();
511 // Check the status code of the response: does it match
512 // the expected response(s)?
513 if(logger.isDebugEnabled()){
514 logger.debug(testName + ": status = " + statusCode);
516 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
517 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
518 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
519 //FIXME: remove the following try catch once Aron fixes signatures
521 MultipartInput input = (MultipartInput) res.getEntity();
522 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
523 client.getCommonPartName(), PersonauthoritiesCommon.class);
524 Assert.assertNotNull(personAuthority);
525 } catch (Exception e) {
526 throw new RuntimeException(e);
533 * @param testName the test name
534 * @throws Exception the exception
536 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
537 groups = {"read"}, dependsOnGroups = {"create"})
538 public void readByName(String testName) throws Exception {
543 // Submit the request to the service and store the response.
544 PersonAuthorityClient client = new PersonAuthorityClient();
545 ClientResponse<MultipartInput> res = client.readByName(knownResourceDisplayName);
546 int statusCode = res.getStatus();
548 // Check the status code of the response: does it match
549 // the expected response(s)?
550 if(logger.isDebugEnabled()){
551 logger.debug(testName + ": status = " + statusCode);
553 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
554 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
555 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
556 //FIXME: remove the following try catch once Aron fixes signatures
558 MultipartInput input = (MultipartInput) res.getEntity();
559 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
560 client.getCommonPartName(), PersonauthoritiesCommon.class);
561 Assert.assertNotNull(personAuthority);
562 } catch (Exception e) {
563 throw new RuntimeException(e);
568 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
569 groups = {"read"}, dependsOnMethods = {"read"})
570 public void readByName(String testName) throws Exception {
575 // Submit the request to the service and store the response.
576 ClientResponse<MultipartInput> res = client.read(knownResourceId);
577 int statusCode = res.getStatus();
579 // Check the status code of the response: does it match
580 // the expected response(s)?
581 if(logger.isDebugEnabled()){
582 logger.debug(testName + ": status = " + statusCode);
584 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
585 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
586 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
587 //FIXME: remove the following try catch once Aron fixes signatures
589 MultipartInput input = (MultipartInput) res.getEntity();
590 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
591 client.getCommonPartName(), PersonauthoritiesCommon.class);
592 Assert.assertNotNull(personAuthority);
593 } catch (Exception e) {
594 throw new RuntimeException(e);
602 * @param testName the test name
603 * @throws Exception the exception
605 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
606 groups = {"read"}, dependsOnMethods = {"read"})
607 public void readItem(String testName) throws Exception {
612 // Submit the request to the service and store the response.
613 PersonAuthorityClient client = new PersonAuthorityClient();
614 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
615 int statusCode = res.getStatus();
617 // Check the status code of the response: does it match
618 // the expected response(s)?
619 if(logger.isDebugEnabled()){
620 logger.debug(testName + ": status = " + statusCode);
622 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
623 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
624 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
626 // Check whether we've received a person.
627 MultipartInput input = (MultipartInput) res.getEntity();
628 PersonsCommon person = (PersonsCommon) extractPart(input,
629 client.getItemCommonPartName(), PersonsCommon.class);
630 Assert.assertNotNull(person);
631 boolean showFull = true;
632 if(showFull && logger.isDebugEnabled()){
633 logger.debug(testName + ": returned payload:");
634 logger.debug(objectAsXmlString(person, PersonsCommon.class));
636 Assert.assertEquals(person.getInAuthority(), knownResourceId);
641 * Verify item display name.
643 * @param testName the test name
644 * @throws Exception the exception
646 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
647 dependsOnMethods = {"readItem", "updateItem"})
648 public void verifyItemDisplayName(String testName) throws Exception {
651 setupUpdate(testName);
653 // Submit the request to the service and store the response.
654 PersonAuthorityClient client = new PersonAuthorityClient();
655 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
656 int statusCode = res.getStatus();
658 // Check the status code of the response: does it match
659 // the expected response(s)?
660 if(logger.isDebugEnabled()){
661 logger.debug(testName + ": status = " + statusCode);
663 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
664 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
665 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
667 // Check whether person has expected displayName.
668 MultipartInput input = (MultipartInput) res.getEntity();
669 PersonsCommon person = (PersonsCommon) extractPart(input,
670 client.getItemCommonPartName(), PersonsCommon.class);
671 Assert.assertNotNull(person);
672 String displayName = person.getDisplayName();
673 // Make sure displayName matches computed form
674 String expectedDisplayName =
675 PersonAuthorityClientUtils.prepareDefaultDisplayName(
676 TEST_FORE_NAME, null, TEST_SUR_NAME,
677 TEST_BIRTH_DATE, TEST_DEATH_DATE);
678 Assert.assertNotNull(displayName, expectedDisplayName);
680 // Update the shortName and verify the computed name is updated.
681 person.setCsid(null);
682 person.setDisplayNameComputed(true);
683 person.setForeName("updated-" + TEST_FORE_NAME);
684 expectedDisplayName =
685 PersonAuthorityClientUtils.prepareDefaultDisplayName(
686 "updated-" + TEST_FORE_NAME, null, TEST_SUR_NAME,
687 TEST_BIRTH_DATE, TEST_DEATH_DATE);
689 // Submit the updated resource to the service and store the response.
690 MultipartOutput output = new MultipartOutput();
691 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
692 commonPart.getHeaders().add("label", client.getItemCommonPartName());
693 res = client.updateItem(knownResourceId, knownItemResourceId, output);
694 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();
706 PersonsCommon updatedPerson =
707 (PersonsCommon) extractPart(input,
708 client.getItemCommonPartName(), PersonsCommon.class);
709 Assert.assertNotNull(updatedPerson);
711 // Verify that the updated resource received the correct data.
712 Assert.assertEquals(updatedPerson.getForeName(), person.getForeName(),
713 "Updated ForeName in Person did not match submitted data.");
714 // Verify that the updated resource computes the right displayName.
715 Assert.assertEquals(updatedPerson.getDisplayName(), expectedDisplayName,
716 "Updated ForeName in Person not reflected in computed DisplayName.");
718 // Now Update the displayName, not computed and verify the computed name is overriden.
719 person.setDisplayNameComputed(false);
720 expectedDisplayName = "TestName";
721 person.setDisplayName(expectedDisplayName);
723 // Submit the updated resource to the service and store the response.
724 output = new MultipartOutput();
725 commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
726 commonPart.getHeaders().add("label", client.getItemCommonPartName());
727 res = client.updateItem(knownResourceId, knownItemResourceId, output);
728 statusCode = res.getStatus();
730 // Check the status code of the response: does it match the expected response(s)?
731 if(logger.isDebugEnabled()){
732 logger.debug("updateItem: status = " + statusCode);
734 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
735 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
736 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
738 // Retrieve the updated resource and verify that its contents exist.
739 input = (MultipartInput) res.getEntity();
741 (PersonsCommon) extractPart(input,
742 client.getItemCommonPartName(), PersonsCommon.class);
743 Assert.assertNotNull(updatedPerson);
745 // Verify that the updated resource received the correct data.
746 Assert.assertEquals(updatedPerson.isDisplayNameComputed(), false,
747 "Updated displayNameComputed in Person did not match submitted data.");
748 // Verify that the updated resource computes the right displayName.
749 Assert.assertEquals(updatedPerson.getDisplayName(),
751 "Updated DisplayName (not computed) in Person not stored.");
755 * Verify illegal item display name.
757 * @param testName the test name
758 * @throws Exception the exception
760 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
761 dependsOnMethods = {"verifyItemDisplayName"})
762 public void verifyIllegalItemDisplayName(String testName) throws Exception {
765 setupUpdateWithWrongXmlSchema(testName);
767 // Submit the request to the service and store the response.
768 PersonAuthorityClient client = new PersonAuthorityClient();
769 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
770 int statusCode = res.getStatus();
772 // Check the status code of the response: does it match
773 // the expected response(s)?
774 if(logger.isDebugEnabled()){
775 logger.debug(testName + ": status = " + statusCode);
777 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
778 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
779 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
781 // Check whether Person has expected displayName.
782 MultipartInput input = (MultipartInput) res.getEntity();
783 PersonsCommon person = (PersonsCommon) extractPart(input,
784 client.getItemCommonPartName(), PersonsCommon.class);
785 Assert.assertNotNull(person);
786 // Try to Update with computed false and no displayName
787 person.setDisplayNameComputed(false);
788 person.setDisplayName(null);
790 // Submit the updated resource to the service and store the response.
791 MultipartOutput output = new MultipartOutput();
792 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
793 commonPart.getHeaders().add("label", client.getItemCommonPartName());
794 res = client.updateItem(knownResourceId, knownItemResourceId, output);
795 statusCode = res.getStatus();
797 // Check the status code of the response: does it match the expected response(s)?
798 if(logger.isDebugEnabled()){
799 logger.debug("updateItem: status = " + statusCode);
801 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
802 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
803 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
809 * @param testName the test name
810 * @throws Exception the exception
812 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
813 groups = {"read"}, dependsOnMethods = {"readItem"})
814 public void readContact(String testName) throws Exception {
819 // Submit the request to the service and store the response.
820 PersonAuthorityClient client = new PersonAuthorityClient();
821 ClientResponse<MultipartInput> res =
822 client.readContact(knownResourceId, knownItemResourceId,
823 knownContactResourceId);
824 int statusCode = res.getStatus();
826 // Check the status code of the response: does it match
827 // the expected response(s)?
828 if(logger.isDebugEnabled()){
829 logger.debug(testName + ": status = " + statusCode);
831 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
832 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
833 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
835 // Check whether we've received a contact.
836 MultipartInput input = (MultipartInput) res.getEntity();
837 ContactsCommon contact = (ContactsCommon) extractPart(input,
838 new ContactClient().getCommonPartName(), ContactsCommon.class);
839 Assert.assertNotNull(contact);
840 boolean showFull = true;
841 if(showFull && logger.isDebugEnabled()){
842 logger.debug(testName + ": returned payload:");
843 logger.debug(objectAsXmlString(contact, ContactsCommon.class));
845 Assert.assertEquals(contact.getInAuthority(), knownResourceId);
846 Assert.assertEquals(contact.getInItem(), knownItemResourceId);
852 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
855 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
856 groups = {"read"}, dependsOnMethods = {"read"})
857 public void readNonExistent(String testName) {
860 setupReadNonExistent(testName);
862 // Submit the request to the service and store the response.
863 PersonAuthorityClient client = new PersonAuthorityClient();
864 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
865 int statusCode = res.getStatus();
867 // Check the status code of the response: does it match
868 // the expected response(s)?
869 if(logger.isDebugEnabled()){
870 logger.debug(testName + ": status = " + statusCode);
872 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
873 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
874 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
878 * Read item non existent.
880 * @param testName the test name
882 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
883 groups = {"read"}, dependsOnMethods = {"readItem"})
884 public void readItemNonExistent(String testName) {
887 setupReadNonExistent(testName);
889 // Submit the request to the service and store the response.
890 PersonAuthorityClient client = new PersonAuthorityClient();
891 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
892 int statusCode = res.getStatus();
894 // Check the status code of the response: does it match
895 // the expected response(s)?
896 if(logger.isDebugEnabled()){
897 logger.debug(testName + ": status = " + statusCode);
899 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
900 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
901 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
905 * Read contact non existent.
907 * @param testName the test name
909 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
910 groups = {"read"}, dependsOnMethods = {"readContact"})
911 public void readContactNonExistent(String testName) {
914 setupReadNonExistent(testName);
916 // Submit the request to the service and store the response.
917 PersonAuthorityClient client = new PersonAuthorityClient();
918 ClientResponse<MultipartInput> res =
919 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
920 int statusCode = res.getStatus();
922 // Check the status code of the response: does it match
923 // the expected response(s)?
924 if(logger.isDebugEnabled()){
925 logger.debug(testName + ": status = " + statusCode);
927 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
928 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
929 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
932 // ---------------------------------------------------------------
933 // CRUD tests : READ_LIST tests
934 // ---------------------------------------------------------------
938 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
941 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
942 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
943 public void readList(String testName) throws Exception {
946 setupReadList(testName);
948 // Submit the request to the service and store the response.
949 PersonAuthorityClient client = new PersonAuthorityClient();
950 ClientResponse<PersonauthoritiesCommonList> res = client.readList();
951 PersonauthoritiesCommonList list = res.getEntity();
952 int statusCode = res.getStatus();
954 // Check the status code of the response: does it match
955 // the expected response(s)?
956 if(logger.isDebugEnabled()){
957 logger.debug(testName + ": status = " + statusCode);
959 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
960 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
961 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
963 // Optionally output additional data about list members for debugging.
964 boolean iterateThroughList = false;
965 if (iterateThroughList && logger.isDebugEnabled()) {
966 List<PersonauthoritiesCommonList.PersonauthorityListItem> items =
967 list.getPersonauthorityListItem();
969 for (PersonauthoritiesCommonList.PersonauthorityListItem item : items) {
970 String csid = item.getCsid();
971 logger.debug(testName + ": list-item[" + i + "] csid=" +
973 logger.debug(testName + ": list-item[" + i + "] displayName=" +
974 item.getDisplayName());
975 logger.debug(testName + ": list-item[" + i + "] URI=" +
977 readItemList(csid, null);
986 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
987 public void readItemList() {
988 readItemList(knownResourceId, null);
992 * Read item list by authority name.
994 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
995 public void readItemListByAuthorityName() {
996 readItemList(null, knownResourceDisplayName);
1002 * @param vcsid the vcsid
1003 * @param name the name
1005 private void readItemList(String vcsid, String name) {
1007 final String testName = "readItemList";
1010 setupReadList(testName);
1012 // Submit the request to the service and store the response.
1013 PersonAuthorityClient client = new PersonAuthorityClient();
1014 ClientResponse<PersonsCommonList> res = null;
1016 res = client.readItemList(vcsid);
1017 } else if(name!= null) {
1018 res = client.readItemListForNamedAuthority(name);
1020 Assert.fail("readItemList passed null csid and name!");
1022 PersonsCommonList list = res.getEntity();
1023 int statusCode = res.getStatus();
1025 // Check the status code of the response: does it match
1026 // the expected response(s)?
1027 if(logger.isDebugEnabled()){
1028 logger.debug(testName + ": status = " + statusCode);
1030 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1031 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1032 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1034 List<PersonsCommonList.PersonListItem> items =
1035 list.getPersonListItem();
1036 int nItemsReturned = items.size();
1037 // There will be one item created, associated with a
1038 // known parent resource, by the createItem test.
1040 // In addition, there will be 'nItemsToCreateInList'
1041 // additional items created by the createItemList test,
1042 // all associated with the same parent resource.
1043 int nExpectedItems = nItemsToCreateInList + 1;
1044 if(logger.isDebugEnabled()){
1045 logger.debug(testName + ": Expected "
1046 + nExpectedItems +" items; got: "+nItemsReturned);
1048 Assert.assertEquals(nItemsReturned, nExpectedItems);
1051 for (PersonsCommonList.PersonListItem item : items) {
1052 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
1053 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
1054 // Optionally output additional data about list members for debugging.
1055 boolean showDetails = true;
1056 if (showDetails && logger.isDebugEnabled()) {
1057 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1059 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
1061 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
1062 item.getDisplayName());
1063 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1071 * Read contact list.
1073 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1074 public void readContactList() {
1075 readContactList(knownResourceId, knownItemResourceId);
1079 * Read contact list.
1081 * @param parentcsid the parentcsid
1082 * @param itemcsid the itemcsid
1084 private void readContactList(String parentcsid, String itemcsid) {
1085 final String testName = "readContactList";
1088 setupReadList(testName);
1090 // Submit the request to the service and store the response.
1091 PersonAuthorityClient client = new PersonAuthorityClient();
1092 ClientResponse<ContactsCommonList> res =
1093 client.readContactList(parentcsid, itemcsid);
1094 ContactsCommonList list = res.getEntity();
1095 int statusCode = res.getStatus();
1097 // Check the status code of the response: does it match
1098 // the expected response(s)?
1099 if(logger.isDebugEnabled()){
1100 logger.debug(testName + ": status = " + statusCode);
1102 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1103 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1104 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1106 List<ContactsCommonList.ContactListItem> listitems =
1107 list.getContactListItem();
1108 int nItemsReturned = listitems.size();
1109 // There will be one item created, associated with a
1110 // known parent resource, by the createItem test.
1112 // In addition, there will be 'nItemsToCreateInList'
1113 // additional items created by the createItemList test,
1114 // all associated with the same parent resource.
1115 int nExpectedItems = nItemsToCreateInList + 1;
1116 if(logger.isDebugEnabled()){
1117 logger.debug(testName + ": Expected "
1118 + nExpectedItems +" items; got: "+nItemsReturned);
1120 Assert.assertEquals(nItemsReturned, nExpectedItems);
1123 for (ContactsCommonList.ContactListItem listitem : listitems) {
1124 // Optionally output additional data about list members for debugging.
1125 boolean showDetails = false;
1126 if (showDetails && logger.isDebugEnabled()) {
1127 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1128 listitem.getCsid());
1129 logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" +
1130 listitem.getAddressPlace());
1131 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1141 // ---------------------------------------------------------------
1142 // CRUD tests : UPDATE tests
1143 // ---------------------------------------------------------------
1146 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
1149 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1150 groups = {"update"}, dependsOnGroups = {"read", "readList"})
1151 public void update(String testName) throws Exception {
1154 setupUpdate(testName);
1156 // Retrieve the contents of a resource to update.
1157 PersonAuthorityClient client = new PersonAuthorityClient();
1158 ClientResponse<MultipartInput> res =
1159 client.read(knownResourceId);
1160 if(logger.isDebugEnabled()){
1161 logger.debug(testName + ": read status = " + res.getStatus());
1163 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1165 if(logger.isDebugEnabled()){
1166 logger.debug("got PersonAuthority to update with ID: " + knownResourceId);
1168 MultipartInput input = (MultipartInput) res.getEntity();
1169 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
1170 client.getCommonPartName(), PersonauthoritiesCommon.class);
1171 Assert.assertNotNull(personAuthority);
1173 // Update the contents of this resource.
1174 personAuthority.setDisplayName("updated-" + personAuthority.getDisplayName());
1175 personAuthority.setVocabType("updated-" + personAuthority.getVocabType());
1176 if(logger.isDebugEnabled()){
1177 logger.debug("to be updated PersonAuthority");
1178 logger.debug(objectAsXmlString(personAuthority, PersonauthoritiesCommon.class));
1181 // Submit the updated resource to the service and store the response.
1182 MultipartOutput output = new MultipartOutput();
1183 OutputPart commonPart = output.addPart(personAuthority, MediaType.APPLICATION_XML_TYPE);
1184 commonPart.getHeaders().add("label", client.getCommonPartName());
1185 res = client.update(knownResourceId, output);
1186 int statusCode = res.getStatus();
1188 // Check the status code of the response: does it match the expected response(s)?
1189 if(logger.isDebugEnabled()){
1190 logger.debug(testName + ": status = " + statusCode);
1192 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1193 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1194 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1196 // Retrieve the updated resource and verify that its contents exist.
1197 input = (MultipartInput) res.getEntity();
1198 PersonauthoritiesCommon updatedPersonAuthority =
1199 (PersonauthoritiesCommon) extractPart(input,
1200 client.getCommonPartName(), PersonauthoritiesCommon.class);
1201 Assert.assertNotNull(updatedPersonAuthority);
1203 // Verify that the updated resource received the correct data.
1204 Assert.assertEquals(updatedPersonAuthority.getDisplayName(),
1205 personAuthority.getDisplayName(),
1206 "Data in updated object did not match submitted data.");
1212 * @param testName the test name
1213 * @throws Exception the exception
1215 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1216 groups = {"update"}, dependsOnMethods = {"update"})
1217 public void updateItem(String testName) throws Exception {
1220 setupUpdate(testName);
1222 // Retrieve the contents of a resource to update.
1223 PersonAuthorityClient client = new PersonAuthorityClient();
1224 ClientResponse<MultipartInput> res =
1225 client.readItem(knownResourceId, knownItemResourceId);
1226 if(logger.isDebugEnabled()){
1227 logger.debug(testName + ": read status = " + res.getStatus());
1229 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1231 if(logger.isDebugEnabled()){
1232 logger.debug("got Person to update with ID: " +
1233 knownItemResourceId +
1234 " in PersonAuthority: " + knownResourceId );
1236 MultipartInput input = (MultipartInput) res.getEntity();
1237 PersonsCommon person = (PersonsCommon) extractPart(input,
1238 client.getItemCommonPartName(), PersonsCommon.class);
1239 Assert.assertNotNull(person);
1241 // Update the contents of this resource.
1242 person.setCsid(null);
1243 person.setForeName("updated-" + person.getForeName());
1244 if(logger.isDebugEnabled()){
1245 logger.debug("to be updated Person");
1246 logger.debug(objectAsXmlString(person,
1247 PersonsCommon.class));
1250 // Submit the updated resource to the service and store the response.
1251 MultipartOutput output = new MultipartOutput();
1252 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
1253 commonPart.getHeaders().add("label", client.getItemCommonPartName());
1254 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1255 int statusCode = res.getStatus();
1257 // Check the status code of the response: does it match the expected response(s)?
1258 if(logger.isDebugEnabled()){
1259 logger.debug(testName + ": status = " + statusCode);
1261 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1262 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1263 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1265 // Retrieve the updated resource and verify that its contents exist.
1266 input = (MultipartInput) res.getEntity();
1267 PersonsCommon updatedPerson =
1268 (PersonsCommon) extractPart(input,
1269 client.getItemCommonPartName(), PersonsCommon.class);
1270 Assert.assertNotNull(updatedPerson);
1272 // Verify that the updated resource received the correct data.
1273 Assert.assertEquals(updatedPerson.getForeName(),
1274 person.getForeName(),
1275 "Data in updated Person did not match submitted data.");
1281 * @param testName the test name
1282 * @throws Exception the exception
1284 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1285 groups = {"update"}, dependsOnMethods = {"updateItem"})
1286 public void updateContact(String testName) throws Exception {
1289 setupUpdate(testName);
1291 // Retrieve the contents of a resource to update.
1292 PersonAuthorityClient client = new PersonAuthorityClient();
1293 ClientResponse<MultipartInput> res =
1294 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1295 if(logger.isDebugEnabled()){
1296 logger.debug(testName + ": read status = " + res.getStatus());
1298 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1300 if(logger.isDebugEnabled()){
1301 logger.debug("got Contact to update with ID: " +
1302 knownContactResourceId +
1303 " in item: " + knownItemResourceId +
1304 " in parent: " + knownResourceId );
1306 MultipartInput input = (MultipartInput) res.getEntity();
1307 ContactsCommon contact = (ContactsCommon) extractPart(input,
1308 new ContactClient().getCommonPartName(), ContactsCommon.class);
1309 Assert.assertNotNull(contact);
1311 // Update the contents of this resource.
1312 contact.setAddressPlace("updated-" + contact.getAddressPlace());
1313 if(logger.isDebugEnabled()){
1314 logger.debug("to be updated Contact");
1315 logger.debug(objectAsXmlString(contact,
1316 ContactsCommon.class));
1319 // Submit the updated resource to the service and store the response.
1320 MultipartOutput output = new MultipartOutput();
1321 OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1322 commonPart.getHeaders().add("label", new ContactClient().getCommonPartName());
1323 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1324 int statusCode = res.getStatus();
1326 // Check the status code of the response: does it match the expected response(s)?
1327 if(logger.isDebugEnabled()){
1328 logger.debug(testName + ": status = " + statusCode);
1330 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1331 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1332 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1334 // Retrieve the updated resource and verify that its contents exist.
1335 input = (MultipartInput) res.getEntity();
1336 ContactsCommon updatedContact =
1337 (ContactsCommon) extractPart(input,
1338 new ContactClient().getCommonPartName(), ContactsCommon.class);
1339 Assert.assertNotNull(updatedContact);
1341 // Verify that the updated resource received the correct data.
1342 Assert.assertEquals(updatedContact.getAddressPlace(),
1343 contact.getAddressPlace(),
1344 "Data in updated Contact did not match submitted data.");
1348 // Placeholders until the three tests below can be uncommented.
1349 // See Issue CSPACE-401.
1351 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1354 public void updateWithEmptyEntityBody(String testName) throws Exception {
1358 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1361 public void updateWithMalformedXml(String testName) throws Exception {
1365 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1368 public void updateWithWrongXmlSchema(String testName) throws Exception {
1373 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1374 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1375 public void updateWithEmptyEntityBody(String testName) throws Exception {
1378 setupUpdateWithEmptyEntityBody(testName);
1380 // Submit the request to the service and store the response.
1381 String method = REQUEST_TYPE.httpMethodName();
1382 String url = getResourceURL(knownResourceId);
1383 String mediaType = MediaType.APPLICATION_XML;
1384 final String entity = "";
1385 int statusCode = submitRequest(method, url, mediaType, entity);
1387 // Check the status code of the response: does it match
1388 // the expected response(s)?
1389 if(logger.isDebugEnabled()){
1390 logger.debug(testName + ": url=" + url +
1391 " status=" + statusCode);
1393 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1394 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1395 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1399 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1400 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1401 public void updateWithMalformedXml(String testName) throws Exception {
1404 setupUpdateWithMalformedXml(testName);
1406 // Submit the request to the service and store the response.
1407 String method = REQUEST_TYPE.httpMethodName();
1408 String url = getResourceURL(knownResourceId);
1409 String mediaType = MediaType.APPLICATION_XML;
1410 final String entity = MALFORMED_XML_DATA;
1411 int statusCode = submitRequest(method, url, mediaType, entity);
1413 // Check the status code of the response: does it match
1414 // the expected response(s)?
1415 if(logger.isDebugEnabled()){
1416 logger.debug(testName + ": url=" + url +
1417 " status=" + statusCode);
1419 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1420 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1421 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1425 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1426 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1427 public void updateWithWrongXmlSchema(String testName) throws Exception {
1430 setupUpdateWithWrongXmlSchema(testName);
1432 // Submit the request to the service and store the response.
1433 String method = REQUEST_TYPE.httpMethodName();
1434 String url = getResourceURL(knownResourceId);
1435 String mediaType = MediaType.APPLICATION_XML;
1436 final String entity = WRONG_XML_SCHEMA_DATA;
1437 int statusCode = submitRequest(method, url, mediaType, entity);
1439 // Check the status code of the response: does it match
1440 // the expected response(s)?
1441 if(logger.isDebugEnabled()){
1442 logger.debug("updateWithWrongXmlSchema: url=" + url +
1443 " status=" + statusCode);
1445 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1446 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1447 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1452 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1455 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1456 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1457 public void updateNonExistent(String testName) throws Exception {
1460 setupUpdateNonExistent(testName);
1462 // Submit the request to the service and store the response.
1463 // Note: The ID(s) used when creating the request payload may be arbitrary.
1464 // The only relevant ID may be the one used in update(), below.
1465 PersonAuthorityClient client = new PersonAuthorityClient();
1466 String displayName = "displayName-NON_EXISTENT_ID";
1467 String fullRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, true);
1468 MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
1469 displayName, fullRefName, client.getCommonPartName());
1470 ClientResponse<MultipartInput> res =
1471 client.update(NON_EXISTENT_ID, multipart);
1472 int statusCode = res.getStatus();
1474 // Check the status code of the response: does it match
1475 // the expected response(s)?
1476 if(logger.isDebugEnabled()){
1477 logger.debug(testName + ": status = " + statusCode);
1479 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1480 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1481 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1485 * Update non existent item.
1487 * @param testName the test name
1488 * @throws Exception the exception
1490 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1491 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1492 public void updateNonExistentItem(String testName) throws Exception {
1495 setupUpdateNonExistent(testName);
1497 // Submit the request to the service and store the response.
1498 // Note: The ID used in this 'create' call may be arbitrary.
1499 // The only relevant ID may be the one used in update(), below.
1500 PersonAuthorityClient client = new PersonAuthorityClient();
1501 Map<String, String> nonexMap = new HashMap<String,String>();
1502 nonexMap.put(PersonJAXBSchema.FORE_NAME, "John");
1503 nonexMap.put(PersonJAXBSchema.SUR_NAME, "Wayne");
1504 nonexMap.put(PersonJAXBSchema.GENDER, "male");
1505 MultipartOutput multipart =
1506 PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID,
1507 PersonAuthorityClientUtils.createPersonRefName(NON_EXISTENT_ID, NON_EXISTENT_ID, true), nonexMap,
1508 client.getItemCommonPartName() );
1509 ClientResponse<MultipartInput> res =
1510 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1511 int statusCode = res.getStatus();
1513 // Check the status code of the response: does it match
1514 // the expected response(s)?
1515 if(logger.isDebugEnabled()){
1516 logger.debug(testName + ": status = " + statusCode);
1518 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1519 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1520 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1524 * Update non existent contact.
1526 * @param testName the test name
1527 * @throws Exception the exception
1529 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1530 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1531 public void updateNonExistentContact(String testName) throws Exception {
1532 // Currently a no-op test
1535 // ---------------------------------------------------------------
1536 // CRUD tests : DELETE tests
1537 // ---------------------------------------------------------------
1540 // Note: delete sub-resources in ascending hierarchical order,
1541 // before deleting their parents.
1546 * @param testName the test name
1547 * @throws Exception the exception
1549 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1550 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1551 public void deleteContact(String testName) throws Exception {
1554 setupDelete(testName);
1556 if(logger.isDebugEnabled()){
1557 logger.debug("parentcsid =" + knownResourceId +
1558 " itemcsid = " + knownItemResourceId +
1559 " csid = " + knownContactResourceId);
1562 // Submit the request to the service and store the response.
1563 PersonAuthorityClient client = new PersonAuthorityClient();
1564 ClientResponse<Response> res =
1565 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1566 int statusCode = res.getStatus();
1568 // Check the status code of the response: does it match
1569 // the expected response(s)?
1570 if(logger.isDebugEnabled()){
1571 logger.debug(testName + ": status = " + statusCode);
1573 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1574 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1575 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1581 * @param testName the test name
1582 * @throws Exception the exception
1584 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1585 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1586 public void deleteItem(String testName) throws Exception {
1589 setupDelete(testName);
1591 if(logger.isDebugEnabled()){
1592 logger.debug("parentcsid =" + knownResourceId +
1593 " itemcsid = " + knownItemResourceId);
1596 // Submit the request to the service and store the response.
1597 PersonAuthorityClient client = new PersonAuthorityClient();
1598 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1599 int statusCode = res.getStatus();
1601 // Check the status code of the response: does it match
1602 // the expected response(s)?
1603 if(logger.isDebugEnabled()){
1604 logger.debug(testName + ": status = " + statusCode);
1606 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1607 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1608 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1612 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1615 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1616 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1617 public void delete(String testName) throws Exception {
1620 setupDelete(testName);
1622 if(logger.isDebugEnabled()){
1623 logger.debug("parentcsid =" + knownResourceId);
1626 // Submit the request to the service and store the response.
1627 PersonAuthorityClient client = new PersonAuthorityClient();
1628 ClientResponse<Response> res = client.delete(knownResourceId);
1629 int statusCode = res.getStatus();
1631 // Check the status code of the response: does it match
1632 // the expected response(s)?
1633 if(logger.isDebugEnabled()){
1634 logger.debug(testName + ": status = " + statusCode);
1636 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1637 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1638 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1643 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1646 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1647 groups = {"delete"}, dependsOnMethods = {"delete"})
1648 public void deleteNonExistent(String testName) throws Exception {
1651 setupDeleteNonExistent(testName);
1653 // Submit the request to the service and store the response.
1654 PersonAuthorityClient client = new PersonAuthorityClient();
1655 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1656 int statusCode = res.getStatus();
1658 // Check the status code of the response: does it match
1659 // the expected response(s)?
1660 if(logger.isDebugEnabled()){
1661 logger.debug(testName + ": status = " + statusCode);
1663 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1664 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1665 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1669 * Delete non existent item.
1671 * @param testName the test name
1673 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1674 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1675 public void deleteNonExistentItem(String testName) {
1678 setupDeleteNonExistent(testName);
1680 // Submit the request to the service and store the response.
1681 PersonAuthorityClient client = new PersonAuthorityClient();
1682 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1683 int statusCode = res.getStatus();
1685 // Check the status code of the response: does it match
1686 // the expected response(s)?
1687 if(logger.isDebugEnabled()){
1688 logger.debug(testName + ": status = " + statusCode);
1690 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1691 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1692 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1696 * Delete non existent contact.
1698 * @param testName the test name
1700 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1701 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1702 public void deleteNonExistentContact(String testName) {
1705 setupDeleteNonExistent(testName);
1707 // Submit the request to the service and store the response.
1708 PersonAuthorityClient client = new PersonAuthorityClient();
1709 ClientResponse<Response> res =
1710 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1711 int statusCode = res.getStatus();
1713 // Check the status code of the response: does it match
1714 // the expected response(s)?
1715 if(logger.isDebugEnabled()){
1716 logger.debug(testName + ": status = " + statusCode);
1718 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1719 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1720 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1723 // ---------------------------------------------------------------
1724 // Utility tests : tests of code used in tests above
1725 // ---------------------------------------------------------------
1727 * Tests the code for manually submitting data that is used by several
1728 * of the methods above.
1730 @Test(dependsOnMethods = {"create", "read"})
1731 public void testSubmitRequest() {
1733 // Expected status code: 200 OK
1734 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1736 // Submit the request to the service and store the response.
1737 String method = ServiceRequestType.READ.httpMethodName();
1738 String url = getResourceURL(knownResourceId);
1739 int statusCode = submitRequest(method, url);
1741 // Check the status code of the response: does it match
1742 // the expected response(s)?
1743 if(logger.isDebugEnabled()){
1744 logger.debug("testSubmitRequest: url=" + url +
1745 " status=" + statusCode);
1747 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1752 * Test item submit request.
1754 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1755 public void testItemSubmitRequest() {
1757 // Expected status code: 200 OK
1758 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1760 // Submit the request to the service and store the response.
1761 String method = ServiceRequestType.READ.httpMethodName();
1762 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1763 int statusCode = submitRequest(method, url);
1765 // Check the status code of the response: does it match
1766 // the expected response(s)?
1767 if(logger.isDebugEnabled()){
1768 logger.debug("testItemSubmitRequest: url=" + url +
1769 " status=" + statusCode);
1771 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1776 * Test contact submit request.
1778 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
1779 public void testContactSubmitRequest() {
1781 // Expected status code: 200 OK
1782 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1784 // Submit the request to the service and store the response.
1785 String method = ServiceRequestType.READ.httpMethodName();
1786 String url = getContactResourceURL(knownResourceId,
1787 knownItemResourceId, knownContactResourceId);
1788 int statusCode = submitRequest(method, url);
1790 // Check the status code of the response: does it match
1791 // the expected response(s)?
1792 if(logger.isDebugEnabled()){
1793 logger.debug("testItemSubmitRequest: url=" + url +
1794 " status=" + statusCode);
1796 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1801 // ---------------------------------------------------------------
1802 // Cleanup of resources created during testing
1803 // ---------------------------------------------------------------
1806 * Deletes all resources created by tests, after all tests have been run.
1808 * This cleanup method will always be run, even if one or more tests fail.
1809 * For this reason, it attempts to remove all resources created
1810 * at any point during testing, even if some of those resources
1811 * may be expected to be deleted by certain tests.
1814 @AfterClass(alwaysRun=true)
1815 public void cleanUp() {
1816 String noTest = System.getProperty("noTestCleanup");
1817 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1818 if (logger.isDebugEnabled()) {
1819 logger.debug("Skipping Cleanup phase ...");
1823 if (logger.isDebugEnabled()) {
1824 logger.debug("Cleaning up temporary resources created for testing ...");
1826 String parentResourceId;
1827 String itemResourceId;
1828 String contactResourceId;
1829 // Clean up contact resources.
1830 PersonAuthorityClient client = new PersonAuthorityClient();
1831 parentResourceId = knownResourceId;
1832 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
1833 contactResourceId = entry.getKey();
1834 itemResourceId = entry.getValue();
1835 // Note: Any non-success responses from the delete operation
1836 // below are ignored and not reported.
1837 ClientResponse<Response> res =
1838 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
1840 // Clean up item resources.
1841 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1842 itemResourceId = entry.getKey();
1843 parentResourceId = entry.getValue();
1844 // Note: Any non-success responses from the delete operation
1845 // below are ignored and not reported.
1846 ClientResponse<Response> res =
1847 client.deleteItem(parentResourceId, itemResourceId);
1849 // Clean up parent resources.
1850 for (String resourceId : allResourceIdsCreated) {
1851 // Note: Any non-success responses from the delete operation
1852 // below are ignored and not reported.
1853 ClientResponse<Response> res = client.delete(resourceId);
1857 // ---------------------------------------------------------------
1858 // Utility methods used by tests above
1859 // ---------------------------------------------------------------
1861 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
1864 public String getServicePathComponent() {
1865 return SERVICE_PATH_COMPONENT;
1869 * Gets the item service path component.
1871 * @return the item service path component
1873 public String getItemServicePathComponent() {
1874 return ITEM_SERVICE_PATH_COMPONENT;
1878 * Gets the contact service path component.
1880 * @return the contact service path component
1882 public String getContactServicePathComponent() {
1883 return CONTACT_SERVICE_PATH_COMPONENT;
1887 * Returns the root URL for the item service.
1889 * This URL consists of a base URL for all services, followed by
1890 * a path component for the owning parent, followed by the
1891 * path component for the items.
1893 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1894 * parent authority resource of the relevant item resource.
1896 * @return The root URL for the item service.
1898 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1899 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1903 * Returns the URL of a specific item resource managed by a service, and
1904 * designated by an identifier (such as a universally unique ID, or UUID).
1906 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1907 * parent authority resource of the relevant item resource.
1909 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1912 * @return The URL of a specific item resource managed by a service.
1914 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1915 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
1920 * Returns the root URL for the contact service.
1922 * This URL consists of a base URL for all services, followed by
1923 * a path component for the owning authority, followed by the
1924 * path component for the owning item, followed by the path component
1925 * for the contact service.
1927 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1928 * parent authority resource of the relevant item resource.
1930 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1933 * @return The root URL for the contact service.
1935 protected String getContactServiceRootURL(String parentResourceIdentifier,
1936 String itemResourceIdentifier) {
1937 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
1938 getContactServicePathComponent();
1942 * Returns the URL of a specific contact resource managed by a service, and
1943 * designated by an identifier (such as a universally unique ID, or UUID).
1945 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1946 * parent resource of the relevant item resource.
1948 * @param resourceIdentifier An identifier (such as a UUID) for an
1951 * @return The URL of a specific resource managed by a service.
1953 protected String getContactResourceURL(String parentResourceIdentifier,
1954 String itemResourceIdentifier, String contactResourceIdentifier) {
1955 return getContactServiceRootURL(parentResourceIdentifier,
1956 itemResourceIdentifier) + "/" + contactResourceIdentifier;