]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
823820475b49bef72c011d71e670ba30d7126ca8
[tmp/jakarta-migration.git] /
1 /**
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:
5  *
6  * http://www.collectionspace.org
7  * http://wiki.collectionspace.org
8  *
9  * Copyright (c)) 2009 Regents of the University of California
10  *
11  * Licensed under the Educational Community License (ECL), Version 2.0.
12  * You may not use this file except in compliance with this License.
13  *
14  * You may obtain a copy of the ECL 2.0 License at
15  * https://source.collectionspace.org/collection-space/LICENSE.txt
16  *
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.
22  */
23 package org.collectionspace.services.client.test;
24
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.Map;
29 import javax.ws.rs.core.MediaType;
30 import javax.ws.rs.core.Response;
31
32 import org.collectionspace.services.OrganizationJAXBSchema;
33 import org.collectionspace.services.client.OrgAuthorityClient;
34 import org.collectionspace.services.client.OrgAuthorityClientUtils;
35 import org.collectionspace.services.organization.OrgauthoritiesCommon;
36 import org.collectionspace.services.organization.OrgauthoritiesCommonList;
37 import org.collectionspace.services.organization.OrganizationsCommon;
38 import org.collectionspace.services.organization.OrganizationsCommonList;
39
40 import org.jboss.resteasy.client.ClientResponse;
41 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
42 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
43 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
46 import org.testng.Assert;
47 import org.testng.annotations.AfterClass;
48 import org.testng.annotations.Test;
49
50 /**
51  * OrgAuthorityServiceTest, carries out tests against a
52  * deployed and running OrgAuthority Service.
53  *
54  * $LastChangedRevision: 753 $
55  * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
56  */
57 public class OrgAuthorityServiceTest extends AbstractServiceTestImpl {
58
59     private final Logger logger =
60         LoggerFactory.getLogger(OrgAuthorityServiceTest.class);
61
62     // Instance variables specific to this test.
63     private OrgAuthorityClient client = new OrgAuthorityClient();
64     final String SERVICE_PATH_COMPONENT = "orgauthorities";
65     final String ITEM_SERVICE_PATH_COMPONENT = "items";
66     private final String TEST_ORG_SHORTNAME = "Test Org";
67     private final String TEST_ORG_FOUNDING_PLACE = "Anytown, USA";
68     private String knownResourceId = null;
69     private String lastOrgAuthId = null;
70     private String knownResourceRefName = null;
71     private String knownItemResourceId = null;
72     private int nItemsToCreateInList = 3;
73     private List<String> allResourceIdsCreated = new ArrayList<String>();
74     private Map<String, String> allResourceItemIdsCreated =
75         new HashMap<String, String>();
76     
77     // ---------------------------------------------------------------
78     // CRUD tests : CREATE tests
79     // ---------------------------------------------------------------
80     // Success outcomes
81     @Override
82     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
83     public void create(String testName) throws Exception {
84
85         // Perform setup, such as initializing the type of service request
86         // (e.g. CREATE, DELETE), its valid and expected status codes, and
87         // its associated HTTP method name (e.g. POST, DELETE).
88         setupCreate(testName);
89
90         // Submit the request to the service and store the response.
91         String identifier = createIdentifier();
92         String displayName = "displayName-" + identifier;
93         String refName = OrgAuthorityClientUtils.createOrgAuthRefName(displayName, true);
94         MultipartOutput multipart = 
95                 OrgAuthorityClientUtils.createOrgAuthorityInstance(
96                                 displayName, refName, 
97                                 client.getCommonPartName());
98         ClientResponse<Response> res = client.create(multipart);
99         int statusCode = res.getStatus();
100
101         // Check the status code of the response: does it match
102         // the expected response(s)?
103         //
104         // Specifically:
105         // Does it fall within the set of valid status codes?
106         // Does it exactly match the expected status code?
107         if(logger.isDebugEnabled()){
108             logger.debug(testName + ": status = " + statusCode);
109         }
110         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
111                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
112         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
113
114         // Store the refname from the first resource created
115         // for additional tests below.
116         knownResourceRefName = refName;
117
118         lastOrgAuthId = extractId(res);
119         // Store the ID returned from the first resource created
120         // for additional tests below.
121         if (knownResourceId == null){
122             knownResourceId = lastOrgAuthId;
123             if (logger.isDebugEnabled()) {
124                 logger.debug(testName + ": knownResourceId=" + knownResourceId);
125             }
126         }
127         // Store the IDs from every resource created by tests,
128         // so they can be deleted after tests have been run.
129         allResourceIdsCreated.add(extractId(res));
130
131     }
132
133     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
134         dependsOnMethods = {"create"})
135     public void createItem(String testName) {
136         setupCreate(testName);
137
138         knownItemResourceId = createItemInAuthority(lastOrgAuthId, knownResourceRefName);
139         if(logger.isDebugEnabled()){
140             logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
141         }
142     }
143
144     private String createItemInAuthority(String vcsid, String orgAuthorityRefName) {
145
146         final String testName = "createItemInAuthority";
147         if(logger.isDebugEnabled()){
148             logger.debug(testName + ":...");
149         }
150
151         // Submit the request to the service and store the response.
152         String identifier = createIdentifier();
153         String refName = OrgAuthorityClientUtils.createOrganizationRefName(knownResourceRefName, identifier, true);
154         Map<String, String> testOrgMap = new HashMap<String,String>();
155         testOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, TEST_ORG_SHORTNAME);
156         testOrgMap.put(OrganizationJAXBSchema.LONG_NAME, "The real official test organization");
157         testOrgMap.put(OrganizationJAXBSchema.CONTACT_NAME, "joe@test.org");
158         testOrgMap.put(OrganizationJAXBSchema.FOUNDING_DATE, "May 26, 1907");
159         testOrgMap.put(OrganizationJAXBSchema.FOUNDING_PLACE, TEST_ORG_FOUNDING_PLACE);
160         testOrgMap.put(OrganizationJAXBSchema.FUNCTION, "For testing");
161         String newID = OrgAuthorityClientUtils.createItemInAuthority(
162                         vcsid, orgAuthorityRefName, testOrgMap, client);
163         // Store the ID returned from the first item resource created
164         // for additional tests below.
165         if (knownItemResourceId == null){
166             knownItemResourceId = newID;
167             if (logger.isDebugEnabled()) {
168                 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
169             }
170         }
171
172         // Store the IDs from any item resources created
173         // by tests, along with the IDs of their parents, so these items
174         // can be deleted after all tests have been run.
175         allResourceItemIdsCreated.put(newID, vcsid);
176
177         return newID;
178     }
179
180     @Override
181     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
182             dependsOnMethods = {"create", "createItem"})
183     public void createList(String testName) throws Exception {
184         for (int i = 0; i < 3; i++) {
185             create(testName);
186             knownResourceId = lastOrgAuthId;
187             if (logger.isDebugEnabled()) {
188                 logger.debug(testName + ": Resetting knownResourceId to" + knownResourceId);
189             }
190             // Add nItemsToCreateInList items to each orgauthority
191             for (int j = 0; j < nItemsToCreateInList; j++) {
192                 createItem(testName);
193             }
194         }
195     }
196
197     // Failure outcomes
198     // Placeholders until the three tests below can be uncommented.
199     // See Issue CSPACE-401.
200     @Override
201     public void createWithEmptyEntityBody(String testName) throws Exception {
202     }
203
204     @Override
205     public void createWithMalformedXml(String testName) throws Exception {
206     }
207
208     @Override
209     public void createWithWrongXmlSchema(String testName) throws Exception {
210     }
211
212     /*
213     @Override
214     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
215         dependsOnMethods = {"create", "testSubmitRequest"})
216     public void createWithEmptyEntityBody(String testName) throws Exception {
217
218     // Perform setup.
219     setupCreateWithEmptyEntityBody(testName);
220
221     // Submit the request to the service and store the response.
222     String method = REQUEST_TYPE.httpMethodName();
223     String url = getServiceRootURL();
224     String mediaType = MediaType.APPLICATION_XML;
225     final String entity = "";
226     int statusCode = submitRequest(method, url, mediaType, entity);
227
228     // Check the status code of the response: does it match
229     // the expected response(s)?
230     if(logger.isDebugEnabled()) {
231         logger.debug(testName + ": url=" + url +
232             " status=" + statusCode);
233      }
234     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
235     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
236     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
237     }
238
239     @Override
240     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
241         dependsOnMethods = {"create", "testSubmitRequest"})
242     public void createWithMalformedXml(String testName) throws Exception {
243
244     // Perform setup.
245     setupCreateWithMalformedXml(testName);
246
247     // Submit the request to the service and store the response.
248     String method = REQUEST_TYPE.httpMethodName();
249     String url = getServiceRootURL();
250     String mediaType = MediaType.APPLICATION_XML;
251     final String entity = MALFORMED_XML_DATA; // Constant from base class.
252     int statusCode = submitRequest(method, url, mediaType, entity);
253
254     // Check the status code of the response: does it match
255     // the expected response(s)?
256     if(logger.isDebugEnabled()){
257         logger.debug(testName + ": url=" + url +
258             " status=" + statusCode);
259      }
260     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
261     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
262     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
263     }
264
265     @Override
266     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
267         dependsOnMethods = {"create", "testSubmitRequest"})
268     public void createWithWrongXmlSchema(String testName) throws Exception {
269
270     // Perform setup.
271     setupCreateWithWrongXmlSchema(testName);
272
273     // Submit the request to the service and store the response.
274     String method = REQUEST_TYPE.httpMethodName();
275     String url = getServiceRootURL();
276     String mediaType = MediaType.APPLICATION_XML;
277     final String entity = WRONG_XML_SCHEMA_DATA;
278     int statusCode = submitRequest(method, url, mediaType, entity);
279
280     // Check the status code of the response: does it match
281     // the expected response(s)?
282     if(logger.isDebugEnabled()){
283         logger.debug(testName + ": url=" + url +
284             " status=" + statusCode);
285      }
286     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
287     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
288     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
289     }
290      */
291
292     // ---------------------------------------------------------------
293     // CRUD tests : READ tests
294     // ---------------------------------------------------------------
295     // Success outcomes
296     @Override
297     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
298         dependsOnMethods = {"create"})
299     public void read(String testName) throws Exception {
300
301         // Perform setup.
302         setupRead();
303
304         // Submit the request to the service and store the response.
305         ClientResponse<MultipartInput> res = client.read(knownResourceId);
306         int statusCode = res.getStatus();
307
308         // Check the status code of the response: does it match
309         // the expected response(s)?
310         if(logger.isDebugEnabled()){
311             logger.debug(testName + ": status = " + statusCode);
312         }
313         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
314                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
315         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
316         //FIXME: remove the following try catch once Aron fixes signatures
317         try {
318             MultipartInput input = (MultipartInput) res.getEntity();
319             OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
320                     client.getCommonPartName(), OrgauthoritiesCommon.class);
321             Assert.assertNotNull(orgAuthority);
322         } catch (Exception e) {
323             throw new RuntimeException(e);
324         }
325     }
326
327     /*
328     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
329             dependsOnMethods = {"read"})
330         public void readByName(String testName) throws Exception {
331
332             // Perform setup.
333             setupRead();
334
335             // Submit the request to the service and store the response.
336             ClientResponse<MultipartInput> res = client.read(knownResourceId);
337             int statusCode = res.getStatus();
338
339             // Check the status code of the response: does it match
340             // the expected response(s)?
341             if(logger.isDebugEnabled()){
342                 logger.debug(testName + ": status = " + statusCode);
343             }
344             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
345                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
346             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
347             //FIXME: remove the following try catch once Aron fixes signatures
348             try {
349                 MultipartInput input = (MultipartInput) res.getEntity();
350                 OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
351                         client.getCommonPartName(), OrgauthoritiesCommon.class);
352                 Assert.assertNotNull(orgAuthority);
353             } catch (Exception e) {
354                 throw new RuntimeException(e);
355             }
356         }
357     */
358
359     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
360         dependsOnMethods = {"createItem", "read"})
361     public void readItem(String testName) throws Exception {
362
363         // Perform setup.
364         setupRead(testName);
365
366         // Submit the request to the service and store the response.
367         ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
368         int statusCode = res.getStatus();
369
370         // Check the status code of the response: does it match
371         // the expected response(s)?
372         if(logger.isDebugEnabled()){
373             logger.debug(testName + ": status = " + statusCode);
374         }
375         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
376                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
377         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
378
379         // Check whether we've received a organization.
380         MultipartInput input = (MultipartInput) res.getEntity();
381         OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
382                 client.getItemCommonPartName(), OrganizationsCommon.class);
383         Assert.assertNotNull(organization);
384         boolean showFull = true;
385         if(showFull && logger.isDebugEnabled()){
386             logger.debug(testName + ": returned payload:");
387             logger.debug(objectAsXmlString(organization,
388                     OrganizationsCommon.class));
389         }
390         Assert.assertEquals(organization.getInAuthority(), knownResourceId);
391     }
392
393     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
394             dependsOnMethods = {"readItem", "updateItem"})
395     public void verifyItemDisplayName(String testName) throws Exception {
396
397         // Perform setup.
398         setupUpdate(testName);
399
400         // Submit the request to the service and store the response.
401         ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
402         int statusCode = res.getStatus();
403
404         // Check the status code of the response: does it match
405         // the expected response(s)?
406         if(logger.isDebugEnabled()){
407             logger.debug(testName + ": status = " + statusCode);
408         }
409         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
410                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
411         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
412
413         // Check whether organization has expected displayName.
414         MultipartInput input = (MultipartInput) res.getEntity();
415         OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
416                 client.getItemCommonPartName(), OrganizationsCommon.class);
417         Assert.assertNotNull(organization);
418         String displayName = organization.getDisplayName();
419         // Make sure displayName matches computed form
420         String expectedDisplayName = 
421                 OrgAuthorityClientUtils.prepareDefaultDisplayName(
422                                 TEST_ORG_SHORTNAME, TEST_ORG_FOUNDING_PLACE);
423         Assert.assertNotNull(displayName, expectedDisplayName);
424         
425         // Update the shortName and verify the computed name is updated.
426         organization.setDisplayNameComputed(true);
427         organization.setShortName("updated-" + TEST_ORG_SHORTNAME);
428         expectedDisplayName = 
429                 OrgAuthorityClientUtils.prepareDefaultDisplayName(
430                                 "updated-" + TEST_ORG_SHORTNAME, TEST_ORG_FOUNDING_PLACE);
431
432         // Submit the updated resource to the service and store the response.
433         MultipartOutput output = new MultipartOutput();
434         OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
435         commonPart.getHeaders().add("label", client.getItemCommonPartName());
436         res = client.updateItem(knownResourceId, knownItemResourceId, output);
437         statusCode = res.getStatus();
438
439         // Check the status code of the response: does it match the expected response(s)?
440         if(logger.isDebugEnabled()){
441             logger.debug("updateItem: status = " + statusCode);
442         }
443         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
444                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
445         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
446
447         // Retrieve the updated resource and verify that its contents exist.
448         input = (MultipartInput) res.getEntity();
449         OrganizationsCommon updatedOrganization =
450                 (OrganizationsCommon) extractPart(input,
451                         client.getItemCommonPartName(), OrganizationsCommon.class);
452         Assert.assertNotNull(updatedOrganization);
453
454         // Verify that the updated resource received the correct data.
455         Assert.assertEquals(updatedOrganization.getShortName(),
456                 organization.getShortName(),
457                 "Updated ShortName in Organization did not match submitted data.");
458         // Verify that the updated resource computes the right displayName.
459         Assert.assertEquals(updatedOrganization.getDisplayName(),
460                         expectedDisplayName,
461                 "Updated ShortName in Organization not reflected in computed DisplayName.");
462
463         // Now Update the displayName, not computed and verify the computed name is overriden.
464         organization.setDisplayNameComputed(false);
465         expectedDisplayName = "TestName";
466         organization.setDisplayName(expectedDisplayName);
467
468         // Submit the updated resource to the service and store the response.
469         output = new MultipartOutput();
470         commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
471         commonPart.getHeaders().add("label", client.getItemCommonPartName());
472         res = client.updateItem(knownResourceId, knownItemResourceId, output);
473         statusCode = res.getStatus();
474
475         // Check the status code of the response: does it match the expected response(s)?
476         if(logger.isDebugEnabled()){
477             logger.debug("updateItem: status = " + statusCode);
478         }
479         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
480                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
481         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
482
483         // Retrieve the updated resource and verify that its contents exist.
484         input = (MultipartInput) res.getEntity();
485         updatedOrganization =
486                 (OrganizationsCommon) extractPart(input,
487                         client.getItemCommonPartName(), OrganizationsCommon.class);
488         Assert.assertNotNull(updatedOrganization);
489
490         // Verify that the updated resource received the correct data.
491         Assert.assertEquals(updatedOrganization.isDisplayNameComputed(), false,
492                 "Updated displayNameComputed in Organization did not match submitted data.");
493         // Verify that the updated resource computes the right displayName.
494         Assert.assertEquals(updatedOrganization.getDisplayName(),
495                         expectedDisplayName,
496                 "Updated DisplayName (not computed) in Organization not stored.");
497     }
498
499     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
500             dependsOnMethods = {"verifyItemDisplayName"})
501     public void verifyIllegalItemDisplayName(String testName) throws Exception {
502
503         // Perform setup.
504         setupUpdateWithWrongXmlSchema(testName);
505
506         // Submit the request to the service and store the response.
507         ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
508         int statusCode = res.getStatus();
509
510         // Check the status code of the response: does it match
511         // the expected response(s)?
512         if(logger.isDebugEnabled()){
513             logger.debug(testName + ": status = " + statusCode);
514         }
515         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
516                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
517         Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
518
519         // Check whether organization has expected displayName.
520         MultipartInput input = (MultipartInput) res.getEntity();
521         OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
522                 client.getItemCommonPartName(), OrganizationsCommon.class);
523         Assert.assertNotNull(organization);
524         // Try to Update with computed false and no displayName
525         organization.setDisplayNameComputed(false);
526         organization.setDisplayName(null);
527
528         // Submit the updated resource to the service and store the response.
529         MultipartOutput output = new MultipartOutput();
530         OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
531         commonPart.getHeaders().add("label", client.getItemCommonPartName());
532         res = client.updateItem(knownResourceId, knownItemResourceId, output);
533         statusCode = res.getStatus();
534
535         // Check the status code of the response: does it match the expected response(s)?
536         if(logger.isDebugEnabled()){
537             logger.debug("updateItem: status = " + statusCode);
538         }
539         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
540                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
541         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
542     }
543
544     // Failure outcomes
545     @Override
546     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
547         dependsOnMethods = {"read"})
548     public void readNonExistent(String testName) {
549
550         // Perform setup.
551         setupReadNonExistent(testName);
552
553         // Submit the request to the service and store the response.
554         ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
555         int statusCode = res.getStatus();
556
557         // Check the status code of the response: does it match
558         // the expected response(s)?
559         if(logger.isDebugEnabled()){
560             logger.debug(testName + ": status = " + statusCode);
561         }
562         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
563                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
564         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
565     }
566
567     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
568         dependsOnMethods = {"readItem", "readNonExistent"})
569     public void readItemNonExistent(String testName) {
570
571         // Perform setup.
572         setupReadNonExistent(testName);
573
574         // Submit the request to the service and store the response.
575         ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
576         int statusCode = res.getStatus();
577
578         // Check the status code of the response: does it match
579         // the expected response(s)?
580         if(logger.isDebugEnabled()){
581             logger.debug(testName + ": status = " + statusCode);
582         }
583         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
584                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
585         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
586     }
587     // ---------------------------------------------------------------
588     // CRUD tests : READ_LIST tests
589     // ---------------------------------------------------------------
590     // Success outcomes
591
592     @Override
593     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
594         dependsOnMethods = {"createList", "read"})
595     public void readList(String testName) throws Exception {
596
597         // Perform setup.
598         setupReadList(testName);
599
600         // Submit the request to the service and store the response.
601         ClientResponse<OrgauthoritiesCommonList> res = client.readList();
602         OrgauthoritiesCommonList list = res.getEntity();
603         int statusCode = res.getStatus();
604
605         // Check the status code of the response: does it match
606         // the expected response(s)?
607         if(logger.isDebugEnabled()){
608             logger.debug(testName + ": status = " + statusCode);
609         }
610         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
611                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
612         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
613
614         // Optionally output additional data about list members for debugging.
615         boolean iterateThroughList = false;
616         if (iterateThroughList && logger.isDebugEnabled()) {
617             List<OrgauthoritiesCommonList.OrgauthorityListItem> items =
618                     list.getOrgauthorityListItem();
619             int i = 0;
620             for (OrgauthoritiesCommonList.OrgauthorityListItem item : items) {
621                 String csid = item.getCsid();
622                 logger.debug(testName + ": list-item[" + i + "] csid=" +
623                         csid);
624                 logger.debug(testName + ": list-item[" + i + "] displayName=" +
625                         item.getDisplayName());
626                 logger.debug(testName + ": list-item[" + i + "] URI=" +
627                         item.getUri());
628                 readItemList(csid);
629                 i++;
630             }
631         }
632     }
633
634     @Test(dependsOnMethods = {"createList", "readItem"})
635     public void readItemList() {
636         readItemList(knownResourceId);
637     }
638
639     private void readItemList(String vcsid) {
640
641         final String testName = "readItemList";
642
643         // Perform setup.
644         setupReadList(testName);
645
646         // Submit the request to the service and store the response.
647         ClientResponse<OrganizationsCommonList> res =
648                 client.readItemList(vcsid);
649         OrganizationsCommonList list = res.getEntity();
650         int statusCode = res.getStatus();
651
652         // Check the status code of the response: does it match
653         // the expected response(s)?
654         if(logger.isDebugEnabled()){
655             logger.debug("  " + testName + ": status = " + statusCode);
656         }
657         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
658                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
659         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
660
661         List<OrganizationsCommonList.OrganizationListItem> items =
662             list.getOrganizationListItem();
663         int nItemsReturned = items.size();
664         if(logger.isDebugEnabled()){
665             logger.debug("  " + testName + ": Expected "
666                         + nItemsToCreateInList+" items; got: "+nItemsReturned);
667         }
668         Assert.assertEquals( nItemsReturned, nItemsToCreateInList);
669
670         int i = 0;
671         for (OrganizationsCommonList.OrganizationListItem item : items) {
672                 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
673                 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
674                 // Optionally output additional data about list members for debugging.
675                 boolean showDetails = true;
676                 if (showDetails && logger.isDebugEnabled()) {
677                 logger.debug("  " + testName + ": list-item[" + i + "] csid=" +
678                         item.getCsid());
679                 logger.debug("  " + testName + ": list-item[" + i + "] refName=" +
680                         item.getRefName());
681                 logger.debug("  " + testName + ": list-item[" + i + "] displayName=" +
682                         item.getDisplayName());
683                 logger.debug("  " + testName + ": list-item[" + i + "] URI=" +
684                         item.getUri());
685             }
686             i++;
687         }
688     }
689
690     // Failure outcomes
691     // None at present.
692     // ---------------------------------------------------------------
693     // CRUD tests : UPDATE tests
694     // ---------------------------------------------------------------
695     // Success outcomes
696     @Override
697     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
698         dependsOnMethods = {"read"})
699     public void update(String testName) throws Exception {
700
701         // Perform setup.
702         setupUpdate(testName);
703
704         // Retrieve the contents of a resource to update.
705         ClientResponse<MultipartInput> res =
706                 client.read(knownResourceId);
707         if(logger.isDebugEnabled()){
708             logger.debug(testName + ": read status = " + res.getStatus());
709         }
710         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
711
712         if(logger.isDebugEnabled()){
713             logger.debug("got OrgAuthority to update with ID: " + knownResourceId);
714         }
715         MultipartInput input = (MultipartInput) res.getEntity();
716         OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
717                 client.getCommonPartName(), OrgauthoritiesCommon.class);
718         Assert.assertNotNull(orgAuthority);
719
720         // Update the contents of this resource.
721         orgAuthority.setDisplayName("updated-" + orgAuthority.getDisplayName());
722         orgAuthority.setVocabType("updated-" + orgAuthority.getVocabType());
723         if(logger.isDebugEnabled()){
724             logger.debug("to be updated OrgAuthority");
725             logger.debug(objectAsXmlString(orgAuthority, OrgauthoritiesCommon.class));
726         }
727
728         // Submit the updated resource to the service and store the response.
729         MultipartOutput output = new MultipartOutput();
730         OutputPart commonPart = output.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE);
731         commonPart.getHeaders().add("label", client.getCommonPartName());
732         res = client.update(knownResourceId, output);
733         int statusCode = res.getStatus();
734
735         // Check the status code of the response: does it match the expected response(s)?
736         if(logger.isDebugEnabled()){
737             logger.debug("update: status = " + statusCode);
738         }
739         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
740                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
741         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
742
743         // Retrieve the updated resource and verify that its contents exist.
744         input = (MultipartInput) res.getEntity();
745         OrgauthoritiesCommon updatedOrgAuthority =
746                 (OrgauthoritiesCommon) extractPart(input,
747                         client.getCommonPartName(), OrgauthoritiesCommon.class);
748         Assert.assertNotNull(updatedOrgAuthority);
749
750         // Verify that the updated resource received the correct data.
751         Assert.assertEquals(updatedOrgAuthority.getDisplayName(),
752                 orgAuthority.getDisplayName(),
753                 "Data in updated object did not match submitted data.");
754     }
755
756     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
757         dependsOnMethods = {"readItem", "update"})
758     public void updateItem(String testName) throws Exception {
759
760         // Perform setup.
761         setupUpdate(testName);
762
763         ClientResponse<MultipartInput> res =
764                 client.readItem(knownResourceId, knownItemResourceId);
765         if(logger.isDebugEnabled()){
766             logger.debug(testName + ": read status = " + res.getStatus());
767         }
768         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
769
770         if(logger.isDebugEnabled()){
771             logger.debug("got Organization to update with ID: " +
772                 knownItemResourceId +
773                 " in OrgAuthority: " + knownResourceId );
774         }
775         MultipartInput input = (MultipartInput) res.getEntity();
776         OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
777                 client.getItemCommonPartName(), OrganizationsCommon.class);
778         Assert.assertNotNull(organization);
779
780         // Update the contents of this resource.
781         organization.setShortName("updated-" + organization.getShortName());
782         if(logger.isDebugEnabled()){
783             logger.debug("to be updated Organization");
784             logger.debug(objectAsXmlString(organization,
785                 OrganizationsCommon.class));
786         }
787
788         // Submit the updated resource to the service and store the response.
789         MultipartOutput output = new MultipartOutput();
790         OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
791         commonPart.getHeaders().add("label", client.getItemCommonPartName());
792         res = client.updateItem(knownResourceId, knownItemResourceId, output);
793         int statusCode = res.getStatus();
794
795         // Check the status code of the response: does it match the expected response(s)?
796         if(logger.isDebugEnabled()){
797             logger.debug("updateItem: status = " + statusCode);
798         }
799         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
800                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
801         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
802
803         // Retrieve the updated resource and verify that its contents exist.
804         input = (MultipartInput) res.getEntity();
805         OrganizationsCommon updatedOrganization =
806                 (OrganizationsCommon) extractPart(input,
807                         client.getItemCommonPartName(), OrganizationsCommon.class);
808         Assert.assertNotNull(updatedOrganization);
809
810         // Verify that the updated resource received the correct data.
811         Assert.assertEquals(updatedOrganization.getShortName(),
812                 organization.getShortName(),
813                 "Data in updated Organization did not match submitted data.");
814     }
815
816     // Failure outcomes
817     // Placeholders until the three tests below can be uncommented.
818     // See Issue CSPACE-401.
819     @Override
820     public void updateWithEmptyEntityBody(String testName) throws Exception {
821     }
822
823     @Override
824     public void updateWithMalformedXml(String testName) throws Exception {
825     }
826
827     @Override
828     public void updateWithWrongXmlSchema(String testName) throws Exception {
829     }
830
831     /*
832     @Override
833     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
834         dependsOnMethods = {"create", "update", "testSubmitRequest"})
835     public void updateWithEmptyEntityBody(String testName) throws Exception {
836
837     // Perform setup.
838     setupUpdateWithEmptyEntityBody(testName);
839
840     // Submit the request to the service and store the response.
841     String method = REQUEST_TYPE.httpMethodName();
842     String url = getResourceURL(knownResourceId);
843     String mediaType = MediaType.APPLICATION_XML;
844     final String entity = "";
845     int statusCode = submitRequest(method, url, mediaType, entity);
846
847     // Check the status code of the response: does it match
848     // the expected response(s)?
849     if(logger.isDebugEnabled()){
850         logger.debug(testName + ": url=" + url +
851             " status=" + statusCode);
852      }
853     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
854     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
855     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
856     }
857
858     @Override
859     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
860         dependsOnMethods = {"create", "update", "testSubmitRequest"})
861     public void updateWithMalformedXml(String testName) throws Exception {
862
863     // Perform setup.
864     setupUpdateWithMalformedXml(testName);
865
866     // Submit the request to the service and store the response.
867     String method = REQUEST_TYPE.httpMethodName();
868     String url = getResourceURL(knownResourceId);
869     String mediaType = MediaType.APPLICATION_XML;
870     final String entity = MALFORMED_XML_DATA;
871     int statusCode = submitRequest(method, url, mediaType, entity);
872
873     // Check the status code of the response: does it match
874     // the expected response(s)?
875     if(logger.isDebugEnabled()){
876         logger.debug(testName + ": url=" + url +
877            " status=" + statusCode);
878      }
879     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
880     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
881     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
882     }
883
884     @Override
885     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
886         dependsOnMethods = {"create", "update", "testSubmitRequest"})
887     public void updateWithWrongXmlSchema(String testName) throws Exception {
888
889     // Perform setup.
890     setupUpdateWithWrongXmlSchema(testName);
891
892     // Submit the request to the service and store the response.
893     String method = REQUEST_TYPE.httpMethodName();
894     String url = getResourceURL(knownResourceId);
895     String mediaType = MediaType.APPLICATION_XML;
896     final String entity = WRONG_XML_SCHEMA_DATA;
897     int statusCode = submitRequest(method, url, mediaType, entity);
898
899     // Check the status code of the response: does it match
900     // the expected response(s)?
901     if(logger.isDebugEnabled()){
902         logger.debug("updateWithWrongXmlSchema: url=" + url +
903             " status=" + statusCode);
904      }
905     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
906     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
907     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
908     }
909      */
910
911
912     @Override
913     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
914         dependsOnMethods = {"update", "testSubmitRequest"})
915     public void updateNonExistent(String testName) throws Exception {
916
917         // Perform setup.
918         setupUpdateNonExistent(testName);
919
920         // Submit the request to the service and store the response.
921         // Note: The ID used in this 'create' call may be arbitrary.
922         // The only relevant ID may be the one used in update(), below.
923
924         // The only relevant ID may be the one used in update(), below.
925         MultipartOutput multipart = createOrgAuthorityInstance(NON_EXISTENT_ID);
926         ClientResponse<MultipartInput> res =
927                 client.update(NON_EXISTENT_ID, multipart);
928         int statusCode = res.getStatus();
929
930         // Check the status code of the response: does it match
931         // the expected response(s)?
932         if(logger.isDebugEnabled()){
933             logger.debug(testName + ": status = " + statusCode);
934         }
935         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
936                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
937         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
938     }
939
940     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
941         dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
942     public void updateNonExistentItem(String testName) throws Exception {
943
944         // Perform setup.
945         setupUpdateNonExistent(testName);
946
947         // Submit the request to the service and store the response.
948         // Note: The ID used in this 'create' call may be arbitrary.
949         // The only relevant ID may be the one used in update(), below.
950
951         // The only relevant ID may be the one used in update(), below.
952         Map<String, String> nonexOrgMap = new HashMap<String,String>();
953         nonexOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Non-existent");
954         String refName = OrgAuthorityClientUtils.createOrganizationRefName(knownResourceRefName, NON_EXISTENT_ID, true);
955         MultipartOutput multipart = 
956                 OrgAuthorityClientUtils.createOrganizationInstance(
957                         knownResourceId, refName,
958                         nonexOrgMap, client.getItemCommonPartName() );
959         ClientResponse<MultipartInput> res =
960                 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
961         int statusCode = res.getStatus();
962
963         // Check the status code of the response: does it match
964         // the expected response(s)?
965         if(logger.isDebugEnabled()){
966             logger.debug(testName + ": status = " + statusCode);
967         }
968         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
969                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
970         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
971     }
972
973     // ---------------------------------------------------------------
974     // CRUD tests : DELETE tests
975     // ---------------------------------------------------------------
976     // Success outcomes
977     @Override
978     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
979         dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
980     public void delete(String testName) throws Exception {
981
982         // Perform setup.
983         setupDelete(testName);
984
985         // Submit the request to the service and store the response.
986         ClientResponse<Response> res = client.delete(knownResourceId);
987         int statusCode = res.getStatus();
988
989         // Check the status code of the response: does it match
990         // the expected response(s)?
991         if(logger.isDebugEnabled()){
992             logger.debug(testName + ": status = " + statusCode);
993         }
994         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
995                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
996         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
997     }
998
999    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1000         dependsOnMethods = {"createItem", "readItemList", "testItemSubmitRequest",
1001             "updateItem", "verifyIllegalItemDisplayName"})
1002     public void deleteItem(String testName) throws Exception {
1003
1004         // Perform setup.
1005         setupDelete(testName);
1006
1007         // Submit the request to the service and store the response.
1008         ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1009         int statusCode = res.getStatus();
1010
1011         // Check the status code of the response: does it match
1012         // the expected response(s)?
1013         if(logger.isDebugEnabled()){
1014             logger.debug("delete: status = " + statusCode);
1015         }
1016         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1017                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1018         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1019     }
1020
1021     // Failure outcomes
1022     @Override
1023     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1024         dependsOnMethods = {"delete"})
1025     public void deleteNonExistent(String testName) throws Exception {
1026
1027         // Perform setup.
1028         setupDeleteNonExistent(testName);
1029
1030         // Submit the request to the service and store the response.
1031         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1032         int statusCode = res.getStatus();
1033
1034         // Check the status code of the response: does it match
1035         // the expected response(s)?
1036         if(logger.isDebugEnabled()){
1037             logger.debug(testName + ": status = " + statusCode);
1038         }
1039         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1040                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1041         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1042     }
1043
1044     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1045         dependsOnMethods = {"deleteItem"})
1046     public void deleteNonExistentItem(String testName) {
1047
1048         // Perform setup.
1049         setupDeleteNonExistent(testName);
1050
1051         // Submit the request to the service and store the response.
1052         ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1053         int statusCode = res.getStatus();
1054
1055         // Check the status code of the response: does it match
1056         // the expected response(s)?
1057         if(logger.isDebugEnabled()){
1058             logger.debug(testName + ": status = " + statusCode);
1059         }
1060         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1061                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1062         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1063     }
1064
1065     // ---------------------------------------------------------------
1066     // Utility tests : tests of code used in tests above
1067     // ---------------------------------------------------------------
1068     /**
1069      * Tests the code for manually submitting data that is used by several
1070      * of the methods above.
1071      */
1072     @Test(dependsOnMethods = {"create", "read"})
1073     public void testSubmitRequest() {
1074
1075         // Expected status code: 200 OK
1076         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1077
1078         // Submit the request to the service and store the response.
1079         String method = ServiceRequestType.READ.httpMethodName();
1080         String url = getResourceURL(knownResourceId);
1081         int statusCode = submitRequest(method, url);
1082
1083         // Check the status code of the response: does it match
1084         // the expected response(s)?
1085         if(logger.isDebugEnabled()){
1086             logger.debug("testSubmitRequest: url=" + url +
1087                 " status=" + statusCode);
1088         }
1089         Assert.assertEquals(statusCode, EXPECTED_STATUS);
1090
1091     }
1092
1093     @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1094     public void testItemSubmitRequest() {
1095
1096         // Expected status code: 200 OK
1097         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1098
1099         // Submit the request to the service and store the response.
1100         String method = ServiceRequestType.READ.httpMethodName();
1101         String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1102         int statusCode = submitRequest(method, url);
1103
1104         // Check the status code of the response: does it match
1105         // the expected response(s)?
1106         if(logger.isDebugEnabled()){
1107             logger.debug("testItemSubmitRequest: url=" + url +
1108                 " status=" + statusCode);
1109         }
1110         Assert.assertEquals(statusCode, EXPECTED_STATUS);
1111
1112     }
1113
1114     // ---------------------------------------------------------------
1115     // Cleanup of resources created during testing
1116     // ---------------------------------------------------------------
1117     
1118     /**
1119      * Deletes all resources created by tests, after all tests have been run.
1120      *
1121      * This cleanup method will always be run, even if one or more tests fail.
1122      * For this reason, it attempts to remove all resources created
1123      * at any point during testing, even if some of those resources
1124      * may be expected to be deleted by certain tests.
1125      */
1126     @AfterClass(alwaysRun=true)
1127     public void cleanUp() {
1128         if (logger.isDebugEnabled()) {
1129             logger.debug("Cleaning up temporary resources created for testing ...");
1130         }
1131         // Clean up organization resources.
1132         String orgAuthorityResourceId;
1133         String organizationResourceId;
1134         for (Map.Entry<String, String> entry : allResourceItemIdsCreated.entrySet()) {
1135             organizationResourceId = entry.getKey();
1136             orgAuthorityResourceId = entry.getValue();
1137             // Note: Any non-success responses are ignored and not reported.
1138             ClientResponse<Response> res =
1139                 client.deleteItem(orgAuthorityResourceId, organizationResourceId);
1140         }
1141         // Clean up orgAuthority resources.
1142         for (String resourceId : allResourceIdsCreated) {
1143             // Note: Any non-success responses are ignored and not reported.
1144             ClientResponse<Response> res = client.delete(resourceId);
1145         }
1146     }
1147
1148     // ---------------------------------------------------------------
1149     // Utility methods used by tests above
1150     // ---------------------------------------------------------------
1151     @Override
1152     public String getServicePathComponent() {
1153         return SERVICE_PATH_COMPONENT;
1154     }
1155
1156     public String getItemServicePathComponent() {
1157         return ITEM_SERVICE_PATH_COMPONENT;
1158     }
1159
1160     /**
1161      * Returns the root URL for a service.
1162      *
1163      * This URL consists of a base URL for all services, followed by
1164      * a path component for the owning orgAuthority, followed by the 
1165      * path component for the items.
1166      *
1167      * @return The root URL for a service.
1168      */
1169     protected String getItemServiceRootURL(String parentResourceIdentifier) {
1170         return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1171     }
1172
1173     /**
1174      * Returns the URL of a specific resource managed by a service, and
1175      * designated by an identifier (such as a universally unique ID, or UUID).
1176      *
1177      * @param  resourceIdentifier  An identifier (such as a UUID) for a resource.
1178      *
1179      * @return The URL of a specific resource managed by a service.
1180      */
1181     protected String getItemResourceURL(String parentResourceIdentifier, String resourceIdentifier) {
1182         return getItemServiceRootURL(parentResourceIdentifier) + "/" + resourceIdentifier;
1183     }
1184
1185     private MultipartOutput createOrgAuthorityInstance(String identifier) {
1186         String displayName = "displayName-" + identifier;
1187         String refName = OrgAuthorityClientUtils.createOrgAuthRefName(displayName, true);
1188         return OrgAuthorityClientUtils.createOrgAuthorityInstance(
1189                                 displayName, refName, 
1190                                 client.getCommonPartName());
1191     }
1192 }