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