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.CollectionSpaceClient;
34 import org.collectionspace.services.client.ContactClient;
35 import org.collectionspace.services.client.ContactClientUtils;
36 import org.collectionspace.services.contact.ContactsCommon;
37 import org.collectionspace.services.contact.ContactsCommonList;
38 import org.collectionspace.services.client.OrgAuthorityClient;
39 import org.collectionspace.services.client.OrgAuthorityClientUtils;
40 import org.collectionspace.services.jaxb.AbstractCommonList;
41 import org.collectionspace.services.organization.OrgauthoritiesCommon;
42 import org.collectionspace.services.organization.OrgauthoritiesCommonList;
43 import org.collectionspace.services.organization.OrganizationsCommon;
44 import org.collectionspace.services.organization.OrganizationsCommonList;
46 import org.jboss.resteasy.client.ClientResponse;
47 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
48 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
49 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
50 import org.slf4j.Logger;
51 import org.slf4j.LoggerFactory;
52 import org.testng.Assert;
53 import org.testng.annotations.AfterClass;
54 import org.testng.annotations.Test;
57 * OrgAuthorityServiceTest, carries out tests against a
58 * deployed and running OrgAuthority Service.
60 * $LastChangedRevision: 753 $
61 * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
63 public class OrgAuthorityServiceTest extends AbstractServiceTestImpl {
65 private final Logger logger =
66 LoggerFactory.getLogger(OrgAuthorityServiceTest.class);
68 // Instance variables specific to this test.
69 final String SERVICE_PATH_COMPONENT = "orgauthorities";
70 final String ITEM_SERVICE_PATH_COMPONENT = "items";
71 final String CONTACT_SERVICE_PATH_COMPONENT = "contacts";
72 private final String TEST_ORG_SHORTNAME = "Test Org";
73 private final String TEST_ORG_FOUNDING_PLACE = "Anytown, USA";
74 private String knownResourceId = null;
75 private String knownResourceDisplayName = null;
76 private String knownResourceRefName = null;
77 private String knownItemResourceId = null;
78 private String knownContactResourceId = null;
79 private int nItemsToCreateInList = 3;
80 private List<String> allResourceIdsCreated = new ArrayList<String>();
81 private Map<String, String> allItemResourceIdsCreated =
82 new HashMap<String, String>();
83 private Map<String, String> allContactResourceIdsCreated =
84 new HashMap<String, String>();
87 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
90 protected CollectionSpaceClient getClientInstance() {
91 return new OrgAuthorityClient();
95 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
98 protected AbstractCommonList getAbstractCommonList(
99 ClientResponse<AbstractCommonList> response) {
100 return response.getEntity(OrganizationsCommonList.class);
103 // ---------------------------------------------------------------
104 // CRUD tests : CREATE tests
105 // ---------------------------------------------------------------
108 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
110 public void create(String testName) throws Exception {
112 // Perform setup, such as initializing the type of service request
113 // (e.g. CREATE, DELETE), its valid and expected status codes, and
114 // its associated HTTP method name (e.g. POST, DELETE).
115 setupCreate(testName);
117 // Submit the request to the service and store the response.
118 OrgAuthorityClient client = new OrgAuthorityClient();
119 String identifier = createIdentifier();
120 String displayName = "displayName-" + identifier;
121 String refName = OrgAuthorityClientUtils.createOrgAuthRefName(displayName, true);
122 MultipartOutput multipart =
123 OrgAuthorityClientUtils.createOrgAuthorityInstance(
124 displayName, refName, client.getCommonPartName());
125 ClientResponse<Response> res = client.create(multipart);
126 int statusCode = res.getStatus();
128 // Check the status code of the response: does it match
129 // the expected response(s)?
132 // Does it fall within the set of valid status codes?
133 // Does it exactly match the expected status code?
134 if(logger.isDebugEnabled()){
135 logger.debug(testName + ": status = " + statusCode);
137 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
138 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
139 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
141 // Store the refname from the first resource created
142 // for additional tests below.
143 knownResourceRefName = refName;
145 String newID = OrgAuthorityClientUtils.extractId(res);
146 // Store the ID returned from the first resource created
147 // for additional tests below.
148 if (knownResourceId == null){
149 knownResourceId = newID;
150 knownResourceDisplayName = displayName;
151 if (logger.isDebugEnabled()) {
152 logger.debug(testName + ": knownResourceId=" + knownResourceId);
155 // Store the IDs from every resource created by tests,
156 // so they can be deleted after tests have been run.
157 allResourceIdsCreated.add(newID);
160 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
161 groups = {"create"}, dependsOnMethods = {"create"})
162 public void createItem(String testName) {
163 setupCreate(testName);
164 String newID = createItemInAuthority(knownResourceId, knownResourceRefName);
167 private String createItemInAuthority(String vcsid, String authRefName) {
169 final String testName = "createItemInAuthority";
170 if(logger.isDebugEnabled()){
171 logger.debug(testName + ":...");
174 // Submit the request to the service and store the response.
175 OrgAuthorityClient client = new OrgAuthorityClient();
176 String identifier = createIdentifier();
177 String refName = OrgAuthorityClientUtils.createOrganizationRefName(knownResourceRefName, identifier, true);
178 Map<String, String> testOrgMap = new HashMap<String,String>();
179 testOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, TEST_ORG_SHORTNAME);
180 testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "The real official test organization");
181 testOrgMap.put(OrganizationJAXBSchema.CONTACT_NAME, "joe@test.org");
182 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "May 26, 1907");
183 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, TEST_ORG_FOUNDING_PLACE);
184 testOrgMap.put(OrganizationJAXBSchema.FUNCTION, "For testing");
185 String newID = OrgAuthorityClientUtils.createItemInAuthority(
186 vcsid, authRefName, testOrgMap, client);
187 // Store the ID returned from the first item resource created
188 // for additional tests below.
189 if (knownItemResourceId == null){
190 knownItemResourceId = newID;
191 if (logger.isDebugEnabled()) {
192 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
196 // Store the IDs from any item resources created
197 // by tests, along with the IDs of their parents, so these items
198 // can be deleted after all tests have been run.
199 allItemResourceIdsCreated.put(newID, vcsid);
204 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
205 groups = {"create"}, dependsOnMethods = {"createItem"})
206 public void createContact(String testName) {
207 setupCreate(testName);
208 String newID = createContactInItem(knownResourceId, knownItemResourceId);
211 private String createContactInItem(String parentcsid, String itemcsid) {
213 final String testName = "createContactInItem";
214 setupCreate(testName);
215 if(logger.isDebugEnabled()){
216 logger.debug(testName + ":...");
219 // Submit the request to the service and store the response.
220 OrgAuthorityClient client = new OrgAuthorityClient();
221 String identifier = createIdentifier();
222 MultipartOutput multipart =
223 ContactClientUtils.createContactInstance(parentcsid,
224 itemcsid, identifier, new ContactClient().getCommonPartName());
225 ClientResponse<Response> res =
226 client.createContact(parentcsid, itemcsid, multipart);
227 int statusCode = res.getStatus();
228 String newID = OrgAuthorityClientUtils.extractId(res);
230 // Check the status code of the response: does it match
231 // the expected response(s)?
232 if(logger.isDebugEnabled()){
233 logger.debug(testName + ": status = " + statusCode);
235 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
236 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
237 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
239 // Store the ID returned from the first contact resource created
240 // for additional tests below.
241 if (knownContactResourceId == null){
242 knownContactResourceId = newID;
243 if (logger.isDebugEnabled()) {
244 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
248 // Store the IDs from any contact resources created
249 // by tests, along with the IDs of their parent items,
250 // so these items can be deleted after all tests have been run.
251 allContactResourceIdsCreated.put(newID, itemcsid);
258 // Placeholders until the three tests below can be uncommented.
259 // See Issue CSPACE-401.
261 public void createWithEmptyEntityBody(String testName) throws Exception {
265 public void createWithMalformedXml(String testName) throws Exception {
269 public void createWithWrongXmlSchema(String testName) throws Exception {
274 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
275 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
276 public void createWithEmptyEntityBody(String testName) throws Exception {
279 setupCreateWithEmptyEntityBody(testName);
281 // Submit the request to the service and store the response.
282 String method = REQUEST_TYPE.httpMethodName();
283 String url = getServiceRootURL();
284 String mediaType = MediaType.APPLICATION_XML;
285 final String entity = "";
286 int statusCode = submitRequest(method, url, mediaType, entity);
288 // Check the status code of the response: does it match
289 // the expected response(s)?
290 if(logger.isDebugEnabled()) {
291 logger.debug(testName + ": url=" + url +
292 " status=" + statusCode);
294 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
295 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
296 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
300 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
301 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
302 public void createWithMalformedXml(String testName) throws Exception {
305 setupCreateWithMalformedXml(testName);
307 // Submit the request to the service and store the response.
308 String method = REQUEST_TYPE.httpMethodName();
309 String url = getServiceRootURL();
310 String mediaType = MediaType.APPLICATION_XML;
311 final String entity = MALFORMED_XML_DATA; // Constant from base class.
312 int statusCode = submitRequest(method, url, mediaType, entity);
314 // Check the status code of the response: does it match
315 // the expected response(s)?
316 if(logger.isDebugEnabled()){
317 logger.debug(testName + ": url=" + url +
318 " status=" + statusCode);
320 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
321 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
322 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
326 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
327 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
328 public void createWithWrongXmlSchema(String testName) throws Exception {
331 setupCreateWithWrongXmlSchema(testName);
333 // Submit the request to the service and store the response.
334 String method = REQUEST_TYPE.httpMethodName();
335 String url = getServiceRootURL();
336 String mediaType = MediaType.APPLICATION_XML;
337 final String entity = WRONG_XML_SCHEMA_DATA;
338 int statusCode = submitRequest(method, url, mediaType, entity);
340 // Check the status code of the response: does it match
341 // the expected response(s)?
342 if(logger.isDebugEnabled()){
343 logger.debug(testName + ": url=" + url +
344 " status=" + statusCode);
346 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
347 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
348 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
352 // ---------------------------------------------------------------
353 // CRUD tests : CREATE LIST tests
354 // ---------------------------------------------------------------
357 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
358 groups = {"createList"}, dependsOnGroups = {"create"})
359 public void createList(String testName) throws Exception {
360 for (int i = 0; i < nItemsToCreateInList; i++) {
365 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
366 groups = {"createList"}, dependsOnMethods = {"createList"})
367 public void createItemList(String testName) throws Exception {
368 // Add items to the initially-created, known parent record.
369 for (int j = 0; j < nItemsToCreateInList; j++) {
370 createItem(testName);
374 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
375 groups = {"createList"}, dependsOnMethods = {"createItemList"})
376 public void createContactList(String testName) throws Exception {
377 // Add contacts to the initially-created, known item record.
378 for (int j = 0; j < nItemsToCreateInList; j++) {
379 createContact(testName);
383 // ---------------------------------------------------------------
384 // CRUD tests : READ tests
385 // ---------------------------------------------------------------
388 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
389 groups = {"read"}, dependsOnGroups = {"create"})
390 public void read(String testName) throws Exception {
395 // Submit the request to the service and store the response.
396 OrgAuthorityClient client = new OrgAuthorityClient();
397 ClientResponse<MultipartInput> res = client.read(knownResourceId);
398 int statusCode = res.getStatus();
400 // Check the status code of the response: does it match
401 // the expected response(s)?
402 if(logger.isDebugEnabled()){
403 logger.debug(testName + ": status = " + statusCode);
405 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
406 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
407 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
408 //FIXME: remove the following try catch once Aron fixes signatures
410 MultipartInput input = (MultipartInput) res.getEntity();
411 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
412 client.getCommonPartName(), OrgauthoritiesCommon.class);
413 Assert.assertNotNull(orgAuthority);
414 } catch (Exception e) {
415 throw new RuntimeException(e);
419 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
420 groups = {"read"}, dependsOnGroups = {"create"})
421 public void readByName(String testName) throws Exception {
426 // Submit the request to the service and store the response.
427 OrgAuthorityClient client = new OrgAuthorityClient();
428 ClientResponse<MultipartInput> res = client.readByName(knownResourceDisplayName);
429 int statusCode = res.getStatus();
431 // Check the status code of the response: does it match
432 // the expected response(s)?
433 if(logger.isDebugEnabled()){
434 logger.debug(testName + ": status = " + statusCode);
436 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
437 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
438 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
439 //FIXME: remove the following try catch once Aron fixes signatures
441 MultipartInput input = (MultipartInput) res.getEntity();
442 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
443 new OrgAuthorityClient().getCommonPartName(), OrgauthoritiesCommon.class);
444 Assert.assertNotNull(orgAuthority);
445 } catch (Exception e) {
446 throw new RuntimeException(e);
451 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
452 groups = {"read"}, dependsOnMethods = {"read"})
453 public void readByName(String testName) throws Exception {
458 // Submit the request to the service and store the response.
459 ClientResponse<MultipartInput> res = client.read(knownResourceId);
460 int statusCode = res.getStatus();
462 // Check the status code of the response: does it match
463 // the expected response(s)?
464 if(logger.isDebugEnabled()){
465 logger.debug(testName + ": status = " + statusCode);
467 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
468 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
469 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
470 //FIXME: remove the following try catch once Aron fixes signatures
472 MultipartInput input = (MultipartInput) res.getEntity();
473 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
474 client.getCommonPartName(), OrgauthoritiesCommon.class);
475 Assert.assertNotNull(orgAuthority);
476 } catch (Exception e) {
477 throw new RuntimeException(e);
482 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
483 groups = {"read"}, dependsOnMethods = {"read"})
484 public void readItem(String testName) throws Exception {
489 // Submit the request to the service and store the response.
490 OrgAuthorityClient client = new OrgAuthorityClient();
491 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
492 int statusCode = res.getStatus();
494 // Check the status code of the response: does it match
495 // the expected response(s)?
496 if(logger.isDebugEnabled()){
497 logger.debug(testName + ": status = " + statusCode);
499 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
500 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
501 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
503 // Check whether we've received a organization.
504 MultipartInput input = (MultipartInput) res.getEntity();
505 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
506 client.getItemCommonPartName(), OrganizationsCommon.class);
507 Assert.assertNotNull(organization);
508 boolean showFull = true;
509 if(showFull && logger.isDebugEnabled()){
510 logger.debug(testName + ": returned payload:");
511 logger.debug(objectAsXmlString(organization,
512 OrganizationsCommon.class));
514 Assert.assertEquals(organization.getInAuthority(), knownResourceId);
517 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
518 dependsOnMethods = {"readItem", "updateItem"})
519 public void verifyItemDisplayName(String testName) throws Exception {
522 setupUpdate(testName);
524 // Submit the request to the service and store the response.
525 OrgAuthorityClient client = new OrgAuthorityClient();
526 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
527 int statusCode = res.getStatus();
529 // Check the status code of the response: does it match
530 // the expected response(s)?
531 if(logger.isDebugEnabled()){
532 logger.debug(testName + ": status = " + statusCode);
534 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
535 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
536 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
538 // Check whether organization has expected displayName.
539 MultipartInput input = (MultipartInput) res.getEntity();
540 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
541 client.getItemCommonPartName(), OrganizationsCommon.class);
542 Assert.assertNotNull(organization);
543 String displayName = organization.getDisplayName();
544 // Make sure displayName matches computed form
545 String expectedDisplayName =
546 OrgAuthorityClientUtils.prepareDefaultDisplayName(
547 TEST_ORG_SHORTNAME, TEST_ORG_FOUNDING_PLACE);
548 Assert.assertNotNull(displayName, expectedDisplayName);
550 // Update the shortName and verify the computed name is updated.
551 organization.setCsid(null);
552 organization.setDisplayNameComputed(true);
553 organization.setShortName("updated-" + TEST_ORG_SHORTNAME);
554 expectedDisplayName =
555 OrgAuthorityClientUtils.prepareDefaultDisplayName(
556 "updated-" + TEST_ORG_SHORTNAME, TEST_ORG_FOUNDING_PLACE);
558 // Submit the updated resource to the service and store the response.
559 MultipartOutput output = new MultipartOutput();
560 OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
561 commonPart.getHeaders().add("label", client.getItemCommonPartName());
562 res = client.updateItem(knownResourceId, knownItemResourceId, output);
563 statusCode = res.getStatus();
565 // Check the status code of the response: does it match the expected response(s)?
566 if(logger.isDebugEnabled()){
567 logger.debug("updateItem: status = " + statusCode);
569 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
570 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
571 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
573 // Retrieve the updated resource and verify that its contents exist.
574 input = (MultipartInput) res.getEntity();
575 OrganizationsCommon updatedOrganization =
576 (OrganizationsCommon) extractPart(input,
577 client.getItemCommonPartName(), OrganizationsCommon.class);
578 Assert.assertNotNull(updatedOrganization);
580 // Verify that the updated resource received the correct data.
581 Assert.assertEquals(updatedOrganization.getShortName(), organization.getShortName(),
582 "Updated ShortName in Organization did not match submitted data.");
583 // Verify that the updated resource computes the right displayName.
584 Assert.assertEquals(updatedOrganization.getDisplayName(), expectedDisplayName,
585 "Updated ShortName in Organization not reflected in computed DisplayName.");
587 // Now Update the displayName, not computed and verify the computed name is overriden.
588 organization.setDisplayNameComputed(false);
589 expectedDisplayName = "TestName";
590 organization.setDisplayName(expectedDisplayName);
592 // Submit the updated resource to the service and store the response.
593 output = new MultipartOutput();
594 commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
595 commonPart.getHeaders().add("label", client.getItemCommonPartName());
596 res = client.updateItem(knownResourceId, knownItemResourceId, output);
597 statusCode = res.getStatus();
599 // Check the status code of the response: does it match the expected response(s)?
600 if(logger.isDebugEnabled()){
601 logger.debug("updateItem: status = " + statusCode);
603 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
604 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
605 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
607 // Retrieve the updated resource and verify that its contents exist.
608 input = (MultipartInput) res.getEntity();
609 updatedOrganization =
610 (OrganizationsCommon) extractPart(input,
611 client.getItemCommonPartName(), OrganizationsCommon.class);
612 Assert.assertNotNull(updatedOrganization);
614 // Verify that the updated resource received the correct data.
615 Assert.assertEquals(updatedOrganization.isDisplayNameComputed(), false,
616 "Updated displayNameComputed in Organization did not match submitted data.");
617 // Verify that the updated resource computes the right displayName.
618 Assert.assertEquals(updatedOrganization.getDisplayName(),
620 "Updated DisplayName (not computed) in Organization not stored.");
623 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
624 dependsOnMethods = {"verifyItemDisplayName"})
625 public void verifyIllegalItemDisplayName(String testName) throws Exception {
628 setupUpdateWithWrongXmlSchema(testName);
630 // Submit the request to the service and store the response.
631 OrgAuthorityClient client = new OrgAuthorityClient();
632 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
633 int statusCode = res.getStatus();
635 // Check the status code of the response: does it match
636 // the expected response(s)?
637 if(logger.isDebugEnabled()){
638 logger.debug(testName + ": status = " + statusCode);
640 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
641 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
642 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
644 // Check whether organization has expected displayName.
645 MultipartInput input = (MultipartInput) res.getEntity();
646 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
647 client.getItemCommonPartName(), OrganizationsCommon.class);
648 Assert.assertNotNull(organization);
649 // Try to Update with computed false and no displayName
650 organization.setDisplayNameComputed(false);
651 organization.setDisplayName(null);
653 // Submit the updated resource to the service and store the response.
654 MultipartOutput output = new MultipartOutput();
655 OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
656 commonPart.getHeaders().add("label", client.getItemCommonPartName());
657 res = client.updateItem(knownResourceId, knownItemResourceId, output);
658 statusCode = res.getStatus();
660 // Check the status code of the response: does it match the expected response(s)?
661 if(logger.isDebugEnabled()){
662 logger.debug("updateItem: status = " + statusCode);
664 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
665 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
666 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
669 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
670 groups = {"read"}, dependsOnMethods = {"readItem"})
671 public void readContact(String testName) throws Exception {
676 // Submit the request to the service and store the response.
677 OrgAuthorityClient client = new OrgAuthorityClient();
678 ClientResponse<MultipartInput> res =
679 client.readContact(knownResourceId, knownItemResourceId,
680 knownContactResourceId);
681 int statusCode = res.getStatus();
683 // Check the status code of the response: does it match
684 // the expected response(s)?
685 if(logger.isDebugEnabled()){
686 logger.debug(testName + ": status = " + statusCode);
688 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
689 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
690 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
692 // Check whether we've received a contact.
693 MultipartInput input = (MultipartInput) res.getEntity();
694 ContactsCommon contact = (ContactsCommon) extractPart(input,
695 new ContactClient().getCommonPartName(), ContactsCommon.class);
696 Assert.assertNotNull(contact);
697 boolean showFull = true;
698 if(showFull && logger.isDebugEnabled()){
699 logger.debug(testName + ": returned payload:");
700 logger.debug(objectAsXmlString(contact, ContactsCommon.class));
702 Assert.assertEquals(contact.getInAuthority(), knownResourceId);
703 Assert.assertEquals(contact.getInItem(), knownItemResourceId);
709 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
710 groups = {"read"}, dependsOnMethods = {"read"})
711 public void readNonExistent(String testName) {
714 setupReadNonExistent(testName);
716 // Submit the request to the service and store the response.
717 OrgAuthorityClient client = new OrgAuthorityClient();
718 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
719 int statusCode = res.getStatus();
721 // Check the status code of the response: does it match
722 // the expected response(s)?
723 if(logger.isDebugEnabled()){
724 logger.debug(testName + ": status = " + statusCode);
726 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
727 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
728 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
731 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
732 groups = {"read"}, dependsOnMethods = {"readItem"})
733 public void readItemNonExistent(String testName) {
736 setupReadNonExistent(testName);
738 // Submit the request to the service and store the response.
739 OrgAuthorityClient client = new OrgAuthorityClient();
740 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
741 int statusCode = res.getStatus();
743 // Check the status code of the response: does it match
744 // the expected response(s)?
745 if(logger.isDebugEnabled()){
746 logger.debug(testName + ": status = " + statusCode);
748 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
749 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
750 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
753 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
754 groups = {"read"}, dependsOnMethods = {"readContact"})
755 public void readContactNonExistent(String testName) {
758 setupReadNonExistent(testName);
760 // Submit the request to the service and store the response.
761 OrgAuthorityClient client = new OrgAuthorityClient();
762 ClientResponse<MultipartInput> res =
763 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
764 int statusCode = res.getStatus();
766 // Check the status code of the response: does it match
767 // the expected response(s)?
768 if(logger.isDebugEnabled()){
769 logger.debug(testName + ": status = " + statusCode);
771 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
772 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
773 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
776 // ---------------------------------------------------------------
777 // CRUD tests : READ_LIST tests
778 // ---------------------------------------------------------------
782 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
783 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
784 public void readList(String testName) throws Exception {
787 setupReadList(testName);
789 // Submit the request to the service and store the response.
790 OrgAuthorityClient client = new OrgAuthorityClient();
791 ClientResponse<OrgauthoritiesCommonList> res = client.readList();
792 OrgauthoritiesCommonList list = res.getEntity();
793 int statusCode = res.getStatus();
795 // Check the status code of the response: does it match
796 // the expected response(s)?
797 if(logger.isDebugEnabled()){
798 logger.debug(testName + ": status = " + statusCode);
800 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
801 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
802 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
804 // Optionally output additional data about list members for debugging.
805 boolean iterateThroughList = false;
806 if (iterateThroughList && logger.isDebugEnabled()) {
807 List<OrgauthoritiesCommonList.OrgauthorityListItem> items =
808 list.getOrgauthorityListItem();
810 for (OrgauthoritiesCommonList.OrgauthorityListItem item : items) {
811 String csid = item.getCsid();
812 logger.debug(testName + ": list-item[" + i + "] csid=" +
814 logger.debug(testName + ": list-item[" + i + "] displayName=" +
815 item.getDisplayName());
816 logger.debug(testName + ": list-item[" + i + "] URI=" +
818 readItemList(csid, null);
824 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
825 public void readItemList() {
826 readItemList(knownResourceId, null);
829 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
830 public void readItemListByAuthorityName() {
831 readItemList(null, knownResourceDisplayName);
834 private void readItemList(String vcsid, String name) {
836 final String testName = "readItemList";
839 setupReadList(testName);
841 // Submit the request to the service and store the response.
842 OrgAuthorityClient client = new OrgAuthorityClient();
843 ClientResponse<OrganizationsCommonList> res = null;
845 res = client.readItemList(vcsid);
846 } else if(name!= null) {
847 res = client.readItemListForNamedAuthority(name);
849 Assert.fail("readItemList passed null csid and name!");
851 OrganizationsCommonList list = res.getEntity();
852 int statusCode = res.getStatus();
854 // Check the status code of the response: does it match
855 // the expected response(s)?
856 if(logger.isDebugEnabled()){
857 logger.debug(testName + ": status = " + statusCode);
859 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
860 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
861 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
863 List<OrganizationsCommonList.OrganizationListItem> items =
864 list.getOrganizationListItem();
865 int nItemsReturned = items.size();
866 // There will be one item created, associated with a
867 // known parent resource, by the createItem test.
869 // In addition, there will be 'nItemsToCreateInList'
870 // additional items created by the createItemList test,
871 // all associated with the same parent resource.
872 int nExpectedItems = nItemsToCreateInList + 1;
873 if(logger.isDebugEnabled()){
874 logger.debug(testName + ": Expected "
875 + nExpectedItems +" items; got: "+nItemsReturned);
877 Assert.assertEquals(nItemsReturned, nExpectedItems);
880 for (OrganizationsCommonList.OrganizationListItem item : items) {
881 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
882 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
883 // Optionally output additional data about list members for debugging.
884 boolean showDetails = true;
885 if (showDetails && logger.isDebugEnabled()) {
886 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
888 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
890 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
891 item.getDisplayName());
892 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
899 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
900 public void readContactList() {
901 readContactList(knownResourceId, knownItemResourceId);
904 private void readContactList(String parentcsid, String itemcsid) {
905 final String testName = "readContactList";
908 setupReadList(testName);
910 // Submit the request to the service and store the response.
911 OrgAuthorityClient client = new OrgAuthorityClient();
912 ClientResponse<ContactsCommonList> res =
913 client.readContactList(parentcsid, itemcsid);
914 ContactsCommonList list = res.getEntity();
915 int statusCode = res.getStatus();
917 // Check the status code of the response: does it match
918 // the expected response(s)?
919 if(logger.isDebugEnabled()){
920 logger.debug(testName + ": status = " + statusCode);
922 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
923 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
924 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
926 List<ContactsCommonList.ContactListItem> listitems =
927 list.getContactListItem();
928 int nItemsReturned = listitems.size();
929 // There will be one item created, associated with a
930 // known parent resource, by the createItem test.
932 // In addition, there will be 'nItemsToCreateInList'
933 // additional items created by the createItemList test,
934 // all associated with the same parent resource.
935 int nExpectedItems = nItemsToCreateInList + 1;
936 if(logger.isDebugEnabled()){
937 logger.debug(testName + ": Expected "
938 + nExpectedItems +" items; got: "+nItemsReturned);
940 Assert.assertEquals(nItemsReturned, nExpectedItems);
943 for (ContactsCommonList.ContactListItem listitem : listitems) {
944 // Optionally output additional data about list members for debugging.
945 boolean showDetails = false;
946 if (showDetails && logger.isDebugEnabled()) {
947 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
949 logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" +
950 listitem.getAddressPlace());
951 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
961 // ---------------------------------------------------------------
962 // CRUD tests : UPDATE tests
963 // ---------------------------------------------------------------
966 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
967 groups = {"update"}, dependsOnGroups = {"read", "readList"})
968 public void update(String testName) throws Exception {
971 setupUpdate(testName);
973 // Retrieve the contents of a resource to update.
974 OrgAuthorityClient client = new OrgAuthorityClient();
975 ClientResponse<MultipartInput> res =
976 client.read(knownResourceId);
977 if(logger.isDebugEnabled()){
978 logger.debug(testName + ": read status = " + res.getStatus());
980 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
982 if(logger.isDebugEnabled()){
983 logger.debug("got OrgAuthority to update with ID: " + knownResourceId);
985 MultipartInput input = (MultipartInput) res.getEntity();
986 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
987 client.getCommonPartName(), OrgauthoritiesCommon.class);
988 Assert.assertNotNull(orgAuthority);
990 // Update the contents of this resource.
991 orgAuthority.setDisplayName("updated-" + orgAuthority.getDisplayName());
992 orgAuthority.setVocabType("updated-" + orgAuthority.getVocabType());
993 if(logger.isDebugEnabled()){
994 logger.debug("to be updated OrgAuthority");
995 logger.debug(objectAsXmlString(orgAuthority, OrgauthoritiesCommon.class));
998 // Submit the updated resource to the service and store the response.
999 MultipartOutput output = new MultipartOutput();
1000 OutputPart commonPart = output.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE);
1001 commonPart.getHeaders().add("label", client.getCommonPartName());
1002 res = client.update(knownResourceId, output);
1003 int statusCode = res.getStatus();
1005 // Check the status code of the response: does it match the expected response(s)?
1006 if(logger.isDebugEnabled()){
1007 logger.debug(testName + ": status = " + statusCode);
1009 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1010 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1011 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1013 // Retrieve the updated resource and verify that its contents exist.
1014 input = (MultipartInput) res.getEntity();
1015 OrgauthoritiesCommon updatedOrgAuthority =
1016 (OrgauthoritiesCommon) extractPart(input,
1017 client.getCommonPartName(), OrgauthoritiesCommon.class);
1018 Assert.assertNotNull(updatedOrgAuthority);
1020 // Verify that the updated resource received the correct data.
1021 Assert.assertEquals(updatedOrgAuthority.getDisplayName(),
1022 orgAuthority.getDisplayName(),
1023 "Data in updated object did not match submitted data.");
1026 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1027 groups = {"update"}, dependsOnMethods = {"update"})
1028 public void updateItem(String testName) throws Exception {
1031 setupUpdate(testName);
1033 // Retrieve the contents of a resource to update.
1034 OrgAuthorityClient client = new OrgAuthorityClient();
1035 ClientResponse<MultipartInput> res =
1036 client.readItem(knownResourceId, knownItemResourceId);
1037 if(logger.isDebugEnabled()){
1038 logger.debug(testName + ": read status = " + res.getStatus());
1040 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1042 if(logger.isDebugEnabled()){
1043 logger.debug("got Organization to update with ID: " +
1044 knownItemResourceId +
1045 " in OrgAuthority: " + knownResourceId );
1047 MultipartInput input = (MultipartInput) res.getEntity();
1048 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
1049 client.getItemCommonPartName(), OrganizationsCommon.class);
1050 Assert.assertNotNull(organization);
1052 // Update the contents of this resource.
1053 organization.setCsid(null);
1054 organization.setShortName("updated-" + organization.getShortName());
1055 if(logger.isDebugEnabled()){
1056 logger.debug("to be updated Organization");
1057 logger.debug(objectAsXmlString(organization,
1058 OrganizationsCommon.class));
1061 // Submit the updated resource to the service and store the response.
1062 MultipartOutput output = new MultipartOutput();
1063 OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
1064 commonPart.getHeaders().add("label", client.getItemCommonPartName());
1065 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1066 int statusCode = res.getStatus();
1068 // Check the status code of the response: does it match the expected response(s)?
1069 if(logger.isDebugEnabled()){
1070 logger.debug(testName + ": status = " + statusCode);
1072 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1073 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1074 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1076 // Retrieve the updated resource and verify that its contents exist.
1077 input = (MultipartInput) res.getEntity();
1078 OrganizationsCommon updatedOrganization =
1079 (OrganizationsCommon) extractPart(input,
1080 client.getItemCommonPartName(), OrganizationsCommon.class);
1081 Assert.assertNotNull(updatedOrganization);
1083 // Verify that the updated resource received the correct data.
1084 Assert.assertEquals(updatedOrganization.getShortName(),
1085 organization.getShortName(),
1086 "Data in updated Organization did not match submitted data.");
1089 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1090 groups = {"update"}, dependsOnMethods = {"updateItem"})
1091 public void updateContact(String testName) throws Exception {
1094 setupUpdate(testName);
1096 // Retrieve the contents of a resource to update.
1097 OrgAuthorityClient client = new OrgAuthorityClient();
1098 ClientResponse<MultipartInput> res =
1099 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1100 if(logger.isDebugEnabled()){
1101 logger.debug(testName + ": read status = " + res.getStatus());
1103 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1105 if(logger.isDebugEnabled()){
1106 logger.debug("got Contact to update with ID: " +
1107 knownContactResourceId +
1108 " in item: " + knownItemResourceId +
1109 " in parent: " + knownResourceId );
1111 MultipartInput input = (MultipartInput) res.getEntity();
1112 ContactsCommon contact = (ContactsCommon) extractPart(input,
1113 new ContactClient().getCommonPartName(), ContactsCommon.class);
1114 Assert.assertNotNull(contact);
1116 // Update the contents of this resource.
1117 contact.setAddressPlace("updated-" + contact.getAddressPlace());
1118 if(logger.isDebugEnabled()){
1119 logger.debug("to be updated Contact");
1120 logger.debug(objectAsXmlString(contact,
1121 ContactsCommon.class));
1124 // Submit the updated resource to the service and store the response.
1125 MultipartOutput output = new MultipartOutput();
1126 OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1127 commonPart.getHeaders().add("label", new ContactClient().getCommonPartName());
1128 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1129 int statusCode = res.getStatus();
1131 // Check the status code of the response: does it match the expected response(s)?
1132 if(logger.isDebugEnabled()){
1133 logger.debug(testName + ": status = " + statusCode);
1135 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1136 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1137 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1139 // Retrieve the updated resource and verify that its contents exist.
1140 input = (MultipartInput) res.getEntity();
1141 ContactsCommon updatedContact =
1142 (ContactsCommon) extractPart(input,
1143 new ContactClient().getCommonPartName(), ContactsCommon.class);
1144 Assert.assertNotNull(updatedContact);
1146 // Verify that the updated resource received the correct data.
1147 Assert.assertEquals(updatedContact.getAddressPlace(),
1148 contact.getAddressPlace(),
1149 "Data in updated Contact did not match submitted data.");
1153 // Placeholders until the three tests below can be uncommented.
1154 // See Issue CSPACE-401.
1156 public void updateWithEmptyEntityBody(String testName) throws Exception {
1160 public void updateWithMalformedXml(String testName) throws Exception {
1164 public void updateWithWrongXmlSchema(String testName) throws Exception {
1169 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1170 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1171 public void updateWithEmptyEntityBody(String testName) throws Exception {
1174 setupUpdateWithEmptyEntityBody(testName);
1176 // Submit the request to the service and store the response.
1177 String method = REQUEST_TYPE.httpMethodName();
1178 String url = getResourceURL(knownResourceId);
1179 String mediaType = MediaType.APPLICATION_XML;
1180 final String entity = "";
1181 int statusCode = submitRequest(method, url, mediaType, entity);
1183 // Check the status code of the response: does it match
1184 // the expected response(s)?
1185 if(logger.isDebugEnabled()){
1186 logger.debug(testName + ": url=" + url +
1187 " status=" + statusCode);
1189 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1190 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1191 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1195 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1196 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1197 public void updateWithMalformedXml(String testName) throws Exception {
1200 setupUpdateWithMalformedXml(testName);
1202 // Submit the request to the service and store the response.
1203 String method = REQUEST_TYPE.httpMethodName();
1204 String url = getResourceURL(knownResourceId);
1205 String mediaType = MediaType.APPLICATION_XML;
1206 final String entity = MALFORMED_XML_DATA;
1207 int statusCode = submitRequest(method, url, mediaType, entity);
1209 // Check the status code of the response: does it match
1210 // the expected response(s)?
1211 if(logger.isDebugEnabled()){
1212 logger.debug(testName + ": url=" + url +
1213 " status=" + statusCode);
1215 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1216 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1217 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1221 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1222 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1223 public void updateWithWrongXmlSchema(String testName) throws Exception {
1226 setupUpdateWithWrongXmlSchema(testName);
1228 // Submit the request to the service and store the response.
1229 String method = REQUEST_TYPE.httpMethodName();
1230 String url = getResourceURL(knownResourceId);
1231 String mediaType = MediaType.APPLICATION_XML;
1232 final String entity = WRONG_XML_SCHEMA_DATA;
1233 int statusCode = submitRequest(method, url, mediaType, entity);
1235 // Check the status code of the response: does it match
1236 // the expected response(s)?
1237 if(logger.isDebugEnabled()){
1238 logger.debug("updateWithWrongXmlSchema: url=" + url +
1239 " status=" + statusCode);
1241 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1242 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1243 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1248 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1249 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1250 public void updateNonExistent(String testName) throws Exception {
1253 setupUpdateNonExistent(testName);
1255 // Submit the request to the service and store the response.
1256 // Note: The ID used in this 'create' call may be arbitrary.
1257 // The only relevant ID may be the one used in update(), below.
1258 OrgAuthorityClient client = new OrgAuthorityClient();
1259 MultipartOutput multipart = createOrgAuthorityInstance(NON_EXISTENT_ID);
1260 ClientResponse<MultipartInput> res =
1261 client.update(NON_EXISTENT_ID, multipart);
1262 int statusCode = res.getStatus();
1264 // Check the status code of the response: does it match
1265 // the expected response(s)?
1266 if(logger.isDebugEnabled()){
1267 logger.debug(testName + ": status = " + statusCode);
1269 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1270 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1271 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1274 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1275 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1276 public void updateNonExistentItem(String testName) throws Exception {
1279 setupUpdateNonExistent(testName);
1281 // Submit the request to the service and store the response.
1282 // Note: The ID(s) used when creating the request payload may be arbitrary.
1283 // The only relevant ID may be the one used in update(), below.
1284 OrgAuthorityClient client = new OrgAuthorityClient();
1285 Map<String, String> nonexOrgMap = new HashMap<String,String>();
1286 nonexOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Non-existent");
1287 String refName = OrgAuthorityClientUtils.createOrganizationRefName(knownResourceRefName, NON_EXISTENT_ID, true);
1288 MultipartOutput multipart =
1289 OrgAuthorityClientUtils.createOrganizationInstance(
1290 NON_EXISTENT_ID, refName,
1291 nonexOrgMap, client.getItemCommonPartName() );
1292 ClientResponse<MultipartInput> res =
1293 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1294 int statusCode = res.getStatus();
1296 // Check the status code of the response: does it match
1297 // the expected response(s)?
1298 if(logger.isDebugEnabled()){
1299 logger.debug(testName + ": status = " + statusCode);
1301 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1302 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1303 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1306 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1307 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1308 public void updateNonExistentContact(String testName) throws Exception {
1309 // Currently a no-op test
1312 // ---------------------------------------------------------------
1313 // CRUD tests : DELETE tests
1314 // ---------------------------------------------------------------
1317 // Note: delete sub-resources in ascending hierarchical order,
1318 // before deleting their parents.
1320 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1321 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1322 public void deleteContact(String testName) throws Exception {
1325 setupDelete(testName);
1327 if(logger.isDebugEnabled()){
1328 logger.debug("parentcsid =" + knownResourceId +
1329 " itemcsid = " + knownItemResourceId +
1330 " csid = " + knownContactResourceId);
1333 // Submit the request to the service and store the response.
1334 OrgAuthorityClient client = new OrgAuthorityClient();
1335 ClientResponse<Response> res =
1336 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1337 int statusCode = res.getStatus();
1339 // Check the status code of the response: does it match
1340 // the expected response(s)?
1341 if(logger.isDebugEnabled()){
1342 logger.debug(testName + ": status = " + statusCode);
1344 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1345 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1346 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1349 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1350 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1351 public void deleteItem(String testName) throws Exception {
1354 setupDelete(testName);
1356 if(logger.isDebugEnabled()){
1357 logger.debug("parentcsid =" + knownResourceId +
1358 " itemcsid = " + knownItemResourceId);
1361 // Submit the request to the service and store the response.
1362 OrgAuthorityClient client = new OrgAuthorityClient();
1363 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1364 int statusCode = res.getStatus();
1366 // Check the status code of the response: does it match
1367 // the expected response(s)?
1368 if(logger.isDebugEnabled()){
1369 logger.debug(testName + ": status = " + statusCode);
1371 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1372 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1373 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1377 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1378 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1379 public void delete(String testName) throws Exception {
1382 setupDelete(testName);
1384 if(logger.isDebugEnabled()){
1385 logger.debug("parentcsid =" + knownResourceId);
1388 // Submit the request to the service and store the response.
1389 OrgAuthorityClient client = new OrgAuthorityClient();
1390 ClientResponse<Response> res = client.delete(knownResourceId);
1391 int statusCode = res.getStatus();
1393 // Check the status code of the response: does it match
1394 // the expected response(s)?
1395 if(logger.isDebugEnabled()){
1396 logger.debug(testName + ": status = " + statusCode);
1398 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1399 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1400 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1405 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1406 groups = {"delete"}, dependsOnMethods = {"delete"})
1407 public void deleteNonExistent(String testName) throws Exception {
1410 setupDeleteNonExistent(testName);
1412 // Submit the request to the service and store the response.
1413 OrgAuthorityClient client = new OrgAuthorityClient();
1414 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1415 int statusCode = res.getStatus();
1417 // Check the status code of the response: does it match
1418 // the expected response(s)?
1419 if(logger.isDebugEnabled()){
1420 logger.debug(testName + ": status = " + statusCode);
1422 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1423 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1424 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1427 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1428 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1429 public void deleteNonExistentItem(String testName) {
1432 setupDeleteNonExistent(testName);
1434 // Submit the request to the service and store the response.
1435 OrgAuthorityClient client = new OrgAuthorityClient();
1436 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1437 int statusCode = res.getStatus();
1439 // Check the status code of the response: does it match
1440 // the expected response(s)?
1441 if(logger.isDebugEnabled()){
1442 logger.debug(testName + ": status = " + statusCode);
1444 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1445 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1446 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1449 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1450 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1451 public void deleteNonExistentContact(String testName) {
1454 setupDeleteNonExistent(testName);
1456 // Submit the request to the service and store the response.
1457 OrgAuthorityClient client = new OrgAuthorityClient();
1458 ClientResponse<Response> res =
1459 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1460 int statusCode = res.getStatus();
1462 // Check the status code of the response: does it match
1463 // the expected response(s)?
1464 if(logger.isDebugEnabled()){
1465 logger.debug(testName + ": status = " + statusCode);
1467 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1468 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1469 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1472 // ---------------------------------------------------------------
1473 // Utility tests : tests of code used in tests above
1474 // ---------------------------------------------------------------
1476 * Tests the code for manually submitting data that is used by several
1477 * of the methods above.
1479 @Test(dependsOnMethods = {"create", "read"})
1480 public void testSubmitRequest() {
1482 // Expected status code: 200 OK
1483 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1485 // Submit the request to the service and store the response.
1486 String method = ServiceRequestType.READ.httpMethodName();
1487 String url = getResourceURL(knownResourceId);
1488 int statusCode = submitRequest(method, url);
1490 // Check the status code of the response: does it match
1491 // the expected response(s)?
1492 if(logger.isDebugEnabled()){
1493 logger.debug("testSubmitRequest: url=" + url +
1494 " status=" + statusCode);
1496 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1500 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1501 public void testItemSubmitRequest() {
1503 // Expected status code: 200 OK
1504 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1506 // Submit the request to the service and store the response.
1507 String method = ServiceRequestType.READ.httpMethodName();
1508 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1509 int statusCode = submitRequest(method, url);
1511 // Check the status code of the response: does it match
1512 // the expected response(s)?
1513 if(logger.isDebugEnabled()){
1514 logger.debug("testItemSubmitRequest: url=" + url +
1515 " status=" + statusCode);
1517 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1521 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
1522 public void testContactSubmitRequest() {
1524 // Expected status code: 200 OK
1525 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1527 // Submit the request to the service and store the response.
1528 String method = ServiceRequestType.READ.httpMethodName();
1529 String url = getContactResourceURL(knownResourceId,
1530 knownItemResourceId, knownContactResourceId);
1531 int statusCode = submitRequest(method, url);
1533 // Check the status code of the response: does it match
1534 // the expected response(s)?
1535 if(logger.isDebugEnabled()){
1536 logger.debug("testItemSubmitRequest: url=" + url +
1537 " status=" + statusCode);
1539 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1544 // ---------------------------------------------------------------
1545 // Cleanup of resources created during testing
1546 // ---------------------------------------------------------------
1549 * Deletes all resources created by tests, after all tests have been run.
1551 * This cleanup method will always be run, even if one or more tests fail.
1552 * For this reason, it attempts to remove all resources created
1553 * at any point during testing, even if some of those resources
1554 * may be expected to be deleted by certain tests.
1557 @AfterClass(alwaysRun=true)
1558 public void cleanUp() {
1559 String noTest = System.getProperty("noTestCleanup");
1560 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1561 if (logger.isDebugEnabled()) {
1562 logger.debug("Skipping Cleanup phase ...");
1566 if (logger.isDebugEnabled()) {
1567 logger.debug("Cleaning up temporary resources created for testing ...");
1569 String parentResourceId;
1570 String itemResourceId;
1571 String contactResourceId;
1572 // Clean up contact resources.
1573 parentResourceId = knownResourceId;
1574 OrgAuthorityClient client = new OrgAuthorityClient();
1575 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
1576 contactResourceId = entry.getKey();
1577 itemResourceId = entry.getValue();
1578 // Note: Any non-success responses from the delete operation
1579 // below are ignored and not reported.
1580 ClientResponse<Response> res =
1581 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
1583 // Clean up item resources.
1584 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1585 itemResourceId = entry.getKey();
1586 parentResourceId = entry.getValue();
1587 // Note: Any non-success responses from the delete operation
1588 // below are ignored and not reported.
1589 ClientResponse<Response> res =
1590 client.deleteItem(parentResourceId, itemResourceId);
1592 // Clean up parent resources.
1593 for (String resourceId : allResourceIdsCreated) {
1594 // Note: Any non-success responses from the delete operation
1595 // below are ignored and not reported.
1596 ClientResponse<Response> res = client.delete(resourceId);
1600 // ---------------------------------------------------------------
1601 // Utility methods used by tests above
1602 // ---------------------------------------------------------------
1604 public String getServicePathComponent() {
1605 return SERVICE_PATH_COMPONENT;
1608 public String getItemServicePathComponent() {
1609 return ITEM_SERVICE_PATH_COMPONENT;
1612 public String getContactServicePathComponent() {
1613 return CONTACT_SERVICE_PATH_COMPONENT;
1617 * Returns the root URL for the item service.
1619 * This URL consists of a base URL for all services, followed by
1620 * a path component for the owning parent, followed by the
1621 * path component for the items.
1623 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1624 * parent authority resource of the relevant item resource.
1626 * @return The root URL for the item service.
1628 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1629 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1633 * Returns the URL of a specific item resource managed by a service, and
1634 * designated by an identifier (such as a universally unique ID, or UUID).
1636 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1637 * parent authority resource of the relevant item resource.
1639 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1642 * @return The URL of a specific item resource managed by a service.
1644 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1645 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
1650 * Returns the root URL for the contact service.
1652 * This URL consists of a base URL for all services, followed by
1653 * a path component for the owning authority, followed by the
1654 * path component for the owning item, followed by the path component
1655 * for the contact service.
1657 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1658 * parent authority resource of the relevant item resource.
1660 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1663 * @return The root URL for the contact service.
1665 protected String getContactServiceRootURL(String parentResourceIdentifier,
1666 String itemResourceIdentifier) {
1667 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
1668 getContactServicePathComponent();
1672 * Returns the URL of a specific contact resource managed by a service, and
1673 * designated by an identifier (such as a universally unique ID, or UUID).
1675 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1676 * parent resource of the relevant item resource.
1678 * @param resourceIdentifier An identifier (such as a UUID) for an
1681 * @return The URL of a specific resource managed by a service.
1683 protected String getContactResourceURL(String parentResourceIdentifier,
1684 String itemResourceIdentifier, String contactResourceIdentifier) {
1685 return getContactServiceRootURL(parentResourceIdentifier,
1686 itemResourceIdentifier) + "/" + contactResourceIdentifier;
1689 private MultipartOutput createOrgAuthorityInstance(String identifier) {
1690 String displayName = "displayName-" + identifier;
1691 String refName = OrgAuthorityClientUtils.createOrgAuthRefName(displayName, true);
1692 return OrgAuthorityClientUtils.createOrgAuthorityInstance(
1693 displayName, refName,
1694 new OrgAuthorityClient().getCommonPartName());