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