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:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright (c)) 2009 Regents of the University of California
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
15 * https://source.collectionspace.org/collection-space/LICENSE.txt
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.
23 package org.collectionspace.services.client.test;
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.List;
29 import javax.ws.rs.core.MediaType;
30 import javax.ws.rs.core.Response;
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;
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;
53 * VocabularyServiceTest, carries out tests against a
54 * deployed and running Vocabulary Service.
56 * $LastChangedRevision: 753 $
57 * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
59 public class VocabularyServiceTest extends AbstractServiceTestImpl {
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>();
78 protected void setKnownResource(String id, String shortIdentifer,
79 String refName, String fullRefName) {
81 knownResourceShortIdentifer = shortIdentifer;
82 knownResourceRefName = refName;
83 knownResourceFullRefName = fullRefName;
87 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
90 protected CollectionSpaceClient getClientInstance() {
91 return new VocabularyClient();
95 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
98 protected AbstractCommonList getAbstractCommonList(
99 ClientResponse<AbstractCommonList> response) {
100 return response.getEntity(VocabulariesCommonList.class);
104 protected PoxPayloadOut createInstance(String identifier) {
105 VocabularyClient client = new VocabularyClient();
106 String displayName = "displayName-" + identifier;
107 PoxPayloadOut multipart = VocabularyClientUtils.createEnumerationInstance(
108 displayName, identifier, client.getCommonPartName());
113 // ---------------------------------------------------------------
114 // CRUD tests : CREATE tests
115 // ---------------------------------------------------------------
118 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
119 public void create(String testName) throws Exception {
121 if (logger.isDebugEnabled()) {
122 logger.debug(testBanner(testName, CLASS_NAME));
124 // Perform setup, such as initializing the type of service request
125 // (e.g. CREATE, DELETE), its valid and expected status codes, and
126 // its associated HTTP method name (e.g. POST, DELETE).
129 // Submit the request to the service and store the response.
130 VocabularyClient client = new VocabularyClient();
131 String identifier = createIdentifier();
132 String displayName = "displayName-" + identifier;
133 PoxPayloadOut multipart = VocabularyClientUtils.createEnumerationInstance(
134 displayName, identifier, client.getCommonPartName());
135 ClientResponse<Response> res = client.create(multipart);
136 int statusCode = res.getStatus();
138 // Check the status code of the response: does it match
139 // the expected response(s)?
142 // Does it fall within the set of valid status codes?
143 // Does it exactly match the expected status code?
144 if (logger.isDebugEnabled()) {
145 logger.debug(testName + ": status = " + statusCode);
147 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
148 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
149 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
151 // Store the ID returned from the first resource created
152 // for additional tests below.
153 if (knownResourceId == null) {
154 setKnownResource(extractId(res), identifier,
155 VocabularyClientUtils.createVocabularyRefName(identifier, null),
156 VocabularyClientUtils.createVocabularyRefName(identifier, displayName));
157 if (logger.isDebugEnabled()) {
158 logger.debug(testName + ": knownResourceId=" + knownResourceId);
161 // Store the IDs from every resource created by tests,
162 // so they can be deleted after tests have been run.
163 allResourceIdsCreated.add(extractId(res));
167 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
168 dependsOnMethods = {"create"})
169 public void createItem(String testName) {
171 if (null != testName && logger.isDebugEnabled()) {
172 logger.debug(testBanner(testName, CLASS_NAME));
177 VocabularyClient client = new VocabularyClient();
178 HashMap<String, String> itemInfo = new HashMap<String, String>();
179 String shortId = createIdentifier();
180 itemInfo.put(AuthorityItemJAXBSchema.SHORT_IDENTIFIER, shortId);
181 itemInfo.put(AuthorityItemJAXBSchema.DISPLAY_NAME, "display-" + shortId);
182 String newID = VocabularyClientUtils.createItemInVocabulary(knownResourceId,
183 knownResourceRefName, itemInfo, client);
185 // Store the ID returned from the first item resource created
186 // for additional tests below.
187 if (knownItemResourceId == null) {
188 knownItemResourceId = newID;
189 if (null != testName && logger.isDebugEnabled()) {
190 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
193 // Store the IDs from any item resources created
194 // by tests, along with the IDs of their parents, so these items
195 // can be deleted after all tests have been run.
196 allResourceItemIdsCreated.put(newID, knownResourceId);
200 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
201 dependsOnMethods = {"create", "createItem", "readItem"})
202 public void createList(String testName) throws Exception {
203 for (int i = 0; i < 3; i++) {
204 // Force create to reset the known resource info
205 setKnownResource(null, null, null, null);
206 knownItemResourceId = null;
208 // Add nItemsToCreateInList items to each vocab
209 for (int j = 0; j < nItemsToCreateInList; j++) {
216 // Placeholders until the three tests below can be uncommented.
217 // See Issue CSPACE-401.
219 public void createWithEmptyEntityBody(String testName) throws Exception {
223 public void createWithMalformedXml(String testName) throws Exception {
227 public void createWithWrongXmlSchema(String testName) throws Exception {
230 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
231 dependsOnMethods = {"create"})
232 public void createWithBadShortId(String testName) throws Exception {
234 if (logger.isDebugEnabled()) {
235 logger.debug(testBanner(testName, CLASS_NAME));
237 testSetup(STATUS_BAD_REQUEST, ServiceRequestType.CREATE);
239 // Submit the request to the service and store the response.
240 VocabularyClient client = new VocabularyClient();
241 PoxPayloadOut multipart = VocabularyClientUtils.createEnumerationInstance(
242 "Vocab with Bad Short Id", "Bad Short Id!", client.getCommonPartName());
243 ClientResponse<Response> res = client.create(multipart);
244 int statusCode = res.getStatus();
246 // Check the status code of the response: does it match
247 // the expected response(s)?
250 // Does it fall within the set of valid status codes?
251 // Does it exactly match the expected status code?
252 if (logger.isDebugEnabled()) {
253 logger.debug(testName + ": status = " + statusCode);
255 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
256 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
257 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
260 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
261 dependsOnMethods = {"createItem"})
262 public void createItemWithBadShortId(String testName) throws Exception {
264 if (logger.isDebugEnabled()) {
265 logger.debug(testBanner(testName, CLASS_NAME));
267 setupCreateWithMalformedXml();
269 // Submit the request to the service and store the response.
270 VocabularyClient client = new VocabularyClient();
271 HashMap<String, String> itemInfo = new HashMap<String, String>();
272 itemInfo.put(AuthorityItemJAXBSchema.SHORT_IDENTIFIER, "Bad Item Short Id!");
273 itemInfo.put(AuthorityItemJAXBSchema.DISPLAY_NAME, "Bad Item!");
274 PoxPayloadOut multipart =
275 VocabularyClientUtils.createVocabularyItemInstance(knownResourceRefName,
276 itemInfo, client.getCommonPartItemName());
277 ClientResponse<Response> res = client.createItem(knownResourceId, multipart);
279 int statusCode = res.getStatus();
281 if (!REQUEST_TYPE.isValidStatusCode(statusCode)) {
282 throw new RuntimeException("Could not create Item: \"" + itemInfo.get(AuthorityItemJAXBSchema.DISPLAY_NAME)
283 + "\" in personAuthority: \"" + knownResourceRefName
284 + "\" " + invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
286 if (statusCode != EXPECTED_STATUS_CODE) {
287 throw new RuntimeException("Unexpected Status when creating Item: \"" + itemInfo.get(AuthorityItemJAXBSchema.DISPLAY_NAME)
288 + "\" in personAuthority: \"" + knownResourceRefName + "\", Status:" + statusCode);
294 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
295 dependsOnMethods = {"create", "testSubmitRequest"})
296 public void createWithEmptyEntityBody(String testName) throws Exception {
298 if (logger.isDebugEnabled()) {
299 logger.debug(testBanner(testName, CLASS_NAME));
302 setupCreateWithEmptyEntityBody(testName, CLASS_NAME);
304 // Submit the request to the service and store the response.
305 String method = REQUEST_TYPE.httpMethodName();
306 String url = getServiceRootURL();
307 String mediaType = MediaType.APPLICATION_XML;
308 final String entity = "";
309 int statusCode = submitRequest(method, url, mediaType, entity);
311 // Check the status code of the response: does it match
312 // the expected response(s)?
313 if(logger.isDebugEnabled()) {
314 logger.debug(testName + ": url=" + url +
315 " status=" + statusCode);
317 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
318 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
319 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
323 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
324 dependsOnMethods = {"create", "testSubmitRequest"})
325 public void createWithMalformedXml(String testName) throws Exception {
327 if (logger.isDebugEnabled()) {
328 logger.debug(testBanner(testName, CLASS_NAME));
331 setupCreateWithMalformedXml();
333 // Submit the request to the service and store the response.
334 String method = REQUEST_TYPE.httpMethodName();
335 String url = getServiceRootURL();
336 String mediaType = MediaType.APPLICATION_XML;
337 final String entity = MALFORMED_XML_DATA; // Constant from base class.
338 int statusCode = submitRequest(method, url, mediaType, entity);
340 // Check the status code of the response: does it match
341 // the expected response(s)?
342 if(logger.isDebugEnabled()){
343 logger.debug(testName + ": url=" + url +
344 " status=" + statusCode);
346 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
347 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
348 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
352 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
353 dependsOnMethods = {"create", "testSubmitRequest"})
354 public void createWithWrongXmlSchema(String testName) throws Exception {
356 if (logger.isDebugEnabled()) {
357 logger.debug(testBanner(testName, CLASS_NAME));
360 setupCreateWithWrongXmlSchema();
362 // Submit the request to the service and store the response.
363 String method = REQUEST_TYPE.httpMethodName();
364 String url = getServiceRootURL();
365 String mediaType = MediaType.APPLICATION_XML;
366 final String entity = WRONG_XML_SCHEMA_DATA;
367 int statusCode = submitRequest(method, url, mediaType, entity);
369 // Check the status code of the response: does it match
370 // the expected response(s)?
371 if(logger.isDebugEnabled()){
372 logger.debug(testName + ": url=" + url +
373 " status=" + statusCode);
375 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
376 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
377 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
380 // ---------------------------------------------------------------
381 // CRUD tests : READ tests
382 // ---------------------------------------------------------------
385 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
386 dependsOnMethods = {"create"})
387 public void read(String testName) throws Exception {
389 if (logger.isDebugEnabled()) {
390 logger.debug(testBanner(testName, CLASS_NAME));
395 // Submit the request to the service and store the response.
396 VocabularyClient client = new VocabularyClient();
397 ClientResponse<String> res = client.read(knownResourceId);
398 int statusCode = res.getStatus();
400 // Check the status code of the response: does it match
401 // the expected response(s)?
402 if (logger.isDebugEnabled()) {
403 logger.debug(testName + ": status = " + statusCode);
405 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
406 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
407 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
408 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
409 VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input,
410 client.getCommonPartName(), VocabulariesCommon.class);
412 Assert.assertNotNull(vocabulary);
413 Assert.assertEquals(vocabulary.getRefName(), knownResourceFullRefName);
419 * @param testName the test name
420 * @throws Exception the exception
422 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
423 dependsOnMethods = {"read"})
424 public void readByName(String testName) throws Exception {
426 if (logger.isDebugEnabled()) {
427 logger.debug(testBanner(testName, CLASS_NAME));
432 // Submit the request to the service and store the response.
433 VocabularyClient client = new VocabularyClient();
434 ClientResponse<String> res = client.readByName(knownResourceShortIdentifer);
435 int statusCode = res.getStatus();
437 // Check the status code of the response: does it match
438 // the expected response(s)?
439 if (logger.isDebugEnabled()) {
440 logger.debug(testName + ": status = " + statusCode);
442 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
443 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
444 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
445 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
446 VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input,
447 client.getCommonPartName(), VocabulariesCommon.class);
449 Assert.assertNotNull(vocabulary);
453 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
454 dependsOnMethods = {"read"})
455 public void readByName(String testName) throws Exception {
457 if (logger.isDebugEnabled()) {
458 logger.debug(testBanner(testName, CLASS_NAME));
463 // Submit the request to the service and store the response.
464 ClientResponse<PoxPayloadIn> res = client.read(knownResourceId);
465 int statusCode = res.getStatus();
467 // Check the status code of the response: does it match
468 // the expected response(s)?
469 if(logger.isDebugEnabled()){
470 logger.debug(testName + ": status = " + statusCode);
472 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
473 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
474 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
475 //FIXME: remove the following try catch once Aron fixes signatures
477 PoxPayloadIn input = (PoxPayloadIn) res.getEntity();
478 VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input,
479 client.getCommonPartName(), VocabulariesCommon.class);
480 Assert.assertNotNull(vocabulary);
481 } catch (Exception e) {
482 throw new RuntimeException(e);
486 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
487 dependsOnMethods = {"createItem", "read"})
488 public void readItem(String testName) throws Exception {
490 if (logger.isDebugEnabled()) {
491 logger.debug(testBanner(testName, CLASS_NAME));
496 // Submit the request to the service and store the response.
497 VocabularyClient client = new VocabularyClient();
498 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
499 int statusCode = res.getStatus();
501 // Check the status code of the response: does it match
502 // the expected response(s)?
503 if (logger.isDebugEnabled()) {
504 logger.debug(testName + ": status = " + statusCode);
506 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
507 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
508 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
510 // Check whether we've received a vocabulary item.
511 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
512 VocabularyitemsCommon vocabularyItem = (VocabularyitemsCommon) extractPart(input,
513 client.getCommonPartItemName(), VocabularyitemsCommon.class);
514 Assert.assertNotNull(vocabularyItem);
515 Assert.assertEquals(vocabularyItem.getInAuthority(), knownResourceId);
519 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
520 dependsOnMethods = {"updateItem"})
521 public void verifyIllegalItemDisplayName(String testName) throws Exception {
523 if (logger.isDebugEnabled()) {
524 logger.debug(testBanner(testName, CLASS_NAME));
527 testSetup(STATUS_BAD_REQUEST, ServiceRequestType.UPDATE);
528 // setupUpdateWithWrongXmlSchema(testName);
530 // Submit the request to the service and store the response.
531 VocabularyClient client = new VocabularyClient();
532 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
533 int statusCode = res.getStatus();
535 // Check the status code of the response: does it match
536 // the expected response(s)?
537 if (logger.isDebugEnabled()) {
538 logger.debug(testName + ": status = " + statusCode);
540 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
541 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
542 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
544 // Check whether Person has expected displayName.
545 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
546 VocabularyitemsCommon vitem = (VocabularyitemsCommon) extractPart(input,
547 client.getCommonPartItemName(), VocabularyitemsCommon.class);
548 Assert.assertNotNull(vitem);
549 // Try to Update with null displayName
550 vitem.setDisplayName(null);
552 // Submit the updated resource to the service and store the response.
553 PoxPayloadOut output = new PoxPayloadOut(SERVICE_ITEM_PAYLOAD_NAME);
554 PayloadOutputPart commonPart = output.addPart(vitem, MediaType.APPLICATION_XML_TYPE);
555 commonPart.setLabel(client.getCommonPartItemName());
556 res = client.updateItem(knownResourceId, knownItemResourceId, output);
557 statusCode = res.getStatus();
559 // Check the status code of the response: does it match the expected response(s)?
560 if (logger.isDebugEnabled()) {
561 logger.debug("updateItem: status = " + statusCode);
563 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
564 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
565 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE,
566 "Expecting invalid message because of null displayName.");
568 // Now try to Update with 1-char displayName (too short)
569 vitem.setDisplayName("a");
571 // Submit the updated resource to the service and store the response.
572 output = new PoxPayloadOut(SERVICE_ITEM_PAYLOAD_NAME);
573 commonPart = output.addPart(vitem, MediaType.APPLICATION_XML_TYPE);
574 commonPart.setLabel(client.getCommonPartItemName());
575 res = client.updateItem(knownResourceId, knownItemResourceId, output);
576 statusCode = res.getStatus();
578 // Check the status code of the response: does it match the expected response(s)?
579 if (logger.isDebugEnabled()) {
580 logger.debug("updateItem: status = " + statusCode);
582 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
583 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
584 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE,
585 "Expecting invalid message because of 1-char displayName.");
589 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
590 dependsOnMethods = {"read"})
591 public void readNonExistent(String testName) {
593 if (logger.isDebugEnabled()) {
594 logger.debug(testBanner(testName, CLASS_NAME));
597 setupReadNonExistent();
599 // Submit the request to the service and store the response.
600 VocabularyClient client = new VocabularyClient();
601 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
602 int statusCode = res.getStatus();
604 // Check the status code of the response: does it match
605 // the expected response(s)?
606 if (logger.isDebugEnabled()) {
607 logger.debug(testName + ": status = " + statusCode);
609 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
610 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
611 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
614 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
615 dependsOnMethods = {"readItem", "readNonExistent"})
616 public void readItemNonExistent(String testName) {
618 if (logger.isDebugEnabled()) {
619 logger.debug(testBanner(testName, CLASS_NAME));
622 setupReadNonExistent();
624 // Submit the request to the service and store the response.
625 VocabularyClient client = new VocabularyClient();
626 ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
627 int statusCode = res.getStatus();
629 // Check the status code of the response: does it match
630 // the expected response(s)?
631 if (logger.isDebugEnabled()) {
632 logger.debug(testName + ": status = " + statusCode);
634 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
635 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
636 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
638 // ---------------------------------------------------------------
639 // CRUD tests : READ_LIST tests
640 // ---------------------------------------------------------------
644 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
645 dependsOnMethods = {"createList", "read"})
646 public void readList(String testName) throws Exception {
648 if (logger.isDebugEnabled()) {
649 logger.debug(testBanner(testName, CLASS_NAME));
654 // Submit the request to the service and store the response.
655 VocabularyClient client = new VocabularyClient();
656 ClientResponse<VocabulariesCommonList> res = client.readList();
657 VocabulariesCommonList list = res.getEntity();
658 int statusCode = res.getStatus();
660 // Check the status code of the response: does it match
661 // the expected response(s)?
662 if (logger.isDebugEnabled()) {
663 logger.debug(testName + ": status = " + statusCode);
665 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
666 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
667 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
669 // Optionally output additional data about list members for debugging.
670 boolean iterateThroughList = false;
671 if (iterateThroughList && logger.isDebugEnabled()) {
672 List<VocabulariesCommonList.VocabularyListItem> items =
673 list.getVocabularyListItem();
675 for (VocabulariesCommonList.VocabularyListItem item : items) {
676 String csid = item.getCsid();
677 logger.debug(testName + ": list-item[" + i + "] csid="
679 logger.debug(testName + ": list-item[" + i + "] displayName="
680 + item.getDisplayName());
681 logger.debug(testName + ": list-item[" + i + "] URI="
683 readItemListInt(csid, null, "readList");
689 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
690 dependsOnMethods = {"createList", "readItem"})
691 public void readItemList(String testName) {
692 readItemListInt(knownResourceId, null, testName);
695 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
696 dependsOnMethods = {"createList", "readItem"})
697 public void readItemListByName(String testName) {
698 readItemListInt(null, knownResourceShortIdentifer, testName);
701 private void readItemListInt(String vcsid, String shortId, String testName) {
706 // Submit the request to the service and store the response.
707 VocabularyClient client = new VocabularyClient();
708 ClientResponse<VocabularyitemsCommonList> res = null;
710 res = client.readItemList(vcsid, null, null);
711 } else if (shortId != null) {
712 res = client.readItemListForNamedAuthority(shortId, null, null);
714 Assert.fail("Internal Error: readItemList both vcsid and shortId are null!");
716 VocabularyitemsCommonList list = res.getEntity();
717 int statusCode = res.getStatus();
719 // Check the status code of the response: does it match
720 // the expected response(s)?
721 if (logger.isDebugEnabled()) {
722 logger.debug(" " + testName + ": status = " + statusCode);
724 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
725 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
726 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
728 List<VocabularyitemsCommonList.VocabularyitemListItem> items =
729 list.getVocabularyitemListItem();
730 int nItemsReturned = items.size();
731 long nItemsTotal = list.getTotalItems();
732 if (logger.isDebugEnabled()) {
733 logger.debug(" " + testName + ": Expected "
734 + nItemsToCreateInList + " items; got: " + nItemsReturned + " of: " + nItemsTotal);
736 Assert.assertEquals(nItemsTotal, nItemsToCreateInList);
738 // Optionally output additional data about list members for debugging.
739 boolean iterateThroughList = true;
740 if (iterateThroughList && logger.isDebugEnabled()) {
741 logger.debug(" " + testName + ": checking items");
743 for (VocabularyitemsCommonList.VocabularyitemListItem item : items) {
744 logger.debug(" " + testName + ": list-item[" + i + "] csid="
746 logger.debug(" " + testName + ": list-item[" + i + "] displayName="
747 + item.getDisplayName());
748 logger.debug(" " + testName + ": list-item[" + i + "] URI="
757 // ---------------------------------------------------------------
758 // CRUD tests : UPDATE tests
759 // ---------------------------------------------------------------
762 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
763 dependsOnMethods = {"read"})
764 public void update(String testName) throws Exception {
766 if (logger.isDebugEnabled()) {
767 logger.debug(testBanner(testName, CLASS_NAME));
772 // Retrieve the contents of a resource to update.
773 VocabularyClient client = new VocabularyClient();
774 ClientResponse<String> res =
775 client.read(knownResourceId);
776 if (logger.isDebugEnabled()) {
777 logger.debug(testName + ": read status = " + res.getStatus());
779 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
781 if (logger.isDebugEnabled()) {
782 logger.debug("got Vocabulary to update with ID: " + knownResourceId);
784 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
785 VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input,
786 client.getCommonPartName(), VocabulariesCommon.class);
787 Assert.assertNotNull(vocabulary);
789 // Update the contents of this resource.
790 vocabulary.setDisplayName("updated-" + vocabulary.getDisplayName());
791 vocabulary.setVocabType("updated-" + vocabulary.getVocabType());
792 if (logger.isDebugEnabled()) {
793 logger.debug("to be updated Vocabulary");
794 logger.debug(objectAsXmlString(vocabulary, VocabulariesCommon.class));
797 // Submit the updated resource to the service and store the response.
798 PoxPayloadOut output = new PoxPayloadOut(SERVICE_PAYLOAD_NAME);
800 PayloadOutputPart commonPart = output.addPart(vocabulary, MediaType.APPLICATION_XML_TYPE);
801 commonPart.setLabel(client.getCommonPartName());
802 res = client.update(knownResourceId, output);
803 int statusCode = res.getStatus();
805 // Check the status code of the response: does it match the expected response(s)?
806 if (logger.isDebugEnabled()) {
807 logger.debug("update: status = " + statusCode);
809 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
810 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
811 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
813 // Retrieve the updated resource and verify that its contents exist.
814 input = new PoxPayloadIn(res.getEntity());
815 VocabulariesCommon updatedVocabulary =
816 (VocabulariesCommon) extractPart(input,
817 client.getCommonPartName(), VocabulariesCommon.class);
818 Assert.assertNotNull(updatedVocabulary);
820 // Verify that the updated resource received the correct data.
821 Assert.assertEquals(updatedVocabulary.getDisplayName(),
822 vocabulary.getDisplayName(),
823 "Data in updated object did not match submitted data.");
826 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
827 dependsOnMethods = {"readItem", "update", "verifyIgnoredUpdateWithInAuthority"})
828 public void updateItem(String testName) throws Exception {
830 if (logger.isDebugEnabled()) {
831 logger.debug(testBanner(testName, CLASS_NAME));
836 // Retrieve the contents of a resource to update.
837 VocabularyClient client = new VocabularyClient();
838 ClientResponse<String> res =
839 client.readItem(knownResourceId, knownItemResourceId);
840 if (logger.isDebugEnabled()) {
841 logger.debug(testName + ": read status = " + res.getStatus());
843 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
845 if (logger.isDebugEnabled()) {
846 logger.debug("got VocabularyItem to update with ID: "
847 + knownItemResourceId
848 + " in Vocab: " + knownResourceId);
850 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
851 VocabularyitemsCommon vocabularyItem = (VocabularyitemsCommon) extractPart(input,
852 client.getCommonPartItemName(), VocabularyitemsCommon.class);
853 Assert.assertNotNull(vocabularyItem);
855 // Update the contents of this resource.
856 vocabularyItem.setDisplayName("updated-" + vocabularyItem.getDisplayName());
857 if (logger.isDebugEnabled()) {
858 logger.debug("to be updated VocabularyItem");
859 logger.debug(objectAsXmlString(vocabularyItem,
860 VocabularyitemsCommon.class));
863 // Submit the updated resource to the service and store the response.
864 PoxPayloadOut output = new PoxPayloadOut(SERVICE_ITEM_PAYLOAD_NAME);
865 PayloadOutputPart commonPart = output.addPart(vocabularyItem, MediaType.APPLICATION_XML_TYPE);
866 commonPart.setLabel(client.getCommonPartItemName());
867 res = client.updateItem(knownResourceId, knownItemResourceId, output);
868 int statusCode = res.getStatus();
870 // Check the status code of the response: does it match the expected response(s)?
871 if (logger.isDebugEnabled()) {
872 logger.debug("updateItem: status = " + statusCode);
874 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
875 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
876 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
878 // Retrieve the updated resource and verify that its contents exist.
879 input = new PoxPayloadIn(res.getEntity());
880 VocabularyitemsCommon updatedVocabularyItem =
881 (VocabularyitemsCommon) extractPart(input,
882 client.getCommonPartItemName(), VocabularyitemsCommon.class);
883 Assert.assertNotNull(updatedVocabularyItem);
885 // Verify that the updated resource received the correct data.
886 Assert.assertEquals(updatedVocabularyItem.getDisplayName(),
887 vocabularyItem.getDisplayName(),
888 "Data in updated VocabularyItem did not match submitted data.");
891 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
892 dependsOnMethods = {"readItem"})
893 public void verifyIgnoredUpdateWithInAuthority(String testName) throws Exception {
895 if (logger.isDebugEnabled()) {
896 logger.debug(testBanner(testName, CLASS_NAME));
901 // Submit the request to the service and store the response.
902 VocabularyClient client = new VocabularyClient();
903 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
904 int statusCode = res.getStatus();
906 // Check the status code of the response: does it match
907 // the expected response(s)?
908 if (logger.isDebugEnabled()) {
909 logger.debug(testName + " read Vocab:" + knownResourceId + "/Item:"
910 + knownItemResourceId + " status = " + statusCode);
912 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
913 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
914 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
916 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
917 VocabularyitemsCommon vitem = (VocabularyitemsCommon) extractPart(input,
918 client.getCommonPartItemName(), VocabularyitemsCommon.class);
919 Assert.assertNotNull(vitem);
920 // Try to Update with new parent vocab (use self, for test).
921 Assert.assertEquals(vitem.getInAuthority(),
923 "VocabularyItem inAuthority does not match knownResourceId.");
924 vitem.setInAuthority(knownItemResourceId);
926 // Submit the updated resource to the service and store the response.
927 PoxPayloadOut output = new PoxPayloadOut(SERVICE_ITEM_PAYLOAD_NAME);
928 PayloadOutputPart commonPart = output.addPart(vitem, MediaType.APPLICATION_XML_TYPE);
929 commonPart.setLabel(client.getCommonPartItemName());
930 res = client.updateItem(knownResourceId, knownItemResourceId, output);
931 statusCode = res.getStatus();
933 // Check the status code of the response: does it match the expected response(s)?
934 if (logger.isDebugEnabled()) {
935 logger.debug(testName + ": status = " + statusCode);
937 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
938 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
939 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
941 // Retrieve the updated resource and verify that the parent did not change
942 res = client.readItem(knownResourceId, knownItemResourceId);
943 input = new PoxPayloadIn(res.getEntity());
944 VocabularyitemsCommon updatedVocabularyItem =
945 (VocabularyitemsCommon) extractPart(input,
946 client.getCommonPartItemName(), VocabularyitemsCommon.class);
947 Assert.assertNotNull(updatedVocabularyItem);
949 // Verify that the updated resource received the correct data.
950 Assert.assertEquals(updatedVocabularyItem.getInAuthority(),
952 "VocabularyItem allowed update to the parent (inAuthority).");
956 // Placeholders until the three tests below can be uncommented.
957 // See Issue CSPACE-401.
959 public void updateWithEmptyEntityBody(String testName) throws Exception {
963 public void updateWithMalformedXml(String testName) throws Exception {
967 public void updateWithWrongXmlSchema(String testName) throws Exception {
972 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
973 dependsOnMethods = {"create", "update", "testSubmitRequest"})
974 public void updateWithEmptyEntityBody(String testName) throws Exception {
976 if (logger.isDebugEnabled()) {
977 logger.debug(testBanner(testName, CLASS_NAME));
980 setupUpdateWithEmptyEntityBody();
982 // Submit the request to the service and store the response.
983 String method = REQUEST_TYPE.httpMethodName();
984 String url = getResourceURL(knownResourceId);
985 String mediaType = MediaType.APPLICATION_XML;
986 final String entity = "";
987 int statusCode = submitRequest(method, url, mediaType, entity);
989 // Check the status code of the response: does it match
990 // the expected response(s)?
991 if(logger.isDebugEnabled()){
992 logger.debug(testName + ": url=" + url +
993 " status=" + statusCode);
995 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
996 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
997 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1001 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1002 dependsOnMethods = {"create", "update", "testSubmitRequest"})
1003 public void updateWithMalformedXml(String testName) throws Exception {
1005 if (logger.isDebugEnabled()) {
1006 logger.debug(testBanner(testName, CLASS_NAME));
1009 setupUpdateWithMalformedXml();
1011 // Submit the request to the service and store the response.
1012 String method = REQUEST_TYPE.httpMethodName();
1013 String url = getResourceURL(knownResourceId);
1014 String mediaType = MediaType.APPLICATION_XML;
1015 final String entity = MALFORMED_XML_DATA;
1016 int statusCode = submitRequest(method, url, mediaType, entity);
1018 // Check the status code of the response: does it match
1019 // the expected response(s)?
1020 if(logger.isDebugEnabled()){
1021 logger.debug(testName + ": url=" + url +
1022 " status=" + statusCode);
1024 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1025 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1026 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1030 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1031 dependsOnMethods = {"create", "update", "testSubmitRequest"})
1032 public void updateWithWrongXmlSchema(String testName) throws Exception {
1034 if (logger.isDebugEnabled()) {
1035 logger.debug(testBanner(testName, CLASS_NAME));
1038 setupUpdateWithWrongXmlSchema();
1040 // Submit the request to the service and store the response.
1041 String method = REQUEST_TYPE.httpMethodName();
1042 String url = getResourceURL(knownResourceId);
1043 String mediaType = MediaType.APPLICATION_XML;
1044 final String entity = WRONG_XML_SCHEMA_DATA;
1045 int statusCode = submitRequest(method, url, mediaType, entity);
1047 // Check the status code of the response: does it match
1048 // the expected response(s)?
1049 if(logger.isDebugEnabled()){
1050 logger.debug("updateWithWrongXmlSchema: url=" + url +
1051 " status=" + statusCode);
1053 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1054 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1055 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1059 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1060 dependsOnMethods = {"update", "testSubmitRequest"})
1061 public void updateNonExistent(String testName) throws Exception {
1063 if (logger.isDebugEnabled()) {
1064 logger.debug(testBanner(testName, CLASS_NAME));
1067 setupUpdateNonExistent();
1069 // Submit the request to the service and store the response.
1070 // Note: The ID used in this 'create' call may be arbitrary.
1071 // The only relevant ID may be the one used in update(), below.
1072 VocabularyClient client = new VocabularyClient();
1073 String displayName = "displayName-" + NON_EXISTENT_ID;
1074 PoxPayloadOut multipart = VocabularyClientUtils.createEnumerationInstance(
1075 displayName, NON_EXISTENT_ID, client.getCommonPartName());
1076 ClientResponse<String> res =
1077 client.update(NON_EXISTENT_ID, multipart);
1078 int statusCode = res.getStatus();
1080 // Check the status code of the response: does it match
1081 // the expected response(s)?
1082 if (logger.isDebugEnabled()) {
1083 logger.debug(testName + ": status = " + statusCode);
1085 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1086 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1087 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1090 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1091 dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1092 public void updateNonExistentItem(String testName) throws Exception {
1094 if (logger.isDebugEnabled()) {
1095 logger.debug(testBanner(testName, CLASS_NAME));
1098 setupUpdateNonExistent();
1100 // Submit the request to the service and store the response.
1101 // Note: The ID used in this 'create' call may be arbitrary.
1102 // The only relevant ID may be the one used in update(), below.
1103 VocabularyClient client = new VocabularyClient();
1104 HashMap<String, String> itemInfo = new HashMap<String, String>();
1105 itemInfo.put(AuthorityItemJAXBSchema.SHORT_IDENTIFIER, "nonex");
1106 itemInfo.put(AuthorityItemJAXBSchema.DISPLAY_NAME, "display-nonex");
1107 PoxPayloadOut multipart =
1108 VocabularyClientUtils.createVocabularyItemInstance(
1109 VocabularyClientUtils.createVocabularyRefName(NON_EXISTENT_ID, null),
1110 itemInfo, client.getCommonPartItemName());
1111 ClientResponse<String> res =
1112 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1113 int statusCode = res.getStatus();
1115 // Check the status code of the response: does it match
1116 // the expected response(s)?
1117 if (logger.isDebugEnabled()) {
1118 logger.debug(testName + ": status = " + statusCode);
1120 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1121 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1122 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1125 // ---------------------------------------------------------------
1126 // CRUD tests : DELETE tests
1127 // ---------------------------------------------------------------
1130 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1131 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update", "deleteItem"})
1132 public void delete(String testName) throws Exception {
1134 if (logger.isDebugEnabled()) {
1135 logger.debug(testBanner(testName, CLASS_NAME));
1140 // Submit the request to the service and store the response.
1141 VocabularyClient client = new VocabularyClient();
1142 ClientResponse<Response> res = client.delete(knownResourceId);
1143 int statusCode = res.getStatus();
1145 // Check the status code of the response: does it match
1146 // the expected response(s)?
1147 if (logger.isDebugEnabled()) {
1148 logger.debug(testName + ": status = " + statusCode);
1150 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1151 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1152 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1155 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1156 dependsOnMethods = {"createItem", "readItemList", "testItemSubmitRequest",
1157 "updateItem", "verifyIllegalItemDisplayName", "verifyIgnoredUpdateWithInAuthority"})
1158 public void deleteItem(String testName) throws Exception {
1160 if (logger.isDebugEnabled()) {
1161 logger.debug(testBanner(testName, CLASS_NAME));
1166 // Submit the request to the service and store the response.
1167 VocabularyClient client = new VocabularyClient();
1168 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1169 int statusCode = res.getStatus();
1171 // Check the status code of the response: does it match
1172 // the expected response(s)?
1173 if (logger.isDebugEnabled()) {
1174 logger.debug("delete: status = " + statusCode);
1176 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1177 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1178 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1183 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1184 dependsOnMethods = {"delete"})
1185 public void deleteNonExistent(String testName) throws Exception {
1187 if (logger.isDebugEnabled()) {
1188 logger.debug(testBanner(testName, CLASS_NAME));
1191 setupDeleteNonExistent();
1193 // Submit the request to the service and store the response.
1194 VocabularyClient client = new VocabularyClient();
1195 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1196 int statusCode = res.getStatus();
1198 // Check the status code of the response: does it match
1199 // the expected response(s)?
1200 if (logger.isDebugEnabled()) {
1201 logger.debug(testName + ": status = " + statusCode);
1203 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1204 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1205 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1208 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1209 dependsOnMethods = {"deleteItem"})
1210 public void deleteNonExistentItem(String testName) {
1212 if (logger.isDebugEnabled()) {
1213 logger.debug(testBanner(testName, CLASS_NAME));
1216 setupDeleteNonExistent();
1218 // Submit the request to the service and store the response.
1219 VocabularyClient client = new VocabularyClient();
1220 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1221 int statusCode = res.getStatus();
1223 // Check the status code of the response: does it match
1224 // the expected response(s)?
1225 if (logger.isDebugEnabled()) {
1226 logger.debug(testName + ": status = " + statusCode);
1228 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1229 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1230 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1233 // ---------------------------------------------------------------
1234 // Utility tests : tests of code used in tests above
1235 // ---------------------------------------------------------------
1237 * Tests the code for manually submitting data that is used by several
1238 * of the methods above.
1240 @Test(dependsOnMethods = {"create", "read"})
1241 public void testSubmitRequest() {
1243 // Expected status code: 200 OK
1246 // Submit the request to the service and store the response.
1247 String method = ServiceRequestType.READ.httpMethodName();
1248 String url = getResourceURL(knownResourceId);
1249 int statusCode = submitRequest(method, url);
1251 // Check the status code of the response: does it match
1252 // the expected response(s)?
1253 if (logger.isDebugEnabled()) {
1254 logger.debug("testSubmitRequest: url=" + url
1255 + " status=" + statusCode);
1257 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1261 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1262 public void testItemSubmitRequest() {
1264 // Expected status code: 200 OK
1265 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1267 // Submit the request to the service and store the response.
1268 String method = ServiceRequestType.READ.httpMethodName();
1269 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1270 int statusCode = submitRequest(method, url);
1272 // Check the status code of the response: does it match
1273 // the expected response(s)?
1274 if (logger.isDebugEnabled()) {
1275 logger.debug("testItemSubmitRequest: url=" + url
1276 + " status=" + statusCode);
1278 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1282 // ---------------------------------------------------------------
1283 // Cleanup of resources created during testing
1284 // ---------------------------------------------------------------
1286 * Deletes all resources created by tests, after all tests have been run.
1288 * This cleanup method will always be run, even if one or more tests fail.
1289 * For this reason, it attempts to remove all resources created
1290 * at any point during testing, even if some of those resources
1291 * may be expected to be deleted by certain tests.
1293 @AfterClass(alwaysRun = true)
1294 public void cleanUp() {
1295 String noTest = System.getProperty("noTestCleanup");
1296 if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1297 if (logger.isDebugEnabled()) {
1298 logger.debug("Skipping Cleanup phase ...");
1302 if (logger.isDebugEnabled()) {
1303 logger.debug("Cleaning up temporary resources created for testing ...");
1305 VocabularyClient client = new VocabularyClient();
1306 String vocabularyResourceId;
1307 String vocabularyItemResourceId;
1308 // Clean up vocabulary item resources.
1309 for (Map.Entry<String, String> entry : allResourceItemIdsCreated.entrySet()) {
1310 vocabularyItemResourceId = entry.getKey();
1311 vocabularyResourceId = entry.getValue();
1312 // Note: Any non-success responses are ignored and not reported.
1313 client.deleteItem(vocabularyResourceId, vocabularyItemResourceId).releaseConnection();
1315 // Clean up vocabulary resources.
1316 for (String resourceId : allResourceIdsCreated) {
1317 // Note: Any non-success responses are ignored and not reported.
1318 client.delete(resourceId).releaseConnection();
1323 // ---------------------------------------------------------------
1324 // Utility methods used by tests above
1325 // ---------------------------------------------------------------
1327 public String getServicePathComponent() {
1328 return SERVICE_PATH_COMPONENT;
1331 public String getServicePathItemsComponent() {
1332 return this.SERVICE_PATH_ITEMS_COMPONENT;
1336 * Returns the root URL for a service.
1338 * This URL consists of a base URL for all services, followed by
1339 * a path component for the owning vocabulary, followed by the
1340 * path component for the items.
1342 * @return The root URL for a service.
1344 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1345 return getResourceURL(parentResourceIdentifier) + "/" + getServicePathItemsComponent();
1349 * Returns the URL of a specific resource managed by a service, and
1350 * designated by an identifier (such as a universally unique ID, or UUID).
1352 * @param resourceIdentifier An identifier (such as a UUID) for a resource.
1354 * @return The URL of a specific resource managed by a service.
1356 protected String getItemResourceURL(String parentResourceIdentifier, String resourceIdentifier) {
1357 return getItemServiceRootURL(parentResourceIdentifier) + "/" + resourceIdentifier;
1361 protected String getServiceName() {
1362 return VocabularyClient.SERVICE_NAME;