]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
e390e05e2a1be5b0ce9ee88102b88393f0c8e87e
[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.VocabularyClient;
34 import org.collectionspace.services.client.VocabularyClientUtils;
35 import org.collectionspace.services.vocabulary.VocabulariesCommon;
36 import org.collectionspace.services.vocabulary.VocabulariesCommonList;
37 import org.collectionspace.services.vocabulary.VocabularyitemsCommon;
38 import org.collectionspace.services.vocabulary.VocabularyitemsCommonList;
39
40 import org.jboss.resteasy.client.ClientResponse;
41 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
42 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
43 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
46 import org.testng.Assert;
47 import org.testng.annotations.AfterClass;
48 import org.testng.annotations.Test;
49
50 /**
51  * VocabularyServiceTest, carries out tests against a
52  * deployed and running Vocabulary Service.
53  *
54  * $LastChangedRevision: 753 $
55  * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
56  */
57 public class VocabularyServiceTest extends AbstractServiceTestImpl {
58
59     private final Logger logger =
60         LoggerFactory.getLogger(VocabularyServiceTest.class);
61
62     // Instance variables specific to this test.
63     private VocabularyClient client = new VocabularyClient();
64     final String SERVICE_PATH_COMPONENT = "vocabularies";
65     final String ITEM_SERVICE_PATH_COMPONENT = "items";
66     private String knownResourceId = null;
67     private String knownResourceRefName = null;
68     private String knownItemResourceId = null;
69     private int nItemsToCreateInList = 3;
70     private List<String> allResourceIdsCreated = new ArrayList<String>();
71     private Map<String, String> allResourceItemIdsCreated =
72         new HashMap<String, String>();
73     
74     protected void setKnownResource( String id, String refName ) {
75         knownResourceId = id;
76         knownResourceRefName = refName;
77     }
78
79     // ---------------------------------------------------------------
80     // CRUD tests : CREATE tests
81     // ---------------------------------------------------------------
82     // Success outcomes
83     @Override
84     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
85     public void create(String testName) throws Exception {
86
87         // Perform setup, such as initializing the type of service request
88         // (e.g. CREATE, DELETE), its valid and expected status codes, and
89         // its associated HTTP method name (e.g. POST, DELETE).
90         setupCreate(testName);
91
92         // Submit the request to the service and store the response.
93         String identifier = createIdentifier();
94         String displayName = "displayName-" + identifier;
95         String refName = VocabularyClientUtils.createVocabularyRefName(displayName, false);
96         MultipartOutput multipart = VocabularyClientUtils.createEnumerationInstance(
97                                         displayName, refName, client.getCommonPartName());
98         ClientResponse<Response> res = client.create(multipart);
99         int statusCode = res.getStatus();
100
101         // Check the status code of the response: does it match
102         // the expected response(s)?
103         //
104         // Specifically:
105         // Does it fall within the set of valid status codes?
106         // Does it exactly match the expected status code?
107         if(logger.isDebugEnabled()){
108             logger.debug(testName + ": status = " + statusCode);
109         }
110         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
111                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
112         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
113
114         // Store the ID returned from the first resource created
115         // for additional tests below.
116         if (knownResourceId == null){
117                 setKnownResource(extractId(res), refName);
118             if (logger.isDebugEnabled()) {
119                 logger.debug(testName + ": knownResourceId=" + knownResourceId);
120             }
121         }
122         // Store the IDs from every resource created by tests,
123         // so they can be deleted after tests have been run.
124         allResourceIdsCreated.add(extractId(res));
125
126     }
127
128     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
129         dependsOnMethods = {"create"})
130     public void createItem(String testName) {
131         setupCreate(testName);
132
133         HashMap<String, String> itemInfo = new HashMap<String, String>();
134         itemInfo.put(VocabularyItemJAXBSchema.DISPLAY_NAME, createIdentifier());
135         knownItemResourceId = VocabularyClientUtils.createItemInVocabulary(knownResourceId, 
136                                 knownResourceRefName, itemInfo, client);
137         if(logger.isDebugEnabled()){
138             logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
139         }
140     }
141
142     @Override
143     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
144             dependsOnMethods = {"create", "createItem"})
145     public void createList(String testName) throws Exception {
146         for (int i = 0; i < 3; i++) {
147                 // Force create to reset the known resource info
148                 setKnownResource(null, null);
149             create(testName);
150             // Add nItemsToCreateInList items to each vocab
151             for (int j = 0; j < nItemsToCreateInList; j++) {
152                 createItem(testName);
153             }
154         }
155     }
156
157     // Failure outcomes
158     // Placeholders until the three tests below can be uncommented.
159     // See Issue CSPACE-401.
160     @Override
161     public void createWithEmptyEntityBody(String testName) throws Exception {
162     }
163
164     @Override
165     public void createWithMalformedXml(String testName) throws Exception {
166     }
167
168     @Override
169     public void createWithWrongXmlSchema(String testName) throws Exception {
170     }
171
172     /*
173     @Override
174     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
175         dependsOnMethods = {"create", "testSubmitRequest"})
176     public void createWithEmptyEntityBody(String testName) throws Exception {
177
178     // Perform setup.
179     setupCreateWithEmptyEntityBody(testName);
180
181     // Submit the request to the service and store the response.
182     String method = REQUEST_TYPE.httpMethodName();
183     String url = getServiceRootURL();
184     String mediaType = MediaType.APPLICATION_XML;
185     final String entity = "";
186     int statusCode = submitRequest(method, url, mediaType, entity);
187
188     // Check the status code of the response: does it match
189     // the expected response(s)?
190     if(logger.isDebugEnabled()) {
191         logger.debug(testName + ": url=" + url +
192             " status=" + statusCode);
193      }
194     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
195     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
196     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
197     }
198
199     @Override
200     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
201         dependsOnMethods = {"create", "testSubmitRequest"})
202     public void createWithMalformedXml(String testName) throws Exception {
203
204     // Perform setup.
205     setupCreateWithMalformedXml(testName);
206
207     // Submit the request to the service and store the response.
208     String method = REQUEST_TYPE.httpMethodName();
209     String url = getServiceRootURL();
210     String mediaType = MediaType.APPLICATION_XML;
211     final String entity = MALFORMED_XML_DATA; // Constant from base class.
212     int statusCode = submitRequest(method, url, mediaType, entity);
213
214     // Check the status code of the response: does it match
215     // the expected response(s)?
216     if(logger.isDebugEnabled()){
217         logger.debug(testName + ": url=" + url +
218             " status=" + statusCode);
219      }
220     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
221     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
222     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
223     }
224
225     @Override
226     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
227         dependsOnMethods = {"create", "testSubmitRequest"})
228     public void createWithWrongXmlSchema(String testName) throws Exception {
229
230     // Perform setup.
231     setupCreateWithWrongXmlSchema(testName);
232
233     // Submit the request to the service and store the response.
234     String method = REQUEST_TYPE.httpMethodName();
235     String url = getServiceRootURL();
236     String mediaType = MediaType.APPLICATION_XML;
237     final String entity = WRONG_XML_SCHEMA_DATA;
238     int statusCode = submitRequest(method, url, mediaType, entity);
239
240     // Check the status code of the response: does it match
241     // the expected response(s)?
242     if(logger.isDebugEnabled()){
243         logger.debug(testName + ": url=" + url +
244             " status=" + statusCode);
245      }
246     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
247     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
248     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
249     }
250      */
251
252     // ---------------------------------------------------------------
253     // CRUD tests : READ tests
254     // ---------------------------------------------------------------
255     // Success outcomes
256     @Override
257     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
258         dependsOnMethods = {"create"})
259     public void read(String testName) throws Exception {
260
261         // Perform setup.
262         setupRead();
263
264         // Submit the request to the service and store the response.
265         ClientResponse<MultipartInput> res = client.read(knownResourceId);
266         int statusCode = res.getStatus();
267
268         // Check the status code of the response: does it match
269         // the expected response(s)?
270         if(logger.isDebugEnabled()){
271             logger.debug(testName + ": status = " + statusCode);
272         }
273         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
274                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
275         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
276         //FIXME: remove the following try catch once Aron fixes signatures
277         try {
278             MultipartInput input = (MultipartInput) res.getEntity();
279             VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input,
280                     client.getCommonPartName(), VocabulariesCommon.class);
281             Assert.assertNotNull(vocabulary);
282         } catch (Exception e) {
283             throw new RuntimeException(e);
284         }
285     }
286
287     /*
288     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
289             dependsOnMethods = {"read"})
290         public void readByName(String testName) throws Exception {
291
292             // Perform setup.
293             setupRead();
294
295             // Submit the request to the service and store the response.
296             ClientResponse<MultipartInput> res = client.read(knownResourceId);
297             int statusCode = res.getStatus();
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 + ": status = " + statusCode);
303             }
304             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
305                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
306             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
307             //FIXME: remove the following try catch once Aron fixes signatures
308             try {
309                 MultipartInput input = (MultipartInput) res.getEntity();
310                 VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input,
311                         client.getCommonPartName(), VocabulariesCommon.class);
312                 Assert.assertNotNull(vocabulary);
313             } catch (Exception e) {
314                 throw new RuntimeException(e);
315             }
316         }
317     */
318
319     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
320         dependsOnMethods = {"createItem", "read"})
321     public void readItem(String testName) throws Exception {
322
323         // Perform setup.
324         setupRead(testName);
325
326         // Submit the request to the service and store the response.
327         ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
328         int statusCode = res.getStatus();
329
330         // Check the status code of the response: does it match
331         // the expected response(s)?
332         if(logger.isDebugEnabled()){
333             logger.debug(testName + ": status = " + statusCode);
334         }
335         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
336                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
337         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
338
339         // Check whether we've received a vocabulary item.
340         MultipartInput input = (MultipartInput) res.getEntity();
341         VocabularyitemsCommon vocabularyItem = (VocabularyitemsCommon) extractPart(input,
342                 client.getItemCommonPartName(), VocabularyitemsCommon.class);
343         Assert.assertNotNull(vocabularyItem);
344
345     }
346
347     // Failure outcomes
348     @Override
349     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
350         dependsOnMethods = {"read"})
351     public void readNonExistent(String testName) {
352
353         // Perform setup.
354         setupReadNonExistent(testName);
355
356         // Submit the request to the service and store the response.
357         ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
358         int statusCode = res.getStatus();
359
360         // Check the status code of the response: does it match
361         // the expected response(s)?
362         if(logger.isDebugEnabled()){
363             logger.debug(testName + ": status = " + statusCode);
364         }
365         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
366                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
367         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
368     }
369
370     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
371         dependsOnMethods = {"readItem", "readNonExistent"})
372     public void readItemNonExistent(String testName) {
373
374         // Perform setup.
375         setupReadNonExistent(testName);
376
377         // Submit the request to the service and store the response.
378         ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
379         int statusCode = res.getStatus();
380
381         // Check the status code of the response: does it match
382         // the expected response(s)?
383         if(logger.isDebugEnabled()){
384             logger.debug(testName + ": status = " + statusCode);
385         }
386         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
387                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
388         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
389     }
390     // ---------------------------------------------------------------
391     // CRUD tests : READ_LIST tests
392     // ---------------------------------------------------------------
393     // Success outcomes
394
395     @Override
396     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
397         dependsOnMethods = {"createList", "read"})
398     public void readList(String testName) throws Exception {
399
400         // Perform setup.
401         setupReadList(testName);
402
403         // Submit the request to the service and store the response.
404         ClientResponse<VocabulariesCommonList> res = client.readList();
405         VocabulariesCommonList list = res.getEntity();
406         int statusCode = res.getStatus();
407
408         // Check the status code of the response: does it match
409         // the expected response(s)?
410         if(logger.isDebugEnabled()){
411             logger.debug(testName + ": status = " + statusCode);
412         }
413         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
414                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
415         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
416
417         // Optionally output additional data about list members for debugging.
418         boolean iterateThroughList = false;
419         if (iterateThroughList && logger.isDebugEnabled()) {
420             List<VocabulariesCommonList.VocabularyListItem> items =
421                     list.getVocabularyListItem();
422             int i = 0;
423             for (VocabulariesCommonList.VocabularyListItem item : items) {
424                 String csid = item.getCsid();
425                 logger.debug(testName + ": list-item[" + i + "] csid=" +
426                         csid);
427                 logger.debug(testName + ": list-item[" + i + "] displayName=" +
428                         item.getDisplayName());
429                 logger.debug(testName + ": list-item[" + i + "] URI=" +
430                         item.getUri());
431                 readItemList(csid);
432                 i++;
433             }
434         }
435     }
436
437     @Test(dependsOnMethods = {"createList", "readItem"})
438     public void readItemList() {
439         readItemList(knownResourceId);
440     }
441
442     private void readItemList(String vcsid) {
443
444         final String testName = "readItemList";
445
446         // Perform setup.
447         setupReadList(testName);
448
449         // Submit the request to the service and store the response.
450         ClientResponse<VocabularyitemsCommonList> res =
451                 client.readItemList(vcsid);
452         VocabularyitemsCommonList list = res.getEntity();
453         int statusCode = res.getStatus();
454
455         // Check the status code of the response: does it match
456         // the expected response(s)?
457         if(logger.isDebugEnabled()){
458             logger.debug("  " + testName + ": status = " + statusCode);
459         }
460         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
461                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
462         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
463
464         List<VocabularyitemsCommonList.VocabularyitemListItem> items =
465             list.getVocabularyitemListItem();
466         int nItemsReturned = items.size();
467         if(logger.isDebugEnabled()){
468             logger.debug("  " + testName + ": Expected "
469                         + nItemsToCreateInList+" items; got: "+nItemsReturned);
470         }
471         Assert.assertEquals( nItemsReturned, nItemsToCreateInList);
472
473         // Optionally output additional data about list members for debugging.
474         boolean iterateThroughList = true;
475         if (iterateThroughList && logger.isDebugEnabled()) {
476             logger.debug("  " + testName + ": checking items");
477             int i = 0;
478             for (VocabularyitemsCommonList.VocabularyitemListItem item : items) {
479                 logger.debug("  " + testName + ": list-item[" + i + "] csid=" +
480                         item.getCsid());
481                 logger.debug("  " + testName + ": list-item[" + i + "] displayName=" +
482                         item.getDisplayName());
483                 logger.debug("  " + testName + ": list-item[" + i + "] URI=" +
484                         item.getUri());
485                 i++;
486             }
487         }
488     }
489
490     // Failure outcomes
491     // None at present.
492     // ---------------------------------------------------------------
493     // CRUD tests : UPDATE tests
494     // ---------------------------------------------------------------
495     // Success outcomes
496     @Override
497     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
498         dependsOnMethods = {"read"})
499     public void update(String testName) throws Exception {
500
501         // Perform setup.
502         setupUpdate(testName);
503
504         // Retrieve the contents of a resource to update.
505         ClientResponse<MultipartInput> res =
506                 client.read(knownResourceId);
507         if(logger.isDebugEnabled()){
508             logger.debug(testName + ": read status = " + res.getStatus());
509         }
510         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
511
512         if(logger.isDebugEnabled()){
513             logger.debug("got Vocabulary to update with ID: " + knownResourceId);
514         }
515         MultipartInput input = (MultipartInput) res.getEntity();
516         VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input,
517                 client.getCommonPartName(), VocabulariesCommon.class);
518         Assert.assertNotNull(vocabulary);
519
520         // Update the contents of this resource.
521         vocabulary.setDisplayName("updated-" + vocabulary.getDisplayName());
522         vocabulary.setVocabType("updated-" + vocabulary.getVocabType());
523         if(logger.isDebugEnabled()){
524             logger.debug("to be updated Vocabulary");
525             logger.debug(objectAsXmlString(vocabulary, VocabulariesCommon.class));
526         }
527
528         // Submit the updated resource to the service and store the response.
529         MultipartOutput output = new MultipartOutput();
530         OutputPart commonPart = output.addPart(vocabulary, MediaType.APPLICATION_XML_TYPE);
531         commonPart.getHeaders().add("label", client.getCommonPartName());
532         res = client.update(knownResourceId, output);
533         int statusCode = res.getStatus();
534
535         // Check the status code of the response: does it match the expected response(s)?
536         if(logger.isDebugEnabled()){
537             logger.debug("update: status = " + statusCode);
538         }
539         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
540                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
541         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
542
543         // Retrieve the updated resource and verify that its contents exist.
544         input = (MultipartInput) res.getEntity();
545         VocabulariesCommon updatedVocabulary =
546                 (VocabulariesCommon) extractPart(input,
547                         client.getCommonPartName(), VocabulariesCommon.class);
548         Assert.assertNotNull(updatedVocabulary);
549
550         // Verify that the updated resource received the correct data.
551         Assert.assertEquals(updatedVocabulary.getDisplayName(),
552                 vocabulary.getDisplayName(),
553                 "Data in updated object did not match submitted data.");
554     }
555
556     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
557         dependsOnMethods = {"readItem", "update"})
558     public void updateItem(String testName) throws Exception {
559
560         // Perform setup.
561         setupUpdate(testName);
562
563         ClientResponse<MultipartInput> res =
564                 client.readItem(knownResourceId, knownItemResourceId);
565         if(logger.isDebugEnabled()){
566             logger.debug(testName + ": read status = " + res.getStatus());
567         }
568         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
569
570         if(logger.isDebugEnabled()){
571             logger.debug("got VocabularyItem to update with ID: " +
572                 knownItemResourceId +
573                 " in Vocab: " + knownResourceId );
574         }
575         MultipartInput input = (MultipartInput) res.getEntity();
576         VocabularyitemsCommon vocabularyItem = (VocabularyitemsCommon) extractPart(input,
577                 client.getItemCommonPartName(), VocabularyitemsCommon.class);
578         Assert.assertNotNull(vocabularyItem);
579
580         // Update the contents of this resource.
581         vocabularyItem.setDisplayName("updated-" + vocabularyItem.getDisplayName());
582         if(logger.isDebugEnabled()){
583             logger.debug("to be updated VocabularyItem");
584             logger.debug(objectAsXmlString(vocabularyItem,
585                 VocabularyitemsCommon.class));
586         }
587
588         // Submit the updated resource to the service and store the response.
589         MultipartOutput output = new MultipartOutput();
590         OutputPart commonPart = output.addPart(vocabularyItem, MediaType.APPLICATION_XML_TYPE);
591         commonPart.getHeaders().add("label", client.getItemCommonPartName());
592         res = client.updateItem(knownResourceId, knownItemResourceId, output);
593         int statusCode = res.getStatus();
594
595         // Check the status code of the response: does it match the expected response(s)?
596         if(logger.isDebugEnabled()){
597             logger.debug("updateItem: status = " + statusCode);
598         }
599         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
600                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
601         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
602
603         // Retrieve the updated resource and verify that its contents exist.
604         input = (MultipartInput) res.getEntity();
605         VocabularyitemsCommon updatedVocabularyItem =
606                 (VocabularyitemsCommon) extractPart(input,
607                         client.getItemCommonPartName(), VocabularyitemsCommon.class);
608         Assert.assertNotNull(updatedVocabularyItem);
609
610         // Verify that the updated resource received the correct data.
611         Assert.assertEquals(updatedVocabularyItem.getDisplayName(),
612                 vocabularyItem.getDisplayName(),
613                 "Data in updated VocabularyItem did not match submitted data.");
614     }
615
616     // Failure outcomes
617     // Placeholders until the three tests below can be uncommented.
618     // See Issue CSPACE-401.
619     @Override
620     public void updateWithEmptyEntityBody(String testName) throws Exception {
621     }
622
623     @Override
624     public void updateWithMalformedXml(String testName) throws Exception {
625     }
626
627     @Override
628     public void updateWithWrongXmlSchema(String testName) throws Exception {
629     }
630
631     /*
632     @Override
633     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
634         dependsOnMethods = {"create", "update", "testSubmitRequest"})
635     public void updateWithEmptyEntityBody(String testName) throws Exception {
636
637     // Perform setup.
638     setupUpdateWithEmptyEntityBody(testName);
639
640     // Submit the request to the service and store the response.
641     String method = REQUEST_TYPE.httpMethodName();
642     String url = getResourceURL(knownResourceId);
643     String mediaType = MediaType.APPLICATION_XML;
644     final String entity = "";
645     int statusCode = submitRequest(method, url, mediaType, entity);
646
647     // Check the status code of the response: does it match
648     // the expected response(s)?
649     if(logger.isDebugEnabled()){
650         logger.debug(testName + ": url=" + url +
651             " status=" + statusCode);
652      }
653     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
654     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
655     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
656     }
657
658     @Override
659     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
660         dependsOnMethods = {"create", "update", "testSubmitRequest"})
661     public void updateWithMalformedXml(String testName) throws Exception {
662
663     // Perform setup.
664     setupUpdateWithMalformedXml(testName);
665
666     // Submit the request to the service and store the response.
667     String method = REQUEST_TYPE.httpMethodName();
668     String url = getResourceURL(knownResourceId);
669     String mediaType = MediaType.APPLICATION_XML;
670     final String entity = MALFORMED_XML_DATA;
671     int statusCode = submitRequest(method, url, mediaType, entity);
672
673     // Check the status code of the response: does it match
674     // the expected response(s)?
675     if(logger.isDebugEnabled()){
676         logger.debug(testName + ": url=" + url +
677            " status=" + statusCode);
678      }
679     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
680     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
681     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
682     }
683
684     @Override
685     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
686         dependsOnMethods = {"create", "update", "testSubmitRequest"})
687     public void updateWithWrongXmlSchema(String testName) throws Exception {
688
689     // Perform setup.
690     setupUpdateWithWrongXmlSchema(testName);
691
692     // Submit the request to the service and store the response.
693     String method = REQUEST_TYPE.httpMethodName();
694     String url = getResourceURL(knownResourceId);
695     String mediaType = MediaType.APPLICATION_XML;
696     final String entity = WRONG_XML_SCHEMA_DATA;
697     int statusCode = submitRequest(method, url, mediaType, entity);
698
699     // Check the status code of the response: does it match
700     // the expected response(s)?
701     if(logger.isDebugEnabled()){
702         logger.debug("updateWithWrongXmlSchema: url=" + url +
703             " status=" + statusCode);
704      }
705     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
706     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
707     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
708     }
709      */
710
711
712     @Override
713     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
714         dependsOnMethods = {"update", "testSubmitRequest"})
715     public void updateNonExistent(String testName) throws Exception {
716
717         // Perform setup.
718         setupUpdateNonExistent(testName);
719
720         // Submit the request to the service and store the response.
721         // Note: The ID used in this 'create' call may be arbitrary.
722         // The only relevant ID may be the one used in update(), below.
723
724         // The only relevant ID may be the one used in update(), below.
725         String displayName = "displayName-" + NON_EXISTENT_ID;
726         String refName = VocabularyClientUtils.createVocabularyRefName(displayName, false);
727         MultipartOutput multipart = VocabularyClientUtils.createEnumerationInstance(
728                                 displayName, refName, client.getCommonPartName());
729         ClientResponse<MultipartInput> res =
730                 client.update(NON_EXISTENT_ID, multipart);
731         int statusCode = res.getStatus();
732
733         // Check the status code of the response: does it match
734         // the expected response(s)?
735         if(logger.isDebugEnabled()){
736             logger.debug(testName + ": status = " + statusCode);
737         }
738         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
739                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
740         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
741     }
742
743     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
744         dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
745     public void updateNonExistentItem(String testName) throws Exception {
746
747         // Perform setup.
748         setupUpdateNonExistent(testName);
749
750         // Submit the request to the service and store the response.
751         // Note: The ID used in this 'create' call may be arbitrary.
752         // The only relevant ID may be the one used in update(), below.
753
754         // The only relevant ID may be the one used in update(), below.
755         HashMap<String, String> itemInfo = new HashMap<String, String>();
756         itemInfo.put(VocabularyItemJAXBSchema.DISPLAY_NAME, "nonex");
757         MultipartOutput multipart = VocabularyClientUtils.createVocabularyItemInstance(
758                         knownResourceId, NON_EXISTENT_ID, itemInfo, NON_EXISTENT_ID);
759         ClientResponse<MultipartInput> res =
760                 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
761         int statusCode = res.getStatus();
762
763         // Check the status code of the response: does it match
764         // the expected response(s)?
765         if(logger.isDebugEnabled()){
766             logger.debug(testName + ": status = " + statusCode);
767         }
768         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
769                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
770         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
771     }
772
773     // ---------------------------------------------------------------
774     // CRUD tests : DELETE tests
775     // ---------------------------------------------------------------
776     // Success outcomes
777     @Override
778     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
779         dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
780     public void delete(String testName) throws Exception {
781
782         // Perform setup.
783         setupDelete(testName);
784
785         // Submit the request to the service and store the response.
786         ClientResponse<Response> res = client.delete(knownResourceId);
787         int statusCode = res.getStatus();
788
789         // Check the status code of the response: does it match
790         // the expected response(s)?
791         if(logger.isDebugEnabled()){
792             logger.debug(testName + ": status = " + statusCode);
793         }
794         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
795                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
796         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
797     }
798
799    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
800         dependsOnMethods = {"createItem", "readItemList", "testItemSubmitRequest",
801             "updateItem"})
802     public void deleteItem(String testName) throws Exception {
803
804         // Perform setup.
805         setupDelete(testName);
806
807         // Submit the request to the service and store the response.
808         ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
809         int statusCode = res.getStatus();
810
811         // Check the status code of the response: does it match
812         // the expected response(s)?
813         if(logger.isDebugEnabled()){
814             logger.debug("delete: status = " + statusCode);
815         }
816         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
817                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
818         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
819     }
820
821     // Failure outcomes
822     @Override
823     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
824         dependsOnMethods = {"delete"})
825     public void deleteNonExistent(String testName) throws Exception {
826
827         // Perform setup.
828         setupDeleteNonExistent(testName);
829
830         // Submit the request to the service and store the response.
831         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
832         int statusCode = res.getStatus();
833
834         // Check the status code of the response: does it match
835         // the expected response(s)?
836         if(logger.isDebugEnabled()){
837             logger.debug(testName + ": status = " + statusCode);
838         }
839         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
840                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
841         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
842     }
843
844     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
845         dependsOnMethods = {"deleteItem"})
846     public void deleteNonExistentItem(String testName) {
847
848         // Perform setup.
849         setupDeleteNonExistent(testName);
850
851         // Submit the request to the service and store the response.
852         ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
853         int statusCode = res.getStatus();
854
855         // Check the status code of the response: does it match
856         // the expected response(s)?
857         if(logger.isDebugEnabled()){
858             logger.debug(testName + ": status = " + statusCode);
859         }
860         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
861                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
862         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
863     }
864
865     // ---------------------------------------------------------------
866     // Utility tests : tests of code used in tests above
867     // ---------------------------------------------------------------
868     /**
869      * Tests the code for manually submitting data that is used by several
870      * of the methods above.
871      */
872     @Test(dependsOnMethods = {"create", "read"})
873     public void testSubmitRequest() {
874
875         // Expected status code: 200 OK
876         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
877
878         // Submit the request to the service and store the response.
879         String method = ServiceRequestType.READ.httpMethodName();
880         String url = getResourceURL(knownResourceId);
881         int statusCode = submitRequest(method, url);
882
883         // Check the status code of the response: does it match
884         // the expected response(s)?
885         if(logger.isDebugEnabled()){
886             logger.debug("testSubmitRequest: url=" + url +
887                 " status=" + statusCode);
888         }
889         Assert.assertEquals(statusCode, EXPECTED_STATUS);
890
891     }
892
893     @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
894     public void testItemSubmitRequest() {
895
896         // Expected status code: 200 OK
897         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
898
899         // Submit the request to the service and store the response.
900         String method = ServiceRequestType.READ.httpMethodName();
901         String url = getItemResourceURL(knownResourceId, knownItemResourceId);
902         int statusCode = submitRequest(method, url);
903
904         // Check the status code of the response: does it match
905         // the expected response(s)?
906         if(logger.isDebugEnabled()){
907             logger.debug("testItemSubmitRequest: url=" + url +
908                 " status=" + statusCode);
909         }
910         Assert.assertEquals(statusCode, EXPECTED_STATUS);
911
912     }
913
914     // ---------------------------------------------------------------
915     // Cleanup of resources created during testing
916     // ---------------------------------------------------------------
917     
918     /**
919      * Deletes all resources created by tests, after all tests have been run.
920      *
921      * This cleanup method will always be run, even if one or more tests fail.
922      * For this reason, it attempts to remove all resources created
923      * at any point during testing, even if some of those resources
924      * may be expected to be deleted by certain tests.
925      */
926     @AfterClass(alwaysRun=true)
927     public void cleanUp() {
928
929         if (logger.isDebugEnabled()) {
930             logger.debug("Cleaning up temporary resources created for testing ...");
931         }
932         // Clean up vocabulary item resources.
933         String vocabularyResourceId;
934         String vocabularyItemResourceId;
935         for (Map.Entry<String, String> entry : allResourceItemIdsCreated.entrySet()) {
936             vocabularyItemResourceId = entry.getKey();
937             vocabularyResourceId = entry.getValue();
938             // Note: Any non-success responses are ignored and not reported.
939             ClientResponse<Response> res =
940                 client.deleteItem(vocabularyResourceId, vocabularyItemResourceId);
941         }
942         // Clean up vocabulary resources.
943         for (String resourceId : allResourceIdsCreated) {
944             // Note: Any non-success responses are ignored and not reported.
945             ClientResponse<Response> res = client.delete(resourceId);
946         }
947
948     }
949
950     // ---------------------------------------------------------------
951     // Utility methods used by tests above
952     // ---------------------------------------------------------------
953     @Override
954     public String getServicePathComponent() {
955         return SERVICE_PATH_COMPONENT;
956     }
957
958     public String getItemServicePathComponent() {
959         return ITEM_SERVICE_PATH_COMPONENT;
960     }
961
962     /**
963      * Returns the root URL for a service.
964      *
965      * This URL consists of a base URL for all services, followed by
966      * a path component for the owning vocabulary, followed by the 
967      * path component for the items.
968      *
969      * @return The root URL for a service.
970      */
971     protected String getItemServiceRootURL(String parentResourceIdentifier) {
972         return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
973     }
974
975     /**
976      * Returns the URL of a specific resource managed by a service, and
977      * designated by an identifier (such as a universally unique ID, or UUID).
978      *
979      * @param  resourceIdentifier  An identifier (such as a UUID) for a resource.
980      *
981      * @return The URL of a specific resource managed by a service.
982      */
983     protected String getItemResourceURL(String parentResourceIdentifier, String resourceIdentifier) {
984         return getItemServiceRootURL(parentResourceIdentifier) + "/" + resourceIdentifier;
985     }
986
987
988
989 }