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.VocabularyItemJAXBSchema;
33 import org.collectionspace.services.client.CollectionSpaceClient;
34 import org.collectionspace.services.client.VocabularyClient;
35 import org.collectionspace.services.client.VocabularyClientUtils;
36 import org.collectionspace.services.jaxb.AbstractCommonList;
37 import org.collectionspace.services.vocabulary.VocabulariesCommon;
38 import org.collectionspace.services.vocabulary.VocabulariesCommonList;
39 import org.collectionspace.services.vocabulary.VocabularyitemsCommon;
40 import org.collectionspace.services.vocabulary.VocabularyitemsCommonList;
42 import org.jboss.resteasy.client.ClientResponse;
43 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
44 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
45 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
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);
64 // Instance variables specific to this test.
65 final String SERVICE_PATH_COMPONENT = "vocabularies";
66 final String ITEM_SERVICE_PATH_COMPONENT = "items";
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 = 3;
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 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
97 protected AbstractCommonList getAbstractCommonList(
98 ClientResponse<AbstractCommonList> response) {
99 return response.getEntity(VocabulariesCommonList.class);
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 MultipartOutput 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,
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));
156 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
157 dependsOnMethods = {"create"})
158 public void createItem(String testName) {
160 if (logger.isDebugEnabled()) {
161 logger.debug(testBanner(testName, CLASS_NAME));
166 VocabularyClient client = new VocabularyClient();
167 HashMap<String, String> itemInfo = new HashMap<String, String>();
168 String shortId = createIdentifier();
169 itemInfo.put(VocabularyItemJAXBSchema.SHORT_IDENTIFIER, shortId);
170 itemInfo.put(VocabularyItemJAXBSchema.DISPLAY_NAME, "display-"+shortId);
171 String newID = VocabularyClientUtils.createItemInVocabulary(knownResourceId,
172 knownResourceRefName, itemInfo, client);
174 // Store the ID returned from the first item resource created
175 // for additional tests below.
176 if (knownItemResourceId == null){
177 knownItemResourceId = newID;
178 if (logger.isDebugEnabled()) {
179 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
182 // Store the IDs from any item resources created
183 // by tests, along with the IDs of their parents, so these items
184 // can be deleted after all tests have been run.
185 allResourceItemIdsCreated.put(newID, knownResourceId);
189 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
190 dependsOnMethods = {"create", "createItem", "readItem"})
191 public void createList(String testName) throws Exception {
192 for (int i = 0; i < 3; i++) {
193 // Force create to reset the known resource info
194 setKnownResource(null, null, null, null);
196 // Add nItemsToCreateInList items to each vocab
197 for (int j = 0; j < nItemsToCreateInList; j++) {
198 createItem(testName);
204 // Placeholders until the three tests below can be uncommented.
205 // See Issue CSPACE-401.
207 public void createWithEmptyEntityBody(String testName) throws Exception {
211 public void createWithMalformedXml(String testName) throws Exception {
215 public void createWithWrongXmlSchema(String testName) throws Exception {
218 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
219 dependsOnMethods = {"create"})
220 public void createWithBadShortId(String testName) throws Exception {
222 if (logger.isDebugEnabled()) {
223 logger.debug(testBanner(testName, CLASS_NAME));
225 testSetup(STATUS_BAD_REQUEST, ServiceRequestType.CREATE);
227 // Submit the request to the service and store the response.
228 VocabularyClient client = new VocabularyClient();
229 MultipartOutput multipart = VocabularyClientUtils.createEnumerationInstance(
230 "Vocab with Bad Short Id", "Bad Short Id!", client.getCommonPartName());
231 ClientResponse<Response> res = client.create(multipart);
232 int statusCode = res.getStatus();
234 // Check the status code of the response: does it match
235 // the expected response(s)?
238 // Does it fall within the set of valid status codes?
239 // Does it exactly match the expected status code?
240 if(logger.isDebugEnabled()){
241 logger.debug(testName + ": status = " + statusCode);
243 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
244 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
245 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
248 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
249 dependsOnMethods = {"createItem"})
250 public void createItemWithBadShortId(String testName) throws Exception {
252 if (logger.isDebugEnabled()) {
253 logger.debug(testBanner(testName, CLASS_NAME));
255 setupCreateWithMalformedXml();
257 // Submit the request to the service and store the response.
258 VocabularyClient client = new VocabularyClient();
259 HashMap<String, String> itemInfo = new HashMap<String, String>();
260 itemInfo.put(VocabularyItemJAXBSchema.SHORT_IDENTIFIER, "Bad Item Short Id!");
261 itemInfo.put(VocabularyItemJAXBSchema.DISPLAY_NAME, "Bad Item!");
262 MultipartOutput multipart =
263 VocabularyClientUtils.createVocabularyItemInstance( knownResourceId, knownResourceRefName,
264 itemInfo, client.getItemCommonPartName() );
265 ClientResponse<Response> res = client.createItem(knownResourceId, multipart);
267 int statusCode = res.getStatus();
269 if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {
270 throw new RuntimeException("Could not create Item: \""+itemInfo.get(VocabularyItemJAXBSchema.DISPLAY_NAME)
271 +"\" in personAuthority: \"" + knownResourceRefName
272 +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
274 if(statusCode != EXPECTED_STATUS_CODE) {
275 throw new RuntimeException("Unexpected Status when creating Item: \""+itemInfo.get(VocabularyItemJAXBSchema.DISPLAY_NAME)
276 +"\" in personAuthority: \"" + knownResourceRefName +"\", Status:"+ statusCode);
282 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
283 dependsOnMethods = {"create", "testSubmitRequest"})
284 public void createWithEmptyEntityBody(String testName) throws Exception {
286 if (logger.isDebugEnabled()) {
287 logger.debug(testBanner(testName, CLASS_NAME));
290 setupCreateWithEmptyEntityBody(testName, CLASS_NAME);
292 // Submit the request to the service and store the response.
293 String method = REQUEST_TYPE.httpMethodName();
294 String url = getServiceRootURL();
295 String mediaType = MediaType.APPLICATION_XML;
296 final String entity = "";
297 int statusCode = submitRequest(method, url, mediaType, entity);
299 // Check the status code of the response: does it match
300 // the expected response(s)?
301 if(logger.isDebugEnabled()) {
302 logger.debug(testName + ": url=" + url +
303 " status=" + statusCode);
305 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
306 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
307 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
311 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
312 dependsOnMethods = {"create", "testSubmitRequest"})
313 public void createWithMalformedXml(String testName) throws Exception {
315 if (logger.isDebugEnabled()) {
316 logger.debug(testBanner(testName, CLASS_NAME));
319 setupCreateWithMalformedXml();
321 // Submit the request to the service and store the response.
322 String method = REQUEST_TYPE.httpMethodName();
323 String url = getServiceRootURL();
324 String mediaType = MediaType.APPLICATION_XML;
325 final String entity = MALFORMED_XML_DATA; // Constant from base class.
326 int statusCode = submitRequest(method, url, mediaType, entity);
328 // Check the status code of the response: does it match
329 // the expected response(s)?
330 if(logger.isDebugEnabled()){
331 logger.debug(testName + ": url=" + url +
332 " status=" + statusCode);
334 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
335 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
336 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
340 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
341 dependsOnMethods = {"create", "testSubmitRequest"})
342 public void createWithWrongXmlSchema(String testName) throws Exception {
344 if (logger.isDebugEnabled()) {
345 logger.debug(testBanner(testName, CLASS_NAME));
348 setupCreateWithWrongXmlSchema();
350 // Submit the request to the service and store the response.
351 String method = REQUEST_TYPE.httpMethodName();
352 String url = getServiceRootURL();
353 String mediaType = MediaType.APPLICATION_XML;
354 final String entity = WRONG_XML_SCHEMA_DATA;
355 int statusCode = submitRequest(method, url, mediaType, entity);
357 // Check the status code of the response: does it match
358 // the expected response(s)?
359 if(logger.isDebugEnabled()){
360 logger.debug(testName + ": url=" + url +
361 " status=" + statusCode);
363 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
364 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
365 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
369 // ---------------------------------------------------------------
370 // CRUD tests : READ tests
371 // ---------------------------------------------------------------
374 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
375 dependsOnMethods = {"create"})
376 public void read(String testName) throws Exception {
378 if (logger.isDebugEnabled()) {
379 logger.debug(testBanner(testName, CLASS_NAME));
384 // Submit the request to the service and store the response.
385 VocabularyClient client = new VocabularyClient();
386 ClientResponse<MultipartInput> res = client.read(knownResourceId);
387 int statusCode = res.getStatus();
389 // Check the status code of the response: does it match
390 // the expected response(s)?
391 if(logger.isDebugEnabled()){
392 logger.debug(testName + ": status = " + statusCode);
394 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
395 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
396 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
397 //FIXME: remove the following try catch once Aron fixes signatures
399 MultipartInput input = (MultipartInput) res.getEntity();
400 VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input,
401 client.getCommonPartName(), VocabulariesCommon.class);
402 Assert.assertNotNull(vocabulary);
403 Assert.assertEquals(vocabulary.getRefName(), knownResourceFullRefName);
404 } catch (Exception e) {
405 throw new RuntimeException(e);
412 * @param testName the test name
413 * @throws Exception the exception
415 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
416 dependsOnMethods = {"read"})
417 public void readByName(String testName) throws Exception {
419 if (logger.isDebugEnabled()) {
420 logger.debug(testBanner(testName, CLASS_NAME));
425 // Submit the request to the service and store the response.
426 VocabularyClient client = new VocabularyClient();
427 ClientResponse<MultipartInput> res = client.readByName(knownResourceShortIdentifer);
429 int statusCode = res.getStatus();
431 // Check the status code of the response: does it match
432 // the expected response(s)?
433 if(logger.isDebugEnabled()){
434 logger.debug(testName + ": status = " + statusCode);
436 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
437 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
438 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
439 //FIXME: remove the following try catch once Aron fixes signatures
441 MultipartInput input = (MultipartInput) res.getEntity();
442 VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input,
443 client.getCommonPartName(), VocabulariesCommon.class);
444 Assert.assertNotNull(vocabulary);
445 } catch (Exception e) {
446 throw new RuntimeException(e);
449 res.releaseConnection();
454 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
455 dependsOnMethods = {"read"})
456 public void readByName(String testName) throws Exception {
458 if (logger.isDebugEnabled()) {
459 logger.debug(testBanner(testName, CLASS_NAME));
464 // Submit the request to the service and store the response.
465 ClientResponse<MultipartInput> res = client.read(knownResourceId);
466 int statusCode = res.getStatus();
468 // Check the status code of the response: does it match
469 // the expected response(s)?
470 if(logger.isDebugEnabled()){
471 logger.debug(testName + ": status = " + statusCode);
473 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
474 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
475 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
476 //FIXME: remove the following try catch once Aron fixes signatures
478 MultipartInput input = (MultipartInput) res.getEntity();
479 VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input,
480 client.getCommonPartName(), VocabulariesCommon.class);
481 Assert.assertNotNull(vocabulary);
482 } catch (Exception e) {
483 throw new RuntimeException(e);
488 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
489 dependsOnMethods = {"createItem", "read"})
490 public void readItem(String testName) throws Exception {
492 if (logger.isDebugEnabled()) {
493 logger.debug(testBanner(testName, CLASS_NAME));
498 // Submit the request to the service and store the response.
499 VocabularyClient client = new VocabularyClient();
500 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
501 int statusCode = res.getStatus();
503 // Check the status code of the response: does it match
504 // the expected response(s)?
505 if(logger.isDebugEnabled()){
506 logger.debug(testName + ": status = " + statusCode);
508 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
509 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
510 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
512 // Check whether we've received a vocabulary item.
513 MultipartInput input = (MultipartInput) res.getEntity();
514 VocabularyitemsCommon vocabularyItem = (VocabularyitemsCommon) extractPart(input,
515 client.getItemCommonPartName(), VocabularyitemsCommon.class);
516 Assert.assertNotNull(vocabularyItem);
517 Assert.assertEquals(vocabularyItem.getInVocabulary(), knownResourceId);
521 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
522 dependsOnMethods = {"updateItem"})
523 public void verifyIllegalItemDisplayName(String testName) throws Exception {
525 if (logger.isDebugEnabled()) {
526 logger.debug(testBanner(testName, CLASS_NAME));
529 testSetup(STATUS_BAD_REQUEST, ServiceRequestType.UPDATE);
530 // setupUpdateWithWrongXmlSchema(testName);
532 // Submit the request to the service and store the response.
533 VocabularyClient client = new VocabularyClient();
534 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
535 int statusCode = res.getStatus();
537 // Check the status code of the response: does it match
538 // the expected response(s)?
539 if(logger.isDebugEnabled()){
540 logger.debug(testName + ": status = " + statusCode);
542 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
543 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
544 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
546 // Check whether Person has expected displayName.
547 MultipartInput input = (MultipartInput) res.getEntity();
548 VocabularyitemsCommon vitem = (VocabularyitemsCommon) extractPart(input,
549 client.getItemCommonPartName(), VocabularyitemsCommon.class);
550 Assert.assertNotNull(vitem);
551 // Try to Update with null displayName
552 vitem.setDisplayName(null);
554 // Submit the updated resource to the service and store the response.
555 MultipartOutput output = new MultipartOutput();
556 OutputPart commonPart = output.addPart(vitem, MediaType.APPLICATION_XML_TYPE);
557 commonPart.getHeaders().add("label", client.getItemCommonPartName());
558 res = client.updateItem(knownResourceId, knownItemResourceId, output);
559 statusCode = res.getStatus();
561 // Check the status code of the response: does it match the expected response(s)?
562 if(logger.isDebugEnabled()){
563 logger.debug("updateItem: status = " + statusCode);
565 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
566 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
567 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE,
568 "Expecting invalid message because of null displayName.");
570 // Now try to Update with 1-char displayName (too short)
571 vitem.setDisplayName("a");
573 // Submit the updated resource to the service and store the response.
574 output = new MultipartOutput();
575 commonPart = output.addPart(vitem, MediaType.APPLICATION_XML_TYPE);
576 commonPart.getHeaders().add("label", client.getItemCommonPartName());
577 res = client.updateItem(knownResourceId, knownItemResourceId, output);
578 statusCode = res.getStatus();
580 // Check the status code of the response: does it match the expected response(s)?
581 if(logger.isDebugEnabled()){
582 logger.debug("updateItem: status = " + statusCode);
584 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
585 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
586 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE,
587 "Expecting invalid message because of 1-char displayName.");
591 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
592 dependsOnMethods = {"read"})
593 public void readNonExistent(String testName) {
595 if (logger.isDebugEnabled()) {
596 logger.debug(testBanner(testName, CLASS_NAME));
599 setupReadNonExistent();
601 // Submit the request to the service and store the response.
602 VocabularyClient client = new VocabularyClient();
603 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
604 int statusCode = res.getStatus();
606 // Check the status code of the response: does it match
607 // the expected response(s)?
608 if(logger.isDebugEnabled()){
609 logger.debug(testName + ": status = " + statusCode);
611 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
612 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
613 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
616 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
617 dependsOnMethods = {"readItem", "readNonExistent"})
618 public void readItemNonExistent(String testName) {
620 if (logger.isDebugEnabled()) {
621 logger.debug(testBanner(testName, CLASS_NAME));
624 setupReadNonExistent();
626 // Submit the request to the service and store the response.
627 VocabularyClient client = new VocabularyClient();
628 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
629 int statusCode = res.getStatus();
631 // Check the status code of the response: does it match
632 // the expected response(s)?
633 if(logger.isDebugEnabled()){
634 logger.debug(testName + ": status = " + statusCode);
636 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
637 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
638 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
640 // ---------------------------------------------------------------
641 // CRUD tests : READ_LIST tests
642 // ---------------------------------------------------------------
646 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
647 dependsOnMethods = {"createList", "read"})
648 public void readList(String testName) throws Exception {
650 if (logger.isDebugEnabled()) {
651 logger.debug(testBanner(testName, CLASS_NAME));
656 // Submit the request to the service and store the response.
657 VocabularyClient client = new VocabularyClient();
658 ClientResponse<VocabulariesCommonList> res = client.readList();
659 VocabulariesCommonList list = res.getEntity();
660 int statusCode = res.getStatus();
662 // Check the status code of the response: does it match
663 // the expected response(s)?
664 if(logger.isDebugEnabled()){
665 logger.debug(testName + ": status = " + statusCode);
667 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
668 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
669 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
671 // Optionally output additional data about list members for debugging.
672 boolean iterateThroughList = false;
673 if (iterateThroughList && logger.isDebugEnabled()) {
674 List<VocabulariesCommonList.VocabularyListItem> items =
675 list.getVocabularyListItem();
677 for (VocabulariesCommonList.VocabularyListItem item : items) {
678 String csid = item.getCsid();
679 logger.debug(testName + ": list-item[" + i + "] csid=" +
681 logger.debug(testName + ": list-item[" + i + "] displayName=" +
682 item.getDisplayName());
683 logger.debug(testName + ": list-item[" + i + "] URI=" +
685 readItemListInt(csid, null, "readList");
691 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
692 dependsOnMethods = {"createList", "readItem"})
693 public void readItemList(String testName) {
694 readItemListInt(knownResourceId, null, testName);
697 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
698 dependsOnMethods = {"createList", "readItem"})
699 public void readItemListByName(String testName) {
700 readItemListInt(null, knownResourceShortIdentifer, testName);
703 private void readItemListInt(String vcsid, String shortId, String testName) {
708 // Submit the request to the service and store the response.
709 VocabularyClient client = new VocabularyClient();
710 ClientResponse<VocabularyitemsCommonList> res = null;
712 res = client.readItemList(vcsid);
713 } else if(shortId!=null) {
714 res = client.readItemListForNamedVocabulary(shortId);
716 Assert.fail("Internal Error: readItemList both vcsid and shortId are null!");
718 VocabularyitemsCommonList list = res.getEntity();
719 int statusCode = res.getStatus();
721 // Check the status code of the response: does it match
722 // the expected response(s)?
723 if(logger.isDebugEnabled()){
724 logger.debug(" " + testName + ": status = " + statusCode);
726 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
727 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
728 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
730 List<VocabularyitemsCommonList.VocabularyitemListItem> items =
731 list.getVocabularyitemListItem();
732 int nItemsReturned = items.size();
733 if(logger.isDebugEnabled()){
734 logger.debug(" " + testName + ": Expected "
735 + nItemsToCreateInList+" items; got: "+nItemsReturned);
737 Assert.assertEquals( nItemsReturned, nItemsToCreateInList);
739 // Optionally output additional data about list members for debugging.
740 boolean iterateThroughList = true;
741 if (iterateThroughList && logger.isDebugEnabled()) {
742 logger.debug(" " + testName + ": checking items");
744 for (VocabularyitemsCommonList.VocabularyitemListItem item : items) {
745 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
747 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
748 item.getDisplayName());
749 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
758 // ---------------------------------------------------------------
759 // CRUD tests : UPDATE tests
760 // ---------------------------------------------------------------
763 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
764 dependsOnMethods = {"read"})
765 public void update(String testName) throws Exception {
767 if (logger.isDebugEnabled()) {
768 logger.debug(testBanner(testName, CLASS_NAME));
773 // Retrieve the contents of a resource to update.
774 VocabularyClient client = new VocabularyClient();
775 ClientResponse<MultipartInput> res =
776 client.read(knownResourceId);
777 if(logger.isDebugEnabled()){
778 logger.debug(testName + ": read status = " + res.getStatus());
780 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
782 if(logger.isDebugEnabled()){
783 logger.debug("got Vocabulary to update with ID: " + knownResourceId);
785 MultipartInput input = (MultipartInput) res.getEntity();
786 VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input,
787 client.getCommonPartName(), VocabulariesCommon.class);
788 Assert.assertNotNull(vocabulary);
790 // Update the contents of this resource.
791 vocabulary.setDisplayName("updated-" + vocabulary.getDisplayName());
792 vocabulary.setVocabType("updated-" + vocabulary.getVocabType());
793 if(logger.isDebugEnabled()){
794 logger.debug("to be updated Vocabulary");
795 logger.debug(objectAsXmlString(vocabulary, VocabulariesCommon.class));
798 // Submit the updated resource to the service and store the response.
799 MultipartOutput output = new MultipartOutput();
800 OutputPart commonPart = output.addPart(vocabulary, MediaType.APPLICATION_XML_TYPE);
801 commonPart.getHeaders().add("label", client.getCommonPartName());
802 res = client.update(knownResourceId, output);
803 int statusCode = res.getStatus();
805 // Check the status code of the response: does it match the expected response(s)?
806 if(logger.isDebugEnabled()){
807 logger.debug("update: status = " + statusCode);
809 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
810 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
811 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
813 // Retrieve the updated resource and verify that its contents exist.
814 input = (MultipartInput) res.getEntity();
815 VocabulariesCommon updatedVocabulary =
816 (VocabulariesCommon) extractPart(input,
817 client.getCommonPartName(), VocabulariesCommon.class);
818 Assert.assertNotNull(updatedVocabulary);
820 // Verify that the updated resource received the correct data.
821 Assert.assertEquals(updatedVocabulary.getDisplayName(),
822 vocabulary.getDisplayName(),
823 "Data in updated object did not match submitted data.");
826 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
827 dependsOnMethods = {"readItem", "update"})
828 public void updateItem(String testName) throws Exception {
830 if (logger.isDebugEnabled()) {
831 logger.debug(testBanner(testName, CLASS_NAME));
836 // Retrieve the contents of a resource to update.
837 VocabularyClient client = new VocabularyClient();
838 ClientResponse<MultipartInput> res =
839 client.readItem(knownResourceId, knownItemResourceId);
840 if(logger.isDebugEnabled()){
841 logger.debug(testName + ": read status = " + res.getStatus());
843 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
845 if(logger.isDebugEnabled()){
846 logger.debug("got VocabularyItem to update with ID: " +
847 knownItemResourceId +
848 " in Vocab: " + knownResourceId );
850 MultipartInput input = (MultipartInput) res.getEntity();
851 VocabularyitemsCommon vocabularyItem = (VocabularyitemsCommon) extractPart(input,
852 client.getItemCommonPartName(), VocabularyitemsCommon.class);
853 Assert.assertNotNull(vocabularyItem);
855 // Update the contents of this resource.
856 vocabularyItem.setDisplayName("updated-" + vocabularyItem.getDisplayName());
857 if(logger.isDebugEnabled()){
858 logger.debug("to be updated VocabularyItem");
859 logger.debug(objectAsXmlString(vocabularyItem,
860 VocabularyitemsCommon.class));
863 // Submit the updated resource to the service and store the response.
864 MultipartOutput output = new MultipartOutput();
865 OutputPart commonPart = output.addPart(vocabularyItem, MediaType.APPLICATION_XML_TYPE);
866 commonPart.getHeaders().add("label", client.getItemCommonPartName());
867 res = client.updateItem(knownResourceId, knownItemResourceId, output);
868 int statusCode = res.getStatus();
870 // Check the status code of the response: does it match the expected response(s)?
871 if(logger.isDebugEnabled()){
872 logger.debug("updateItem: status = " + statusCode);
874 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
875 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
876 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
878 // Retrieve the updated resource and verify that its contents exist.
879 input = (MultipartInput) res.getEntity();
880 VocabularyitemsCommon updatedVocabularyItem =
881 (VocabularyitemsCommon) extractPart(input,
882 client.getItemCommonPartName(), VocabularyitemsCommon.class);
883 Assert.assertNotNull(updatedVocabularyItem);
885 // Verify that the updated resource received the correct data.
886 Assert.assertEquals(updatedVocabularyItem.getDisplayName(),
887 vocabularyItem.getDisplayName(),
888 "Data in updated VocabularyItem did not match submitted data.");
892 // Placeholders until the three tests below can be uncommented.
893 // See Issue CSPACE-401.
895 public void updateWithEmptyEntityBody(String testName) throws Exception {
899 public void updateWithMalformedXml(String testName) throws Exception {
903 public void updateWithWrongXmlSchema(String testName) throws Exception {
908 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
909 dependsOnMethods = {"create", "update", "testSubmitRequest"})
910 public void updateWithEmptyEntityBody(String testName) throws Exception {
912 if (logger.isDebugEnabled()) {
913 logger.debug(testBanner(testName, CLASS_NAME));
916 setupUpdateWithEmptyEntityBody();
918 // Submit the request to the service and store the response.
919 String method = REQUEST_TYPE.httpMethodName();
920 String url = getResourceURL(knownResourceId);
921 String mediaType = MediaType.APPLICATION_XML;
922 final String entity = "";
923 int statusCode = submitRequest(method, url, mediaType, entity);
925 // Check the status code of the response: does it match
926 // the expected response(s)?
927 if(logger.isDebugEnabled()){
928 logger.debug(testName + ": url=" + url +
929 " status=" + statusCode);
931 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
932 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
933 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
937 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
938 dependsOnMethods = {"create", "update", "testSubmitRequest"})
939 public void updateWithMalformedXml(String testName) throws Exception {
941 if (logger.isDebugEnabled()) {
942 logger.debug(testBanner(testName, CLASS_NAME));
945 setupUpdateWithMalformedXml();
947 // Submit the request to the service and store the response.
948 String method = REQUEST_TYPE.httpMethodName();
949 String url = getResourceURL(knownResourceId);
950 String mediaType = MediaType.APPLICATION_XML;
951 final String entity = MALFORMED_XML_DATA;
952 int statusCode = submitRequest(method, url, mediaType, entity);
954 // Check the status code of the response: does it match
955 // the expected response(s)?
956 if(logger.isDebugEnabled()){
957 logger.debug(testName + ": url=" + url +
958 " status=" + statusCode);
960 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
961 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
962 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
966 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
967 dependsOnMethods = {"create", "update", "testSubmitRequest"})
968 public void updateWithWrongXmlSchema(String testName) throws Exception {
970 if (logger.isDebugEnabled()) {
971 logger.debug(testBanner(testName, CLASS_NAME));
974 setupUpdateWithWrongXmlSchema();
976 // Submit the request to the service and store the response.
977 String method = REQUEST_TYPE.httpMethodName();
978 String url = getResourceURL(knownResourceId);
979 String mediaType = MediaType.APPLICATION_XML;
980 final String entity = WRONG_XML_SCHEMA_DATA;
981 int statusCode = submitRequest(method, url, mediaType, entity);
983 // Check the status code of the response: does it match
984 // the expected response(s)?
985 if(logger.isDebugEnabled()){
986 logger.debug("updateWithWrongXmlSchema: url=" + url +
987 " status=" + statusCode);
989 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
990 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
991 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
997 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
998 dependsOnMethods = {"update", "testSubmitRequest"})
999 public void updateNonExistent(String testName) throws Exception {
1001 if (logger.isDebugEnabled()) {
1002 logger.debug(testBanner(testName, CLASS_NAME));
1005 setupUpdateNonExistent();
1007 // Submit the request to the service and store the response.
1008 // Note: The ID used in this 'create' call may be arbitrary.
1009 // The only relevant ID may be the one used in update(), below.
1010 VocabularyClient client = new VocabularyClient();
1011 String displayName = "displayName-" + NON_EXISTENT_ID;
1012 MultipartOutput multipart = VocabularyClientUtils.createEnumerationInstance(
1013 displayName, NON_EXISTENT_ID, client.getCommonPartName());
1014 ClientResponse<MultipartInput> res =
1015 client.update(NON_EXISTENT_ID, multipart);
1016 int statusCode = res.getStatus();
1018 // Check the status code of the response: does it match
1019 // the expected response(s)?
1020 if(logger.isDebugEnabled()){
1021 logger.debug(testName + ": status = " + statusCode);
1023 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1024 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1025 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1028 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1029 dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1030 public void updateNonExistentItem(String testName) throws Exception {
1032 if (logger.isDebugEnabled()) {
1033 logger.debug(testBanner(testName, CLASS_NAME));
1036 setupUpdateNonExistent();
1038 // Submit the request to the service and store the response.
1039 // Note: The ID used in this 'create' call may be arbitrary.
1040 // The only relevant ID may be the one used in update(), below.
1041 VocabularyClient client = new VocabularyClient();
1042 HashMap<String, String> itemInfo = new HashMap<String, String>();
1043 itemInfo.put(VocabularyItemJAXBSchema.SHORT_IDENTIFIER, "nonex");
1044 itemInfo.put(VocabularyItemJAXBSchema.DISPLAY_NAME, "display-nonex");
1045 MultipartOutput multipart =
1046 VocabularyClientUtils.createVocabularyItemInstance(knownResourceId,
1047 VocabularyClientUtils.createVocabularyRefName(NON_EXISTENT_ID, null),
1048 itemInfo, client.getItemCommonPartName());
1049 ClientResponse<MultipartInput> res =
1050 client.updateItem(knownResourceId, 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 // ---------------------------------------------------------------
1064 // CRUD tests : DELETE tests
1065 // ---------------------------------------------------------------
1068 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1069 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
1070 public void delete(String testName) throws Exception {
1072 if (logger.isDebugEnabled()) {
1073 logger.debug(testBanner(testName, CLASS_NAME));
1078 // Submit the request to the service and store the response.
1079 VocabularyClient client = new VocabularyClient();
1080 ClientResponse<Response> res = client.delete(knownResourceId);
1081 int statusCode = res.getStatus();
1083 // Check the status code of the response: does it match
1084 // the expected response(s)?
1085 if(logger.isDebugEnabled()){
1086 logger.debug(testName + ": status = " + statusCode);
1088 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1089 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1090 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1093 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1094 dependsOnMethods = {"createItem", "readItemList", "testItemSubmitRequest",
1095 "updateItem", "verifyIllegalItemDisplayName"})
1096 public void deleteItem(String testName) throws Exception {
1098 if (logger.isDebugEnabled()) {
1099 logger.debug(testBanner(testName, CLASS_NAME));
1104 // Submit the request to the service and store the response.
1105 VocabularyClient client = new VocabularyClient();
1106 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1107 int statusCode = res.getStatus();
1109 // Check the status code of the response: does it match
1110 // the expected response(s)?
1111 if(logger.isDebugEnabled()){
1112 logger.debug("delete: status = " + statusCode);
1114 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1115 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1116 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1121 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1122 dependsOnMethods = {"delete"})
1123 public void deleteNonExistent(String testName) throws Exception {
1125 if (logger.isDebugEnabled()) {
1126 logger.debug(testBanner(testName, CLASS_NAME));
1129 setupDeleteNonExistent();
1131 // Submit the request to the service and store the response.
1132 VocabularyClient client = new VocabularyClient();
1133 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1134 int statusCode = res.getStatus();
1136 // Check the status code of the response: does it match
1137 // the expected response(s)?
1138 if(logger.isDebugEnabled()){
1139 logger.debug(testName + ": status = " + statusCode);
1141 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1142 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1143 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1146 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1147 dependsOnMethods = {"deleteItem"})
1148 public void deleteNonExistentItem(String testName) {
1150 if (logger.isDebugEnabled()) {
1151 logger.debug(testBanner(testName, CLASS_NAME));
1154 setupDeleteNonExistent();
1156 // Submit the request to the service and store the response.
1157 VocabularyClient client = new VocabularyClient();
1158 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1159 int statusCode = res.getStatus();
1161 // Check the status code of the response: does it match
1162 // the expected response(s)?
1163 if(logger.isDebugEnabled()){
1164 logger.debug(testName + ": status = " + statusCode);
1166 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1167 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1168 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1171 // ---------------------------------------------------------------
1172 // Utility tests : tests of code used in tests above
1173 // ---------------------------------------------------------------
1175 * Tests the code for manually submitting data that is used by several
1176 * of the methods above.
1178 @Test(dependsOnMethods = {"create", "read"})
1179 public void testSubmitRequest() {
1181 // Expected status code: 200 OK
1184 // Submit the request to the service and store the response.
1185 String method = ServiceRequestType.READ.httpMethodName();
1186 String url = getResourceURL(knownResourceId);
1187 int statusCode = submitRequest(method, url);
1189 // Check the status code of the response: does it match
1190 // the expected response(s)?
1191 if(logger.isDebugEnabled()){
1192 logger.debug("testSubmitRequest: url=" + url +
1193 " status=" + statusCode);
1195 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1199 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1200 public void testItemSubmitRequest() {
1202 // Expected status code: 200 OK
1203 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1205 // Submit the request to the service and store the response.
1206 String method = ServiceRequestType.READ.httpMethodName();
1207 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1208 int statusCode = submitRequest(method, url);
1210 // Check the status code of the response: does it match
1211 // the expected response(s)?
1212 if(logger.isDebugEnabled()){
1213 logger.debug("testItemSubmitRequest: url=" + url +
1214 " status=" + statusCode);
1216 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1220 // ---------------------------------------------------------------
1221 // Cleanup of resources created during testing
1222 // ---------------------------------------------------------------
1225 * Deletes all resources created by tests, after all tests have been run.
1227 * This cleanup method will always be run, even if one or more tests fail.
1228 * For this reason, it attempts to remove all resources created
1229 * at any point during testing, even if some of those resources
1230 * may be expected to be deleted by certain tests.
1232 @AfterClass(alwaysRun=true)
1233 public void cleanUp() {
1234 String noTest = System.getProperty("noTestCleanup");
1235 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1236 if (logger.isDebugEnabled()) {
1237 logger.debug("Skipping Cleanup phase ...");
1241 if (logger.isDebugEnabled()) {
1242 logger.debug("Cleaning up temporary resources created for testing ...");
1244 VocabularyClient client = new VocabularyClient();
1245 String vocabularyResourceId;
1246 String vocabularyItemResourceId;
1247 // Clean up vocabulary item resources.
1248 for (Map.Entry<String, String> entry : allResourceItemIdsCreated.entrySet()) {
1249 vocabularyItemResourceId = entry.getKey();
1250 vocabularyResourceId = entry.getValue();
1251 // Note: Any non-success responses are ignored and not reported.
1252 client.deleteItem(vocabularyResourceId, vocabularyItemResourceId).releaseConnection();
1254 // Clean up vocabulary resources.
1255 for (String resourceId : allResourceIdsCreated) {
1256 // Note: Any non-success responses are ignored and not reported.
1257 client.delete(resourceId).releaseConnection();
1262 // ---------------------------------------------------------------
1263 // Utility methods used by tests above
1264 // ---------------------------------------------------------------
1266 public String getServicePathComponent() {
1267 return SERVICE_PATH_COMPONENT;
1270 public String getItemServicePathComponent() {
1271 return ITEM_SERVICE_PATH_COMPONENT;
1275 * Returns the root URL for a service.
1277 * This URL consists of a base URL for all services, followed by
1278 * a path component for the owning vocabulary, followed by the
1279 * path component for the items.
1281 * @return The root URL for a service.
1283 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1284 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1288 * Returns the URL of a specific resource managed by a service, and
1289 * designated by an identifier (such as a universally unique ID, or UUID).
1291 * @param resourceIdentifier An identifier (such as a UUID) for a resource.
1293 * @return The URL of a specific resource managed by a service.
1295 protected String getItemResourceURL(String parentResourceIdentifier, String resourceIdentifier) {
1296 return getItemServiceRootURL(parentResourceIdentifier) + "/" + resourceIdentifier;