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.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.PersonAuthorityClient;
38 import org.collectionspace.services.client.PersonAuthorityClientUtils;
39 import org.collectionspace.services.person.PersonauthoritiesCommon;
40 import org.collectionspace.services.person.PersonauthoritiesCommonList;
41 import org.collectionspace.services.person.PersonsCommon;
42 import org.collectionspace.services.person.PersonsCommonList;
43 import org.jboss.resteasy.client.ClientResponse;
44 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
45 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
46 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
49 import org.testng.Assert;
50 import org.testng.annotations.AfterClass;
51 import org.testng.annotations.Test;
54 * PersonAuthorityServiceTest, carries out tests against a
55 * deployed and running PersonAuthority Service.
57 * $LastChangedRevision: 753 $
58 * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
60 public class PersonAuthorityServiceTest extends AbstractServiceTestImpl {
62 private final Logger logger =
63 LoggerFactory.getLogger(PersonAuthorityServiceTest.class);
65 // Instance variables specific to this test.
66 final String SERVICE_PATH_COMPONENT = "personauthorities";
67 final String ITEM_SERVICE_PATH_COMPONENT = "items";
68 final String CONTACT_SERVICE_PATH_COMPONENT = "contacts";
69 final String TEST_FORE_NAME = "John";
70 final String TEST_MIDDLE_NAME = null;
71 final String TEST_SUR_NAME = "Wayne";
72 final String TEST_BIRTH_DATE = "May 26, 1907";
73 final String TEST_DEATH_DATE = "June 11, 1979";
75 private String knownResourceId = null;
76 private String knownResourceDisplayName = null;
77 private String knownResourceRefName = null;
78 private String knownItemResourceId = null;
79 private String knownContactResourceId = null;
80 private int nItemsToCreateInList = 3;
81 private List<String> allResourceIdsCreated = new ArrayList<String>();
82 private Map<String, String> allItemResourceIdsCreated =
83 new HashMap<String, String>();
84 private Map<String, String> allContactResourceIdsCreated =
85 new HashMap<String, String>();
87 // ---------------------------------------------------------------
88 // CRUD tests : CREATE tests
89 // ---------------------------------------------------------------
92 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
94 public void create(String testName) throws Exception {
96 // Perform setup, such as initializing the type of service request
97 // (e.g. CREATE, DELETE), its valid and expected status codes, and
98 // its associated HTTP method name (e.g. POST, DELETE).
99 setupCreate(testName);
101 // Submit the request to the service and store the response.
102 PersonAuthorityClient client = new PersonAuthorityClient();
103 String identifier = createIdentifier();
104 String displayName = "displayName-" + identifier;
105 String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, false);
106 String fullRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, true);
107 MultipartOutput multipart =
108 PersonAuthorityClientUtils.createPersonAuthorityInstance(
109 displayName, fullRefName, client.getCommonPartName());
110 ClientResponse<Response> res = client.create(multipart);
111 int statusCode = res.getStatus();
113 // Check the status code of the response: does it match
114 // the expected response(s)?
117 // Does it fall within the set of valid status codes?
118 // Does it exactly match the expected status code?
119 if(logger.isDebugEnabled()){
120 logger.debug(testName + ": status = " + statusCode);
122 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
123 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
124 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
126 // Store the refname from the first resource created
127 // for additional tests below.
128 knownResourceRefName = baseRefName;
130 String newID = PersonAuthorityClientUtils.extractId(res);
131 // Store the ID returned from the first resource created
132 // for additional tests below.
133 if (knownResourceId == null){
134 knownResourceId = newID;
135 knownResourceDisplayName = displayName;
136 if (logger.isDebugEnabled()) {
137 logger.debug(testName + ": knownResourceId=" + knownResourceId);
140 // Store the IDs from every resource created by tests,
141 // so they can be deleted after tests have been run.
142 allResourceIdsCreated.add(newID);
145 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
146 groups = {"create"}, dependsOnMethods = {"create"})
147 public void createItem(String testName) {
148 setupCreate(testName);
149 String newID = createItemInAuthority(knownResourceId, knownResourceRefName);
152 private String createItemInAuthority(String vcsid, String authRefName) {
154 final String testName = "createItemInAuthority";
155 if(logger.isDebugEnabled()){
156 logger.debug(testName + ":...");
159 // Submit the request to the service and store the response.
160 PersonAuthorityClient client = new PersonAuthorityClient();
161 String identifier = createIdentifier();
162 String refName = PersonAuthorityClientUtils.createPersonRefName(authRefName, "John Wayne", true);
163 Map<String, String> johnWayneMap = new HashMap<String,String>();
164 johnWayneMap.put(PersonJAXBSchema.FORE_NAME, TEST_FORE_NAME);
165 johnWayneMap.put(PersonJAXBSchema.SUR_NAME, TEST_SUR_NAME);
166 johnWayneMap.put(PersonJAXBSchema.GENDER, "male");
167 johnWayneMap.put(PersonJAXBSchema.BIRTH_DATE, TEST_BIRTH_DATE);
168 johnWayneMap.put(PersonJAXBSchema.BIRTH_PLACE, "Winterset, Iowa");
169 johnWayneMap.put(PersonJAXBSchema.DEATH_DATE, TEST_DEATH_DATE);
170 johnWayneMap.put(PersonJAXBSchema.BIO_NOTE, "born Marion Robert Morrison and better" +
171 "known by his stage name John Wayne, was an American film actor, director " +
172 "and producer. He epitomized rugged masculinity and has become an enduring " +
173 "American icon. He is famous for his distinctive voice, walk and height. " +
174 "He was also known for his conservative political views and his support in " +
175 "the 1950s for anti-communist positions.");
176 MultipartOutput multipart =
177 PersonAuthorityClientUtils.createPersonInstance(vcsid, refName, johnWayneMap,
178 client.getItemCommonPartName() );
179 ClientResponse<Response> res = client.createItem(vcsid, multipart);
180 int statusCode = res.getStatus();
181 String newID = PersonAuthorityClientUtils.extractId(res);
183 // Check the status code of the response: does it match
184 // the expected response(s)?
185 if(logger.isDebugEnabled()){
186 logger.debug(testName + ": status = " + statusCode);
188 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
189 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
190 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
192 // Store the ID returned from the first item resource created
193 // for additional tests below.
194 if (knownItemResourceId == null){
195 knownItemResourceId = newID;
196 if (logger.isDebugEnabled()) {
197 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
201 // Store the IDs from any item resources created
202 // by tests, along with the IDs of their parents, so these items
203 // can be deleted after all tests have been run.
204 allItemResourceIdsCreated.put(newID, vcsid);
209 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
210 groups = {"create"}, dependsOnMethods = {"createItem"})
211 public void createContact(String testName) {
212 setupCreate(testName);
213 String newID = createContactInItem(knownResourceId, knownItemResourceId);
216 private String createContactInItem(String parentcsid, String itemcsid) {
218 final String testName = "createContactInItem";
219 setupCreate(testName);
220 if(logger.isDebugEnabled()){
221 logger.debug(testName + ":...");
224 // Submit the request to the service and store the response.
225 PersonAuthorityClient client = new PersonAuthorityClient();
226 String identifier = createIdentifier();
227 MultipartOutput multipart =
228 ContactClientUtils.createContactInstance(parentcsid,
229 itemcsid, identifier, new ContactClient().getCommonPartName());
230 ClientResponse<Response> res =
231 client.createContact(parentcsid, itemcsid, multipart);
232 int statusCode = res.getStatus();
233 String newID = PersonAuthorityClientUtils.extractId(res);
235 // Check the status code of the response: does it match
236 // the expected response(s)?
237 if(logger.isDebugEnabled()){
238 logger.debug(testName + ": status = " + statusCode);
240 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
241 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
242 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
244 // Store the ID returned from the first contact resource created
245 // for additional tests below.
246 if (knownContactResourceId == null){
247 knownContactResourceId = newID;
248 if (logger.isDebugEnabled()) {
249 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
253 // Store the IDs from any contact resources created
254 // by tests, along with the IDs of their parent items,
255 // so these items can be deleted after all tests have been run.
256 allContactResourceIdsCreated.put(newID, itemcsid);
263 // Placeholders until the three tests below can be uncommented.
264 // See Issue CSPACE-401.
266 public void createWithEmptyEntityBody(String testName) throws Exception {
270 public void createWithMalformedXml(String testName) throws Exception {
274 public void createWithWrongXmlSchema(String testName) throws Exception {
279 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
280 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
281 public void createWithEmptyEntityBody(String testName) throws Exception {
284 setupCreateWithEmptyEntityBody(testName);
286 // Submit the request to the service and store the response.
287 String method = REQUEST_TYPE.httpMethodName();
288 String url = getServiceRootURL();
289 String mediaType = MediaType.APPLICATION_XML;
290 final String entity = "";
291 int statusCode = submitRequest(method, url, mediaType, entity);
293 // Check the status code of the response: does it match
294 // the expected response(s)?
295 if(logger.isDebugEnabled()) {
296 logger.debug(testName + ": url=" + url +
297 " status=" + statusCode);
299 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
300 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
301 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
305 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
306 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
307 public void createWithMalformedXml(String testName) throws Exception {
310 setupCreateWithMalformedXml(testName);
312 // Submit the request to the service and store the response.
313 String method = REQUEST_TYPE.httpMethodName();
314 String url = getServiceRootURL();
315 String mediaType = MediaType.APPLICATION_XML;
316 final String entity = MALFORMED_XML_DATA; // Constant from base class.
317 int statusCode = submitRequest(method, url, mediaType, entity);
319 // Check the status code of the response: does it match
320 // the expected response(s)?
321 if(logger.isDebugEnabled()){
322 logger.debug(testName + ": url=" + url +
323 " status=" + statusCode);
325 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
326 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
327 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
331 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
332 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
333 public void createWithWrongXmlSchema(String testName) throws Exception {
336 setupCreateWithWrongXmlSchema(testName);
338 // Submit the request to the service and store the response.
339 String method = REQUEST_TYPE.httpMethodName();
340 String url = getServiceRootURL();
341 String mediaType = MediaType.APPLICATION_XML;
342 final String entity = WRONG_XML_SCHEMA_DATA;
343 int statusCode = submitRequest(method, url, mediaType, entity);
345 // Check the status code of the response: does it match
346 // the expected response(s)?
347 if(logger.isDebugEnabled()){
348 logger.debug(testName + ": url=" + url +
349 " status=" + statusCode);
351 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
352 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
353 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
357 // ---------------------------------------------------------------
358 // CRUD tests : CREATE LIST tests
359 // ---------------------------------------------------------------
362 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
363 groups = {"createList"}, dependsOnGroups = {"create"})
364 public void createList(String testName) throws Exception {
365 for (int i = 0; i < nItemsToCreateInList; i++) {
370 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
371 groups = {"createList"}, dependsOnMethods = {"createList"})
372 public void createItemList(String testName) throws Exception {
373 // Add items to the initially-created, known parent record.
374 for (int j = 0; j < nItemsToCreateInList; j++) {
375 createItem(testName);
379 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
380 groups = {"createList"}, dependsOnMethods = {"createItemList"})
381 public void createContactList(String testName) throws Exception {
382 // Add contacts to the initially-created, known item record.
383 for (int j = 0; j < nItemsToCreateInList; j++) {
384 createContact(testName);
388 // ---------------------------------------------------------------
389 // CRUD tests : READ tests
390 // ---------------------------------------------------------------
393 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
394 groups = {"read"}, dependsOnGroups = {"create"})
395 public void read(String testName) throws Exception {
400 // Submit the request to the service and store the response.
401 PersonAuthorityClient client = new PersonAuthorityClient();
402 ClientResponse<MultipartInput> res = client.read(knownResourceId);
403 int statusCode = res.getStatus();
405 // Check the status code of the response: does it match
406 // the expected response(s)?
407 if(logger.isDebugEnabled()){
408 logger.debug(testName + ": status = " + statusCode);
410 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
411 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
412 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
413 //FIXME: remove the following try catch once Aron fixes signatures
415 MultipartInput input = (MultipartInput) res.getEntity();
416 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
417 client.getCommonPartName(), PersonauthoritiesCommon.class);
418 Assert.assertNotNull(personAuthority);
419 } catch (Exception e) {
420 throw new RuntimeException(e);
424 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
425 groups = {"read"}, dependsOnGroups = {"create"})
426 public void readByName(String testName) throws Exception {
431 // Submit the request to the service and store the response.
432 PersonAuthorityClient client = new PersonAuthorityClient();
433 ClientResponse<MultipartInput> res = client.readByName(knownResourceDisplayName);
434 int statusCode = res.getStatus();
436 // Check the status code of the response: does it match
437 // the expected response(s)?
438 if(logger.isDebugEnabled()){
439 logger.debug(testName + ": status = " + statusCode);
441 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
442 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
443 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
444 //FIXME: remove the following try catch once Aron fixes signatures
446 MultipartInput input = (MultipartInput) res.getEntity();
447 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
448 client.getCommonPartName(), PersonauthoritiesCommon.class);
449 Assert.assertNotNull(personAuthority);
450 } catch (Exception e) {
451 throw new RuntimeException(e);
456 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
457 groups = {"read"}, dependsOnMethods = {"read"})
458 public void readByName(String testName) throws Exception {
463 // Submit the request to the service and store the response.
464 ClientResponse<MultipartInput> res = client.read(knownResourceId);
465 int statusCode = res.getStatus();
467 // Check the status code of the response: does it match
468 // the expected response(s)?
469 if(logger.isDebugEnabled()){
470 logger.debug(testName + ": status = " + statusCode);
472 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
473 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
474 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
475 //FIXME: remove the following try catch once Aron fixes signatures
477 MultipartInput input = (MultipartInput) res.getEntity();
478 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
479 client.getCommonPartName(), PersonauthoritiesCommon.class);
480 Assert.assertNotNull(personAuthority);
481 } catch (Exception e) {
482 throw new RuntimeException(e);
487 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
488 groups = {"read"}, dependsOnMethods = {"read"})
489 public void readItem(String testName) throws Exception {
494 // Submit the request to the service and store the response.
495 PersonAuthorityClient client = new PersonAuthorityClient();
496 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
497 int statusCode = res.getStatus();
499 // Check the status code of the response: does it match
500 // the expected response(s)?
501 if(logger.isDebugEnabled()){
502 logger.debug(testName + ": status = " + statusCode);
504 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
505 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
506 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
508 // Check whether we've received a person.
509 MultipartInput input = (MultipartInput) res.getEntity();
510 PersonsCommon person = (PersonsCommon) extractPart(input,
511 client.getItemCommonPartName(), PersonsCommon.class);
512 Assert.assertNotNull(person);
513 boolean showFull = true;
514 if(showFull && logger.isDebugEnabled()){
515 logger.debug(testName + ": returned payload:");
516 logger.debug(objectAsXmlString(person, PersonsCommon.class));
518 Assert.assertEquals(person.getInAuthority(), knownResourceId);
522 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
523 dependsOnMethods = {"readItem", "updateItem"})
524 public void verifyItemDisplayName(String testName) throws Exception {
527 setupUpdate(testName);
529 // Submit the request to the service and store the response.
530 PersonAuthorityClient client = new PersonAuthorityClient();
531 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
532 int statusCode = res.getStatus();
534 // Check the status code of the response: does it match
535 // the expected response(s)?
536 if(logger.isDebugEnabled()){
537 logger.debug(testName + ": status = " + statusCode);
539 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
540 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
541 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
543 // Check whether person has expected displayName.
544 MultipartInput input = (MultipartInput) res.getEntity();
545 PersonsCommon person = (PersonsCommon) extractPart(input,
546 client.getItemCommonPartName(), PersonsCommon.class);
547 Assert.assertNotNull(person);
548 String displayName = person.getDisplayName();
549 // Make sure displayName matches computed form
550 String expectedDisplayName =
551 PersonAuthorityClientUtils.prepareDefaultDisplayName(
552 TEST_FORE_NAME, null, TEST_SUR_NAME,
553 TEST_BIRTH_DATE, TEST_DEATH_DATE);
554 Assert.assertNotNull(displayName, expectedDisplayName);
556 // Update the shortName and verify the computed name is updated.
557 person.setCsid(null);
558 person.setDisplayNameComputed(true);
559 person.setForeName("updated-" + TEST_FORE_NAME);
560 expectedDisplayName =
561 PersonAuthorityClientUtils.prepareDefaultDisplayName(
562 "updated-" + TEST_FORE_NAME, null, TEST_SUR_NAME,
563 TEST_BIRTH_DATE, TEST_DEATH_DATE);
565 // Submit the updated resource to the service and store the response.
566 MultipartOutput output = new MultipartOutput();
567 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
568 commonPart.getHeaders().add("label", client.getItemCommonPartName());
569 res = client.updateItem(knownResourceId, knownItemResourceId, output);
570 statusCode = res.getStatus();
572 // Check the status code of the response: does it match the expected response(s)?
573 if(logger.isDebugEnabled()){
574 logger.debug("updateItem: status = " + statusCode);
576 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
577 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
578 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
580 // Retrieve the updated resource and verify that its contents exist.
581 input = (MultipartInput) res.getEntity();
582 PersonsCommon updatedPerson =
583 (PersonsCommon) extractPart(input,
584 client.getItemCommonPartName(), PersonsCommon.class);
585 Assert.assertNotNull(updatedPerson);
587 // Verify that the updated resource received the correct data.
588 Assert.assertEquals(updatedPerson.getForeName(), person.getForeName(),
589 "Updated ForeName in Person did not match submitted data.");
590 // Verify that the updated resource computes the right displayName.
591 Assert.assertEquals(updatedPerson.getDisplayName(), expectedDisplayName,
592 "Updated ForeName in Person not reflected in computed DisplayName.");
594 // Now Update the displayName, not computed and verify the computed name is overriden.
595 person.setDisplayNameComputed(false);
596 expectedDisplayName = "TestName";
597 person.setDisplayName(expectedDisplayName);
599 // Submit the updated resource to the service and store the response.
600 output = new MultipartOutput();
601 commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
602 commonPart.getHeaders().add("label", client.getItemCommonPartName());
603 res = client.updateItem(knownResourceId, knownItemResourceId, output);
604 statusCode = res.getStatus();
606 // Check the status code of the response: does it match the expected response(s)?
607 if(logger.isDebugEnabled()){
608 logger.debug("updateItem: status = " + statusCode);
610 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
611 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
612 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
614 // Retrieve the updated resource and verify that its contents exist.
615 input = (MultipartInput) res.getEntity();
617 (PersonsCommon) extractPart(input,
618 client.getItemCommonPartName(), PersonsCommon.class);
619 Assert.assertNotNull(updatedPerson);
621 // Verify that the updated resource received the correct data.
622 Assert.assertEquals(updatedPerson.isDisplayNameComputed(), false,
623 "Updated displayNameComputed in Person did not match submitted data.");
624 // Verify that the updated resource computes the right displayName.
625 Assert.assertEquals(updatedPerson.getDisplayName(),
627 "Updated DisplayName (not computed) in Person not stored.");
630 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
631 dependsOnMethods = {"verifyItemDisplayName"})
632 public void verifyIllegalItemDisplayName(String testName) throws Exception {
635 setupUpdateWithWrongXmlSchema(testName);
637 // Submit the request to the service and store the response.
638 PersonAuthorityClient client = new PersonAuthorityClient();
639 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
640 int statusCode = res.getStatus();
642 // Check the status code of the response: does it match
643 // the expected response(s)?
644 if(logger.isDebugEnabled()){
645 logger.debug(testName + ": status = " + statusCode);
647 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
648 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
649 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
651 // Check whether Person has expected displayName.
652 MultipartInput input = (MultipartInput) res.getEntity();
653 PersonsCommon person = (PersonsCommon) extractPart(input,
654 client.getItemCommonPartName(), PersonsCommon.class);
655 Assert.assertNotNull(person);
656 // Try to Update with computed false and no displayName
657 person.setDisplayNameComputed(false);
658 person.setDisplayName(null);
660 // Submit the updated resource to the service and store the response.
661 MultipartOutput output = new MultipartOutput();
662 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
663 commonPart.getHeaders().add("label", client.getItemCommonPartName());
664 res = client.updateItem(knownResourceId, knownItemResourceId, output);
665 statusCode = res.getStatus();
667 // Check the status code of the response: does it match the expected response(s)?
668 if(logger.isDebugEnabled()){
669 logger.debug("updateItem: status = " + statusCode);
671 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
672 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
673 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
676 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
677 groups = {"read"}, dependsOnMethods = {"readItem"})
678 public void readContact(String testName) throws Exception {
683 // Submit the request to the service and store the response.
684 PersonAuthorityClient client = new PersonAuthorityClient();
685 ClientResponse<MultipartInput> res =
686 client.readContact(knownResourceId, knownItemResourceId,
687 knownContactResourceId);
688 int statusCode = res.getStatus();
690 // Check the status code of the response: does it match
691 // the expected response(s)?
692 if(logger.isDebugEnabled()){
693 logger.debug(testName + ": status = " + statusCode);
695 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
696 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
697 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
699 // Check whether we've received a contact.
700 MultipartInput input = (MultipartInput) res.getEntity();
701 ContactsCommon contact = (ContactsCommon) extractPart(input,
702 new ContactClient().getCommonPartName(), ContactsCommon.class);
703 Assert.assertNotNull(contact);
704 boolean showFull = true;
705 if(showFull && logger.isDebugEnabled()){
706 logger.debug(testName + ": returned payload:");
707 logger.debug(objectAsXmlString(contact, ContactsCommon.class));
709 Assert.assertEquals(contact.getInAuthority(), knownResourceId);
710 Assert.assertEquals(contact.getInItem(), knownItemResourceId);
716 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
717 groups = {"read"}, dependsOnMethods = {"read"})
718 public void readNonExistent(String testName) {
721 setupReadNonExistent(testName);
723 // Submit the request to the service and store the response.
724 PersonAuthorityClient client = new PersonAuthorityClient();
725 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
726 int statusCode = res.getStatus();
728 // Check the status code of the response: does it match
729 // the expected response(s)?
730 if(logger.isDebugEnabled()){
731 logger.debug(testName + ": status = " + statusCode);
733 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
734 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
735 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
738 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
739 groups = {"read"}, dependsOnMethods = {"readItem"})
740 public void readItemNonExistent(String testName) {
743 setupReadNonExistent(testName);
745 // Submit the request to the service and store the response.
746 PersonAuthorityClient client = new PersonAuthorityClient();
747 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
748 int statusCode = res.getStatus();
750 // Check the status code of the response: does it match
751 // the expected response(s)?
752 if(logger.isDebugEnabled()){
753 logger.debug(testName + ": status = " + statusCode);
755 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
756 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
757 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
760 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
761 groups = {"read"}, dependsOnMethods = {"readContact"})
762 public void readContactNonExistent(String testName) {
765 setupReadNonExistent(testName);
767 // Submit the request to the service and store the response.
768 PersonAuthorityClient client = new PersonAuthorityClient();
769 ClientResponse<MultipartInput> res =
770 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
771 int statusCode = res.getStatus();
773 // Check the status code of the response: does it match
774 // the expected response(s)?
775 if(logger.isDebugEnabled()){
776 logger.debug(testName + ": status = " + statusCode);
778 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
779 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
780 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
783 // ---------------------------------------------------------------
784 // CRUD tests : READ_LIST tests
785 // ---------------------------------------------------------------
789 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
790 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
791 public void readList(String testName) throws Exception {
794 setupReadList(testName);
796 // Submit the request to the service and store the response.
797 PersonAuthorityClient client = new PersonAuthorityClient();
798 ClientResponse<PersonauthoritiesCommonList> res = client.readList();
799 PersonauthoritiesCommonList list = res.getEntity();
800 int statusCode = res.getStatus();
802 // Check the status code of the response: does it match
803 // the expected response(s)?
804 if(logger.isDebugEnabled()){
805 logger.debug(testName + ": status = " + statusCode);
807 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
808 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
809 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
811 // Optionally output additional data about list members for debugging.
812 boolean iterateThroughList = false;
813 if (iterateThroughList && logger.isDebugEnabled()) {
814 List<PersonauthoritiesCommonList.PersonauthorityListItem> items =
815 list.getPersonauthorityListItem();
817 for (PersonauthoritiesCommonList.PersonauthorityListItem item : items) {
818 String csid = item.getCsid();
819 logger.debug(testName + ": list-item[" + i + "] csid=" +
821 logger.debug(testName + ": list-item[" + i + "] displayName=" +
822 item.getDisplayName());
823 logger.debug(testName + ": list-item[" + i + "] URI=" +
825 readItemList(csid, null);
831 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
832 public void readItemList() {
833 readItemList(knownResourceId, null);
836 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
837 public void readItemListByAuthorityName() {
838 readItemList(null, knownResourceDisplayName);
840 private void readItemList(String vcsid, String name) {
842 final String testName = "readItemList";
845 setupReadList(testName);
847 // Submit the request to the service and store the response.
848 PersonAuthorityClient client = new PersonAuthorityClient();
849 ClientResponse<PersonsCommonList> res = null;
851 res = client.readItemList(vcsid);
852 } else if(name!= null) {
853 res = client.readItemListForNamedAuthority(name);
855 Assert.fail("readItemList passed null csid and name!");
857 PersonsCommonList list = res.getEntity();
858 int statusCode = res.getStatus();
860 // Check the status code of the response: does it match
861 // the expected response(s)?
862 if(logger.isDebugEnabled()){
863 logger.debug(testName + ": status = " + statusCode);
865 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
866 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
867 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
869 List<PersonsCommonList.PersonListItem> items =
870 list.getPersonListItem();
871 int nItemsReturned = items.size();
872 // There will be one item created, associated with a
873 // known parent resource, by the createItem test.
875 // In addition, there will be 'nItemsToCreateInList'
876 // additional items created by the createItemList test,
877 // all associated with the same parent resource.
878 int nExpectedItems = nItemsToCreateInList + 1;
879 if(logger.isDebugEnabled()){
880 logger.debug(testName + ": Expected "
881 + nExpectedItems +" items; got: "+nItemsReturned);
883 Assert.assertEquals(nItemsReturned, nExpectedItems);
886 for (PersonsCommonList.PersonListItem item : items) {
887 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
888 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
889 // Optionally output additional data about list members for debugging.
890 boolean showDetails = true;
891 if (showDetails && logger.isDebugEnabled()) {
892 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
894 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
896 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
897 item.getDisplayName());
898 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
905 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
906 public void readContactList() {
907 readContactList(knownResourceId, knownItemResourceId);
910 private void readContactList(String parentcsid, String itemcsid) {
911 final String testName = "readContactList";
914 setupReadList(testName);
916 // Submit the request to the service and store the response.
917 PersonAuthorityClient client = new PersonAuthorityClient();
918 ClientResponse<ContactsCommonList> res =
919 client.readContactList(parentcsid, itemcsid);
920 ContactsCommonList list = res.getEntity();
921 int statusCode = res.getStatus();
923 // Check the status code of the response: does it match
924 // the expected response(s)?
925 if(logger.isDebugEnabled()){
926 logger.debug(testName + ": status = " + statusCode);
928 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
929 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
930 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
932 List<ContactsCommonList.ContactListItem> listitems =
933 list.getContactListItem();
934 int nItemsReturned = listitems.size();
935 // There will be one item created, associated with a
936 // known parent resource, by the createItem test.
938 // In addition, there will be 'nItemsToCreateInList'
939 // additional items created by the createItemList test,
940 // all associated with the same parent resource.
941 int nExpectedItems = nItemsToCreateInList + 1;
942 if(logger.isDebugEnabled()){
943 logger.debug(testName + ": Expected "
944 + nExpectedItems +" items; got: "+nItemsReturned);
946 Assert.assertEquals(nItemsReturned, nExpectedItems);
949 for (ContactsCommonList.ContactListItem listitem : listitems) {
950 // Optionally output additional data about list members for debugging.
951 boolean showDetails = false;
952 if (showDetails && logger.isDebugEnabled()) {
953 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
955 logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" +
956 listitem.getAddressPlace());
957 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
967 // ---------------------------------------------------------------
968 // CRUD tests : UPDATE tests
969 // ---------------------------------------------------------------
972 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
973 groups = {"update"}, dependsOnGroups = {"read", "readList"})
974 public void update(String testName) throws Exception {
977 setupUpdate(testName);
979 // Retrieve the contents of a resource to update.
980 PersonAuthorityClient client = new PersonAuthorityClient();
981 ClientResponse<MultipartInput> res =
982 client.read(knownResourceId);
983 if(logger.isDebugEnabled()){
984 logger.debug(testName + ": read status = " + res.getStatus());
986 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
988 if(logger.isDebugEnabled()){
989 logger.debug("got PersonAuthority to update with ID: " + knownResourceId);
991 MultipartInput input = (MultipartInput) res.getEntity();
992 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
993 client.getCommonPartName(), PersonauthoritiesCommon.class);
994 Assert.assertNotNull(personAuthority);
996 // Update the contents of this resource.
997 personAuthority.setDisplayName("updated-" + personAuthority.getDisplayName());
998 personAuthority.setVocabType("updated-" + personAuthority.getVocabType());
999 if(logger.isDebugEnabled()){
1000 logger.debug("to be updated PersonAuthority");
1001 logger.debug(objectAsXmlString(personAuthority, PersonauthoritiesCommon.class));
1004 // Submit the updated resource to the service and store the response.
1005 MultipartOutput output = new MultipartOutput();
1006 OutputPart commonPart = output.addPart(personAuthority, MediaType.APPLICATION_XML_TYPE);
1007 commonPart.getHeaders().add("label", client.getCommonPartName());
1008 res = client.update(knownResourceId, output);
1009 int statusCode = res.getStatus();
1011 // Check the status code of the response: does it match the expected response(s)?
1012 if(logger.isDebugEnabled()){
1013 logger.debug(testName + ": status = " + statusCode);
1015 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1016 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1017 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1019 // Retrieve the updated resource and verify that its contents exist.
1020 input = (MultipartInput) res.getEntity();
1021 PersonauthoritiesCommon updatedPersonAuthority =
1022 (PersonauthoritiesCommon) extractPart(input,
1023 client.getCommonPartName(), PersonauthoritiesCommon.class);
1024 Assert.assertNotNull(updatedPersonAuthority);
1026 // Verify that the updated resource received the correct data.
1027 Assert.assertEquals(updatedPersonAuthority.getDisplayName(),
1028 personAuthority.getDisplayName(),
1029 "Data in updated object did not match submitted data.");
1032 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1033 groups = {"update"}, dependsOnMethods = {"update"})
1034 public void updateItem(String testName) throws Exception {
1037 setupUpdate(testName);
1039 // Retrieve the contents of a resource to update.
1040 PersonAuthorityClient client = new PersonAuthorityClient();
1041 ClientResponse<MultipartInput> res =
1042 client.readItem(knownResourceId, knownItemResourceId);
1043 if(logger.isDebugEnabled()){
1044 logger.debug(testName + ": read status = " + res.getStatus());
1046 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1048 if(logger.isDebugEnabled()){
1049 logger.debug("got Person to update with ID: " +
1050 knownItemResourceId +
1051 " in PersonAuthority: " + knownResourceId );
1053 MultipartInput input = (MultipartInput) res.getEntity();
1054 PersonsCommon person = (PersonsCommon) extractPart(input,
1055 client.getItemCommonPartName(), PersonsCommon.class);
1056 Assert.assertNotNull(person);
1058 // Update the contents of this resource.
1059 person.setCsid(null);
1060 person.setForeName("updated-" + person.getForeName());
1061 if(logger.isDebugEnabled()){
1062 logger.debug("to be updated Person");
1063 logger.debug(objectAsXmlString(person,
1064 PersonsCommon.class));
1067 // Submit the updated resource to the service and store the response.
1068 MultipartOutput output = new MultipartOutput();
1069 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
1070 commonPart.getHeaders().add("label", client.getItemCommonPartName());
1071 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1072 int statusCode = res.getStatus();
1074 // Check the status code of the response: does it match the expected response(s)?
1075 if(logger.isDebugEnabled()){
1076 logger.debug(testName + ": status = " + statusCode);
1078 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1079 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1080 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1082 // Retrieve the updated resource and verify that its contents exist.
1083 input = (MultipartInput) res.getEntity();
1084 PersonsCommon updatedPerson =
1085 (PersonsCommon) extractPart(input,
1086 client.getItemCommonPartName(), PersonsCommon.class);
1087 Assert.assertNotNull(updatedPerson);
1089 // Verify that the updated resource received the correct data.
1090 Assert.assertEquals(updatedPerson.getForeName(),
1091 person.getForeName(),
1092 "Data in updated Person did not match submitted data.");
1095 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1096 groups = {"update"}, dependsOnMethods = {"updateItem"})
1097 public void updateContact(String testName) throws Exception {
1100 setupUpdate(testName);
1102 // Retrieve the contents of a resource to update.
1103 PersonAuthorityClient client = new PersonAuthorityClient();
1104 ClientResponse<MultipartInput> res =
1105 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1106 if(logger.isDebugEnabled()){
1107 logger.debug(testName + ": read status = " + res.getStatus());
1109 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1111 if(logger.isDebugEnabled()){
1112 logger.debug("got Contact to update with ID: " +
1113 knownContactResourceId +
1114 " in item: " + knownItemResourceId +
1115 " in parent: " + knownResourceId );
1117 MultipartInput input = (MultipartInput) res.getEntity();
1118 ContactsCommon contact = (ContactsCommon) extractPart(input,
1119 new ContactClient().getCommonPartName(), ContactsCommon.class);
1120 Assert.assertNotNull(contact);
1122 // Update the contents of this resource.
1123 contact.setAddressPlace("updated-" + contact.getAddressPlace());
1124 if(logger.isDebugEnabled()){
1125 logger.debug("to be updated Contact");
1126 logger.debug(objectAsXmlString(contact,
1127 ContactsCommon.class));
1130 // Submit the updated resource to the service and store the response.
1131 MultipartOutput output = new MultipartOutput();
1132 OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1133 commonPart.getHeaders().add("label", new ContactClient().getCommonPartName());
1134 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1135 int statusCode = res.getStatus();
1137 // Check the status code of the response: does it match the expected response(s)?
1138 if(logger.isDebugEnabled()){
1139 logger.debug(testName + ": status = " + statusCode);
1141 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1142 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1143 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1145 // Retrieve the updated resource and verify that its contents exist.
1146 input = (MultipartInput) res.getEntity();
1147 ContactsCommon updatedContact =
1148 (ContactsCommon) extractPart(input,
1149 new ContactClient().getCommonPartName(), ContactsCommon.class);
1150 Assert.assertNotNull(updatedContact);
1152 // Verify that the updated resource received the correct data.
1153 Assert.assertEquals(updatedContact.getAddressPlace(),
1154 contact.getAddressPlace(),
1155 "Data in updated Contact did not match submitted data.");
1159 // Placeholders until the three tests below can be uncommented.
1160 // See Issue CSPACE-401.
1162 public void updateWithEmptyEntityBody(String testName) throws Exception {
1166 public void updateWithMalformedXml(String testName) throws Exception {
1170 public void updateWithWrongXmlSchema(String testName) throws Exception {
1175 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1176 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1177 public void updateWithEmptyEntityBody(String testName) throws Exception {
1180 setupUpdateWithEmptyEntityBody(testName);
1182 // Submit the request to the service and store the response.
1183 String method = REQUEST_TYPE.httpMethodName();
1184 String url = getResourceURL(knownResourceId);
1185 String mediaType = MediaType.APPLICATION_XML;
1186 final String entity = "";
1187 int statusCode = submitRequest(method, url, mediaType, entity);
1189 // Check the status code of the response: does it match
1190 // the expected response(s)?
1191 if(logger.isDebugEnabled()){
1192 logger.debug(testName + ": url=" + url +
1193 " status=" + statusCode);
1195 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1196 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1197 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1201 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1202 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1203 public void updateWithMalformedXml(String testName) throws Exception {
1206 setupUpdateWithMalformedXml(testName);
1208 // Submit the request to the service and store the response.
1209 String method = REQUEST_TYPE.httpMethodName();
1210 String url = getResourceURL(knownResourceId);
1211 String mediaType = MediaType.APPLICATION_XML;
1212 final String entity = MALFORMED_XML_DATA;
1213 int statusCode = submitRequest(method, url, mediaType, entity);
1215 // Check the status code of the response: does it match
1216 // the expected response(s)?
1217 if(logger.isDebugEnabled()){
1218 logger.debug(testName + ": url=" + url +
1219 " status=" + statusCode);
1221 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1222 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1223 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1227 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1228 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1229 public void updateWithWrongXmlSchema(String testName) throws Exception {
1232 setupUpdateWithWrongXmlSchema(testName);
1234 // Submit the request to the service and store the response.
1235 String method = REQUEST_TYPE.httpMethodName();
1236 String url = getResourceURL(knownResourceId);
1237 String mediaType = MediaType.APPLICATION_XML;
1238 final String entity = WRONG_XML_SCHEMA_DATA;
1239 int statusCode = submitRequest(method, url, mediaType, entity);
1241 // Check the status code of the response: does it match
1242 // the expected response(s)?
1243 if(logger.isDebugEnabled()){
1244 logger.debug("updateWithWrongXmlSchema: url=" + url +
1245 " status=" + statusCode);
1247 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1248 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1249 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1254 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1255 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1256 public void updateNonExistent(String testName) throws Exception {
1259 setupUpdateNonExistent(testName);
1261 // Submit the request to the service and store the response.
1262 // Note: The ID(s) used when creating the request payload may be arbitrary.
1263 // The only relevant ID may be the one used in update(), below.
1264 PersonAuthorityClient client = new PersonAuthorityClient();
1265 String displayName = "displayName-NON_EXISTENT_ID";
1266 String fullRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, true);
1267 MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
1268 displayName, fullRefName, client.getCommonPartName());
1269 ClientResponse<MultipartInput> res =
1270 client.update(NON_EXISTENT_ID, multipart);
1271 int statusCode = res.getStatus();
1273 // Check the status code of the response: does it match
1274 // the expected response(s)?
1275 if(logger.isDebugEnabled()){
1276 logger.debug(testName + ": status = " + statusCode);
1278 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1279 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1280 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1283 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1284 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1285 public void updateNonExistentItem(String testName) throws Exception {
1288 setupUpdateNonExistent(testName);
1290 // Submit the request to the service and store the response.
1291 // Note: The ID used in this 'create' call may be arbitrary.
1292 // The only relevant ID may be the one used in update(), below.
1293 PersonAuthorityClient client = new PersonAuthorityClient();
1294 Map<String, String> nonexMap = new HashMap<String,String>();
1295 nonexMap.put(PersonJAXBSchema.FORE_NAME, "John");
1296 nonexMap.put(PersonJAXBSchema.SUR_NAME, "Wayne");
1297 nonexMap.put(PersonJAXBSchema.GENDER, "male");
1298 MultipartOutput multipart =
1299 PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID,
1300 PersonAuthorityClientUtils.createPersonRefName(NON_EXISTENT_ID, NON_EXISTENT_ID, true), nonexMap,
1301 client.getItemCommonPartName() );
1302 ClientResponse<MultipartInput> res =
1303 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1304 int statusCode = res.getStatus();
1306 // Check the status code of the response: does it match
1307 // the expected response(s)?
1308 if(logger.isDebugEnabled()){
1309 logger.debug(testName + ": status = " + statusCode);
1311 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1312 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1313 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1316 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1317 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1318 public void updateNonExistentContact(String testName) throws Exception {
1319 // Currently a no-op test
1322 // ---------------------------------------------------------------
1323 // CRUD tests : DELETE tests
1324 // ---------------------------------------------------------------
1327 // Note: delete sub-resources in ascending hierarchical order,
1328 // before deleting their parents.
1330 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1331 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1332 public void deleteContact(String testName) throws Exception {
1335 setupDelete(testName);
1337 if(logger.isDebugEnabled()){
1338 logger.debug("parentcsid =" + knownResourceId +
1339 " itemcsid = " + knownItemResourceId +
1340 " csid = " + knownContactResourceId);
1343 // Submit the request to the service and store the response.
1344 PersonAuthorityClient client = new PersonAuthorityClient();
1345 ClientResponse<Response> res =
1346 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1347 int statusCode = res.getStatus();
1349 // Check the status code of the response: does it match
1350 // the expected response(s)?
1351 if(logger.isDebugEnabled()){
1352 logger.debug(testName + ": status = " + statusCode);
1354 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1355 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1356 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1359 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1360 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1361 public void deleteItem(String testName) throws Exception {
1364 setupDelete(testName);
1366 if(logger.isDebugEnabled()){
1367 logger.debug("parentcsid =" + knownResourceId +
1368 " itemcsid = " + knownItemResourceId);
1371 // Submit the request to the service and store the response.
1372 PersonAuthorityClient client = new PersonAuthorityClient();
1373 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1374 int statusCode = res.getStatus();
1376 // Check the status code of the response: does it match
1377 // the expected response(s)?
1378 if(logger.isDebugEnabled()){
1379 logger.debug(testName + ": status = " + statusCode);
1381 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1382 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1383 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1387 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1388 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1389 public void delete(String testName) throws Exception {
1392 setupDelete(testName);
1394 if(logger.isDebugEnabled()){
1395 logger.debug("parentcsid =" + knownResourceId);
1398 // Submit the request to the service and store the response.
1399 PersonAuthorityClient client = new PersonAuthorityClient();
1400 ClientResponse<Response> res = client.delete(knownResourceId);
1401 int statusCode = res.getStatus();
1403 // Check the status code of the response: does it match
1404 // the expected response(s)?
1405 if(logger.isDebugEnabled()){
1406 logger.debug(testName + ": status = " + statusCode);
1408 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1409 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1410 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1415 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1416 groups = {"delete"}, dependsOnMethods = {"delete"})
1417 public void deleteNonExistent(String testName) throws Exception {
1420 setupDeleteNonExistent(testName);
1422 // Submit the request to the service and store the response.
1423 PersonAuthorityClient client = new PersonAuthorityClient();
1424 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1425 int statusCode = res.getStatus();
1427 // Check the status code of the response: does it match
1428 // the expected response(s)?
1429 if(logger.isDebugEnabled()){
1430 logger.debug(testName + ": status = " + statusCode);
1432 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1433 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1434 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1437 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1438 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1439 public void deleteNonExistentItem(String testName) {
1442 setupDeleteNonExistent(testName);
1444 // Submit the request to the service and store the response.
1445 PersonAuthorityClient client = new PersonAuthorityClient();
1446 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1447 int statusCode = res.getStatus();
1449 // Check the status code of the response: does it match
1450 // the expected response(s)?
1451 if(logger.isDebugEnabled()){
1452 logger.debug(testName + ": status = " + statusCode);
1454 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1455 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1456 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1459 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1460 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1461 public void deleteNonExistentContact(String testName) {
1464 setupDeleteNonExistent(testName);
1466 // Submit the request to the service and store the response.
1467 PersonAuthorityClient client = new PersonAuthorityClient();
1468 ClientResponse<Response> res =
1469 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1470 int statusCode = res.getStatus();
1472 // Check the status code of the response: does it match
1473 // the expected response(s)?
1474 if(logger.isDebugEnabled()){
1475 logger.debug(testName + ": status = " + statusCode);
1477 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1478 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1479 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1482 // ---------------------------------------------------------------
1483 // Utility tests : tests of code used in tests above
1484 // ---------------------------------------------------------------
1486 * Tests the code for manually submitting data that is used by several
1487 * of the methods above.
1489 @Test(dependsOnMethods = {"create", "read"})
1490 public void testSubmitRequest() {
1492 // Expected status code: 200 OK
1493 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1495 // Submit the request to the service and store the response.
1496 String method = ServiceRequestType.READ.httpMethodName();
1497 String url = getResourceURL(knownResourceId);
1498 int statusCode = submitRequest(method, url);
1500 // Check the status code of the response: does it match
1501 // the expected response(s)?
1502 if(logger.isDebugEnabled()){
1503 logger.debug("testSubmitRequest: url=" + url +
1504 " status=" + statusCode);
1506 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1510 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1511 public void testItemSubmitRequest() {
1513 // Expected status code: 200 OK
1514 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1516 // Submit the request to the service and store the response.
1517 String method = ServiceRequestType.READ.httpMethodName();
1518 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1519 int statusCode = submitRequest(method, url);
1521 // Check the status code of the response: does it match
1522 // the expected response(s)?
1523 if(logger.isDebugEnabled()){
1524 logger.debug("testItemSubmitRequest: url=" + url +
1525 " status=" + statusCode);
1527 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1531 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
1532 public void testContactSubmitRequest() {
1534 // Expected status code: 200 OK
1535 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1537 // Submit the request to the service and store the response.
1538 String method = ServiceRequestType.READ.httpMethodName();
1539 String url = getContactResourceURL(knownResourceId,
1540 knownItemResourceId, knownContactResourceId);
1541 int statusCode = submitRequest(method, url);
1543 // Check the status code of the response: does it match
1544 // the expected response(s)?
1545 if(logger.isDebugEnabled()){
1546 logger.debug("testItemSubmitRequest: url=" + url +
1547 " status=" + statusCode);
1549 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1554 // ---------------------------------------------------------------
1555 // Cleanup of resources created during testing
1556 // ---------------------------------------------------------------
1559 * Deletes all resources created by tests, after all tests have been run.
1561 * This cleanup method will always be run, even if one or more tests fail.
1562 * For this reason, it attempts to remove all resources created
1563 * at any point during testing, even if some of those resources
1564 * may be expected to be deleted by certain tests.
1567 @AfterClass(alwaysRun=true)
1568 public void cleanUp() {
1569 if (logger.isDebugEnabled()) {
1570 logger.debug("Cleaning up temporary resources created for testing ...");
1572 String parentResourceId;
1573 String itemResourceId;
1574 String contactResourceId;
1575 // Clean up contact resources.
1576 PersonAuthorityClient client = new PersonAuthorityClient();
1577 parentResourceId = knownResourceId;
1578 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
1579 contactResourceId = entry.getKey();
1580 itemResourceId = entry.getValue();
1581 // Note: Any non-success responses from the delete operation
1582 // below are ignored and not reported.
1583 ClientResponse<Response> res =
1584 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
1586 // Clean up item resources.
1587 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1588 itemResourceId = entry.getKey();
1589 parentResourceId = entry.getValue();
1590 // Note: Any non-success responses from the delete operation
1591 // below are ignored and not reported.
1592 ClientResponse<Response> res =
1593 client.deleteItem(parentResourceId, itemResourceId);
1595 // Clean up parent resources.
1596 for (String resourceId : allResourceIdsCreated) {
1597 // Note: Any non-success responses from the delete operation
1598 // below are ignored and not reported.
1599 ClientResponse<Response> res = client.delete(resourceId);
1603 // ---------------------------------------------------------------
1604 // Utility methods used by tests above
1605 // ---------------------------------------------------------------
1607 public String getServicePathComponent() {
1608 return SERVICE_PATH_COMPONENT;
1611 public String getItemServicePathComponent() {
1612 return ITEM_SERVICE_PATH_COMPONENT;
1615 public String getContactServicePathComponent() {
1616 return CONTACT_SERVICE_PATH_COMPONENT;
1620 * Returns the root URL for the item service.
1622 * This URL consists of a base URL for all services, followed by
1623 * a path component for the owning parent, followed by the
1624 * path component for the items.
1626 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1627 * parent authority resource of the relevant item resource.
1629 * @return The root URL for the item service.
1631 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1632 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1636 * Returns the URL of a specific item resource managed by a service, and
1637 * designated by an identifier (such as a universally unique ID, or UUID).
1639 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1640 * parent authority resource of the relevant item resource.
1642 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1645 * @return The URL of a specific item resource managed by a service.
1647 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1648 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
1653 * Returns the root URL for the contact service.
1655 * This URL consists of a base URL for all services, followed by
1656 * a path component for the owning authority, followed by the
1657 * path component for the owning item, followed by the path component
1658 * for the contact service.
1660 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1661 * parent authority resource of the relevant item resource.
1663 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1666 * @return The root URL for the contact service.
1668 protected String getContactServiceRootURL(String parentResourceIdentifier,
1669 String itemResourceIdentifier) {
1670 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
1671 getContactServicePathComponent();
1675 * Returns the URL of a specific contact resource managed by a service, and
1676 * designated by an identifier (such as a universally unique ID, or UUID).
1678 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1679 * parent resource of the relevant item resource.
1681 * @param resourceIdentifier An identifier (such as a UUID) for an
1684 * @return The URL of a specific resource managed by a service.
1686 protected String getContactResourceURL(String parentResourceIdentifier,
1687 String itemResourceIdentifier, String contactResourceIdentifier) {
1688 return getContactServiceRootURL(parentResourceIdentifier,
1689 itemResourceIdentifier) + "/" + contactResourceIdentifier;