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;
30 import javax.ws.rs.core.MediaType;
31 import javax.ws.rs.core.MultivaluedMap;
32 import javax.ws.rs.core.Response;
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.PersonJAXBSchema;
39 import org.collectionspace.services.client.PersonAuthorityClient;
40 import org.collectionspace.services.client.PersonAuthorityClientUtils;
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 {
64 private final Logger logger =
65 LoggerFactory.getLogger(PersonAuthorityServiceTest.class);
67 // Instance variables specific to this test.
68 private PersonAuthorityClient client = new PersonAuthorityClient();
69 private ContactClient contactClient = new ContactClient();
70 final String SERVICE_PATH_COMPONENT = "personauthorities";
71 final String ITEM_SERVICE_PATH_COMPONENT = "items";
72 final String CONTACT_SERVICE_PATH_COMPONENT = "contacts";
73 final String TEST_FORE_NAME = "John";
74 final String TEST_MIDDLE_NAME = null;
75 final String TEST_SUR_NAME = "Wayne";
76 final String TEST_BIRTH_DATE = "May 26, 1907";
77 final String TEST_DEATH_DATE = "June 11, 1979";
79 private String knownResourceId = null;
80 private String knownResourceRefName = null;
81 private String knownItemResourceId = null;
82 private String knownContactResourceId = null;
83 private int nItemsToCreateInList = 3;
84 private List<String> allResourceIdsCreated = new ArrayList<String>();
85 private Map<String, String> allItemResourceIdsCreated =
86 new HashMap<String, String>();
87 private Map<String, String> allContactResourceIdsCreated =
88 new HashMap<String, String>();
90 // ---------------------------------------------------------------
91 // CRUD tests : CREATE tests
92 // ---------------------------------------------------------------
95 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
97 public void create(String testName) throws Exception {
99 // Perform setup, such as initializing the type of service request
100 // (e.g. CREATE, DELETE), its valid and expected status codes, and
101 // its associated HTTP method name (e.g. POST, DELETE).
102 setupCreate(testName);
104 // Submit the request to the service and store the response.
105 String identifier = createIdentifier();
106 String displayName = "displayName-" + identifier;
107 String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, false);
108 String fullRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, true);
109 MultipartOutput multipart =
110 PersonAuthorityClientUtils.createPersonAuthorityInstance(
111 displayName, fullRefName, client.getCommonPartName());
112 ClientResponse<Response> res = client.create(multipart);
113 int statusCode = res.getStatus();
115 // Check the status code of the response: does it match
116 // the expected response(s)?
119 // Does it fall within the set of valid status codes?
120 // Does it exactly match the expected status code?
121 if(logger.isDebugEnabled()){
122 logger.debug(testName + ": status = " + statusCode);
124 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
125 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
126 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
128 // Store the refname from the first resource created
129 // for additional tests below.
130 knownResourceRefName = baseRefName;
132 String newID = PersonAuthorityClientUtils.extractId(res);
133 // Store the ID returned from the first resource created
134 // for additional tests below.
135 if (knownResourceId == null){
136 knownResourceId = newID;
137 if (logger.isDebugEnabled()) {
138 logger.debug(testName + ": knownResourceId=" + knownResourceId);
141 // Store the IDs from every resource created by tests,
142 // so they can be deleted after tests have been run.
143 allResourceIdsCreated.add(newID);
147 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
148 groups = {"create"}, dependsOnMethods = {"create"})
149 public void createItem(String testName) {
150 setupCreate(testName);
151 String newID = createItemInAuthority(knownResourceId, knownResourceRefName);
154 private String createItemInAuthority(String vcsid, String authRefName) {
156 final String testName = "createItemInAuthority";
157 if(logger.isDebugEnabled()){
158 logger.debug(testName + ":...");
161 // Submit the request to the service and store the response.
162 String identifier = createIdentifier();
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 String refName = PersonAuthorityClientUtils.createPersonRefName(authRefName, "John Wayne", true);
177 MultipartOutput multipart =
178 PersonAuthorityClientUtils.createPersonInstance(vcsid, refName, johnWayneMap,
179 client.getItemCommonPartName() );
180 ClientResponse<Response> res = client.createItem(vcsid, multipart);
181 int statusCode = res.getStatus();
182 String newID = PersonAuthorityClientUtils.extractId(res);
184 // Check the status code of the response: does it match
185 // the expected response(s)?
186 if(logger.isDebugEnabled()){
187 logger.debug(testName + ": status = " + statusCode);
189 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
190 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
191 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
193 // Store the ID returned from the first item resource created
194 // for additional tests below.
195 if (knownItemResourceId == null){
196 knownItemResourceId = newID;
197 if (logger.isDebugEnabled()) {
198 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
202 // Store the IDs from any item resources created
203 // by tests, along with the IDs of their parents, so these items
204 // can be deleted after all tests have been run.
205 allItemResourceIdsCreated.put(newID, vcsid);
210 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
211 groups = {"create"}, dependsOnMethods = {"createItem"})
212 public void createContact(String testName) {
213 setupCreate(testName);
214 String newID = createContactInItem(knownResourceId, knownItemResourceId);
217 private String createContactInItem(String parentcsid, String itemcsid) {
219 final String testName = "createContactInItem";
220 setupCreate(testName);
221 if(logger.isDebugEnabled()){
222 logger.debug(testName + ":...");
225 // Submit the request to the service and store the response.
226 String identifier = createIdentifier();
227 MultipartOutput multipart =
228 ContactClientUtils.createContactInstance(parentcsid,
229 itemcsid, identifier, 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);
262 // Placeholders until the three tests below can be uncommented.
263 // See Issue CSPACE-401.
265 public void createWithEmptyEntityBody(String testName) throws Exception {
269 public void createWithMalformedXml(String testName) throws Exception {
273 public void createWithWrongXmlSchema(String testName) throws Exception {
278 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
279 dependsOnMethods = {"create", "testSubmitRequest"})
280 public void createWithEmptyEntityBody(String testName) throws Exception {
283 setupCreateWithEmptyEntityBody(testName);
285 // Submit the request to the service and store the response.
286 String method = REQUEST_TYPE.httpMethodName();
287 String url = getServiceRootURL();
288 String mediaType = MediaType.APPLICATION_XML;
289 final String entity = "";
290 int statusCode = submitRequest(method, url, mediaType, entity);
292 // Check the status code of the response: does it match
293 // the expected response(s)?
294 if(logger.isDebugEnabled()) {
295 logger.debug(testName + ": url=" + url +
296 " status=" + statusCode);
298 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
299 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
300 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
304 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
305 dependsOnMethods = {"create", "testSubmitRequest"})
306 public void createWithMalformedXml(String testName) throws Exception {
309 setupCreateWithMalformedXml(testName);
311 // Submit the request to the service and store the response.
312 String method = REQUEST_TYPE.httpMethodName();
313 String url = getServiceRootURL();
314 String mediaType = MediaType.APPLICATION_XML;
315 final String entity = MALFORMED_XML_DATA; // Constant from base class.
316 int statusCode = submitRequest(method, url, mediaType, entity);
318 // Check the status code of the response: does it match
319 // the expected response(s)?
320 if(logger.isDebugEnabled()){
321 logger.debug(testName + ": url=" + url +
322 " status=" + statusCode);
324 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
325 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
326 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
330 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
331 dependsOnMethods = {"create", "testSubmitRequest"})
332 public void createWithWrongXmlSchema(String testName) throws Exception {
335 setupCreateWithWrongXmlSchema(testName);
337 // Submit the request to the service and store the response.
338 String method = REQUEST_TYPE.httpMethodName();
339 String url = getServiceRootURL();
340 String mediaType = MediaType.APPLICATION_XML;
341 final String entity = WRONG_XML_SCHEMA_DATA;
342 int statusCode = submitRequest(method, url, mediaType, entity);
344 // Check the status code of the response: does it match
345 // the expected response(s)?
346 if(logger.isDebugEnabled()){
347 logger.debug(testName + ": url=" + url +
348 " status=" + statusCode);
350 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
351 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
352 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
356 // ---------------------------------------------------------------
357 // CRUD tests : CREATE LIST tests
358 // ---------------------------------------------------------------
361 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
362 groups = {"createList"}, dependsOnGroups = {"create"})
363 public void createList(String testName) throws Exception {
364 for (int i = 0; i < nItemsToCreateInList; i++) {
369 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
370 groups = {"createList"}, dependsOnGroups = {"create"})
371 public void createItemList(String testName) throws Exception {
372 // Add items to the initially-created, known parent record.
373 for (int j = 0; j < nItemsToCreateInList; j++) {
374 createItem(testName);
378 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
379 groups = {"createList"}, dependsOnGroups = {"create"})
380 public void createContactList(String testName) throws Exception {
381 // Add contacts to the initially-created, known item record.
382 for (int j = 0; j < nItemsToCreateInList; j++) {
383 createContact(testName);
387 // ---------------------------------------------------------------
388 // CRUD tests : READ tests
389 // ---------------------------------------------------------------
392 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
393 groups = {"read"}, dependsOnGroups = {"create"})
394 public void read(String testName) throws Exception {
399 // Submit the request to the service and store the response.
400 ClientResponse<MultipartInput> res = client.read(knownResourceId);
401 int statusCode = res.getStatus();
403 // Check the status code of the response: does it match
404 // the expected response(s)?
405 if(logger.isDebugEnabled()){
406 logger.debug(testName + ": status = " + statusCode);
408 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
409 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
410 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
411 //FIXME: remove the following try catch once Aron fixes signatures
413 MultipartInput input = (MultipartInput) res.getEntity();
414 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
415 client.getCommonPartName(), PersonauthoritiesCommon.class);
416 Assert.assertNotNull(personAuthority);
417 } catch (Exception e) {
418 throw new RuntimeException(e);
423 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
424 groups = {"read"}, dependsOnMethods = {"read"})
425 public void readByName(String testName) throws Exception {
430 // Submit the request to the service and store the response.
431 ClientResponse<MultipartInput> res = client.read(knownResourceId);
432 int statusCode = res.getStatus();
434 // Check the status code of the response: does it match
435 // the expected response(s)?
436 if(logger.isDebugEnabled()){
437 logger.debug(testName + ": status = " + statusCode);
439 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
440 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
441 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
442 //FIXME: remove the following try catch once Aron fixes signatures
444 MultipartInput input = (MultipartInput) res.getEntity();
445 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
446 client.getCommonPartName(), PersonauthoritiesCommon.class);
447 Assert.assertNotNull(personAuthority);
448 } catch (Exception e) {
449 throw new RuntimeException(e);
454 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
455 groups = {"read"}, dependsOnMethods = {"read"})
456 public void readItem(String testName) throws Exception {
461 // Submit the request to the service and store the response.
462 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
463 int statusCode = res.getStatus();
465 // Check the status code of the response: does it match
466 // the expected response(s)?
467 if(logger.isDebugEnabled()){
468 logger.debug(testName + ": status = " + statusCode);
470 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
471 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
472 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
474 // Check whether we've received a person.
475 MultipartInput input = (MultipartInput) res.getEntity();
476 PersonsCommon person = (PersonsCommon) extractPart(input,
477 client.getItemCommonPartName(), PersonsCommon.class);
478 Assert.assertNotNull(person);
479 boolean showFull = true;
480 if(showFull && logger.isDebugEnabled()){
481 logger.debug(testName + ": returned payload:");
482 logger.debug(objectAsXmlString(person, PersonsCommon.class));
484 Assert.assertEquals(person.getInAuthority(), knownResourceId);
488 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
489 dependsOnMethods = {"readItem", "updateItem"})
490 public void verifyItemDisplayName(String testName) throws Exception {
493 setupUpdate(testName);
495 // Submit the request to the service and store the response.
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 person has expected displayName.
509 MultipartInput input = (MultipartInput) res.getEntity();
510 PersonsCommon person = (PersonsCommon) extractPart(input,
511 client.getItemCommonPartName(), PersonsCommon.class);
512 Assert.assertNotNull(person);
513 String displayName = person.getDisplayName();
514 // Make sure displayName matches computed form
515 String expectedDisplayName =
516 PersonAuthorityClientUtils.prepareDefaultDisplayName(
517 TEST_FORE_NAME, null, TEST_SUR_NAME,
518 TEST_BIRTH_DATE, TEST_DEATH_DATE);
519 Assert.assertNotNull(displayName, expectedDisplayName);
521 // Update the shortName and verify the computed name is updated.
522 person.setDisplayNameComputed(true);
523 person.setForeName("updated-" + TEST_FORE_NAME);
524 expectedDisplayName =
525 PersonAuthorityClientUtils.prepareDefaultDisplayName(
526 "updated-" + TEST_FORE_NAME, null, TEST_SUR_NAME,
527 TEST_BIRTH_DATE, TEST_DEATH_DATE);
529 // Submit the updated resource to the service and store the response.
530 MultipartOutput output = new MultipartOutput();
531 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
532 commonPart.getHeaders().add("label", client.getItemCommonPartName());
533 res = client.updateItem(knownResourceId, knownItemResourceId, output);
534 statusCode = res.getStatus();
536 // Check the status code of the response: does it match the expected response(s)?
537 if(logger.isDebugEnabled()){
538 logger.debug("updateItem: status = " + statusCode);
540 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
541 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
542 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
544 // Retrieve the updated resource and verify that its contents exist.
545 input = (MultipartInput) res.getEntity();
546 PersonsCommon updatedPerson =
547 (PersonsCommon) extractPart(input,
548 client.getItemCommonPartName(), PersonsCommon.class);
549 Assert.assertNotNull(updatedPerson);
551 // Verify that the updated resource received the correct data.
552 Assert.assertEquals(updatedPerson.getForeName(),
553 person.getForeName(),
554 "Updated ForeName in Person did not match submitted data.");
555 // Verify that the updated resource computes the right displayName.
556 Assert.assertEquals(updatedPerson.getDisplayName(),
558 "Updated ForeName in Person not reflected in computed DisplayName.");
560 // Now Update the displayName, not computed and verify the computed name is overriden.
561 person.setDisplayNameComputed(false);
562 expectedDisplayName = "TestName";
563 person.setDisplayName(expectedDisplayName);
565 // Submit the updated resource to the service and store the response.
566 output = new MultipartOutput();
567 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();
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.isDisplayNameComputed(), false,
589 "Updated displayNameComputed in Person did not match submitted data.");
590 // Verify that the updated resource computes the right displayName.
591 Assert.assertEquals(updatedPerson.getDisplayName(),
593 "Updated DisplayName (not computed) in Person not stored.");
596 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
597 dependsOnMethods = {"verifyItemDisplayName"})
598 public void verifyIllegalItemDisplayName(String testName) throws Exception {
601 setupUpdateWithWrongXmlSchema(testName);
603 // Submit the request to the service and store the response.
604 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
605 int statusCode = res.getStatus();
607 // Check the status code of the response: does it match
608 // the expected response(s)?
609 if(logger.isDebugEnabled()){
610 logger.debug(testName + ": status = " + statusCode);
612 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
613 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
614 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
616 // Check whether Person has expected displayName.
617 MultipartInput input = (MultipartInput) res.getEntity();
618 PersonsCommon person = (PersonsCommon) extractPart(input,
619 client.getItemCommonPartName(), PersonsCommon.class);
620 Assert.assertNotNull(person);
621 // Try to Update with computed false and no displayName
622 person.setDisplayNameComputed(false);
623 person.setDisplayName(null);
625 // Submit the updated resource to the service and store the response.
626 MultipartOutput output = new MultipartOutput();
627 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
628 commonPart.getHeaders().add("label", client.getItemCommonPartName());
629 res = client.updateItem(knownResourceId, knownItemResourceId, output);
630 statusCode = res.getStatus();
632 // Check the status code of the response: does it match the expected response(s)?
633 if(logger.isDebugEnabled()){
634 logger.debug("updateItem: status = " + statusCode);
636 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
637 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
638 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
641 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
642 groups = {"read"}, dependsOnMethods = {"readItem"})
643 public void readContact(String testName) throws Exception {
648 // Submit the request to the service and store the response.
649 ClientResponse<MultipartInput> res =
650 client.readContact(knownResourceId, knownItemResourceId,
651 knownContactResourceId);
652 int statusCode = res.getStatus();
654 // Check the status code of the response: does it match
655 // the expected response(s)?
656 if(logger.isDebugEnabled()){
657 logger.debug(testName + ": status = " + statusCode);
659 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
660 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
661 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
663 // Check whether we've received a contact.
664 MultipartInput input = (MultipartInput) res.getEntity();
665 ContactsCommon contact = (ContactsCommon) extractPart(input,
666 contactClient.getCommonPartName(), ContactsCommon.class);
667 Assert.assertNotNull(contact);
668 boolean showFull = true;
669 if(showFull && logger.isDebugEnabled()){
670 logger.debug(testName + ": returned payload:");
671 logger.debug(objectAsXmlString(contact, ContactsCommon.class));
673 Assert.assertEquals(contact.getInAuthority(), knownResourceId);
674 Assert.assertEquals(contact.getInItem(), knownItemResourceId);
680 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
681 groups = {"read"}, dependsOnMethods = {"read"})
682 public void readNonExistent(String testName) {
685 setupReadNonExistent(testName);
687 // Submit the request to the service and store the response.
688 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
689 int statusCode = res.getStatus();
691 // Check the status code of the response: does it match
692 // the expected response(s)?
693 if(logger.isDebugEnabled()){
694 logger.debug(testName + ": status = " + statusCode);
696 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
697 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
698 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
701 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
702 groups = {"read"}, dependsOnMethods = {"readItem"})
703 public void readItemNonExistent(String testName) {
706 setupReadNonExistent(testName);
708 // Submit the request to the service and store the response.
709 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
710 int statusCode = res.getStatus();
712 // Check the status code of the response: does it match
713 // the expected response(s)?
714 if(logger.isDebugEnabled()){
715 logger.debug(testName + ": status = " + statusCode);
717 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
718 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
719 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
722 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
723 groups = {"read"}, dependsOnMethods = {"readContact"})
724 public void readContactNonExistent(String testName) {
727 setupReadNonExistent(testName);
729 // Submit the request to the service and store the response.
730 ClientResponse<MultipartInput> res =
731 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
732 int statusCode = res.getStatus();
734 // Check the status code of the response: does it match
735 // the expected response(s)?
736 if(logger.isDebugEnabled()){
737 logger.debug(testName + ": status = " + statusCode);
739 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
740 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
741 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
744 // ---------------------------------------------------------------
745 // CRUD tests : READ_LIST tests
746 // ---------------------------------------------------------------
750 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
751 groups = {"readList"}, dependsOnGroups = {"create", "read"})
752 public void readList(String testName) throws Exception {
755 setupReadList(testName);
757 // Submit the request to the service and store the response.
758 ClientResponse<PersonauthoritiesCommonList> res = client.readList();
759 PersonauthoritiesCommonList list = res.getEntity();
760 int statusCode = res.getStatus();
762 // Check the status code of the response: does it match
763 // the expected response(s)?
764 if(logger.isDebugEnabled()){
765 logger.debug(testName + ": status = " + statusCode);
767 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
768 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
769 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
771 // Optionally output additional data about list members for debugging.
772 boolean iterateThroughList = false;
773 if (iterateThroughList && logger.isDebugEnabled()) {
774 List<PersonauthoritiesCommonList.PersonauthorityListItem> items =
775 list.getPersonauthorityListItem();
777 for (PersonauthoritiesCommonList.PersonauthorityListItem item : items) {
778 String csid = item.getCsid();
779 logger.debug(testName + ": list-item[" + i + "] csid=" +
781 logger.debug(testName + ": list-item[" + i + "] displayName=" +
782 item.getDisplayName());
783 logger.debug(testName + ": list-item[" + i + "] URI=" +
791 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
792 public void readItemList() {
793 readItemList(knownResourceId);
796 private void readItemList(String vcsid) {
798 final String testName = "readItemList";
801 setupReadList(testName);
803 // Submit the request to the service and store the response.
804 ClientResponse<PersonsCommonList> res =
805 client.readItemList(vcsid);
806 PersonsCommonList list = res.getEntity();
807 int statusCode = res.getStatus();
809 // Check the status code of the response: does it match
810 // the expected response(s)?
811 if(logger.isDebugEnabled()){
812 logger.debug(testName + ": status = " + statusCode);
814 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
815 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
816 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
818 List<PersonsCommonList.PersonListItem> items =
819 list.getPersonListItem();
820 int nItemsReturned = items.size();
821 // There will be one item created, associated with a
822 // known parent resource, by the createItem test.
824 // In addition, there will be 'nItemsToCreateInList'
825 // additional items created by the createItemList test,
826 // all associated with the same parent resource.
827 int nExpectedItems = nItemsToCreateInList + 1;
828 if(logger.isDebugEnabled()){
829 logger.debug(testName + ": Expected "
830 + nExpectedItems +" items; got: "+nItemsReturned);
832 Assert.assertEquals(nItemsReturned, nExpectedItems);
835 for (PersonsCommonList.PersonListItem item : items) {
836 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
837 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
838 // Optionally output additional data about list members for debugging.
839 boolean showDetails = true;
840 if (showDetails && logger.isDebugEnabled()) {
841 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
843 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
844 item.getDisplayName());
845 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
852 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
853 public void readContactList() {
854 readContactList(knownResourceId, knownItemResourceId);
857 private void readContactList(String parentcsid, String itemcsid) {
858 final String testName = "readContactList";
861 setupReadList(testName);
863 // Submit the request to the service and store the response.
864 ClientResponse<ContactsCommonList> res =
865 client.readContactList(parentcsid, itemcsid);
866 ContactsCommonList list = res.getEntity();
867 int statusCode = res.getStatus();
869 // Check the status code of the response: does it match
870 // the expected response(s)?
871 if(logger.isDebugEnabled()){
872 logger.debug(testName + ": status = " + statusCode);
874 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
875 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
876 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
878 List<ContactsCommonList.ContactListItem> items =
879 list.getContactListItem();
880 int nItemsReturned = items.size();
881 // There will be one item created, associated with a
882 // known parent resource, by the createItem test.
884 // In addition, there will be 'nItemsToCreateInList'
885 // additional items created by the createItemList test,
886 // all associated with the same parent resource.
887 int nExpectedItems = nItemsToCreateInList + 1;
888 if(logger.isDebugEnabled()){
889 logger.debug(testName + ": Expected "
890 + nExpectedItems +" items; got: "+nItemsReturned);
892 Assert.assertEquals(nItemsReturned, nExpectedItems);
894 //FIXME: Add debugging output here.
899 // ---------------------------------------------------------------
900 // CRUD tests : UPDATE tests
901 // ---------------------------------------------------------------
904 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
905 groups = {"update"}, dependsOnGroups = {"read"})
906 public void update(String testName) throws Exception {
909 setupUpdate(testName);
911 // Retrieve the contents of a resource to update.
912 ClientResponse<MultipartInput> res =
913 client.read(knownResourceId);
914 if(logger.isDebugEnabled()){
915 logger.debug(testName + ": read status = " + res.getStatus());
917 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
919 if(logger.isDebugEnabled()){
920 logger.debug("got PersonAuthority to update with ID: " + knownResourceId);
922 MultipartInput input = (MultipartInput) res.getEntity();
923 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
924 client.getCommonPartName(), PersonauthoritiesCommon.class);
925 Assert.assertNotNull(personAuthority);
927 // Update the contents of this resource.
928 personAuthority.setDisplayName("updated-" + personAuthority.getDisplayName());
929 personAuthority.setVocabType("updated-" + personAuthority.getVocabType());
930 if(logger.isDebugEnabled()){
931 logger.debug("to be updated PersonAuthority");
932 logger.debug(objectAsXmlString(personAuthority, PersonauthoritiesCommon.class));
935 // Submit the updated resource to the service and store the response.
936 MultipartOutput output = new MultipartOutput();
937 OutputPart commonPart = output.addPart(personAuthority, MediaType.APPLICATION_XML_TYPE);
938 commonPart.getHeaders().add("label", client.getCommonPartName());
939 res = client.update(knownResourceId, output);
940 int statusCode = res.getStatus();
942 // Check the status code of the response: does it match the expected response(s)?
943 if(logger.isDebugEnabled()){
944 logger.debug(testName + ": status = " + statusCode);
946 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
947 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
948 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
950 // Retrieve the updated resource and verify that its contents exist.
951 input = (MultipartInput) res.getEntity();
952 PersonauthoritiesCommon updatedPersonAuthority =
953 (PersonauthoritiesCommon) extractPart(input,
954 client.getCommonPartName(), PersonauthoritiesCommon.class);
955 Assert.assertNotNull(updatedPersonAuthority);
957 // Verify that the updated resource received the correct data.
958 Assert.assertEquals(updatedPersonAuthority.getDisplayName(),
959 personAuthority.getDisplayName(),
960 "Data in updated object did not match submitted data.");
963 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
964 groups = {"update"}, dependsOnMethods = {"update"})
965 public void updateItem(String testName) throws Exception {
968 setupUpdate(testName);
970 ClientResponse<MultipartInput> res =
971 client.readItem(knownResourceId, knownItemResourceId);
972 if(logger.isDebugEnabled()){
973 logger.debug(testName + ": read status = " + res.getStatus());
975 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
977 if(logger.isDebugEnabled()){
978 logger.debug("got Person to update with ID: " +
979 knownItemResourceId +
980 " in PersonAuthority: " + knownResourceId );
982 MultipartInput input = (MultipartInput) res.getEntity();
983 PersonsCommon person = (PersonsCommon) extractPart(input,
984 client.getItemCommonPartName(), PersonsCommon.class);
985 Assert.assertNotNull(person);
987 // Update the contents of this resource.
988 person.setForeName("updated-" + person.getForeName());
989 if(logger.isDebugEnabled()){
990 logger.debug("to be updated Person");
991 logger.debug(objectAsXmlString(person,
992 PersonsCommon.class));
995 // Submit the updated resource to the service and store the response.
996 MultipartOutput output = new MultipartOutput();
997 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
998 commonPart.getHeaders().add("label", client.getItemCommonPartName());
999 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1000 int statusCode = res.getStatus();
1002 // Check the status code of the response: does it match the expected response(s)?
1003 if(logger.isDebugEnabled()){
1004 logger.debug(testName + ": status = " + statusCode);
1006 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1007 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1008 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1010 // Retrieve the updated resource and verify that its contents exist.
1011 input = (MultipartInput) res.getEntity();
1012 PersonsCommon updatedPerson =
1013 (PersonsCommon) extractPart(input,
1014 client.getItemCommonPartName(), PersonsCommon.class);
1015 Assert.assertNotNull(updatedPerson);
1017 // Verify that the updated resource received the correct data.
1018 Assert.assertEquals(updatedPerson.getForeName(),
1019 person.getForeName(),
1020 "Data in updated Person did not match submitted data.");
1023 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1024 groups = {"update"}, dependsOnMethods = {"updateItem"})
1025 public void updateContact(String testName) throws Exception {
1029 setupUpdate(testName);
1031 ClientResponse<MultipartInput> res =
1032 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1033 if(logger.isDebugEnabled()){
1034 logger.debug(testName + ": read status = " + res.getStatus());
1036 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1038 if(logger.isDebugEnabled()){
1039 logger.debug("got Contact to update with ID: " +
1040 knownContactResourceId +
1041 " in item: " + knownItemResourceId +
1042 " in parent: " + knownResourceId );
1044 MultipartInput input = (MultipartInput) res.getEntity();
1045 ContactsCommon contact = (ContactsCommon) extractPart(input,
1046 contactClient.getCommonPartName(), ContactsCommon.class);
1047 Assert.assertNotNull(contact);
1049 // Update the contents of this resource.
1050 contact.setAddressText1("updated-" + contact.getAddressText1());
1051 if(logger.isDebugEnabled()){
1052 logger.debug("to be updated Contact");
1053 logger.debug(objectAsXmlString(contact,
1054 ContactsCommon.class));
1057 // Submit the updated resource to the service and store the response.
1058 MultipartOutput output = new MultipartOutput();
1059 OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1060 commonPart.getHeaders().add("label", contactClient.getCommonPartName());
1061 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1062 int statusCode = res.getStatus();
1064 // Check the status code of the response: does it match the expected response(s)?
1065 if(logger.isDebugEnabled()){
1066 logger.debug(testName + ": status = " + statusCode);
1068 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1069 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1070 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1072 // Retrieve the updated resource and verify that its contents exist.
1073 input = (MultipartInput) res.getEntity();
1074 ContactsCommon updatedContact =
1075 (ContactsCommon) extractPart(input,
1076 contactClient.getCommonPartName(), ContactsCommon.class);
1077 Assert.assertNotNull(updatedContact);
1079 // Verify that the updated resource received the correct data.
1080 Assert.assertEquals(updatedContact.getAddressText1(),
1081 contact.getAddressText1(),
1082 "Data in updated Contact did not match submitted data.");
1087 // Placeholders until the three tests below can be uncommented.
1088 // See Issue CSPACE-401.
1090 public void updateWithEmptyEntityBody(String testName) throws Exception {
1094 public void updateWithMalformedXml(String testName) throws Exception {
1098 public void updateWithWrongXmlSchema(String testName) throws Exception {
1103 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1104 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1105 public void updateWithEmptyEntityBody(String testName) throws Exception {
1108 setupUpdateWithEmptyEntityBody(testName);
1110 // Submit the request to the service and store the response.
1111 String method = REQUEST_TYPE.httpMethodName();
1112 String url = getResourceURL(knownResourceId);
1113 String mediaType = MediaType.APPLICATION_XML;
1114 final String entity = "";
1115 int statusCode = submitRequest(method, url, mediaType, entity);
1117 // Check the status code of the response: does it match
1118 // the expected response(s)?
1119 if(logger.isDebugEnabled()){
1120 logger.debug(testName + ": url=" + url +
1121 " status=" + statusCode);
1123 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1124 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1125 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1129 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1130 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1131 public void updateWithMalformedXml(String testName) throws Exception {
1134 setupUpdateWithMalformedXml(testName);
1136 // Submit the request to the service and store the response.
1137 String method = REQUEST_TYPE.httpMethodName();
1138 String url = getResourceURL(knownResourceId);
1139 String mediaType = MediaType.APPLICATION_XML;
1140 final String entity = MALFORMED_XML_DATA;
1141 int statusCode = submitRequest(method, url, mediaType, entity);
1143 // Check the status code of the response: does it match
1144 // the expected response(s)?
1145 if(logger.isDebugEnabled()){
1146 logger.debug(testName + ": url=" + url +
1147 " status=" + statusCode);
1149 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1150 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1151 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1155 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1156 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1157 public void updateWithWrongXmlSchema(String testName) throws Exception {
1160 setupUpdateWithWrongXmlSchema(testName);
1162 // Submit the request to the service and store the response.
1163 String method = REQUEST_TYPE.httpMethodName();
1164 String url = getResourceURL(knownResourceId);
1165 String mediaType = MediaType.APPLICATION_XML;
1166 final String entity = WRONG_XML_SCHEMA_DATA;
1167 int statusCode = submitRequest(method, url, mediaType, entity);
1169 // Check the status code of the response: does it match
1170 // the expected response(s)?
1171 if(logger.isDebugEnabled()){
1172 logger.debug("updateWithWrongXmlSchema: url=" + url +
1173 " status=" + statusCode);
1175 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1176 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1177 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1183 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1184 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1185 public void updateNonExistent(String testName) throws Exception {
1188 setupUpdateNonExistent(testName);
1190 // Submit the request to the service and store the response.
1191 // Note: The ID used in this 'create' call may be arbitrary.
1192 // The only relevant ID may be the one used in update(), below.
1194 // The only relevant ID may be the one used in update(), below.
1195 String displayName = "displayName-NON_EXISTENT_ID";
1196 String fullRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, true);
1197 MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
1198 displayName, fullRefName, client.getCommonPartName());
1199 ClientResponse<MultipartInput> res =
1200 client.update(NON_EXISTENT_ID, multipart);
1201 int statusCode = res.getStatus();
1203 // Check the status code of the response: does it match
1204 // the expected response(s)?
1205 if(logger.isDebugEnabled()){
1206 logger.debug(testName + ": status = " + statusCode);
1208 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1209 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1210 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1213 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1214 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1215 public void updateNonExistentItem(String testName) throws Exception {
1218 setupUpdateNonExistent(testName);
1220 // Submit the request to the service and store the response.
1221 // Note: The ID used in this 'create' call may be arbitrary.
1222 // The only relevant ID may be the one used in update(), below.
1224 // The only relevant ID may be the one used in update(), below.
1225 Map<String, String> nonexMap = new HashMap<String,String>();
1226 nonexMap.put(PersonJAXBSchema.FORE_NAME, "John");
1227 nonexMap.put(PersonJAXBSchema.SUR_NAME, "Wayne");
1228 nonexMap.put(PersonJAXBSchema.GENDER, "male");
1229 MultipartOutput multipart =
1230 PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID,
1231 PersonAuthorityClientUtils.createPersonRefName(NON_EXISTENT_ID, NON_EXISTENT_ID, true), nonexMap,
1232 client.getItemCommonPartName() );
1233 ClientResponse<MultipartInput> res =
1234 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1235 int statusCode = res.getStatus();
1237 // Check the status code of the response: does it match
1238 // the expected response(s)?
1239 if(logger.isDebugEnabled()){
1240 logger.debug(testName + ": status = " + statusCode);
1242 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1243 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1244 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1247 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1248 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1249 public void updateNonExistentContact(String testName) throws Exception {
1250 // Currently a no-op test
1253 // ---------------------------------------------------------------
1254 // CRUD tests : DELETE tests
1255 // ---------------------------------------------------------------
1258 // Note: delete sub-resources in ascending hierarchical order,
1259 // before deleting their parents.
1262 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1263 groups = {"delete"}, dependsOnGroups = {"update"})
1264 public void deleteContact(String testName) throws Exception {
1268 setupDelete(testName);
1270 if(logger.isDebugEnabled()){
1271 logger.debug("parentcsid =" + knownResourceId +
1272 " itemcsid = " + knownItemResourceId +
1273 " csid = " + knownContactResourceId);
1276 // Submit the request to the service and store the response.
1277 ClientResponse<Response> res =
1278 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1279 int statusCode = res.getStatus();
1281 // Check the status code of the response: does it match
1282 // the expected response(s)?
1283 if(logger.isDebugEnabled()){
1284 logger.debug(testName + ": status = " + statusCode);
1286 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1287 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1288 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1293 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1294 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1295 public void deleteItem(String testName) throws Exception {
1298 setupDelete(testName);
1300 // Submit the request to the service and store the response.
1301 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1302 int statusCode = res.getStatus();
1304 // Check the status code of the response: does it match
1305 // the expected response(s)?
1306 if(logger.isDebugEnabled()){
1307 logger.debug(testName + ": status = " + statusCode);
1309 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1310 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1311 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1315 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1316 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1317 public void delete(String testName) throws Exception {
1320 setupDelete(testName);
1322 // Submit the request to the service and store the response.
1323 ClientResponse<Response> res = client.delete(knownResourceId);
1324 int statusCode = res.getStatus();
1326 // Check the status code of the response: does it match
1327 // the expected response(s)?
1328 if(logger.isDebugEnabled()){
1329 logger.debug(testName + ": status = " + statusCode);
1331 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1332 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1333 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1338 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1339 groups = {"delete"}, dependsOnMethods = {"delete"})
1340 public void deleteNonExistent(String testName) throws Exception {
1343 setupDeleteNonExistent(testName);
1345 // Submit the request to the service and store the response.
1346 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
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 = {"deleteItem"})
1361 public void deleteNonExistentItem(String testName) {
1364 setupDeleteNonExistent(testName);
1366 // Submit the request to the service and store the response.
1367 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1368 int statusCode = res.getStatus();
1370 // Check the status code of the response: does it match
1371 // the expected response(s)?
1372 if(logger.isDebugEnabled()){
1373 logger.debug(testName + ": status = " + statusCode);
1375 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1376 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1377 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1380 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1381 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1382 public void deleteNonExistentContact(String testName) {
1385 setupDeleteNonExistent(testName);
1387 // Submit the request to the service and store the response.
1388 ClientResponse<Response> res =
1389 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1390 int statusCode = res.getStatus();
1392 // Check the status code of the response: does it match
1393 // the expected response(s)?
1394 if(logger.isDebugEnabled()){
1395 logger.debug(testName + ": status = " + statusCode);
1397 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1398 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1399 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1402 // ---------------------------------------------------------------
1403 // Utility tests : tests of code used in tests above
1404 // ---------------------------------------------------------------
1406 * Tests the code for manually submitting data that is used by several
1407 * of the methods above.
1409 @Test(dependsOnMethods = {"create", "read"})
1410 public void testSubmitRequest() {
1412 // Expected status code: 200 OK
1413 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1415 // Submit the request to the service and store the response.
1416 String method = ServiceRequestType.READ.httpMethodName();
1417 String url = getResourceURL(knownResourceId);
1418 int statusCode = submitRequest(method, url);
1420 // Check the status code of the response: does it match
1421 // the expected response(s)?
1422 if(logger.isDebugEnabled()){
1423 logger.debug("testSubmitRequest: url=" + url +
1424 " status=" + statusCode);
1426 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1430 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1431 public void testItemSubmitRequest() {
1433 // Expected status code: 200 OK
1434 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1436 // Submit the request to the service and store the response.
1437 String method = ServiceRequestType.READ.httpMethodName();
1438 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1439 int statusCode = submitRequest(method, url);
1441 // Check the status code of the response: does it match
1442 // the expected response(s)?
1443 if(logger.isDebugEnabled()){
1444 logger.debug("testItemSubmitRequest: url=" + url +
1445 " status=" + statusCode);
1447 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1451 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
1452 public void testContactSubmitRequest() {
1454 // Expected status code: 200 OK
1455 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1457 // Submit the request to the service and store the response.
1458 String method = ServiceRequestType.READ.httpMethodName();
1459 String url = getContactResourceURL(knownResourceId,
1460 knownItemResourceId, knownContactResourceId);
1461 int statusCode = submitRequest(method, url);
1463 // Check the status code of the response: does it match
1464 // the expected response(s)?
1465 if(logger.isDebugEnabled()){
1466 logger.debug("testItemSubmitRequest: url=" + url +
1467 " status=" + statusCode);
1469 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1474 // ---------------------------------------------------------------
1475 // Cleanup of resources created during testing
1476 // ---------------------------------------------------------------
1479 * Deletes all resources created by tests, after all tests have been run.
1481 * This cleanup method will always be run, even if one or more tests fail.
1482 * For this reason, it attempts to remove all resources created
1483 * at any point during testing, even if some of those resources
1484 * may be expected to be deleted by certain tests.
1487 @AfterClass(alwaysRun=true)
1488 public void cleanUp() {
1489 if (logger.isDebugEnabled()) {
1490 logger.debug("Cleaning up temporary resources created for testing ...");
1492 String parentResourceId;
1493 String itemResourceId;
1494 String contactResourceId;
1495 // Clean up contact resources.
1496 parentResourceId = knownResourceId;
1497 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
1498 contactResourceId = entry.getKey();
1499 itemResourceId = entry.getValue();
1500 // Note: Any non-success responses from the delete operation
1501 // below are ignored and not reported.
1502 ClientResponse<Response> res =
1503 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
1505 // Clean up item resources.
1506 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1507 itemResourceId = entry.getKey();
1508 parentResourceId = entry.getValue();
1509 // Note: Any non-success responses from the delete operation
1510 // below are ignored and not reported.
1511 ClientResponse<Response> res =
1512 client.deleteItem(parentResourceId, itemResourceId);
1514 // Clean up parent resources.
1515 for (String resourceId : allResourceIdsCreated) {
1516 // Note: Any non-success responses from the delete operation
1517 // below are ignored and not reported.
1518 ClientResponse<Response> res = client.delete(resourceId);
1522 // ---------------------------------------------------------------
1523 // Utility methods used by tests above
1524 // ---------------------------------------------------------------
1526 public String getServicePathComponent() {
1527 return SERVICE_PATH_COMPONENT;
1530 public String getItemServicePathComponent() {
1531 return ITEM_SERVICE_PATH_COMPONENT;
1534 public String getContactServicePathComponent() {
1535 return CONTACT_SERVICE_PATH_COMPONENT;
1539 * Returns the root URL for the item service.
1541 * This URL consists of a base URL for all services, followed by
1542 * a path component for the owning parent, followed by the
1543 * path component for the items.
1545 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1546 * parent authority resource of the relevant item resource.
1548 * @return The root URL for the item service.
1550 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1551 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1555 * Returns the URL of a specific item resource managed by a service, and
1556 * designated by an identifier (such as a universally unique ID, or UUID).
1558 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1559 * parent authority resource of the relevant item resource.
1561 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1564 * @return The URL of a specific item resource managed by a service.
1566 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1567 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
1572 * Returns the root URL for the contact service.
1574 * This URL consists of a base URL for all services, followed by
1575 * a path component for the owning authority, followed by the
1576 * path component for the owning item, followed by the path component
1577 * for the contact service.
1579 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1580 * parent authority resource of the relevant item resource.
1582 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1585 * @return The root URL for the contact service.
1587 protected String getContactServiceRootURL(String parentResourceIdentifier,
1588 String itemResourceIdentifier) {
1589 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
1590 getContactServicePathComponent();
1594 * Returns the URL of a specific contact resource managed by a service, and
1595 * designated by an identifier (such as a universally unique ID, or UUID).
1597 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1598 * parent resource of the relevant item resource.
1600 * @param resourceIdentifier An identifier (such as a UUID) for an
1603 * @return The URL of a specific resource managed by a service.
1605 protected String getContactResourceURL(String parentResourceIdentifier,
1606 String itemResourceIdentifier, String contactResourceIdentifier) {
1607 return getContactServiceRootURL(parentResourceIdentifier,
1608 itemResourceIdentifier) + "/" + contactResourceIdentifier;