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.client.AuthorityClient;
33 import org.collectionspace.services.common.AbstractCommonListUtils;
34 import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
35 import org.collectionspace.services.client.CollectionSpaceClient;
36 import org.collectionspace.services.client.PayloadOutputPart;
37 import org.collectionspace.services.client.PoxPayloadIn;
38 import org.collectionspace.services.client.PoxPayloadOut;
39 import org.collectionspace.services.client.VocabularyClient;
40 import org.collectionspace.services.client.VocabularyClientUtils;
41 import org.collectionspace.services.jaxb.AbstractCommonList;
42 import org.collectionspace.services.vocabulary.VocabulariesCommon;
43 import org.collectionspace.services.vocabulary.VocabularyitemsCommon;
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_PAYLOAD_NAME = VocabularyClient.SERVICE_PAYLOAD_NAME;
66 final String SERVICE_ITEM_PAYLOAD_NAME = VocabularyClient.SERVICE_ITEM_PAYLOAD_NAME;
67 private String knownResourceId = null;
68 private String knownResourceShortIdentifer = null;
69 //private String knownResourceRefName = null;
70 //private String knownResourceFullRefName = null;
71 private String knownItemResourceId = null;
72 private int nItemsToCreateInList = 5;
73 // private List<String> allResourceIdsCreated = new ArrayList<String>();
74 // private Map<String, String> allResourceItemIdsCreated =
75 // new HashMap<String, String>();
77 protected void setKnownResource(String id, String shortIdentifer,
78 String refName, String fullRefName) {
80 knownResourceShortIdentifer = shortIdentifer;
81 //knownResourceRefName = refName;
82 //knownResourceFullRefName = fullRefName;
86 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
89 protected CollectionSpaceClient getClientInstance() {
90 return new VocabularyClient();
94 protected PoxPayloadOut createInstance(String identifier) {
95 VocabularyClient client = new VocabularyClient();
96 String displayName = "displayName-" + identifier;
97 PoxPayloadOut multipart = VocabularyClientUtils.createEnumerationInstance(
98 displayName, identifier, client.getCommonPartName());
102 // ---------------------------------------------------------------
103 // CRUD tests : CREATE tests
104 // ---------------------------------------------------------------
107 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
108 public void create(String testName) throws Exception {
110 if (logger.isDebugEnabled()) {
111 logger.debug(testBanner(testName, CLASS_NAME));
113 // Perform setup, such as initializing the type of service request
114 // (e.g. CREATE, DELETE), its valid and expected status codes, and
115 // its associated HTTP method name (e.g. POST, DELETE).
118 // Submit the request to the service and store the response.
119 VocabularyClient client = new VocabularyClient();
120 String identifier = createIdentifier();
121 String displayName = "displayName-" + identifier;
122 PoxPayloadOut multipart = VocabularyClientUtils.createEnumerationInstance(
123 displayName, identifier, client.getCommonPartName());
124 ClientResponse<Response> res = client.create(multipart);
125 int statusCode = res.getStatus();
127 // Check the status code of the response: does it match
128 // the expected response(s)?
131 // Does it fall within the set of valid status codes?
132 // Does it exactly match the expected status code?
133 if (logger.isDebugEnabled()) {
134 logger.debug(testName + ": status = " + statusCode);
136 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
137 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
138 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
140 // Store the ID returned from the first resource created
141 // for additional tests below.
142 if (knownResourceId == null) {
143 setKnownResource(extractId(res), identifier, null, null );
144 //VocabularyClientUtils.createVocabularyRefName(identifier, null),
145 //VocabularyClientUtils.createVocabularyRefName(identifier, displayName));
146 if (logger.isDebugEnabled()) {
147 logger.debug(testName + ": knownResourceId=" + knownResourceId);
150 // Store the IDs from every resource created by tests,
151 // so they can be deleted after tests have been run.
152 allResourceIdsCreated.add(extractId(res));
157 protected PoxPayloadOut createItemInstance(String parentCsid, String identifier) {
158 String headerLabel = new VocabularyClient().getItemCommonPartName();
159 HashMap<String, String> vocabItemInfo = new HashMap<String, String>();
160 String shortId = createIdentifier();
161 vocabItemInfo.put(AuthorityItemJAXBSchema.SHORT_IDENTIFIER, shortId);
162 vocabItemInfo.put(AuthorityItemJAXBSchema.DISPLAY_NAME, "display-" + shortId);
164 return VocabularyClientUtils.createVocabularyItemInstance(identifier, vocabItemInfo, headerLabel);
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 null /*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(null, //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: \"" + knownResourceId //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: \"" + knownResourceId /*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<AbstractCommonList> res = client.readList();
657 AbstractCommonList 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 if(logger.isTraceEnabled()){
671 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
675 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
676 dependsOnMethods = {"createList", "readItem"})
677 public void readItemList(String testName) {
678 readItemListInt(knownResourceId, null, testName);
681 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
682 dependsOnMethods = {"createList", "readItem"})
683 public void readItemListByName(String testName) {
684 readItemListInt(null, knownResourceShortIdentifer, testName);
687 private void readItemListInt(String vcsid, String shortId, String testName) {
692 // Submit the request to the service and store the response.
693 VocabularyClient client = new VocabularyClient();
694 ClientResponse<AbstractCommonList> res = null;
696 res = client.readItemList(vcsid, null, null);
697 } else if (shortId != null) {
698 res = client.readItemListForNamedAuthority(shortId, null, null);
700 Assert.fail("Internal Error: readItemList both vcsid and shortId are null!");
702 AbstractCommonList list = res.getEntity();
703 int statusCode = res.getStatus();
705 // Check the status code of the response: does it match
706 // the expected response(s)?
707 if (logger.isDebugEnabled()) {
708 logger.debug(" " + testName + ": status = " + statusCode);
710 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
711 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
712 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
714 List<AbstractCommonList.ListItem> items = list.getListItem();
715 int nItemsReturned = items.size();
716 long nItemsTotal = list.getTotalItems();
717 if (logger.isDebugEnabled()) {
718 logger.debug(" " + testName + ": Expected "
719 + nItemsToCreateInList + " items; got: " + nItemsReturned + " of: " + nItemsTotal);
721 Assert.assertEquals(nItemsTotal, nItemsToCreateInList);
723 if(logger.isTraceEnabled()){
724 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
730 // ---------------------------------------------------------------
731 // CRUD tests : UPDATE tests
732 // ---------------------------------------------------------------
735 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
736 dependsOnMethods = {"read"})
737 public void update(String testName) throws Exception {
739 if (logger.isDebugEnabled()) {
740 logger.debug(testBanner(testName, CLASS_NAME));
745 // Retrieve the contents of a resource to update.
746 VocabularyClient client = new VocabularyClient();
747 ClientResponse<String> res =
748 client.read(knownResourceId);
749 if (logger.isDebugEnabled()) {
750 logger.debug(testName + ": read status = " + res.getStatus());
752 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
754 if (logger.isDebugEnabled()) {
755 logger.debug("got Vocabulary to update with ID: " + knownResourceId);
757 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
758 VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input,
759 client.getCommonPartName(), VocabulariesCommon.class);
760 Assert.assertNotNull(vocabulary);
762 // Update the contents of this resource.
763 vocabulary.setDisplayName("updated-" + vocabulary.getDisplayName());
764 vocabulary.setVocabType("updated-" + vocabulary.getVocabType());
765 if (logger.isDebugEnabled()) {
766 logger.debug("to be updated Vocabulary");
767 logger.debug(objectAsXmlString(vocabulary, VocabulariesCommon.class));
770 // Submit the updated resource to the service and store the response.
771 PoxPayloadOut output = new PoxPayloadOut(SERVICE_PAYLOAD_NAME);
773 PayloadOutputPart commonPart = output.addPart(vocabulary, MediaType.APPLICATION_XML_TYPE);
774 commonPart.setLabel(client.getCommonPartName());
775 res = client.update(knownResourceId, output);
776 int statusCode = res.getStatus();
778 // Check the status code of the response: does it match the expected response(s)?
779 if (logger.isDebugEnabled()) {
780 logger.debug("update: status = " + statusCode);
782 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
783 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
784 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
786 // Retrieve the updated resource and verify that its contents exist.
787 input = new PoxPayloadIn(res.getEntity());
788 VocabulariesCommon updatedVocabulary =
789 (VocabulariesCommon) extractPart(input,
790 client.getCommonPartName(), VocabulariesCommon.class);
791 Assert.assertNotNull(updatedVocabulary);
793 // Verify that the updated resource received the correct data.
794 Assert.assertEquals(updatedVocabulary.getDisplayName(),
795 vocabulary.getDisplayName(),
796 "Data in updated object did not match submitted data.");
799 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
800 dependsOnMethods = {"readItem", "update", "verifyIgnoredUpdateWithInAuthority"})
801 public void updateItem(String testName) throws Exception {
803 if (logger.isDebugEnabled()) {
804 logger.debug(testBanner(testName, CLASS_NAME));
809 // Retrieve the contents of a resource to update.
810 VocabularyClient client = new VocabularyClient();
811 ClientResponse<String> res =
812 client.readItem(knownResourceId, knownItemResourceId);
813 if (logger.isDebugEnabled()) {
814 logger.debug(testName + ": read status = " + res.getStatus());
816 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
818 if (logger.isDebugEnabled()) {
819 logger.debug("got VocabularyItem to update with ID: "
820 + knownItemResourceId
821 + " in Vocab: " + knownResourceId);
823 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
824 VocabularyitemsCommon vocabularyItem = (VocabularyitemsCommon) extractPart(input,
825 client.getCommonPartItemName(), VocabularyitemsCommon.class);
826 Assert.assertNotNull(vocabularyItem);
828 // Update the contents of this resource.
829 vocabularyItem.setDisplayName("updated-" + vocabularyItem.getDisplayName());
830 if (logger.isDebugEnabled()) {
831 logger.debug("to be updated VocabularyItem");
832 logger.debug(objectAsXmlString(vocabularyItem,
833 VocabularyitemsCommon.class));
836 // Submit the updated resource to the service and store the response.
837 PoxPayloadOut output = new PoxPayloadOut(SERVICE_ITEM_PAYLOAD_NAME);
838 PayloadOutputPart commonPart = output.addPart(vocabularyItem, MediaType.APPLICATION_XML_TYPE);
839 commonPart.setLabel(client.getCommonPartItemName());
840 res = client.updateItem(knownResourceId, knownItemResourceId, output);
841 int statusCode = res.getStatus();
843 // Check the status code of the response: does it match the expected response(s)?
844 if (logger.isDebugEnabled()) {
845 logger.debug("updateItem: status = " + statusCode);
847 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
848 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
849 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
851 // Retrieve the updated resource and verify that its contents exist.
852 input = new PoxPayloadIn(res.getEntity());
853 VocabularyitemsCommon updatedVocabularyItem =
854 (VocabularyitemsCommon) extractPart(input,
855 client.getCommonPartItemName(), VocabularyitemsCommon.class);
856 Assert.assertNotNull(updatedVocabularyItem);
858 // Verify that the updated resource received the correct data.
859 Assert.assertEquals(updatedVocabularyItem.getDisplayName(),
860 vocabularyItem.getDisplayName(),
861 "Data in updated VocabularyItem did not match submitted data.");
864 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
865 dependsOnMethods = {"readItem"})
866 public void verifyIgnoredUpdateWithInAuthority(String testName) throws Exception {
868 if (logger.isDebugEnabled()) {
869 logger.debug(testBanner(testName, CLASS_NAME));
874 // Submit the request to the service and store the response.
875 VocabularyClient client = new VocabularyClient();
876 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
877 int statusCode = res.getStatus();
879 // Check the status code of the response: does it match
880 // the expected response(s)?
881 if (logger.isDebugEnabled()) {
882 logger.debug(testName + " read Vocab:" + knownResourceId + "/Item:"
883 + knownItemResourceId + " status = " + statusCode);
885 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
886 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
887 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
889 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
890 VocabularyitemsCommon vitem = (VocabularyitemsCommon) extractPart(input,
891 client.getCommonPartItemName(), VocabularyitemsCommon.class);
892 Assert.assertNotNull(vitem);
893 // Try to Update with new parent vocab (use self, for test).
894 Assert.assertEquals(vitem.getInAuthority(),
896 "VocabularyItem inAuthority does not match knownResourceId.");
897 vitem.setInAuthority(knownItemResourceId);
899 // Submit the updated resource to the service and store the response.
900 PoxPayloadOut output = new PoxPayloadOut(SERVICE_ITEM_PAYLOAD_NAME);
901 PayloadOutputPart commonPart = output.addPart(vitem, MediaType.APPLICATION_XML_TYPE);
902 commonPart.setLabel(client.getCommonPartItemName());
903 res = client.updateItem(knownResourceId, knownItemResourceId, output);
904 statusCode = res.getStatus();
906 // Check the status code of the response: does it match the expected response(s)?
907 if (logger.isDebugEnabled()) {
908 logger.debug(testName + ": status = " + statusCode);
910 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
911 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
912 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
914 // Retrieve the updated resource and verify that the parent did not change
915 res = client.readItem(knownResourceId, knownItemResourceId);
916 input = new PoxPayloadIn(res.getEntity());
917 VocabularyitemsCommon updatedVocabularyItem =
918 (VocabularyitemsCommon) extractPart(input,
919 client.getCommonPartItemName(), VocabularyitemsCommon.class);
920 Assert.assertNotNull(updatedVocabularyItem);
922 // Verify that the updated resource received the correct data.
923 Assert.assertEquals(updatedVocabularyItem.getInAuthority(),
925 "VocabularyItem allowed update to the parent (inAuthority).");
929 // Placeholders until the three tests below can be uncommented.
930 // See Issue CSPACE-401.
932 public void updateWithEmptyEntityBody(String testName) throws Exception {
936 public void updateWithMalformedXml(String testName) throws Exception {
940 public void updateWithWrongXmlSchema(String testName) throws Exception {
945 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
946 dependsOnMethods = {"create", "update", "testSubmitRequest"})
947 public void updateWithEmptyEntityBody(String testName) throws Exception {
949 if (logger.isDebugEnabled()) {
950 logger.debug(testBanner(testName, CLASS_NAME));
953 setupUpdateWithEmptyEntityBody();
955 // Submit the request to the service and store the response.
956 String method = REQUEST_TYPE.httpMethodName();
957 String url = getResourceURL(knownResourceId);
958 String mediaType = MediaType.APPLICATION_XML;
959 final String entity = "";
960 int statusCode = submitRequest(method, url, mediaType, entity);
962 // Check the status code of the response: does it match
963 // the expected response(s)?
964 if(logger.isDebugEnabled()){
965 logger.debug(testName + ": url=" + url +
966 " status=" + statusCode);
968 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
969 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
970 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
974 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
975 dependsOnMethods = {"create", "update", "testSubmitRequest"})
976 public void updateWithMalformedXml(String testName) throws Exception {
978 if (logger.isDebugEnabled()) {
979 logger.debug(testBanner(testName, CLASS_NAME));
982 setupUpdateWithMalformedXml();
984 // Submit the request to the service and store the response.
985 String method = REQUEST_TYPE.httpMethodName();
986 String url = getResourceURL(knownResourceId);
987 String mediaType = MediaType.APPLICATION_XML;
988 final String entity = MALFORMED_XML_DATA;
989 int statusCode = submitRequest(method, url, mediaType, entity);
991 // Check the status code of the response: does it match
992 // the expected response(s)?
993 if(logger.isDebugEnabled()){
994 logger.debug(testName + ": url=" + url +
995 " status=" + statusCode);
997 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
998 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
999 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1003 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1004 dependsOnMethods = {"create", "update", "testSubmitRequest"})
1005 public void updateWithWrongXmlSchema(String testName) throws Exception {
1007 if (logger.isDebugEnabled()) {
1008 logger.debug(testBanner(testName, CLASS_NAME));
1011 setupUpdateWithWrongXmlSchema();
1013 // Submit the request to the service and store the response.
1014 String method = REQUEST_TYPE.httpMethodName();
1015 String url = getResourceURL(knownResourceId);
1016 String mediaType = MediaType.APPLICATION_XML;
1017 final String entity = WRONG_XML_SCHEMA_DATA;
1018 int statusCode = submitRequest(method, url, mediaType, entity);
1020 // Check the status code of the response: does it match
1021 // the expected response(s)?
1022 if(logger.isDebugEnabled()){
1023 logger.debug("updateWithWrongXmlSchema: url=" + url +
1024 " status=" + statusCode);
1026 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1027 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1028 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1032 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1033 dependsOnMethods = {"update", "testSubmitRequest"})
1034 public void updateNonExistent(String testName) throws Exception {
1036 if (logger.isDebugEnabled()) {
1037 logger.debug(testBanner(testName, CLASS_NAME));
1040 setupUpdateNonExistent();
1042 // Submit the request to the service and store the response.
1043 // Note: The ID used in this 'create' call may be arbitrary.
1044 // The only relevant ID may be the one used in update(), below.
1045 VocabularyClient client = new VocabularyClient();
1046 String displayName = "displayName-" + NON_EXISTENT_ID;
1047 PoxPayloadOut multipart = VocabularyClientUtils.createEnumerationInstance(
1048 displayName, NON_EXISTENT_ID, client.getCommonPartName());
1049 ClientResponse<String> res =
1050 client.update(NON_EXISTENT_ID, multipart);
1051 int statusCode = res.getStatus();
1053 // Check the status code of the response: does it match
1054 // the expected response(s)?
1055 if (logger.isDebugEnabled()) {
1056 logger.debug(testName + ": status = " + statusCode);
1058 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1059 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1060 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1063 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1064 dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1065 public void updateNonExistentItem(String testName) throws Exception {
1067 if (logger.isDebugEnabled()) {
1068 logger.debug(testBanner(testName, CLASS_NAME));
1071 setupUpdateNonExistent();
1073 // Submit the request to the service and store the response.
1074 // Note: The ID used in this 'create' call may be arbitrary.
1075 // The only relevant ID may be the one used in update(), below.
1076 VocabularyClient client = new VocabularyClient();
1077 HashMap<String, String> itemInfo = new HashMap<String, String>();
1078 itemInfo.put(AuthorityItemJAXBSchema.SHORT_IDENTIFIER, "nonex");
1079 itemInfo.put(AuthorityItemJAXBSchema.DISPLAY_NAME, "display-nonex");
1080 PoxPayloadOut multipart =
1081 VocabularyClientUtils.createVocabularyItemInstance(
1082 null, //VocabularyClientUtils.createVocabularyRefName(NON_EXISTENT_ID, null),
1083 itemInfo, client.getCommonPartItemName());
1084 ClientResponse<String> res =
1085 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1086 int statusCode = res.getStatus();
1088 // Check the status code of the response: does it match
1089 // the expected response(s)?
1090 if (logger.isDebugEnabled()) {
1091 logger.debug(testName + ": status = " + statusCode);
1093 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1094 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1095 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1098 // ---------------------------------------------------------------
1099 // CRUD tests : DELETE tests
1100 // ---------------------------------------------------------------
1103 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1104 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update", "deleteItem"})
1105 public void delete(String testName) throws Exception {
1107 if (logger.isDebugEnabled()) {
1108 logger.debug(testBanner(testName, CLASS_NAME));
1113 // Submit the request to the service and store the response.
1114 VocabularyClient client = new VocabularyClient();
1115 ClientResponse<Response> res = client.delete(knownResourceId);
1116 int statusCode = res.getStatus();
1118 // Check the status code of the response: does it match
1119 // the expected response(s)?
1120 if (logger.isDebugEnabled()) {
1121 logger.debug(testName + ": status = " + statusCode);
1123 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1124 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1125 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1128 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1129 dependsOnMethods = {"createItem", "readItemList", "testItemSubmitRequest",
1130 "updateItem", "verifyIllegalItemDisplayName", "verifyIgnoredUpdateWithInAuthority"})
1131 public void deleteItem(String testName) throws Exception {
1133 if (logger.isDebugEnabled()) {
1134 logger.debug(testBanner(testName, CLASS_NAME));
1139 // Submit the request to the service and store the response.
1140 VocabularyClient client = new VocabularyClient();
1141 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1142 int statusCode = res.getStatus();
1144 // Check the status code of the response: does it match
1145 // the expected response(s)?
1146 if (logger.isDebugEnabled()) {
1147 logger.debug("delete: status = " + statusCode);
1149 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1150 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1151 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1156 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1157 dependsOnMethods = {"delete"})
1158 public void deleteNonExistent(String testName) throws Exception {
1160 if (logger.isDebugEnabled()) {
1161 logger.debug(testBanner(testName, CLASS_NAME));
1164 setupDeleteNonExistent();
1166 // Submit the request to the service and store the response.
1167 VocabularyClient client = new VocabularyClient();
1168 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
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(testName + ": status = " + statusCode);
1176 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1177 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1178 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1181 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1182 dependsOnMethods = {"deleteItem"})
1183 public void deleteNonExistentItem(String testName) {
1185 if (logger.isDebugEnabled()) {
1186 logger.debug(testBanner(testName, CLASS_NAME));
1189 setupDeleteNonExistent();
1191 // Submit the request to the service and store the response.
1192 VocabularyClient client = new VocabularyClient();
1193 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1194 int statusCode = res.getStatus();
1196 // Check the status code of the response: does it match
1197 // the expected response(s)?
1198 if (logger.isDebugEnabled()) {
1199 logger.debug(testName + ": status = " + statusCode);
1201 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1202 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1203 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1206 // ---------------------------------------------------------------
1207 // Utility tests : tests of code used in tests above
1208 // ---------------------------------------------------------------
1210 * Tests the code for manually submitting data that is used by several
1211 * of the methods above.
1213 @Test(dependsOnMethods = {"create", "read"})
1214 public void testSubmitRequest() {
1216 // Expected status code: 200 OK
1219 // Submit the request to the service and store the response.
1220 String method = ServiceRequestType.READ.httpMethodName();
1221 String url = getResourceURL(knownResourceId);
1222 int statusCode = submitRequest(method, url);
1224 // Check the status code of the response: does it match
1225 // the expected response(s)?
1226 if (logger.isDebugEnabled()) {
1227 logger.debug("testSubmitRequest: url=" + url
1228 + " status=" + statusCode);
1230 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1234 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1235 public void testItemSubmitRequest() {
1237 // Expected status code: 200 OK
1238 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1240 // Submit the request to the service and store the response.
1241 String method = ServiceRequestType.READ.httpMethodName();
1242 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1243 int statusCode = submitRequest(method, url);
1245 // Check the status code of the response: does it match
1246 // the expected response(s)?
1247 if (logger.isDebugEnabled()) {
1248 logger.debug("testItemSubmitRequest: url=" + url
1249 + " status=" + statusCode);
1251 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1255 // ---------------------------------------------------------------
1256 // Cleanup of resources created during testing
1257 // ---------------------------------------------------------------
1259 * Deletes all resources created by tests, after all tests have been run.
1261 * This cleanup method will always be run, even if one or more tests fail.
1262 * For this reason, it attempts to remove all resources created
1263 * at any point during testing, even if some of those resources
1264 * may be expected to be deleted by certain tests.
1266 // @AfterClass(alwaysRun = true)
1267 // public void cleanUp() {
1268 // String noTest = System.getProperty("noTestCleanup");
1269 // if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1270 // if (logger.isDebugEnabled()) {
1271 // logger.debug("Skipping Cleanup phase ...");
1275 // if (logger.isDebugEnabled()) {
1276 // logger.debug("Cleaning up temporary resources created for testing ...");
1278 // VocabularyClient client = new VocabularyClient();
1279 // String vocabularyResourceId;
1280 // String vocabularyItemResourceId;
1281 // // Clean up vocabulary item resources.
1282 // for (Map.Entry<String, String> entry : allResourceItemIdsCreated.entrySet()) {
1283 // vocabularyItemResourceId = entry.getKey();
1284 // vocabularyResourceId = entry.getValue();
1285 // // Note: Any non-success responses are ignored and not reported.
1286 // client.deleteItem(vocabularyResourceId, vocabularyItemResourceId).releaseConnection();
1288 // // Clean up vocabulary resources.
1289 // for (String resourceId : allResourceIdsCreated) {
1290 // // Note: Any non-success responses are ignored and not reported.
1291 // client.delete(resourceId).releaseConnection();
1296 // ---------------------------------------------------------------
1297 // Utility methods used by tests above
1298 // ---------------------------------------------------------------
1300 public String getServicePathComponent() {
1301 return SERVICE_PATH_COMPONENT;
1304 public String getServicePathItemsComponent() {
1305 return AuthorityClient.ITEMS;
1309 * Returns the root URL for a service.
1311 * This URL consists of a base URL for all services, followed by
1312 * a path component for the owning vocabulary, followed by the
1313 * path component for the items.
1315 * @return The root URL for a service.
1317 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1318 return getResourceURL(parentResourceIdentifier) + "/" + getServicePathItemsComponent();
1322 * Returns the URL of a specific resource managed by a service, and
1323 * designated by an identifier (such as a universally unique ID, or UUID).
1325 * @param resourceIdentifier An identifier (such as a UUID) for a resource.
1327 * @return The URL of a specific resource managed by a service.
1329 protected String getItemResourceURL(String parentResourceIdentifier, String resourceIdentifier) {
1330 return getItemServiceRootURL(parentResourceIdentifier) + "/" + resourceIdentifier;
1334 protected String getServiceName() {
1335 return VocabularyClient.SERVICE_NAME;