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 knownResourceRefName = null;
76 private String knownItemResourceId = null;
77 private String knownContactResourceId = null;
78 private int nItemsToCreateInList = 3;
79 private List<String> allResourceIdsCreated = new ArrayList<String>();
80 private Map<String, String> allItemResourceIdsCreated =
81 new HashMap<String, String>();
82 private Map<String, String> allContactResourceIdsCreated =
83 new HashMap<String, String>();
85 // ---------------------------------------------------------------
86 // CRUD tests : CREATE tests
87 // ---------------------------------------------------------------
90 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
92 public void create(String testName) throws Exception {
94 // Perform setup, such as initializing the type of service request
95 // (e.g. CREATE, DELETE), its valid and expected status codes, and
96 // its associated HTTP method name (e.g. POST, DELETE).
97 setupCreate(testName);
99 // Submit the request to the service and store the response.
100 String identifier = createIdentifier();
101 String displayName = "displayName-" + identifier;
102 String refName = OrgAuthorityClientUtils.createOrgAuthRefName(displayName, true);
103 MultipartOutput multipart =
104 OrgAuthorityClientUtils.createOrgAuthorityInstance(
105 displayName, refName, client.getCommonPartName());
106 ClientResponse<Response> res = client.create(multipart);
107 int statusCode = res.getStatus();
109 // Check the status code of the response: does it match
110 // the expected response(s)?
113 // Does it fall within the set of valid status codes?
114 // Does it exactly match the expected status code?
115 if(logger.isDebugEnabled()){
116 logger.debug(testName + ": status = " + statusCode);
118 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
119 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
120 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
122 // Store the refname from the first resource created
123 // for additional tests below.
124 knownResourceRefName = refName;
126 String newID = OrgAuthorityClientUtils.extractId(res);
127 // Store the ID returned from the first resource created
128 // for additional tests below.
129 if (knownResourceId == null){
130 knownResourceId = newID;
131 if (logger.isDebugEnabled()) {
132 logger.debug(testName + ": knownResourceId=" + knownResourceId);
135 // Store the IDs from every resource created by tests,
136 // so they can be deleted after tests have been run.
137 allResourceIdsCreated.add(newID);
140 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
141 groups = {"create"}, dependsOnMethods = {"create"})
142 public void createItem(String testName) {
143 setupCreate(testName);
144 String newID = createItemInAuthority(knownResourceId, knownResourceRefName);
147 private String createItemInAuthority(String vcsid, String authRefName) {
149 final String testName = "createItemInAuthority";
150 if(logger.isDebugEnabled()){
151 logger.debug(testName + ":...");
154 // Submit the request to the service and store the response.
155 String identifier = createIdentifier();
156 String refName = OrgAuthorityClientUtils.createOrganizationRefName(knownResourceRefName, identifier, true);
157 Map<String, String> testOrgMap = new HashMap<String,String>();
158 testOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, TEST_ORG_SHORTNAME);
159 testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "The real official test organization");
160 testOrgMap.put(OrganizationJAXBSchema.CONTACT_NAME, "joe@test.org");
161 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "May 26, 1907");
162 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, TEST_ORG_FOUNDING_PLACE);
163 testOrgMap.put(OrganizationJAXBSchema.FUNCTION, "For testing");
164 String newID = OrgAuthorityClientUtils.createItemInAuthority(
165 vcsid, authRefName, testOrgMap, client);
166 // Store the ID returned from the first item resource created
167 // for additional tests below.
168 if (knownItemResourceId == null){
169 knownItemResourceId = newID;
170 if (logger.isDebugEnabled()) {
171 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
175 // Store the IDs from any item resources created
176 // by tests, along with the IDs of their parents, so these items
177 // can be deleted after all tests have been run.
178 allItemResourceIdsCreated.put(newID, vcsid);
183 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
184 groups = {"create"}, dependsOnMethods = {"createItem"})
185 public void createContact(String testName) {
186 setupCreate(testName);
187 String newID = createContactInItem(knownResourceId, knownItemResourceId);
190 private String createContactInItem(String parentcsid, String itemcsid) {
192 final String testName = "createContactInItem";
193 setupCreate(testName);
194 if(logger.isDebugEnabled()){
195 logger.debug(testName + ":...");
198 // Submit the request to the service and store the response.
199 String identifier = createIdentifier();
200 MultipartOutput multipart =
201 ContactClientUtils.createContactInstance(parentcsid,
202 itemcsid, identifier, contactClient.getCommonPartName());
203 ClientResponse<Response> res =
204 client.createContact(parentcsid, itemcsid, multipart);
205 int statusCode = res.getStatus();
206 String newID = OrgAuthorityClientUtils.extractId(res);
208 // Check the status code of the response: does it match
209 // the expected response(s)?
210 if(logger.isDebugEnabled()){
211 logger.debug(testName + ": status = " + statusCode);
213 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
214 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
215 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
217 // Store the ID returned from the first contact resource created
218 // for additional tests below.
219 if (knownContactResourceId == null){
220 knownContactResourceId = newID;
221 if (logger.isDebugEnabled()) {
222 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
226 // Store the IDs from any contact resources created
227 // by tests, along with the IDs of their parent items,
228 // so these items can be deleted after all tests have been run.
229 allContactResourceIdsCreated.put(newID, itemcsid);
236 // Placeholders until the three tests below can be uncommented.
237 // See Issue CSPACE-401.
239 public void createWithEmptyEntityBody(String testName) throws Exception {
243 public void createWithMalformedXml(String testName) throws Exception {
247 public void createWithWrongXmlSchema(String testName) throws Exception {
252 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
253 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
254 public void createWithEmptyEntityBody(String testName) throws Exception {
257 setupCreateWithEmptyEntityBody(testName);
259 // Submit the request to the service and store the response.
260 String method = REQUEST_TYPE.httpMethodName();
261 String url = getServiceRootURL();
262 String mediaType = MediaType.APPLICATION_XML;
263 final String entity = "";
264 int statusCode = submitRequest(method, url, mediaType, entity);
266 // Check the status code of the response: does it match
267 // the expected response(s)?
268 if(logger.isDebugEnabled()) {
269 logger.debug(testName + ": url=" + url +
270 " status=" + statusCode);
272 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
273 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
274 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
278 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
279 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
280 public void createWithMalformedXml(String testName) throws Exception {
283 setupCreateWithMalformedXml(testName);
285 // Submit the request to the service and store the response.
286 String method = REQUEST_TYPE.httpMethodName();
287 String url = getServiceRootURL();
288 String mediaType = MediaType.APPLICATION_XML;
289 final String entity = MALFORMED_XML_DATA; // Constant from base class.
290 int statusCode = submitRequest(method, url, mediaType, entity);
292 // Check the status code of the response: does it match
293 // the expected response(s)?
294 if(logger.isDebugEnabled()){
295 logger.debug(testName + ": url=" + url +
296 " status=" + statusCode);
298 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
299 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
300 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
304 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
305 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
306 public void createWithWrongXmlSchema(String testName) throws Exception {
309 setupCreateWithWrongXmlSchema(testName);
311 // Submit the request to the service and store the response.
312 String method = REQUEST_TYPE.httpMethodName();
313 String url = getServiceRootURL();
314 String mediaType = MediaType.APPLICATION_XML;
315 final String entity = WRONG_XML_SCHEMA_DATA;
316 int statusCode = submitRequest(method, url, mediaType, entity);
318 // Check the status code of the response: does it match
319 // the expected response(s)?
320 if(logger.isDebugEnabled()){
321 logger.debug(testName + ": url=" + url +
322 " status=" + statusCode);
324 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
325 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
326 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
330 // ---------------------------------------------------------------
331 // CRUD tests : CREATE LIST tests
332 // ---------------------------------------------------------------
335 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
336 groups = {"createList"}, dependsOnGroups = {"create"})
337 public void createList(String testName) throws Exception {
338 for (int i = 0; i < nItemsToCreateInList; i++) {
343 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
344 groups = {"createList"}, dependsOnMethods = {"createList"})
345 public void createItemList(String testName) throws Exception {
346 // Add items to the initially-created, known parent record.
347 for (int j = 0; j < nItemsToCreateInList; j++) {
348 createItem(testName);
352 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
353 groups = {"createList"}, dependsOnMethods = {"createItemList"})
354 public void createContactList(String testName) throws Exception {
355 // Add contacts to the initially-created, known item record.
356 for (int j = 0; j < nItemsToCreateInList; j++) {
357 createContact(testName);
361 // ---------------------------------------------------------------
362 // CRUD tests : READ tests
363 // ---------------------------------------------------------------
366 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
367 groups = {"read"}, dependsOnGroups = {"create"})
368 public void read(String testName) throws Exception {
373 // Submit the request to the service and store the response.
374 ClientResponse<MultipartInput> res = client.read(knownResourceId);
375 int statusCode = res.getStatus();
377 // Check the status code of the response: does it match
378 // the expected response(s)?
379 if(logger.isDebugEnabled()){
380 logger.debug(testName + ": status = " + statusCode);
382 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
383 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
384 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
385 //FIXME: remove the following try catch once Aron fixes signatures
387 MultipartInput input = (MultipartInput) res.getEntity();
388 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
389 client.getCommonPartName(), OrgauthoritiesCommon.class);
390 Assert.assertNotNull(orgAuthority);
391 } catch (Exception e) {
392 throw new RuntimeException(e);
397 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
398 groups = {"read"}, dependsOnMethods = {"read"})
399 public void readByName(String testName) throws Exception {
404 // Submit the request to the service and store the response.
405 ClientResponse<MultipartInput> res = client.read(knownResourceId);
406 int statusCode = res.getStatus();
408 // Check the status code of the response: does it match
409 // the expected response(s)?
410 if(logger.isDebugEnabled()){
411 logger.debug(testName + ": status = " + statusCode);
413 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
414 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
415 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
416 //FIXME: remove the following try catch once Aron fixes signatures
418 MultipartInput input = (MultipartInput) res.getEntity();
419 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
420 client.getCommonPartName(), OrgauthoritiesCommon.class);
421 Assert.assertNotNull(orgAuthority);
422 } catch (Exception e) {
423 throw new RuntimeException(e);
428 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
429 groups = {"read"}, dependsOnMethods = {"read"})
430 public void readItem(String testName) throws Exception {
435 // Submit the request to the service and store the response.
436 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
437 int statusCode = res.getStatus();
439 // Check the status code of the response: does it match
440 // the expected response(s)?
441 if(logger.isDebugEnabled()){
442 logger.debug(testName + ": status = " + statusCode);
444 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
445 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
446 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
448 // Check whether we've received a organization.
449 MultipartInput input = (MultipartInput) res.getEntity();
450 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
451 client.getItemCommonPartName(), OrganizationsCommon.class);
452 Assert.assertNotNull(organization);
453 boolean showFull = true;
454 if(showFull && logger.isDebugEnabled()){
455 logger.debug(testName + ": returned payload:");
456 logger.debug(objectAsXmlString(organization,
457 OrganizationsCommon.class));
459 Assert.assertEquals(organization.getInAuthority(), knownResourceId);
462 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
463 dependsOnMethods = {"readItem", "updateItem"})
464 public void verifyItemDisplayName(String testName) throws Exception {
467 setupUpdate(testName);
469 // Submit the request to the service and store the response.
470 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
471 int statusCode = res.getStatus();
473 // Check the status code of the response: does it match
474 // the expected response(s)?
475 if(logger.isDebugEnabled()){
476 logger.debug(testName + ": status = " + statusCode);
478 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
479 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
480 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
482 // Check whether organization has expected displayName.
483 MultipartInput input = (MultipartInput) res.getEntity();
484 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
485 client.getItemCommonPartName(), OrganizationsCommon.class);
486 Assert.assertNotNull(organization);
487 String displayName = organization.getDisplayName();
488 // Make sure displayName matches computed form
489 String expectedDisplayName =
490 OrgAuthorityClientUtils.prepareDefaultDisplayName(
491 TEST_ORG_SHORTNAME, TEST_ORG_FOUNDING_PLACE);
492 Assert.assertNotNull(displayName, expectedDisplayName);
494 // Update the shortName and verify the computed name is updated.
495 organization.setDisplayNameComputed(true);
496 organization.setShortName("updated-" + TEST_ORG_SHORTNAME);
497 expectedDisplayName =
498 OrgAuthorityClientUtils.prepareDefaultDisplayName(
499 "updated-" + TEST_ORG_SHORTNAME, TEST_ORG_FOUNDING_PLACE);
501 // Submit the updated resource to the service and store the response.
502 MultipartOutput output = new MultipartOutput();
503 OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
504 commonPart.getHeaders().add("label", client.getItemCommonPartName());
505 res = client.updateItem(knownResourceId, knownItemResourceId, output);
506 statusCode = res.getStatus();
508 // Check the status code of the response: does it match the expected response(s)?
509 if(logger.isDebugEnabled()){
510 logger.debug("updateItem: status = " + statusCode);
512 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
513 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
514 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
516 // Retrieve the updated resource and verify that its contents exist.
517 input = (MultipartInput) res.getEntity();
518 OrganizationsCommon updatedOrganization =
519 (OrganizationsCommon) extractPart(input,
520 client.getItemCommonPartName(), OrganizationsCommon.class);
521 Assert.assertNotNull(updatedOrganization);
523 // Verify that the updated resource received the correct data.
524 Assert.assertEquals(updatedOrganization.getShortName(), organization.getShortName(),
525 "Updated ShortName in Organization did not match submitted data.");
526 // Verify that the updated resource computes the right displayName.
527 Assert.assertEquals(updatedOrganization.getDisplayName(), expectedDisplayName,
528 "Updated ShortName in Organization not reflected in computed DisplayName.");
530 // Now Update the displayName, not computed and verify the computed name is overriden.
531 organization.setDisplayNameComputed(false);
532 expectedDisplayName = "TestName";
533 organization.setDisplayName(expectedDisplayName);
535 // Submit the updated resource to the service and store the response.
536 output = new MultipartOutput();
537 commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
538 commonPart.getHeaders().add("label", client.getItemCommonPartName());
539 res = client.updateItem(knownResourceId, knownItemResourceId, output);
540 statusCode = res.getStatus();
542 // Check the status code of the response: does it match the expected response(s)?
543 if(logger.isDebugEnabled()){
544 logger.debug("updateItem: status = " + statusCode);
546 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
547 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
548 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
550 // Retrieve the updated resource and verify that its contents exist.
551 input = (MultipartInput) res.getEntity();
552 updatedOrganization =
553 (OrganizationsCommon) extractPart(input,
554 client.getItemCommonPartName(), OrganizationsCommon.class);
555 Assert.assertNotNull(updatedOrganization);
557 // Verify that the updated resource received the correct data.
558 Assert.assertEquals(updatedOrganization.isDisplayNameComputed(), false,
559 "Updated displayNameComputed in Organization did not match submitted data.");
560 // Verify that the updated resource computes the right displayName.
561 Assert.assertEquals(updatedOrganization.getDisplayName(),
563 "Updated DisplayName (not computed) in Organization not stored.");
566 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
567 dependsOnMethods = {"verifyItemDisplayName"})
568 public void verifyIllegalItemDisplayName(String testName) throws Exception {
571 setupUpdateWithWrongXmlSchema(testName);
573 // Submit the request to the service and store the response.
574 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
575 int statusCode = res.getStatus();
577 // Check the status code of the response: does it match
578 // the expected response(s)?
579 if(logger.isDebugEnabled()){
580 logger.debug(testName + ": status = " + statusCode);
582 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
583 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
584 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
586 // Check whether organization has expected displayName.
587 MultipartInput input = (MultipartInput) res.getEntity();
588 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
589 client.getItemCommonPartName(), OrganizationsCommon.class);
590 Assert.assertNotNull(organization);
591 // Try to Update with computed false and no displayName
592 organization.setDisplayNameComputed(false);
593 organization.setDisplayName(null);
595 // Submit the updated resource to the service and store the response.
596 MultipartOutput output = new MultipartOutput();
597 OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
598 commonPart.getHeaders().add("label", client.getItemCommonPartName());
599 res = client.updateItem(knownResourceId, knownItemResourceId, output);
600 statusCode = res.getStatus();
602 // Check the status code of the response: does it match the expected response(s)?
603 if(logger.isDebugEnabled()){
604 logger.debug("updateItem: status = " + statusCode);
606 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
607 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
608 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
611 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
612 groups = {"read"}, dependsOnMethods = {"readItem"})
613 public void readContact(String testName) throws Exception {
618 // Submit the request to the service and store the response.
619 ClientResponse<MultipartInput> res =
620 client.readContact(knownResourceId, knownItemResourceId,
621 knownContactResourceId);
622 int statusCode = res.getStatus();
624 // Check the status code of the response: does it match
625 // the expected response(s)?
626 if(logger.isDebugEnabled()){
627 logger.debug(testName + ": status = " + statusCode);
629 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
630 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
631 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
633 // Check whether we've received a contact.
634 MultipartInput input = (MultipartInput) res.getEntity();
635 ContactsCommon contact = (ContactsCommon) extractPart(input,
636 contactClient.getCommonPartName(), ContactsCommon.class);
637 Assert.assertNotNull(contact);
638 boolean showFull = true;
639 if(showFull && logger.isDebugEnabled()){
640 logger.debug(testName + ": returned payload:");
641 logger.debug(objectAsXmlString(contact, ContactsCommon.class));
643 Assert.assertEquals(contact.getInAuthority(), knownResourceId);
644 Assert.assertEquals(contact.getInItem(), knownItemResourceId);
650 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
651 groups = {"read"}, dependsOnMethods = {"read"})
652 public void readNonExistent(String testName) {
655 setupReadNonExistent(testName);
657 // Submit the request to the service and store the response.
658 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
659 int statusCode = res.getStatus();
661 // Check the status code of the response: does it match
662 // the expected response(s)?
663 if(logger.isDebugEnabled()){
664 logger.debug(testName + ": status = " + statusCode);
666 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
667 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
668 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
671 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
672 groups = {"read"}, dependsOnMethods = {"readItem"})
673 public void readItemNonExistent(String testName) {
676 setupReadNonExistent(testName);
678 // Submit the request to the service and store the response.
679 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
680 int statusCode = res.getStatus();
682 // Check the status code of the response: does it match
683 // the expected response(s)?
684 if(logger.isDebugEnabled()){
685 logger.debug(testName + ": status = " + statusCode);
687 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
688 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
689 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
692 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
693 groups = {"read"}, dependsOnMethods = {"readContact"})
694 public void readContactNonExistent(String testName) {
697 setupReadNonExistent(testName);
699 // Submit the request to the service and store the response.
700 ClientResponse<MultipartInput> res =
701 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
702 int statusCode = res.getStatus();
704 // Check the status code of the response: does it match
705 // the expected response(s)?
706 if(logger.isDebugEnabled()){
707 logger.debug(testName + ": status = " + statusCode);
709 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
710 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
711 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
714 // ---------------------------------------------------------------
715 // CRUD tests : READ_LIST tests
716 // ---------------------------------------------------------------
720 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
721 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
722 public void readList(String testName) throws Exception {
725 setupReadList(testName);
727 // Submit the request to the service and store the response.
728 ClientResponse<OrgauthoritiesCommonList> res = client.readList();
729 OrgauthoritiesCommonList list = res.getEntity();
730 int statusCode = res.getStatus();
732 // Check the status code of the response: does it match
733 // the expected response(s)?
734 if(logger.isDebugEnabled()){
735 logger.debug(testName + ": status = " + statusCode);
737 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
738 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
739 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
741 // Optionally output additional data about list members for debugging.
742 boolean iterateThroughList = false;
743 if (iterateThroughList && logger.isDebugEnabled()) {
744 List<OrgauthoritiesCommonList.OrgauthorityListItem> items =
745 list.getOrgauthorityListItem();
747 for (OrgauthoritiesCommonList.OrgauthorityListItem item : items) {
748 String csid = item.getCsid();
749 logger.debug(testName + ": list-item[" + i + "] csid=" +
751 logger.debug(testName + ": list-item[" + i + "] displayName=" +
752 item.getDisplayName());
753 logger.debug(testName + ": list-item[" + i + "] URI=" +
761 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
762 public void readItemList() {
763 readItemList(knownResourceId);
766 private void readItemList(String vcsid) {
768 final String testName = "readItemList";
771 setupReadList(testName);
773 // Submit the request to the service and store the response.
774 ClientResponse<OrganizationsCommonList> res =
775 client.readItemList(vcsid);
776 OrganizationsCommonList list = res.getEntity();
777 int statusCode = res.getStatus();
779 // Check the status code of the response: does it match
780 // the expected response(s)?
781 if(logger.isDebugEnabled()){
782 logger.debug(testName + ": status = " + statusCode);
784 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
785 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
786 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
788 List<OrganizationsCommonList.OrganizationListItem> items =
789 list.getOrganizationListItem();
790 int nItemsReturned = items.size();
791 // There will be one item created, associated with a
792 // known parent resource, by the createItem test.
794 // In addition, there will be 'nItemsToCreateInList'
795 // additional items created by the createItemList test,
796 // all associated with the same parent resource.
797 int nExpectedItems = nItemsToCreateInList + 1;
798 if(logger.isDebugEnabled()){
799 logger.debug(testName + ": Expected "
800 + nExpectedItems +" items; got: "+nItemsReturned);
802 Assert.assertEquals(nItemsReturned, nExpectedItems);
805 for (OrganizationsCommonList.OrganizationListItem item : items) {
806 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
807 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
808 // Optionally output additional data about list members for debugging.
809 boolean showDetails = true;
810 if (showDetails && logger.isDebugEnabled()) {
811 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
813 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
815 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
816 item.getDisplayName());
817 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
824 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
825 public void readContactList() {
826 readContactList(knownResourceId, knownItemResourceId);
829 private void readContactList(String parentcsid, String itemcsid) {
830 final String testName = "readContactList";
833 setupReadList(testName);
835 // Submit the request to the service and store the response.
836 ClientResponse<ContactsCommonList> res =
837 client.readContactList(parentcsid, itemcsid);
838 ContactsCommonList list = res.getEntity();
839 int statusCode = res.getStatus();
841 // Check the status code of the response: does it match
842 // the expected response(s)?
843 if(logger.isDebugEnabled()){
844 logger.debug(testName + ": status = " + statusCode);
846 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
847 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
848 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
850 List<ContactsCommonList.ContactListItem> listitems =
851 list.getContactListItem();
852 int nItemsReturned = listitems.size();
853 // There will be one item created, associated with a
854 // known parent resource, by the createItem test.
856 // In addition, there will be 'nItemsToCreateInList'
857 // additional items created by the createItemList test,
858 // all associated with the same parent resource.
859 int nExpectedItems = nItemsToCreateInList + 1;
860 if(logger.isDebugEnabled()){
861 logger.debug(testName + ": Expected "
862 + nExpectedItems +" items; got: "+nItemsReturned);
864 Assert.assertEquals(nItemsReturned, nExpectedItems);
867 for (ContactsCommonList.ContactListItem listitem : listitems) {
868 // Optionally output additional data about list members for debugging.
869 boolean showDetails = false;
870 if (showDetails && logger.isDebugEnabled()) {
871 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
873 logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" +
874 listitem.getAddressPlace());
875 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
885 // ---------------------------------------------------------------
886 // CRUD tests : UPDATE tests
887 // ---------------------------------------------------------------
890 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
891 groups = {"update"}, dependsOnGroups = {"create"})
892 public void update(String testName) throws Exception {
895 setupUpdate(testName);
897 // Retrieve the contents of a resource to update.
898 ClientResponse<MultipartInput> res =
899 client.read(knownResourceId);
900 if(logger.isDebugEnabled()){
901 logger.debug(testName + ": read status = " + res.getStatus());
903 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
905 if(logger.isDebugEnabled()){
906 logger.debug("got OrgAuthority to update with ID: " + knownResourceId);
908 MultipartInput input = (MultipartInput) res.getEntity();
909 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
910 client.getCommonPartName(), OrgauthoritiesCommon.class);
911 Assert.assertNotNull(orgAuthority);
913 // Update the contents of this resource.
914 orgAuthority.setDisplayName("updated-" + orgAuthority.getDisplayName());
915 orgAuthority.setVocabType("updated-" + orgAuthority.getVocabType());
916 if(logger.isDebugEnabled()){
917 logger.debug("to be updated OrgAuthority");
918 logger.debug(objectAsXmlString(orgAuthority, OrgauthoritiesCommon.class));
921 // Submit the updated resource to the service and store the response.
922 MultipartOutput output = new MultipartOutput();
923 OutputPart commonPart = output.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE);
924 commonPart.getHeaders().add("label", client.getCommonPartName());
925 res = client.update(knownResourceId, output);
926 int statusCode = res.getStatus();
928 // Check the status code of the response: does it match the expected response(s)?
929 if(logger.isDebugEnabled()){
930 logger.debug(testName + ": status = " + statusCode);
932 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
933 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
934 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
936 // Retrieve the updated resource and verify that its contents exist.
937 input = (MultipartInput) res.getEntity();
938 OrgauthoritiesCommon updatedOrgAuthority =
939 (OrgauthoritiesCommon) extractPart(input,
940 client.getCommonPartName(), OrgauthoritiesCommon.class);
941 Assert.assertNotNull(updatedOrgAuthority);
943 // Verify that the updated resource received the correct data.
944 Assert.assertEquals(updatedOrgAuthority.getDisplayName(),
945 orgAuthority.getDisplayName(),
946 "Data in updated object did not match submitted data.");
949 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
950 groups = {"update"}, dependsOnMethods = {"update"})
951 public void updateItem(String testName) throws Exception {
954 setupUpdate(testName);
956 ClientResponse<MultipartInput> res =
957 client.readItem(knownResourceId, knownItemResourceId);
958 if(logger.isDebugEnabled()){
959 logger.debug(testName + ": read status = " + res.getStatus());
961 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
963 if(logger.isDebugEnabled()){
964 logger.debug("got Organization to update with ID: " +
965 knownItemResourceId +
966 " in OrgAuthority: " + knownResourceId );
968 MultipartInput input = (MultipartInput) res.getEntity();
969 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
970 client.getItemCommonPartName(), OrganizationsCommon.class);
971 Assert.assertNotNull(organization);
973 // Update the contents of this resource.
974 organization.setShortName("updated-" + organization.getShortName());
975 if(logger.isDebugEnabled()){
976 logger.debug("to be updated Organization");
977 logger.debug(objectAsXmlString(organization,
978 OrganizationsCommon.class));
981 // Submit the updated resource to the service and store the response.
982 MultipartOutput output = new MultipartOutput();
983 OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
984 commonPart.getHeaders().add("label", client.getItemCommonPartName());
985 res = client.updateItem(knownResourceId, knownItemResourceId, output);
986 int statusCode = res.getStatus();
988 // Check the status code of the response: does it match the expected response(s)?
989 if(logger.isDebugEnabled()){
990 logger.debug(testName + ": status = " + statusCode);
992 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
993 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
994 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
996 // Retrieve the updated resource and verify that its contents exist.
997 input = (MultipartInput) res.getEntity();
998 OrganizationsCommon updatedOrganization =
999 (OrganizationsCommon) extractPart(input,
1000 client.getItemCommonPartName(), OrganizationsCommon.class);
1001 Assert.assertNotNull(updatedOrganization);
1003 // Verify that the updated resource received the correct data.
1004 Assert.assertEquals(updatedOrganization.getShortName(),
1005 organization.getShortName(),
1006 "Data in updated Organization did not match submitted data.");
1009 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1010 groups = {"update"}, dependsOnMethods = {"updateItem"})
1011 public void updateContact(String testName) throws Exception {
1014 setupUpdate(testName);
1016 ClientResponse<MultipartInput> res =
1017 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1018 if(logger.isDebugEnabled()){
1019 logger.debug(testName + ": read status = " + res.getStatus());
1021 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1023 if(logger.isDebugEnabled()){
1024 logger.debug("got Contact to update with ID: " +
1025 knownContactResourceId +
1026 " in item: " + knownItemResourceId +
1027 " in parent: " + knownResourceId );
1029 MultipartInput input = (MultipartInput) res.getEntity();
1030 ContactsCommon contact = (ContactsCommon) extractPart(input,
1031 contactClient.getCommonPartName(), ContactsCommon.class);
1032 Assert.assertNotNull(contact);
1034 // Update the contents of this resource.
1035 contact.setAddressPlace("updated-" + contact.getAddressPlace());
1036 if(logger.isDebugEnabled()){
1037 logger.debug("to be updated Contact");
1038 logger.debug(objectAsXmlString(contact,
1039 ContactsCommon.class));
1042 // Submit the updated resource to the service and store the response.
1043 MultipartOutput output = new MultipartOutput();
1044 OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1045 commonPart.getHeaders().add("label", contactClient.getCommonPartName());
1046 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1047 int statusCode = res.getStatus();
1049 // Check the status code of the response: does it match the expected response(s)?
1050 if(logger.isDebugEnabled()){
1051 logger.debug(testName + ": status = " + statusCode);
1053 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1054 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1055 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1057 // Retrieve the updated resource and verify that its contents exist.
1058 input = (MultipartInput) res.getEntity();
1059 ContactsCommon updatedContact =
1060 (ContactsCommon) extractPart(input,
1061 contactClient.getCommonPartName(), ContactsCommon.class);
1062 Assert.assertNotNull(updatedContact);
1064 // Verify that the updated resource received the correct data.
1065 Assert.assertEquals(updatedContact.getAddressPlace(),
1066 contact.getAddressPlace(),
1067 "Data in updated Contact did not match submitted data.");
1071 // Placeholders until the three tests below can be uncommented.
1072 // See Issue CSPACE-401.
1074 public void updateWithEmptyEntityBody(String testName) throws Exception {
1078 public void updateWithMalformedXml(String testName) throws Exception {
1082 public void updateWithWrongXmlSchema(String testName) throws Exception {
1087 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1088 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1089 public void updateWithEmptyEntityBody(String testName) throws Exception {
1092 setupUpdateWithEmptyEntityBody(testName);
1094 // Submit the request to the service and store the response.
1095 String method = REQUEST_TYPE.httpMethodName();
1096 String url = getResourceURL(knownResourceId);
1097 String mediaType = MediaType.APPLICATION_XML;
1098 final String entity = "";
1099 int statusCode = submitRequest(method, url, mediaType, entity);
1101 // Check the status code of the response: does it match
1102 // the expected response(s)?
1103 if(logger.isDebugEnabled()){
1104 logger.debug(testName + ": url=" + url +
1105 " status=" + statusCode);
1107 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1108 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1109 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1113 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1114 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1115 public void updateWithMalformedXml(String testName) throws Exception {
1118 setupUpdateWithMalformedXml(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 = MALFORMED_XML_DATA;
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 updateWithWrongXmlSchema(String testName) throws Exception {
1144 setupUpdateWithWrongXmlSchema(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 = WRONG_XML_SCHEMA_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("updateWithWrongXmlSchema: url=" + url +
1157 " status=" + statusCode);
1159 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1160 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1161 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1166 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1167 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1168 public void updateNonExistent(String testName) throws Exception {
1171 setupUpdateNonExistent(testName);
1173 // Submit the request to the service and store the response.
1174 // Note: The ID used in this 'create' call may be arbitrary.
1175 // The only relevant ID may be the one used in update(), below.
1176 MultipartOutput multipart = createOrgAuthorityInstance(NON_EXISTENT_ID);
1177 ClientResponse<MultipartInput> res =
1178 client.update(NON_EXISTENT_ID, multipart);
1179 int statusCode = res.getStatus();
1181 // Check the status code of the response: does it match
1182 // the expected response(s)?
1183 if(logger.isDebugEnabled()){
1184 logger.debug(testName + ": status = " + statusCode);
1186 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1187 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1188 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1191 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1192 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1193 public void updateNonExistentItem(String testName) throws Exception {
1196 setupUpdateNonExistent(testName);
1198 // Submit the request to the service and store the response.
1199 // Note: The ID(s) used when creating the request payload may be arbitrary.
1200 // The only relevant ID may be the one used in update(), below.
1201 Map<String, String> nonexOrgMap = new HashMap<String,String>();
1202 nonexOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Non-existent");
1203 String refName = OrgAuthorityClientUtils.createOrganizationRefName(knownResourceRefName, NON_EXISTENT_ID, true);
1204 MultipartOutput multipart =
1205 OrgAuthorityClientUtils.createOrganizationInstance(
1206 NON_EXISTENT_ID, refName,
1207 nonexOrgMap, client.getItemCommonPartName() );
1208 ClientResponse<MultipartInput> res =
1209 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1210 int statusCode = res.getStatus();
1212 // Check the status code of the response: does it match
1213 // the expected response(s)?
1214 if(logger.isDebugEnabled()){
1215 logger.debug(testName + ": status = " + statusCode);
1217 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1218 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1219 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1222 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1223 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1224 public void updateNonExistentContact(String testName) throws Exception {
1225 // Currently a no-op test
1228 // ---------------------------------------------------------------
1229 // CRUD tests : DELETE tests
1230 // ---------------------------------------------------------------
1233 // Note: delete sub-resources in ascending hierarchical order,
1234 // before deleting their parents.
1236 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1237 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1238 public void deleteContact(String testName) throws Exception {
1241 setupDelete(testName);
1243 if(logger.isDebugEnabled()){
1244 logger.debug("parentcsid =" + knownResourceId +
1245 " itemcsid = " + knownItemResourceId +
1246 " csid = " + knownContactResourceId);
1249 // Submit the request to the service and store the response.
1250 ClientResponse<Response> res =
1251 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1252 int statusCode = res.getStatus();
1254 // Check the status code of the response: does it match
1255 // the expected response(s)?
1256 if(logger.isDebugEnabled()){
1257 logger.debug(testName + ": status = " + statusCode);
1259 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1260 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1261 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1264 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1265 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1266 public void deleteItem(String testName) throws Exception {
1269 setupDelete(testName);
1271 if(logger.isDebugEnabled()){
1272 logger.debug("parentcsid =" + knownResourceId +
1273 " itemcsid = " + knownItemResourceId);
1276 // Submit the request to the service and store the response.
1277 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1278 int statusCode = res.getStatus();
1280 // Check the status code of the response: does it match
1281 // the expected response(s)?
1282 if(logger.isDebugEnabled()){
1283 logger.debug(testName + ": status = " + statusCode);
1285 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1286 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1287 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1291 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1292 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1293 public void delete(String testName) throws Exception {
1296 setupDelete(testName);
1298 if(logger.isDebugEnabled()){
1299 logger.debug("parentcsid =" + knownResourceId);
1302 // Submit the request to the service and store the response.
1303 ClientResponse<Response> res = client.delete(knownResourceId);
1304 int statusCode = res.getStatus();
1306 // Check the status code of the response: does it match
1307 // the expected response(s)?
1308 if(logger.isDebugEnabled()){
1309 logger.debug(testName + ": status = " + statusCode);
1311 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1312 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1313 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1318 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1319 groups = {"delete"}, dependsOnMethods = {"delete"})
1320 public void deleteNonExistent(String testName) throws Exception {
1323 setupDeleteNonExistent(testName);
1325 // Submit the request to the service and store the response.
1326 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1327 int statusCode = res.getStatus();
1329 // Check the status code of the response: does it match
1330 // the expected response(s)?
1331 if(logger.isDebugEnabled()){
1332 logger.debug(testName + ": status = " + statusCode);
1334 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1335 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1336 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1339 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1340 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1341 public void deleteNonExistentItem(String testName) {
1344 setupDeleteNonExistent(testName);
1346 // Submit the request to the service and store the response.
1347 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1348 int statusCode = res.getStatus();
1350 // Check the status code of the response: does it match
1351 // the expected response(s)?
1352 if(logger.isDebugEnabled()){
1353 logger.debug(testName + ": status = " + statusCode);
1355 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1356 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1357 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1360 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1361 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1362 public void deleteNonExistentContact(String testName) {
1365 setupDeleteNonExistent(testName);
1367 // Submit the request to the service and store the response.
1368 ClientResponse<Response> res =
1369 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1370 int statusCode = res.getStatus();
1372 // Check the status code of the response: does it match
1373 // the expected response(s)?
1374 if(logger.isDebugEnabled()){
1375 logger.debug(testName + ": status = " + statusCode);
1377 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1378 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1379 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1382 // ---------------------------------------------------------------
1383 // Utility tests : tests of code used in tests above
1384 // ---------------------------------------------------------------
1386 * Tests the code for manually submitting data that is used by several
1387 * of the methods above.
1389 @Test(dependsOnMethods = {"create", "read"})
1390 public void testSubmitRequest() {
1392 // Expected status code: 200 OK
1393 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1395 // Submit the request to the service and store the response.
1396 String method = ServiceRequestType.READ.httpMethodName();
1397 String url = getResourceURL(knownResourceId);
1398 int statusCode = submitRequest(method, url);
1400 // Check the status code of the response: does it match
1401 // the expected response(s)?
1402 if(logger.isDebugEnabled()){
1403 logger.debug("testSubmitRequest: url=" + url +
1404 " status=" + statusCode);
1406 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1410 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1411 public void testItemSubmitRequest() {
1413 // Expected status code: 200 OK
1414 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1416 // Submit the request to the service and store the response.
1417 String method = ServiceRequestType.READ.httpMethodName();
1418 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1419 int statusCode = submitRequest(method, url);
1421 // Check the status code of the response: does it match
1422 // the expected response(s)?
1423 if(logger.isDebugEnabled()){
1424 logger.debug("testItemSubmitRequest: url=" + url +
1425 " status=" + statusCode);
1427 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1431 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
1432 public void testContactSubmitRequest() {
1434 // Expected status code: 200 OK
1435 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1437 // Submit the request to the service and store the response.
1438 String method = ServiceRequestType.READ.httpMethodName();
1439 String url = getContactResourceURL(knownResourceId,
1440 knownItemResourceId, knownContactResourceId);
1441 int statusCode = submitRequest(method, url);
1443 // Check the status code of the response: does it match
1444 // the expected response(s)?
1445 if(logger.isDebugEnabled()){
1446 logger.debug("testItemSubmitRequest: url=" + url +
1447 " status=" + statusCode);
1449 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1454 // ---------------------------------------------------------------
1455 // Cleanup of resources created during testing
1456 // ---------------------------------------------------------------
1459 * Deletes all resources created by tests, after all tests have been run.
1461 * This cleanup method will always be run, even if one or more tests fail.
1462 * For this reason, it attempts to remove all resources created
1463 * at any point during testing, even if some of those resources
1464 * may be expected to be deleted by certain tests.
1467 @AfterClass(alwaysRun=true)
1468 public void cleanUp() {
1469 if (logger.isDebugEnabled()) {
1470 logger.debug("Cleaning up temporary resources created for testing ...");
1472 String parentResourceId;
1473 String itemResourceId;
1474 String contactResourceId;
1475 // Clean up contact resources.
1476 parentResourceId = knownResourceId;
1477 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
1478 contactResourceId = entry.getKey();
1479 itemResourceId = entry.getValue();
1480 // Note: Any non-success responses from the delete operation
1481 // below are ignored and not reported.
1482 ClientResponse<Response> res =
1483 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
1485 // Clean up item resources.
1486 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1487 itemResourceId = entry.getKey();
1488 parentResourceId = entry.getValue();
1489 // Note: Any non-success responses from the delete operation
1490 // below are ignored and not reported.
1491 ClientResponse<Response> res =
1492 client.deleteItem(parentResourceId, itemResourceId);
1494 // Clean up parent resources.
1495 for (String resourceId : allResourceIdsCreated) {
1496 // Note: Any non-success responses from the delete operation
1497 // below are ignored and not reported.
1498 ClientResponse<Response> res = client.delete(resourceId);
1502 // ---------------------------------------------------------------
1503 // Utility methods used by tests above
1504 // ---------------------------------------------------------------
1506 public String getServicePathComponent() {
1507 return SERVICE_PATH_COMPONENT;
1510 public String getItemServicePathComponent() {
1511 return ITEM_SERVICE_PATH_COMPONENT;
1514 public String getContactServicePathComponent() {
1515 return CONTACT_SERVICE_PATH_COMPONENT;
1519 * Returns the root URL for the item service.
1521 * This URL consists of a base URL for all services, followed by
1522 * a path component for the owning parent, followed by the
1523 * path component for the items.
1525 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1526 * parent authority resource of the relevant item resource.
1528 * @return The root URL for the item service.
1530 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1531 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1535 * Returns the URL of a specific item resource managed by a service, and
1536 * designated by an identifier (such as a universally unique ID, or UUID).
1538 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1539 * parent authority resource of the relevant item resource.
1541 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1544 * @return The URL of a specific item resource managed by a service.
1546 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1547 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
1552 * Returns the root URL for the contact service.
1554 * This URL consists of a base URL for all services, followed by
1555 * a path component for the owning authority, followed by the
1556 * path component for the owning item, followed by the path component
1557 * for the contact service.
1559 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1560 * parent authority resource of the relevant item resource.
1562 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1565 * @return The root URL for the contact service.
1567 protected String getContactServiceRootURL(String parentResourceIdentifier,
1568 String itemResourceIdentifier) {
1569 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
1570 getContactServicePathComponent();
1574 * Returns the URL of a specific contact resource managed by a service, and
1575 * designated by an identifier (such as a universally unique ID, or UUID).
1577 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1578 * parent resource of the relevant item resource.
1580 * @param resourceIdentifier An identifier (such as a UUID) for an
1583 * @return The URL of a specific resource managed by a service.
1585 protected String getContactResourceURL(String parentResourceIdentifier,
1586 String itemResourceIdentifier, String contactResourceIdentifier) {
1587 return getContactServiceRootURL(parentResourceIdentifier,
1588 itemResourceIdentifier) + "/" + contactResourceIdentifier;
1591 private MultipartOutput createOrgAuthorityInstance(String identifier) {
1592 String displayName = "displayName-" + identifier;
1593 String refName = OrgAuthorityClientUtils.createOrgAuthRefName(displayName, true);
1594 return OrgAuthorityClientUtils.createOrgAuthorityInstance(
1595 displayName, refName,
1596 client.getCommonPartName());