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