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