]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
a65b361d85042ab99b95a2d3c5877eeea49853d2
[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.common.vocabulary.AuthorityItemJAXBSchema;
33 import org.collectionspace.services.client.CollectionSpaceClient;
34 import org.collectionspace.services.client.PayloadOutputPart;
35 import org.collectionspace.services.client.PoxPayloadIn;
36 import org.collectionspace.services.client.PoxPayloadOut;
37 import org.collectionspace.services.client.VocabularyClient;
38 import org.collectionspace.services.client.VocabularyClientUtils;
39 import org.collectionspace.services.jaxb.AbstractCommonList;
40 import org.collectionspace.services.vocabulary.VocabulariesCommon;
41 import org.collectionspace.services.vocabulary.VocabulariesCommonList;
42 import org.collectionspace.services.vocabulary.VocabularyitemsCommon;
43 import org.collectionspace.services.vocabulary.VocabularyitemsCommonList;
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_PATH_ITEMS_COMPONENT = VocabularyClient.SERVICE_PATH_ITEMS_COMPONENT;//"items";
66     final String SERVICE_PAYLOAD_NAME = VocabularyClient.SERVICE_PAYLOAD_NAME;
67     final String SERVICE_ITEM_PAYLOAD_NAME = VocabularyClient.SERVICE_ITEM_PAYLOAD_NAME;
68     private String knownResourceId = null;
69     private String knownResourceShortIdentifer = null;
70     private String knownResourceRefName = null;
71     private String knownResourceFullRefName = null;
72     private String knownItemResourceId = null;
73     private int nItemsToCreateInList = 5;
74     private List<String> allResourceIdsCreated = new ArrayList<String>();
75     private Map<String, String> allResourceItemIdsCreated =
76             new HashMap<String, String>();
77
78     protected void setKnownResource(String id, String shortIdentifer,
79             String refName, String fullRefName) {
80         knownResourceId = id;
81         knownResourceShortIdentifer = shortIdentifer;
82         knownResourceRefName = refName;
83         knownResourceFullRefName = fullRefName;
84     }
85
86     /* (non-Javadoc)
87      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
88      */
89     @Override
90     protected CollectionSpaceClient getClientInstance() {
91         return new VocabularyClient();
92     }
93
94     /* (non-Javadoc)
95      * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
96      */
97     @Override
98     protected AbstractCommonList getAbstractCommonList(
99             ClientResponse<AbstractCommonList> response) {
100         return response.getEntity(VocabulariesCommonList.class);
101     }
102
103     @Override
104     protected PoxPayloadOut createInstance(String identifier) {
105         VocabularyClient client = new VocabularyClient();
106         String displayName = "displayName-" + identifier;
107         PoxPayloadOut multipart = VocabularyClientUtils.createEnumerationInstance(
108                 displayName, identifier, client.getCommonPartName());
109         return multipart;
110     }
111     
112     
113     // ---------------------------------------------------------------
114     // CRUD tests : CREATE tests
115     // ---------------------------------------------------------------
116     // Success outcomes
117     @Override
118     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
119     public void create(String testName) throws Exception {
120
121         if (logger.isDebugEnabled()) {
122             logger.debug(testBanner(testName, CLASS_NAME));
123         }
124         // Perform setup, such as initializing the type of service request
125         // (e.g. CREATE, DELETE), its valid and expected status codes, and
126         // its associated HTTP method name (e.g. POST, DELETE).
127         setupCreate();
128
129         // Submit the request to the service and store the response.
130         VocabularyClient client = new VocabularyClient();
131         String identifier = createIdentifier();
132         String displayName = "displayName-" + identifier;
133         PoxPayloadOut multipart = VocabularyClientUtils.createEnumerationInstance(
134                 displayName, identifier, client.getCommonPartName());
135         ClientResponse<Response> res = client.create(multipart);
136         int statusCode = res.getStatus();
137
138         // Check the status code of the response: does it match
139         // the expected response(s)?
140         //
141         // Specifically:
142         // Does it fall within the set of valid status codes?
143         // Does it exactly match the expected status code?
144         if (logger.isDebugEnabled()) {
145             logger.debug(testName + ": status = " + statusCode);
146         }
147         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
148                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
149         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
150
151         // Store the ID returned from the first resource created
152         // for additional tests below.
153         if (knownResourceId == null) {
154             setKnownResource(extractId(res), identifier,
155                     VocabularyClientUtils.createVocabularyRefName(identifier, null),
156                     VocabularyClientUtils.createVocabularyRefName(identifier, displayName));
157             if (logger.isDebugEnabled()) {
158                 logger.debug(testName + ": knownResourceId=" + knownResourceId);
159             }
160         }
161         // Store the IDs from every resource created by tests,
162         // so they can be deleted after tests have been run.
163         allResourceIdsCreated.add(extractId(res));
164
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<VocabulariesCommonList> res = client.readList();
657         VocabulariesCommonList 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         boolean iterateThroughList = false;
671         if (iterateThroughList && logger.isDebugEnabled()) {
672             List<VocabulariesCommonList.VocabularyListItem> items =
673                     list.getVocabularyListItem();
674             int i = 0;
675             for (VocabulariesCommonList.VocabularyListItem item : items) {
676                 String csid = item.getCsid();
677                 logger.debug(testName + ": list-item[" + i + "] csid="
678                         + csid);
679                 logger.debug(testName + ": list-item[" + i + "] displayName="
680                         + item.getDisplayName());
681                 logger.debug(testName + ": list-item[" + i + "] URI="
682                         + item.getUri());
683                 readItemListInt(csid, null, "readList");
684                 i++;
685             }
686         }
687     }
688
689     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
690     dependsOnMethods = {"createList", "readItem"})
691     public void readItemList(String testName) {
692         readItemListInt(knownResourceId, null, testName);
693     }
694
695     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
696     dependsOnMethods = {"createList", "readItem"})
697     public void readItemListByName(String testName) {
698         readItemListInt(null, knownResourceShortIdentifer, testName);
699     }
700
701     private void readItemListInt(String vcsid, String shortId, String testName) {
702
703         // Perform setup.
704         setupReadList();
705
706         // Submit the request to the service and store the response.
707         VocabularyClient client = new VocabularyClient();
708         ClientResponse<VocabularyitemsCommonList> res = null;
709         if (vcsid != null) {
710             res = client.readItemList(vcsid, null, null);
711         } else if (shortId != null) {
712             res = client.readItemListForNamedAuthority(shortId, null, null);
713         } else {
714             Assert.fail("Internal Error: readItemList both vcsid and shortId are null!");
715         }
716         VocabularyitemsCommonList list = res.getEntity();
717         int statusCode = res.getStatus();
718
719         // Check the status code of the response: does it match
720         // the expected response(s)?
721         if (logger.isDebugEnabled()) {
722             logger.debug("  " + testName + ": status = " + statusCode);
723         }
724         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
725                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
726         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
727
728         List<VocabularyitemsCommonList.VocabularyitemListItem> items =
729                 list.getVocabularyitemListItem();
730         int nItemsReturned = items.size();
731         long nItemsTotal = list.getTotalItems();
732         if (logger.isDebugEnabled()) {
733             logger.debug("  " + testName + ": Expected "
734                     + nItemsToCreateInList + " items; got: " + nItemsReturned + " of: " + nItemsTotal);
735         }
736         Assert.assertEquals(nItemsTotal, nItemsToCreateInList);
737
738         // Optionally output additional data about list members for debugging.
739         boolean iterateThroughList = true;
740         if (iterateThroughList && logger.isDebugEnabled()) {
741             logger.debug("  " + testName + ": checking items");
742             int i = 0;
743             for (VocabularyitemsCommonList.VocabularyitemListItem item : items) {
744                 logger.debug("  " + testName + ": list-item[" + i + "] csid="
745                         + item.getCsid());
746                 logger.debug("  " + testName + ": list-item[" + i + "] displayName="
747                         + item.getDisplayName());
748                 logger.debug("  " + testName + ": list-item[" + i + "] URI="
749                         + item.getUri());
750                 i++;
751             }
752         }
753     }
754
755     // Failure outcomes
756     // None at present.
757     // ---------------------------------------------------------------
758     // CRUD tests : UPDATE tests
759     // ---------------------------------------------------------------
760     // Success outcomes
761     @Override
762     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
763     dependsOnMethods = {"read"})
764     public void update(String testName) throws Exception {
765
766         if (logger.isDebugEnabled()) {
767             logger.debug(testBanner(testName, CLASS_NAME));
768         }
769         // Perform setup.
770         setupUpdate();
771
772         // Retrieve the contents of a resource to update.
773         VocabularyClient client = new VocabularyClient();
774         ClientResponse<String> res =
775                 client.read(knownResourceId);
776         if (logger.isDebugEnabled()) {
777             logger.debug(testName + ": read status = " + res.getStatus());
778         }
779         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
780
781         if (logger.isDebugEnabled()) {
782             logger.debug("got Vocabulary to update with ID: " + knownResourceId);
783         }
784         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
785         VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input,
786                 client.getCommonPartName(), VocabulariesCommon.class);
787         Assert.assertNotNull(vocabulary);
788
789         // Update the contents of this resource.
790         vocabulary.setDisplayName("updated-" + vocabulary.getDisplayName());
791         vocabulary.setVocabType("updated-" + vocabulary.getVocabType());
792         if (logger.isDebugEnabled()) {
793             logger.debug("to be updated Vocabulary");
794             logger.debug(objectAsXmlString(vocabulary, VocabulariesCommon.class));
795         }
796
797         // Submit the updated resource to the service and store the response.
798         PoxPayloadOut output = new PoxPayloadOut(SERVICE_PAYLOAD_NAME);
799
800         PayloadOutputPart commonPart = output.addPart(vocabulary, MediaType.APPLICATION_XML_TYPE);
801         commonPart.setLabel(client.getCommonPartName());
802         res = client.update(knownResourceId, output);
803         int statusCode = res.getStatus();
804
805         // Check the status code of the response: does it match the expected response(s)?
806         if (logger.isDebugEnabled()) {
807             logger.debug("update: status = " + statusCode);
808         }
809         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
810                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
811         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
812
813         // Retrieve the updated resource and verify that its contents exist.
814         input = new PoxPayloadIn(res.getEntity());
815         VocabulariesCommon updatedVocabulary =
816                 (VocabulariesCommon) extractPart(input,
817                 client.getCommonPartName(), VocabulariesCommon.class);
818         Assert.assertNotNull(updatedVocabulary);
819
820         // Verify that the updated resource received the correct data.
821         Assert.assertEquals(updatedVocabulary.getDisplayName(),
822                 vocabulary.getDisplayName(),
823                 "Data in updated object did not match submitted data.");
824     }
825
826     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
827     dependsOnMethods = {"readItem", "update", "verifyIgnoredUpdateWithInAuthority"})
828     public void updateItem(String testName) throws Exception {
829
830         if (logger.isDebugEnabled()) {
831             logger.debug(testBanner(testName, CLASS_NAME));
832         }
833         // Perform setup.
834         setupUpdate();
835
836         // Retrieve the contents of a resource to update.
837         VocabularyClient client = new VocabularyClient();
838         ClientResponse<String> res =
839                 client.readItem(knownResourceId, knownItemResourceId);
840         if (logger.isDebugEnabled()) {
841             logger.debug(testName + ": read status = " + res.getStatus());
842         }
843         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
844
845         if (logger.isDebugEnabled()) {
846             logger.debug("got VocabularyItem to update with ID: "
847                     + knownItemResourceId
848                     + " in Vocab: " + knownResourceId);
849         }
850         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
851         VocabularyitemsCommon vocabularyItem = (VocabularyitemsCommon) extractPart(input,
852                 client.getCommonPartItemName(), VocabularyitemsCommon.class);
853         Assert.assertNotNull(vocabularyItem);
854
855         // Update the contents of this resource.
856         vocabularyItem.setDisplayName("updated-" + vocabularyItem.getDisplayName());
857         if (logger.isDebugEnabled()) {
858             logger.debug("to be updated VocabularyItem");
859             logger.debug(objectAsXmlString(vocabularyItem,
860                     VocabularyitemsCommon.class));
861         }
862
863         // Submit the updated resource to the service and store the response.
864         PoxPayloadOut output = new PoxPayloadOut(SERVICE_ITEM_PAYLOAD_NAME);
865         PayloadOutputPart commonPart = output.addPart(vocabularyItem, MediaType.APPLICATION_XML_TYPE);
866         commonPart.setLabel(client.getCommonPartItemName());
867         res = client.updateItem(knownResourceId, knownItemResourceId, output);
868         int statusCode = res.getStatus();
869
870         // Check the status code of the response: does it match the expected response(s)?
871         if (logger.isDebugEnabled()) {
872             logger.debug("updateItem: status = " + statusCode);
873         }
874         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
875                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
876         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
877
878         // Retrieve the updated resource and verify that its contents exist.
879         input = new PoxPayloadIn(res.getEntity());
880         VocabularyitemsCommon updatedVocabularyItem =
881                 (VocabularyitemsCommon) extractPart(input,
882                 client.getCommonPartItemName(), VocabularyitemsCommon.class);
883         Assert.assertNotNull(updatedVocabularyItem);
884
885         // Verify that the updated resource received the correct data.
886         Assert.assertEquals(updatedVocabularyItem.getDisplayName(),
887                 vocabularyItem.getDisplayName(),
888                 "Data in updated VocabularyItem did not match submitted data.");
889     }
890
891     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
892     dependsOnMethods = {"readItem"})
893     public void verifyIgnoredUpdateWithInAuthority(String testName) throws Exception {
894
895         if (logger.isDebugEnabled()) {
896             logger.debug(testBanner(testName, CLASS_NAME));
897         }
898         // Perform setup.
899         setupUpdate();
900
901         // Submit the request to the service and store the response.
902         VocabularyClient client = new VocabularyClient();
903         ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
904         int statusCode = res.getStatus();
905
906         // Check the status code of the response: does it match
907         // the expected response(s)?
908         if (logger.isDebugEnabled()) {
909             logger.debug(testName + " read Vocab:" + knownResourceId + "/Item:"
910                     + knownItemResourceId + " status = " + statusCode);
911         }
912         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
913                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
914         Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
915
916         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
917         VocabularyitemsCommon vitem = (VocabularyitemsCommon) extractPart(input,
918                 client.getCommonPartItemName(), VocabularyitemsCommon.class);
919         Assert.assertNotNull(vitem);
920         // Try to Update with new parent vocab (use self, for test).
921         Assert.assertEquals(vitem.getInAuthority(),
922                 knownResourceId,
923                 "VocabularyItem inAuthority does not match knownResourceId.");
924         vitem.setInAuthority(knownItemResourceId);
925
926         // Submit the updated resource to the service and store the response.
927         PoxPayloadOut output = new PoxPayloadOut(SERVICE_ITEM_PAYLOAD_NAME);
928         PayloadOutputPart commonPart = output.addPart(vitem, MediaType.APPLICATION_XML_TYPE);
929         commonPart.setLabel(client.getCommonPartItemName());
930         res = client.updateItem(knownResourceId, knownItemResourceId, output);
931         statusCode = res.getStatus();
932
933         // Check the status code of the response: does it match the expected response(s)?
934         if (logger.isDebugEnabled()) {
935             logger.debug(testName + ": status = " + statusCode);
936         }
937         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
938                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
939         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
940
941         // Retrieve the updated resource and verify that the parent did not change
942         res = client.readItem(knownResourceId, knownItemResourceId);
943         input = new PoxPayloadIn(res.getEntity());
944         VocabularyitemsCommon updatedVocabularyItem =
945                 (VocabularyitemsCommon) extractPart(input,
946                 client.getCommonPartItemName(), VocabularyitemsCommon.class);
947         Assert.assertNotNull(updatedVocabularyItem);
948
949         // Verify that the updated resource received the correct data.
950         Assert.assertEquals(updatedVocabularyItem.getInAuthority(),
951                 knownResourceId,
952                 "VocabularyItem allowed update to the parent (inAuthority).");
953     }
954
955     // Failure outcomes
956     // Placeholders until the three tests below can be uncommented.
957     // See Issue CSPACE-401.
958     @Override
959     public void updateWithEmptyEntityBody(String testName) throws Exception {
960     }
961
962     @Override
963     public void updateWithMalformedXml(String testName) throws Exception {
964     }
965
966     @Override
967     public void updateWithWrongXmlSchema(String testName) throws Exception {
968     }
969
970     /*
971     @Override
972     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
973     dependsOnMethods = {"create", "update", "testSubmitRequest"})
974     public void updateWithEmptyEntityBody(String testName) throws Exception {
975
976     if (logger.isDebugEnabled()) {
977     logger.debug(testBanner(testName, CLASS_NAME));
978     }
979     // Perform setup.
980     setupUpdateWithEmptyEntityBody();
981
982     // Submit the request to the service and store the response.
983     String method = REQUEST_TYPE.httpMethodName();
984     String url = getResourceURL(knownResourceId);
985     String mediaType = MediaType.APPLICATION_XML;
986     final String entity = "";
987     int statusCode = submitRequest(method, url, mediaType, entity);
988
989     // Check the status code of the response: does it match
990     // the expected response(s)?
991     if(logger.isDebugEnabled()){
992     logger.debug(testName + ": url=" + url +
993     " status=" + statusCode);
994     }
995     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
996     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
997     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
998     }
999
1000     @Override
1001     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1002     dependsOnMethods = {"create", "update", "testSubmitRequest"})
1003     public void updateWithMalformedXml(String testName) throws Exception {
1004
1005     if (logger.isDebugEnabled()) {
1006     logger.debug(testBanner(testName, CLASS_NAME));
1007     }
1008     // Perform setup.
1009     setupUpdateWithMalformedXml();
1010
1011     // Submit the request to the service and store the response.
1012     String method = REQUEST_TYPE.httpMethodName();
1013     String url = getResourceURL(knownResourceId);
1014     String mediaType = MediaType.APPLICATION_XML;
1015     final String entity = MALFORMED_XML_DATA;
1016     int statusCode = submitRequest(method, url, mediaType, entity);
1017
1018     // Check the status code of the response: does it match
1019     // the expected response(s)?
1020     if(logger.isDebugEnabled()){
1021     logger.debug(testName + ": url=" + url +
1022     " status=" + statusCode);
1023     }
1024     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1025     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1026     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1027     }
1028
1029     @Override
1030     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1031     dependsOnMethods = {"create", "update", "testSubmitRequest"})
1032     public void updateWithWrongXmlSchema(String testName) throws Exception {
1033
1034     if (logger.isDebugEnabled()) {
1035     logger.debug(testBanner(testName, CLASS_NAME));
1036     }
1037     // Perform setup.
1038     setupUpdateWithWrongXmlSchema();
1039
1040     // Submit the request to the service and store the response.
1041     String method = REQUEST_TYPE.httpMethodName();
1042     String url = getResourceURL(knownResourceId);
1043     String mediaType = MediaType.APPLICATION_XML;
1044     final String entity = WRONG_XML_SCHEMA_DATA;
1045     int statusCode = submitRequest(method, url, mediaType, entity);
1046
1047     // Check the status code of the response: does it match
1048     // the expected response(s)?
1049     if(logger.isDebugEnabled()){
1050     logger.debug("updateWithWrongXmlSchema: url=" + url +
1051     " status=" + statusCode);
1052     }
1053     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1054     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1055     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1056     }
1057      */
1058     @Override
1059     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1060     dependsOnMethods = {"update", "testSubmitRequest"})
1061     public void updateNonExistent(String testName) throws Exception {
1062
1063         if (logger.isDebugEnabled()) {
1064             logger.debug(testBanner(testName, CLASS_NAME));
1065         }
1066         // Perform setup.
1067         setupUpdateNonExistent();
1068
1069         // Submit the request to the service and store the response.
1070         // Note: The ID used in this 'create' call may be arbitrary.
1071         // The only relevant ID may be the one used in update(), below.
1072         VocabularyClient client = new VocabularyClient();
1073         String displayName = "displayName-" + NON_EXISTENT_ID;
1074         PoxPayloadOut multipart = VocabularyClientUtils.createEnumerationInstance(
1075                 displayName, NON_EXISTENT_ID, client.getCommonPartName());
1076         ClientResponse<String> res =
1077                 client.update(NON_EXISTENT_ID, multipart);
1078         int statusCode = res.getStatus();
1079
1080         // Check the status code of the response: does it match
1081         // the expected response(s)?
1082         if (logger.isDebugEnabled()) {
1083             logger.debug(testName + ": status = " + statusCode);
1084         }
1085         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1086                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1087         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1088     }
1089
1090     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1091     dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1092     public void updateNonExistentItem(String testName) throws Exception {
1093
1094         if (logger.isDebugEnabled()) {
1095             logger.debug(testBanner(testName, CLASS_NAME));
1096         }
1097         // Perform setup.
1098         setupUpdateNonExistent();
1099
1100         // Submit the request to the service and store the response.
1101         // Note: The ID used in this 'create' call may be arbitrary.
1102         // The only relevant ID may be the one used in update(), below.
1103         VocabularyClient client = new VocabularyClient();
1104         HashMap<String, String> itemInfo = new HashMap<String, String>();
1105         itemInfo.put(AuthorityItemJAXBSchema.SHORT_IDENTIFIER, "nonex");
1106         itemInfo.put(AuthorityItemJAXBSchema.DISPLAY_NAME, "display-nonex");
1107         PoxPayloadOut multipart =
1108                 VocabularyClientUtils.createVocabularyItemInstance(
1109                 VocabularyClientUtils.createVocabularyRefName(NON_EXISTENT_ID, null),
1110                 itemInfo, client.getCommonPartItemName());
1111         ClientResponse<String> res =
1112                 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1113         int statusCode = res.getStatus();
1114
1115         // Check the status code of the response: does it match
1116         // the expected response(s)?
1117         if (logger.isDebugEnabled()) {
1118             logger.debug(testName + ": status = " + statusCode);
1119         }
1120         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1121                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1122         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1123     }
1124
1125     // ---------------------------------------------------------------
1126     // CRUD tests : DELETE tests
1127     // ---------------------------------------------------------------
1128     // Success outcomes
1129     @Override
1130     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1131     dependsOnMethods = {"create", "readList", "testSubmitRequest", "update", "deleteItem"})
1132     public void delete(String testName) throws Exception {
1133
1134         if (logger.isDebugEnabled()) {
1135             logger.debug(testBanner(testName, CLASS_NAME));
1136         }
1137         // Perform setup.
1138         setupDelete();
1139
1140         // Submit the request to the service and store the response.
1141         VocabularyClient client = new VocabularyClient();
1142         ClientResponse<Response> res = client.delete(knownResourceId);
1143         int statusCode = res.getStatus();
1144
1145         // Check the status code of the response: does it match
1146         // the expected response(s)?
1147         if (logger.isDebugEnabled()) {
1148             logger.debug(testName + ": status = " + statusCode);
1149         }
1150         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1151                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1152         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1153     }
1154
1155     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1156     dependsOnMethods = {"createItem", "readItemList", "testItemSubmitRequest",
1157         "updateItem", "verifyIllegalItemDisplayName", "verifyIgnoredUpdateWithInAuthority"})
1158     public void deleteItem(String testName) throws Exception {
1159
1160         if (logger.isDebugEnabled()) {
1161             logger.debug(testBanner(testName, CLASS_NAME));
1162         }
1163         // Perform setup.
1164         setupDelete();
1165
1166         // Submit the request to the service and store the response.
1167         VocabularyClient client = new VocabularyClient();
1168         ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
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("delete: 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     // Failure outcomes
1182     @Override
1183     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1184     dependsOnMethods = {"delete"})
1185     public void deleteNonExistent(String testName) throws Exception {
1186
1187         if (logger.isDebugEnabled()) {
1188             logger.debug(testBanner(testName, CLASS_NAME));
1189         }
1190         // Perform setup.
1191         setupDeleteNonExistent();
1192
1193         // Submit the request to the service and store the response.
1194         VocabularyClient client = new VocabularyClient();
1195         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1196         int statusCode = res.getStatus();
1197
1198         // Check the status code of the response: does it match
1199         // the expected response(s)?
1200         if (logger.isDebugEnabled()) {
1201             logger.debug(testName + ": status = " + statusCode);
1202         }
1203         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1204                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1205         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1206     }
1207
1208     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1209     dependsOnMethods = {"deleteItem"})
1210     public void deleteNonExistentItem(String testName) {
1211
1212         if (logger.isDebugEnabled()) {
1213             logger.debug(testBanner(testName, CLASS_NAME));
1214         }
1215         // Perform setup.
1216         setupDeleteNonExistent();
1217
1218         // Submit the request to the service and store the response.
1219         VocabularyClient client = new VocabularyClient();
1220         ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1221         int statusCode = res.getStatus();
1222
1223         // Check the status code of the response: does it match
1224         // the expected response(s)?
1225         if (logger.isDebugEnabled()) {
1226             logger.debug(testName + ": status = " + statusCode);
1227         }
1228         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1229                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1230         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1231     }
1232
1233     // ---------------------------------------------------------------
1234     // Utility tests : tests of code used in tests above
1235     // ---------------------------------------------------------------
1236     /**
1237      * Tests the code for manually submitting data that is used by several
1238      * of the methods above.
1239      */
1240     @Test(dependsOnMethods = {"create", "read"})
1241     public void testSubmitRequest() {
1242
1243         // Expected status code: 200 OK
1244         setupRead();
1245
1246         // Submit the request to the service and store the response.
1247         String method = ServiceRequestType.READ.httpMethodName();
1248         String url = getResourceURL(knownResourceId);
1249         int statusCode = submitRequest(method, url);
1250
1251         // Check the status code of the response: does it match
1252         // the expected response(s)?
1253         if (logger.isDebugEnabled()) {
1254             logger.debug("testSubmitRequest: url=" + url
1255                     + " status=" + statusCode);
1256         }
1257         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1258
1259     }
1260
1261     @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1262     public void testItemSubmitRequest() {
1263
1264         // Expected status code: 200 OK
1265         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1266
1267         // Submit the request to the service and store the response.
1268         String method = ServiceRequestType.READ.httpMethodName();
1269         String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1270         int statusCode = submitRequest(method, url);
1271
1272         // Check the status code of the response: does it match
1273         // the expected response(s)?
1274         if (logger.isDebugEnabled()) {
1275             logger.debug("testItemSubmitRequest: url=" + url
1276                     + " status=" + statusCode);
1277         }
1278         Assert.assertEquals(statusCode, EXPECTED_STATUS);
1279
1280     }
1281
1282     // ---------------------------------------------------------------
1283     // Cleanup of resources created during testing
1284     // ---------------------------------------------------------------
1285     /**
1286      * Deletes all resources created by tests, after all tests have been run.
1287      *
1288      * This cleanup method will always be run, even if one or more tests fail.
1289      * For this reason, it attempts to remove all resources created
1290      * at any point during testing, even if some of those resources
1291      * may be expected to be deleted by certain tests.
1292      */
1293     @AfterClass(alwaysRun = true)
1294     public void cleanUp() {
1295         String noTest = System.getProperty("noTestCleanup");
1296         if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1297             if (logger.isDebugEnabled()) {
1298                 logger.debug("Skipping Cleanup phase ...");
1299             }
1300             return;
1301         }
1302         if (logger.isDebugEnabled()) {
1303             logger.debug("Cleaning up temporary resources created for testing ...");
1304         }
1305         VocabularyClient client = new VocabularyClient();
1306         String vocabularyResourceId;
1307         String vocabularyItemResourceId;
1308         // Clean up vocabulary item resources.
1309         for (Map.Entry<String, String> entry : allResourceItemIdsCreated.entrySet()) {
1310             vocabularyItemResourceId = entry.getKey();
1311             vocabularyResourceId = entry.getValue();
1312             // Note: Any non-success responses are ignored and not reported.
1313             client.deleteItem(vocabularyResourceId, vocabularyItemResourceId).releaseConnection();
1314         }
1315         // Clean up vocabulary resources.
1316         for (String resourceId : allResourceIdsCreated) {
1317             // Note: Any non-success responses are ignored and not reported.
1318             client.delete(resourceId).releaseConnection();
1319         }
1320
1321     }
1322
1323     // ---------------------------------------------------------------
1324     // Utility methods used by tests above
1325     // ---------------------------------------------------------------
1326     @Override
1327     public String getServicePathComponent() {
1328         return SERVICE_PATH_COMPONENT;
1329     }
1330
1331     public String getServicePathItemsComponent() {
1332         return this.SERVICE_PATH_ITEMS_COMPONENT;
1333     }
1334
1335     /**
1336      * Returns the root URL for a service.
1337      *
1338      * This URL consists of a base URL for all services, followed by
1339      * a path component for the owning vocabulary, followed by the 
1340      * path component for the items.
1341      *
1342      * @return The root URL for a service.
1343      */
1344     protected String getItemServiceRootURL(String parentResourceIdentifier) {
1345         return getResourceURL(parentResourceIdentifier) + "/" + getServicePathItemsComponent();
1346     }
1347
1348     /**
1349      * Returns the URL of a specific resource managed by a service, and
1350      * designated by an identifier (such as a universally unique ID, or UUID).
1351      *
1352      * @param  resourceIdentifier  An identifier (such as a UUID) for a resource.
1353      *
1354      * @return The URL of a specific resource managed by a service.
1355      */
1356     protected String getItemResourceURL(String parentResourceIdentifier, String resourceIdentifier) {
1357         return getItemServiceRootURL(parentResourceIdentifier) + "/" + resourceIdentifier;
1358     }
1359
1360     @Override
1361     protected String getServiceName() {
1362         return VocabularyClient.SERVICE_NAME;
1363     }
1364 }