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.testng.Assert;
40 import org.testng.annotations.Test;
43 * VocabularyServiceTest, carries out tests against a
44 * deployed and running Vocabulary Service.
46 * $LastChangedRevision: 753 $
47 * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
49 public class VocabularyServiceTest extends AbstractServiceTest {
51 // Instance variables specific to this test.
52 private VocabularyClient client = new VocabularyClient();
53 final String SERVICE_PATH_COMPONENT = "vocabularies";
54 final String ITEM_SERVICE_PATH_COMPONENT = "items";
55 private String knownResourceId = null;
56 private String knownItemResourceId = null;
58 // ---------------------------------------------------------------
59 // CRUD tests : CREATE tests
60 // ---------------------------------------------------------------
64 public void create() {
66 // Perform setup, such as initializing the type of service request
67 // (e.g. CREATE, DELETE), its valid and expected status codes, and
68 // its associated HTTP method name (e.g. POST, DELETE).
71 // Submit the request to the service and store the response.
72 String identifier = createIdentifier();
74 MultipartOutput multipart = createVocabularyInstance(identifier);
75 ClientResponse<Response> res = client.create(multipart);
77 int statusCode = res.getStatus();
79 // Check the status code of the response: does it match
80 // the expected response(s)?
83 // Does it fall within the set of valid status codes?
84 // Does it exactly match the expected status code?
85 verbose("create: status = " + statusCode);
86 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
87 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
88 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
90 // Store the ID returned from this create operation
91 // for additional tests below.
92 knownResourceId = extractId(res);
93 verbose("create: knownResourceId=" + knownResourceId);
96 @Test(dependsOnMethods = {"create"})
97 public void createItem() {
98 setupCreate("Create Item");
100 knownItemResourceId = createItemInVocab(knownResourceId);
101 verbose("createItem: knownItemResourceId=" + knownItemResourceId);
104 private String createItemInVocab(String vcsid) {
105 // Submit the request to the service and store the response.
106 String identifier = createIdentifier();
108 verbose("createItem:...");
109 MultipartOutput multipart = createVocabularyItemInstance(vcsid, identifier);
110 ClientResponse<Response> res = client.createItem(vcsid, multipart);
112 int statusCode = res.getStatus();
114 // Check the status code of the response: does it match
115 // the expected response(s)?
118 // Does it fall within the set of valid status codes?
119 // Does it exactly match the expected status code?
120 verbose("createItem: status = " + statusCode);
121 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
122 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
123 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
125 return extractId(res);
129 @Test(dependsOnMethods = {"create", "createItem"})
130 public void createList() {
131 for(int i = 0; i < 3; i++){
133 // Add 3 items to each vocab
134 for(int j = 0; j < 3; j++){
141 // Placeholders until the three tests below can be uncommented.
142 // See Issue CSPACE-401.
143 public void createWithEmptyEntityBody() {
146 public void createWithMalformedXml() {
149 public void createWithWrongXmlSchema() {
154 @Test(dependsOnMethods = {"create", "testSubmitRequest"})
155 public void createWithEmptyEntityBody() {
158 setupCreateWithEmptyEntityBody();
160 // Submit the request to the service and store the response.
161 String method = REQUEST_TYPE.httpMethodName();
162 String url = getServiceRootURL();
163 String mediaType = MediaType.APPLICATION_XML;
164 final String entity = "";
165 int statusCode = submitRequest(method, url, mediaType, entity);
167 // Check the status code of the response: does it match
168 // the expected response(s)?
169 verbose("createWithEmptyEntityBody url=" + url + " status=" + statusCode);
170 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
171 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
172 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
176 @Test(dependsOnMethods = {"create", "testSubmitRequest"})
177 public void createWithMalformedXml() {
180 setupCreateWithMalformedXml();
182 // Submit the request to the service and store the response.
183 String method = REQUEST_TYPE.httpMethodName();
184 String url = getServiceRootURL();
185 String mediaType = MediaType.APPLICATION_XML;
186 final String entity = MALFORMED_XML_DATA; // Constant from base class.
187 int statusCode = submitRequest(method, url, mediaType, entity);
189 // Check the status code of the response: does it match
190 // the expected response(s)?
191 verbose("createWithMalformedXml url=" + url + " status=" + statusCode);
192 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
193 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
194 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
198 @Test(dependsOnMethods = {"create", "testSubmitRequest"})
199 public void createWithWrongXmlSchema() {
202 setupCreateWithWrongXmlSchema();
204 // Submit the request to the service and store the response.
205 String method = REQUEST_TYPE.httpMethodName();
206 String url = getServiceRootURL();
207 String mediaType = MediaType.APPLICATION_XML;
208 final String entity = WRONG_XML_SCHEMA_DATA;
209 int statusCode = submitRequest(method, url, mediaType, entity);
211 // Check the status code of the response: does it match
212 // the expected response(s)?
213 verbose("createWithWrongSchema url=" + url + " status=" + statusCode);
214 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
215 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
216 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
219 // ---------------------------------------------------------------
220 // CRUD tests : READ tests
221 // ---------------------------------------------------------------
224 @Test(dependsOnMethods = {"create"})
230 // Submit the request to the service and store the response.
231 ClientResponse<MultipartInput> res = client.read(knownResourceId);
232 int statusCode = res.getStatus();
234 // Check the status code of the response: does it match
235 // the expected response(s)?
236 verbose("read: status = " + statusCode);
237 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
238 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
239 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
240 //FIXME: remove the following try catch once Aron fixes signatures
242 MultipartInput input = (MultipartInput) res.getEntity();
243 VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input,
244 client.getCommonPartName(), VocabulariesCommon.class);
245 Assert.assertNotNull(vocabulary);
247 throw new RuntimeException(e);
251 @Test(dependsOnMethods = {"createItem", "read"})
252 public void readItem() {
255 setupRead("Read Item");
257 // Submit the request to the service and store the response.
258 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
259 int statusCode = res.getStatus();
261 // Check the status code of the response: does it match
262 // the expected response(s)?
263 verbose("readItem: status = " + statusCode);
264 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
265 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
266 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
267 //FIXME: remove the following try catch once Aron fixes signatures
269 MultipartInput input = (MultipartInput) res.getEntity();
270 VocabularyitemsCommon vocabularyItem = (VocabularyitemsCommon) extractPart(input,
271 client.getItemCommonPartName(), VocabularyitemsCommon.class);
272 Assert.assertNotNull(vocabularyItem);
274 throw new RuntimeException(e);
280 @Test(dependsOnMethods = {"read"})
281 public void readNonExistent() {
284 setupReadNonExistent();
286 // Submit the request to the service and store the response.
287 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
288 int statusCode = res.getStatus();
290 // Check the status code of the response: does it match
291 // the expected response(s)?
292 verbose("readNonExistent: status = " + res.getStatus());
293 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
294 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
295 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
298 @Test(dependsOnMethods = {"readItem", "readNonExistent"})
299 public void readItemNonExistent() {
302 setupReadNonExistent("Read Non-Existent Item");
304 // Submit the request to the service and store the response.
305 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
306 int statusCode = res.getStatus();
308 // Check the status code of the response: does it match
309 // the expected response(s)?
310 verbose("readItemNonExistent: status = " + res.getStatus());
311 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
312 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
313 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
315 // ---------------------------------------------------------------
316 // CRUD tests : READ_LIST tests
317 // ---------------------------------------------------------------
320 @Test(dependsOnMethods = {"read"})
321 public void readList() {
326 // Submit the request to the service and store the response.
327 ClientResponse<VocabulariesCommonList> res = client.readList();
328 VocabulariesCommonList list = res.getEntity();
329 int statusCode = res.getStatus();
331 // Check the status code of the response: does it match
332 // the expected response(s)?
333 verbose("readList: status = " + res.getStatus());
334 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
335 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
336 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
338 // Optionally output additional data about list members for debugging.
339 boolean iterateThroughList = false;
340 if(iterateThroughList && logger.isDebugEnabled()){
341 List<VocabulariesCommonList.VocabularyListItem> items =
342 list.getVocabularyListItem();
344 for(VocabulariesCommonList.VocabularyListItem item : items){
345 String csid = item.getCsid();
346 verbose("readList: list-item[" + i + "] csid=" +
348 verbose("readList: list-item[" + i + "] displayName=" +
349 item.getDisplayName());
350 verbose("readList: list-item[" + i + "] URI=" +
358 @Test(dependsOnMethods = {"readItem"})
359 public void readItemList() {
360 readItemList(knownResourceId);
363 private void readItemList(String vcsid) {
365 setupReadList("Read Item List");
367 // Submit the request to the service and store the response.
368 ClientResponse<VocabularyitemsCommonList> res =
369 client.readItemList(vcsid);
370 VocabularyitemsCommonList list = res.getEntity();
371 int statusCode = res.getStatus();
373 // Check the status code of the response: does it match
374 // the expected response(s)?
375 verbose(" readItemList: status = " + res.getStatus());
376 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
377 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
378 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
380 // Optionally output additional data about list members for debugging.
381 boolean iterateThroughList = false;
382 if(iterateThroughList && logger.isDebugEnabled()){
383 List<VocabularyitemsCommonList.VocabularyitemListItem> items =
384 list.getVocabularyitemListItem();
386 for(VocabularyitemsCommonList.VocabularyitemListItem item : items){
387 verbose(" readItemList: list-item[" + i + "] csid=" +
389 verbose(" readItemList: list-item[" + i + "] displayName=" +
390 item.getDisplayName());
391 verbose(" readItemList: list-item[" + i + "] URI=" +
400 // ---------------------------------------------------------------
401 // CRUD tests : UPDATE tests
402 // ---------------------------------------------------------------
405 @Test(dependsOnMethods = {"read"})
406 public void update() {
411 try{ //ideally, just remove try-catch and let the exception bubble up
412 // Retrieve an existing resource that we can update.
413 ClientResponse<MultipartInput> res =
414 client.read(knownResourceId);
415 verbose("update: read status = " + res.getStatus());
416 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
418 verbose("got Vocabulary to update with ID: " + knownResourceId);
419 MultipartInput input = (MultipartInput) res.getEntity();
420 VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input,
421 client.getCommonPartName(), VocabulariesCommon.class);
422 Assert.assertNotNull(vocabulary);
424 // Update the content of this resource.
425 vocabulary.setDisplayName("updated-" + vocabulary.getDisplayName());
426 vocabulary.setVocabType("updated-" + vocabulary.getVocabType());
427 verbose("to be updated Vocabulary", vocabulary, VocabulariesCommon.class);
428 // Submit the request to the service and store the response.
429 MultipartOutput output = new MultipartOutput();
430 OutputPart commonPart = output.addPart(vocabulary, MediaType.APPLICATION_XML_TYPE);
431 commonPart.getHeaders().add("label", client.getCommonPartName());
433 res = client.update(knownResourceId, output);
434 int statusCode = res.getStatus();
435 // Check the status code of the response: does it match the expected response(s)?
436 verbose("update: status = " + res.getStatus());
437 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
438 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
439 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
442 input = (MultipartInput) res.getEntity();
443 VocabulariesCommon updatedVocabulary =
444 (VocabulariesCommon) extractPart(input,
445 client.getCommonPartName(), VocabulariesCommon.class);
446 Assert.assertNotNull(updatedVocabulary);
448 Assert.assertEquals(updatedVocabulary.getDisplayName(),
449 vocabulary.getDisplayName(),
450 "Data in updated object did not match submitted data.");
456 @Test(dependsOnMethods = {"readItem", "update"})
457 public void updateItem() {
460 setupUpdate("Update Item");
462 try{ //ideally, just remove try-catch and let the exception bubble up
463 // Retrieve an existing resource that we can update.
464 ClientResponse<MultipartInput> res =
465 client.readItem(knownResourceId, knownItemResourceId);
466 verbose("updateItem: read status = " + res.getStatus());
467 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
469 verbose("got VocabularyItem to update with ID: " + knownItemResourceId
470 + " in Vocab: " + knownResourceId );
471 MultipartInput input = (MultipartInput) res.getEntity();
472 VocabularyitemsCommon vocabularyItem = (VocabularyitemsCommon) extractPart(input,
473 client.getItemCommonPartName(), VocabularyitemsCommon.class);
474 Assert.assertNotNull(vocabularyItem);
476 // Update the content of this resource.
477 vocabularyItem.setDisplayName("updated-" + vocabularyItem.getDisplayName());
478 verbose("to be updated VocabularyItem", vocabularyItem, VocabularyitemsCommon.class);
479 // Submit the request to the service and store the response.
480 MultipartOutput output = new MultipartOutput();
481 OutputPart commonPart = output.addPart(vocabularyItem, MediaType.APPLICATION_XML_TYPE);
482 commonPart.getHeaders().add("label", client.getItemCommonPartName());
484 res = client.updateItem(knownResourceId, knownItemResourceId, output);
485 int statusCode = res.getStatus();
486 // Check the status code of the response: does it match the expected response(s)?
487 verbose("updateItem: status = " + res.getStatus());
488 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
489 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
490 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
493 input = (MultipartInput) res.getEntity();
494 VocabularyitemsCommon updatedVocabularyItem =
495 (VocabularyitemsCommon) extractPart(input,
496 client.getItemCommonPartName(), VocabularyitemsCommon.class);
497 Assert.assertNotNull(updatedVocabularyItem);
499 Assert.assertEquals(updatedVocabularyItem.getDisplayName(),
500 vocabularyItem.getDisplayName(),
501 "Data in updated VocabularyItem did not match submitted data.");
508 // Placeholders until the three tests below can be uncommented.
509 // See Issue CSPACE-401.
510 public void updateWithEmptyEntityBody() {
513 public void updateWithMalformedXml() {
516 public void updateWithWrongXmlSchema() {
521 @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
522 public void updateWithEmptyEntityBody() {
525 setupUpdateWithEmptyEntityBody();
527 // Submit the request to the service and store the response.
528 String method = REQUEST_TYPE.httpMethodName();
529 String url = getResourceURL(knownResourceId);
530 String mediaType = MediaType.APPLICATION_XML;
531 final String entity = "";
532 int statusCode = submitRequest(method, url, mediaType, entity);
534 // Check the status code of the response: does it match
535 // the expected response(s)?
536 verbose("updateWithEmptyEntityBody url=" + url + " status=" + statusCode);
537 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
538 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
539 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
543 @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
544 public void updateWithMalformedXml() {
547 setupUpdateWithMalformedXml();
549 // Submit the request to the service and store the response.
550 String method = REQUEST_TYPE.httpMethodName();
551 String url = getResourceURL(knownResourceId);
552 String mediaType = MediaType.APPLICATION_XML;
553 final String entity = MALFORMED_XML_DATA;
554 int statusCode = submitRequest(method, url, mediaType, entity);
556 // Check the status code of the response: does it match
557 // the expected response(s)?
558 verbose("updateWithMalformedXml: url=" + url + " status=" + statusCode);
559 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
560 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
561 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
565 @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
566 public void updateWithWrongXmlSchema() {
569 setupUpdateWithWrongXmlSchema();
571 // Submit the request to the service and store the response.
572 String method = REQUEST_TYPE.httpMethodName();
573 String url = getResourceURL(knownResourceId);
574 String mediaType = MediaType.APPLICATION_XML;
575 final String entity = WRONG_XML_SCHEMA_DATA;
576 int statusCode = submitRequest(method, url, mediaType, entity);
578 // Check the status code of the response: does it match
579 // the expected response(s)?
580 verbose("updateWithWrongSchema: url=" + url + " status=" + statusCode);
581 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
582 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
583 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
588 @Test(dependsOnMethods = {"update", "testSubmitRequest"})
589 public void updateNonExistent() {
592 setupUpdateNonExistent();
594 // Submit the request to the service and store the response.
595 // Note: The ID used in this 'create' call may be arbitrary.
596 // The only relevant ID may be the one used in update(), below.
598 // The only relevant ID may be the one used in update(), below.
599 MultipartOutput multipart = createVocabularyInstance(NON_EXISTENT_ID);
600 ClientResponse<MultipartInput> res =
601 client.update(NON_EXISTENT_ID, multipart);
602 int statusCode = res.getStatus();
604 // Check the status code of the response: does it match
605 // the expected response(s)?
606 verbose("updateNonExistent: status = " + res.getStatus());
607 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
608 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
609 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
612 @Test(dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
613 public void updateNonExistentItem() {
616 setupUpdateNonExistent("Update Non-Existent Item");
618 // Submit the request to the service and store the response.
619 // Note: The ID used in this 'create' call may be arbitrary.
620 // The only relevant ID may be the one used in update(), below.
622 // The only relevant ID may be the one used in update(), below.
623 MultipartOutput multipart = createVocabularyItemInstance(knownResourceId, NON_EXISTENT_ID);
624 ClientResponse<MultipartInput> res =
625 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
626 int statusCode = res.getStatus();
628 // Check the status code of the response: does it match
629 // the expected response(s)?
630 verbose("updateNonExistentItem: status = " + res.getStatus());
631 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
632 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
633 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
636 // ---------------------------------------------------------------
637 // CRUD tests : DELETE tests
638 // ---------------------------------------------------------------
641 @Test(dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
642 public void delete() {
647 // Submit the request to the service and store the response.
648 ClientResponse<Response> res = client.delete(knownResourceId);
649 int statusCode = res.getStatus();
651 // Check the status code of the response: does it match
652 // the expected response(s)?
653 verbose("delete: status = " + res.getStatus());
654 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
655 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
656 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
659 @Test(dependsOnMethods = {"createItem", "readItemList", "testItemSubmitRequest", "updateItem"})
660 public void deleteItem() {
663 setupDelete("Delete Item");
665 // Submit the request to the service and store the response.
666 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
667 int statusCode = res.getStatus();
669 // Check the status code of the response: does it match
670 // the expected response(s)?
671 verbose("delete: status = " + res.getStatus());
672 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
673 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
674 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
679 @Test(dependsOnMethods = {"delete"})
680 public void deleteNonExistent() {
683 setupDeleteNonExistent();
685 // Submit the request to the service and store the response.
686 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
687 int statusCode = res.getStatus();
689 // Check the status code of the response: does it match
690 // the expected response(s)?
691 verbose("deleteNonExistent: status = " + res.getStatus());
692 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
693 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
694 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
697 @Test(dependsOnMethods = {"deleteItem"})
698 public void deleteNonExistentItem() {
701 setupDeleteNonExistent("Delete Non-Existent Item");
703 // Submit the request to the service and store the response.
704 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
705 int statusCode = res.getStatus();
707 // Check the status code of the response: does it match
708 // the expected response(s)?
709 verbose("deleteNonExistent: status = " + res.getStatus());
710 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
711 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
712 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
715 // ---------------------------------------------------------------
716 // Utility tests : tests of code used in tests above
717 // ---------------------------------------------------------------
719 * Tests the code for manually submitting data that is used by several
720 * of the methods above.
722 @Test(dependsOnMethods = {"create", "read"})
723 public void testSubmitRequest() {
725 // Expected status code: 200 OK
726 final int EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();
728 // Submit the request to the service and store the response.
729 String method = ServiceRequestType.READ.httpMethodName();
730 String url = getResourceURL(knownResourceId);
731 int statusCode = submitRequest(method, url);
733 // Check the status code of the response: does it match
734 // the expected response(s)?
735 verbose("testSubmitRequest: url=" + url + " status=" + statusCode);
736 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
740 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
741 public void testItemSubmitRequest() {
743 // Expected status code: 200 OK
744 final int EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode();
746 // Submit the request to the service and store the response.
747 String method = ServiceRequestType.READ.httpMethodName();
748 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
749 int statusCode = submitRequest(method, url);
751 // Check the status code of the response: does it match
752 // the expected response(s)?
753 verbose("testItemSubmitRequest: url=" + url + " status=" + statusCode);
754 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
758 // ---------------------------------------------------------------
759 // Utility methods used by tests above
760 // ---------------------------------------------------------------
762 public String getServicePathComponent() {
763 return SERVICE_PATH_COMPONENT;
766 public String getItemServicePathComponent() {
767 return ITEM_SERVICE_PATH_COMPONENT;
771 * Returns the root URL for a service.
773 * This URL consists of a base URL for all services, followed by
774 * a path component for the owning vocabulary, followed by the
775 * path component for the items.
777 * @return The root URL for a service.
779 protected String getItemServiceRootURL(String parentResourceIdentifier) {
780 return getResourceURL(parentResourceIdentifier)+"/"+getItemServicePathComponent();
784 * Returns the URL of a specific resource managed by a service, and
785 * designated by an identifier (such as a universally unique ID, or UUID).
787 * @param resourceIdentifier An identifier (such as a UUID) for a resource.
789 * @return The URL of a specific resource managed by a service.
791 protected String getItemResourceURL(String parentResourceIdentifier, String resourceIdentifier) {
792 return getItemServiceRootURL(parentResourceIdentifier) + "/" + resourceIdentifier;
795 private MultipartOutput createVocabularyInstance(String identifier) {
796 return createVocabularyInstance(
797 "displayName-" + identifier,
798 "vocabType-" + identifier);
801 private MultipartOutput createVocabularyInstance(String displayName, String vocabType) {
802 VocabulariesCommon vocabulary = new VocabulariesCommon();
803 vocabulary.setDisplayName(displayName);
804 vocabulary.setVocabType(vocabType);
805 MultipartOutput multipart = new MultipartOutput();
806 OutputPart commonPart = multipart.addPart(vocabulary, MediaType.APPLICATION_XML_TYPE);
807 commonPart.getHeaders().add("label", client.getCommonPartName());
809 verbose("to be created, vocabulary common ", vocabulary, VocabulariesCommon.class);
814 private MultipartOutput createVocabularyItemInstance(String inVocabulary, String displayName) {
815 VocabularyitemsCommon vocabularyItem = new VocabularyitemsCommon();
816 vocabularyItem.setInVocabulary(inVocabulary);
817 vocabularyItem.setDisplayName(displayName);
818 MultipartOutput multipart = new MultipartOutput();
819 OutputPart commonPart = multipart.addPart(vocabularyItem, MediaType.APPLICATION_XML_TYPE);
820 commonPart.getHeaders().add("label", client.getItemCommonPartName());
822 verbose("to be created, vocabularyitem common ", vocabularyItem, VocabularyitemsCommon.class);