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 knownResourceRefName = null;
79 private String knownItemResourceId = null;
80 private String knownContactResourceId = null;
81 private int nItemsToCreateInList = 3;
82 private List<String> allResourceIdsCreated = new ArrayList<String>();
83 private Map<String, String> allItemResourceIdsCreated =
84 new HashMap<String, String>();
85 private Map<String, String> allContactResourceIdsCreated =
86 new HashMap<String, String>();
88 // ---------------------------------------------------------------
89 // CRUD tests : CREATE tests
90 // ---------------------------------------------------------------
93 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
95 public void create(String testName) throws Exception {
97 // Perform setup, such as initializing the type of service request
98 // (e.g. CREATE, DELETE), its valid and expected status codes, and
99 // its associated HTTP method name (e.g. POST, DELETE).
100 setupCreate(testName);
102 // Submit the request to the service and store the response.
103 String identifier = createIdentifier();
104 String displayName = "displayName-" + identifier;
105 String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, false);
106 String fullRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, true);
107 MultipartOutput multipart =
108 PersonAuthorityClientUtils.createPersonAuthorityInstance(
109 displayName, fullRefName, client.getCommonPartName());
110 ClientResponse<Response> res = client.create(multipart);
111 int statusCode = res.getStatus();
113 // Check the status code of the response: does it match
114 // the expected response(s)?
117 // Does it fall within the set of valid status codes?
118 // Does it exactly match the expected status code?
119 if(logger.isDebugEnabled()){
120 logger.debug(testName + ": status = " + statusCode);
122 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
123 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
124 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
126 // Store the refname from the first resource created
127 // for additional tests below.
128 knownResourceRefName = baseRefName;
130 String newID = PersonAuthorityClientUtils.extractId(res);
131 // Store the ID returned from the first resource created
132 // for additional tests below.
133 if (knownResourceId == null){
134 knownResourceId = newID;
135 if (logger.isDebugEnabled()) {
136 logger.debug(testName + ": knownResourceId=" + knownResourceId);
139 // Store the IDs from every resource created by tests,
140 // so they can be deleted after tests have been run.
141 allResourceIdsCreated.add(newID);
144 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
145 groups = {"create"}, dependsOnMethods = {"create"})
146 public void createItem(String testName) {
147 setupCreate(testName);
148 String newID = createItemInAuthority(knownResourceId, knownResourceRefName);
151 private String createItemInAuthority(String vcsid, String authRefName) {
153 final String testName = "createItemInAuthority";
154 if(logger.isDebugEnabled()){
155 logger.debug(testName + ":...");
158 // Submit the request to the service and store the response.
159 String identifier = createIdentifier();
160 String refName = PersonAuthorityClientUtils.createPersonRefName(authRefName, "John Wayne", true);
161 Map<String, String> johnWayneMap = new HashMap<String,String>();
162 johnWayneMap.put(PersonJAXBSchema.FORE_NAME, TEST_FORE_NAME);
163 johnWayneMap.put(PersonJAXBSchema.SUR_NAME, TEST_SUR_NAME);
164 johnWayneMap.put(PersonJAXBSchema.GENDER, "male");
165 johnWayneMap.put(PersonJAXBSchema.BIRTH_DATE, TEST_BIRTH_DATE);
166 johnWayneMap.put(PersonJAXBSchema.BIRTH_PLACE, "Winterset, Iowa");
167 johnWayneMap.put(PersonJAXBSchema.DEATH_DATE, TEST_DEATH_DATE);
168 johnWayneMap.put(PersonJAXBSchema.BIO_NOTE, "born Marion Robert Morrison and better" +
169 "known by his stage name John Wayne, was an American film actor, director " +
170 "and producer. He epitomized rugged masculinity and has become an enduring " +
171 "American icon. He is famous for his distinctive voice, walk and height. " +
172 "He was also known for his conservative political views and his support in " +
173 "the 1950s for anti-communist positions.");
174 MultipartOutput multipart =
175 PersonAuthorityClientUtils.createPersonInstance(vcsid, refName, johnWayneMap,
176 client.getItemCommonPartName() );
177 ClientResponse<Response> res = client.createItem(vcsid, multipart);
178 int statusCode = res.getStatus();
179 String newID = PersonAuthorityClientUtils.extractId(res);
181 // Check the status code of the response: does it match
182 // the expected response(s)?
183 if(logger.isDebugEnabled()){
184 logger.debug(testName + ": status = " + statusCode);
186 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
187 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
188 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
190 // Store the ID returned from the first item resource created
191 // for additional tests below.
192 if (knownItemResourceId == null){
193 knownItemResourceId = newID;
194 if (logger.isDebugEnabled()) {
195 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
199 // Store the IDs from any item resources created
200 // by tests, along with the IDs of their parents, so these items
201 // can be deleted after all tests have been run.
202 allItemResourceIdsCreated.put(newID, vcsid);
207 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
208 groups = {"create"}, dependsOnMethods = {"createItem"})
209 public void createContact(String testName) {
210 setupCreate(testName);
211 String newID = createContactInItem(knownResourceId, knownItemResourceId);
214 private String createContactInItem(String parentcsid, String itemcsid) {
216 final String testName = "createContactInItem";
217 setupCreate(testName);
218 if(logger.isDebugEnabled()){
219 logger.debug(testName + ":...");
222 // Submit the request to the service and store the response.
223 String identifier = createIdentifier();
224 MultipartOutput multipart =
225 ContactClientUtils.createContactInstance(parentcsid,
226 itemcsid, identifier, contactClient.getCommonPartName());
227 ClientResponse<Response> res =
228 client.createContact(parentcsid, itemcsid, multipart);
229 int statusCode = res.getStatus();
230 String newID = PersonAuthorityClientUtils.extractId(res);
232 // Check the status code of the response: does it match
233 // the expected response(s)?
234 if(logger.isDebugEnabled()){
235 logger.debug(testName + ": status = " + statusCode);
237 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
238 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
239 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
241 // Store the ID returned from the first contact resource created
242 // for additional tests below.
243 if (knownContactResourceId == null){
244 knownContactResourceId = newID;
245 if (logger.isDebugEnabled()) {
246 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
250 // Store the IDs from any contact resources created
251 // by tests, along with the IDs of their parent items,
252 // so these items can be deleted after all tests have been run.
253 allContactResourceIdsCreated.put(newID, itemcsid);
260 // Placeholders until the three tests below can be uncommented.
261 // See Issue CSPACE-401.
263 public void createWithEmptyEntityBody(String testName) throws Exception {
267 public void createWithMalformedXml(String testName) throws Exception {
271 public void createWithWrongXmlSchema(String testName) throws Exception {
276 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
277 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
278 public void createWithEmptyEntityBody(String testName) throws Exception {
281 setupCreateWithEmptyEntityBody(testName);
283 // Submit the request to the service and store the response.
284 String method = REQUEST_TYPE.httpMethodName();
285 String url = getServiceRootURL();
286 String mediaType = MediaType.APPLICATION_XML;
287 final String entity = "";
288 int statusCode = submitRequest(method, url, mediaType, entity);
290 // Check the status code of the response: does it match
291 // the expected response(s)?
292 if(logger.isDebugEnabled()) {
293 logger.debug(testName + ": url=" + url +
294 " status=" + statusCode);
296 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
297 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
298 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
302 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
303 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
304 public void createWithMalformedXml(String testName) throws Exception {
307 setupCreateWithMalformedXml(testName);
309 // Submit the request to the service and store the response.
310 String method = REQUEST_TYPE.httpMethodName();
311 String url = getServiceRootURL();
312 String mediaType = MediaType.APPLICATION_XML;
313 final String entity = MALFORMED_XML_DATA; // Constant from base class.
314 int statusCode = submitRequest(method, url, mediaType, entity);
316 // Check the status code of the response: does it match
317 // the expected response(s)?
318 if(logger.isDebugEnabled()){
319 logger.debug(testName + ": url=" + url +
320 " status=" + statusCode);
322 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
323 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
324 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
328 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
329 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
330 public void createWithWrongXmlSchema(String testName) throws Exception {
333 setupCreateWithWrongXmlSchema(testName);
335 // Submit the request to the service and store the response.
336 String method = REQUEST_TYPE.httpMethodName();
337 String url = getServiceRootURL();
338 String mediaType = MediaType.APPLICATION_XML;
339 final String entity = WRONG_XML_SCHEMA_DATA;
340 int statusCode = submitRequest(method, url, mediaType, entity);
342 // Check the status code of the response: does it match
343 // the expected response(s)?
344 if(logger.isDebugEnabled()){
345 logger.debug(testName + ": url=" + url +
346 " status=" + statusCode);
348 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
349 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
350 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
354 // ---------------------------------------------------------------
355 // CRUD tests : CREATE LIST tests
356 // ---------------------------------------------------------------
359 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
360 groups = {"createList"}, dependsOnGroups = {"create"})
361 public void createList(String testName) throws Exception {
362 for (int i = 0; i < nItemsToCreateInList; i++) {
367 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
368 groups = {"createList"}, dependsOnMethods = {"createList"})
369 public void createItemList(String testName) throws Exception {
370 // Add items to the initially-created, known parent record.
371 for (int j = 0; j < nItemsToCreateInList; j++) {
372 createItem(testName);
376 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
377 groups = {"createList"}, dependsOnMethods = {"createItemList"})
378 public void createContactList(String testName) throws Exception {
379 // Add contacts to the initially-created, known item record.
380 for (int j = 0; j < nItemsToCreateInList; j++) {
381 createContact(testName);
385 // ---------------------------------------------------------------
386 // CRUD tests : READ tests
387 // ---------------------------------------------------------------
390 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
391 groups = {"read"}, dependsOnGroups = {"create"})
392 public void read(String testName) throws Exception {
397 // Submit the request to the service and store the response.
398 ClientResponse<MultipartInput> res = client.read(knownResourceId);
399 int statusCode = res.getStatus();
401 // Check the status code of the response: does it match
402 // the expected response(s)?
403 if(logger.isDebugEnabled()){
404 logger.debug(testName + ": status = " + statusCode);
406 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
407 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
408 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
409 //FIXME: remove the following try catch once Aron fixes signatures
411 MultipartInput input = (MultipartInput) res.getEntity();
412 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
413 client.getCommonPartName(), PersonauthoritiesCommon.class);
414 Assert.assertNotNull(personAuthority);
415 } catch (Exception e) {
416 throw new RuntimeException(e);
421 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
422 groups = {"read"}, dependsOnMethods = {"read"})
423 public void readByName(String testName) throws Exception {
428 // Submit the request to the service and store the response.
429 ClientResponse<MultipartInput> res = client.read(knownResourceId);
430 int statusCode = res.getStatus();
432 // Check the status code of the response: does it match
433 // the expected response(s)?
434 if(logger.isDebugEnabled()){
435 logger.debug(testName + ": status = " + statusCode);
437 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
438 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
439 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
440 //FIXME: remove the following try catch once Aron fixes signatures
442 MultipartInput input = (MultipartInput) res.getEntity();
443 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
444 client.getCommonPartName(), PersonauthoritiesCommon.class);
445 Assert.assertNotNull(personAuthority);
446 } catch (Exception e) {
447 throw new RuntimeException(e);
452 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
453 groups = {"read"}, dependsOnMethods = {"read"})
454 public void readItem(String testName) throws Exception {
459 // Submit the request to the service and store the response.
460 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
461 int statusCode = res.getStatus();
463 // Check the status code of the response: does it match
464 // the expected response(s)?
465 if(logger.isDebugEnabled()){
466 logger.debug(testName + ": status = " + statusCode);
468 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
469 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
470 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
472 // Check whether we've received a person.
473 MultipartInput input = (MultipartInput) res.getEntity();
474 PersonsCommon person = (PersonsCommon) extractPart(input,
475 client.getItemCommonPartName(), PersonsCommon.class);
476 Assert.assertNotNull(person);
477 boolean showFull = true;
478 if(showFull && logger.isDebugEnabled()){
479 logger.debug(testName + ": returned payload:");
480 logger.debug(objectAsXmlString(person, PersonsCommon.class));
482 Assert.assertEquals(person.getInAuthority(), knownResourceId);
486 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
487 dependsOnMethods = {"readItem", "updateItem"})
488 public void verifyItemDisplayName(String testName) throws Exception {
491 setupUpdate(testName);
493 // Submit the request to the service and store the response.
494 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
495 int statusCode = res.getStatus();
497 // Check the status code of the response: does it match
498 // the expected response(s)?
499 if(logger.isDebugEnabled()){
500 logger.debug(testName + ": status = " + statusCode);
502 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
503 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
504 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
506 // Check whether person has expected displayName.
507 MultipartInput input = (MultipartInput) res.getEntity();
508 PersonsCommon person = (PersonsCommon) extractPart(input,
509 client.getItemCommonPartName(), PersonsCommon.class);
510 Assert.assertNotNull(person);
511 String displayName = person.getDisplayName();
512 // Make sure displayName matches computed form
513 String expectedDisplayName =
514 PersonAuthorityClientUtils.prepareDefaultDisplayName(
515 TEST_FORE_NAME, null, TEST_SUR_NAME,
516 TEST_BIRTH_DATE, TEST_DEATH_DATE);
517 Assert.assertNotNull(displayName, expectedDisplayName);
519 // Update the shortName and verify the computed name is updated.
520 person.setDisplayNameComputed(true);
521 person.setForeName("updated-" + TEST_FORE_NAME);
522 expectedDisplayName =
523 PersonAuthorityClientUtils.prepareDefaultDisplayName(
524 "updated-" + TEST_FORE_NAME, null, TEST_SUR_NAME,
525 TEST_BIRTH_DATE, TEST_DEATH_DATE);
527 // Submit the updated resource to the service and store the response.
528 MultipartOutput output = new MultipartOutput();
529 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
530 commonPart.getHeaders().add("label", client.getItemCommonPartName());
531 res = client.updateItem(knownResourceId, knownItemResourceId, output);
532 statusCode = res.getStatus();
534 // Check the status code of the response: does it match the expected response(s)?
535 if(logger.isDebugEnabled()){
536 logger.debug("updateItem: status = " + statusCode);
538 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
539 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
540 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
542 // Retrieve the updated resource and verify that its contents exist.
543 input = (MultipartInput) res.getEntity();
544 PersonsCommon updatedPerson =
545 (PersonsCommon) extractPart(input,
546 client.getItemCommonPartName(), PersonsCommon.class);
547 Assert.assertNotNull(updatedPerson);
549 // Verify that the updated resource received the correct data.
550 Assert.assertEquals(updatedPerson.getForeName(), person.getForeName(),
551 "Updated ForeName in Person did not match submitted data.");
552 // Verify that the updated resource computes the right displayName.
553 Assert.assertEquals(updatedPerson.getDisplayName(), expectedDisplayName,
554 "Updated ForeName in Person not reflected in computed DisplayName.");
556 // Now Update the displayName, not computed and verify the computed name is overriden.
557 person.setDisplayNameComputed(false);
558 expectedDisplayName = "TestName";
559 person.setDisplayName(expectedDisplayName);
561 // Submit the updated resource to the service and store the response.
562 output = new MultipartOutput();
563 commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
564 commonPart.getHeaders().add("label", client.getItemCommonPartName());
565 res = client.updateItem(knownResourceId, knownItemResourceId, output);
566 statusCode = res.getStatus();
568 // Check the status code of the response: does it match the expected response(s)?
569 if(logger.isDebugEnabled()){
570 logger.debug("updateItem: status = " + statusCode);
572 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
573 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
574 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
576 // Retrieve the updated resource and verify that its contents exist.
577 input = (MultipartInput) res.getEntity();
579 (PersonsCommon) extractPart(input,
580 client.getItemCommonPartName(), PersonsCommon.class);
581 Assert.assertNotNull(updatedPerson);
583 // Verify that the updated resource received the correct data.
584 Assert.assertEquals(updatedPerson.isDisplayNameComputed(), false,
585 "Updated displayNameComputed in Person did not match submitted data.");
586 // Verify that the updated resource computes the right displayName.
587 Assert.assertEquals(updatedPerson.getDisplayName(),
589 "Updated DisplayName (not computed) in Person not stored.");
592 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
593 dependsOnMethods = {"verifyItemDisplayName"})
594 public void verifyIllegalItemDisplayName(String testName) throws Exception {
597 setupUpdateWithWrongXmlSchema(testName);
599 // Submit the request to the service and store the response.
600 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
601 int statusCode = res.getStatus();
603 // Check the status code of the response: does it match
604 // the expected response(s)?
605 if(logger.isDebugEnabled()){
606 logger.debug(testName + ": status = " + statusCode);
608 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
609 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
610 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
612 // Check whether Person has expected displayName.
613 MultipartInput input = (MultipartInput) res.getEntity();
614 PersonsCommon person = (PersonsCommon) extractPart(input,
615 client.getItemCommonPartName(), PersonsCommon.class);
616 Assert.assertNotNull(person);
617 // Try to Update with computed false and no displayName
618 person.setDisplayNameComputed(false);
619 person.setDisplayName(null);
621 // Submit the updated resource to the service and store the response.
622 MultipartOutput output = new MultipartOutput();
623 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
624 commonPart.getHeaders().add("label", client.getItemCommonPartName());
625 res = client.updateItem(knownResourceId, knownItemResourceId, output);
626 statusCode = res.getStatus();
628 // Check the status code of the response: does it match the expected response(s)?
629 if(logger.isDebugEnabled()){
630 logger.debug("updateItem: status = " + statusCode);
632 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
633 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
634 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
637 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
638 groups = {"read"}, dependsOnMethods = {"readItem"})
639 public void readContact(String testName) throws Exception {
644 // Submit the request to the service and store the response.
645 ClientResponse<MultipartInput> res =
646 client.readContact(knownResourceId, knownItemResourceId,
647 knownContactResourceId);
648 int statusCode = res.getStatus();
650 // Check the status code of the response: does it match
651 // the expected response(s)?
652 if(logger.isDebugEnabled()){
653 logger.debug(testName + ": status = " + statusCode);
655 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
656 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
657 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
659 // Check whether we've received a contact.
660 MultipartInput input = (MultipartInput) res.getEntity();
661 ContactsCommon contact = (ContactsCommon) extractPart(input,
662 contactClient.getCommonPartName(), ContactsCommon.class);
663 Assert.assertNotNull(contact);
664 boolean showFull = true;
665 if(showFull && logger.isDebugEnabled()){
666 logger.debug(testName + ": returned payload:");
667 logger.debug(objectAsXmlString(contact, ContactsCommon.class));
669 Assert.assertEquals(contact.getInAuthority(), knownResourceId);
670 Assert.assertEquals(contact.getInItem(), knownItemResourceId);
676 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
677 groups = {"read"}, dependsOnMethods = {"read"})
678 public void readNonExistent(String testName) {
681 setupReadNonExistent(testName);
683 // Submit the request to the service and store the response.
684 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
685 int statusCode = res.getStatus();
687 // Check the status code of the response: does it match
688 // the expected response(s)?
689 if(logger.isDebugEnabled()){
690 logger.debug(testName + ": status = " + statusCode);
692 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
693 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
694 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
697 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
698 groups = {"read"}, dependsOnMethods = {"readItem"})
699 public void readItemNonExistent(String testName) {
702 setupReadNonExistent(testName);
704 // Submit the request to the service and store the response.
705 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
706 int statusCode = res.getStatus();
708 // Check the status code of the response: does it match
709 // the expected response(s)?
710 if(logger.isDebugEnabled()){
711 logger.debug(testName + ": status = " + statusCode);
713 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
714 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
715 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
718 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
719 groups = {"read"}, dependsOnMethods = {"readContact"})
720 public void readContactNonExistent(String testName) {
723 setupReadNonExistent(testName);
725 // Submit the request to the service and store the response.
726 ClientResponse<MultipartInput> res =
727 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
728 int statusCode = res.getStatus();
730 // Check the status code of the response: does it match
731 // the expected response(s)?
732 if(logger.isDebugEnabled()){
733 logger.debug(testName + ": status = " + statusCode);
735 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
736 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
737 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
740 // ---------------------------------------------------------------
741 // CRUD tests : READ_LIST tests
742 // ---------------------------------------------------------------
746 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
747 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
748 public void readList(String testName) throws Exception {
751 setupReadList(testName);
753 // Submit the request to the service and store the response.
754 ClientResponse<PersonauthoritiesCommonList> res = client.readList();
755 PersonauthoritiesCommonList list = res.getEntity();
756 int statusCode = res.getStatus();
758 // Check the status code of the response: does it match
759 // the expected response(s)?
760 if(logger.isDebugEnabled()){
761 logger.debug(testName + ": status = " + statusCode);
763 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
764 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
765 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
767 // Optionally output additional data about list members for debugging.
768 boolean iterateThroughList = false;
769 if (iterateThroughList && logger.isDebugEnabled()) {
770 List<PersonauthoritiesCommonList.PersonauthorityListItem> items =
771 list.getPersonauthorityListItem();
773 for (PersonauthoritiesCommonList.PersonauthorityListItem item : items) {
774 String csid = item.getCsid();
775 logger.debug(testName + ": list-item[" + i + "] csid=" +
777 logger.debug(testName + ": list-item[" + i + "] displayName=" +
778 item.getDisplayName());
779 logger.debug(testName + ": list-item[" + i + "] URI=" +
787 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
788 public void readItemList() {
789 readItemList(knownResourceId);
792 private void readItemList(String vcsid) {
794 final String testName = "readItemList";
797 setupReadList(testName);
799 // Submit the request to the service and store the response.
800 ClientResponse<PersonsCommonList> res =
801 client.readItemList(vcsid);
802 PersonsCommonList list = res.getEntity();
803 int statusCode = res.getStatus();
805 // Check the status code of the response: does it match
806 // the expected response(s)?
807 if(logger.isDebugEnabled()){
808 logger.debug(testName + ": status = " + statusCode);
810 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
811 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
812 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
814 List<PersonsCommonList.PersonListItem> items =
815 list.getPersonListItem();
816 int nItemsReturned = items.size();
817 // There will be one item created, associated with a
818 // known parent resource, by the createItem test.
820 // In addition, there will be 'nItemsToCreateInList'
821 // additional items created by the createItemList test,
822 // all associated with the same parent resource.
823 int nExpectedItems = nItemsToCreateInList + 1;
824 if(logger.isDebugEnabled()){
825 logger.debug(testName + ": Expected "
826 + nExpectedItems +" items; got: "+nItemsReturned);
828 Assert.assertEquals(nItemsReturned, nExpectedItems);
831 for (PersonsCommonList.PersonListItem item : items) {
832 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
833 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
834 // Optionally output additional data about list members for debugging.
835 boolean showDetails = true;
836 if (showDetails && logger.isDebugEnabled()) {
837 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
839 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
841 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
842 item.getDisplayName());
843 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
850 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
851 public void readContactList() {
852 readContactList(knownResourceId, knownItemResourceId);
855 private void readContactList(String parentcsid, String itemcsid) {
856 final String testName = "readContactList";
859 setupReadList(testName);
861 // Submit the request to the service and store the response.
862 ClientResponse<ContactsCommonList> res =
863 client.readContactList(parentcsid, itemcsid);
864 ContactsCommonList list = res.getEntity();
865 int statusCode = res.getStatus();
867 // Check the status code of the response: does it match
868 // the expected response(s)?
869 if(logger.isDebugEnabled()){
870 logger.debug(testName + ": status = " + statusCode);
872 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
873 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
874 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
876 List<ContactsCommonList.ContactListItem> listitems =
877 list.getContactListItem();
878 int nItemsReturned = listitems.size();
879 // There will be one item created, associated with a
880 // known parent resource, by the createItem test.
882 // In addition, there will be 'nItemsToCreateInList'
883 // additional items created by the createItemList test,
884 // all associated with the same parent resource.
885 int nExpectedItems = nItemsToCreateInList + 1;
886 if(logger.isDebugEnabled()){
887 logger.debug(testName + ": Expected "
888 + nExpectedItems +" items; got: "+nItemsReturned);
890 Assert.assertEquals(nItemsReturned, nExpectedItems);
893 for (ContactsCommonList.ContactListItem listitem : listitems) {
894 // Optionally output additional data about list members for debugging.
895 boolean showDetails = false;
896 if (showDetails && logger.isDebugEnabled()) {
897 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
899 logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" +
900 listitem.getAddressPlace());
901 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
911 // ---------------------------------------------------------------
912 // CRUD tests : UPDATE tests
913 // ---------------------------------------------------------------
916 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
917 groups = {"update"}, dependsOnGroups = {"read"})
918 public void update(String testName) throws Exception {
921 setupUpdate(testName);
923 // Retrieve the contents of a resource to update.
924 ClientResponse<MultipartInput> res =
925 client.read(knownResourceId);
926 if(logger.isDebugEnabled()){
927 logger.debug(testName + ": read status = " + res.getStatus());
929 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
931 if(logger.isDebugEnabled()){
932 logger.debug("got PersonAuthority to update with ID: " + knownResourceId);
934 MultipartInput input = (MultipartInput) res.getEntity();
935 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
936 client.getCommonPartName(), PersonauthoritiesCommon.class);
937 Assert.assertNotNull(personAuthority);
939 // Update the contents of this resource.
940 personAuthority.setDisplayName("updated-" + personAuthority.getDisplayName());
941 personAuthority.setVocabType("updated-" + personAuthority.getVocabType());
942 if(logger.isDebugEnabled()){
943 logger.debug("to be updated PersonAuthority");
944 logger.debug(objectAsXmlString(personAuthority, PersonauthoritiesCommon.class));
947 // Submit the updated resource to the service and store the response.
948 MultipartOutput output = new MultipartOutput();
949 OutputPart commonPart = output.addPart(personAuthority, MediaType.APPLICATION_XML_TYPE);
950 commonPart.getHeaders().add("label", client.getCommonPartName());
951 res = client.update(knownResourceId, output);
952 int statusCode = res.getStatus();
954 // Check the status code of the response: does it match the expected response(s)?
955 if(logger.isDebugEnabled()){
956 logger.debug(testName + ": status = " + statusCode);
958 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
959 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
960 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
962 // Retrieve the updated resource and verify that its contents exist.
963 input = (MultipartInput) res.getEntity();
964 PersonauthoritiesCommon updatedPersonAuthority =
965 (PersonauthoritiesCommon) extractPart(input,
966 client.getCommonPartName(), PersonauthoritiesCommon.class);
967 Assert.assertNotNull(updatedPersonAuthority);
969 // Verify that the updated resource received the correct data.
970 Assert.assertEquals(updatedPersonAuthority.getDisplayName(),
971 personAuthority.getDisplayName(),
972 "Data in updated object did not match submitted data.");
975 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
976 groups = {"update"}, dependsOnMethods = {"update"})
977 public void updateItem(String testName) throws Exception {
980 setupUpdate(testName);
982 ClientResponse<MultipartInput> res =
983 client.readItem(knownResourceId, knownItemResourceId);
984 if(logger.isDebugEnabled()){
985 logger.debug(testName + ": read status = " + res.getStatus());
987 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
989 if(logger.isDebugEnabled()){
990 logger.debug("got Person to update with ID: " +
991 knownItemResourceId +
992 " in PersonAuthority: " + knownResourceId );
994 MultipartInput input = (MultipartInput) res.getEntity();
995 PersonsCommon person = (PersonsCommon) extractPart(input,
996 client.getItemCommonPartName(), PersonsCommon.class);
997 Assert.assertNotNull(person);
999 // Update the contents of this resource.
1000 person.setForeName("updated-" + person.getForeName());
1001 if(logger.isDebugEnabled()){
1002 logger.debug("to be updated Person");
1003 logger.debug(objectAsXmlString(person,
1004 PersonsCommon.class));
1007 // Submit the updated resource to the service and store the response.
1008 MultipartOutput output = new MultipartOutput();
1009 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
1010 commonPart.getHeaders().add("label", client.getItemCommonPartName());
1011 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1012 int statusCode = res.getStatus();
1014 // Check the status code of the response: does it match the expected response(s)?
1015 if(logger.isDebugEnabled()){
1016 logger.debug(testName + ": status = " + statusCode);
1018 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1019 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1020 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1022 // Retrieve the updated resource and verify that its contents exist.
1023 input = (MultipartInput) res.getEntity();
1024 PersonsCommon updatedPerson =
1025 (PersonsCommon) extractPart(input,
1026 client.getItemCommonPartName(), PersonsCommon.class);
1027 Assert.assertNotNull(updatedPerson);
1029 // Verify that the updated resource received the correct data.
1030 Assert.assertEquals(updatedPerson.getForeName(),
1031 person.getForeName(),
1032 "Data in updated Person did not match submitted data.");
1035 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1036 groups = {"update"}, dependsOnMethods = {"updateItem"})
1037 public void updateContact(String testName) throws Exception {
1040 setupUpdate(testName);
1042 ClientResponse<MultipartInput> res =
1043 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1044 if(logger.isDebugEnabled()){
1045 logger.debug(testName + ": read status = " + res.getStatus());
1047 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1049 if(logger.isDebugEnabled()){
1050 logger.debug("got Contact to update with ID: " +
1051 knownContactResourceId +
1052 " in item: " + knownItemResourceId +
1053 " in parent: " + knownResourceId );
1055 MultipartInput input = (MultipartInput) res.getEntity();
1056 ContactsCommon contact = (ContactsCommon) extractPart(input,
1057 contactClient.getCommonPartName(), ContactsCommon.class);
1058 Assert.assertNotNull(contact);
1060 // Update the contents of this resource.
1061 contact.setAddressPlace("updated-" + contact.getAddressPlace());
1062 if(logger.isDebugEnabled()){
1063 logger.debug("to be updated Contact");
1064 logger.debug(objectAsXmlString(contact,
1065 ContactsCommon.class));
1068 // Submit the updated resource to the service and store the response.
1069 MultipartOutput output = new MultipartOutput();
1070 OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1071 commonPart.getHeaders().add("label", contactClient.getCommonPartName());
1072 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1073 int statusCode = res.getStatus();
1075 // Check the status code of the response: does it match the expected response(s)?
1076 if(logger.isDebugEnabled()){
1077 logger.debug(testName + ": status = " + statusCode);
1079 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1080 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1081 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1083 // Retrieve the updated resource and verify that its contents exist.
1084 input = (MultipartInput) res.getEntity();
1085 ContactsCommon updatedContact =
1086 (ContactsCommon) extractPart(input,
1087 contactClient.getCommonPartName(), ContactsCommon.class);
1088 Assert.assertNotNull(updatedContact);
1090 // Verify that the updated resource received the correct data.
1091 Assert.assertEquals(updatedContact.getAddressPlace(),
1092 contact.getAddressPlace(),
1093 "Data in updated Contact did not match submitted data.");
1097 // Placeholders until the three tests below can be uncommented.
1098 // See Issue CSPACE-401.
1100 public void updateWithEmptyEntityBody(String testName) throws Exception {
1104 public void updateWithMalformedXml(String testName) throws Exception {
1108 public void updateWithWrongXmlSchema(String testName) throws Exception {
1113 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1114 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1115 public void updateWithEmptyEntityBody(String testName) throws Exception {
1118 setupUpdateWithEmptyEntityBody(testName);
1120 // Submit the request to the service and store the response.
1121 String method = REQUEST_TYPE.httpMethodName();
1122 String url = getResourceURL(knownResourceId);
1123 String mediaType = MediaType.APPLICATION_XML;
1124 final String entity = "";
1125 int statusCode = submitRequest(method, url, mediaType, entity);
1127 // Check the status code of the response: does it match
1128 // the expected response(s)?
1129 if(logger.isDebugEnabled()){
1130 logger.debug(testName + ": url=" + url +
1131 " status=" + statusCode);
1133 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1134 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1135 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1139 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1140 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1141 public void updateWithMalformedXml(String testName) throws Exception {
1144 setupUpdateWithMalformedXml(testName);
1146 // Submit the request to the service and store the response.
1147 String method = REQUEST_TYPE.httpMethodName();
1148 String url = getResourceURL(knownResourceId);
1149 String mediaType = MediaType.APPLICATION_XML;
1150 final String entity = MALFORMED_XML_DATA;
1151 int statusCode = submitRequest(method, url, mediaType, entity);
1153 // Check the status code of the response: does it match
1154 // the expected response(s)?
1155 if(logger.isDebugEnabled()){
1156 logger.debug(testName + ": url=" + url +
1157 " status=" + statusCode);
1159 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1160 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1161 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1165 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1166 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1167 public void updateWithWrongXmlSchema(String testName) throws Exception {
1170 setupUpdateWithWrongXmlSchema(testName);
1172 // Submit the request to the service and store the response.
1173 String method = REQUEST_TYPE.httpMethodName();
1174 String url = getResourceURL(knownResourceId);
1175 String mediaType = MediaType.APPLICATION_XML;
1176 final String entity = WRONG_XML_SCHEMA_DATA;
1177 int statusCode = submitRequest(method, url, mediaType, entity);
1179 // Check the status code of the response: does it match
1180 // the expected response(s)?
1181 if(logger.isDebugEnabled()){
1182 logger.debug("updateWithWrongXmlSchema: url=" + url +
1183 " status=" + statusCode);
1185 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1186 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1187 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1192 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1193 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1194 public void updateNonExistent(String testName) throws Exception {
1197 setupUpdateNonExistent(testName);
1199 // Submit the request to the service and store the response.
1200 // Note: The ID(s) used when creating the request payload may be arbitrary.
1201 // The only relevant ID may be the one used in update(), below.
1202 String displayName = "displayName-NON_EXISTENT_ID";
1203 String fullRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, true);
1204 MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
1205 displayName, fullRefName, client.getCommonPartName());
1206 ClientResponse<MultipartInput> res =
1207 client.update(NON_EXISTENT_ID, multipart);
1208 int statusCode = res.getStatus();
1210 // Check the status code of the response: does it match
1211 // the expected response(s)?
1212 if(logger.isDebugEnabled()){
1213 logger.debug(testName + ": status = " + statusCode);
1215 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1216 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1217 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1220 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1221 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1222 public void updateNonExistentItem(String testName) throws Exception {
1225 setupUpdateNonExistent(testName);
1227 // Submit the request to the service and store the response.
1228 // Note: The ID used in this 'create' call may be arbitrary.
1229 // The only relevant ID may be the one used in update(), below.
1231 // The only relevant ID may be the one used in update(), below.
1232 Map<String, String> nonexMap = new HashMap<String,String>();
1233 nonexMap.put(PersonJAXBSchema.FORE_NAME, "John");
1234 nonexMap.put(PersonJAXBSchema.SUR_NAME, "Wayne");
1235 nonexMap.put(PersonJAXBSchema.GENDER, "male");
1236 MultipartOutput multipart =
1237 PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID,
1238 PersonAuthorityClientUtils.createPersonRefName(NON_EXISTENT_ID, NON_EXISTENT_ID, true), nonexMap,
1239 client.getItemCommonPartName() );
1240 ClientResponse<MultipartInput> res =
1241 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1242 int statusCode = res.getStatus();
1244 // Check the status code of the response: does it match
1245 // the expected response(s)?
1246 if(logger.isDebugEnabled()){
1247 logger.debug(testName + ": status = " + statusCode);
1249 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1250 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1251 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1254 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1255 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1256 public void updateNonExistentContact(String testName) throws Exception {
1257 // Currently a no-op test
1260 // ---------------------------------------------------------------
1261 // CRUD tests : DELETE tests
1262 // ---------------------------------------------------------------
1265 // Note: delete sub-resources in ascending hierarchical order,
1266 // before deleting their parents.
1268 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1269 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1270 public void deleteContact(String testName) throws Exception {
1273 setupDelete(testName);
1275 if(logger.isDebugEnabled()){
1276 logger.debug("parentcsid =" + knownResourceId +
1277 " itemcsid = " + knownItemResourceId +
1278 " csid = " + knownContactResourceId);
1281 // Submit the request to the service and store the response.
1282 ClientResponse<Response> res =
1283 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1284 int statusCode = res.getStatus();
1286 // Check the status code of the response: does it match
1287 // the expected response(s)?
1288 if(logger.isDebugEnabled()){
1289 logger.debug(testName + ": status = " + statusCode);
1291 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1292 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1293 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1296 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1297 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1298 public void deleteItem(String testName) throws Exception {
1301 setupDelete(testName);
1303 if(logger.isDebugEnabled()){
1304 logger.debug("parentcsid =" + knownResourceId +
1305 " itemcsid = " + knownItemResourceId);
1308 // Submit the request to the service and store the response.
1309 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1310 int statusCode = res.getStatus();
1312 // Check the status code of the response: does it match
1313 // the expected response(s)?
1314 if(logger.isDebugEnabled()){
1315 logger.debug(testName + ": status = " + statusCode);
1317 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1318 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1319 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1323 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1324 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1325 public void delete(String testName) throws Exception {
1328 setupDelete(testName);
1330 if(logger.isDebugEnabled()){
1331 logger.debug("parentcsid =" + knownResourceId);
1334 // Submit the request to the service and store the response.
1335 ClientResponse<Response> res = client.delete(knownResourceId);
1336 int statusCode = res.getStatus();
1338 // Check the status code of the response: does it match
1339 // the expected response(s)?
1340 if(logger.isDebugEnabled()){
1341 logger.debug(testName + ": status = " + statusCode);
1343 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1344 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1345 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1350 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1351 groups = {"delete"}, dependsOnMethods = {"delete"})
1352 public void deleteNonExistent(String testName) throws Exception {
1355 setupDeleteNonExistent(testName);
1357 // Submit the request to the service and store the response.
1358 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1359 int statusCode = res.getStatus();
1361 // Check the status code of the response: does it match
1362 // the expected response(s)?
1363 if(logger.isDebugEnabled()){
1364 logger.debug(testName + ": status = " + statusCode);
1366 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1367 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1368 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1371 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1372 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1373 public void deleteNonExistentItem(String testName) {
1376 setupDeleteNonExistent(testName);
1378 // Submit the request to the service and store the response.
1379 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
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);
1392 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1393 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1394 public void deleteNonExistentContact(String testName) {
1397 setupDeleteNonExistent(testName);
1399 // Submit the request to the service and store the response.
1400 ClientResponse<Response> res =
1401 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1402 int statusCode = res.getStatus();
1404 // Check the status code of the response: does it match
1405 // the expected response(s)?
1406 if(logger.isDebugEnabled()){
1407 logger.debug(testName + ": status = " + statusCode);
1409 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1410 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1411 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1414 // ---------------------------------------------------------------
1415 // Utility tests : tests of code used in tests above
1416 // ---------------------------------------------------------------
1418 * Tests the code for manually submitting data that is used by several
1419 * of the methods above.
1421 @Test(dependsOnMethods = {"create", "read"})
1422 public void testSubmitRequest() {
1424 // Expected status code: 200 OK
1425 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1427 // Submit the request to the service and store the response.
1428 String method = ServiceRequestType.READ.httpMethodName();
1429 String url = getResourceURL(knownResourceId);
1430 int statusCode = submitRequest(method, url);
1432 // Check the status code of the response: does it match
1433 // the expected response(s)?
1434 if(logger.isDebugEnabled()){
1435 logger.debug("testSubmitRequest: url=" + url +
1436 " status=" + statusCode);
1438 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1442 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1443 public void testItemSubmitRequest() {
1445 // Expected status code: 200 OK
1446 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1448 // Submit the request to the service and store the response.
1449 String method = ServiceRequestType.READ.httpMethodName();
1450 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1451 int statusCode = submitRequest(method, url);
1453 // Check the status code of the response: does it match
1454 // the expected response(s)?
1455 if(logger.isDebugEnabled()){
1456 logger.debug("testItemSubmitRequest: url=" + url +
1457 " status=" + statusCode);
1459 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1463 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
1464 public void testContactSubmitRequest() {
1466 // Expected status code: 200 OK
1467 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1469 // Submit the request to the service and store the response.
1470 String method = ServiceRequestType.READ.httpMethodName();
1471 String url = getContactResourceURL(knownResourceId,
1472 knownItemResourceId, knownContactResourceId);
1473 int statusCode = submitRequest(method, url);
1475 // Check the status code of the response: does it match
1476 // the expected response(s)?
1477 if(logger.isDebugEnabled()){
1478 logger.debug("testItemSubmitRequest: url=" + url +
1479 " status=" + statusCode);
1481 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1486 // ---------------------------------------------------------------
1487 // Cleanup of resources created during testing
1488 // ---------------------------------------------------------------
1491 * Deletes all resources created by tests, after all tests have been run.
1493 * This cleanup method will always be run, even if one or more tests fail.
1494 * For this reason, it attempts to remove all resources created
1495 * at any point during testing, even if some of those resources
1496 * may be expected to be deleted by certain tests.
1499 @AfterClass(alwaysRun=true)
1500 public void cleanUp() {
1501 if (logger.isDebugEnabled()) {
1502 logger.debug("Cleaning up temporary resources created for testing ...");
1504 String parentResourceId;
1505 String itemResourceId;
1506 String contactResourceId;
1507 // Clean up contact resources.
1508 parentResourceId = knownResourceId;
1509 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
1510 contactResourceId = entry.getKey();
1511 itemResourceId = entry.getValue();
1512 // Note: Any non-success responses from the delete operation
1513 // below are ignored and not reported.
1514 ClientResponse<Response> res =
1515 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
1517 // Clean up item resources.
1518 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1519 itemResourceId = entry.getKey();
1520 parentResourceId = entry.getValue();
1521 // Note: Any non-success responses from the delete operation
1522 // below are ignored and not reported.
1523 ClientResponse<Response> res =
1524 client.deleteItem(parentResourceId, itemResourceId);
1526 // Clean up parent resources.
1527 for (String resourceId : allResourceIdsCreated) {
1528 // Note: Any non-success responses from the delete operation
1529 // below are ignored and not reported.
1530 ClientResponse<Response> res = client.delete(resourceId);
1534 // ---------------------------------------------------------------
1535 // Utility methods used by tests above
1536 // ---------------------------------------------------------------
1538 public String getServicePathComponent() {
1539 return SERVICE_PATH_COMPONENT;
1542 public String getItemServicePathComponent() {
1543 return ITEM_SERVICE_PATH_COMPONENT;
1546 public String getContactServicePathComponent() {
1547 return CONTACT_SERVICE_PATH_COMPONENT;
1551 * Returns the root URL for the item service.
1553 * This URL consists of a base URL for all services, followed by
1554 * a path component for the owning parent, followed by the
1555 * path component for the items.
1557 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1558 * parent authority resource of the relevant item resource.
1560 * @return The root URL for the item service.
1562 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1563 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1567 * Returns the URL of a specific item resource managed by a service, and
1568 * designated by an identifier (such as a universally unique ID, or UUID).
1570 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1571 * parent authority resource of the relevant item resource.
1573 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1576 * @return The URL of a specific item resource managed by a service.
1578 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1579 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
1584 * Returns the root URL for the contact service.
1586 * This URL consists of a base URL for all services, followed by
1587 * a path component for the owning authority, followed by the
1588 * path component for the owning item, followed by the path component
1589 * for the contact service.
1591 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1592 * parent authority resource of the relevant item resource.
1594 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1597 * @return The root URL for the contact service.
1599 protected String getContactServiceRootURL(String parentResourceIdentifier,
1600 String itemResourceIdentifier) {
1601 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
1602 getContactServicePathComponent();
1606 * Returns the URL of a specific contact resource managed by a service, and
1607 * designated by an identifier (such as a universally unique ID, or UUID).
1609 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1610 * parent resource of the relevant item resource.
1612 * @param resourceIdentifier An identifier (such as a UUID) for an
1615 * @return The URL of a specific resource managed by a service.
1617 protected String getContactResourceURL(String parentResourceIdentifier,
1618 String itemResourceIdentifier, String contactResourceIdentifier) {
1619 return getContactServiceRootURL(parentResourceIdentifier,
1620 itemResourceIdentifier) + "/" + contactResourceIdentifier;