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 private PersonAuthorityClient client = new PersonAuthorityClient();
67 private ContactClient contactClient = new ContactClient();
68 final String SERVICE_PATH_COMPONENT = "personauthorities";
69 final String ITEM_SERVICE_PATH_COMPONENT = "items";
70 final String CONTACT_SERVICE_PATH_COMPONENT = "contacts";
71 final String TEST_FORE_NAME = "John";
72 final String TEST_MIDDLE_NAME = null;
73 final String TEST_SUR_NAME = "Wayne";
74 final String TEST_BIRTH_DATE = "May 26, 1907";
75 final String TEST_DEATH_DATE = "June 11, 1979";
77 private String knownResourceId = null;
78 private String knownResourceDisplayName = null;
79 private String knownResourceRefName = null;
80 private String knownItemResourceId = null;
81 private String knownContactResourceId = null;
82 private int nItemsToCreateInList = 3;
83 private List<String> allResourceIdsCreated = new ArrayList<String>();
84 private Map<String, String> allItemResourceIdsCreated =
85 new HashMap<String, String>();
86 private Map<String, String> allContactResourceIdsCreated =
87 new HashMap<String, String>();
89 // ---------------------------------------------------------------
90 // CRUD tests : CREATE tests
91 // ---------------------------------------------------------------
94 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
96 public void create(String testName) throws Exception {
98 // Perform setup, such as initializing the type of service request
99 // (e.g. CREATE, DELETE), its valid and expected status codes, and
100 // its associated HTTP method name (e.g. POST, DELETE).
101 setupCreate(testName);
103 // Submit the request to the service and store the response.
104 String identifier = createIdentifier();
105 String displayName = "displayName-" + identifier;
106 String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, false);
107 String fullRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, true);
108 MultipartOutput multipart =
109 PersonAuthorityClientUtils.createPersonAuthorityInstance(
110 displayName, fullRefName, client.getCommonPartName());
111 ClientResponse<Response> res = client.create(multipart);
112 int statusCode = res.getStatus();
114 // Check the status code of the response: does it match
115 // the expected response(s)?
118 // Does it fall within the set of valid status codes?
119 // Does it exactly match the expected status code?
120 if(logger.isDebugEnabled()){
121 logger.debug(testName + ": status = " + statusCode);
123 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
124 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
125 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
127 // Store the refname from the first resource created
128 // for additional tests below.
129 knownResourceRefName = baseRefName;
131 String newID = PersonAuthorityClientUtils.extractId(res);
132 // Store the ID returned from the first resource created
133 // for additional tests below.
134 if (knownResourceId == null){
135 knownResourceId = newID;
136 knownResourceDisplayName = displayName;
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);
146 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
147 groups = {"create"}, dependsOnMethods = {"create"})
148 public void createItem(String testName) {
149 setupCreate(testName);
150 String newID = createItemInAuthority(knownResourceId, knownResourceRefName);
153 private String createItemInAuthority(String vcsid, String authRefName) {
155 final String testName = "createItemInAuthority";
156 if(logger.isDebugEnabled()){
157 logger.debug(testName + ":...");
160 // Submit the request to the service and store the response.
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 String identifier = createIdentifier();
226 MultipartOutput multipart =
227 ContactClientUtils.createContactInstance(parentcsid,
228 itemcsid, identifier, contactClient.getCommonPartName());
229 ClientResponse<Response> res =
230 client.createContact(parentcsid, itemcsid, multipart);
231 int statusCode = res.getStatus();
232 String newID = PersonAuthorityClientUtils.extractId(res);
234 // Check the status code of the response: does it match
235 // the expected response(s)?
236 if(logger.isDebugEnabled()){
237 logger.debug(testName + ": status = " + statusCode);
239 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
240 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
241 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
243 // Store the ID returned from the first contact resource created
244 // for additional tests below.
245 if (knownContactResourceId == null){
246 knownContactResourceId = newID;
247 if (logger.isDebugEnabled()) {
248 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
252 // Store the IDs from any contact resources created
253 // by tests, along with the IDs of their parent items,
254 // so these items can be deleted after all tests have been run.
255 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 groups = {"create"}, 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 groups = {"create"}, 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 groups = {"create"}, 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"}, dependsOnMethods = {"createList"})
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"}, dependsOnMethods = {"createItemList"})
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);
422 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
423 groups = {"read"}, dependsOnGroups = {"create"})
424 public void readByName(String testName) throws Exception {
429 // Submit the request to the service and store the response.
430 ClientResponse<MultipartInput> res = client.readByName(knownResourceDisplayName);
431 int statusCode = res.getStatus();
433 // Check the status code of the response: does it match
434 // the expected response(s)?
435 if(logger.isDebugEnabled()){
436 logger.debug(testName + ": status = " + statusCode);
438 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
439 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
440 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
441 //FIXME: remove the following try catch once Aron fixes signatures
443 MultipartInput input = (MultipartInput) res.getEntity();
444 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
445 client.getCommonPartName(), PersonauthoritiesCommon.class);
446 Assert.assertNotNull(personAuthority);
447 } catch (Exception e) {
448 throw new RuntimeException(e);
453 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
454 groups = {"read"}, dependsOnMethods = {"read"})
455 public void readByName(String testName) throws Exception {
460 // Submit the request to the service and store the response.
461 ClientResponse<MultipartInput> res = client.read(knownResourceId);
462 int statusCode = res.getStatus();
464 // Check the status code of the response: does it match
465 // the expected response(s)?
466 if(logger.isDebugEnabled()){
467 logger.debug(testName + ": status = " + statusCode);
469 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
470 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
471 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
472 //FIXME: remove the following try catch once Aron fixes signatures
474 MultipartInput input = (MultipartInput) res.getEntity();
475 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
476 client.getCommonPartName(), PersonauthoritiesCommon.class);
477 Assert.assertNotNull(personAuthority);
478 } catch (Exception e) {
479 throw new RuntimeException(e);
484 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
485 groups = {"read"}, dependsOnMethods = {"read"})
486 public void readItem(String testName) throws Exception {
491 // Submit the request to the service and store the response.
492 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
493 int statusCode = res.getStatus();
495 // Check the status code of the response: does it match
496 // the expected response(s)?
497 if(logger.isDebugEnabled()){
498 logger.debug(testName + ": status = " + statusCode);
500 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
501 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
502 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
504 // Check whether we've received a person.
505 MultipartInput input = (MultipartInput) res.getEntity();
506 PersonsCommon person = (PersonsCommon) extractPart(input,
507 client.getItemCommonPartName(), PersonsCommon.class);
508 Assert.assertNotNull(person);
509 boolean showFull = true;
510 if(showFull && logger.isDebugEnabled()){
511 logger.debug(testName + ": returned payload:");
512 logger.debug(objectAsXmlString(person, PersonsCommon.class));
514 Assert.assertEquals(person.getInAuthority(), knownResourceId);
518 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
519 dependsOnMethods = {"readItem", "updateItem"})
520 public void verifyItemDisplayName(String testName) throws Exception {
523 setupUpdate(testName);
525 // Submit the request to the service and store the response.
526 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
527 int statusCode = res.getStatus();
529 // Check the status code of the response: does it match
530 // the expected response(s)?
531 if(logger.isDebugEnabled()){
532 logger.debug(testName + ": status = " + statusCode);
534 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
535 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
536 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
538 // Check whether person has expected displayName.
539 MultipartInput input = (MultipartInput) res.getEntity();
540 PersonsCommon person = (PersonsCommon) extractPart(input,
541 client.getItemCommonPartName(), PersonsCommon.class);
542 Assert.assertNotNull(person);
543 String displayName = person.getDisplayName();
544 // Make sure displayName matches computed form
545 String expectedDisplayName =
546 PersonAuthorityClientUtils.prepareDefaultDisplayName(
547 TEST_FORE_NAME, null, TEST_SUR_NAME,
548 TEST_BIRTH_DATE, TEST_DEATH_DATE);
549 Assert.assertNotNull(displayName, expectedDisplayName);
551 // Update the shortName and verify the computed name is updated.
552 person.setDisplayNameComputed(true);
553 person.setForeName("updated-" + TEST_FORE_NAME);
554 expectedDisplayName =
555 PersonAuthorityClientUtils.prepareDefaultDisplayName(
556 "updated-" + TEST_FORE_NAME, null, TEST_SUR_NAME,
557 TEST_BIRTH_DATE, TEST_DEATH_DATE);
559 // Submit the updated resource to the service and store the response.
560 MultipartOutput output = new MultipartOutput();
561 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
562 commonPart.getHeaders().add("label", client.getItemCommonPartName());
563 res = client.updateItem(knownResourceId, knownItemResourceId, output);
564 statusCode = res.getStatus();
566 // Check the status code of the response: does it match the expected response(s)?
567 if(logger.isDebugEnabled()){
568 logger.debug("updateItem: status = " + statusCode);
570 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
571 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
572 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
574 // Retrieve the updated resource and verify that its contents exist.
575 input = (MultipartInput) res.getEntity();
576 PersonsCommon updatedPerson =
577 (PersonsCommon) extractPart(input,
578 client.getItemCommonPartName(), PersonsCommon.class);
579 Assert.assertNotNull(updatedPerson);
581 // Verify that the updated resource received the correct data.
582 Assert.assertEquals(updatedPerson.getForeName(), person.getForeName(),
583 "Updated ForeName in Person did not match submitted data.");
584 // Verify that the updated resource computes the right displayName.
585 Assert.assertEquals(updatedPerson.getDisplayName(), expectedDisplayName,
586 "Updated ForeName in Person not reflected in computed DisplayName.");
588 // Now Update the displayName, not computed and verify the computed name is overriden.
589 person.setDisplayNameComputed(false);
590 expectedDisplayName = "TestName";
591 person.setDisplayName(expectedDisplayName);
593 // Submit the updated resource to the service and store the response.
594 output = new MultipartOutput();
595 commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
596 commonPart.getHeaders().add("label", client.getItemCommonPartName());
597 res = client.updateItem(knownResourceId, knownItemResourceId, output);
598 statusCode = res.getStatus();
600 // Check the status code of the response: does it match the expected response(s)?
601 if(logger.isDebugEnabled()){
602 logger.debug("updateItem: status = " + statusCode);
604 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
605 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
606 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
608 // Retrieve the updated resource and verify that its contents exist.
609 input = (MultipartInput) res.getEntity();
611 (PersonsCommon) extractPart(input,
612 client.getItemCommonPartName(), PersonsCommon.class);
613 Assert.assertNotNull(updatedPerson);
615 // Verify that the updated resource received the correct data.
616 Assert.assertEquals(updatedPerson.isDisplayNameComputed(), false,
617 "Updated displayNameComputed in Person did not match submitted data.");
618 // Verify that the updated resource computes the right displayName.
619 Assert.assertEquals(updatedPerson.getDisplayName(),
621 "Updated DisplayName (not computed) in Person not stored.");
624 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
625 dependsOnMethods = {"verifyItemDisplayName"})
626 public void verifyIllegalItemDisplayName(String testName) throws Exception {
629 setupUpdateWithWrongXmlSchema(testName);
631 // Submit the request to the service and store the response.
632 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
633 int statusCode = res.getStatus();
635 // Check the status code of the response: does it match
636 // the expected response(s)?
637 if(logger.isDebugEnabled()){
638 logger.debug(testName + ": status = " + statusCode);
640 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
641 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
642 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
644 // Check whether Person has expected displayName.
645 MultipartInput input = (MultipartInput) res.getEntity();
646 PersonsCommon person = (PersonsCommon) extractPart(input,
647 client.getItemCommonPartName(), PersonsCommon.class);
648 Assert.assertNotNull(person);
649 // Try to Update with computed false and no displayName
650 person.setDisplayNameComputed(false);
651 person.setDisplayName(null);
653 // Submit the updated resource to the service and store the response.
654 MultipartOutput output = new MultipartOutput();
655 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
656 commonPart.getHeaders().add("label", client.getItemCommonPartName());
657 res = client.updateItem(knownResourceId, knownItemResourceId, output);
658 statusCode = res.getStatus();
660 // Check the status code of the response: does it match the expected response(s)?
661 if(logger.isDebugEnabled()){
662 logger.debug("updateItem: status = " + statusCode);
664 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
665 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
666 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
669 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
670 groups = {"read"}, dependsOnMethods = {"readItem"})
671 public void readContact(String testName) throws Exception {
676 // Submit the request to the service and store the response.
677 ClientResponse<MultipartInput> res =
678 client.readContact(knownResourceId, knownItemResourceId,
679 knownContactResourceId);
680 int statusCode = res.getStatus();
682 // Check the status code of the response: does it match
683 // the expected response(s)?
684 if(logger.isDebugEnabled()){
685 logger.debug(testName + ": status = " + statusCode);
687 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
688 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
689 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
691 // Check whether we've received a contact.
692 MultipartInput input = (MultipartInput) res.getEntity();
693 ContactsCommon contact = (ContactsCommon) extractPart(input,
694 contactClient.getCommonPartName(), ContactsCommon.class);
695 Assert.assertNotNull(contact);
696 boolean showFull = true;
697 if(showFull && logger.isDebugEnabled()){
698 logger.debug(testName + ": returned payload:");
699 logger.debug(objectAsXmlString(contact, ContactsCommon.class));
701 Assert.assertEquals(contact.getInAuthority(), knownResourceId);
702 Assert.assertEquals(contact.getInItem(), knownItemResourceId);
708 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
709 groups = {"read"}, dependsOnMethods = {"read"})
710 public void readNonExistent(String testName) {
713 setupReadNonExistent(testName);
715 // Submit the request to the service and store the response.
716 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
717 int statusCode = res.getStatus();
719 // Check the status code of the response: does it match
720 // the expected response(s)?
721 if(logger.isDebugEnabled()){
722 logger.debug(testName + ": status = " + statusCode);
724 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
725 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
726 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
729 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
730 groups = {"read"}, dependsOnMethods = {"readItem"})
731 public void readItemNonExistent(String testName) {
734 setupReadNonExistent(testName);
736 // Submit the request to the service and store the response.
737 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
738 int statusCode = res.getStatus();
740 // Check the status code of the response: does it match
741 // the expected response(s)?
742 if(logger.isDebugEnabled()){
743 logger.debug(testName + ": status = " + statusCode);
745 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
746 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
747 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
750 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
751 groups = {"read"}, dependsOnMethods = {"readContact"})
752 public void readContactNonExistent(String testName) {
755 setupReadNonExistent(testName);
757 // Submit the request to the service and store the response.
758 ClientResponse<MultipartInput> res =
759 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
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);
772 // ---------------------------------------------------------------
773 // CRUD tests : READ_LIST tests
774 // ---------------------------------------------------------------
778 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
779 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
780 public void readList(String testName) throws Exception {
783 setupReadList(testName);
785 // Submit the request to the service and store the response.
786 ClientResponse<PersonauthoritiesCommonList> res = client.readList();
787 PersonauthoritiesCommonList list = res.getEntity();
788 int statusCode = res.getStatus();
790 // Check the status code of the response: does it match
791 // the expected response(s)?
792 if(logger.isDebugEnabled()){
793 logger.debug(testName + ": status = " + statusCode);
795 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
796 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
797 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
799 // Optionally output additional data about list members for debugging.
800 boolean iterateThroughList = false;
801 if (iterateThroughList && logger.isDebugEnabled()) {
802 List<PersonauthoritiesCommonList.PersonauthorityListItem> items =
803 list.getPersonauthorityListItem();
805 for (PersonauthoritiesCommonList.PersonauthorityListItem item : items) {
806 String csid = item.getCsid();
807 logger.debug(testName + ": list-item[" + i + "] csid=" +
809 logger.debug(testName + ": list-item[" + i + "] displayName=" +
810 item.getDisplayName());
811 logger.debug(testName + ": list-item[" + i + "] URI=" +
819 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
820 public void readItemList() {
821 readItemList(knownResourceId);
824 private void readItemList(String vcsid) {
826 final String testName = "readItemList";
829 setupReadList(testName);
831 // Submit the request to the service and store the response.
832 ClientResponse<PersonsCommonList> res =
833 client.readItemList(vcsid);
834 PersonsCommonList list = res.getEntity();
835 int statusCode = res.getStatus();
837 // Check the status code of the response: does it match
838 // the expected response(s)?
839 if(logger.isDebugEnabled()){
840 logger.debug(testName + ": status = " + statusCode);
842 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
843 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
844 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
846 List<PersonsCommonList.PersonListItem> items =
847 list.getPersonListItem();
848 int nItemsReturned = items.size();
849 // There will be one item created, associated with a
850 // known parent resource, by the createItem test.
852 // In addition, there will be 'nItemsToCreateInList'
853 // additional items created by the createItemList test,
854 // all associated with the same parent resource.
855 int nExpectedItems = nItemsToCreateInList + 1;
856 if(logger.isDebugEnabled()){
857 logger.debug(testName + ": Expected "
858 + nExpectedItems +" items; got: "+nItemsReturned);
860 Assert.assertEquals(nItemsReturned, nExpectedItems);
863 for (PersonsCommonList.PersonListItem item : items) {
864 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
865 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
866 // Optionally output additional data about list members for debugging.
867 boolean showDetails = true;
868 if (showDetails && logger.isDebugEnabled()) {
869 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
871 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
873 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
874 item.getDisplayName());
875 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
882 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
883 public void readContactList() {
884 readContactList(knownResourceId, knownItemResourceId);
887 private void readContactList(String parentcsid, String itemcsid) {
888 final String testName = "readContactList";
891 setupReadList(testName);
893 // Submit the request to the service and store the response.
894 ClientResponse<ContactsCommonList> res =
895 client.readContactList(parentcsid, itemcsid);
896 ContactsCommonList list = res.getEntity();
897 int statusCode = res.getStatus();
899 // Check the status code of the response: does it match
900 // the expected response(s)?
901 if(logger.isDebugEnabled()){
902 logger.debug(testName + ": status = " + statusCode);
904 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
905 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
906 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
908 List<ContactsCommonList.ContactListItem> listitems =
909 list.getContactListItem();
910 int nItemsReturned = listitems.size();
911 // There will be one item created, associated with a
912 // known parent resource, by the createItem test.
914 // In addition, there will be 'nItemsToCreateInList'
915 // additional items created by the createItemList test,
916 // all associated with the same parent resource.
917 int nExpectedItems = nItemsToCreateInList + 1;
918 if(logger.isDebugEnabled()){
919 logger.debug(testName + ": Expected "
920 + nExpectedItems +" items; got: "+nItemsReturned);
922 Assert.assertEquals(nItemsReturned, nExpectedItems);
925 for (ContactsCommonList.ContactListItem listitem : listitems) {
926 // Optionally output additional data about list members for debugging.
927 boolean showDetails = false;
928 if (showDetails && logger.isDebugEnabled()) {
929 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
931 logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" +
932 listitem.getAddressPlace());
933 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
943 // ---------------------------------------------------------------
944 // CRUD tests : UPDATE tests
945 // ---------------------------------------------------------------
948 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
949 groups = {"update"}, dependsOnGroups = {"read"})
950 public void update(String testName) throws Exception {
953 setupUpdate(testName);
955 // Retrieve the contents of a resource to update.
956 ClientResponse<MultipartInput> res =
957 client.read(knownResourceId);
958 if(logger.isDebugEnabled()){
959 logger.debug(testName + ": read status = " + res.getStatus());
961 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
963 if(logger.isDebugEnabled()){
964 logger.debug("got PersonAuthority to update with ID: " + knownResourceId);
966 MultipartInput input = (MultipartInput) res.getEntity();
967 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
968 client.getCommonPartName(), PersonauthoritiesCommon.class);
969 Assert.assertNotNull(personAuthority);
971 // Update the contents of this resource.
972 personAuthority.setDisplayName("updated-" + personAuthority.getDisplayName());
973 personAuthority.setVocabType("updated-" + personAuthority.getVocabType());
974 if(logger.isDebugEnabled()){
975 logger.debug("to be updated PersonAuthority");
976 logger.debug(objectAsXmlString(personAuthority, PersonauthoritiesCommon.class));
979 // Submit the updated resource to the service and store the response.
980 MultipartOutput output = new MultipartOutput();
981 OutputPart commonPart = output.addPart(personAuthority, MediaType.APPLICATION_XML_TYPE);
982 commonPart.getHeaders().add("label", client.getCommonPartName());
983 res = client.update(knownResourceId, output);
984 int statusCode = res.getStatus();
986 // Check the status code of the response: does it match the expected response(s)?
987 if(logger.isDebugEnabled()){
988 logger.debug(testName + ": status = " + statusCode);
990 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
991 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
992 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
994 // Retrieve the updated resource and verify that its contents exist.
995 input = (MultipartInput) res.getEntity();
996 PersonauthoritiesCommon updatedPersonAuthority =
997 (PersonauthoritiesCommon) extractPart(input,
998 client.getCommonPartName(), PersonauthoritiesCommon.class);
999 Assert.assertNotNull(updatedPersonAuthority);
1001 // Verify that the updated resource received the correct data.
1002 Assert.assertEquals(updatedPersonAuthority.getDisplayName(),
1003 personAuthority.getDisplayName(),
1004 "Data in updated object did not match submitted data.");
1007 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1008 groups = {"update"}, dependsOnMethods = {"update"})
1009 public void updateItem(String testName) throws Exception {
1012 setupUpdate(testName);
1014 ClientResponse<MultipartInput> res =
1015 client.readItem(knownResourceId, knownItemResourceId);
1016 if(logger.isDebugEnabled()){
1017 logger.debug(testName + ": read status = " + res.getStatus());
1019 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1021 if(logger.isDebugEnabled()){
1022 logger.debug("got Person to update with ID: " +
1023 knownItemResourceId +
1024 " in PersonAuthority: " + knownResourceId );
1026 MultipartInput input = (MultipartInput) res.getEntity();
1027 PersonsCommon person = (PersonsCommon) extractPart(input,
1028 client.getItemCommonPartName(), PersonsCommon.class);
1029 Assert.assertNotNull(person);
1031 // Update the contents of this resource.
1032 person.setForeName("updated-" + person.getForeName());
1033 if(logger.isDebugEnabled()){
1034 logger.debug("to be updated Person");
1035 logger.debug(objectAsXmlString(person,
1036 PersonsCommon.class));
1039 // Submit the updated resource to the service and store the response.
1040 MultipartOutput output = new MultipartOutput();
1041 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
1042 commonPart.getHeaders().add("label", client.getItemCommonPartName());
1043 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1044 int statusCode = res.getStatus();
1046 // Check the status code of the response: does it match the expected response(s)?
1047 if(logger.isDebugEnabled()){
1048 logger.debug(testName + ": status = " + statusCode);
1050 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1051 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1052 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1054 // Retrieve the updated resource and verify that its contents exist.
1055 input = (MultipartInput) res.getEntity();
1056 PersonsCommon updatedPerson =
1057 (PersonsCommon) extractPart(input,
1058 client.getItemCommonPartName(), PersonsCommon.class);
1059 Assert.assertNotNull(updatedPerson);
1061 // Verify that the updated resource received the correct data.
1062 Assert.assertEquals(updatedPerson.getForeName(),
1063 person.getForeName(),
1064 "Data in updated Person did not match submitted data.");
1067 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1068 groups = {"update"}, dependsOnMethods = {"updateItem"})
1069 public void updateContact(String testName) throws Exception {
1072 setupUpdate(testName);
1074 ClientResponse<MultipartInput> res =
1075 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1076 if(logger.isDebugEnabled()){
1077 logger.debug(testName + ": read status = " + res.getStatus());
1079 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1081 if(logger.isDebugEnabled()){
1082 logger.debug("got Contact to update with ID: " +
1083 knownContactResourceId +
1084 " in item: " + knownItemResourceId +
1085 " in parent: " + knownResourceId );
1087 MultipartInput input = (MultipartInput) res.getEntity();
1088 ContactsCommon contact = (ContactsCommon) extractPart(input,
1089 contactClient.getCommonPartName(), ContactsCommon.class);
1090 Assert.assertNotNull(contact);
1092 // Update the contents of this resource.
1093 contact.setAddressPlace("updated-" + contact.getAddressPlace());
1094 if(logger.isDebugEnabled()){
1095 logger.debug("to be updated Contact");
1096 logger.debug(objectAsXmlString(contact,
1097 ContactsCommon.class));
1100 // Submit the updated resource to the service and store the response.
1101 MultipartOutput output = new MultipartOutput();
1102 OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1103 commonPart.getHeaders().add("label", contactClient.getCommonPartName());
1104 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1105 int statusCode = res.getStatus();
1107 // Check the status code of the response: does it match the expected response(s)?
1108 if(logger.isDebugEnabled()){
1109 logger.debug(testName + ": status = " + statusCode);
1111 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1112 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1113 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1115 // Retrieve the updated resource and verify that its contents exist.
1116 input = (MultipartInput) res.getEntity();
1117 ContactsCommon updatedContact =
1118 (ContactsCommon) extractPart(input,
1119 contactClient.getCommonPartName(), ContactsCommon.class);
1120 Assert.assertNotNull(updatedContact);
1122 // Verify that the updated resource received the correct data.
1123 Assert.assertEquals(updatedContact.getAddressPlace(),
1124 contact.getAddressPlace(),
1125 "Data in updated Contact did not match submitted data.");
1129 // Placeholders until the three tests below can be uncommented.
1130 // See Issue CSPACE-401.
1132 public void updateWithEmptyEntityBody(String testName) throws Exception {
1136 public void updateWithMalformedXml(String testName) throws Exception {
1140 public void updateWithWrongXmlSchema(String testName) throws Exception {
1145 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1146 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1147 public void updateWithEmptyEntityBody(String testName) throws Exception {
1150 setupUpdateWithEmptyEntityBody(testName);
1152 // Submit the request to the service and store the response.
1153 String method = REQUEST_TYPE.httpMethodName();
1154 String url = getResourceURL(knownResourceId);
1155 String mediaType = MediaType.APPLICATION_XML;
1156 final String entity = "";
1157 int statusCode = submitRequest(method, url, mediaType, entity);
1159 // Check the status code of the response: does it match
1160 // the expected response(s)?
1161 if(logger.isDebugEnabled()){
1162 logger.debug(testName + ": url=" + url +
1163 " status=" + statusCode);
1165 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1166 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1167 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1171 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1172 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1173 public void updateWithMalformedXml(String testName) throws Exception {
1176 setupUpdateWithMalformedXml(testName);
1178 // Submit the request to the service and store the response.
1179 String method = REQUEST_TYPE.httpMethodName();
1180 String url = getResourceURL(knownResourceId);
1181 String mediaType = MediaType.APPLICATION_XML;
1182 final String entity = MALFORMED_XML_DATA;
1183 int statusCode = submitRequest(method, url, mediaType, entity);
1185 // Check the status code of the response: does it match
1186 // the expected response(s)?
1187 if(logger.isDebugEnabled()){
1188 logger.debug(testName + ": url=" + url +
1189 " status=" + statusCode);
1191 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1192 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1193 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1197 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1198 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1199 public void updateWithWrongXmlSchema(String testName) throws Exception {
1202 setupUpdateWithWrongXmlSchema(testName);
1204 // Submit the request to the service and store the response.
1205 String method = REQUEST_TYPE.httpMethodName();
1206 String url = getResourceURL(knownResourceId);
1207 String mediaType = MediaType.APPLICATION_XML;
1208 final String entity = WRONG_XML_SCHEMA_DATA;
1209 int statusCode = submitRequest(method, url, mediaType, entity);
1211 // Check the status code of the response: does it match
1212 // the expected response(s)?
1213 if(logger.isDebugEnabled()){
1214 logger.debug("updateWithWrongXmlSchema: url=" + url +
1215 " status=" + statusCode);
1217 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1218 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1219 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1224 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1225 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1226 public void updateNonExistent(String testName) throws Exception {
1229 setupUpdateNonExistent(testName);
1231 // Submit the request to the service and store the response.
1232 // Note: The ID(s) used when creating the request payload may be arbitrary.
1233 // The only relevant ID may be the one used in update(), below.
1234 String displayName = "displayName-NON_EXISTENT_ID";
1235 String fullRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, true);
1236 MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
1237 displayName, fullRefName, client.getCommonPartName());
1238 ClientResponse<MultipartInput> res =
1239 client.update(NON_EXISTENT_ID, multipart);
1240 int statusCode = res.getStatus();
1242 // Check the status code of the response: does it match
1243 // the expected response(s)?
1244 if(logger.isDebugEnabled()){
1245 logger.debug(testName + ": status = " + statusCode);
1247 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1248 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1249 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1252 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1253 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1254 public void updateNonExistentItem(String testName) throws Exception {
1257 setupUpdateNonExistent(testName);
1259 // Submit the request to the service and store the response.
1260 // Note: The ID used in this 'create' call may be arbitrary.
1261 // The only relevant ID may be the one used in update(), below.
1263 // The only relevant ID may be the one used in update(), below.
1264 Map<String, String> nonexMap = new HashMap<String,String>();
1265 nonexMap.put(PersonJAXBSchema.FORE_NAME, "John");
1266 nonexMap.put(PersonJAXBSchema.SUR_NAME, "Wayne");
1267 nonexMap.put(PersonJAXBSchema.GENDER, "male");
1268 MultipartOutput multipart =
1269 PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID,
1270 PersonAuthorityClientUtils.createPersonRefName(NON_EXISTENT_ID, NON_EXISTENT_ID, true), nonexMap,
1271 client.getItemCommonPartName() );
1272 ClientResponse<MultipartInput> res =
1273 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1274 int statusCode = res.getStatus();
1276 // Check the status code of the response: does it match
1277 // the expected response(s)?
1278 if(logger.isDebugEnabled()){
1279 logger.debug(testName + ": status = " + statusCode);
1281 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1282 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1283 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1286 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1287 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1288 public void updateNonExistentContact(String testName) throws Exception {
1289 // Currently a no-op test
1292 // ---------------------------------------------------------------
1293 // CRUD tests : DELETE tests
1294 // ---------------------------------------------------------------
1297 // Note: delete sub-resources in ascending hierarchical order,
1298 // before deleting their parents.
1300 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1301 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1302 public void deleteContact(String testName) throws Exception {
1305 setupDelete(testName);
1307 if(logger.isDebugEnabled()){
1308 logger.debug("parentcsid =" + knownResourceId +
1309 " itemcsid = " + knownItemResourceId +
1310 " csid = " + knownContactResourceId);
1313 // Submit the request to the service and store the response.
1314 ClientResponse<Response> res =
1315 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1316 int statusCode = res.getStatus();
1318 // Check the status code of the response: does it match
1319 // the expected response(s)?
1320 if(logger.isDebugEnabled()){
1321 logger.debug(testName + ": status = " + statusCode);
1323 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1324 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1325 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1328 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1329 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1330 public void deleteItem(String testName) throws Exception {
1333 setupDelete(testName);
1335 if(logger.isDebugEnabled()){
1336 logger.debug("parentcsid =" + knownResourceId +
1337 " itemcsid = " + knownItemResourceId);
1340 // Submit the request to the service and store the response.
1341 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1342 int statusCode = res.getStatus();
1344 // Check the status code of the response: does it match
1345 // the expected response(s)?
1346 if(logger.isDebugEnabled()){
1347 logger.debug(testName + ": status = " + statusCode);
1349 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1350 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1351 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1355 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1356 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1357 public void delete(String testName) throws Exception {
1360 setupDelete(testName);
1362 if(logger.isDebugEnabled()){
1363 logger.debug("parentcsid =" + knownResourceId);
1366 // Submit the request to the service and store the response.
1367 ClientResponse<Response> res = client.delete(knownResourceId);
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);
1382 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1383 groups = {"delete"}, dependsOnMethods = {"delete"})
1384 public void deleteNonExistent(String testName) throws Exception {
1387 setupDeleteNonExistent(testName);
1389 // Submit the request to the service and store the response.
1390 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1391 int statusCode = res.getStatus();
1393 // Check the status code of the response: does it match
1394 // the expected response(s)?
1395 if(logger.isDebugEnabled()){
1396 logger.debug(testName + ": status = " + statusCode);
1398 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1399 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1400 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1403 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1404 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1405 public void deleteNonExistentItem(String testName) {
1408 setupDeleteNonExistent(testName);
1410 // Submit the request to the service and store the response.
1411 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1412 int statusCode = res.getStatus();
1414 // Check the status code of the response: does it match
1415 // the expected response(s)?
1416 if(logger.isDebugEnabled()){
1417 logger.debug(testName + ": status = " + statusCode);
1419 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1420 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1421 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1424 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1425 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1426 public void deleteNonExistentContact(String testName) {
1429 setupDeleteNonExistent(testName);
1431 // Submit the request to the service and store the response.
1432 ClientResponse<Response> res =
1433 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1434 int statusCode = res.getStatus();
1436 // Check the status code of the response: does it match
1437 // the expected response(s)?
1438 if(logger.isDebugEnabled()){
1439 logger.debug(testName + ": status = " + statusCode);
1441 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1442 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1443 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1446 // ---------------------------------------------------------------
1447 // Utility tests : tests of code used in tests above
1448 // ---------------------------------------------------------------
1450 * Tests the code for manually submitting data that is used by several
1451 * of the methods above.
1453 @Test(dependsOnMethods = {"create", "read"})
1454 public void testSubmitRequest() {
1456 // Expected status code: 200 OK
1457 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1459 // Submit the request to the service and store the response.
1460 String method = ServiceRequestType.READ.httpMethodName();
1461 String url = getResourceURL(knownResourceId);
1462 int statusCode = submitRequest(method, url);
1464 // Check the status code of the response: does it match
1465 // the expected response(s)?
1466 if(logger.isDebugEnabled()){
1467 logger.debug("testSubmitRequest: url=" + url +
1468 " status=" + statusCode);
1470 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1474 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1475 public void testItemSubmitRequest() {
1477 // Expected status code: 200 OK
1478 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1480 // Submit the request to the service and store the response.
1481 String method = ServiceRequestType.READ.httpMethodName();
1482 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1483 int statusCode = submitRequest(method, url);
1485 // Check the status code of the response: does it match
1486 // the expected response(s)?
1487 if(logger.isDebugEnabled()){
1488 logger.debug("testItemSubmitRequest: url=" + url +
1489 " status=" + statusCode);
1491 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1495 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
1496 public void testContactSubmitRequest() {
1498 // Expected status code: 200 OK
1499 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1501 // Submit the request to the service and store the response.
1502 String method = ServiceRequestType.READ.httpMethodName();
1503 String url = getContactResourceURL(knownResourceId,
1504 knownItemResourceId, knownContactResourceId);
1505 int statusCode = submitRequest(method, url);
1507 // Check the status code of the response: does it match
1508 // the expected response(s)?
1509 if(logger.isDebugEnabled()){
1510 logger.debug("testItemSubmitRequest: url=" + url +
1511 " status=" + statusCode);
1513 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1518 // ---------------------------------------------------------------
1519 // Cleanup of resources created during testing
1520 // ---------------------------------------------------------------
1523 * Deletes all resources created by tests, after all tests have been run.
1525 * This cleanup method will always be run, even if one or more tests fail.
1526 * For this reason, it attempts to remove all resources created
1527 * at any point during testing, even if some of those resources
1528 * may be expected to be deleted by certain tests.
1531 @AfterClass(alwaysRun=true)
1532 public void cleanUp() {
1533 if (logger.isDebugEnabled()) {
1534 logger.debug("Cleaning up temporary resources created for testing ...");
1536 String parentResourceId;
1537 String itemResourceId;
1538 String contactResourceId;
1539 // Clean up contact resources.
1540 parentResourceId = knownResourceId;
1541 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
1542 contactResourceId = entry.getKey();
1543 itemResourceId = entry.getValue();
1544 // Note: Any non-success responses from the delete operation
1545 // below are ignored and not reported.
1546 ClientResponse<Response> res =
1547 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
1549 // Clean up item resources.
1550 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1551 itemResourceId = entry.getKey();
1552 parentResourceId = entry.getValue();
1553 // Note: Any non-success responses from the delete operation
1554 // below are ignored and not reported.
1555 ClientResponse<Response> res =
1556 client.deleteItem(parentResourceId, itemResourceId);
1558 // Clean up parent resources.
1559 for (String resourceId : allResourceIdsCreated) {
1560 // Note: Any non-success responses from the delete operation
1561 // below are ignored and not reported.
1562 ClientResponse<Response> res = client.delete(resourceId);
1566 // ---------------------------------------------------------------
1567 // Utility methods used by tests above
1568 // ---------------------------------------------------------------
1570 public String getServicePathComponent() {
1571 return SERVICE_PATH_COMPONENT;
1574 public String getItemServicePathComponent() {
1575 return ITEM_SERVICE_PATH_COMPONENT;
1578 public String getContactServicePathComponent() {
1579 return CONTACT_SERVICE_PATH_COMPONENT;
1583 * Returns the root URL for the item service.
1585 * This URL consists of a base URL for all services, followed by
1586 * a path component for the owning parent, followed by the
1587 * path component for the items.
1589 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1590 * parent authority resource of the relevant item resource.
1592 * @return The root URL for the item service.
1594 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1595 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1599 * Returns the URL of a specific item resource managed by a service, and
1600 * designated by an identifier (such as a universally unique ID, or UUID).
1602 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1603 * parent authority resource of the relevant item resource.
1605 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1608 * @return The URL of a specific item resource managed by a service.
1610 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1611 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
1616 * Returns the root URL for the contact service.
1618 * This URL consists of a base URL for all services, followed by
1619 * a path component for the owning authority, followed by the
1620 * path component for the owning item, followed by the path component
1621 * for the contact service.
1623 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1624 * parent authority resource of the relevant item resource.
1626 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1629 * @return The root URL for the contact service.
1631 protected String getContactServiceRootURL(String parentResourceIdentifier,
1632 String itemResourceIdentifier) {
1633 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
1634 getContactServicePathComponent();
1638 * Returns the URL of a specific contact resource managed by a service, and
1639 * designated by an identifier (such as a universally unique ID, or UUID).
1641 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1642 * parent resource of the relevant item resource.
1644 * @param resourceIdentifier An identifier (such as a UUID) for an
1647 * @return The URL of a specific resource managed by a service.
1649 protected String getContactResourceURL(String parentResourceIdentifier,
1650 String itemResourceIdentifier, String contactResourceIdentifier) {
1651 return getContactServiceRootURL(parentResourceIdentifier,
1652 itemResourceIdentifier) + "/" + contactResourceIdentifier;