2 * This document is a part of the source code and related artifacts
3 * for CollectionSpace, an open source collections management system
4 * for museums and related institutions:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright (c)) 2009 Regents of the University of California
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
15 * https://source.collectionspace.org/collection-space/LICENSE.txt
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 package org.collectionspace.services.client.test;
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.List;
29 import javax.ws.rs.core.MediaType;
30 import javax.ws.rs.core.Response;
32 import org.collectionspace.services.OrganizationJAXBSchema;
33 import org.collectionspace.services.client.ContactClient;
34 import org.collectionspace.services.client.ContactClientUtils;
35 import org.collectionspace.services.contact.ContactsCommon;
36 import org.collectionspace.services.contact.ContactsCommonList;
37 import org.collectionspace.services.client.OrgAuthorityClient;
38 import org.collectionspace.services.client.OrgAuthorityClientUtils;
39 import org.collectionspace.services.organization.OrgauthoritiesCommon;
40 import org.collectionspace.services.organization.OrgauthoritiesCommonList;
41 import org.collectionspace.services.organization.OrganizationsCommon;
42 import org.collectionspace.services.organization.OrganizationsCommonList;
44 import org.jboss.resteasy.client.ClientResponse;
45 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
46 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
47 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
50 import org.testng.Assert;
51 import org.testng.annotations.AfterClass;
52 import org.testng.annotations.Test;
55 * OrgAuthorityServiceTest, carries out tests against a
56 * deployed and running OrgAuthority Service.
58 * $LastChangedRevision: 753 $
59 * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
61 public class OrgAuthorityServiceTest extends AbstractServiceTestImpl {
63 private final Logger logger =
64 LoggerFactory.getLogger(OrgAuthorityServiceTest.class);
66 // Instance variables specific to this test.
67 private OrgAuthorityClient client = new OrgAuthorityClient();
68 private ContactClient contactClient = new ContactClient();
69 final String SERVICE_PATH_COMPONENT = "orgauthorities";
70 final String ITEM_SERVICE_PATH_COMPONENT = "items";
71 final String CONTACT_SERVICE_PATH_COMPONENT = "contacts";
72 private final String TEST_ORG_SHORTNAME = "Test Org";
73 private final String TEST_ORG_FOUNDING_PLACE = "Anytown, USA";
74 private String knownResourceId = null;
75 private String knownResourceDisplayName = null;
76 private String knownResourceRefName = null;
77 private String knownItemResourceId = null;
78 private String knownContactResourceId = null;
79 private int nItemsToCreateInList = 3;
80 private List<String> allResourceIdsCreated = new ArrayList<String>();
81 private Map<String, String> allItemResourceIdsCreated =
82 new HashMap<String, String>();
83 private Map<String, String> allContactResourceIdsCreated =
84 new HashMap<String, String>();
86 // ---------------------------------------------------------------
87 // CRUD tests : CREATE tests
88 // ---------------------------------------------------------------
91 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
93 public void create(String testName) throws Exception {
95 // Perform setup, such as initializing the type of service request
96 // (e.g. CREATE, DELETE), its valid and expected status codes, and
97 // its associated HTTP method name (e.g. POST, DELETE).
98 setupCreate(testName);
100 // Submit the request to the service and store the response.
101 String identifier = createIdentifier();
102 String displayName = "displayName-" + identifier;
103 String refName = OrgAuthorityClientUtils.createOrgAuthRefName(displayName, true);
104 MultipartOutput multipart =
105 OrgAuthorityClientUtils.createOrgAuthorityInstance(
106 displayName, refName, client.getCommonPartName());
107 ClientResponse<Response> res = client.create(multipart);
108 int statusCode = res.getStatus();
110 // Check the status code of the response: does it match
111 // the expected response(s)?
114 // Does it fall within the set of valid status codes?
115 // Does it exactly match the expected status code?
116 if(logger.isDebugEnabled()){
117 logger.debug(testName + ": status = " + statusCode);
119 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
120 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
121 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
123 // Store the refname from the first resource created
124 // for additional tests below.
125 knownResourceRefName = refName;
127 String newID = OrgAuthorityClientUtils.extractId(res);
128 // Store the ID returned from the first resource created
129 // for additional tests below.
130 if (knownResourceId == null){
131 knownResourceId = newID;
132 knownResourceDisplayName = displayName;
133 if (logger.isDebugEnabled()) {
134 logger.debug(testName + ": knownResourceId=" + knownResourceId);
137 // Store the IDs from every resource created by tests,
138 // so they can be deleted after tests have been run.
139 allResourceIdsCreated.add(newID);
142 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
143 groups = {"create"}, dependsOnMethods = {"create"})
144 public void createItem(String testName) {
145 setupCreate(testName);
146 String newID = createItemInAuthority(knownResourceId, knownResourceRefName);
149 private String createItemInAuthority(String vcsid, String authRefName) {
151 final String testName = "createItemInAuthority";
152 if(logger.isDebugEnabled()){
153 logger.debug(testName + ":...");
156 // Submit the request to the service and store the response.
157 String identifier = createIdentifier();
158 String refName = OrgAuthorityClientUtils.createOrganizationRefName(knownResourceRefName, identifier, true);
159 Map<String, String> testOrgMap = new HashMap<String,String>();
160 testOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, TEST_ORG_SHORTNAME);
161 testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "The real official test organization");
162 testOrgMap.put(OrganizationJAXBSchema.CONTACT_NAME, "joe@test.org");
163 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "May 26, 1907");
164 testOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, TEST_ORG_FOUNDING_PLACE);
165 testOrgMap.put(OrganizationJAXBSchema.FUNCTION, "For testing");
166 String newID = OrgAuthorityClientUtils.createItemInAuthority(
167 vcsid, authRefName, testOrgMap, client);
168 // Store the ID returned from the first item resource created
169 // for additional tests below.
170 if (knownItemResourceId == null){
171 knownItemResourceId = newID;
172 if (logger.isDebugEnabled()) {
173 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
177 // Store the IDs from any item resources created
178 // by tests, along with the IDs of their parents, so these items
179 // can be deleted after all tests have been run.
180 allItemResourceIdsCreated.put(newID, vcsid);
185 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
186 groups = {"create"}, dependsOnMethods = {"createItem"})
187 public void createContact(String testName) {
188 setupCreate(testName);
189 String newID = createContactInItem(knownResourceId, knownItemResourceId);
192 private String createContactInItem(String parentcsid, String itemcsid) {
194 final String testName = "createContactInItem";
195 setupCreate(testName);
196 if(logger.isDebugEnabled()){
197 logger.debug(testName + ":...");
200 // Submit the request to the service and store the response.
201 String identifier = createIdentifier();
202 MultipartOutput multipart =
203 ContactClientUtils.createContactInstance(parentcsid,
204 itemcsid, identifier, contactClient.getCommonPartName());
205 ClientResponse<Response> res =
206 client.createContact(parentcsid, itemcsid, multipart);
207 int statusCode = res.getStatus();
208 String newID = OrgAuthorityClientUtils.extractId(res);
210 // Check the status code of the response: does it match
211 // the expected response(s)?
212 if(logger.isDebugEnabled()){
213 logger.debug(testName + ": status = " + statusCode);
215 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
216 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
217 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
219 // Store the ID returned from the first contact resource created
220 // for additional tests below.
221 if (knownContactResourceId == null){
222 knownContactResourceId = newID;
223 if (logger.isDebugEnabled()) {
224 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
228 // Store the IDs from any contact resources created
229 // by tests, along with the IDs of their parent items,
230 // so these items can be deleted after all tests have been run.
231 allContactResourceIdsCreated.put(newID, itemcsid);
238 // Placeholders until the three tests below can be uncommented.
239 // See Issue CSPACE-401.
241 public void createWithEmptyEntityBody(String testName) throws Exception {
245 public void createWithMalformedXml(String testName) throws Exception {
249 public void createWithWrongXmlSchema(String testName) throws Exception {
254 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
255 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
256 public void createWithEmptyEntityBody(String testName) throws Exception {
259 setupCreateWithEmptyEntityBody(testName);
261 // Submit the request to the service and store the response.
262 String method = REQUEST_TYPE.httpMethodName();
263 String url = getServiceRootURL();
264 String mediaType = MediaType.APPLICATION_XML;
265 final String entity = "";
266 int statusCode = submitRequest(method, url, mediaType, entity);
268 // Check the status code of the response: does it match
269 // the expected response(s)?
270 if(logger.isDebugEnabled()) {
271 logger.debug(testName + ": url=" + url +
272 " status=" + statusCode);
274 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
275 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
276 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
280 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
281 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
282 public void createWithMalformedXml(String testName) throws Exception {
285 setupCreateWithMalformedXml(testName);
287 // Submit the request to the service and store the response.
288 String method = REQUEST_TYPE.httpMethodName();
289 String url = getServiceRootURL();
290 String mediaType = MediaType.APPLICATION_XML;
291 final String entity = MALFORMED_XML_DATA; // Constant from base class.
292 int statusCode = submitRequest(method, url, mediaType, entity);
294 // Check the status code of the response: does it match
295 // the expected response(s)?
296 if(logger.isDebugEnabled()){
297 logger.debug(testName + ": url=" + url +
298 " status=" + statusCode);
300 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
301 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
302 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
306 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
307 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
308 public void createWithWrongXmlSchema(String testName) throws Exception {
311 setupCreateWithWrongXmlSchema(testName);
313 // Submit the request to the service and store the response.
314 String method = REQUEST_TYPE.httpMethodName();
315 String url = getServiceRootURL();
316 String mediaType = MediaType.APPLICATION_XML;
317 final String entity = WRONG_XML_SCHEMA_DATA;
318 int statusCode = submitRequest(method, url, mediaType, entity);
320 // Check the status code of the response: does it match
321 // the expected response(s)?
322 if(logger.isDebugEnabled()){
323 logger.debug(testName + ": url=" + url +
324 " status=" + statusCode);
326 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
327 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
328 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
332 // ---------------------------------------------------------------
333 // CRUD tests : CREATE LIST tests
334 // ---------------------------------------------------------------
337 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
338 groups = {"createList"}, dependsOnGroups = {"create"})
339 public void createList(String testName) throws Exception {
340 for (int i = 0; i < nItemsToCreateInList; i++) {
345 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
346 groups = {"createList"}, dependsOnMethods = {"createList"})
347 public void createItemList(String testName) throws Exception {
348 // Add items to the initially-created, known parent record.
349 for (int j = 0; j < nItemsToCreateInList; j++) {
350 createItem(testName);
354 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
355 groups = {"createList"}, dependsOnMethods = {"createItemList"})
356 public void createContactList(String testName) throws Exception {
357 // Add contacts to the initially-created, known item record.
358 for (int j = 0; j < nItemsToCreateInList; j++) {
359 createContact(testName);
363 // ---------------------------------------------------------------
364 // CRUD tests : READ tests
365 // ---------------------------------------------------------------
368 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
369 groups = {"read"}, dependsOnGroups = {"create"})
370 public void read(String testName) throws Exception {
375 // Submit the request to the service and store the response.
376 ClientResponse<MultipartInput> res = client.read(knownResourceId);
377 int statusCode = res.getStatus();
379 // Check the status code of the response: does it match
380 // the expected response(s)?
381 if(logger.isDebugEnabled()){
382 logger.debug(testName + ": status = " + statusCode);
384 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
385 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
386 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
387 //FIXME: remove the following try catch once Aron fixes signatures
389 MultipartInput input = (MultipartInput) res.getEntity();
390 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
391 client.getCommonPartName(), OrgauthoritiesCommon.class);
392 Assert.assertNotNull(orgAuthority);
393 } catch (Exception e) {
394 throw new RuntimeException(e);
398 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
399 groups = {"read"}, dependsOnGroups = {"create"})
400 public void readByName(String testName) throws Exception {
405 // Submit the request to the service and store the response.
406 ClientResponse<MultipartInput> res = client.readByName(knownResourceDisplayName);
407 int statusCode = res.getStatus();
409 // Check the status code of the response: does it match
410 // the expected response(s)?
411 if(logger.isDebugEnabled()){
412 logger.debug(testName + ": status = " + statusCode);
414 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
415 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
416 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
417 //FIXME: remove the following try catch once Aron fixes signatures
419 MultipartInput input = (MultipartInput) res.getEntity();
420 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
421 client.getCommonPartName(), OrgauthoritiesCommon.class);
422 Assert.assertNotNull(orgAuthority);
423 } catch (Exception e) {
424 throw new RuntimeException(e);
429 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
430 groups = {"read"}, dependsOnMethods = {"read"})
431 public void readByName(String testName) throws Exception {
436 // Submit the request to the service and store the response.
437 ClientResponse<MultipartInput> res = client.read(knownResourceId);
438 int statusCode = res.getStatus();
440 // Check the status code of the response: does it match
441 // the expected response(s)?
442 if(logger.isDebugEnabled()){
443 logger.debug(testName + ": status = " + statusCode);
445 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
446 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
447 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
448 //FIXME: remove the following try catch once Aron fixes signatures
450 MultipartInput input = (MultipartInput) res.getEntity();
451 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
452 client.getCommonPartName(), OrgauthoritiesCommon.class);
453 Assert.assertNotNull(orgAuthority);
454 } catch (Exception e) {
455 throw new RuntimeException(e);
460 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
461 groups = {"read"}, dependsOnMethods = {"read"})
462 public void readItem(String testName) throws Exception {
467 // Submit the request to the service and store the response.
468 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
469 int statusCode = res.getStatus();
471 // Check the status code of the response: does it match
472 // the expected response(s)?
473 if(logger.isDebugEnabled()){
474 logger.debug(testName + ": status = " + statusCode);
476 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
477 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
478 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
480 // Check whether we've received a organization.
481 MultipartInput input = (MultipartInput) res.getEntity();
482 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
483 client.getItemCommonPartName(), OrganizationsCommon.class);
484 Assert.assertNotNull(organization);
485 boolean showFull = true;
486 if(showFull && logger.isDebugEnabled()){
487 logger.debug(testName + ": returned payload:");
488 logger.debug(objectAsXmlString(organization,
489 OrganizationsCommon.class));
491 Assert.assertEquals(organization.getInAuthority(), knownResourceId);
494 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
495 dependsOnMethods = {"readItem", "updateItem"})
496 public void verifyItemDisplayName(String testName) throws Exception {
499 setupUpdate(testName);
501 // Submit the request to the service and store the response.
502 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
503 int statusCode = res.getStatus();
505 // Check the status code of the response: does it match
506 // the expected response(s)?
507 if(logger.isDebugEnabled()){
508 logger.debug(testName + ": status = " + statusCode);
510 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
511 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
512 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
514 // Check whether organization has expected displayName.
515 MultipartInput input = (MultipartInput) res.getEntity();
516 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
517 client.getItemCommonPartName(), OrganizationsCommon.class);
518 Assert.assertNotNull(organization);
519 String displayName = organization.getDisplayName();
520 // Make sure displayName matches computed form
521 String expectedDisplayName =
522 OrgAuthorityClientUtils.prepareDefaultDisplayName(
523 TEST_ORG_SHORTNAME, TEST_ORG_FOUNDING_PLACE);
524 Assert.assertNotNull(displayName, expectedDisplayName);
526 // Update the shortName and verify the computed name is updated.
527 organization.setCsid(null);
528 organization.setDisplayNameComputed(true);
529 organization.setShortName("updated-" + TEST_ORG_SHORTNAME);
530 expectedDisplayName =
531 OrgAuthorityClientUtils.prepareDefaultDisplayName(
532 "updated-" + TEST_ORG_SHORTNAME, TEST_ORG_FOUNDING_PLACE);
534 // Submit the updated resource to the service and store the response.
535 MultipartOutput output = new MultipartOutput();
536 OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
537 commonPart.getHeaders().add("label", client.getItemCommonPartName());
538 res = client.updateItem(knownResourceId, knownItemResourceId, output);
539 statusCode = res.getStatus();
541 // Check the status code of the response: does it match the expected response(s)?
542 if(logger.isDebugEnabled()){
543 logger.debug("updateItem: status = " + statusCode);
545 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
546 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
547 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
549 // Retrieve the updated resource and verify that its contents exist.
550 input = (MultipartInput) res.getEntity();
551 OrganizationsCommon updatedOrganization =
552 (OrganizationsCommon) extractPart(input,
553 client.getItemCommonPartName(), OrganizationsCommon.class);
554 Assert.assertNotNull(updatedOrganization);
556 // Verify that the updated resource received the correct data.
557 Assert.assertEquals(updatedOrganization.getShortName(), organization.getShortName(),
558 "Updated ShortName in Organization did not match submitted data.");
559 // Verify that the updated resource computes the right displayName.
560 Assert.assertEquals(updatedOrganization.getDisplayName(), expectedDisplayName,
561 "Updated ShortName in Organization not reflected in computed DisplayName.");
563 // Now Update the displayName, not computed and verify the computed name is overriden.
564 organization.setDisplayNameComputed(false);
565 expectedDisplayName = "TestName";
566 organization.setDisplayName(expectedDisplayName);
568 // Submit the updated resource to the service and store the response.
569 output = new MultipartOutput();
570 commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
571 commonPart.getHeaders().add("label", client.getItemCommonPartName());
572 res = client.updateItem(knownResourceId, knownItemResourceId, output);
573 statusCode = res.getStatus();
575 // Check the status code of the response: does it match the expected response(s)?
576 if(logger.isDebugEnabled()){
577 logger.debug("updateItem: status = " + statusCode);
579 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
580 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
581 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
583 // Retrieve the updated resource and verify that its contents exist.
584 input = (MultipartInput) res.getEntity();
585 updatedOrganization =
586 (OrganizationsCommon) extractPart(input,
587 client.getItemCommonPartName(), OrganizationsCommon.class);
588 Assert.assertNotNull(updatedOrganization);
590 // Verify that the updated resource received the correct data.
591 Assert.assertEquals(updatedOrganization.isDisplayNameComputed(), false,
592 "Updated displayNameComputed in Organization did not match submitted data.");
593 // Verify that the updated resource computes the right displayName.
594 Assert.assertEquals(updatedOrganization.getDisplayName(),
596 "Updated DisplayName (not computed) in Organization not stored.");
599 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
600 dependsOnMethods = {"verifyItemDisplayName"})
601 public void verifyIllegalItemDisplayName(String testName) throws Exception {
604 setupUpdateWithWrongXmlSchema(testName);
606 // Submit the request to the service and store the response.
607 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
608 int statusCode = res.getStatus();
610 // Check the status code of the response: does it match
611 // the expected response(s)?
612 if(logger.isDebugEnabled()){
613 logger.debug(testName + ": status = " + statusCode);
615 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
616 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
617 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
619 // Check whether organization has expected displayName.
620 MultipartInput input = (MultipartInput) res.getEntity();
621 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
622 client.getItemCommonPartName(), OrganizationsCommon.class);
623 Assert.assertNotNull(organization);
624 // Try to Update with computed false and no displayName
625 organization.setDisplayNameComputed(false);
626 organization.setDisplayName(null);
628 // Submit the updated resource to the service and store the response.
629 MultipartOutput output = new MultipartOutput();
630 OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
631 commonPart.getHeaders().add("label", client.getItemCommonPartName());
632 res = client.updateItem(knownResourceId, knownItemResourceId, output);
633 statusCode = res.getStatus();
635 // Check the status code of the response: does it match the expected response(s)?
636 if(logger.isDebugEnabled()){
637 logger.debug("updateItem: status = " + statusCode);
639 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
640 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
641 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
644 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
645 groups = {"read"}, dependsOnMethods = {"readItem"})
646 public void readContact(String testName) throws Exception {
651 // Submit the request to the service and store the response.
652 ClientResponse<MultipartInput> res =
653 client.readContact(knownResourceId, knownItemResourceId,
654 knownContactResourceId);
655 int statusCode = res.getStatus();
657 // Check the status code of the response: does it match
658 // the expected response(s)?
659 if(logger.isDebugEnabled()){
660 logger.debug(testName + ": status = " + statusCode);
662 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
663 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
664 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
666 // Check whether we've received a contact.
667 MultipartInput input = (MultipartInput) res.getEntity();
668 ContactsCommon contact = (ContactsCommon) extractPart(input,
669 contactClient.getCommonPartName(), ContactsCommon.class);
670 Assert.assertNotNull(contact);
671 boolean showFull = true;
672 if(showFull && logger.isDebugEnabled()){
673 logger.debug(testName + ": returned payload:");
674 logger.debug(objectAsXmlString(contact, ContactsCommon.class));
676 Assert.assertEquals(contact.getInAuthority(), knownResourceId);
677 Assert.assertEquals(contact.getInItem(), knownItemResourceId);
683 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
684 groups = {"read"}, dependsOnMethods = {"read"})
685 public void readNonExistent(String testName) {
688 setupReadNonExistent(testName);
690 // Submit the request to the service and store the response.
691 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
692 int statusCode = res.getStatus();
694 // Check the status code of the response: does it match
695 // the expected response(s)?
696 if(logger.isDebugEnabled()){
697 logger.debug(testName + ": status = " + statusCode);
699 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
700 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
701 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
704 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
705 groups = {"read"}, dependsOnMethods = {"readItem"})
706 public void readItemNonExistent(String testName) {
709 setupReadNonExistent(testName);
711 // Submit the request to the service and store the response.
712 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
713 int statusCode = res.getStatus();
715 // Check the status code of the response: does it match
716 // the expected response(s)?
717 if(logger.isDebugEnabled()){
718 logger.debug(testName + ": status = " + statusCode);
720 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
721 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
722 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
725 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
726 groups = {"read"}, dependsOnMethods = {"readContact"})
727 public void readContactNonExistent(String testName) {
730 setupReadNonExistent(testName);
732 // Submit the request to the service and store the response.
733 ClientResponse<MultipartInput> res =
734 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
735 int statusCode = res.getStatus();
737 // Check the status code of the response: does it match
738 // the expected response(s)?
739 if(logger.isDebugEnabled()){
740 logger.debug(testName + ": status = " + statusCode);
742 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
743 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
744 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
747 // ---------------------------------------------------------------
748 // CRUD tests : READ_LIST tests
749 // ---------------------------------------------------------------
753 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
754 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
755 public void readList(String testName) throws Exception {
758 setupReadList(testName);
760 // Submit the request to the service and store the response.
761 ClientResponse<OrgauthoritiesCommonList> res = client.readList();
762 OrgauthoritiesCommonList list = res.getEntity();
763 int statusCode = res.getStatus();
765 // Check the status code of the response: does it match
766 // the expected response(s)?
767 if(logger.isDebugEnabled()){
768 logger.debug(testName + ": status = " + statusCode);
770 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
771 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
772 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
774 // Optionally output additional data about list members for debugging.
775 boolean iterateThroughList = false;
776 if (iterateThroughList && logger.isDebugEnabled()) {
777 List<OrgauthoritiesCommonList.OrgauthorityListItem> items =
778 list.getOrgauthorityListItem();
780 for (OrgauthoritiesCommonList.OrgauthorityListItem item : items) {
781 String csid = item.getCsid();
782 logger.debug(testName + ": list-item[" + i + "] csid=" +
784 logger.debug(testName + ": list-item[" + i + "] displayName=" +
785 item.getDisplayName());
786 logger.debug(testName + ": list-item[" + i + "] URI=" +
788 readItemList(csid, null);
794 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
795 public void readItemList() {
796 readItemList(knownResourceId, null);
799 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
800 public void readItemListByAuthorityName() {
801 readItemList(null, knownResourceDisplayName);
804 private void readItemList(String vcsid, String name) {
806 final String testName = "readItemList";
809 setupReadList(testName);
811 // Submit the request to the service and store the response.
812 ClientResponse<OrganizationsCommonList> res = null;
815 // Submit the request to the service and store the response.
816 res = client.readItemList(vcsid);
817 } else if(name!= null) {
818 // Submit the request to the service and store the response.
819 res = client.readItemListForNamedAuthority(name);
821 Assert.fail("readItemList passed null csid and name!");
823 OrganizationsCommonList list = res.getEntity();
824 int statusCode = res.getStatus();
826 // Check the status code of the response: does it match
827 // the expected response(s)?
828 if(logger.isDebugEnabled()){
829 logger.debug(testName + ": status = " + statusCode);
831 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
832 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
833 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
835 List<OrganizationsCommonList.OrganizationListItem> items =
836 list.getOrganizationListItem();
837 int nItemsReturned = items.size();
838 // There will be one item created, associated with a
839 // known parent resource, by the createItem test.
841 // In addition, there will be 'nItemsToCreateInList'
842 // additional items created by the createItemList test,
843 // all associated with the same parent resource.
844 int nExpectedItems = nItemsToCreateInList + 1;
845 if(logger.isDebugEnabled()){
846 logger.debug(testName + ": Expected "
847 + nExpectedItems +" items; got: "+nItemsReturned);
849 Assert.assertEquals(nItemsReturned, nExpectedItems);
852 for (OrganizationsCommonList.OrganizationListItem item : items) {
853 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
854 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
855 // Optionally output additional data about list members for debugging.
856 boolean showDetails = true;
857 if (showDetails && logger.isDebugEnabled()) {
858 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
860 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
862 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
863 item.getDisplayName());
864 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
871 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
872 public void readContactList() {
873 readContactList(knownResourceId, knownItemResourceId);
876 private void readContactList(String parentcsid, String itemcsid) {
877 final String testName = "readContactList";
880 setupReadList(testName);
882 // Submit the request to the service and store the response.
883 ClientResponse<ContactsCommonList> res =
884 client.readContactList(parentcsid, itemcsid);
885 ContactsCommonList list = res.getEntity();
886 int statusCode = res.getStatus();
888 // Check the status code of the response: does it match
889 // the expected response(s)?
890 if(logger.isDebugEnabled()){
891 logger.debug(testName + ": status = " + statusCode);
893 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
894 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
895 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
897 List<ContactsCommonList.ContactListItem> listitems =
898 list.getContactListItem();
899 int nItemsReturned = listitems.size();
900 // There will be one item created, associated with a
901 // known parent resource, by the createItem test.
903 // In addition, there will be 'nItemsToCreateInList'
904 // additional items created by the createItemList test,
905 // all associated with the same parent resource.
906 int nExpectedItems = nItemsToCreateInList + 1;
907 if(logger.isDebugEnabled()){
908 logger.debug(testName + ": Expected "
909 + nExpectedItems +" items; got: "+nItemsReturned);
911 Assert.assertEquals(nItemsReturned, nExpectedItems);
914 for (ContactsCommonList.ContactListItem listitem : listitems) {
915 // Optionally output additional data about list members for debugging.
916 boolean showDetails = false;
917 if (showDetails && logger.isDebugEnabled()) {
918 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
920 logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" +
921 listitem.getAddressPlace());
922 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
932 // ---------------------------------------------------------------
933 // CRUD tests : UPDATE tests
934 // ---------------------------------------------------------------
937 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
938 groups = {"update"}, dependsOnGroups = {"read", "readList"})
939 public void update(String testName) throws Exception {
942 setupUpdate(testName);
944 // Retrieve the contents of a resource to update.
945 ClientResponse<MultipartInput> res =
946 client.read(knownResourceId);
947 if(logger.isDebugEnabled()){
948 logger.debug(testName + ": read status = " + res.getStatus());
950 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
952 if(logger.isDebugEnabled()){
953 logger.debug("got OrgAuthority to update with ID: " + knownResourceId);
955 MultipartInput input = (MultipartInput) res.getEntity();
956 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
957 client.getCommonPartName(), OrgauthoritiesCommon.class);
958 Assert.assertNotNull(orgAuthority);
960 // Update the contents of this resource.
961 orgAuthority.setDisplayName("updated-" + orgAuthority.getDisplayName());
962 orgAuthority.setVocabType("updated-" + orgAuthority.getVocabType());
963 if(logger.isDebugEnabled()){
964 logger.debug("to be updated OrgAuthority");
965 logger.debug(objectAsXmlString(orgAuthority, OrgauthoritiesCommon.class));
968 // Submit the updated resource to the service and store the response.
969 MultipartOutput output = new MultipartOutput();
970 OutputPart commonPart = output.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE);
971 commonPart.getHeaders().add("label", client.getCommonPartName());
972 res = client.update(knownResourceId, output);
973 int statusCode = res.getStatus();
975 // Check the status code of the response: does it match the expected response(s)?
976 if(logger.isDebugEnabled()){
977 logger.debug(testName + ": status = " + statusCode);
979 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
980 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
981 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
983 // Retrieve the updated resource and verify that its contents exist.
984 input = (MultipartInput) res.getEntity();
985 OrgauthoritiesCommon updatedOrgAuthority =
986 (OrgauthoritiesCommon) extractPart(input,
987 client.getCommonPartName(), OrgauthoritiesCommon.class);
988 Assert.assertNotNull(updatedOrgAuthority);
990 // Verify that the updated resource received the correct data.
991 Assert.assertEquals(updatedOrgAuthority.getDisplayName(),
992 orgAuthority.getDisplayName(),
993 "Data in updated object did not match submitted data.");
996 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
997 groups = {"update"}, dependsOnMethods = {"update"})
998 public void updateItem(String testName) throws Exception {
1001 setupUpdate(testName);
1003 ClientResponse<MultipartInput> res =
1004 client.readItem(knownResourceId, knownItemResourceId);
1005 if(logger.isDebugEnabled()){
1006 logger.debug(testName + ": read status = " + res.getStatus());
1008 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1010 if(logger.isDebugEnabled()){
1011 logger.debug("got Organization to update with ID: " +
1012 knownItemResourceId +
1013 " in OrgAuthority: " + knownResourceId );
1015 MultipartInput input = (MultipartInput) res.getEntity();
1016 OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
1017 client.getItemCommonPartName(), OrganizationsCommon.class);
1018 Assert.assertNotNull(organization);
1020 // Update the contents of this resource.
1021 organization.setCsid(null);
1022 organization.setShortName("updated-" + organization.getShortName());
1023 if(logger.isDebugEnabled()){
1024 logger.debug("to be updated Organization");
1025 logger.debug(objectAsXmlString(organization,
1026 OrganizationsCommon.class));
1029 // Submit the updated resource to the service and store the response.
1030 MultipartOutput output = new MultipartOutput();
1031 OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
1032 commonPart.getHeaders().add("label", client.getItemCommonPartName());
1033 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1034 int statusCode = res.getStatus();
1036 // Check the status code of the response: does it match the expected response(s)?
1037 if(logger.isDebugEnabled()){
1038 logger.debug(testName + ": status = " + statusCode);
1040 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1041 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1042 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1044 // Retrieve the updated resource and verify that its contents exist.
1045 input = (MultipartInput) res.getEntity();
1046 OrganizationsCommon updatedOrganization =
1047 (OrganizationsCommon) extractPart(input,
1048 client.getItemCommonPartName(), OrganizationsCommon.class);
1049 Assert.assertNotNull(updatedOrganization);
1051 // Verify that the updated resource received the correct data.
1052 Assert.assertEquals(updatedOrganization.getShortName(),
1053 organization.getShortName(),
1054 "Data in updated Organization did not match submitted data.");
1057 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1058 groups = {"update"}, dependsOnMethods = {"updateItem"})
1059 public void updateContact(String testName) throws Exception {
1062 setupUpdate(testName);
1064 ClientResponse<MultipartInput> res =
1065 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1066 if(logger.isDebugEnabled()){
1067 logger.debug(testName + ": read status = " + res.getStatus());
1069 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1071 if(logger.isDebugEnabled()){
1072 logger.debug("got Contact to update with ID: " +
1073 knownContactResourceId +
1074 " in item: " + knownItemResourceId +
1075 " in parent: " + knownResourceId );
1077 MultipartInput input = (MultipartInput) res.getEntity();
1078 ContactsCommon contact = (ContactsCommon) extractPart(input,
1079 contactClient.getCommonPartName(), ContactsCommon.class);
1080 Assert.assertNotNull(contact);
1082 // Update the contents of this resource.
1083 contact.setAddressPlace("updated-" + contact.getAddressPlace());
1084 if(logger.isDebugEnabled()){
1085 logger.debug("to be updated Contact");
1086 logger.debug(objectAsXmlString(contact,
1087 ContactsCommon.class));
1090 // Submit the updated resource to the service and store the response.
1091 MultipartOutput output = new MultipartOutput();
1092 OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1093 commonPart.getHeaders().add("label", contactClient.getCommonPartName());
1094 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1095 int statusCode = res.getStatus();
1097 // Check the status code of the response: does it match the expected response(s)?
1098 if(logger.isDebugEnabled()){
1099 logger.debug(testName + ": status = " + statusCode);
1101 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1102 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1103 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1105 // Retrieve the updated resource and verify that its contents exist.
1106 input = (MultipartInput) res.getEntity();
1107 ContactsCommon updatedContact =
1108 (ContactsCommon) extractPart(input,
1109 contactClient.getCommonPartName(), ContactsCommon.class);
1110 Assert.assertNotNull(updatedContact);
1112 // Verify that the updated resource received the correct data.
1113 Assert.assertEquals(updatedContact.getAddressPlace(),
1114 contact.getAddressPlace(),
1115 "Data in updated Contact did not match submitted data.");
1119 // Placeholders until the three tests below can be uncommented.
1120 // See Issue CSPACE-401.
1122 public void updateWithEmptyEntityBody(String testName) throws Exception {
1126 public void updateWithMalformedXml(String testName) throws Exception {
1130 public void updateWithWrongXmlSchema(String testName) throws Exception {
1135 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1136 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1137 public void updateWithEmptyEntityBody(String testName) throws Exception {
1140 setupUpdateWithEmptyEntityBody(testName);
1142 // Submit the request to the service and store the response.
1143 String method = REQUEST_TYPE.httpMethodName();
1144 String url = getResourceURL(knownResourceId);
1145 String mediaType = MediaType.APPLICATION_XML;
1146 final String entity = "";
1147 int statusCode = submitRequest(method, url, mediaType, entity);
1149 // Check the status code of the response: does it match
1150 // the expected response(s)?
1151 if(logger.isDebugEnabled()){
1152 logger.debug(testName + ": url=" + url +
1153 " status=" + statusCode);
1155 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1156 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1157 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1161 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1162 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1163 public void updateWithMalformedXml(String testName) throws Exception {
1166 setupUpdateWithMalformedXml(testName);
1168 // Submit the request to the service and store the response.
1169 String method = REQUEST_TYPE.httpMethodName();
1170 String url = getResourceURL(knownResourceId);
1171 String mediaType = MediaType.APPLICATION_XML;
1172 final String entity = MALFORMED_XML_DATA;
1173 int statusCode = submitRequest(method, url, mediaType, entity);
1175 // Check the status code of the response: does it match
1176 // the expected response(s)?
1177 if(logger.isDebugEnabled()){
1178 logger.debug(testName + ": url=" + url +
1179 " status=" + statusCode);
1181 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1182 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1183 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1187 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1188 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1189 public void updateWithWrongXmlSchema(String testName) throws Exception {
1192 setupUpdateWithWrongXmlSchema(testName);
1194 // Submit the request to the service and store the response.
1195 String method = REQUEST_TYPE.httpMethodName();
1196 String url = getResourceURL(knownResourceId);
1197 String mediaType = MediaType.APPLICATION_XML;
1198 final String entity = WRONG_XML_SCHEMA_DATA;
1199 int statusCode = submitRequest(method, url, mediaType, entity);
1201 // Check the status code of the response: does it match
1202 // the expected response(s)?
1203 if(logger.isDebugEnabled()){
1204 logger.debug("updateWithWrongXmlSchema: url=" + url +
1205 " status=" + statusCode);
1207 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1208 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1209 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1214 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1215 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1216 public void updateNonExistent(String testName) throws Exception {
1219 setupUpdateNonExistent(testName);
1221 // Submit the request to the service and store the response.
1222 // Note: The ID used in this 'create' call may be arbitrary.
1223 // The only relevant ID may be the one used in update(), below.
1224 MultipartOutput multipart = createOrgAuthorityInstance(NON_EXISTENT_ID);
1225 ClientResponse<MultipartInput> res =
1226 client.update(NON_EXISTENT_ID, multipart);
1227 int statusCode = res.getStatus();
1229 // Check the status code of the response: does it match
1230 // the expected response(s)?
1231 if(logger.isDebugEnabled()){
1232 logger.debug(testName + ": status = " + statusCode);
1234 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1235 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1236 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1239 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1240 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1241 public void updateNonExistentItem(String testName) throws Exception {
1244 setupUpdateNonExistent(testName);
1246 // Submit the request to the service and store the response.
1247 // Note: The ID(s) used when creating the request payload may be arbitrary.
1248 // The only relevant ID may be the one used in update(), below.
1249 Map<String, String> nonexOrgMap = new HashMap<String,String>();
1250 nonexOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Non-existent");
1251 String refName = OrgAuthorityClientUtils.createOrganizationRefName(knownResourceRefName, NON_EXISTENT_ID, true);
1252 MultipartOutput multipart =
1253 OrgAuthorityClientUtils.createOrganizationInstance(
1254 NON_EXISTENT_ID, refName,
1255 nonexOrgMap, client.getItemCommonPartName() );
1256 ClientResponse<MultipartInput> res =
1257 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1258 int statusCode = res.getStatus();
1260 // Check the status code of the response: does it match
1261 // the expected response(s)?
1262 if(logger.isDebugEnabled()){
1263 logger.debug(testName + ": status = " + statusCode);
1265 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1266 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1267 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1270 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1271 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1272 public void updateNonExistentContact(String testName) throws Exception {
1273 // Currently a no-op test
1276 // ---------------------------------------------------------------
1277 // CRUD tests : DELETE tests
1278 // ---------------------------------------------------------------
1281 // Note: delete sub-resources in ascending hierarchical order,
1282 // before deleting their parents.
1284 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1285 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1286 public void deleteContact(String testName) throws Exception {
1289 setupDelete(testName);
1291 if(logger.isDebugEnabled()){
1292 logger.debug("parentcsid =" + knownResourceId +
1293 " itemcsid = " + knownItemResourceId +
1294 " csid = " + knownContactResourceId);
1297 // Submit the request to the service and store the response.
1298 ClientResponse<Response> res =
1299 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1300 int statusCode = res.getStatus();
1302 // Check the status code of the response: does it match
1303 // the expected response(s)?
1304 if(logger.isDebugEnabled()){
1305 logger.debug(testName + ": status = " + statusCode);
1307 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1308 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1309 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1312 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1313 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1314 public void deleteItem(String testName) throws Exception {
1317 setupDelete(testName);
1319 if(logger.isDebugEnabled()){
1320 logger.debug("parentcsid =" + knownResourceId +
1321 " itemcsid = " + knownItemResourceId);
1324 // Submit the request to the service and store the response.
1325 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1326 int statusCode = res.getStatus();
1328 // Check the status code of the response: does it match
1329 // the expected response(s)?
1330 if(logger.isDebugEnabled()){
1331 logger.debug(testName + ": status = " + statusCode);
1333 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1334 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1335 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1339 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1340 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1341 public void delete(String testName) throws Exception {
1344 setupDelete(testName);
1346 if(logger.isDebugEnabled()){
1347 logger.debug("parentcsid =" + knownResourceId);
1350 // Submit the request to the service and store the response.
1351 ClientResponse<Response> res = client.delete(knownResourceId);
1352 int statusCode = res.getStatus();
1354 // Check the status code of the response: does it match
1355 // the expected response(s)?
1356 if(logger.isDebugEnabled()){
1357 logger.debug(testName + ": status = " + statusCode);
1359 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1360 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1361 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1366 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1367 groups = {"delete"}, dependsOnMethods = {"delete"})
1368 public void deleteNonExistent(String testName) throws Exception {
1371 setupDeleteNonExistent(testName);
1373 // Submit the request to the service and store the response.
1374 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1375 int statusCode = res.getStatus();
1377 // Check the status code of the response: does it match
1378 // the expected response(s)?
1379 if(logger.isDebugEnabled()){
1380 logger.debug(testName + ": status = " + statusCode);
1382 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1383 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1384 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1387 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1388 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1389 public void deleteNonExistentItem(String testName) {
1392 setupDeleteNonExistent(testName);
1394 // Submit the request to the service and store the response.
1395 ClientResponse<Response> res = client.deleteItem(knownResourceId, 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 = {"deleteContact"})
1410 public void deleteNonExistentContact(String testName) {
1413 setupDeleteNonExistent(testName);
1415 // Submit the request to the service and store the response.
1416 ClientResponse<Response> res =
1417 client.deleteContact(knownResourceId, knownItemResourceId, 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 // ---------------------------------------------------------------
1431 // Utility tests : tests of code used in tests above
1432 // ---------------------------------------------------------------
1434 * Tests the code for manually submitting data that is used by several
1435 * of the methods above.
1437 @Test(dependsOnMethods = {"create", "read"})
1438 public void testSubmitRequest() {
1440 // Expected status code: 200 OK
1441 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1443 // Submit the request to the service and store the response.
1444 String method = ServiceRequestType.READ.httpMethodName();
1445 String url = getResourceURL(knownResourceId);
1446 int statusCode = submitRequest(method, url);
1448 // Check the status code of the response: does it match
1449 // the expected response(s)?
1450 if(logger.isDebugEnabled()){
1451 logger.debug("testSubmitRequest: url=" + url +
1452 " status=" + statusCode);
1454 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1458 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1459 public void testItemSubmitRequest() {
1461 // Expected status code: 200 OK
1462 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1464 // Submit the request to the service and store the response.
1465 String method = ServiceRequestType.READ.httpMethodName();
1466 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1467 int statusCode = submitRequest(method, url);
1469 // Check the status code of the response: does it match
1470 // the expected response(s)?
1471 if(logger.isDebugEnabled()){
1472 logger.debug("testItemSubmitRequest: url=" + url +
1473 " status=" + statusCode);
1475 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1479 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
1480 public void testContactSubmitRequest() {
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 = getContactResourceURL(knownResourceId,
1488 knownItemResourceId, knownContactResourceId);
1489 int statusCode = submitRequest(method, url);
1491 // Check the status code of the response: does it match
1492 // the expected response(s)?
1493 if(logger.isDebugEnabled()){
1494 logger.debug("testItemSubmitRequest: url=" + url +
1495 " status=" + statusCode);
1497 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1502 // ---------------------------------------------------------------
1503 // Cleanup of resources created during testing
1504 // ---------------------------------------------------------------
1507 * Deletes all resources created by tests, after all tests have been run.
1509 * This cleanup method will always be run, even if one or more tests fail.
1510 * For this reason, it attempts to remove all resources created
1511 * at any point during testing, even if some of those resources
1512 * may be expected to be deleted by certain tests.
1515 @AfterClass(alwaysRun=true)
1516 public void cleanUp() {
1517 if (logger.isDebugEnabled()) {
1518 logger.debug("Cleaning up temporary resources created for testing ...");
1520 String parentResourceId;
1521 String itemResourceId;
1522 String contactResourceId;
1523 // Clean up contact resources.
1524 parentResourceId = knownResourceId;
1525 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
1526 contactResourceId = entry.getKey();
1527 itemResourceId = entry.getValue();
1528 // Note: Any non-success responses from the delete operation
1529 // below are ignored and not reported.
1530 ClientResponse<Response> res =
1531 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
1533 // Clean up item resources.
1534 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1535 itemResourceId = entry.getKey();
1536 parentResourceId = entry.getValue();
1537 // Note: Any non-success responses from the delete operation
1538 // below are ignored and not reported.
1539 ClientResponse<Response> res =
1540 client.deleteItem(parentResourceId, itemResourceId);
1542 // Clean up parent resources.
1543 for (String resourceId : allResourceIdsCreated) {
1544 // Note: Any non-success responses from the delete operation
1545 // below are ignored and not reported.
1546 ClientResponse<Response> res = client.delete(resourceId);
1550 // ---------------------------------------------------------------
1551 // Utility methods used by tests above
1552 // ---------------------------------------------------------------
1554 public String getServicePathComponent() {
1555 return SERVICE_PATH_COMPONENT;
1558 public String getItemServicePathComponent() {
1559 return ITEM_SERVICE_PATH_COMPONENT;
1562 public String getContactServicePathComponent() {
1563 return CONTACT_SERVICE_PATH_COMPONENT;
1567 * Returns the root URL for the item service.
1569 * This URL consists of a base URL for all services, followed by
1570 * a path component for the owning parent, followed by the
1571 * path component for the items.
1573 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1574 * parent authority resource of the relevant item resource.
1576 * @return The root URL for the item service.
1578 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1579 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1583 * Returns the URL of a specific item resource managed by a service, and
1584 * designated by an identifier (such as a universally unique ID, or UUID).
1586 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1587 * parent authority resource of the relevant item resource.
1589 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1592 * @return The URL of a specific item resource managed by a service.
1594 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1595 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
1600 * Returns the root URL for the contact service.
1602 * This URL consists of a base URL for all services, followed by
1603 * a path component for the owning authority, followed by the
1604 * path component for the owning item, followed by the path component
1605 * for the contact service.
1607 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1608 * parent authority resource of the relevant item resource.
1610 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1613 * @return The root URL for the contact service.
1615 protected String getContactServiceRootURL(String parentResourceIdentifier,
1616 String itemResourceIdentifier) {
1617 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
1618 getContactServicePathComponent();
1622 * Returns the URL of a specific contact resource managed by a service, and
1623 * designated by an identifier (such as a universally unique ID, or UUID).
1625 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1626 * parent resource of the relevant item resource.
1628 * @param resourceIdentifier An identifier (such as a UUID) for an
1631 * @return The URL of a specific resource managed by a service.
1633 protected String getContactResourceURL(String parentResourceIdentifier,
1634 String itemResourceIdentifier, String contactResourceIdentifier) {
1635 return getContactServiceRootURL(parentResourceIdentifier,
1636 itemResourceIdentifier) + "/" + contactResourceIdentifier;
1639 private MultipartOutput createOrgAuthorityInstance(String identifier) {
1640 String displayName = "displayName-" + identifier;
1641 String refName = OrgAuthorityClientUtils.createOrgAuthRefName(displayName, true);
1642 return OrgAuthorityClientUtils.createOrgAuthorityInstance(
1643 displayName, refName,
1644 client.getCommonPartName());