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