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 final String SERVICE_PATH_COMPONENT = "orgauthorities";
68 final String ITEM_SERVICE_PATH_COMPONENT = "items";
69 final String CONTACT_SERVICE_PATH_COMPONENT = "contacts";
70 private final String TEST_ORG_SHORTNAME = "Test Org";
71 private final String TEST_ORG_FOUNDING_PLACE = "Anytown, USA";
72 private String knownResourceId = null;
73 private String knownResourceDisplayName = null;
74 private String knownResourceRefName = null;
75 private String knownItemResourceId = null;
76 private String knownContactResourceId = null;
77 private int nItemsToCreateInList = 3;
78 private List<String> allResourceIdsCreated = new ArrayList<String>();
79 private Map<String, String> allItemResourceIdsCreated =
80 new HashMap<String, String>();
81 private Map<String, String> allContactResourceIdsCreated =
82 new HashMap<String, String>();
84 // ---------------------------------------------------------------
85 // CRUD tests : CREATE tests
86 // ---------------------------------------------------------------
89 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
91 public void create(String testName) throws Exception {
93 // Perform setup, such as initializing the type of service request
94 // (e.g. CREATE, DELETE), its valid and expected status codes, and
95 // its associated HTTP method name (e.g. POST, DELETE).
96 setupCreate(testName);
98 // Submit the request to the service and store the response.
99 OrgAuthorityClient client = new OrgAuthorityClient();
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 knownResourceDisplayName = displayName;
132 if (logger.isDebugEnabled()) {
133 logger.debug(testName + ": knownResourceId=" + knownResourceId);
136 // Store the IDs from every resource created by tests,
137 // so they can be deleted after tests have been run.
138 allResourceIdsCreated.add(newID);
141 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
142 groups = {"create"}, dependsOnMethods = {"create"})
143 public void createItem(String testName) {
144 setupCreate(testName);
145 String newID = createItemInAuthority(knownResourceId, knownResourceRefName);
148 private String createItemInAuthority(String vcsid, String authRefName) {
150 final String testName = "createItemInAuthority";
151 if(logger.isDebugEnabled()){
152 logger.debug(testName + ":...");
155 // Submit the request to the service and store the response.
156 OrgAuthorityClient client = new OrgAuthorityClient();
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 OrgAuthorityClient client = new OrgAuthorityClient();
202 String identifier = createIdentifier();
203 MultipartOutput multipart =
204 ContactClientUtils.createContactInstance(parentcsid,
205 itemcsid, identifier, new ContactClient().getCommonPartName());
206 ClientResponse<Response> res =
207 client.createContact(parentcsid, itemcsid, multipart);
208 int statusCode = res.getStatus();
209 String newID = OrgAuthorityClientUtils.extractId(res);
211 // Check the status code of the response: does it match
212 // the expected response(s)?
213 if(logger.isDebugEnabled()){
214 logger.debug(testName + ": status = " + statusCode);
216 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
217 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
218 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
220 // Store the ID returned from the first contact resource created
221 // for additional tests below.
222 if (knownContactResourceId == null){
223 knownContactResourceId = newID;
224 if (logger.isDebugEnabled()) {
225 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
229 // Store the IDs from any contact resources created
230 // by tests, along with the IDs of their parent items,
231 // so these items can be deleted after all tests have been run.
232 allContactResourceIdsCreated.put(newID, itemcsid);
239 // Placeholders until the three tests below can be uncommented.
240 // See Issue CSPACE-401.
242 public void createWithEmptyEntityBody(String testName) throws Exception {
246 public void createWithMalformedXml(String testName) throws Exception {
250 public void createWithWrongXmlSchema(String testName) throws Exception {
255 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
256 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
257 public void createWithEmptyEntityBody(String testName) throws Exception {
260 setupCreateWithEmptyEntityBody(testName);
262 // Submit the request to the service and store the response.
263 String method = REQUEST_TYPE.httpMethodName();
264 String url = getServiceRootURL();
265 String mediaType = MediaType.APPLICATION_XML;
266 final String entity = "";
267 int statusCode = submitRequest(method, url, mediaType, entity);
269 // Check the status code of the response: does it match
270 // the expected response(s)?
271 if(logger.isDebugEnabled()) {
272 logger.debug(testName + ": url=" + url +
273 " status=" + statusCode);
275 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
276 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
277 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
281 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
282 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
283 public void createWithMalformedXml(String testName) throws Exception {
286 setupCreateWithMalformedXml(testName);
288 // Submit the request to the service and store the response.
289 String method = REQUEST_TYPE.httpMethodName();
290 String url = getServiceRootURL();
291 String mediaType = MediaType.APPLICATION_XML;
292 final String entity = MALFORMED_XML_DATA; // Constant from base class.
293 int statusCode = submitRequest(method, url, mediaType, entity);
295 // Check the status code of the response: does it match
296 // the expected response(s)?
297 if(logger.isDebugEnabled()){
298 logger.debug(testName + ": url=" + url +
299 " status=" + statusCode);
301 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
302 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
303 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
307 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
308 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
309 public void createWithWrongXmlSchema(String testName) throws Exception {
312 setupCreateWithWrongXmlSchema(testName);
314 // Submit the request to the service and store the response.
315 String method = REQUEST_TYPE.httpMethodName();
316 String url = getServiceRootURL();
317 String mediaType = MediaType.APPLICATION_XML;
318 final String entity = WRONG_XML_SCHEMA_DATA;
319 int statusCode = submitRequest(method, url, mediaType, entity);
321 // Check the status code of the response: does it match
322 // the expected response(s)?
323 if(logger.isDebugEnabled()){
324 logger.debug(testName + ": url=" + url +
325 " status=" + statusCode);
327 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
328 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
329 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
333 // ---------------------------------------------------------------
334 // CRUD tests : CREATE LIST tests
335 // ---------------------------------------------------------------
338 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
339 groups = {"createList"}, dependsOnGroups = {"create"})
340 public void createList(String testName) throws Exception {
341 for (int i = 0; i < nItemsToCreateInList; i++) {
346 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
347 groups = {"createList"}, dependsOnMethods = {"createList"})
348 public void createItemList(String testName) throws Exception {
349 // Add items to the initially-created, known parent record.
350 for (int j = 0; j < nItemsToCreateInList; j++) {
351 createItem(testName);
355 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
356 groups = {"createList"}, dependsOnMethods = {"createItemList"})
357 public void createContactList(String testName) throws Exception {
358 // Add contacts to the initially-created, known item record.
359 for (int j = 0; j < nItemsToCreateInList; j++) {
360 createContact(testName);
364 // ---------------------------------------------------------------
365 // CRUD tests : READ tests
366 // ---------------------------------------------------------------
369 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
370 groups = {"read"}, dependsOnGroups = {"create"})
371 public void read(String testName) throws Exception {
376 // Submit the request to the service and store the response.
377 OrgAuthorityClient client = new OrgAuthorityClient();
378 ClientResponse<MultipartInput> res = client.read(knownResourceId);
379 int statusCode = res.getStatus();
381 // Check the status code of the response: does it match
382 // the expected response(s)?
383 if(logger.isDebugEnabled()){
384 logger.debug(testName + ": status = " + statusCode);
386 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
387 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
388 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
389 //FIXME: remove the following try catch once Aron fixes signatures
391 MultipartInput input = (MultipartInput) res.getEntity();
392 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
393 client.getCommonPartName(), OrgauthoritiesCommon.class);
394 Assert.assertNotNull(orgAuthority);
395 } catch (Exception e) {
396 throw new RuntimeException(e);
400 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
401 groups = {"read"}, dependsOnGroups = {"create"})
402 public void readByName(String testName) throws Exception {
407 // Submit the request to the service and store the response.
408 OrgAuthorityClient client = new OrgAuthorityClient();
409 ClientResponse<MultipartInput> res = client.readByName(knownResourceDisplayName);
410 int statusCode = res.getStatus();
412 // Check the status code of the response: does it match
413 // the expected response(s)?
414 if(logger.isDebugEnabled()){
415 logger.debug(testName + ": status = " + statusCode);
417 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
418 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
419 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
420 //FIXME: remove the following try catch once Aron fixes signatures
422 MultipartInput input = (MultipartInput) res.getEntity();
423 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
424 new OrgAuthorityClient().getCommonPartName(), OrgauthoritiesCommon.class);
425 Assert.assertNotNull(orgAuthority);
426 } catch (Exception e) {
427 throw new RuntimeException(e);
432 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
433 groups = {"read"}, dependsOnMethods = {"read"})
434 public void readByName(String testName) throws Exception {
439 // Submit the request to the service and store the response.
440 ClientResponse<MultipartInput> res = client.read(knownResourceId);
441 int statusCode = res.getStatus();
443 // Check the status code of the response: does it match
444 // the expected response(s)?
445 if(logger.isDebugEnabled()){
446 logger.debug(testName + ": status = " + statusCode);
448 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
449 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
450 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
451 //FIXME: remove the following try catch once Aron fixes signatures
453 MultipartInput input = (MultipartInput) res.getEntity();
454 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
455 client.getCommonPartName(), OrgauthoritiesCommon.class);
456 Assert.assertNotNull(orgAuthority);
457 } catch (Exception e) {
458 throw new RuntimeException(e);
463 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
464 groups = {"read"}, dependsOnMethods = {"read"})
465 public void readItem(String testName) throws Exception {
470 // Submit the request to the service and store the response.
471 OrgAuthorityClient client = new OrgAuthorityClient();
472 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
473 int statusCode = res.getStatus();
475 // Check the status code of the response: does it match
476 // the expected response(s)?
477 if(logger.isDebugEnabled()){
478 logger.debug(testName + ": status = " + statusCode);
480 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
481 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
482 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
484 // Check whether we've received a organization.
485 MultipartInput input = (MultipartInput) res.getEntity();
486 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
487 client.getItemCommonPartName(), OrganizationsCommon.class);
488 Assert.assertNotNull(organization);
489 boolean showFull = true;
490 if(showFull && logger.isDebugEnabled()){
491 logger.debug(testName + ": returned payload:");
492 logger.debug(objectAsXmlString(organization,
493 OrganizationsCommon.class));
495 Assert.assertEquals(organization.getInAuthority(), knownResourceId);
498 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
499 dependsOnMethods = {"readItem", "updateItem"})
500 public void verifyItemDisplayName(String testName) throws Exception {
503 setupUpdate(testName);
505 // Submit the request to the service and store the response.
506 OrgAuthorityClient client = new OrgAuthorityClient();
507 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
508 int statusCode = res.getStatus();
510 // Check the status code of the response: does it match
511 // the expected response(s)?
512 if(logger.isDebugEnabled()){
513 logger.debug(testName + ": status = " + statusCode);
515 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
516 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
517 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
519 // Check whether organization has expected displayName.
520 MultipartInput input = (MultipartInput) res.getEntity();
521 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
522 client.getItemCommonPartName(), OrganizationsCommon.class);
523 Assert.assertNotNull(organization);
524 String displayName = organization.getDisplayName();
525 // Make sure displayName matches computed form
526 String expectedDisplayName =
527 OrgAuthorityClientUtils.prepareDefaultDisplayName(
528 TEST_ORG_SHORTNAME, TEST_ORG_FOUNDING_PLACE);
529 Assert.assertNotNull(displayName, expectedDisplayName);
531 // Update the shortName and verify the computed name is updated.
532 organization.setCsid(null);
533 organization.setDisplayNameComputed(true);
534 organization.setShortName("updated-" + TEST_ORG_SHORTNAME);
535 expectedDisplayName =
536 OrgAuthorityClientUtils.prepareDefaultDisplayName(
537 "updated-" + TEST_ORG_SHORTNAME, TEST_ORG_FOUNDING_PLACE);
539 // Submit the updated resource to the service and store the response.
540 MultipartOutput output = new MultipartOutput();
541 OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
542 commonPart.getHeaders().add("label", client.getItemCommonPartName());
543 res = client.updateItem(knownResourceId, knownItemResourceId, output);
544 statusCode = res.getStatus();
546 // Check the status code of the response: does it match the expected response(s)?
547 if(logger.isDebugEnabled()){
548 logger.debug("updateItem: status = " + statusCode);
550 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
551 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
552 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
554 // Retrieve the updated resource and verify that its contents exist.
555 input = (MultipartInput) res.getEntity();
556 OrganizationsCommon updatedOrganization =
557 (OrganizationsCommon) extractPart(input,
558 client.getItemCommonPartName(), OrganizationsCommon.class);
559 Assert.assertNotNull(updatedOrganization);
561 // Verify that the updated resource received the correct data.
562 Assert.assertEquals(updatedOrganization.getShortName(), organization.getShortName(),
563 "Updated ShortName in Organization did not match submitted data.");
564 // Verify that the updated resource computes the right displayName.
565 Assert.assertEquals(updatedOrganization.getDisplayName(), expectedDisplayName,
566 "Updated ShortName in Organization not reflected in computed DisplayName.");
568 // Now Update the displayName, not computed and verify the computed name is overriden.
569 organization.setDisplayNameComputed(false);
570 expectedDisplayName = "TestName";
571 organization.setDisplayName(expectedDisplayName);
573 // Submit the updated resource to the service and store the response.
574 output = new MultipartOutput();
575 commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
576 commonPart.getHeaders().add("label", client.getItemCommonPartName());
577 res = client.updateItem(knownResourceId, knownItemResourceId, output);
578 statusCode = res.getStatus();
580 // Check the status code of the response: does it match the expected response(s)?
581 if(logger.isDebugEnabled()){
582 logger.debug("updateItem: status = " + statusCode);
584 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
585 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
586 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
588 // Retrieve the updated resource and verify that its contents exist.
589 input = (MultipartInput) res.getEntity();
590 updatedOrganization =
591 (OrganizationsCommon) extractPart(input,
592 client.getItemCommonPartName(), OrganizationsCommon.class);
593 Assert.assertNotNull(updatedOrganization);
595 // Verify that the updated resource received the correct data.
596 Assert.assertEquals(updatedOrganization.isDisplayNameComputed(), false,
597 "Updated displayNameComputed in Organization did not match submitted data.");
598 // Verify that the updated resource computes the right displayName.
599 Assert.assertEquals(updatedOrganization.getDisplayName(),
601 "Updated DisplayName (not computed) in Organization not stored.");
604 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
605 dependsOnMethods = {"verifyItemDisplayName"})
606 public void verifyIllegalItemDisplayName(String testName) throws Exception {
609 setupUpdateWithWrongXmlSchema(testName);
611 // Submit the request to the service and store the response.
612 OrgAuthorityClient client = new OrgAuthorityClient();
613 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
614 int statusCode = res.getStatus();
616 // Check the status code of the response: does it match
617 // the expected response(s)?
618 if(logger.isDebugEnabled()){
619 logger.debug(testName + ": status = " + statusCode);
621 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
622 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
623 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
625 // Check whether organization has expected displayName.
626 MultipartInput input = (MultipartInput) res.getEntity();
627 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
628 client.getItemCommonPartName(), OrganizationsCommon.class);
629 Assert.assertNotNull(organization);
630 // Try to Update with computed false and no displayName
631 organization.setDisplayNameComputed(false);
632 organization.setDisplayName(null);
634 // Submit the updated resource to the service and store the response.
635 MultipartOutput output = new MultipartOutput();
636 OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
637 commonPart.getHeaders().add("label", client.getItemCommonPartName());
638 res = client.updateItem(knownResourceId, knownItemResourceId, output);
639 statusCode = res.getStatus();
641 // Check the status code of the response: does it match the expected response(s)?
642 if(logger.isDebugEnabled()){
643 logger.debug("updateItem: status = " + statusCode);
645 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
646 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
647 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
650 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
651 groups = {"read"}, dependsOnMethods = {"readItem"})
652 public void readContact(String testName) throws Exception {
657 // Submit the request to the service and store the response.
658 OrgAuthorityClient client = new OrgAuthorityClient();
659 ClientResponse<MultipartInput> res =
660 client.readContact(knownResourceId, knownItemResourceId,
661 knownContactResourceId);
662 int statusCode = res.getStatus();
664 // Check the status code of the response: does it match
665 // the expected response(s)?
666 if(logger.isDebugEnabled()){
667 logger.debug(testName + ": status = " + statusCode);
669 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
670 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
671 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
673 // Check whether we've received a contact.
674 MultipartInput input = (MultipartInput) res.getEntity();
675 ContactsCommon contact = (ContactsCommon) extractPart(input,
676 new ContactClient().getCommonPartName(), ContactsCommon.class);
677 Assert.assertNotNull(contact);
678 boolean showFull = true;
679 if(showFull && logger.isDebugEnabled()){
680 logger.debug(testName + ": returned payload:");
681 logger.debug(objectAsXmlString(contact, ContactsCommon.class));
683 Assert.assertEquals(contact.getInAuthority(), knownResourceId);
684 Assert.assertEquals(contact.getInItem(), knownItemResourceId);
690 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
691 groups = {"read"}, dependsOnMethods = {"read"})
692 public void readNonExistent(String testName) {
695 setupReadNonExistent(testName);
697 // Submit the request to the service and store the response.
698 OrgAuthorityClient client = new OrgAuthorityClient();
699 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
700 int statusCode = res.getStatus();
702 // Check the status code of the response: does it match
703 // the expected response(s)?
704 if(logger.isDebugEnabled()){
705 logger.debug(testName + ": status = " + statusCode);
707 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
708 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
709 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
712 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
713 groups = {"read"}, dependsOnMethods = {"readItem"})
714 public void readItemNonExistent(String testName) {
717 setupReadNonExistent(testName);
719 // Submit the request to the service and store the response.
720 OrgAuthorityClient client = new OrgAuthorityClient();
721 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
722 int statusCode = res.getStatus();
724 // Check the status code of the response: does it match
725 // the expected response(s)?
726 if(logger.isDebugEnabled()){
727 logger.debug(testName + ": status = " + statusCode);
729 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
730 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
731 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
734 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
735 groups = {"read"}, dependsOnMethods = {"readContact"})
736 public void readContactNonExistent(String testName) {
739 setupReadNonExistent(testName);
741 // Submit the request to the service and store the response.
742 OrgAuthorityClient client = new OrgAuthorityClient();
743 ClientResponse<MultipartInput> res =
744 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
745 int statusCode = res.getStatus();
747 // Check the status code of the response: does it match
748 // the expected response(s)?
749 if(logger.isDebugEnabled()){
750 logger.debug(testName + ": status = " + statusCode);
752 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
753 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
754 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
757 // ---------------------------------------------------------------
758 // CRUD tests : READ_LIST tests
759 // ---------------------------------------------------------------
763 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
764 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
765 public void readList(String testName) throws Exception {
768 setupReadList(testName);
770 // Submit the request to the service and store the response.
771 OrgAuthorityClient client = new OrgAuthorityClient();
772 ClientResponse<OrgauthoritiesCommonList> res = client.readList();
773 OrgauthoritiesCommonList list = res.getEntity();
774 int statusCode = res.getStatus();
776 // Check the status code of the response: does it match
777 // the expected response(s)?
778 if(logger.isDebugEnabled()){
779 logger.debug(testName + ": status = " + statusCode);
781 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
782 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
783 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
785 // Optionally output additional data about list members for debugging.
786 boolean iterateThroughList = false;
787 if (iterateThroughList && logger.isDebugEnabled()) {
788 List<OrgauthoritiesCommonList.OrgauthorityListItem> items =
789 list.getOrgauthorityListItem();
791 for (OrgauthoritiesCommonList.OrgauthorityListItem item : items) {
792 String csid = item.getCsid();
793 logger.debug(testName + ": list-item[" + i + "] csid=" +
795 logger.debug(testName + ": list-item[" + i + "] displayName=" +
796 item.getDisplayName());
797 logger.debug(testName + ": list-item[" + i + "] URI=" +
799 readItemList(csid, null);
805 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
806 public void readItemList() {
807 readItemList(knownResourceId, null);
810 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
811 public void readItemListByAuthorityName() {
812 readItemList(null, knownResourceDisplayName);
815 private void readItemList(String vcsid, String name) {
817 final String testName = "readItemList";
820 setupReadList(testName);
822 // Submit the request to the service and store the response.
823 OrgAuthorityClient client = new OrgAuthorityClient();
824 ClientResponse<OrganizationsCommonList> res = null;
826 res = client.readItemList(vcsid);
827 } else if(name!= null) {
828 res = client.readItemListForNamedAuthority(name);
830 Assert.fail("readItemList passed null csid and name!");
832 OrganizationsCommonList list = res.getEntity();
833 int statusCode = res.getStatus();
835 // Check the status code of the response: does it match
836 // the expected response(s)?
837 if(logger.isDebugEnabled()){
838 logger.debug(testName + ": status = " + statusCode);
840 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
841 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
842 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
844 List<OrganizationsCommonList.OrganizationListItem> items =
845 list.getOrganizationListItem();
846 int nItemsReturned = items.size();
847 // There will be one item created, associated with a
848 // known parent resource, by the createItem test.
850 // In addition, there will be 'nItemsToCreateInList'
851 // additional items created by the createItemList test,
852 // all associated with the same parent resource.
853 int nExpectedItems = nItemsToCreateInList + 1;
854 if(logger.isDebugEnabled()){
855 logger.debug(testName + ": Expected "
856 + nExpectedItems +" items; got: "+nItemsReturned);
858 Assert.assertEquals(nItemsReturned, nExpectedItems);
861 for (OrganizationsCommonList.OrganizationListItem item : items) {
862 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
863 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
864 // Optionally output additional data about list members for debugging.
865 boolean showDetails = true;
866 if (showDetails && logger.isDebugEnabled()) {
867 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
869 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
871 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
872 item.getDisplayName());
873 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
880 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
881 public void readContactList() {
882 readContactList(knownResourceId, knownItemResourceId);
885 private void readContactList(String parentcsid, String itemcsid) {
886 final String testName = "readContactList";
889 setupReadList(testName);
891 // Submit the request to the service and store the response.
892 OrgAuthorityClient client = new OrgAuthorityClient();
893 ClientResponse<ContactsCommonList> res =
894 client.readContactList(parentcsid, itemcsid);
895 ContactsCommonList list = res.getEntity();
896 int statusCode = res.getStatus();
898 // Check the status code of the response: does it match
899 // the expected response(s)?
900 if(logger.isDebugEnabled()){
901 logger.debug(testName + ": status = " + statusCode);
903 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
904 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
905 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
907 List<ContactsCommonList.ContactListItem> listitems =
908 list.getContactListItem();
909 int nItemsReturned = listitems.size();
910 // There will be one item created, associated with a
911 // known parent resource, by the createItem test.
913 // In addition, there will be 'nItemsToCreateInList'
914 // additional items created by the createItemList test,
915 // all associated with the same parent resource.
916 int nExpectedItems = nItemsToCreateInList + 1;
917 if(logger.isDebugEnabled()){
918 logger.debug(testName + ": Expected "
919 + nExpectedItems +" items; got: "+nItemsReturned);
921 Assert.assertEquals(nItemsReturned, nExpectedItems);
924 for (ContactsCommonList.ContactListItem listitem : listitems) {
925 // Optionally output additional data about list members for debugging.
926 boolean showDetails = false;
927 if (showDetails && logger.isDebugEnabled()) {
928 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
930 logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" +
931 listitem.getAddressPlace());
932 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
942 // ---------------------------------------------------------------
943 // CRUD tests : UPDATE tests
944 // ---------------------------------------------------------------
947 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
948 groups = {"update"}, dependsOnGroups = {"read", "readList"})
949 public void update(String testName) throws Exception {
952 setupUpdate(testName);
954 // Retrieve the contents of a resource to update.
955 OrgAuthorityClient client = new OrgAuthorityClient();
956 ClientResponse<MultipartInput> res =
957 client.read(knownResourceId);
958 if(logger.isDebugEnabled()){
959 logger.debug(testName + ": read status = " + res.getStatus());
961 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
963 if(logger.isDebugEnabled()){
964 logger.debug("got OrgAuthority to update with ID: " + knownResourceId);
966 MultipartInput input = (MultipartInput) res.getEntity();
967 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
968 client.getCommonPartName(), OrgauthoritiesCommon.class);
969 Assert.assertNotNull(orgAuthority);
971 // Update the contents of this resource.
972 orgAuthority.setDisplayName("updated-" + orgAuthority.getDisplayName());
973 orgAuthority.setVocabType("updated-" + orgAuthority.getVocabType());
974 if(logger.isDebugEnabled()){
975 logger.debug("to be updated OrgAuthority");
976 logger.debug(objectAsXmlString(orgAuthority, OrgauthoritiesCommon.class));
979 // Submit the updated resource to the service and store the response.
980 MultipartOutput output = new MultipartOutput();
981 OutputPart commonPart = output.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE);
982 commonPart.getHeaders().add("label", client.getCommonPartName());
983 res = client.update(knownResourceId, output);
984 int statusCode = res.getStatus();
986 // Check the status code of the response: does it match the expected response(s)?
987 if(logger.isDebugEnabled()){
988 logger.debug(testName + ": status = " + statusCode);
990 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
991 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
992 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
994 // Retrieve the updated resource and verify that its contents exist.
995 input = (MultipartInput) res.getEntity();
996 OrgauthoritiesCommon updatedOrgAuthority =
997 (OrgauthoritiesCommon) extractPart(input,
998 client.getCommonPartName(), OrgauthoritiesCommon.class);
999 Assert.assertNotNull(updatedOrgAuthority);
1001 // Verify that the updated resource received the correct data.
1002 Assert.assertEquals(updatedOrgAuthority.getDisplayName(),
1003 orgAuthority.getDisplayName(),
1004 "Data in updated object did not match submitted data.");
1007 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1008 groups = {"update"}, dependsOnMethods = {"update"})
1009 public void updateItem(String testName) throws Exception {
1012 setupUpdate(testName);
1014 // Retrieve the contents of a resource to update.
1015 OrgAuthorityClient client = new OrgAuthorityClient();
1016 ClientResponse<MultipartInput> res =
1017 client.readItem(knownResourceId, knownItemResourceId);
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 Organization to update with ID: " +
1025 knownItemResourceId +
1026 " in OrgAuthority: " + knownResourceId );
1028 MultipartInput input = (MultipartInput) res.getEntity();
1029 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
1030 client.getItemCommonPartName(), OrganizationsCommon.class);
1031 Assert.assertNotNull(organization);
1033 // Update the contents of this resource.
1034 organization.setCsid(null);
1035 organization.setShortName("updated-" + organization.getShortName());
1036 if(logger.isDebugEnabled()){
1037 logger.debug("to be updated Organization");
1038 logger.debug(objectAsXmlString(organization,
1039 OrganizationsCommon.class));
1042 // Submit the updated resource to the service and store the response.
1043 MultipartOutput output = new MultipartOutput();
1044 OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
1045 commonPart.getHeaders().add("label", client.getItemCommonPartName());
1046 res = client.updateItem(knownResourceId, knownItemResourceId, 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 OrganizationsCommon updatedOrganization =
1060 (OrganizationsCommon) extractPart(input,
1061 client.getItemCommonPartName(), OrganizationsCommon.class);
1062 Assert.assertNotNull(updatedOrganization);
1064 // Verify that the updated resource received the correct data.
1065 Assert.assertEquals(updatedOrganization.getShortName(),
1066 organization.getShortName(),
1067 "Data in updated Organization did not match submitted data.");
1070 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1071 groups = {"update"}, dependsOnMethods = {"updateItem"})
1072 public void updateContact(String testName) throws Exception {
1075 setupUpdate(testName);
1077 // Retrieve the contents of a resource to update.
1078 OrgAuthorityClient client = new OrgAuthorityClient();
1079 ClientResponse<MultipartInput> res =
1080 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1081 if(logger.isDebugEnabled()){
1082 logger.debug(testName + ": read status = " + res.getStatus());
1084 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1086 if(logger.isDebugEnabled()){
1087 logger.debug("got Contact to update with ID: " +
1088 knownContactResourceId +
1089 " in item: " + knownItemResourceId +
1090 " in parent: " + knownResourceId );
1092 MultipartInput input = (MultipartInput) res.getEntity();
1093 ContactsCommon contact = (ContactsCommon) extractPart(input,
1094 new ContactClient().getCommonPartName(), ContactsCommon.class);
1095 Assert.assertNotNull(contact);
1097 // Update the contents of this resource.
1098 contact.setAddressPlace("updated-" + contact.getAddressPlace());
1099 if(logger.isDebugEnabled()){
1100 logger.debug("to be updated Contact");
1101 logger.debug(objectAsXmlString(contact,
1102 ContactsCommon.class));
1105 // Submit the updated resource to the service and store the response.
1106 MultipartOutput output = new MultipartOutput();
1107 OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1108 commonPart.getHeaders().add("label", new ContactClient().getCommonPartName());
1109 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1110 int statusCode = res.getStatus();
1112 // Check the status code of the response: does it match the expected response(s)?
1113 if(logger.isDebugEnabled()){
1114 logger.debug(testName + ": status = " + statusCode);
1116 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1117 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1118 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1120 // Retrieve the updated resource and verify that its contents exist.
1121 input = (MultipartInput) res.getEntity();
1122 ContactsCommon updatedContact =
1123 (ContactsCommon) extractPart(input,
1124 new ContactClient().getCommonPartName(), ContactsCommon.class);
1125 Assert.assertNotNull(updatedContact);
1127 // Verify that the updated resource received the correct data.
1128 Assert.assertEquals(updatedContact.getAddressPlace(),
1129 contact.getAddressPlace(),
1130 "Data in updated Contact did not match submitted data.");
1134 // Placeholders until the three tests below can be uncommented.
1135 // See Issue CSPACE-401.
1137 public void updateWithEmptyEntityBody(String testName) throws Exception {
1141 public void updateWithMalformedXml(String testName) throws Exception {
1145 public void updateWithWrongXmlSchema(String testName) throws Exception {
1150 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1151 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1152 public void updateWithEmptyEntityBody(String testName) throws Exception {
1155 setupUpdateWithEmptyEntityBody(testName);
1157 // Submit the request to the service and store the response.
1158 String method = REQUEST_TYPE.httpMethodName();
1159 String url = getResourceURL(knownResourceId);
1160 String mediaType = MediaType.APPLICATION_XML;
1161 final String entity = "";
1162 int statusCode = submitRequest(method, url, mediaType, entity);
1164 // Check the status code of the response: does it match
1165 // the expected response(s)?
1166 if(logger.isDebugEnabled()){
1167 logger.debug(testName + ": url=" + url +
1168 " status=" + statusCode);
1170 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1171 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1172 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1176 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1177 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1178 public void updateWithMalformedXml(String testName) throws Exception {
1181 setupUpdateWithMalformedXml(testName);
1183 // Submit the request to the service and store the response.
1184 String method = REQUEST_TYPE.httpMethodName();
1185 String url = getResourceURL(knownResourceId);
1186 String mediaType = MediaType.APPLICATION_XML;
1187 final String entity = MALFORMED_XML_DATA;
1188 int statusCode = submitRequest(method, url, mediaType, entity);
1190 // Check the status code of the response: does it match
1191 // the expected response(s)?
1192 if(logger.isDebugEnabled()){
1193 logger.debug(testName + ": url=" + url +
1194 " status=" + statusCode);
1196 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1197 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1198 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1202 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1203 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1204 public void updateWithWrongXmlSchema(String testName) throws Exception {
1207 setupUpdateWithWrongXmlSchema(testName);
1209 // Submit the request to the service and store the response.
1210 String method = REQUEST_TYPE.httpMethodName();
1211 String url = getResourceURL(knownResourceId);
1212 String mediaType = MediaType.APPLICATION_XML;
1213 final String entity = WRONG_XML_SCHEMA_DATA;
1214 int statusCode = submitRequest(method, url, mediaType, entity);
1216 // Check the status code of the response: does it match
1217 // the expected response(s)?
1218 if(logger.isDebugEnabled()){
1219 logger.debug("updateWithWrongXmlSchema: url=" + url +
1220 " status=" + statusCode);
1222 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1223 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1224 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1229 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1230 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1231 public void updateNonExistent(String testName) throws Exception {
1234 setupUpdateNonExistent(testName);
1236 // Submit the request to the service and store the response.
1237 // Note: The ID used in this 'create' call may be arbitrary.
1238 // The only relevant ID may be the one used in update(), below.
1239 OrgAuthorityClient client = new OrgAuthorityClient();
1240 MultipartOutput multipart = createOrgAuthorityInstance(NON_EXISTENT_ID);
1241 ClientResponse<MultipartInput> res =
1242 client.update(NON_EXISTENT_ID, multipart);
1243 int statusCode = res.getStatus();
1245 // Check the status code of the response: does it match
1246 // the expected response(s)?
1247 if(logger.isDebugEnabled()){
1248 logger.debug(testName + ": status = " + statusCode);
1250 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1251 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1252 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1255 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1256 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1257 public void updateNonExistentItem(String testName) throws Exception {
1260 setupUpdateNonExistent(testName);
1262 // Submit the request to the service and store the response.
1263 // Note: The ID(s) used when creating the request payload may be arbitrary.
1264 // The only relevant ID may be the one used in update(), below.
1265 OrgAuthorityClient client = new OrgAuthorityClient();
1266 Map<String, String> nonexOrgMap = new HashMap<String,String>();
1267 nonexOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Non-existent");
1268 String refName = OrgAuthorityClientUtils.createOrganizationRefName(knownResourceRefName, NON_EXISTENT_ID, true);
1269 MultipartOutput multipart =
1270 OrgAuthorityClientUtils.createOrganizationInstance(
1271 NON_EXISTENT_ID, refName,
1272 nonexOrgMap, client.getItemCommonPartName() );
1273 ClientResponse<MultipartInput> res =
1274 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1275 int statusCode = res.getStatus();
1277 // Check the status code of the response: does it match
1278 // the expected response(s)?
1279 if(logger.isDebugEnabled()){
1280 logger.debug(testName + ": status = " + statusCode);
1282 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1283 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1284 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1287 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1288 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1289 public void updateNonExistentContact(String testName) throws Exception {
1290 // Currently a no-op test
1293 // ---------------------------------------------------------------
1294 // CRUD tests : DELETE tests
1295 // ---------------------------------------------------------------
1298 // Note: delete sub-resources in ascending hierarchical order,
1299 // before deleting their parents.
1301 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1302 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1303 public void deleteContact(String testName) throws Exception {
1306 setupDelete(testName);
1308 if(logger.isDebugEnabled()){
1309 logger.debug("parentcsid =" + knownResourceId +
1310 " itemcsid = " + knownItemResourceId +
1311 " csid = " + knownContactResourceId);
1314 // Submit the request to the service and store the response.
1315 OrgAuthorityClient client = new OrgAuthorityClient();
1316 ClientResponse<Response> res =
1317 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1318 int statusCode = res.getStatus();
1320 // Check the status code of the response: does it match
1321 // the expected response(s)?
1322 if(logger.isDebugEnabled()){
1323 logger.debug(testName + ": status = " + statusCode);
1325 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1326 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1327 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1330 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1331 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1332 public void deleteItem(String testName) throws Exception {
1335 setupDelete(testName);
1337 if(logger.isDebugEnabled()){
1338 logger.debug("parentcsid =" + knownResourceId +
1339 " itemcsid = " + knownItemResourceId);
1342 // Submit the request to the service and store the response.
1343 OrgAuthorityClient client = new OrgAuthorityClient();
1344 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1345 int statusCode = res.getStatus();
1347 // Check the status code of the response: does it match
1348 // the expected response(s)?
1349 if(logger.isDebugEnabled()){
1350 logger.debug(testName + ": status = " + statusCode);
1352 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1353 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1354 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1358 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1359 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1360 public void delete(String testName) throws Exception {
1363 setupDelete(testName);
1365 if(logger.isDebugEnabled()){
1366 logger.debug("parentcsid =" + knownResourceId);
1369 // Submit the request to the service and store the response.
1370 OrgAuthorityClient client = new OrgAuthorityClient();
1371 ClientResponse<Response> res = client.delete(knownResourceId);
1372 int statusCode = res.getStatus();
1374 // Check the status code of the response: does it match
1375 // the expected response(s)?
1376 if(logger.isDebugEnabled()){
1377 logger.debug(testName + ": status = " + statusCode);
1379 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1380 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1381 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1386 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1387 groups = {"delete"}, dependsOnMethods = {"delete"})
1388 public void deleteNonExistent(String testName) throws Exception {
1391 setupDeleteNonExistent(testName);
1393 // Submit the request to the service and store the response.
1394 OrgAuthorityClient client = new OrgAuthorityClient();
1395 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1396 int statusCode = res.getStatus();
1398 // Check the status code of the response: does it match
1399 // the expected response(s)?
1400 if(logger.isDebugEnabled()){
1401 logger.debug(testName + ": status = " + statusCode);
1403 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1404 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1405 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1408 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1409 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1410 public void deleteNonExistentItem(String testName) {
1413 setupDeleteNonExistent(testName);
1415 // Submit the request to the service and store the response.
1416 OrgAuthorityClient client = new OrgAuthorityClient();
1417 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1418 int statusCode = res.getStatus();
1420 // Check the status code of the response: does it match
1421 // the expected response(s)?
1422 if(logger.isDebugEnabled()){
1423 logger.debug(testName + ": status = " + statusCode);
1425 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1426 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1427 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1430 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1431 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1432 public void deleteNonExistentContact(String testName) {
1435 setupDeleteNonExistent(testName);
1437 // Submit the request to the service and store the response.
1438 OrgAuthorityClient client = new OrgAuthorityClient();
1439 ClientResponse<Response> res =
1440 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1441 int statusCode = res.getStatus();
1443 // Check the status code of the response: does it match
1444 // the expected response(s)?
1445 if(logger.isDebugEnabled()){
1446 logger.debug(testName + ": status = " + statusCode);
1448 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1449 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1450 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1453 // ---------------------------------------------------------------
1454 // Utility tests : tests of code used in tests above
1455 // ---------------------------------------------------------------
1457 * Tests the code for manually submitting data that is used by several
1458 * of the methods above.
1460 @Test(dependsOnMethods = {"create", "read"})
1461 public void testSubmitRequest() {
1463 // Expected status code: 200 OK
1464 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1466 // Submit the request to the service and store the response.
1467 String method = ServiceRequestType.READ.httpMethodName();
1468 String url = getResourceURL(knownResourceId);
1469 int statusCode = submitRequest(method, url);
1471 // Check the status code of the response: does it match
1472 // the expected response(s)?
1473 if(logger.isDebugEnabled()){
1474 logger.debug("testSubmitRequest: url=" + url +
1475 " status=" + statusCode);
1477 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1481 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1482 public void testItemSubmitRequest() {
1484 // Expected status code: 200 OK
1485 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1487 // Submit the request to the service and store the response.
1488 String method = ServiceRequestType.READ.httpMethodName();
1489 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1490 int statusCode = submitRequest(method, url);
1492 // Check the status code of the response: does it match
1493 // the expected response(s)?
1494 if(logger.isDebugEnabled()){
1495 logger.debug("testItemSubmitRequest: url=" + url +
1496 " status=" + statusCode);
1498 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1502 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
1503 public void testContactSubmitRequest() {
1505 // Expected status code: 200 OK
1506 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1508 // Submit the request to the service and store the response.
1509 String method = ServiceRequestType.READ.httpMethodName();
1510 String url = getContactResourceURL(knownResourceId,
1511 knownItemResourceId, knownContactResourceId);
1512 int statusCode = submitRequest(method, url);
1514 // Check the status code of the response: does it match
1515 // the expected response(s)?
1516 if(logger.isDebugEnabled()){
1517 logger.debug("testItemSubmitRequest: url=" + url +
1518 " status=" + statusCode);
1520 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1525 // ---------------------------------------------------------------
1526 // Cleanup of resources created during testing
1527 // ---------------------------------------------------------------
1530 * Deletes all resources created by tests, after all tests have been run.
1532 * This cleanup method will always be run, even if one or more tests fail.
1533 * For this reason, it attempts to remove all resources created
1534 * at any point during testing, even if some of those resources
1535 * may be expected to be deleted by certain tests.
1538 @AfterClass(alwaysRun=true)
1539 public void cleanUp() {
1540 String noTest = System.getProperty("noTestCleanup");
1541 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1542 if (logger.isDebugEnabled()) {
1543 logger.debug("Skipping Cleanup phase ...");
1547 if (logger.isDebugEnabled()) {
1548 logger.debug("Cleaning up temporary resources created for testing ...");
1550 String parentResourceId;
1551 String itemResourceId;
1552 String contactResourceId;
1553 // Clean up contact resources.
1554 parentResourceId = knownResourceId;
1555 OrgAuthorityClient client = new OrgAuthorityClient();
1556 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
1557 contactResourceId = entry.getKey();
1558 itemResourceId = entry.getValue();
1559 // Note: Any non-success responses from the delete operation
1560 // below are ignored and not reported.
1561 ClientResponse<Response> res =
1562 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
1564 // Clean up item resources.
1565 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1566 itemResourceId = entry.getKey();
1567 parentResourceId = entry.getValue();
1568 // Note: Any non-success responses from the delete operation
1569 // below are ignored and not reported.
1570 ClientResponse<Response> res =
1571 client.deleteItem(parentResourceId, itemResourceId);
1573 // Clean up parent resources.
1574 for (String resourceId : allResourceIdsCreated) {
1575 // Note: Any non-success responses from the delete operation
1576 // below are ignored and not reported.
1577 ClientResponse<Response> res = client.delete(resourceId);
1581 // ---------------------------------------------------------------
1582 // Utility methods used by tests above
1583 // ---------------------------------------------------------------
1585 public String getServicePathComponent() {
1586 return SERVICE_PATH_COMPONENT;
1589 public String getItemServicePathComponent() {
1590 return ITEM_SERVICE_PATH_COMPONENT;
1593 public String getContactServicePathComponent() {
1594 return CONTACT_SERVICE_PATH_COMPONENT;
1598 * Returns the root URL for the item service.
1600 * This URL consists of a base URL for all services, followed by
1601 * a path component for the owning parent, followed by the
1602 * path component for the items.
1604 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1605 * parent authority resource of the relevant item resource.
1607 * @return The root URL for the item service.
1609 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1610 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1614 * Returns the URL of a specific item resource managed by a service, and
1615 * designated by an identifier (such as a universally unique ID, or UUID).
1617 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1618 * parent authority resource of the relevant item resource.
1620 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1623 * @return The URL of a specific item resource managed by a service.
1625 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1626 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
1631 * Returns the root URL for the contact service.
1633 * This URL consists of a base URL for all services, followed by
1634 * a path component for the owning authority, followed by the
1635 * path component for the owning item, followed by the path component
1636 * for the contact service.
1638 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1639 * parent authority resource of the relevant item resource.
1641 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1644 * @return The root URL for the contact service.
1646 protected String getContactServiceRootURL(String parentResourceIdentifier,
1647 String itemResourceIdentifier) {
1648 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
1649 getContactServicePathComponent();
1653 * Returns the URL of a specific contact resource managed by a service, and
1654 * designated by an identifier (such as a universally unique ID, or UUID).
1656 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1657 * parent resource of the relevant item resource.
1659 * @param resourceIdentifier An identifier (such as a UUID) for an
1662 * @return The URL of a specific resource managed by a service.
1664 protected String getContactResourceURL(String parentResourceIdentifier,
1665 String itemResourceIdentifier, String contactResourceIdentifier) {
1666 return getContactServiceRootURL(parentResourceIdentifier,
1667 itemResourceIdentifier) + "/" + contactResourceIdentifier;
1670 private MultipartOutput createOrgAuthorityInstance(String identifier) {
1671 String displayName = "displayName-" + identifier;
1672 String refName = OrgAuthorityClientUtils.createOrgAuthRefName(displayName, true);
1673 return OrgAuthorityClientUtils.createOrgAuthorityInstance(
1674 displayName, refName,
1675 new OrgAuthorityClient().getCommonPartName());