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