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