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