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());
112 // ---------------------------------------------------------------
113 // CRUD tests : CREATE tests
114 // ---------------------------------------------------------------
117 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
118 public void create(String testName) throws Exception {
120 if (logger.isDebugEnabled()) {
121 logger.debug(testBanner(testName, CLASS_NAME));
123 // Perform setup, such as initializing the type of service request
124 // (e.g. CREATE, DELETE), its valid and expected status codes, and
125 // its associated HTTP method name (e.g. POST, DELETE).
128 // Submit the request to the service and store the response.
129 VocabularyClient client = new VocabularyClient();
130 String identifier = createIdentifier();
131 String displayName = "displayName-" + identifier;
132 PoxPayloadOut multipart = VocabularyClientUtils.createEnumerationInstance(
133 displayName, identifier, client.getCommonPartName());
134 ClientResponse<Response> res = client.create(multipart);
135 int statusCode = res.getStatus();
137 // Check the status code of the response: does it match
138 // the expected response(s)?
141 // Does it fall within the set of valid status codes?
142 // Does it exactly match the expected status code?
143 if (logger.isDebugEnabled()) {
144 logger.debug(testName + ": status = " + statusCode);
146 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
147 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
148 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
150 // Store the ID returned from the first resource created
151 // for additional tests below.
152 if (knownResourceId == null) {
153 setKnownResource(extractId(res), identifier,
154 VocabularyClientUtils.createVocabularyRefName(identifier, null),
155 VocabularyClientUtils.createVocabularyRefName(identifier, displayName));
156 if (logger.isDebugEnabled()) {
157 logger.debug(testName + ": knownResourceId=" + knownResourceId);
160 // Store the IDs from every resource created by tests,
161 // so they can be deleted after tests have been run.
162 allResourceIdsCreated.add(extractId(res));
167 protected PoxPayloadOut createItemInstance(String parentCsid, String identifier) {
168 String headerLabel = new VocabularyClient().getItemCommonPartName();
169 HashMap<String, String> vocabItemInfo = new HashMap<String, String>();
170 String shortId = createIdentifier();
171 vocabItemInfo.put(AuthorityItemJAXBSchema.SHORT_IDENTIFIER, shortId);
172 vocabItemInfo.put(AuthorityItemJAXBSchema.DISPLAY_NAME, "display-" + shortId);
174 return VocabularyClientUtils.createVocabularyItemInstance(identifier, vocabItemInfo, headerLabel);
177 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
178 dependsOnMethods = {"create"})
179 public void createItem(String testName) {
181 if (null != testName && logger.isDebugEnabled()) {
182 logger.debug(testBanner(testName, CLASS_NAME));
187 VocabularyClient client = new VocabularyClient();
188 HashMap<String, String> itemInfo = new HashMap<String, String>();
189 String shortId = createIdentifier();
190 itemInfo.put(AuthorityItemJAXBSchema.SHORT_IDENTIFIER, shortId);
191 itemInfo.put(AuthorityItemJAXBSchema.DISPLAY_NAME, "display-" + shortId);
192 String newID = VocabularyClientUtils.createItemInVocabulary(knownResourceId,
193 knownResourceRefName, itemInfo, client);
195 // Store the ID returned from the first item resource created
196 // for additional tests below.
197 if (knownItemResourceId == null) {
198 knownItemResourceId = newID;
199 if (null != testName && logger.isDebugEnabled()) {
200 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
203 // Store the IDs from any item resources created
204 // by tests, along with the IDs of their parents, so these items
205 // can be deleted after all tests have been run.
206 allResourceItemIdsCreated.put(newID, knownResourceId);
210 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
211 dependsOnMethods = {"create", "createItem", "readItem"})
212 public void createList(String testName) throws Exception {
213 for (int i = 0; i < 3; i++) {
214 // Force create to reset the known resource info
215 setKnownResource(null, null, null, null);
216 knownItemResourceId = null;
218 // Add nItemsToCreateInList items to each vocab
219 for (int j = 0; j < nItemsToCreateInList; j++) {
226 // Placeholders until the three tests below can be uncommented.
227 // See Issue CSPACE-401.
229 public void createWithEmptyEntityBody(String testName) throws Exception {
233 public void createWithMalformedXml(String testName) throws Exception {
237 public void createWithWrongXmlSchema(String testName) throws Exception {
240 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
241 dependsOnMethods = {"create"})
242 public void createWithBadShortId(String testName) throws Exception {
244 if (logger.isDebugEnabled()) {
245 logger.debug(testBanner(testName, CLASS_NAME));
247 testSetup(STATUS_BAD_REQUEST, ServiceRequestType.CREATE);
249 // Submit the request to the service and store the response.
250 VocabularyClient client = new VocabularyClient();
251 PoxPayloadOut multipart = VocabularyClientUtils.createEnumerationInstance(
252 "Vocab with Bad Short Id", "Bad Short Id!", client.getCommonPartName());
253 ClientResponse<Response> res = client.create(multipart);
254 int statusCode = res.getStatus();
256 // Check the status code of the response: does it match
257 // the expected response(s)?
260 // Does it fall within the set of valid status codes?
261 // Does it exactly match the expected status code?
262 if (logger.isDebugEnabled()) {
263 logger.debug(testName + ": status = " + statusCode);
265 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
266 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
267 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
270 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
271 dependsOnMethods = {"createItem"})
272 public void createItemWithBadShortId(String testName) throws Exception {
274 if (logger.isDebugEnabled()) {
275 logger.debug(testBanner(testName, CLASS_NAME));
277 setupCreateWithMalformedXml();
279 // Submit the request to the service and store the response.
280 VocabularyClient client = new VocabularyClient();
281 HashMap<String, String> itemInfo = new HashMap<String, String>();
282 itemInfo.put(AuthorityItemJAXBSchema.SHORT_IDENTIFIER, "Bad Item Short Id!");
283 itemInfo.put(AuthorityItemJAXBSchema.DISPLAY_NAME, "Bad Item!");
284 PoxPayloadOut multipart =
285 VocabularyClientUtils.createVocabularyItemInstance(knownResourceRefName,
286 itemInfo, client.getCommonPartItemName());
287 ClientResponse<Response> res = client.createItem(knownResourceId, multipart);
289 int statusCode = res.getStatus();
291 if (!REQUEST_TYPE.isValidStatusCode(statusCode)) {
292 throw new RuntimeException("Could not create Item: \"" + itemInfo.get(AuthorityItemJAXBSchema.DISPLAY_NAME)
293 + "\" in personAuthority: \"" + knownResourceRefName
294 + "\" " + invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
296 if (statusCode != EXPECTED_STATUS_CODE) {
297 throw new RuntimeException("Unexpected Status when creating Item: \"" + itemInfo.get(AuthorityItemJAXBSchema.DISPLAY_NAME)
298 + "\" in personAuthority: \"" + knownResourceRefName + "\", Status:" + statusCode);
304 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
305 dependsOnMethods = {"create", "testSubmitRequest"})
306 public void createWithEmptyEntityBody(String testName) throws Exception {
308 if (logger.isDebugEnabled()) {
309 logger.debug(testBanner(testName, CLASS_NAME));
312 setupCreateWithEmptyEntityBody(testName, CLASS_NAME);
314 // Submit the request to the service and store the response.
315 String method = REQUEST_TYPE.httpMethodName();
316 String url = getServiceRootURL();
317 String mediaType = MediaType.APPLICATION_XML;
318 final String entity = "";
319 int statusCode = submitRequest(method, url, mediaType, entity);
321 // Check the status code of the response: does it match
322 // the expected response(s)?
323 if(logger.isDebugEnabled()) {
324 logger.debug(testName + ": url=" + url +
325 " status=" + statusCode);
327 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
328 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
329 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
333 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
334 dependsOnMethods = {"create", "testSubmitRequest"})
335 public void createWithMalformedXml(String testName) throws Exception {
337 if (logger.isDebugEnabled()) {
338 logger.debug(testBanner(testName, CLASS_NAME));
341 setupCreateWithMalformedXml();
343 // Submit the request to the service and store the response.
344 String method = REQUEST_TYPE.httpMethodName();
345 String url = getServiceRootURL();
346 String mediaType = MediaType.APPLICATION_XML;
347 final String entity = MALFORMED_XML_DATA; // Constant from base class.
348 int statusCode = submitRequest(method, url, mediaType, entity);
350 // Check the status code of the response: does it match
351 // the expected response(s)?
352 if(logger.isDebugEnabled()){
353 logger.debug(testName + ": url=" + url +
354 " status=" + statusCode);
356 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
357 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
358 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
362 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
363 dependsOnMethods = {"create", "testSubmitRequest"})
364 public void createWithWrongXmlSchema(String testName) throws Exception {
366 if (logger.isDebugEnabled()) {
367 logger.debug(testBanner(testName, CLASS_NAME));
370 setupCreateWithWrongXmlSchema();
372 // Submit the request to the service and store the response.
373 String method = REQUEST_TYPE.httpMethodName();
374 String url = getServiceRootURL();
375 String mediaType = MediaType.APPLICATION_XML;
376 final String entity = WRONG_XML_SCHEMA_DATA;
377 int statusCode = submitRequest(method, url, mediaType, entity);
379 // Check the status code of the response: does it match
380 // the expected response(s)?
381 if(logger.isDebugEnabled()){
382 logger.debug(testName + ": url=" + url +
383 " status=" + statusCode);
385 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
386 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
387 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
390 // ---------------------------------------------------------------
391 // CRUD tests : READ tests
392 // ---------------------------------------------------------------
395 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
396 dependsOnMethods = {"create"})
397 public void read(String testName) throws Exception {
399 if (logger.isDebugEnabled()) {
400 logger.debug(testBanner(testName, CLASS_NAME));
405 // Submit the request to the service and store the response.
406 VocabularyClient client = new VocabularyClient();
407 ClientResponse<String> res = client.read(knownResourceId);
408 int statusCode = res.getStatus();
410 // Check the status code of the response: does it match
411 // the expected response(s)?
412 if (logger.isDebugEnabled()) {
413 logger.debug(testName + ": status = " + statusCode);
415 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
416 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
417 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
418 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
419 VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input,
420 client.getCommonPartName(), VocabulariesCommon.class);
422 Assert.assertNotNull(vocabulary);
423 Assert.assertEquals(vocabulary.getRefName(), knownResourceFullRefName);
429 * @param testName the test name
430 * @throws Exception the exception
432 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
433 dependsOnMethods = {"read"})
434 public void readByName(String testName) throws Exception {
436 if (logger.isDebugEnabled()) {
437 logger.debug(testBanner(testName, CLASS_NAME));
442 // Submit the request to the service and store the response.
443 VocabularyClient client = new VocabularyClient();
444 ClientResponse<String> res = client.readByName(knownResourceShortIdentifer);
445 int statusCode = res.getStatus();
447 // Check the status code of the response: does it match
448 // the expected response(s)?
449 if (logger.isDebugEnabled()) {
450 logger.debug(testName + ": status = " + statusCode);
452 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
453 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
454 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
455 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
456 VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input,
457 client.getCommonPartName(), VocabulariesCommon.class);
459 Assert.assertNotNull(vocabulary);
463 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
464 dependsOnMethods = {"read"})
465 public void readByName(String testName) throws Exception {
467 if (logger.isDebugEnabled()) {
468 logger.debug(testBanner(testName, CLASS_NAME));
473 // Submit the request to the service and store the response.
474 ClientResponse<PoxPayloadIn> res = client.read(knownResourceId);
475 int statusCode = res.getStatus();
477 // Check the status code of the response: does it match
478 // the expected response(s)?
479 if(logger.isDebugEnabled()){
480 logger.debug(testName + ": status = " + statusCode);
482 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
483 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
484 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
485 //FIXME: remove the following try catch once Aron fixes signatures
487 PoxPayloadIn input = (PoxPayloadIn) res.getEntity();
488 VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input,
489 client.getCommonPartName(), VocabulariesCommon.class);
490 Assert.assertNotNull(vocabulary);
491 } catch (Exception e) {
492 throw new RuntimeException(e);
496 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
497 dependsOnMethods = {"createItem", "read"})
498 public void readItem(String testName) throws Exception {
500 if (logger.isDebugEnabled()) {
501 logger.debug(testBanner(testName, CLASS_NAME));
506 // Submit the request to the service and store the response.
507 VocabularyClient client = new VocabularyClient();
508 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
509 int statusCode = res.getStatus();
511 // Check the status code of the response: does it match
512 // the expected response(s)?
513 if (logger.isDebugEnabled()) {
514 logger.debug(testName + ": status = " + statusCode);
516 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
517 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
518 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
520 // Check whether we've received a vocabulary item.
521 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
522 VocabularyitemsCommon vocabularyItem = (VocabularyitemsCommon) extractPart(input,
523 client.getCommonPartItemName(), VocabularyitemsCommon.class);
524 Assert.assertNotNull(vocabularyItem);
525 Assert.assertEquals(vocabularyItem.getInAuthority(), knownResourceId);
529 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
530 dependsOnMethods = {"updateItem"})
531 public void verifyIllegalItemDisplayName(String testName) throws Exception {
533 if (logger.isDebugEnabled()) {
534 logger.debug(testBanner(testName, CLASS_NAME));
537 testSetup(STATUS_BAD_REQUEST, ServiceRequestType.UPDATE);
538 // setupUpdateWithWrongXmlSchema(testName);
540 // Submit the request to the service and store the response.
541 VocabularyClient client = new VocabularyClient();
542 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
543 int statusCode = res.getStatus();
545 // Check the status code of the response: does it match
546 // the expected response(s)?
547 if (logger.isDebugEnabled()) {
548 logger.debug(testName + ": status = " + statusCode);
550 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
551 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
552 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
554 // Check whether Person has expected displayName.
555 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
556 VocabularyitemsCommon vitem = (VocabularyitemsCommon) extractPart(input,
557 client.getCommonPartItemName(), VocabularyitemsCommon.class);
558 Assert.assertNotNull(vitem);
559 // Try to Update with null displayName
560 vitem.setDisplayName(null);
562 // Submit the updated resource to the service and store the response.
563 PoxPayloadOut output = new PoxPayloadOut(SERVICE_ITEM_PAYLOAD_NAME);
564 PayloadOutputPart commonPart = output.addPart(vitem, MediaType.APPLICATION_XML_TYPE);
565 commonPart.setLabel(client.getCommonPartItemName());
566 res = client.updateItem(knownResourceId, knownItemResourceId, output);
567 statusCode = res.getStatus();
569 // Check the status code of the response: does it match the expected response(s)?
570 if (logger.isDebugEnabled()) {
571 logger.debug("updateItem: status = " + statusCode);
573 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
574 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
575 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE,
576 "Expecting invalid message because of null displayName.");
578 // Now try to Update with 1-char displayName (too short)
579 vitem.setDisplayName("a");
581 // Submit the updated resource to the service and store the response.
582 output = new PoxPayloadOut(SERVICE_ITEM_PAYLOAD_NAME);
583 commonPart = output.addPart(vitem, MediaType.APPLICATION_XML_TYPE);
584 commonPart.setLabel(client.getCommonPartItemName());
585 res = client.updateItem(knownResourceId, knownItemResourceId, output);
586 statusCode = res.getStatus();
588 // Check the status code of the response: does it match the expected response(s)?
589 if (logger.isDebugEnabled()) {
590 logger.debug("updateItem: status = " + statusCode);
592 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
593 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
594 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE,
595 "Expecting invalid message because of 1-char displayName.");
599 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
600 dependsOnMethods = {"read"})
601 public void readNonExistent(String testName) {
603 if (logger.isDebugEnabled()) {
604 logger.debug(testBanner(testName, CLASS_NAME));
607 setupReadNonExistent();
609 // Submit the request to the service and store the response.
610 VocabularyClient client = new VocabularyClient();
611 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
612 int statusCode = res.getStatus();
614 // Check the status code of the response: does it match
615 // the expected response(s)?
616 if (logger.isDebugEnabled()) {
617 logger.debug(testName + ": status = " + statusCode);
619 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
620 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
621 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
624 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
625 dependsOnMethods = {"readItem", "readNonExistent"})
626 public void readItemNonExistent(String testName) {
628 if (logger.isDebugEnabled()) {
629 logger.debug(testBanner(testName, CLASS_NAME));
632 setupReadNonExistent();
634 // Submit the request to the service and store the response.
635 VocabularyClient client = new VocabularyClient();
636 ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
637 int statusCode = res.getStatus();
639 // Check the status code of the response: does it match
640 // the expected response(s)?
641 if (logger.isDebugEnabled()) {
642 logger.debug(testName + ": status = " + statusCode);
644 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
645 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
646 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
648 // ---------------------------------------------------------------
649 // CRUD tests : READ_LIST tests
650 // ---------------------------------------------------------------
654 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
655 dependsOnMethods = {"createList", "read"})
656 public void readList(String testName) throws Exception {
658 if (logger.isDebugEnabled()) {
659 logger.debug(testBanner(testName, CLASS_NAME));
664 // Submit the request to the service and store the response.
665 VocabularyClient client = new VocabularyClient();
666 ClientResponse<VocabulariesCommonList> res = client.readList();
667 VocabulariesCommonList list = res.getEntity();
668 int statusCode = res.getStatus();
670 // Check the status code of the response: does it match
671 // the expected response(s)?
672 if (logger.isDebugEnabled()) {
673 logger.debug(testName + ": status = " + statusCode);
675 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
676 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
677 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
679 // Optionally output additional data about list members for debugging.
680 boolean iterateThroughList = false;
681 if (iterateThroughList && logger.isDebugEnabled()) {
682 List<VocabulariesCommonList.VocabularyListItem> items =
683 list.getVocabularyListItem();
685 for (VocabulariesCommonList.VocabularyListItem item : items) {
686 String csid = item.getCsid();
687 logger.debug(testName + ": list-item[" + i + "] csid="
689 logger.debug(testName + ": list-item[" + i + "] displayName="
690 + item.getDisplayName());
691 logger.debug(testName + ": list-item[" + i + "] URI="
693 readItemListInt(csid, null, "readList");
699 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
700 dependsOnMethods = {"createList", "readItem"})
701 public void readItemList(String testName) {
702 readItemListInt(knownResourceId, null, testName);
705 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
706 dependsOnMethods = {"createList", "readItem"})
707 public void readItemListByName(String testName) {
708 readItemListInt(null, knownResourceShortIdentifer, testName);
711 private void readItemListInt(String vcsid, String shortId, String testName) {
716 // Submit the request to the service and store the response.
717 VocabularyClient client = new VocabularyClient();
718 ClientResponse<VocabularyitemsCommonList> res = null;
720 res = client.readItemList(vcsid, null, null);
721 } else if (shortId != null) {
722 res = client.readItemListForNamedAuthority(shortId, null, null);
724 Assert.fail("Internal Error: readItemList both vcsid and shortId are null!");
726 VocabularyitemsCommonList list = res.getEntity();
727 int statusCode = res.getStatus();
729 // Check the status code of the response: does it match
730 // the expected response(s)?
731 if (logger.isDebugEnabled()) {
732 logger.debug(" " + testName + ": status = " + statusCode);
734 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
735 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
736 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
738 List<VocabularyitemsCommonList.VocabularyitemListItem> items =
739 list.getVocabularyitemListItem();
740 int nItemsReturned = items.size();
741 long nItemsTotal = list.getTotalItems();
742 if (logger.isDebugEnabled()) {
743 logger.debug(" " + testName + ": Expected "
744 + nItemsToCreateInList + " items; got: " + nItemsReturned + " of: " + nItemsTotal);
746 Assert.assertEquals(nItemsTotal, nItemsToCreateInList);
748 // Optionally output additional data about list members for debugging.
749 boolean iterateThroughList = true;
750 if (iterateThroughList && logger.isDebugEnabled()) {
751 logger.debug(" " + testName + ": checking items");
753 for (VocabularyitemsCommonList.VocabularyitemListItem item : items) {
754 logger.debug(" " + testName + ": list-item[" + i + "] csid="
756 logger.debug(" " + testName + ": list-item[" + i + "] displayName="
757 + item.getDisplayName());
758 logger.debug(" " + testName + ": list-item[" + i + "] URI="
767 // ---------------------------------------------------------------
768 // CRUD tests : UPDATE tests
769 // ---------------------------------------------------------------
772 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
773 dependsOnMethods = {"read"})
774 public void update(String testName) throws Exception {
776 if (logger.isDebugEnabled()) {
777 logger.debug(testBanner(testName, CLASS_NAME));
782 // Retrieve the contents of a resource to update.
783 VocabularyClient client = new VocabularyClient();
784 ClientResponse<String> res =
785 client.read(knownResourceId);
786 if (logger.isDebugEnabled()) {
787 logger.debug(testName + ": read status = " + res.getStatus());
789 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
791 if (logger.isDebugEnabled()) {
792 logger.debug("got Vocabulary to update with ID: " + knownResourceId);
794 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
795 VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input,
796 client.getCommonPartName(), VocabulariesCommon.class);
797 Assert.assertNotNull(vocabulary);
799 // Update the contents of this resource.
800 vocabulary.setDisplayName("updated-" + vocabulary.getDisplayName());
801 vocabulary.setVocabType("updated-" + vocabulary.getVocabType());
802 if (logger.isDebugEnabled()) {
803 logger.debug("to be updated Vocabulary");
804 logger.debug(objectAsXmlString(vocabulary, VocabulariesCommon.class));
807 // Submit the updated resource to the service and store the response.
808 PoxPayloadOut output = new PoxPayloadOut(SERVICE_PAYLOAD_NAME);
810 PayloadOutputPart commonPart = output.addPart(vocabulary, MediaType.APPLICATION_XML_TYPE);
811 commonPart.setLabel(client.getCommonPartName());
812 res = client.update(knownResourceId, output);
813 int statusCode = res.getStatus();
815 // Check the status code of the response: does it match the expected response(s)?
816 if (logger.isDebugEnabled()) {
817 logger.debug("update: status = " + statusCode);
819 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
820 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
821 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
823 // Retrieve the updated resource and verify that its contents exist.
824 input = new PoxPayloadIn(res.getEntity());
825 VocabulariesCommon updatedVocabulary =
826 (VocabulariesCommon) extractPart(input,
827 client.getCommonPartName(), VocabulariesCommon.class);
828 Assert.assertNotNull(updatedVocabulary);
830 // Verify that the updated resource received the correct data.
831 Assert.assertEquals(updatedVocabulary.getDisplayName(),
832 vocabulary.getDisplayName(),
833 "Data in updated object did not match submitted data.");
836 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
837 dependsOnMethods = {"readItem", "update", "verifyIgnoredUpdateWithInAuthority"})
838 public void updateItem(String testName) throws Exception {
840 if (logger.isDebugEnabled()) {
841 logger.debug(testBanner(testName, CLASS_NAME));
846 // Retrieve the contents of a resource to update.
847 VocabularyClient client = new VocabularyClient();
848 ClientResponse<String> res =
849 client.readItem(knownResourceId, knownItemResourceId);
850 if (logger.isDebugEnabled()) {
851 logger.debug(testName + ": read status = " + res.getStatus());
853 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
855 if (logger.isDebugEnabled()) {
856 logger.debug("got VocabularyItem to update with ID: "
857 + knownItemResourceId
858 + " in Vocab: " + knownResourceId);
860 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
861 VocabularyitemsCommon vocabularyItem = (VocabularyitemsCommon) extractPart(input,
862 client.getCommonPartItemName(), VocabularyitemsCommon.class);
863 Assert.assertNotNull(vocabularyItem);
865 // Update the contents of this resource.
866 vocabularyItem.setDisplayName("updated-" + vocabularyItem.getDisplayName());
867 if (logger.isDebugEnabled()) {
868 logger.debug("to be updated VocabularyItem");
869 logger.debug(objectAsXmlString(vocabularyItem,
870 VocabularyitemsCommon.class));
873 // Submit the updated resource to the service and store the response.
874 PoxPayloadOut output = new PoxPayloadOut(SERVICE_ITEM_PAYLOAD_NAME);
875 PayloadOutputPart commonPart = output.addPart(vocabularyItem, MediaType.APPLICATION_XML_TYPE);
876 commonPart.setLabel(client.getCommonPartItemName());
877 res = client.updateItem(knownResourceId, knownItemResourceId, output);
878 int statusCode = res.getStatus();
880 // Check the status code of the response: does it match the expected response(s)?
881 if (logger.isDebugEnabled()) {
882 logger.debug("updateItem: status = " + statusCode);
884 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
885 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
886 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
888 // Retrieve the updated resource and verify that its contents exist.
889 input = new PoxPayloadIn(res.getEntity());
890 VocabularyitemsCommon updatedVocabularyItem =
891 (VocabularyitemsCommon) extractPart(input,
892 client.getCommonPartItemName(), VocabularyitemsCommon.class);
893 Assert.assertNotNull(updatedVocabularyItem);
895 // Verify that the updated resource received the correct data.
896 Assert.assertEquals(updatedVocabularyItem.getDisplayName(),
897 vocabularyItem.getDisplayName(),
898 "Data in updated VocabularyItem did not match submitted data.");
901 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
902 dependsOnMethods = {"readItem"})
903 public void verifyIgnoredUpdateWithInAuthority(String testName) throws Exception {
905 if (logger.isDebugEnabled()) {
906 logger.debug(testBanner(testName, CLASS_NAME));
911 // Submit the request to the service and store the response.
912 VocabularyClient client = new VocabularyClient();
913 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
914 int statusCode = res.getStatus();
916 // Check the status code of the response: does it match
917 // the expected response(s)?
918 if (logger.isDebugEnabled()) {
919 logger.debug(testName + " read Vocab:" + knownResourceId + "/Item:"
920 + knownItemResourceId + " status = " + statusCode);
922 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
923 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
924 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
926 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
927 VocabularyitemsCommon vitem = (VocabularyitemsCommon) extractPart(input,
928 client.getCommonPartItemName(), VocabularyitemsCommon.class);
929 Assert.assertNotNull(vitem);
930 // Try to Update with new parent vocab (use self, for test).
931 Assert.assertEquals(vitem.getInAuthority(),
933 "VocabularyItem inAuthority does not match knownResourceId.");
934 vitem.setInAuthority(knownItemResourceId);
936 // Submit the updated resource to the service and store the response.
937 PoxPayloadOut output = new PoxPayloadOut(SERVICE_ITEM_PAYLOAD_NAME);
938 PayloadOutputPart commonPart = output.addPart(vitem, MediaType.APPLICATION_XML_TYPE);
939 commonPart.setLabel(client.getCommonPartItemName());
940 res = client.updateItem(knownResourceId, knownItemResourceId, output);
941 statusCode = res.getStatus();
943 // Check the status code of the response: does it match the expected response(s)?
944 if (logger.isDebugEnabled()) {
945 logger.debug(testName + ": status = " + statusCode);
947 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
948 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
949 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
951 // Retrieve the updated resource and verify that the parent did not change
952 res = client.readItem(knownResourceId, knownItemResourceId);
953 input = new PoxPayloadIn(res.getEntity());
954 VocabularyitemsCommon updatedVocabularyItem =
955 (VocabularyitemsCommon) extractPart(input,
956 client.getCommonPartItemName(), VocabularyitemsCommon.class);
957 Assert.assertNotNull(updatedVocabularyItem);
959 // Verify that the updated resource received the correct data.
960 Assert.assertEquals(updatedVocabularyItem.getInAuthority(),
962 "VocabularyItem allowed update to the parent (inAuthority).");
966 // Placeholders until the three tests below can be uncommented.
967 // See Issue CSPACE-401.
969 public void updateWithEmptyEntityBody(String testName) throws Exception {
973 public void updateWithMalformedXml(String testName) throws Exception {
977 public void updateWithWrongXmlSchema(String testName) throws Exception {
982 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
983 dependsOnMethods = {"create", "update", "testSubmitRequest"})
984 public void updateWithEmptyEntityBody(String testName) throws Exception {
986 if (logger.isDebugEnabled()) {
987 logger.debug(testBanner(testName, CLASS_NAME));
990 setupUpdateWithEmptyEntityBody();
992 // Submit the request to the service and store the response.
993 String method = REQUEST_TYPE.httpMethodName();
994 String url = getResourceURL(knownResourceId);
995 String mediaType = MediaType.APPLICATION_XML;
996 final String entity = "";
997 int statusCode = submitRequest(method, url, mediaType, entity);
999 // Check the status code of the response: does it match
1000 // the expected response(s)?
1001 if(logger.isDebugEnabled()){
1002 logger.debug(testName + ": url=" + url +
1003 " status=" + statusCode);
1005 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1006 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1007 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1011 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1012 dependsOnMethods = {"create", "update", "testSubmitRequest"})
1013 public void updateWithMalformedXml(String testName) throws Exception {
1015 if (logger.isDebugEnabled()) {
1016 logger.debug(testBanner(testName, CLASS_NAME));
1019 setupUpdateWithMalformedXml();
1021 // Submit the request to the service and store the response.
1022 String method = REQUEST_TYPE.httpMethodName();
1023 String url = getResourceURL(knownResourceId);
1024 String mediaType = MediaType.APPLICATION_XML;
1025 final String entity = MALFORMED_XML_DATA;
1026 int statusCode = submitRequest(method, url, mediaType, entity);
1028 // Check the status code of the response: does it match
1029 // the expected response(s)?
1030 if(logger.isDebugEnabled()){
1031 logger.debug(testName + ": url=" + url +
1032 " status=" + statusCode);
1034 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1035 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1036 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1040 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1041 dependsOnMethods = {"create", "update", "testSubmitRequest"})
1042 public void updateWithWrongXmlSchema(String testName) throws Exception {
1044 if (logger.isDebugEnabled()) {
1045 logger.debug(testBanner(testName, CLASS_NAME));
1048 setupUpdateWithWrongXmlSchema();
1050 // Submit the request to the service and store the response.
1051 String method = REQUEST_TYPE.httpMethodName();
1052 String url = getResourceURL(knownResourceId);
1053 String mediaType = MediaType.APPLICATION_XML;
1054 final String entity = WRONG_XML_SCHEMA_DATA;
1055 int statusCode = submitRequest(method, url, mediaType, entity);
1057 // Check the status code of the response: does it match
1058 // the expected response(s)?
1059 if(logger.isDebugEnabled()){
1060 logger.debug("updateWithWrongXmlSchema: url=" + url +
1061 " status=" + statusCode);
1063 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1064 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1065 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1069 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1070 dependsOnMethods = {"update", "testSubmitRequest"})
1071 public void updateNonExistent(String testName) throws Exception {
1073 if (logger.isDebugEnabled()) {
1074 logger.debug(testBanner(testName, CLASS_NAME));
1077 setupUpdateNonExistent();
1079 // Submit the request to the service and store the response.
1080 // Note: The ID used in this 'create' call may be arbitrary.
1081 // The only relevant ID may be the one used in update(), below.
1082 VocabularyClient client = new VocabularyClient();
1083 String displayName = "displayName-" + NON_EXISTENT_ID;
1084 PoxPayloadOut multipart = VocabularyClientUtils.createEnumerationInstance(
1085 displayName, NON_EXISTENT_ID, client.getCommonPartName());
1086 ClientResponse<String> res =
1087 client.update(NON_EXISTENT_ID, multipart);
1088 int statusCode = res.getStatus();
1090 // Check the status code of the response: does it match
1091 // the expected response(s)?
1092 if (logger.isDebugEnabled()) {
1093 logger.debug(testName + ": status = " + statusCode);
1095 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1096 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1097 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1100 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1101 dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1102 public void updateNonExistentItem(String testName) throws Exception {
1104 if (logger.isDebugEnabled()) {
1105 logger.debug(testBanner(testName, CLASS_NAME));
1108 setupUpdateNonExistent();
1110 // Submit the request to the service and store the response.
1111 // Note: The ID used in this 'create' call may be arbitrary.
1112 // The only relevant ID may be the one used in update(), below.
1113 VocabularyClient client = new VocabularyClient();
1114 HashMap<String, String> itemInfo = new HashMap<String, String>();
1115 itemInfo.put(AuthorityItemJAXBSchema.SHORT_IDENTIFIER, "nonex");
1116 itemInfo.put(AuthorityItemJAXBSchema.DISPLAY_NAME, "display-nonex");
1117 PoxPayloadOut multipart =
1118 VocabularyClientUtils.createVocabularyItemInstance(
1119 VocabularyClientUtils.createVocabularyRefName(NON_EXISTENT_ID, null),
1120 itemInfo, client.getCommonPartItemName());
1121 ClientResponse<String> res =
1122 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1123 int statusCode = res.getStatus();
1125 // Check the status code of the response: does it match
1126 // the expected response(s)?
1127 if (logger.isDebugEnabled()) {
1128 logger.debug(testName + ": status = " + statusCode);
1130 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1131 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1132 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1135 // ---------------------------------------------------------------
1136 // CRUD tests : DELETE tests
1137 // ---------------------------------------------------------------
1140 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1141 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update", "deleteItem"})
1142 public void delete(String testName) throws Exception {
1144 if (logger.isDebugEnabled()) {
1145 logger.debug(testBanner(testName, CLASS_NAME));
1150 // Submit the request to the service and store the response.
1151 VocabularyClient client = new VocabularyClient();
1152 ClientResponse<Response> res = client.delete(knownResourceId);
1153 int statusCode = res.getStatus();
1155 // Check the status code of the response: does it match
1156 // the expected response(s)?
1157 if (logger.isDebugEnabled()) {
1158 logger.debug(testName + ": status = " + statusCode);
1160 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1161 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1162 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1165 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1166 dependsOnMethods = {"createItem", "readItemList", "testItemSubmitRequest",
1167 "updateItem", "verifyIllegalItemDisplayName", "verifyIgnoredUpdateWithInAuthority"})
1168 public void deleteItem(String testName) throws Exception {
1170 if (logger.isDebugEnabled()) {
1171 logger.debug(testBanner(testName, CLASS_NAME));
1176 // Submit the request to the service and store the response.
1177 VocabularyClient client = new VocabularyClient();
1178 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1179 int statusCode = res.getStatus();
1181 // Check the status code of the response: does it match
1182 // the expected response(s)?
1183 if (logger.isDebugEnabled()) {
1184 logger.debug("delete: status = " + statusCode);
1186 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1187 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1188 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1193 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1194 dependsOnMethods = {"delete"})
1195 public void deleteNonExistent(String testName) throws Exception {
1197 if (logger.isDebugEnabled()) {
1198 logger.debug(testBanner(testName, CLASS_NAME));
1201 setupDeleteNonExistent();
1203 // Submit the request to the service and store the response.
1204 VocabularyClient client = new VocabularyClient();
1205 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1206 int statusCode = res.getStatus();
1208 // Check the status code of the response: does it match
1209 // the expected response(s)?
1210 if (logger.isDebugEnabled()) {
1211 logger.debug(testName + ": status = " + statusCode);
1213 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1214 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1215 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1218 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1219 dependsOnMethods = {"deleteItem"})
1220 public void deleteNonExistentItem(String testName) {
1222 if (logger.isDebugEnabled()) {
1223 logger.debug(testBanner(testName, CLASS_NAME));
1226 setupDeleteNonExistent();
1228 // Submit the request to the service and store the response.
1229 VocabularyClient client = new VocabularyClient();
1230 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1231 int statusCode = res.getStatus();
1233 // Check the status code of the response: does it match
1234 // the expected response(s)?
1235 if (logger.isDebugEnabled()) {
1236 logger.debug(testName + ": status = " + statusCode);
1238 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1239 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1240 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1243 // ---------------------------------------------------------------
1244 // Utility tests : tests of code used in tests above
1245 // ---------------------------------------------------------------
1247 * Tests the code for manually submitting data that is used by several
1248 * of the methods above.
1250 @Test(dependsOnMethods = {"create", "read"})
1251 public void testSubmitRequest() {
1253 // Expected status code: 200 OK
1256 // Submit the request to the service and store the response.
1257 String method = ServiceRequestType.READ.httpMethodName();
1258 String url = getResourceURL(knownResourceId);
1259 int statusCode = submitRequest(method, url);
1261 // Check the status code of the response: does it match
1262 // the expected response(s)?
1263 if (logger.isDebugEnabled()) {
1264 logger.debug("testSubmitRequest: url=" + url
1265 + " status=" + statusCode);
1267 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1271 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1272 public void testItemSubmitRequest() {
1274 // Expected status code: 200 OK
1275 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1277 // Submit the request to the service and store the response.
1278 String method = ServiceRequestType.READ.httpMethodName();
1279 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1280 int statusCode = submitRequest(method, url);
1282 // Check the status code of the response: does it match
1283 // the expected response(s)?
1284 if (logger.isDebugEnabled()) {
1285 logger.debug("testItemSubmitRequest: url=" + url
1286 + " status=" + statusCode);
1288 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1292 // ---------------------------------------------------------------
1293 // Cleanup of resources created during testing
1294 // ---------------------------------------------------------------
1296 * Deletes all resources created by tests, after all tests have been run.
1298 * This cleanup method will always be run, even if one or more tests fail.
1299 * For this reason, it attempts to remove all resources created
1300 * at any point during testing, even if some of those resources
1301 * may be expected to be deleted by certain tests.
1303 // @AfterClass(alwaysRun = true)
1304 // public void cleanUp() {
1305 // String noTest = System.getProperty("noTestCleanup");
1306 // if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1307 // if (logger.isDebugEnabled()) {
1308 // logger.debug("Skipping Cleanup phase ...");
1312 // if (logger.isDebugEnabled()) {
1313 // logger.debug("Cleaning up temporary resources created for testing ...");
1315 // VocabularyClient client = new VocabularyClient();
1316 // String vocabularyResourceId;
1317 // String vocabularyItemResourceId;
1318 // // Clean up vocabulary item resources.
1319 // for (Map.Entry<String, String> entry : allResourceItemIdsCreated.entrySet()) {
1320 // vocabularyItemResourceId = entry.getKey();
1321 // vocabularyResourceId = entry.getValue();
1322 // // Note: Any non-success responses are ignored and not reported.
1323 // client.deleteItem(vocabularyResourceId, vocabularyItemResourceId).releaseConnection();
1325 // // Clean up vocabulary resources.
1326 // for (String resourceId : allResourceIdsCreated) {
1327 // // Note: Any non-success responses are ignored and not reported.
1328 // client.delete(resourceId).releaseConnection();
1333 // ---------------------------------------------------------------
1334 // Utility methods used by tests above
1335 // ---------------------------------------------------------------
1337 public String getServicePathComponent() {
1338 return SERVICE_PATH_COMPONENT;
1341 public String getServicePathItemsComponent() {
1342 return this.SERVICE_PATH_ITEMS_COMPONENT;
1346 * Returns the root URL for a service.
1348 * This URL consists of a base URL for all services, followed by
1349 * a path component for the owning vocabulary, followed by the
1350 * path component for the items.
1352 * @return The root URL for a service.
1354 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1355 return getResourceURL(parentResourceIdentifier) + "/" + getServicePathItemsComponent();
1359 * Returns the URL of a specific resource managed by a service, and
1360 * designated by an identifier (such as a universally unique ID, or UUID).
1362 * @param resourceIdentifier An identifier (such as a UUID) for a resource.
1364 * @return The URL of a specific resource managed by a service.
1366 protected String getItemResourceURL(String parentResourceIdentifier, String resourceIdentifier) {
1367 return getItemServiceRootURL(parentResourceIdentifier) + "/" + resourceIdentifier;
1371 protected String getServiceName() {
1372 return VocabularyClient.SERVICE_NAME;