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=" +
813 readItemList(csid, null);
819 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
820 public void readItemList() {
821 readItemList(knownResourceId, null);
824 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
825 public void readItemListByAuthorityName() {
826 readItemList(null, knownResourceDisplayName);
828 private void readItemList(String vcsid, String name) {
830 final String testName = "readItemList";
833 setupReadList(testName);
835 ClientResponse<PersonsCommonList> res = null;
838 // Submit the request to the service and store the response.
839 res = client.readItemList(vcsid);
840 } else if(name!= null) {
841 // Submit the request to the service and store the response.
842 res = client.readItemListForNamedAuthority(name);
844 Assert.fail("readItemList passed null csid and name!");
846 PersonsCommonList list = res.getEntity();
847 int statusCode = res.getStatus();
849 // Check the status code of the response: does it match
850 // the expected response(s)?
851 if(logger.isDebugEnabled()){
852 logger.debug(testName + ": status = " + statusCode);
854 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
855 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
856 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
858 List<PersonsCommonList.PersonListItem> items =
859 list.getPersonListItem();
860 int nItemsReturned = items.size();
861 // There will be one item created, associated with a
862 // known parent resource, by the createItem test.
864 // In addition, there will be 'nItemsToCreateInList'
865 // additional items created by the createItemList test,
866 // all associated with the same parent resource.
867 int nExpectedItems = nItemsToCreateInList + 1;
868 if(logger.isDebugEnabled()){
869 logger.debug(testName + ": Expected "
870 + nExpectedItems +" items; got: "+nItemsReturned);
872 Assert.assertEquals(nItemsReturned, nExpectedItems);
875 for (PersonsCommonList.PersonListItem item : items) {
876 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
877 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
878 // Optionally output additional data about list members for debugging.
879 boolean showDetails = true;
880 if (showDetails && logger.isDebugEnabled()) {
881 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
883 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
885 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
886 item.getDisplayName());
887 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
894 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
895 public void readContactList() {
896 readContactList(knownResourceId, knownItemResourceId);
899 private void readContactList(String parentcsid, String itemcsid) {
900 final String testName = "readContactList";
903 setupReadList(testName);
905 // Submit the request to the service and store the response.
906 ClientResponse<ContactsCommonList> res =
907 client.readContactList(parentcsid, itemcsid);
908 ContactsCommonList list = res.getEntity();
909 int statusCode = res.getStatus();
911 // Check the status code of the response: does it match
912 // the expected response(s)?
913 if(logger.isDebugEnabled()){
914 logger.debug(testName + ": status = " + statusCode);
916 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
917 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
918 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
920 List<ContactsCommonList.ContactListItem> listitems =
921 list.getContactListItem();
922 int nItemsReturned = listitems.size();
923 // There will be one item created, associated with a
924 // known parent resource, by the createItem test.
926 // In addition, there will be 'nItemsToCreateInList'
927 // additional items created by the createItemList test,
928 // all associated with the same parent resource.
929 int nExpectedItems = nItemsToCreateInList + 1;
930 if(logger.isDebugEnabled()){
931 logger.debug(testName + ": Expected "
932 + nExpectedItems +" items; got: "+nItemsReturned);
934 Assert.assertEquals(nItemsReturned, nExpectedItems);
937 for (ContactsCommonList.ContactListItem listitem : listitems) {
938 // Optionally output additional data about list members for debugging.
939 boolean showDetails = false;
940 if (showDetails && logger.isDebugEnabled()) {
941 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
943 logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" +
944 listitem.getAddressPlace());
945 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
955 // ---------------------------------------------------------------
956 // CRUD tests : UPDATE tests
957 // ---------------------------------------------------------------
960 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
961 groups = {"update"}, dependsOnGroups = {"read", "readList"})
962 public void update(String testName) throws Exception {
965 setupUpdate(testName);
967 // Retrieve the contents of a resource to update.
968 ClientResponse<MultipartInput> res =
969 client.read(knownResourceId);
970 if(logger.isDebugEnabled()){
971 logger.debug(testName + ": read status = " + res.getStatus());
973 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
975 if(logger.isDebugEnabled()){
976 logger.debug("got PersonAuthority to update with ID: " + knownResourceId);
978 MultipartInput input = (MultipartInput) res.getEntity();
979 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
980 client.getCommonPartName(), PersonauthoritiesCommon.class);
981 Assert.assertNotNull(personAuthority);
983 // Update the contents of this resource.
984 personAuthority.setDisplayName("updated-" + personAuthority.getDisplayName());
985 personAuthority.setVocabType("updated-" + personAuthority.getVocabType());
986 if(logger.isDebugEnabled()){
987 logger.debug("to be updated PersonAuthority");
988 logger.debug(objectAsXmlString(personAuthority, PersonauthoritiesCommon.class));
991 // Submit the updated resource to the service and store the response.
992 MultipartOutput output = new MultipartOutput();
993 OutputPart commonPart = output.addPart(personAuthority, MediaType.APPLICATION_XML_TYPE);
994 commonPart.getHeaders().add("label", client.getCommonPartName());
995 res = client.update(knownResourceId, output);
996 int statusCode = res.getStatus();
998 // Check the status code of the response: does it match the expected response(s)?
999 if(logger.isDebugEnabled()){
1000 logger.debug(testName + ": status = " + statusCode);
1002 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1003 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1004 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1006 // Retrieve the updated resource and verify that its contents exist.
1007 input = (MultipartInput) res.getEntity();
1008 PersonauthoritiesCommon updatedPersonAuthority =
1009 (PersonauthoritiesCommon) extractPart(input,
1010 client.getCommonPartName(), PersonauthoritiesCommon.class);
1011 Assert.assertNotNull(updatedPersonAuthority);
1013 // Verify that the updated resource received the correct data.
1014 Assert.assertEquals(updatedPersonAuthority.getDisplayName(),
1015 personAuthority.getDisplayName(),
1016 "Data in updated object did not match submitted data.");
1019 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1020 groups = {"update"}, dependsOnMethods = {"update"})
1021 public void updateItem(String testName) throws Exception {
1024 setupUpdate(testName);
1026 ClientResponse<MultipartInput> res =
1027 client.readItem(knownResourceId, knownItemResourceId);
1028 if(logger.isDebugEnabled()){
1029 logger.debug(testName + ": read status = " + res.getStatus());
1031 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1033 if(logger.isDebugEnabled()){
1034 logger.debug("got Person to update with ID: " +
1035 knownItemResourceId +
1036 " in PersonAuthority: " + knownResourceId );
1038 MultipartInput input = (MultipartInput) res.getEntity();
1039 PersonsCommon person = (PersonsCommon) extractPart(input,
1040 client.getItemCommonPartName(), PersonsCommon.class);
1041 Assert.assertNotNull(person);
1043 // Update the contents of this resource.
1044 person.setForeName("updated-" + person.getForeName());
1045 if(logger.isDebugEnabled()){
1046 logger.debug("to be updated Person");
1047 logger.debug(objectAsXmlString(person,
1048 PersonsCommon.class));
1051 // Submit the updated resource to the service and store the response.
1052 MultipartOutput output = new MultipartOutput();
1053 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
1054 commonPart.getHeaders().add("label", client.getItemCommonPartName());
1055 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1056 int statusCode = res.getStatus();
1058 // Check the status code of the response: does it match the expected response(s)?
1059 if(logger.isDebugEnabled()){
1060 logger.debug(testName + ": status = " + statusCode);
1062 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1063 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1064 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1066 // Retrieve the updated resource and verify that its contents exist.
1067 input = (MultipartInput) res.getEntity();
1068 PersonsCommon updatedPerson =
1069 (PersonsCommon) extractPart(input,
1070 client.getItemCommonPartName(), PersonsCommon.class);
1071 Assert.assertNotNull(updatedPerson);
1073 // Verify that the updated resource received the correct data.
1074 Assert.assertEquals(updatedPerson.getForeName(),
1075 person.getForeName(),
1076 "Data in updated Person did not match submitted data.");
1079 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1080 groups = {"update"}, dependsOnMethods = {"updateItem"})
1081 public void updateContact(String testName) throws Exception {
1084 setupUpdate(testName);
1086 ClientResponse<MultipartInput> res =
1087 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1088 if(logger.isDebugEnabled()){
1089 logger.debug(testName + ": read status = " + res.getStatus());
1091 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1093 if(logger.isDebugEnabled()){
1094 logger.debug("got Contact to update with ID: " +
1095 knownContactResourceId +
1096 " in item: " + knownItemResourceId +
1097 " in parent: " + knownResourceId );
1099 MultipartInput input = (MultipartInput) res.getEntity();
1100 ContactsCommon contact = (ContactsCommon) extractPart(input,
1101 contactClient.getCommonPartName(), ContactsCommon.class);
1102 Assert.assertNotNull(contact);
1104 // Update the contents of this resource.
1105 contact.setAddressPlace("updated-" + contact.getAddressPlace());
1106 if(logger.isDebugEnabled()){
1107 logger.debug("to be updated Contact");
1108 logger.debug(objectAsXmlString(contact,
1109 ContactsCommon.class));
1112 // Submit the updated resource to the service and store the response.
1113 MultipartOutput output = new MultipartOutput();
1114 OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1115 commonPart.getHeaders().add("label", contactClient.getCommonPartName());
1116 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1117 int statusCode = res.getStatus();
1119 // Check the status code of the response: does it match the expected response(s)?
1120 if(logger.isDebugEnabled()){
1121 logger.debug(testName + ": status = " + statusCode);
1123 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1124 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1125 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1127 // Retrieve the updated resource and verify that its contents exist.
1128 input = (MultipartInput) res.getEntity();
1129 ContactsCommon updatedContact =
1130 (ContactsCommon) extractPart(input,
1131 contactClient.getCommonPartName(), ContactsCommon.class);
1132 Assert.assertNotNull(updatedContact);
1134 // Verify that the updated resource received the correct data.
1135 Assert.assertEquals(updatedContact.getAddressPlace(),
1136 contact.getAddressPlace(),
1137 "Data in updated Contact did not match submitted data.");
1141 // Placeholders until the three tests below can be uncommented.
1142 // See Issue CSPACE-401.
1144 public void updateWithEmptyEntityBody(String testName) throws Exception {
1148 public void updateWithMalformedXml(String testName) throws Exception {
1152 public void updateWithWrongXmlSchema(String testName) throws Exception {
1157 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1158 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1159 public void updateWithEmptyEntityBody(String testName) throws Exception {
1162 setupUpdateWithEmptyEntityBody(testName);
1164 // Submit the request to the service and store the response.
1165 String method = REQUEST_TYPE.httpMethodName();
1166 String url = getResourceURL(knownResourceId);
1167 String mediaType = MediaType.APPLICATION_XML;
1168 final String entity = "";
1169 int statusCode = submitRequest(method, url, mediaType, entity);
1171 // Check the status code of the response: does it match
1172 // the expected response(s)?
1173 if(logger.isDebugEnabled()){
1174 logger.debug(testName + ": url=" + url +
1175 " status=" + statusCode);
1177 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1178 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1179 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1183 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1184 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1185 public void updateWithMalformedXml(String testName) throws Exception {
1188 setupUpdateWithMalformedXml(testName);
1190 // Submit the request to the service and store the response.
1191 String method = REQUEST_TYPE.httpMethodName();
1192 String url = getResourceURL(knownResourceId);
1193 String mediaType = MediaType.APPLICATION_XML;
1194 final String entity = MALFORMED_XML_DATA;
1195 int statusCode = submitRequest(method, url, mediaType, entity);
1197 // Check the status code of the response: does it match
1198 // the expected response(s)?
1199 if(logger.isDebugEnabled()){
1200 logger.debug(testName + ": url=" + url +
1201 " status=" + statusCode);
1203 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1204 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1205 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1209 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1210 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1211 public void updateWithWrongXmlSchema(String testName) throws Exception {
1214 setupUpdateWithWrongXmlSchema(testName);
1216 // Submit the request to the service and store the response.
1217 String method = REQUEST_TYPE.httpMethodName();
1218 String url = getResourceURL(knownResourceId);
1219 String mediaType = MediaType.APPLICATION_XML;
1220 final String entity = WRONG_XML_SCHEMA_DATA;
1221 int statusCode = submitRequest(method, url, mediaType, entity);
1223 // Check the status code of the response: does it match
1224 // the expected response(s)?
1225 if(logger.isDebugEnabled()){
1226 logger.debug("updateWithWrongXmlSchema: url=" + url +
1227 " status=" + statusCode);
1229 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1230 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1231 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1236 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1237 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1238 public void updateNonExistent(String testName) throws Exception {
1241 setupUpdateNonExistent(testName);
1243 // Submit the request to the service and store the response.
1244 // Note: The ID(s) used when creating the request payload may be arbitrary.
1245 // The only relevant ID may be the one used in update(), below.
1246 String displayName = "displayName-NON_EXISTENT_ID";
1247 String fullRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, true);
1248 MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
1249 displayName, fullRefName, client.getCommonPartName());
1250 ClientResponse<MultipartInput> res =
1251 client.update(NON_EXISTENT_ID, multipart);
1252 int statusCode = res.getStatus();
1254 // Check the status code of the response: does it match
1255 // the expected response(s)?
1256 if(logger.isDebugEnabled()){
1257 logger.debug(testName + ": status = " + statusCode);
1259 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1260 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1261 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1264 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1265 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1266 public void updateNonExistentItem(String testName) throws Exception {
1269 setupUpdateNonExistent(testName);
1271 // Submit the request to the service and store the response.
1272 // Note: The ID used in this 'create' call may be arbitrary.
1273 // The only relevant ID may be the one used in update(), below.
1275 // The only relevant ID may be the one used in update(), below.
1276 Map<String, String> nonexMap = new HashMap<String,String>();
1277 nonexMap.put(PersonJAXBSchema.FORE_NAME, "John");
1278 nonexMap.put(PersonJAXBSchema.SUR_NAME, "Wayne");
1279 nonexMap.put(PersonJAXBSchema.GENDER, "male");
1280 MultipartOutput multipart =
1281 PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID,
1282 PersonAuthorityClientUtils.createPersonRefName(NON_EXISTENT_ID, NON_EXISTENT_ID, true), nonexMap,
1283 client.getItemCommonPartName() );
1284 ClientResponse<MultipartInput> res =
1285 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1286 int statusCode = res.getStatus();
1288 // Check the status code of the response: does it match
1289 // the expected response(s)?
1290 if(logger.isDebugEnabled()){
1291 logger.debug(testName + ": status = " + statusCode);
1293 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1294 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1295 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1298 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1299 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1300 public void updateNonExistentContact(String testName) throws Exception {
1301 // Currently a no-op test
1304 // ---------------------------------------------------------------
1305 // CRUD tests : DELETE tests
1306 // ---------------------------------------------------------------
1309 // Note: delete sub-resources in ascending hierarchical order,
1310 // before deleting their parents.
1312 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1313 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1314 public void deleteContact(String testName) throws Exception {
1317 setupDelete(testName);
1319 if(logger.isDebugEnabled()){
1320 logger.debug("parentcsid =" + knownResourceId +
1321 " itemcsid = " + knownItemResourceId +
1322 " csid = " + knownContactResourceId);
1325 // Submit the request to the service and store the response.
1326 ClientResponse<Response> res =
1327 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1328 int statusCode = res.getStatus();
1330 // Check the status code of the response: does it match
1331 // the expected response(s)?
1332 if(logger.isDebugEnabled()){
1333 logger.debug(testName + ": status = " + statusCode);
1335 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1336 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1337 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1340 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1341 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1342 public void deleteItem(String testName) throws Exception {
1345 setupDelete(testName);
1347 if(logger.isDebugEnabled()){
1348 logger.debug("parentcsid =" + knownResourceId +
1349 " itemcsid = " + knownItemResourceId);
1352 // Submit the request to the service and store the response.
1353 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1354 int statusCode = res.getStatus();
1356 // Check the status code of the response: does it match
1357 // the expected response(s)?
1358 if(logger.isDebugEnabled()){
1359 logger.debug(testName + ": status = " + statusCode);
1361 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1362 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1363 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1367 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1368 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1369 public void delete(String testName) throws Exception {
1372 setupDelete(testName);
1374 if(logger.isDebugEnabled()){
1375 logger.debug("parentcsid =" + knownResourceId);
1378 // Submit the request to the service and store the response.
1379 ClientResponse<Response> res = client.delete(knownResourceId);
1380 int statusCode = res.getStatus();
1382 // Check the status code of the response: does it match
1383 // the expected response(s)?
1384 if(logger.isDebugEnabled()){
1385 logger.debug(testName + ": status = " + statusCode);
1387 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1388 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1389 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1394 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1395 groups = {"delete"}, dependsOnMethods = {"delete"})
1396 public void deleteNonExistent(String testName) throws Exception {
1399 setupDeleteNonExistent(testName);
1401 // Submit the request to the service and store the response.
1402 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1403 int statusCode = res.getStatus();
1405 // Check the status code of the response: does it match
1406 // the expected response(s)?
1407 if(logger.isDebugEnabled()){
1408 logger.debug(testName + ": status = " + statusCode);
1410 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1411 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1412 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1415 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1416 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1417 public void deleteNonExistentItem(String testName) {
1420 setupDeleteNonExistent(testName);
1422 // Submit the request to the service and store the response.
1423 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1424 int statusCode = res.getStatus();
1426 // Check the status code of the response: does it match
1427 // the expected response(s)?
1428 if(logger.isDebugEnabled()){
1429 logger.debug(testName + ": status = " + statusCode);
1431 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1432 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1433 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1436 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1437 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1438 public void deleteNonExistentContact(String testName) {
1441 setupDeleteNonExistent(testName);
1443 // Submit the request to the service and store the response.
1444 ClientResponse<Response> res =
1445 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1446 int statusCode = res.getStatus();
1448 // Check the status code of the response: does it match
1449 // the expected response(s)?
1450 if(logger.isDebugEnabled()){
1451 logger.debug(testName + ": status = " + statusCode);
1453 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1454 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1455 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1458 // ---------------------------------------------------------------
1459 // Utility tests : tests of code used in tests above
1460 // ---------------------------------------------------------------
1462 * Tests the code for manually submitting data that is used by several
1463 * of the methods above.
1465 @Test(dependsOnMethods = {"create", "read"})
1466 public void testSubmitRequest() {
1468 // Expected status code: 200 OK
1469 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1471 // Submit the request to the service and store the response.
1472 String method = ServiceRequestType.READ.httpMethodName();
1473 String url = getResourceURL(knownResourceId);
1474 int statusCode = submitRequest(method, url);
1476 // Check the status code of the response: does it match
1477 // the expected response(s)?
1478 if(logger.isDebugEnabled()){
1479 logger.debug("testSubmitRequest: url=" + url +
1480 " status=" + statusCode);
1482 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1486 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1487 public void testItemSubmitRequest() {
1489 // Expected status code: 200 OK
1490 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1492 // Submit the request to the service and store the response.
1493 String method = ServiceRequestType.READ.httpMethodName();
1494 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1495 int statusCode = submitRequest(method, url);
1497 // Check the status code of the response: does it match
1498 // the expected response(s)?
1499 if(logger.isDebugEnabled()){
1500 logger.debug("testItemSubmitRequest: url=" + url +
1501 " status=" + statusCode);
1503 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1507 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
1508 public void testContactSubmitRequest() {
1510 // Expected status code: 200 OK
1511 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1513 // Submit the request to the service and store the response.
1514 String method = ServiceRequestType.READ.httpMethodName();
1515 String url = getContactResourceURL(knownResourceId,
1516 knownItemResourceId, knownContactResourceId);
1517 int statusCode = submitRequest(method, url);
1519 // Check the status code of the response: does it match
1520 // the expected response(s)?
1521 if(logger.isDebugEnabled()){
1522 logger.debug("testItemSubmitRequest: url=" + url +
1523 " status=" + statusCode);
1525 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1530 // ---------------------------------------------------------------
1531 // Cleanup of resources created during testing
1532 // ---------------------------------------------------------------
1535 * Deletes all resources created by tests, after all tests have been run.
1537 * This cleanup method will always be run, even if one or more tests fail.
1538 * For this reason, it attempts to remove all resources created
1539 * at any point during testing, even if some of those resources
1540 * may be expected to be deleted by certain tests.
1543 @AfterClass(alwaysRun=true)
1544 public void cleanUp() {
1545 if (logger.isDebugEnabled()) {
1546 logger.debug("Cleaning up temporary resources created for testing ...");
1548 String parentResourceId;
1549 String itemResourceId;
1550 String contactResourceId;
1551 // Clean up contact resources.
1552 parentResourceId = knownResourceId;
1553 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
1554 contactResourceId = entry.getKey();
1555 itemResourceId = entry.getValue();
1556 // Note: Any non-success responses from the delete operation
1557 // below are ignored and not reported.
1558 ClientResponse<Response> res =
1559 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
1561 // Clean up item resources.
1562 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1563 itemResourceId = entry.getKey();
1564 parentResourceId = entry.getValue();
1565 // Note: Any non-success responses from the delete operation
1566 // below are ignored and not reported.
1567 ClientResponse<Response> res =
1568 client.deleteItem(parentResourceId, itemResourceId);
1570 // Clean up parent resources.
1571 for (String resourceId : allResourceIdsCreated) {
1572 // Note: Any non-success responses from the delete operation
1573 // below are ignored and not reported.
1574 ClientResponse<Response> res = client.delete(resourceId);
1578 // ---------------------------------------------------------------
1579 // Utility methods used by tests above
1580 // ---------------------------------------------------------------
1582 public String getServicePathComponent() {
1583 return SERVICE_PATH_COMPONENT;
1586 public String getItemServicePathComponent() {
1587 return ITEM_SERVICE_PATH_COMPONENT;
1590 public String getContactServicePathComponent() {
1591 return CONTACT_SERVICE_PATH_COMPONENT;
1595 * Returns the root URL for the item service.
1597 * This URL consists of a base URL for all services, followed by
1598 * a path component for the owning parent, followed by the
1599 * path component for the items.
1601 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1602 * parent authority resource of the relevant item resource.
1604 * @return The root URL for the item service.
1606 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1607 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1611 * Returns the URL of a specific item resource managed by a service, and
1612 * designated by an identifier (such as a universally unique ID, or UUID).
1614 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1615 * parent authority resource of the relevant item resource.
1617 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1620 * @return The URL of a specific item resource managed by a service.
1622 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1623 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
1628 * Returns the root URL for the contact service.
1630 * This URL consists of a base URL for all services, followed by
1631 * a path component for the owning authority, followed by the
1632 * path component for the owning item, followed by the path component
1633 * for the contact service.
1635 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1636 * parent authority resource of the relevant item resource.
1638 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1641 * @return The root URL for the contact service.
1643 protected String getContactServiceRootURL(String parentResourceIdentifier,
1644 String itemResourceIdentifier) {
1645 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
1646 getContactServicePathComponent();
1650 * Returns the URL of a specific contact resource managed by a service, and
1651 * designated by an identifier (such as a universally unique ID, or UUID).
1653 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1654 * parent resource of the relevant item resource.
1656 * @param resourceIdentifier An identifier (such as a UUID) for an
1659 * @return The URL of a specific resource managed by a service.
1661 protected String getContactResourceURL(String parentResourceIdentifier,
1662 String itemResourceIdentifier, String contactResourceIdentifier) {
1663 return getContactServiceRootURL(parentResourceIdentifier,
1664 itemResourceIdentifier) + "/" + contactResourceIdentifier;