]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
fb103e585acedabd9468fd0c8231a1c560ac3ca4
[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,
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                 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(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: \"" + 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: \"" + 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         int statusCode = res.getStatus();
436
437         // Check the status code of the response: does it match
438         // the expected response(s)?
439         if (logger.isDebugEnabled()) {
440             logger.debug(testName + ": status = " + statusCode);
441         }
442         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
443                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
444         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
445         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
446         VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input,
447                 client.getCommonPartName(), VocabulariesCommon.class);
448
449         Assert.assertNotNull(vocabulary);
450     }
451
452     /*
453     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
454     dependsOnMethods = {"read"})
455     public void readByName(String testName) throws Exception {
456
457     if (logger.isDebugEnabled()) {
458     logger.debug(testBanner(testName, CLASS_NAME));
459     }
460     // Perform setup.
461     setupRead();
462
463     // Submit the request to the service and store the response.
464     ClientResponse<PoxPayloadIn> res = client.read(knownResourceId);
465     int statusCode = res.getStatus();
466
467     // Check the status code of the response: does it match
468     // the expected response(s)?
469     if(logger.isDebugEnabled()){
470     logger.debug(testName + ": status = " + statusCode);
471     }
472     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
473     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
474     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
475     //FIXME: remove the following try catch once Aron fixes signatures
476     try {
477     PoxPayloadIn input = (PoxPayloadIn) res.getEntity();
478     VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input,
479     client.getCommonPartName(), VocabulariesCommon.class);
480     Assert.assertNotNull(vocabulary);
481     } catch (Exception e) {
482     throw new RuntimeException(e);
483     }
484     }
485      */
486     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
487     dependsOnMethods = {"createItem", "read"})
488     public void readItem(String testName) throws Exception {
489
490         if (logger.isDebugEnabled()) {
491             logger.debug(testBanner(testName, CLASS_NAME));
492         }
493         // Perform setup.
494         setupRead();
495
496         // Submit the request to the service and store the response.
497         VocabularyClient client = new VocabularyClient();
498         ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
499         int statusCode = res.getStatus();
500
501         // Check the status code of the response: does it match
502         // the expected response(s)?
503         if (logger.isDebugEnabled()) {
504             logger.debug(testName + ": status = " + statusCode);
505         }
506         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
507                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
508         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
509
510         // Check whether we've received a vocabulary item.
511         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
512         VocabularyitemsCommon vocabularyItem = (VocabularyitemsCommon) extractPart(input,
513                 client.getCommonPartItemName(), VocabularyitemsCommon.class);
514         Assert.assertNotNull(vocabularyItem);
515         Assert.assertEquals(vocabularyItem.getInAuthority(), knownResourceId);
516     }
517
518     // Failure outcomes
519     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
520     dependsOnMethods = {"updateItem"})
521     public void verifyIllegalItemDisplayName(String testName) throws Exception {
522
523         if (logger.isDebugEnabled()) {
524             logger.debug(testBanner(testName, CLASS_NAME));
525         }
526         // Perform setup.
527         testSetup(STATUS_BAD_REQUEST, ServiceRequestType.UPDATE);
528         // setupUpdateWithWrongXmlSchema(testName);
529
530         // Submit the request to the service and store the response.
531         VocabularyClient client = new VocabularyClient();
532         ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
533         int statusCode = res.getStatus();
534
535         // Check the status code of the response: does it match
536         // the expected response(s)?
537         if (logger.isDebugEnabled()) {
538             logger.debug(testName + ": status = " + statusCode);
539         }
540         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
541                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
542         Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
543
544         // Check whether Person has expected displayName.
545         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
546         VocabularyitemsCommon vitem = (VocabularyitemsCommon) extractPart(input,
547                 client.getCommonPartItemName(), VocabularyitemsCommon.class);
548         Assert.assertNotNull(vitem);
549         // Try to Update with null displayName
550         vitem.setDisplayName(null);
551
552         // Submit the updated resource to the service and store the response.
553         PoxPayloadOut output = new PoxPayloadOut(SERVICE_ITEM_PAYLOAD_NAME);
554         PayloadOutputPart commonPart = output.addPart(vitem, MediaType.APPLICATION_XML_TYPE);
555         commonPart.setLabel(client.getCommonPartItemName());
556         res = client.updateItem(knownResourceId, knownItemResourceId, output);
557         statusCode = res.getStatus();
558
559         // Check the status code of the response: does it match the expected response(s)?
560         if (logger.isDebugEnabled()) {
561             logger.debug("updateItem: status = " + statusCode);
562         }
563         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
564                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
565         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE,
566                 "Expecting invalid message because of null displayName.");
567
568         // Now try to Update with 1-char displayName (too short)
569         vitem.setDisplayName("a");
570
571         // Submit the updated resource to the service and store the response.
572         output = new PoxPayloadOut(SERVICE_ITEM_PAYLOAD_NAME);
573         commonPart = output.addPart(vitem, MediaType.APPLICATION_XML_TYPE);
574         commonPart.setLabel(client.getCommonPartItemName());
575         res = client.updateItem(knownResourceId, knownItemResourceId, output);
576         statusCode = res.getStatus();
577
578         // Check the status code of the response: does it match the expected response(s)?
579         if (logger.isDebugEnabled()) {
580             logger.debug("updateItem: status = " + statusCode);
581         }
582         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
583                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
584         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE,
585                 "Expecting invalid message because of 1-char displayName.");
586     }
587
588     @Override
589     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
590     dependsOnMethods = {"read"})
591     public void readNonExistent(String testName) {
592
593         if (logger.isDebugEnabled()) {
594             logger.debug(testBanner(testName, CLASS_NAME));
595         }
596         // Perform setup.
597         setupReadNonExistent();
598
599         // Submit the request to the service and store the response.
600         VocabularyClient client = new VocabularyClient();
601         ClientResponse<String> res = client.read(NON_EXISTENT_ID);
602         int statusCode = res.getStatus();
603
604         // Check the status code of the response: does it match
605         // the expected response(s)?
606         if (logger.isDebugEnabled()) {
607             logger.debug(testName + ": status = " + statusCode);
608         }
609         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
610                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
611         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
612     }
613
614     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
615     dependsOnMethods = {"readItem", "readNonExistent"})
616     public void readItemNonExistent(String testName) {
617
618         if (logger.isDebugEnabled()) {
619             logger.debug(testBanner(testName, CLASS_NAME));
620         }
621         // Perform setup.
622         setupReadNonExistent();
623
624         // Submit the request to the service and store the response.
625         VocabularyClient client = new VocabularyClient();
626         ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
627         int statusCode = res.getStatus();
628
629         // Check the status code of the response: does it match
630         // the expected response(s)?
631         if (logger.isDebugEnabled()) {
632             logger.debug(testName + ": status = " + statusCode);
633         }
634         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
635                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
636         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
637     }
638     // ---------------------------------------------------------------
639     // CRUD tests : READ_LIST tests
640     // ---------------------------------------------------------------
641     // Success outcomes
642
643     @Override
644     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
645     dependsOnMethods = {"createList", "read"})
646     public void readList(String testName) throws Exception {
647
648         if (logger.isDebugEnabled()) {
649             logger.debug(testBanner(testName, CLASS_NAME));
650         }
651         // Perform setup.
652         setupReadList();
653
654         // Submit the request to the service and store the response.
655         VocabularyClient client = new VocabularyClient();
656         ClientResponse<AbstractCommonList> res = client.readList();
657         AbstractCommonList list = res.getEntity();
658         int statusCode = res.getStatus();
659
660         // Check the status code of the response: does it match
661         // the expected response(s)?
662         if (logger.isDebugEnabled()) {
663             logger.debug(testName + ": status = " + statusCode);
664         }
665         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
666                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
667         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
668
669         // Optionally output additional data about list members for debugging.
670         if(logger.isTraceEnabled()){
671                 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
672         }
673     }
674
675     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
676     dependsOnMethods = {"createList", "readItem"})
677     public void readItemList(String testName) {
678         readItemListInt(knownResourceId, null, testName);
679     }
680
681     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
682     dependsOnMethods = {"createList", "readItem"})
683     public void readItemListByName(String testName) {
684         readItemListInt(null, knownResourceShortIdentifer, testName);
685     }
686
687     private void readItemListInt(String vcsid, String shortId, String testName) {
688
689         // Perform setup.
690         setupReadList();
691
692         // Submit the request to the service and store the response.
693         VocabularyClient client = new VocabularyClient();
694         ClientResponse<AbstractCommonList> res = null;
695         if (vcsid != null) {
696             res = client.readItemList(vcsid, null, null);
697         } else if (shortId != null) {
698             res = client.readItemListForNamedAuthority(shortId, null, null);
699         } else {
700             Assert.fail("Internal Error: readItemList both vcsid and shortId are null!");
701         }
702         AbstractCommonList list = res.getEntity();
703         int statusCode = res.getStatus();
704
705         // Check the status code of the response: does it match
706         // the expected response(s)?
707         if (logger.isDebugEnabled()) {
708             logger.debug("  " + testName + ": status = " + statusCode);
709         }
710         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
711                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
712         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
713
714         List<AbstractCommonList.ListItem> items = list.getListItem();
715         int nItemsReturned = items.size();
716         long nItemsTotal = list.getTotalItems();
717         if (logger.isDebugEnabled()) {
718             logger.debug("  " + testName + ": Expected "
719                     + nItemsToCreateInList + " items; got: " + nItemsReturned + " of: " + nItemsTotal);
720         }
721         Assert.assertEquals(nItemsTotal, nItemsToCreateInList);
722
723         if(logger.isTraceEnabled()){
724                 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
725         }
726     }
727
728     // Failure outcomes
729     // None at present.
730     // ---------------------------------------------------------------
731     // CRUD tests : UPDATE tests
732     // ---------------------------------------------------------------
733     // Success outcomes
734     @Override
735     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
736     dependsOnMethods = {"read"})
737     public void update(String testName) throws Exception {
738
739         if (logger.isDebugEnabled()) {
740             logger.debug(testBanner(testName, CLASS_NAME));
741         }
742         // Perform setup.
743         setupUpdate();
744
745         // Retrieve the contents of a resource to update.
746         VocabularyClient client = new VocabularyClient();
747         ClientResponse<String> res =
748                 client.read(knownResourceId);
749         if (logger.isDebugEnabled()) {
750             logger.debug(testName + ": read status = " + res.getStatus());
751         }
752         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
753
754         if (logger.isDebugEnabled()) {
755             logger.debug("got Vocabulary to update with ID: " + knownResourceId);
756         }
757         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
758         VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input,
759                 client.getCommonPartName(), VocabulariesCommon.class);
760         Assert.assertNotNull(vocabulary);
761
762         // Update the contents of this resource.
763         vocabulary.setDisplayName("updated-" + vocabulary.getDisplayName());
764         vocabulary.setVocabType("updated-" + vocabulary.getVocabType());
765         if (logger.isDebugEnabled()) {
766             logger.debug("to be updated Vocabulary");
767             logger.debug(objectAsXmlString(vocabulary, VocabulariesCommon.class));
768         }
769
770         // Submit the updated resource to the service and store the response.
771         PoxPayloadOut output = new PoxPayloadOut(SERVICE_PAYLOAD_NAME);
772
773         PayloadOutputPart commonPart = output.addPart(vocabulary, MediaType.APPLICATION_XML_TYPE);
774         commonPart.setLabel(client.getCommonPartName());
775         res = client.update(knownResourceId, output);
776         int statusCode = res.getStatus();
777
778         // Check the status code of the response: does it match the expected response(s)?
779         if (logger.isDebugEnabled()) {
780             logger.debug("update: status = " + statusCode);
781         }
782         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
783                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
784         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
785
786         // Retrieve the updated resource and verify that its contents exist.
787         input = new PoxPayloadIn(res.getEntity());
788         VocabulariesCommon updatedVocabulary =
789                 (VocabulariesCommon) extractPart(input,
790                 client.getCommonPartName(), VocabulariesCommon.class);
791         Assert.assertNotNull(updatedVocabulary);
792
793         // Verify that the updated resource received the correct data.
794         Assert.assertEquals(updatedVocabulary.getDisplayName(),
795                 vocabulary.getDisplayName(),
796                 "Data in updated object did not match submitted data.");
797     }
798
799     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
800     dependsOnMethods = {"readItem", "update", "verifyIgnoredUpdateWithInAuthority"})
801     public void updateItem(String testName) throws Exception {
802
803         if (logger.isDebugEnabled()) {
804             logger.debug(testBanner(testName, CLASS_NAME));
805         }
806         // Perform setup.
807         setupUpdate();
808
809         // Retrieve the contents of a resource to update.
810         VocabularyClient client = new VocabularyClient();
811         ClientResponse<String> res =
812                 client.readItem(knownResourceId, knownItemResourceId);
813         if (logger.isDebugEnabled()) {
814             logger.debug(testName + ": read status = " + res.getStatus());
815         }
816         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
817
818         if (logger.isDebugEnabled()) {
819             logger.debug("got VocabularyItem to update with ID: "
820                     + knownItemResourceId
821                     + " in Vocab: " + knownResourceId);
822         }
823         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
824         VocabularyitemsCommon vocabularyItem = (VocabularyitemsCommon) extractPart(input,
825                 client.getCommonPartItemName(), VocabularyitemsCommon.class);
826         Assert.assertNotNull(vocabularyItem);
827
828         // Update the contents of this resource.
829         vocabularyItem.setDisplayName("updated-" + vocabularyItem.getDisplayName());
830         if (logger.isDebugEnabled()) {
831             logger.debug("to be updated VocabularyItem");
832             logger.debug(objectAsXmlString(vocabularyItem,
833                     VocabularyitemsCommon.class));
834         }
835
836         // Submit the updated resource to the service and store the response.
837         PoxPayloadOut output = new PoxPayloadOut(SERVICE_ITEM_PAYLOAD_NAME);
838         PayloadOutputPart commonPart = output.addPart(vocabularyItem, MediaType.APPLICATION_XML_TYPE);
839         commonPart.setLabel(client.getCommonPartItemName());
840         res = client.updateItem(knownResourceId, knownItemResourceId, output);
841         int statusCode = res.getStatus();
842
843         // Check the status code of the response: does it match the expected response(s)?
844         if (logger.isDebugEnabled()) {
845             logger.debug("updateItem: status = " + statusCode);
846         }
847         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
848                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
849         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
850
851         // Retrieve the updated resource and verify that its contents exist.
852         input = new PoxPayloadIn(res.getEntity());
853         VocabularyitemsCommon updatedVocabularyItem =
854                 (VocabularyitemsCommon) extractPart(input,
855                 client.getCommonPartItemName(), VocabularyitemsCommon.class);
856         Assert.assertNotNull(updatedVocabularyItem);
857
858         // Verify that the updated resource received the correct data.
859         Assert.assertEquals(updatedVocabularyItem.getDisplayName(),
860                 vocabularyItem.getDisplayName(),
861                 "Data in updated VocabularyItem did not match submitted data.");
862     }
863
864     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
865     dependsOnMethods = {"readItem"})
866     public void verifyIgnoredUpdateWithInAuthority(String testName) throws Exception {
867
868         if (logger.isDebugEnabled()) {
869             logger.debug(testBanner(testName, CLASS_NAME));
870         }
871         // Perform setup.
872         setupUpdate();
873
874         // Submit the request to the service and store the response.
875         VocabularyClient client = new VocabularyClient();
876         ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
877         int statusCode = res.getStatus();
878
879         // Check the status code of the response: does it match
880         // the expected response(s)?
881         if (logger.isDebugEnabled()) {
882             logger.debug(testName + " read Vocab:" + knownResourceId + "/Item:"
883                     + knownItemResourceId + " status = " + statusCode);
884         }
885         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
886                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
887         Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
888
889         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
890         VocabularyitemsCommon vitem = (VocabularyitemsCommon) extractPart(input,
891                 client.getCommonPartItemName(), VocabularyitemsCommon.class);
892         Assert.assertNotNull(vitem);
893         // Try to Update with new parent vocab (use self, for test).
894         Assert.assertEquals(vitem.getInAuthority(),
895                 knownResourceId,
896                 "VocabularyItem inAuthority does not match knownResourceId.");
897         vitem.setInAuthority(knownItemResourceId);
898
899         // Submit the updated resource to the service and store the response.
900         PoxPayloadOut output = new PoxPayloadOut(SERVICE_ITEM_PAYLOAD_NAME);
901         PayloadOutputPart commonPart = output.addPart(vitem, MediaType.APPLICATION_XML_TYPE);
902         commonPart.setLabel(client.getCommonPartItemName());
903         res = client.updateItem(knownResourceId, knownItemResourceId, output);
904         statusCode = res.getStatus();
905
906         // Check the status code of the response: does it match the expected response(s)?
907         if (logger.isDebugEnabled()) {
908             logger.debug(testName + ": status = " + statusCode);
909         }
910         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
911                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
912         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
913
914         // Retrieve the updated resource and verify that the parent did not change
915         res = client.readItem(knownResourceId, knownItemResourceId);
916         input = new PoxPayloadIn(res.getEntity());
917         VocabularyitemsCommon updatedVocabularyItem =
918                 (VocabularyitemsCommon) extractPart(input,
919                 client.getCommonPartItemName(), VocabularyitemsCommon.class);
920         Assert.assertNotNull(updatedVocabularyItem);
921
922         // Verify that the updated resource received the correct data.
923         Assert.assertEquals(updatedVocabularyItem.getInAuthority(),
924                 knownResourceId,
925                 "VocabularyItem allowed update to the parent (inAuthority).");
926     }
927
928     // Failure outcomes
929     // Placeholders until the three tests below can be uncommented.
930     // See Issue CSPACE-401.
931     @Override
932     public void updateWithEmptyEntityBody(String testName) throws Exception {
933     }
934
935     @Override
936     public void updateWithMalformedXml(String testName) throws Exception {
937     }
938
939     @Override
940     public void updateWithWrongXmlSchema(String testName) throws Exception {
941     }
942
943     /*
944     @Override
945     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
946     dependsOnMethods = {"create", "update", "testSubmitRequest"})
947     public void updateWithEmptyEntityBody(String testName) throws Exception {
948
949     if (logger.isDebugEnabled()) {
950     logger.debug(testBanner(testName, CLASS_NAME));
951     }
952     // Perform setup.
953     setupUpdateWithEmptyEntityBody();
954
955     // Submit the request to the service and store the response.
956     String method = REQUEST_TYPE.httpMethodName();
957     String url = getResourceURL(knownResourceId);
958     String mediaType = MediaType.APPLICATION_XML;
959     final String entity = "";
960     int statusCode = submitRequest(method, url, mediaType, entity);
961
962     // Check the status code of the response: does it match
963     // the expected response(s)?
964     if(logger.isDebugEnabled()){
965     logger.debug(testName + ": url=" + url +
966     " 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     @Override
974     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
975     dependsOnMethods = {"create", "update", "testSubmitRequest"})
976     public void updateWithMalformedXml(String testName) throws Exception {
977
978     if (logger.isDebugEnabled()) {
979     logger.debug(testBanner(testName, CLASS_NAME));
980     }
981     // Perform setup.
982     setupUpdateWithMalformedXml();
983
984     // Submit the request to the service and store the response.
985     String method = REQUEST_TYPE.httpMethodName();
986     String url = getResourceURL(knownResourceId);
987     String mediaType = MediaType.APPLICATION_XML;
988     final String entity = MALFORMED_XML_DATA;
989     int statusCode = submitRequest(method, url, mediaType, entity);
990
991     // Check the status code of the response: does it match
992     // the expected response(s)?
993     if(logger.isDebugEnabled()){
994     logger.debug(testName + ": url=" + url +
995     " status=" + statusCode);
996     }
997     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
998     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
999     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1000     }
1001
1002     @Override
1003     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1004     dependsOnMethods = {"create", "update", "testSubmitRequest"})
1005     public void updateWithWrongXmlSchema(String testName) throws Exception {
1006
1007     if (logger.isDebugEnabled()) {
1008     logger.debug(testBanner(testName, CLASS_NAME));
1009     }
1010     // Perform setup.
1011     setupUpdateWithWrongXmlSchema();
1012
1013     // Submit the request to the service and store the response.
1014     String method = REQUEST_TYPE.httpMethodName();
1015     String url = getResourceURL(knownResourceId);
1016     String mediaType = MediaType.APPLICATION_XML;
1017     final String entity = WRONG_XML_SCHEMA_DATA;
1018     int statusCode = submitRequest(method, url, mediaType, entity);
1019
1020     // Check the status code of the response: does it match
1021     // the expected response(s)?
1022     if(logger.isDebugEnabled()){
1023     logger.debug("updateWithWrongXmlSchema: url=" + url +
1024     " status=" + statusCode);
1025     }
1026     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1027     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1028     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1029     }
1030      */
1031     @Override
1032     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1033     dependsOnMethods = {"update", "testSubmitRequest"})
1034     public void updateNonExistent(String testName) throws Exception {
1035
1036         if (logger.isDebugEnabled()) {
1037             logger.debug(testBanner(testName, CLASS_NAME));
1038         }
1039         // Perform setup.
1040         setupUpdateNonExistent();
1041
1042         // Submit the request to the service and store the response.
1043         // Note: The ID used in this 'create' call may be arbitrary.
1044         // The only relevant ID may be the one used in update(), below.
1045         VocabularyClient client = new VocabularyClient();
1046         String displayName = "displayName-" + NON_EXISTENT_ID;
1047         PoxPayloadOut multipart = VocabularyClientUtils.createEnumerationInstance(
1048                 displayName, NON_EXISTENT_ID, client.getCommonPartName());
1049         ClientResponse<String> res =
1050                 client.update(NON_EXISTENT_ID, multipart);
1051         int statusCode = res.getStatus();
1052
1053         // Check the status code of the response: does it match
1054         // the expected response(s)?
1055         if (logger.isDebugEnabled()) {
1056             logger.debug(testName + ": status = " + statusCode);
1057         }
1058         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1059                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1060         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1061     }
1062
1063     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1064     dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1065     public void updateNonExistentItem(String testName) throws Exception {
1066
1067         if (logger.isDebugEnabled()) {
1068             logger.debug(testBanner(testName, CLASS_NAME));
1069         }
1070         // Perform setup.
1071         setupUpdateNonExistent();
1072
1073         // Submit the request to the service and store the response.
1074         // Note: The ID used in this 'create' call may be arbitrary.
1075         // The only relevant ID may be the one used in update(), below.
1076         VocabularyClient client = new VocabularyClient();
1077         HashMap<String, String> itemInfo = new HashMap<String, String>();
1078         itemInfo.put(AuthorityItemJAXBSchema.SHORT_IDENTIFIER, "nonex");
1079         itemInfo.put(AuthorityItemJAXBSchema.DISPLAY_NAME, "display-nonex");
1080         PoxPayloadOut multipart =
1081                 VocabularyClientUtils.createVocabularyItemInstance(
1082                 VocabularyClientUtils.createVocabularyRefName(NON_EXISTENT_ID, null),
1083                 itemInfo, client.getCommonPartItemName());
1084         ClientResponse<String> res =
1085                 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1086         int statusCode = res.getStatus();
1087
1088         // Check the status code of the response: does it match
1089         // the expected response(s)?
1090         if (logger.isDebugEnabled()) {
1091             logger.debug(testName + ": status = " + statusCode);
1092         }
1093         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1094                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1095         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1096     }
1097
1098     // ---------------------------------------------------------------
1099     // CRUD tests : DELETE tests
1100     // ---------------------------------------------------------------
1101     // Success outcomes
1102     @Override
1103     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1104     dependsOnMethods = {"create", "readList", "testSubmitRequest", "update", "deleteItem"})
1105     public void delete(String testName) throws Exception {
1106
1107         if (logger.isDebugEnabled()) {
1108             logger.debug(testBanner(testName, CLASS_NAME));
1109         }
1110         // Perform setup.
1111         setupDelete();
1112
1113         // Submit the request to the service and store the response.
1114         VocabularyClient client = new VocabularyClient();
1115         ClientResponse<Response> res = client.delete(knownResourceId);
1116         int statusCode = res.getStatus();
1117
1118         // Check the status code of the response: does it match
1119         // the expected response(s)?
1120         if (logger.isDebugEnabled()) {
1121             logger.debug(testName + ": status = " + statusCode);
1122         }
1123         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1124                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1125         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1126     }
1127
1128     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1129     dependsOnMethods = {"createItem", "readItemList", "testItemSubmitRequest",
1130         "updateItem", "verifyIllegalItemDisplayName", "verifyIgnoredUpdateWithInAuthority"})
1131     public void deleteItem(String testName) throws Exception {
1132
1133         if (logger.isDebugEnabled()) {
1134             logger.debug(testBanner(testName, CLASS_NAME));
1135         }
1136         // Perform setup.
1137         setupDelete();
1138
1139         // Submit the request to the service and store the response.
1140         VocabularyClient client = new VocabularyClient();
1141         ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1142         int statusCode = res.getStatus();
1143
1144         // Check the status code of the response: does it match
1145         // the expected response(s)?
1146         if (logger.isDebugEnabled()) {
1147             logger.debug("delete: status = " + statusCode);
1148         }
1149         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1150                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1151         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1152     }
1153
1154     // Failure outcomes
1155     @Override
1156     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1157     dependsOnMethods = {"delete"})
1158     public void deleteNonExistent(String testName) throws Exception {
1159
1160         if (logger.isDebugEnabled()) {
1161             logger.debug(testBanner(testName, CLASS_NAME));
1162         }
1163         // Perform setup.
1164         setupDeleteNonExistent();
1165
1166         // Submit the request to the service and store the response.
1167         VocabularyClient client = new VocabularyClient();
1168         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1169         int statusCode = res.getStatus();
1170
1171         // Check the status code of the response: does it match
1172         // the expected response(s)?
1173         if (logger.isDebugEnabled()) {
1174             logger.debug(testName + ": status = " + statusCode);
1175         }
1176         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1177                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1178         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1179     }
1180
1181     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1182     dependsOnMethods = {"deleteItem"})
1183     public void deleteNonExistentItem(String testName) {
1184
1185         if (logger.isDebugEnabled()) {
1186             logger.debug(testBanner(testName, CLASS_NAME));
1187         }
1188         // Perform setup.
1189         setupDeleteNonExistent();
1190
1191         // Submit the request to the service and store the response.
1192         VocabularyClient client = new VocabularyClient();
1193         ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1194         int statusCode = res.getStatus();
1195
1196         // Check the status code of the response: does it match
1197         // the expected response(s)?
1198         if (logger.isDebugEnabled()) {
1199             logger.debug(testName + ": status = " + statusCode);
1200         }
1201         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1202                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1203         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1204     }
1205
1206     // ---------------------------------------------------------------
1207     // Utility tests : tests of code used in tests above
1208     // ---------------------------------------------------------------
1209     /**
1210      * Tests the code for manually submitting data that is used by several
1211      * of the methods above.
1212      */
1213     @Test(dependsOnMethods = {"create", "read"})
1214     public void testSubmitRequest() {
1215
1216         // Expected status code: 200 OK
1217         setupRead();
1218
1219         // Submit the request to the service and store the response.
1220         String method = ServiceRequestType.READ.httpMethodName();
1221         String url = getResourceURL(knownResourceId);
1222         int statusCode = submitRequest(method, url);
1223
1224         // Check the status code of the response: does it match
1225         // the expected response(s)?
1226         if (logger.isDebugEnabled()) {
1227             logger.debug("testSubmitRequest: url=" + url
1228                     + " status=" + statusCode);
1229         }
1230         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1231
1232     }
1233
1234     @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1235     public void testItemSubmitRequest() {
1236
1237         // Expected status code: 200 OK
1238         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1239
1240         // Submit the request to the service and store the response.
1241         String method = ServiceRequestType.READ.httpMethodName();
1242         String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1243         int statusCode = submitRequest(method, url);
1244
1245         // Check the status code of the response: does it match
1246         // the expected response(s)?
1247         if (logger.isDebugEnabled()) {
1248             logger.debug("testItemSubmitRequest: url=" + url
1249                     + " status=" + statusCode);
1250         }
1251         Assert.assertEquals(statusCode, EXPECTED_STATUS);
1252
1253     }
1254
1255     // ---------------------------------------------------------------
1256     // Cleanup of resources created during testing
1257     // ---------------------------------------------------------------
1258     /**
1259      * Deletes all resources created by tests, after all tests have been run.
1260      *
1261      * This cleanup method will always be run, even if one or more tests fail.
1262      * For this reason, it attempts to remove all resources created
1263      * at any point during testing, even if some of those resources
1264      * may be expected to be deleted by certain tests.
1265      */
1266 //    @AfterClass(alwaysRun = true)
1267 //    public void cleanUp() {
1268 //        String noTest = System.getProperty("noTestCleanup");
1269 //        if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1270 //            if (logger.isDebugEnabled()) {
1271 //                logger.debug("Skipping Cleanup phase ...");
1272 //            }
1273 //            return;
1274 //        }
1275 //        if (logger.isDebugEnabled()) {
1276 //            logger.debug("Cleaning up temporary resources created for testing ...");
1277 //        }
1278 //        VocabularyClient client = new VocabularyClient();
1279 //        String vocabularyResourceId;
1280 //        String vocabularyItemResourceId;
1281 //        // Clean up vocabulary item resources.
1282 //        for (Map.Entry<String, String> entry : allResourceItemIdsCreated.entrySet()) {
1283 //            vocabularyItemResourceId = entry.getKey();
1284 //            vocabularyResourceId = entry.getValue();
1285 //            // Note: Any non-success responses are ignored and not reported.
1286 //            client.deleteItem(vocabularyResourceId, vocabularyItemResourceId).releaseConnection();
1287 //        }
1288 //        // Clean up vocabulary resources.
1289 //        for (String resourceId : allResourceIdsCreated) {
1290 //            // Note: Any non-success responses are ignored and not reported.
1291 //            client.delete(resourceId).releaseConnection();
1292 //        }
1293 //
1294 //    }
1295
1296     // ---------------------------------------------------------------
1297     // Utility methods used by tests above
1298     // ---------------------------------------------------------------
1299     @Override
1300     public String getServicePathComponent() {
1301         return SERVICE_PATH_COMPONENT;
1302     }
1303
1304     public String getServicePathItemsComponent() {
1305         return AuthorityClient.ITEMS;
1306     }
1307
1308     /**
1309      * Returns the root URL for a service.
1310      *
1311      * This URL consists of a base URL for all services, followed by
1312      * a path component for the owning vocabulary, followed by the 
1313      * path component for the items.
1314      *
1315      * @return The root URL for a service.
1316      */
1317     protected String getItemServiceRootURL(String parentResourceIdentifier) {
1318         return getResourceURL(parentResourceIdentifier) + "/" + getServicePathItemsComponent();
1319     }
1320
1321     /**
1322      * Returns the URL of a specific resource managed by a service, and
1323      * designated by an identifier (such as a universally unique ID, or UUID).
1324      *
1325      * @param  resourceIdentifier  An identifier (such as a UUID) for a resource.
1326      *
1327      * @return The URL of a specific resource managed by a service.
1328      */
1329     protected String getItemResourceURL(String parentResourceIdentifier, String resourceIdentifier) {
1330         return getItemServiceRootURL(parentResourceIdentifier) + "/" + resourceIdentifier;
1331     }
1332
1333     @Override
1334     protected String getServiceName() {
1335         return VocabularyClient.SERVICE_NAME;
1336     }
1337 }