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.OrganizationJAXBSchema;
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.OrgAuthorityClient;
38 import org.collectionspace.services.client.OrgAuthorityClientUtils;
39 import org.collectionspace.services.organization.OrgauthoritiesCommon;
40 import org.collectionspace.services.organization.OrgauthoritiesCommonList;
41 import org.collectionspace.services.organization.OrganizationsCommon;
42 import org.collectionspace.services.organization.OrganizationsCommonList;
44 import org.jboss.resteasy.client.ClientResponse;
45 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
46 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
47 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
50 import org.testng.Assert;
51 import org.testng.annotations.AfterClass;
52 import org.testng.annotations.Test;
55 * OrgAuthorityServiceTest, carries out tests against a
56 * deployed and running OrgAuthority Service.
58 * $LastChangedRevision: 753 $
59 * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
61 public class OrgAuthorityServiceTest extends AbstractServiceTestImpl {
63 private final Logger logger =
64 LoggerFactory.getLogger(OrgAuthorityServiceTest.class);
66 // Instance variables specific to this test.
67 private OrgAuthorityClient client = new OrgAuthorityClient();
68 private ContactClient contactClient = new ContactClient();
69 final String SERVICE_PATH_COMPONENT = "orgauthorities";
70 final String ITEM_SERVICE_PATH_COMPONENT = "items";
71 final String CONTACT_SERVICE_PATH_COMPONENT = "contacts";
72 private final String TEST_ORG_SHORTNAME = "Test Org";
73 private final String TEST_ORG_FOUNDING_PLACE = "Anytown, USA";
74 private String knownResourceId = null;
75 private String knownResourceDisplayName = null;
76 private String knownResourceRefName = null;
77 private String knownItemResourceId = null;
78 private String knownContactResourceId = null;
79 private int nItemsToCreateInList = 3;
80 private List<String> allResourceIdsCreated = new ArrayList<String>();
81 private Map<String, String> allItemResourceIdsCreated =
82 new HashMap<String, String>();
83 private Map<String, String> allContactResourceIdsCreated =
84 new HashMap<String, String>();
86 // ---------------------------------------------------------------
87 // CRUD tests : CREATE tests
88 // ---------------------------------------------------------------
91 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
93 public void create(String testName) throws Exception {
95 // Perform setup, such as initializing the type of service request
96 // (e.g. CREATE, DELETE), its valid and expected status codes, and
97 // its associated HTTP method name (e.g. POST, DELETE).
98 setupCreate(testName);
100 // Submit the request to the service and store the response.
101 String identifier = createIdentifier();
102 String displayName = "displayName-" + identifier;
103 String refName = OrgAuthorityClientUtils.createOrgAuthRefName(displayName, true);
104 MultipartOutput multipart =
105 OrgAuthorityClientUtils.createOrgAuthorityInstance(
106 displayName, refName, client.getCommonPartName());
107 ClientResponse<Response> res = client.create(multipart);
108 int statusCode = res.getStatus();
110 // Check the status code of the response: does it match
111 // the expected response(s)?
114 // Does it fall within the set of valid status codes?
115 // Does it exactly match the expected status code?
116 if(logger.isDebugEnabled()){
117 logger.debug(testName + ": status = " + statusCode);
119 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
120 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
121 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
123 // Store the refname from the first resource created
124 // for additional tests below.
125 knownResourceRefName = refName;
127 String newID = OrgAuthorityClientUtils.extractId(res);
128 // Store the ID returned from the first resource created
129 // for additional tests below.
130 if (knownResourceId == null){
131 knownResourceId = newID;
132 knownResourceDisplayName = displayName;
133 if (logger.isDebugEnabled()) {
134 logger.debug(testName + ": knownResourceId=" + knownResourceId);
137 // Store the IDs from every resource created by tests,
138 // so they can be deleted after tests have been run.
139 allResourceIdsCreated.add(newID);
142 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
143 groups = {"create"}, dependsOnMethods = {"create"})
144 public void createItem(String testName) {
145 setupCreate(testName);
146 String newID = createItemInAuthority(knownResourceId, knownResourceRefName);
149 private String createItemInAuthority(String vcsid, String authRefName) {
151 final String testName = "createItemInAuthority";
152 if(logger.isDebugEnabled()){
153 logger.debug(testName + ":...");
156 // Submit the request to the service and store the response.
157 String identifier = createIdentifier();
158 String refName = OrgAuthorityClientUtils.createOrganizationRefName(knownResourceRefName, identifier, true);
159 Map<String, String> testOrgMap = new HashMap<String,String>();
160 testOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, TEST_ORG_SHORTNAME);
161 testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "The real official test organization");
162 testOrgMap.put(OrganizationJAXBSchema.CONTACT_NAME, "joe@test.org");
163 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "May 26, 1907");
164 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, TEST_ORG_FOUNDING_PLACE);
165 testOrgMap.put(OrganizationJAXBSchema.FUNCTION, "For testing");
166 String newID = OrgAuthorityClientUtils.createItemInAuthority(
167 vcsid, authRefName, testOrgMap, client);
168 // Store the ID returned from the first item resource created
169 // for additional tests below.
170 if (knownItemResourceId == null){
171 knownItemResourceId = newID;
172 if (logger.isDebugEnabled()) {
173 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
177 // Store the IDs from any item resources created
178 // by tests, along with the IDs of their parents, so these items
179 // can be deleted after all tests have been run.
180 allItemResourceIdsCreated.put(newID, vcsid);
185 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
186 groups = {"create"}, dependsOnMethods = {"createItem"})
187 public void createContact(String testName) {
188 setupCreate(testName);
189 String newID = createContactInItem(knownResourceId, knownItemResourceId);
192 private String createContactInItem(String parentcsid, String itemcsid) {
194 final String testName = "createContactInItem";
195 setupCreate(testName);
196 if(logger.isDebugEnabled()){
197 logger.debug(testName + ":...");
200 // Submit the request to the service and store the response.
201 String identifier = createIdentifier();
202 MultipartOutput multipart =
203 ContactClientUtils.createContactInstance(parentcsid,
204 itemcsid, identifier, contactClient.getCommonPartName());
205 ClientResponse<Response> res =
206 client.createContact(parentcsid, itemcsid, multipart);
207 int statusCode = res.getStatus();
208 String newID = OrgAuthorityClientUtils.extractId(res);
210 // Check the status code of the response: does it match
211 // the expected response(s)?
212 if(logger.isDebugEnabled()){
213 logger.debug(testName + ": status = " + statusCode);
215 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
216 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
217 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
219 // Store the ID returned from the first contact resource created
220 // for additional tests below.
221 if (knownContactResourceId == null){
222 knownContactResourceId = newID;
223 if (logger.isDebugEnabled()) {
224 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
228 // Store the IDs from any contact resources created
229 // by tests, along with the IDs of their parent items,
230 // so these items can be deleted after all tests have been run.
231 allContactResourceIdsCreated.put(newID, itemcsid);
238 // Placeholders until the three tests below can be uncommented.
239 // See Issue CSPACE-401.
241 public void createWithEmptyEntityBody(String testName) throws Exception {
245 public void createWithMalformedXml(String testName) throws Exception {
249 public void createWithWrongXmlSchema(String testName) throws Exception {
254 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
255 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
256 public void createWithEmptyEntityBody(String testName) throws Exception {
259 setupCreateWithEmptyEntityBody(testName);
261 // Submit the request to the service and store the response.
262 String method = REQUEST_TYPE.httpMethodName();
263 String url = getServiceRootURL();
264 String mediaType = MediaType.APPLICATION_XML;
265 final String entity = "";
266 int statusCode = submitRequest(method, url, mediaType, entity);
268 // Check the status code of the response: does it match
269 // the expected response(s)?
270 if(logger.isDebugEnabled()) {
271 logger.debug(testName + ": url=" + url +
272 " status=" + statusCode);
274 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
275 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
276 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
280 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
281 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
282 public void createWithMalformedXml(String testName) throws Exception {
285 setupCreateWithMalformedXml(testName);
287 // Submit the request to the service and store the response.
288 String method = REQUEST_TYPE.httpMethodName();
289 String url = getServiceRootURL();
290 String mediaType = MediaType.APPLICATION_XML;
291 final String entity = MALFORMED_XML_DATA; // Constant from base class.
292 int statusCode = submitRequest(method, url, mediaType, entity);
294 // Check the status code of the response: does it match
295 // the expected response(s)?
296 if(logger.isDebugEnabled()){
297 logger.debug(testName + ": url=" + url +
298 " status=" + statusCode);
300 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
301 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
302 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
306 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
307 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
308 public void createWithWrongXmlSchema(String testName) throws Exception {
311 setupCreateWithWrongXmlSchema(testName);
313 // Submit the request to the service and store the response.
314 String method = REQUEST_TYPE.httpMethodName();
315 String url = getServiceRootURL();
316 String mediaType = MediaType.APPLICATION_XML;
317 final String entity = WRONG_XML_SCHEMA_DATA;
318 int statusCode = submitRequest(method, url, mediaType, entity);
320 // Check the status code of the response: does it match
321 // the expected response(s)?
322 if(logger.isDebugEnabled()){
323 logger.debug(testName + ": url=" + url +
324 " status=" + statusCode);
326 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
327 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
328 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
332 // ---------------------------------------------------------------
333 // CRUD tests : CREATE LIST tests
334 // ---------------------------------------------------------------
337 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
338 groups = {"createList"}, dependsOnGroups = {"create"})
339 public void createList(String testName) throws Exception {
340 for (int i = 0; i < nItemsToCreateInList; i++) {
345 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
346 groups = {"createList"}, dependsOnMethods = {"createList"})
347 public void createItemList(String testName) throws Exception {
348 // Add items to the initially-created, known parent record.
349 for (int j = 0; j < nItemsToCreateInList; j++) {
350 createItem(testName);
354 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
355 groups = {"createList"}, dependsOnMethods = {"createItemList"})
356 public void createContactList(String testName) throws Exception {
357 // Add contacts to the initially-created, known item record.
358 for (int j = 0; j < nItemsToCreateInList; j++) {
359 createContact(testName);
363 // ---------------------------------------------------------------
364 // CRUD tests : READ tests
365 // ---------------------------------------------------------------
368 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
369 groups = {"read"}, dependsOnGroups = {"create"})
370 public void read(String testName) throws Exception {
375 // Submit the request to the service and store the response.
376 ClientResponse<MultipartInput> res = client.read(knownResourceId);
377 int statusCode = res.getStatus();
379 // Check the status code of the response: does it match
380 // the expected response(s)?
381 if(logger.isDebugEnabled()){
382 logger.debug(testName + ": status = " + statusCode);
384 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
385 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
386 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
387 //FIXME: remove the following try catch once Aron fixes signatures
389 MultipartInput input = (MultipartInput) res.getEntity();
390 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
391 client.getCommonPartName(), OrgauthoritiesCommon.class);
392 Assert.assertNotNull(orgAuthority);
393 } catch (Exception e) {
394 throw new RuntimeException(e);
398 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
399 groups = {"read"}, dependsOnGroups = {"create"})
400 public void readByName(String testName) throws Exception {
405 // Submit the request to the service and store the response.
406 ClientResponse<MultipartInput> res = client.readByName(knownResourceDisplayName);
407 int statusCode = res.getStatus();
409 // Check the status code of the response: does it match
410 // the expected response(s)?
411 if(logger.isDebugEnabled()){
412 logger.debug(testName + ": status = " + statusCode);
414 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
415 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
416 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
417 //FIXME: remove the following try catch once Aron fixes signatures
419 MultipartInput input = (MultipartInput) res.getEntity();
420 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
421 client.getCommonPartName(), OrgauthoritiesCommon.class);
422 Assert.assertNotNull(orgAuthority);
423 } catch (Exception e) {
424 throw new RuntimeException(e);
429 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
430 groups = {"read"}, dependsOnMethods = {"read"})
431 public void readByName(String testName) throws Exception {
436 // Submit the request to the service and store the response.
437 ClientResponse<MultipartInput> res = client.read(knownResourceId);
438 int statusCode = res.getStatus();
440 // Check the status code of the response: does it match
441 // the expected response(s)?
442 if(logger.isDebugEnabled()){
443 logger.debug(testName + ": status = " + statusCode);
445 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
446 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
447 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
448 //FIXME: remove the following try catch once Aron fixes signatures
450 MultipartInput input = (MultipartInput) res.getEntity();
451 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
452 client.getCommonPartName(), OrgauthoritiesCommon.class);
453 Assert.assertNotNull(orgAuthority);
454 } catch (Exception e) {
455 throw new RuntimeException(e);
460 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
461 groups = {"read"}, dependsOnMethods = {"read"})
462 public void readItem(String testName) throws Exception {
467 // Submit the request to the service and store the response.
468 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
469 int statusCode = res.getStatus();
471 // Check the status code of the response: does it match
472 // the expected response(s)?
473 if(logger.isDebugEnabled()){
474 logger.debug(testName + ": status = " + statusCode);
476 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
477 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
478 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
480 // Check whether we've received a organization.
481 MultipartInput input = (MultipartInput) res.getEntity();
482 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
483 client.getItemCommonPartName(), OrganizationsCommon.class);
484 Assert.assertNotNull(organization);
485 boolean showFull = true;
486 if(showFull && logger.isDebugEnabled()){
487 logger.debug(testName + ": returned payload:");
488 logger.debug(objectAsXmlString(organization,
489 OrganizationsCommon.class));
491 Assert.assertEquals(organization.getInAuthority(), knownResourceId);
494 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
495 dependsOnMethods = {"readItem", "updateItem"})
496 public void verifyItemDisplayName(String testName) throws Exception {
499 setupUpdate(testName);
501 // Submit the request to the service and store the response.
502 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
503 int statusCode = res.getStatus();
505 // Check the status code of the response: does it match
506 // the expected response(s)?
507 if(logger.isDebugEnabled()){
508 logger.debug(testName + ": status = " + statusCode);
510 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
511 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
512 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
514 // Check whether organization has expected displayName.
515 MultipartInput input = (MultipartInput) res.getEntity();
516 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
517 client.getItemCommonPartName(), OrganizationsCommon.class);
518 Assert.assertNotNull(organization);
519 String displayName = organization.getDisplayName();
520 // Make sure displayName matches computed form
521 String expectedDisplayName =
522 OrgAuthorityClientUtils.prepareDefaultDisplayName(
523 TEST_ORG_SHORTNAME, TEST_ORG_FOUNDING_PLACE);
524 Assert.assertNotNull(displayName, expectedDisplayName);
526 // Update the shortName and verify the computed name is updated.
527 organization.setDisplayNameComputed(true);
528 organization.setShortName("updated-" + TEST_ORG_SHORTNAME);
529 expectedDisplayName =
530 OrgAuthorityClientUtils.prepareDefaultDisplayName(
531 "updated-" + TEST_ORG_SHORTNAME, TEST_ORG_FOUNDING_PLACE);
533 // Submit the updated resource to the service and store the response.
534 MultipartOutput output = new MultipartOutput();
535 OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
536 commonPart.getHeaders().add("label", client.getItemCommonPartName());
537 res = client.updateItem(knownResourceId, knownItemResourceId, output);
538 statusCode = res.getStatus();
540 // Check the status code of the response: does it match the expected response(s)?
541 if(logger.isDebugEnabled()){
542 logger.debug("updateItem: status = " + statusCode);
544 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
545 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
546 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
548 // Retrieve the updated resource and verify that its contents exist.
549 input = (MultipartInput) res.getEntity();
550 OrganizationsCommon updatedOrganization =
551 (OrganizationsCommon) extractPart(input,
552 client.getItemCommonPartName(), OrganizationsCommon.class);
553 Assert.assertNotNull(updatedOrganization);
555 // Verify that the updated resource received the correct data.
556 Assert.assertEquals(updatedOrganization.getShortName(), organization.getShortName(),
557 "Updated ShortName in Organization did not match submitted data.");
558 // Verify that the updated resource computes the right displayName.
559 Assert.assertEquals(updatedOrganization.getDisplayName(), expectedDisplayName,
560 "Updated ShortName in Organization not reflected in computed DisplayName.");
562 // Now Update the displayName, not computed and verify the computed name is overriden.
563 organization.setDisplayNameComputed(false);
564 expectedDisplayName = "TestName";
565 organization.setDisplayName(expectedDisplayName);
567 // Submit the updated resource to the service and store the response.
568 output = new MultipartOutput();
569 commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
570 commonPart.getHeaders().add("label", client.getItemCommonPartName());
571 res = client.updateItem(knownResourceId, knownItemResourceId, output);
572 statusCode = res.getStatus();
574 // Check the status code of the response: does it match the expected response(s)?
575 if(logger.isDebugEnabled()){
576 logger.debug("updateItem: status = " + statusCode);
578 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
579 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
580 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
582 // Retrieve the updated resource and verify that its contents exist.
583 input = (MultipartInput) res.getEntity();
584 updatedOrganization =
585 (OrganizationsCommon) extractPart(input,
586 client.getItemCommonPartName(), OrganizationsCommon.class);
587 Assert.assertNotNull(updatedOrganization);
589 // Verify that the updated resource received the correct data.
590 Assert.assertEquals(updatedOrganization.isDisplayNameComputed(), false,
591 "Updated displayNameComputed in Organization did not match submitted data.");
592 // Verify that the updated resource computes the right displayName.
593 Assert.assertEquals(updatedOrganization.getDisplayName(),
595 "Updated DisplayName (not computed) in Organization not stored.");
598 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
599 dependsOnMethods = {"verifyItemDisplayName"})
600 public void verifyIllegalItemDisplayName(String testName) throws Exception {
603 setupUpdateWithWrongXmlSchema(testName);
605 // Submit the request to the service and store the response.
606 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
607 int statusCode = res.getStatus();
609 // Check the status code of the response: does it match
610 // the expected response(s)?
611 if(logger.isDebugEnabled()){
612 logger.debug(testName + ": status = " + statusCode);
614 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
615 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
616 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
618 // Check whether organization has expected displayName.
619 MultipartInput input = (MultipartInput) res.getEntity();
620 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
621 client.getItemCommonPartName(), OrganizationsCommon.class);
622 Assert.assertNotNull(organization);
623 // Try to Update with computed false and no displayName
624 organization.setDisplayNameComputed(false);
625 organization.setDisplayName(null);
627 // Submit the updated resource to the service and store the response.
628 MultipartOutput output = new MultipartOutput();
629 OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
630 commonPart.getHeaders().add("label", client.getItemCommonPartName());
631 res = client.updateItem(knownResourceId, knownItemResourceId, output);
632 statusCode = res.getStatus();
634 // Check the status code of the response: does it match the expected response(s)?
635 if(logger.isDebugEnabled()){
636 logger.debug("updateItem: status = " + statusCode);
638 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
639 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
640 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
643 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
644 groups = {"read"}, dependsOnMethods = {"readItem"})
645 public void readContact(String testName) throws Exception {
650 // Submit the request to the service and store the response.
651 ClientResponse<MultipartInput> res =
652 client.readContact(knownResourceId, knownItemResourceId,
653 knownContactResourceId);
654 int statusCode = res.getStatus();
656 // Check the status code of the response: does it match
657 // the expected response(s)?
658 if(logger.isDebugEnabled()){
659 logger.debug(testName + ": status = " + statusCode);
661 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
662 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
663 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
665 // Check whether we've received a contact.
666 MultipartInput input = (MultipartInput) res.getEntity();
667 ContactsCommon contact = (ContactsCommon) extractPart(input,
668 contactClient.getCommonPartName(), ContactsCommon.class);
669 Assert.assertNotNull(contact);
670 boolean showFull = true;
671 if(showFull && logger.isDebugEnabled()){
672 logger.debug(testName + ": returned payload:");
673 logger.debug(objectAsXmlString(contact, ContactsCommon.class));
675 Assert.assertEquals(contact.getInAuthority(), knownResourceId);
676 Assert.assertEquals(contact.getInItem(), knownItemResourceId);
682 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
683 groups = {"read"}, dependsOnMethods = {"read"})
684 public void readNonExistent(String testName) {
687 setupReadNonExistent(testName);
689 // Submit the request to the service and store the response.
690 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
691 int statusCode = res.getStatus();
693 // Check the status code of the response: does it match
694 // the expected response(s)?
695 if(logger.isDebugEnabled()){
696 logger.debug(testName + ": status = " + statusCode);
698 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
699 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
700 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
703 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
704 groups = {"read"}, dependsOnMethods = {"readItem"})
705 public void readItemNonExistent(String testName) {
708 setupReadNonExistent(testName);
710 // Submit the request to the service and store the response.
711 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
712 int statusCode = res.getStatus();
714 // Check the status code of the response: does it match
715 // the expected response(s)?
716 if(logger.isDebugEnabled()){
717 logger.debug(testName + ": status = " + statusCode);
719 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
720 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
721 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
724 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
725 groups = {"read"}, dependsOnMethods = {"readContact"})
726 public void readContactNonExistent(String testName) {
729 setupReadNonExistent(testName);
731 // Submit the request to the service and store the response.
732 ClientResponse<MultipartInput> res =
733 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
734 int statusCode = res.getStatus();
736 // Check the status code of the response: does it match
737 // the expected response(s)?
738 if(logger.isDebugEnabled()){
739 logger.debug(testName + ": status = " + statusCode);
741 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
742 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
743 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
746 // ---------------------------------------------------------------
747 // CRUD tests : READ_LIST tests
748 // ---------------------------------------------------------------
752 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
753 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
754 public void readList(String testName) throws Exception {
757 setupReadList(testName);
759 // Submit the request to the service and store the response.
760 ClientResponse<OrgauthoritiesCommonList> res = client.readList();
761 OrgauthoritiesCommonList list = res.getEntity();
762 int statusCode = res.getStatus();
764 // Check the status code of the response: does it match
765 // the expected response(s)?
766 if(logger.isDebugEnabled()){
767 logger.debug(testName + ": status = " + statusCode);
769 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
770 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
771 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
773 // Optionally output additional data about list members for debugging.
774 boolean iterateThroughList = false;
775 if (iterateThroughList && logger.isDebugEnabled()) {
776 List<OrgauthoritiesCommonList.OrgauthorityListItem> items =
777 list.getOrgauthorityListItem();
779 for (OrgauthoritiesCommonList.OrgauthorityListItem item : items) {
780 String csid = item.getCsid();
781 logger.debug(testName + ": list-item[" + i + "] csid=" +
783 logger.debug(testName + ": list-item[" + i + "] displayName=" +
784 item.getDisplayName());
785 logger.debug(testName + ": list-item[" + i + "] URI=" +
787 readItemList(csid, null);
793 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
794 public void readItemList() {
795 readItemList(knownResourceId, null);
798 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
799 public void readItemListByAuthorityName() {
800 readItemList(null, knownResourceDisplayName);
803 private void readItemList(String vcsid, String name) {
805 final String testName = "readItemList";
808 setupReadList(testName);
810 // Submit the request to the service and store the response.
811 ClientResponse<OrganizationsCommonList> res = null;
814 // Submit the request to the service and store the response.
815 res = client.readItemList(vcsid);
816 } else if(name!= null) {
817 // Submit the request to the service and store the response.
818 res = client.readItemListForNamedAuthority(name);
820 Assert.fail("readItemList passed null csid and name!");
822 OrganizationsCommonList list = res.getEntity();
823 int statusCode = res.getStatus();
825 // Check the status code of the response: does it match
826 // the expected response(s)?
827 if(logger.isDebugEnabled()){
828 logger.debug(testName + ": status = " + statusCode);
830 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
831 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
832 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
834 List<OrganizationsCommonList.OrganizationListItem> items =
835 list.getOrganizationListItem();
836 int nItemsReturned = items.size();
837 // There will be one item created, associated with a
838 // known parent resource, by the createItem test.
840 // In addition, there will be 'nItemsToCreateInList'
841 // additional items created by the createItemList test,
842 // all associated with the same parent resource.
843 int nExpectedItems = nItemsToCreateInList + 1;
844 if(logger.isDebugEnabled()){
845 logger.debug(testName + ": Expected "
846 + nExpectedItems +" items; got: "+nItemsReturned);
848 Assert.assertEquals(nItemsReturned, nExpectedItems);
851 for (OrganizationsCommonList.OrganizationListItem item : items) {
852 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
853 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
854 // Optionally output additional data about list members for debugging.
855 boolean showDetails = true;
856 if (showDetails && logger.isDebugEnabled()) {
857 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
859 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
861 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
862 item.getDisplayName());
863 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
870 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
871 public void readContactList() {
872 readContactList(knownResourceId, knownItemResourceId);
875 private void readContactList(String parentcsid, String itemcsid) {
876 final String testName = "readContactList";
879 setupReadList(testName);
881 // Submit the request to the service and store the response.
882 ClientResponse<ContactsCommonList> res =
883 client.readContactList(parentcsid, itemcsid);
884 ContactsCommonList list = res.getEntity();
885 int statusCode = res.getStatus();
887 // Check the status code of the response: does it match
888 // the expected response(s)?
889 if(logger.isDebugEnabled()){
890 logger.debug(testName + ": status = " + statusCode);
892 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
893 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
894 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
896 List<ContactsCommonList.ContactListItem> listitems =
897 list.getContactListItem();
898 int nItemsReturned = listitems.size();
899 // There will be one item created, associated with a
900 // known parent resource, by the createItem test.
902 // In addition, there will be 'nItemsToCreateInList'
903 // additional items created by the createItemList test,
904 // all associated with the same parent resource.
905 int nExpectedItems = nItemsToCreateInList + 1;
906 if(logger.isDebugEnabled()){
907 logger.debug(testName + ": Expected "
908 + nExpectedItems +" items; got: "+nItemsReturned);
910 Assert.assertEquals(nItemsReturned, nExpectedItems);
913 for (ContactsCommonList.ContactListItem listitem : listitems) {
914 // Optionally output additional data about list members for debugging.
915 boolean showDetails = false;
916 if (showDetails && logger.isDebugEnabled()) {
917 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
919 logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" +
920 listitem.getAddressPlace());
921 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
931 // ---------------------------------------------------------------
932 // CRUD tests : UPDATE tests
933 // ---------------------------------------------------------------
936 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
937 groups = {"update"}, dependsOnGroups = {"read", "readList"})
938 public void update(String testName) throws Exception {
941 setupUpdate(testName);
943 // Retrieve the contents of a resource to update.
944 ClientResponse<MultipartInput> res =
945 client.read(knownResourceId);
946 if(logger.isDebugEnabled()){
947 logger.debug(testName + ": read status = " + res.getStatus());
949 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
951 if(logger.isDebugEnabled()){
952 logger.debug("got OrgAuthority to update with ID: " + knownResourceId);
954 MultipartInput input = (MultipartInput) res.getEntity();
955 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
956 client.getCommonPartName(), OrgauthoritiesCommon.class);
957 Assert.assertNotNull(orgAuthority);
959 // Update the contents of this resource.
960 orgAuthority.setDisplayName("updated-" + orgAuthority.getDisplayName());
961 orgAuthority.setVocabType("updated-" + orgAuthority.getVocabType());
962 if(logger.isDebugEnabled()){
963 logger.debug("to be updated OrgAuthority");
964 logger.debug(objectAsXmlString(orgAuthority, OrgauthoritiesCommon.class));
967 // Submit the updated resource to the service and store the response.
968 MultipartOutput output = new MultipartOutput();
969 OutputPart commonPart = output.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE);
970 commonPart.getHeaders().add("label", client.getCommonPartName());
971 res = client.update(knownResourceId, output);
972 int statusCode = res.getStatus();
974 // Check the status code of the response: does it match the expected response(s)?
975 if(logger.isDebugEnabled()){
976 logger.debug(testName + ": status = " + statusCode);
978 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
979 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
980 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
982 // Retrieve the updated resource and verify that its contents exist.
983 input = (MultipartInput) res.getEntity();
984 OrgauthoritiesCommon updatedOrgAuthority =
985 (OrgauthoritiesCommon) extractPart(input,
986 client.getCommonPartName(), OrgauthoritiesCommon.class);
987 Assert.assertNotNull(updatedOrgAuthority);
989 // Verify that the updated resource received the correct data.
990 Assert.assertEquals(updatedOrgAuthority.getDisplayName(),
991 orgAuthority.getDisplayName(),
992 "Data in updated object did not match submitted data.");
995 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
996 groups = {"update"}, dependsOnMethods = {"update"})
997 public void updateItem(String testName) throws Exception {
1000 setupUpdate(testName);
1002 ClientResponse<MultipartInput> res =
1003 client.readItem(knownResourceId, knownItemResourceId);
1004 if(logger.isDebugEnabled()){
1005 logger.debug(testName + ": read status = " + res.getStatus());
1007 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1009 if(logger.isDebugEnabled()){
1010 logger.debug("got Organization to update with ID: " +
1011 knownItemResourceId +
1012 " in OrgAuthority: " + knownResourceId );
1014 MultipartInput input = (MultipartInput) res.getEntity();
1015 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
1016 client.getItemCommonPartName(), OrganizationsCommon.class);
1017 Assert.assertNotNull(organization);
1019 // Update the contents of this resource.
1020 organization.setShortName("updated-" + organization.getShortName());
1021 if(logger.isDebugEnabled()){
1022 logger.debug("to be updated Organization");
1023 logger.debug(objectAsXmlString(organization,
1024 OrganizationsCommon.class));
1027 // Submit the updated resource to the service and store the response.
1028 MultipartOutput output = new MultipartOutput();
1029 OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
1030 commonPart.getHeaders().add("label", client.getItemCommonPartName());
1031 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1032 int statusCode = res.getStatus();
1034 // Check the status code of the response: does it match the expected response(s)?
1035 if(logger.isDebugEnabled()){
1036 logger.debug(testName + ": status = " + statusCode);
1038 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1039 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1040 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1042 // Retrieve the updated resource and verify that its contents exist.
1043 input = (MultipartInput) res.getEntity();
1044 OrganizationsCommon updatedOrganization =
1045 (OrganizationsCommon) extractPart(input,
1046 client.getItemCommonPartName(), OrganizationsCommon.class);
1047 Assert.assertNotNull(updatedOrganization);
1049 // Verify that the updated resource received the correct data.
1050 Assert.assertEquals(updatedOrganization.getShortName(),
1051 organization.getShortName(),
1052 "Data in updated Organization did not match submitted data.");
1055 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1056 groups = {"update"}, dependsOnMethods = {"updateItem"})
1057 public void updateContact(String testName) throws Exception {
1060 setupUpdate(testName);
1062 ClientResponse<MultipartInput> res =
1063 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1064 if(logger.isDebugEnabled()){
1065 logger.debug(testName + ": read status = " + res.getStatus());
1067 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1069 if(logger.isDebugEnabled()){
1070 logger.debug("got Contact to update with ID: " +
1071 knownContactResourceId +
1072 " in item: " + knownItemResourceId +
1073 " in parent: " + knownResourceId );
1075 MultipartInput input = (MultipartInput) res.getEntity();
1076 ContactsCommon contact = (ContactsCommon) extractPart(input,
1077 contactClient.getCommonPartName(), ContactsCommon.class);
1078 Assert.assertNotNull(contact);
1080 // Update the contents of this resource.
1081 contact.setAddressPlace("updated-" + contact.getAddressPlace());
1082 if(logger.isDebugEnabled()){
1083 logger.debug("to be updated Contact");
1084 logger.debug(objectAsXmlString(contact,
1085 ContactsCommon.class));
1088 // Submit the updated resource to the service and store the response.
1089 MultipartOutput output = new MultipartOutput();
1090 OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1091 commonPart.getHeaders().add("label", contactClient.getCommonPartName());
1092 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1093 int statusCode = res.getStatus();
1095 // Check the status code of the response: does it match the expected response(s)?
1096 if(logger.isDebugEnabled()){
1097 logger.debug(testName + ": status = " + statusCode);
1099 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1100 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1101 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1103 // Retrieve the updated resource and verify that its contents exist.
1104 input = (MultipartInput) res.getEntity();
1105 ContactsCommon updatedContact =
1106 (ContactsCommon) extractPart(input,
1107 contactClient.getCommonPartName(), ContactsCommon.class);
1108 Assert.assertNotNull(updatedContact);
1110 // Verify that the updated resource received the correct data.
1111 Assert.assertEquals(updatedContact.getAddressPlace(),
1112 contact.getAddressPlace(),
1113 "Data in updated Contact did not match submitted data.");
1117 // Placeholders until the three tests below can be uncommented.
1118 // See Issue CSPACE-401.
1120 public void updateWithEmptyEntityBody(String testName) throws Exception {
1124 public void updateWithMalformedXml(String testName) throws Exception {
1128 public void updateWithWrongXmlSchema(String testName) throws Exception {
1133 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1134 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1135 public void updateWithEmptyEntityBody(String testName) throws Exception {
1138 setupUpdateWithEmptyEntityBody(testName);
1140 // Submit the request to the service and store the response.
1141 String method = REQUEST_TYPE.httpMethodName();
1142 String url = getResourceURL(knownResourceId);
1143 String mediaType = MediaType.APPLICATION_XML;
1144 final String entity = "";
1145 int statusCode = submitRequest(method, url, mediaType, entity);
1147 // Check the status code of the response: does it match
1148 // the expected response(s)?
1149 if(logger.isDebugEnabled()){
1150 logger.debug(testName + ": url=" + url +
1151 " status=" + statusCode);
1153 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1154 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1155 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1159 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1160 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1161 public void updateWithMalformedXml(String testName) throws Exception {
1164 setupUpdateWithMalformedXml(testName);
1166 // Submit the request to the service and store the response.
1167 String method = REQUEST_TYPE.httpMethodName();
1168 String url = getResourceURL(knownResourceId);
1169 String mediaType = MediaType.APPLICATION_XML;
1170 final String entity = MALFORMED_XML_DATA;
1171 int statusCode = submitRequest(method, url, mediaType, entity);
1173 // Check the status code of the response: does it match
1174 // the expected response(s)?
1175 if(logger.isDebugEnabled()){
1176 logger.debug(testName + ": url=" + url +
1177 " status=" + statusCode);
1179 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1180 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1181 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1185 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1186 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1187 public void updateWithWrongXmlSchema(String testName) throws Exception {
1190 setupUpdateWithWrongXmlSchema(testName);
1192 // Submit the request to the service and store the response.
1193 String method = REQUEST_TYPE.httpMethodName();
1194 String url = getResourceURL(knownResourceId);
1195 String mediaType = MediaType.APPLICATION_XML;
1196 final String entity = WRONG_XML_SCHEMA_DATA;
1197 int statusCode = submitRequest(method, url, mediaType, entity);
1199 // Check the status code of the response: does it match
1200 // the expected response(s)?
1201 if(logger.isDebugEnabled()){
1202 logger.debug("updateWithWrongXmlSchema: url=" + url +
1203 " status=" + statusCode);
1205 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1206 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1207 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1212 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1213 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1214 public void updateNonExistent(String testName) throws Exception {
1217 setupUpdateNonExistent(testName);
1219 // Submit the request to the service and store the response.
1220 // Note: The ID used in this 'create' call may be arbitrary.
1221 // The only relevant ID may be the one used in update(), below.
1222 MultipartOutput multipart = createOrgAuthorityInstance(NON_EXISTENT_ID);
1223 ClientResponse<MultipartInput> res =
1224 client.update(NON_EXISTENT_ID, multipart);
1225 int statusCode = res.getStatus();
1227 // Check the status code of the response: does it match
1228 // the expected response(s)?
1229 if(logger.isDebugEnabled()){
1230 logger.debug(testName + ": status = " + statusCode);
1232 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1233 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1234 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1237 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1238 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1239 public void updateNonExistentItem(String testName) throws Exception {
1242 setupUpdateNonExistent(testName);
1244 // Submit the request to the service and store the response.
1245 // Note: The ID(s) used when creating the request payload may be arbitrary.
1246 // The only relevant ID may be the one used in update(), below.
1247 Map<String, String> nonexOrgMap = new HashMap<String,String>();
1248 nonexOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Non-existent");
1249 String refName = OrgAuthorityClientUtils.createOrganizationRefName(knownResourceRefName, NON_EXISTENT_ID, true);
1250 MultipartOutput multipart =
1251 OrgAuthorityClientUtils.createOrganizationInstance(
1252 NON_EXISTENT_ID, refName,
1253 nonexOrgMap, client.getItemCommonPartName() );
1254 ClientResponse<MultipartInput> res =
1255 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1256 int statusCode = res.getStatus();
1258 // Check the status code of the response: does it match
1259 // the expected response(s)?
1260 if(logger.isDebugEnabled()){
1261 logger.debug(testName + ": status = " + statusCode);
1263 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1264 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1265 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1268 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1269 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1270 public void updateNonExistentContact(String testName) throws Exception {
1271 // Currently a no-op test
1274 // ---------------------------------------------------------------
1275 // CRUD tests : DELETE tests
1276 // ---------------------------------------------------------------
1279 // Note: delete sub-resources in ascending hierarchical order,
1280 // before deleting their parents.
1282 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1283 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1284 public void deleteContact(String testName) throws Exception {
1287 setupDelete(testName);
1289 if(logger.isDebugEnabled()){
1290 logger.debug("parentcsid =" + knownResourceId +
1291 " itemcsid = " + knownItemResourceId +
1292 " csid = " + knownContactResourceId);
1295 // Submit the request to the service and store the response.
1296 ClientResponse<Response> res =
1297 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1298 int statusCode = res.getStatus();
1300 // Check the status code of the response: does it match
1301 // the expected response(s)?
1302 if(logger.isDebugEnabled()){
1303 logger.debug(testName + ": status = " + statusCode);
1305 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1306 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1307 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1310 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1311 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1312 public void deleteItem(String testName) throws Exception {
1315 setupDelete(testName);
1317 if(logger.isDebugEnabled()){
1318 logger.debug("parentcsid =" + knownResourceId +
1319 " itemcsid = " + knownItemResourceId);
1322 // Submit the request to the service and store the response.
1323 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1324 int statusCode = res.getStatus();
1326 // Check the status code of the response: does it match
1327 // the expected response(s)?
1328 if(logger.isDebugEnabled()){
1329 logger.debug(testName + ": status = " + statusCode);
1331 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1332 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1333 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1337 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1338 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1339 public void delete(String testName) throws Exception {
1342 setupDelete(testName);
1344 if(logger.isDebugEnabled()){
1345 logger.debug("parentcsid =" + knownResourceId);
1348 // Submit the request to the service and store the response.
1349 ClientResponse<Response> res = client.delete(knownResourceId);
1350 int statusCode = res.getStatus();
1352 // Check the status code of the response: does it match
1353 // the expected response(s)?
1354 if(logger.isDebugEnabled()){
1355 logger.debug(testName + ": status = " + statusCode);
1357 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1358 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1359 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1364 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1365 groups = {"delete"}, dependsOnMethods = {"delete"})
1366 public void deleteNonExistent(String testName) throws Exception {
1369 setupDeleteNonExistent(testName);
1371 // Submit the request to the service and store the response.
1372 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1373 int statusCode = res.getStatus();
1375 // Check the status code of the response: does it match
1376 // the expected response(s)?
1377 if(logger.isDebugEnabled()){
1378 logger.debug(testName + ": status = " + statusCode);
1380 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1381 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1382 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1385 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1386 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1387 public void deleteNonExistentItem(String testName) {
1390 setupDeleteNonExistent(testName);
1392 // Submit the request to the service and store the response.
1393 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1394 int statusCode = res.getStatus();
1396 // Check the status code of the response: does it match
1397 // the expected response(s)?
1398 if(logger.isDebugEnabled()){
1399 logger.debug(testName + ": status = " + statusCode);
1401 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1402 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1403 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1406 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1407 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1408 public void deleteNonExistentContact(String testName) {
1411 setupDeleteNonExistent(testName);
1413 // Submit the request to the service and store the response.
1414 ClientResponse<Response> res =
1415 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1416 int statusCode = res.getStatus();
1418 // Check the status code of the response: does it match
1419 // the expected response(s)?
1420 if(logger.isDebugEnabled()){
1421 logger.debug(testName + ": status = " + statusCode);
1423 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1424 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1425 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1428 // ---------------------------------------------------------------
1429 // Utility tests : tests of code used in tests above
1430 // ---------------------------------------------------------------
1432 * Tests the code for manually submitting data that is used by several
1433 * of the methods above.
1435 @Test(dependsOnMethods = {"create", "read"})
1436 public void testSubmitRequest() {
1438 // Expected status code: 200 OK
1439 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1441 // Submit the request to the service and store the response.
1442 String method = ServiceRequestType.READ.httpMethodName();
1443 String url = getResourceURL(knownResourceId);
1444 int statusCode = submitRequest(method, url);
1446 // Check the status code of the response: does it match
1447 // the expected response(s)?
1448 if(logger.isDebugEnabled()){
1449 logger.debug("testSubmitRequest: url=" + url +
1450 " status=" + statusCode);
1452 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1456 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1457 public void testItemSubmitRequest() {
1459 // Expected status code: 200 OK
1460 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1462 // Submit the request to the service and store the response.
1463 String method = ServiceRequestType.READ.httpMethodName();
1464 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1465 int statusCode = submitRequest(method, url);
1467 // Check the status code of the response: does it match
1468 // the expected response(s)?
1469 if(logger.isDebugEnabled()){
1470 logger.debug("testItemSubmitRequest: url=" + url +
1471 " status=" + statusCode);
1473 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1477 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
1478 public void testContactSubmitRequest() {
1480 // Expected status code: 200 OK
1481 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1483 // Submit the request to the service and store the response.
1484 String method = ServiceRequestType.READ.httpMethodName();
1485 String url = getContactResourceURL(knownResourceId,
1486 knownItemResourceId, knownContactResourceId);
1487 int statusCode = submitRequest(method, url);
1489 // Check the status code of the response: does it match
1490 // the expected response(s)?
1491 if(logger.isDebugEnabled()){
1492 logger.debug("testItemSubmitRequest: url=" + url +
1493 " status=" + statusCode);
1495 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1500 // ---------------------------------------------------------------
1501 // Cleanup of resources created during testing
1502 // ---------------------------------------------------------------
1505 * Deletes all resources created by tests, after all tests have been run.
1507 * This cleanup method will always be run, even if one or more tests fail.
1508 * For this reason, it attempts to remove all resources created
1509 * at any point during testing, even if some of those resources
1510 * may be expected to be deleted by certain tests.
1513 @AfterClass(alwaysRun=true)
1514 public void cleanUp() {
1515 if (logger.isDebugEnabled()) {
1516 logger.debug("Cleaning up temporary resources created for testing ...");
1518 String parentResourceId;
1519 String itemResourceId;
1520 String contactResourceId;
1521 // Clean up contact resources.
1522 parentResourceId = knownResourceId;
1523 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
1524 contactResourceId = entry.getKey();
1525 itemResourceId = entry.getValue();
1526 // Note: Any non-success responses from the delete operation
1527 // below are ignored and not reported.
1528 ClientResponse<Response> res =
1529 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
1531 // Clean up item resources.
1532 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1533 itemResourceId = entry.getKey();
1534 parentResourceId = entry.getValue();
1535 // Note: Any non-success responses from the delete operation
1536 // below are ignored and not reported.
1537 ClientResponse<Response> res =
1538 client.deleteItem(parentResourceId, itemResourceId);
1540 // Clean up parent resources.
1541 for (String resourceId : allResourceIdsCreated) {
1542 // Note: Any non-success responses from the delete operation
1543 // below are ignored and not reported.
1544 ClientResponse<Response> res = client.delete(resourceId);
1548 // ---------------------------------------------------------------
1549 // Utility methods used by tests above
1550 // ---------------------------------------------------------------
1552 public String getServicePathComponent() {
1553 return SERVICE_PATH_COMPONENT;
1556 public String getItemServicePathComponent() {
1557 return ITEM_SERVICE_PATH_COMPONENT;
1560 public String getContactServicePathComponent() {
1561 return CONTACT_SERVICE_PATH_COMPONENT;
1565 * Returns the root URL for the item service.
1567 * This URL consists of a base URL for all services, followed by
1568 * a path component for the owning parent, followed by the
1569 * path component for the items.
1571 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1572 * parent authority resource of the relevant item resource.
1574 * @return The root URL for the item service.
1576 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1577 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1581 * Returns the URL of a specific item resource managed by a service, and
1582 * designated by an identifier (such as a universally unique ID, or UUID).
1584 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1585 * parent authority resource of the relevant item resource.
1587 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1590 * @return The URL of a specific item resource managed by a service.
1592 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1593 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
1598 * Returns the root URL for the contact service.
1600 * This URL consists of a base URL for all services, followed by
1601 * a path component for the owning authority, followed by the
1602 * path component for the owning item, followed by the path component
1603 * for the contact service.
1605 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1606 * parent authority resource of the relevant item resource.
1608 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1611 * @return The root URL for the contact service.
1613 protected String getContactServiceRootURL(String parentResourceIdentifier,
1614 String itemResourceIdentifier) {
1615 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
1616 getContactServicePathComponent();
1620 * Returns the URL of a specific contact resource managed by a service, and
1621 * designated by an identifier (such as a universally unique ID, or UUID).
1623 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1624 * parent resource of the relevant item resource.
1626 * @param resourceIdentifier An identifier (such as a UUID) for an
1629 * @return The URL of a specific resource managed by a service.
1631 protected String getContactResourceURL(String parentResourceIdentifier,
1632 String itemResourceIdentifier, String contactResourceIdentifier) {
1633 return getContactServiceRootURL(parentResourceIdentifier,
1634 itemResourceIdentifier) + "/" + contactResourceIdentifier;
1637 private MultipartOutput createOrgAuthorityInstance(String identifier) {
1638 String displayName = "displayName-" + identifier;
1639 String refName = OrgAuthorityClientUtils.createOrgAuthRefName(displayName, true);
1640 return OrgAuthorityClientUtils.createOrgAuthorityInstance(
1641 displayName, refName,
1642 client.getCommonPartName());