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.List;
27 import javax.ws.rs.core.MediaType;
28 import javax.ws.rs.core.Response;
30 import org.collectionspace.services.client.VocabularyClient;
31 import org.collectionspace.services.vocabulary.VocabulariesCommon;
32 import org.collectionspace.services.vocabulary.VocabulariesCommonList;
33 import org.collectionspace.services.vocabulary.VocabularyitemsCommon;
34 import org.collectionspace.services.vocabulary.VocabularyitemsCommonList;
35 import org.jboss.resteasy.client.ClientResponse;
36 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
37 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
38 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41 import org.testng.Assert;
42 import org.testng.annotations.Test;
45 * VocabularyServiceTest, carries out tests against a
46 * deployed and running Vocabulary Service.
48 * $LastChangedRevision: 753 $
49 * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
51 public class VocabularyServiceTest extends AbstractServiceTest {
53 private final Logger logger =
54 LoggerFactory.getLogger(VocabularyServiceTest.class);
55 // Instance variables specific to this test.
56 private VocabularyClient client = new VocabularyClient();
57 final String SERVICE_PATH_COMPONENT = "vocabularies";
58 final String ITEM_SERVICE_PATH_COMPONENT = "items";
59 private String knownResourceId = null;
60 private String knownItemResourceId = null;
62 // ---------------------------------------------------------------
63 // CRUD tests : CREATE tests
64 // ---------------------------------------------------------------
68 public void create() {
70 // Perform setup, such as initializing the type of service request
71 // (e.g. CREATE, DELETE), its valid and expected status codes, and
72 // its associated HTTP method name (e.g. POST, DELETE).
75 // Submit the request to the service and store the response.
76 String identifier = createIdentifier();
78 MultipartOutput multipart = createVocabularyInstance(identifier);
79 ClientResponse<Response> res = client.create(multipart);
81 int statusCode = res.getStatus();
83 // Check the status code of the response: does it match
84 // the expected response(s)?
87 // Does it fall within the set of valid status codes?
88 // Does it exactly match the expected status code?
89 verbose("create: status = " + statusCode);
90 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
91 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
92 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
94 // Store the ID returned from this create operation
95 // for additional tests below.
96 knownResourceId = extractId(res);
97 verbose("create: knownResourceId=" + knownResourceId);
100 @Test(dependsOnMethods = {"create"})
101 public void createItem() {
102 setupCreate("Create Item");
104 knownItemResourceId = createItemInVocab(knownResourceId);
105 verbose("createItem: knownItemResourceId=" + knownItemResourceId);
108 private String createItemInVocab(String vcsid) {
109 // Submit the request to the service and store the response.
110 String identifier = createIdentifier();
112 verbose("createItem:...");
113 MultipartOutput multipart = createVocabularyItemInstance(vcsid, identifier);
114 ClientResponse<Response> res = client.createItem(vcsid, multipart);
116 int statusCode = res.getStatus();
118 // Check the status code of the response: does it match
119 // the expected response(s)?
122 // Does it fall within the set of valid status codes?
123 // Does it exactly match the expected status code?
124 verbose("createItem: status = " + statusCode);
125 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
126 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
127 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
129 return extractId(res);
133 @Test(dependsOnMethods = {"create", "createItem"})
134 public void createList() {
135 for (int i = 0; i < 3; i++) {
137 // Add 3 items to each vocab
138 for (int j = 0; j < 3; j++) {
145 // Placeholders until the three tests below can be uncommented.
146 // See Issue CSPACE-401.
147 public void createWithEmptyEntityBody() {
150 public void createWithMalformedXml() {
153 public void createWithWrongXmlSchema() {
158 @Test(dependsOnMethods = {"create", "testSubmitRequest"})
159 public void createWithEmptyEntityBody() {
162 setupCreateWithEmptyEntityBody();
164 // Submit the request to the service and store the response.
165 String method = REQUEST_TYPE.httpMethodName();
166 String url = getServiceRootURL();
167 String mediaType = MediaType.APPLICATION_XML;
168 final String entity = "";
169 int statusCode = submitRequest(method, url, mediaType, entity);
171 // Check the status code of the response: does it match
172 // the expected response(s)?
173 verbose("createWithEmptyEntityBody url=" + url + " status=" + statusCode);
174 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
175 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
176 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
180 @Test(dependsOnMethods = {"create", "testSubmitRequest"})
181 public void createWithMalformedXml() {
184 setupCreateWithMalformedXml();
186 // Submit the request to the service and store the response.
187 String method = REQUEST_TYPE.httpMethodName();
188 String url = getServiceRootURL();
189 String mediaType = MediaType.APPLICATION_XML;
190 final String entity = MALFORMED_XML_DATA; // Constant from base class.
191 int statusCode = submitRequest(method, url, mediaType, entity);
193 // Check the status code of the response: does it match
194 // the expected response(s)?
195 verbose("createWithMalformedXml url=" + url + " status=" + statusCode);
196 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
197 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
198 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
202 @Test(dependsOnMethods = {"create", "testSubmitRequest"})
203 public void createWithWrongXmlSchema() {
206 setupCreateWithWrongXmlSchema();
208 // Submit the request to the service and store the response.
209 String method = REQUEST_TYPE.httpMethodName();
210 String url = getServiceRootURL();
211 String mediaType = MediaType.APPLICATION_XML;
212 final String entity = WRONG_XML_SCHEMA_DATA;
213 int statusCode = submitRequest(method, url, mediaType, entity);
215 // Check the status code of the response: does it match
216 // the expected response(s)?
217 verbose("createWithWrongSchema url=" + url + " status=" + statusCode);
218 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
219 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
220 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
223 // ---------------------------------------------------------------
224 // CRUD tests : READ tests
225 // ---------------------------------------------------------------
228 @Test(dependsOnMethods = {"create"})
234 // Submit the request to the service and store the response.
235 ClientResponse<MultipartInput> res = client.read(knownResourceId);
236 int statusCode = res.getStatus();
238 // Check the status code of the response: does it match
239 // the expected response(s)?
240 verbose("read: status = " + statusCode);
241 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
242 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
243 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
244 //FIXME: remove the following try catch once Aron fixes signatures
246 MultipartInput input = (MultipartInput) res.getEntity();
247 VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input,
248 client.getCommonPartName(), VocabulariesCommon.class);
249 Assert.assertNotNull(vocabulary);
250 } catch (Exception e) {
251 throw new RuntimeException(e);
255 @Test(dependsOnMethods = {"createItem", "read"})
256 public void readItem() {
259 setupRead("Read Item");
261 // Submit the request to the service and store the response.
262 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
263 int statusCode = res.getStatus();
265 // Check the status code of the response: does it match
266 // the expected response(s)?
267 verbose("readItem: status = " + statusCode);
268 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
269 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
270 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
271 //FIXME: remove the following try catch once Aron fixes signatures
273 MultipartInput input = (MultipartInput) res.getEntity();
274 VocabularyitemsCommon vocabularyItem = (VocabularyitemsCommon) extractPart(input,
275 client.getItemCommonPartName(), VocabularyitemsCommon.class);
276 Assert.assertNotNull(vocabularyItem);
277 } catch (Exception e) {
278 throw new RuntimeException(e);
284 @Test(dependsOnMethods = {"read"})
285 public void readNonExistent() {
288 setupReadNonExistent();
290 // Submit the request to the service and store the response.
291 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
292 int statusCode = res.getStatus();
294 // Check the status code of the response: does it match
295 // the expected response(s)?
296 verbose("readNonExistent: status = " + res.getStatus());
297 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
298 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
299 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
302 @Test(dependsOnMethods = {"readItem", "readNonExistent"})
303 public void readItemNonExistent() {
306 setupReadNonExistent("Read Non-Existent Item");
308 // Submit the request to the service and store the response.
309 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
310 int statusCode = res.getStatus();
312 // Check the status code of the response: does it match
313 // the expected response(s)?
314 verbose("readItemNonExistent: status = " + res.getStatus());
315 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
316 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
317 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
319 // ---------------------------------------------------------------
320 // CRUD tests : READ_LIST tests
321 // ---------------------------------------------------------------
325 @Test(dependsOnMethods = {"read"})
326 public void readList() {
331 // Submit the request to the service and store the response.
332 ClientResponse<VocabulariesCommonList> res = client.readList();
333 VocabulariesCommonList list = res.getEntity();
334 int statusCode = res.getStatus();
336 // Check the status code of the response: does it match
337 // the expected response(s)?
338 verbose("readList: status = " + res.getStatus());
339 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
340 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
341 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
343 // Optionally output additional data about list members for debugging.
344 boolean iterateThroughList = false;
345 if (iterateThroughList && logger.isDebugEnabled()) {
346 List<VocabulariesCommonList.VocabularyListItem> items =
347 list.getVocabularyListItem();
349 for (VocabulariesCommonList.VocabularyListItem item : items) {
350 String csid = item.getCsid();
351 verbose("readList: list-item[" + i + "] csid=" +
353 verbose("readList: list-item[" + i + "] displayName=" +
354 item.getDisplayName());
355 verbose("readList: list-item[" + i + "] URI=" +
363 @Test(dependsOnMethods = {"readItem"})
364 public void readItemList() {
365 readItemList(knownResourceId);
368 private void readItemList(String vcsid) {
370 setupReadList("Read Item List");
372 // Submit the request to the service and store the response.
373 ClientResponse<VocabularyitemsCommonList> res =
374 client.readItemList(vcsid);
375 VocabularyitemsCommonList list = res.getEntity();
376 int statusCode = res.getStatus();
378 // Check the status code of the response: does it match
379 // the expected response(s)?
380 verbose(" readItemList: status = " + res.getStatus());
381 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
382 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
383 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
385 // Optionally output additional data about list members for debugging.
386 boolean iterateThroughList = false;
387 if (iterateThroughList && logger.isDebugEnabled()) {
388 List<VocabularyitemsCommonList.VocabularyitemListItem> items =
389 list.getVocabularyitemListItem();
391 for (VocabularyitemsCommonList.VocabularyitemListItem item : items) {
392 verbose(" readItemList: list-item[" + i + "] csid=" +
394 verbose(" readItemList: list-item[" + i + "] displayName=" +
395 item.getDisplayName());
396 verbose(" readItemList: list-item[" + i + "] URI=" +
405 // ---------------------------------------------------------------
406 // CRUD tests : UPDATE tests
407 // ---------------------------------------------------------------
410 @Test(dependsOnMethods = {"read"})
411 public void update() {
416 try { //ideally, just remove try-catch and let the exception bubble up
417 // Retrieve an existing resource that we can update.
418 ClientResponse<MultipartInput> res =
419 client.read(knownResourceId);
420 verbose("update: read status = " + res.getStatus());
421 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
423 verbose("got Vocabulary to update with ID: " + knownResourceId);
424 MultipartInput input = (MultipartInput) res.getEntity();
425 VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input,
426 client.getCommonPartName(), VocabulariesCommon.class);
427 Assert.assertNotNull(vocabulary);
429 // Update the content of this resource.
430 vocabulary.setDisplayName("updated-" + vocabulary.getDisplayName());
431 vocabulary.setVocabType("updated-" + vocabulary.getVocabType());
432 verbose("to be updated Vocabulary", vocabulary, VocabulariesCommon.class);
433 // Submit the request to the service and store the response.
434 MultipartOutput output = new MultipartOutput();
435 OutputPart commonPart = output.addPart(vocabulary, MediaType.APPLICATION_XML_TYPE);
436 commonPart.getHeaders().add("label", client.getCommonPartName());
438 res = client.update(knownResourceId, output);
439 int statusCode = res.getStatus();
440 // Check the status code of the response: does it match the expected response(s)?
441 verbose("update: status = " + res.getStatus());
442 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
443 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
444 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
447 input = (MultipartInput) res.getEntity();
448 VocabulariesCommon updatedVocabulary =
449 (VocabulariesCommon) extractPart(input,
450 client.getCommonPartName(), VocabulariesCommon.class);
451 Assert.assertNotNull(updatedVocabulary);
453 Assert.assertEquals(updatedVocabulary.getDisplayName(),
454 vocabulary.getDisplayName(),
455 "Data in updated object did not match submitted data.");
456 } catch (Exception e) {
461 @Test(dependsOnMethods = {"readItem", "update"})
462 public void updateItem() {
465 setupUpdate("Update Item");
467 try { //ideally, just remove try-catch and let the exception bubble up
468 // Retrieve an existing resource that we can update.
469 ClientResponse<MultipartInput> res =
470 client.readItem(knownResourceId, knownItemResourceId);
471 verbose("updateItem: read status = " + res.getStatus());
472 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
474 verbose("got VocabularyItem to update with ID: " + knownItemResourceId + " in Vocab: " + knownResourceId);
475 MultipartInput input = (MultipartInput) res.getEntity();
476 VocabularyitemsCommon vocabularyItem = (VocabularyitemsCommon) extractPart(input,
477 client.getItemCommonPartName(), VocabularyitemsCommon.class);
478 Assert.assertNotNull(vocabularyItem);
480 // Update the content of this resource.
481 vocabularyItem.setDisplayName("updated-" + vocabularyItem.getDisplayName());
482 verbose("to be updated VocabularyItem", vocabularyItem, VocabularyitemsCommon.class);
483 // Submit the request to the service and store the response.
484 MultipartOutput output = new MultipartOutput();
485 OutputPart commonPart = output.addPart(vocabularyItem, MediaType.APPLICATION_XML_TYPE);
486 commonPart.getHeaders().add("label", client.getItemCommonPartName());
488 res = client.updateItem(knownResourceId, knownItemResourceId, output);
489 int statusCode = res.getStatus();
490 // Check the status code of the response: does it match the expected response(s)?
491 verbose("updateItem: status = " + res.getStatus());
492 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
493 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
494 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
497 input = (MultipartInput) res.getEntity();
498 VocabularyitemsCommon updatedVocabularyItem =
499 (VocabularyitemsCommon) extractPart(input,
500 client.getItemCommonPartName(), VocabularyitemsCommon.class);
501 Assert.assertNotNull(updatedVocabularyItem);
503 Assert.assertEquals(updatedVocabularyItem.getDisplayName(),
504 vocabularyItem.getDisplayName(),
505 "Data in updated VocabularyItem did not match submitted data.");
506 } catch (Exception e) {
512 // Placeholders until the three tests below can be uncommented.
513 // See Issue CSPACE-401.
514 public void updateWithEmptyEntityBody() {
517 public void updateWithMalformedXml() {
520 public void updateWithWrongXmlSchema() {
525 @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
526 public void updateWithEmptyEntityBody() {
529 setupUpdateWithEmptyEntityBody();
531 // Submit the request to the service and store the response.
532 String method = REQUEST_TYPE.httpMethodName();
533 String url = getResourceURL(knownResourceId);
534 String mediaType = MediaType.APPLICATION_XML;
535 final String entity = "";
536 int statusCode = submitRequest(method, url, mediaType, entity);
538 // Check the status code of the response: does it match
539 // the expected response(s)?
540 verbose("updateWithEmptyEntityBody url=" + url + " status=" + statusCode);
541 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
542 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
543 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
547 @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
548 public void updateWithMalformedXml() {
551 setupUpdateWithMalformedXml();
553 // Submit the request to the service and store the response.
554 String method = REQUEST_TYPE.httpMethodName();
555 String url = getResourceURL(knownResourceId);
556 String mediaType = MediaType.APPLICATION_XML;
557 final String entity = MALFORMED_XML_DATA;
558 int statusCode = submitRequest(method, url, mediaType, entity);
560 // Check the status code of the response: does it match
561 // the expected response(s)?
562 verbose("updateWithMalformedXml: url=" + url + " status=" + statusCode);
563 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
564 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
565 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
569 @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
570 public void updateWithWrongXmlSchema() {
573 setupUpdateWithWrongXmlSchema();
575 // Submit the request to the service and store the response.
576 String method = REQUEST_TYPE.httpMethodName();
577 String url = getResourceURL(knownResourceId);
578 String mediaType = MediaType.APPLICATION_XML;
579 final String entity = WRONG_XML_SCHEMA_DATA;
580 int statusCode = submitRequest(method, url, mediaType, entity);
582 // Check the status code of the response: does it match
583 // the expected response(s)?
584 verbose("updateWithWrongSchema: url=" + url + " status=" + statusCode);
585 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
586 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
587 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
591 @Test(dependsOnMethods = {"update", "testSubmitRequest"})
592 public void updateNonExistent() {
595 setupUpdateNonExistent();
597 // Submit the request to the service and store the response.
598 // Note: The ID used in this 'create' call may be arbitrary.
599 // The only relevant ID may be the one used in update(), below.
601 // The only relevant ID may be the one used in update(), below.
602 MultipartOutput multipart = createVocabularyInstance(NON_EXISTENT_ID);
603 ClientResponse<MultipartInput> res =
604 client.update(NON_EXISTENT_ID, multipart);
605 int statusCode = res.getStatus();
607 // Check the status code of the response: does it match
608 // the expected response(s)?
609 verbose("updateNonExistent: status = " + res.getStatus());
610 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
611 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
612 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
615 @Test(dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
616 public void updateNonExistentItem() {
619 setupUpdateNonExistent("Update Non-Existent Item");
621 // Submit the request to the service and store the response.
622 // Note: The ID used in this 'create' call may be arbitrary.
623 // The only relevant ID may be the one used in update(), below.
625 // The only relevant ID may be the one used in update(), below.
626 MultipartOutput multipart = createVocabularyItemInstance(knownResourceId, NON_EXISTENT_ID);
627 ClientResponse<MultipartInput> res =
628 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
629 int statusCode = res.getStatus();
631 // Check the status code of the response: does it match
632 // the expected response(s)?
633 verbose("updateNonExistentItem: status = " + res.getStatus());
634 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
635 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
636 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
639 // ---------------------------------------------------------------
640 // CRUD tests : DELETE tests
641 // ---------------------------------------------------------------
644 @Test(dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
645 public void delete() {
650 // Submit the request to the service and store the response.
651 ClientResponse<Response> res = client.delete(knownResourceId);
652 int statusCode = res.getStatus();
654 // Check the status code of the response: does it match
655 // the expected response(s)?
656 verbose("delete: status = " + res.getStatus());
657 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
658 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
659 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
662 @Test(dependsOnMethods = {"createItem", "readItemList", "testItemSubmitRequest", "updateItem"})
663 public void deleteItem() {
666 setupDelete("Delete Item");
668 // Submit the request to the service and store the response.
669 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
670 int statusCode = res.getStatus();
672 // Check the status code of the response: does it match
673 // the expected response(s)?
674 verbose("delete: status = " + res.getStatus());
675 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
676 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
677 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
682 @Test(dependsOnMethods = {"delete"})
683 public void deleteNonExistent() {
686 setupDeleteNonExistent();
688 // Submit the request to the service and store the response.
689 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
690 int statusCode = res.getStatus();
692 // Check the status code of the response: does it match
693 // the expected response(s)?
694 verbose("deleteNonExistent: status = " + res.getStatus());
695 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
696 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
697 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
700 @Test(dependsOnMethods = {"deleteItem"})
701 public void deleteNonExistentItem() {
704 setupDeleteNonExistent("Delete Non-Existent Item");
706 // Submit the request to the service and store the response.
707 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
708 int statusCode = res.getStatus();
710 // Check the status code of the response: does it match
711 // the expected response(s)?
712 verbose("deleteNonExistent: status = " + res.getStatus());
713 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
714 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
715 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
718 // ---------------------------------------------------------------
719 // Utility tests : tests of code used in tests above
720 // ---------------------------------------------------------------
722 * Tests the code for manually submitting data that is used by several
723 * of the methods above.
725 @Test(dependsOnMethods = {"create", "read"})
726 public void testSubmitRequest() {
728 // Expected status code: 200 OK
729 final int EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();
731 // Submit the request to the service and store the response.
732 String method = ServiceRequestType.READ.httpMethodName();
733 String url = getResourceURL(knownResourceId);
734 int statusCode = submitRequest(method, url);
736 // Check the status code of the response: does it match
737 // the expected response(s)?
738 verbose("testSubmitRequest: url=" + url + " status=" + statusCode);
739 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
743 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
744 public void testItemSubmitRequest() {
746 // Expected status code: 200 OK
747 final int EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();
749 // Submit the request to the service and store the response.
750 String method = ServiceRequestType.READ.httpMethodName();
751 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
752 int statusCode = submitRequest(method, url);
754 // Check the status code of the response: does it match
755 // the expected response(s)?
756 verbose("testItemSubmitRequest: url=" + url + " status=" + statusCode);
757 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
761 // ---------------------------------------------------------------
762 // Utility methods used by tests above
763 // ---------------------------------------------------------------
765 public String getServicePathComponent() {
766 return SERVICE_PATH_COMPONENT;
769 public String getItemServicePathComponent() {
770 return ITEM_SERVICE_PATH_COMPONENT;
774 * Returns the root URL for a service.
776 * This URL consists of a base URL for all services, followed by
777 * a path component for the owning vocabulary, followed by the
778 * path component for the items.
780 * @return The root URL for a service.
782 protected String getItemServiceRootURL(String parentResourceIdentifier) {
783 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
787 * Returns the URL of a specific resource managed by a service, and
788 * designated by an identifier (such as a universally unique ID, or UUID).
790 * @param resourceIdentifier An identifier (such as a UUID) for a resource.
792 * @return The URL of a specific resource managed by a service.
794 protected String getItemResourceURL(String parentResourceIdentifier, String resourceIdentifier) {
795 return getItemServiceRootURL(parentResourceIdentifier) + "/" + resourceIdentifier;
798 private MultipartOutput createVocabularyInstance(String identifier) {
799 return createVocabularyInstance(
800 "displayName-" + identifier,
801 "vocabType-" + identifier);
804 private MultipartOutput createVocabularyInstance(String displayName, String vocabType) {
805 VocabulariesCommon vocabulary = new VocabulariesCommon();
806 vocabulary.setDisplayName(displayName);
807 vocabulary.setVocabType(vocabType);
808 MultipartOutput multipart = new MultipartOutput();
809 OutputPart commonPart = multipart.addPart(vocabulary, MediaType.APPLICATION_XML_TYPE);
810 commonPart.getHeaders().add("label", client.getCommonPartName());
812 verbose("to be created, vocabulary common ", vocabulary, VocabulariesCommon.class);
817 private MultipartOutput createVocabularyItemInstance(String inVocabulary, String displayName) {
818 VocabularyitemsCommon vocabularyItem = new VocabularyitemsCommon();
819 vocabularyItem.setInVocabulary(inVocabulary);
820 vocabularyItem.setDisplayName(displayName);
821 MultipartOutput multipart = new MultipartOutput();
822 OutputPart commonPart = multipart.addPart(vocabularyItem, MediaType.APPLICATION_XML_TYPE);
823 commonPart.getHeaders().add("label", client.getItemCommonPartName());
825 verbose("to be created, vocabularyitem common ", vocabularyItem, VocabularyitemsCommon.class);