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 © 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;
26 import javax.ws.rs.core.MediaType;
27 import javax.ws.rs.core.Response;
29 import org.collectionspace.services.client.CollectionSpaceClient;
30 import org.collectionspace.services.client.RelationClient;
31 import org.collectionspace.services.jaxb.AbstractCommonList;
32 import org.collectionspace.services.relation.RelationsCommon;
33 import org.collectionspace.services.relation.RelationsCommonList;
34 import org.collectionspace.services.relation.RelationshipType;
36 import org.jboss.resteasy.client.ClientResponse;
38 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
39 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
40 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
41 import org.testng.Assert;
42 import org.testng.annotations.Test;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
48 * RelationServiceTest, carries out tests against a
49 * deployed and running Relation Service.
51 * $LastChangedRevision$
54 public class RelationServiceTest extends AbstractServiceTestImpl {
57 private final String CLASS_NAME = RelationServiceTest.class.getName();
58 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
60 /** The SERVICE path component. */
61 final String SERVICE_PATH_COMPONENT = "relations";
63 /** The known resource id. */
64 private String knownResourceId = null;
67 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
70 protected CollectionSpaceClient getClientInstance() {
71 return new RelationClient();
75 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
78 protected AbstractCommonList getAbstractCommonList(
79 ClientResponse<AbstractCommonList> response) {
80 return response.getEntity(RelationsCommonList.class);
83 // ---------------------------------------------------------------
84 // CRUD tests : CREATE tests
85 // ---------------------------------------------------------------
88 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
90 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
92 public void create(String testName) throws Exception {
94 if (logger.isDebugEnabled()) {
95 logger.debug(testBanner(testName, CLASS_NAME));
97 // Perform setup, such as initializing the type of service request
98 // (e.g. CREATE, DELETE), its valid and expected status codes, and
99 // its associated HTTP method name (e.g. POST, DELETE).
102 // Submit the request to the service and store the response.
103 RelationClient client = new RelationClient();
104 String identifier = createIdentifier();
105 MultipartOutput multipart = createRelationInstance(identifier);
106 ClientResponse<Response> res = client.create(multipart);
107 int statusCode = res.getStatus();
109 // Check the status code of the response: does it match
110 // the expected response(s)?
112 // Does it fall within the set of valid status codes?
113 // Does it exactly match the expected status code?
114 if(logger.isDebugEnabled()){
115 logger.debug(testName + ": status = " + statusCode);
117 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
118 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
119 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
121 // Store the ID returned from the first resource created
122 // for additional tests below.
123 if (knownResourceId == null){
124 knownResourceId = extractId(res);
125 if (logger.isDebugEnabled()) {
126 logger.debug(testName + ": knownResourceId=" + knownResourceId);
130 // Store the IDs from every resource created by tests,
131 // so they can be deleted after tests have been run.
132 allResourceIdsCreated.add(extractId(res));
136 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
139 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
140 dependsOnMethods = {"create"})
141 public void createList(String testName) throws Exception {
142 for(int i = 0; i < 3; i++){
147 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
148 dependsOnMethods = {"create"})
149 public void createWithSelfRelation(String testName) throws Exception {
151 if (logger.isDebugEnabled()) {
152 logger.debug(testBanner(testName, CLASS_NAME));
155 setupCreateWithInvalidBody();
157 // Submit the request to the service and store the response.
158 RelationClient client = new RelationClient();
159 String identifier = createIdentifier();
160 RelationsCommon relationsCommon = createRelationsCommon(identifier);
161 // Make the subject ID equal to the object ID
162 relationsCommon.setDocumentId1(relationsCommon.getDocumentId2());
163 MultipartOutput multipart = createRelationInstance(relationsCommon);
164 ClientResponse<Response> res = client.create(multipart);
165 int statusCode = res.getStatus();
167 // Check the status code of the response: does it match
168 // the expected response(s)?
170 // Does it fall within the set of valid status codes?
171 // Does it exactly match the expected status code?
172 if(logger.isDebugEnabled()){
173 logger.debug(testName + ": status = " + statusCode);
175 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
176 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
177 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
181 // Placeholders until the three tests below can be uncommented.
182 // See Issue CSPACE-401.
184 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
187 public void createWithEmptyEntityBody(String testName) throws Exception {
188 //Should this test really be empty?
192 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
195 public void createWithMalformedXml(String testName) throws Exception {
196 //Should this test really be empty?
200 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
203 public void createWithWrongXmlSchema(String testName) throws Exception {
204 //Should this test really be empty?
209 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
210 dependsOnMethods = {"create", "testSubmitRequest"})
211 public void createWithEmptyEntityBody(String testName) throws Exception {
213 if (logger.isDebugEnabled()) {
214 logger.debug(testBanner(testName, CLASS_NAME));
217 setupCreateWithEmptyEntityBody();
219 // Submit the request to the service and store the response.
220 String method = REQUEST_TYPE.httpMethodName();
221 String url = getServiceRootURL();
222 String mediaType = MediaType.APPLICATION_XML;
223 final String entity = "";
224 int statusCode = submitRequest(method, url, mediaType, entity);
226 // Check the status code of the response: does it match
227 // the expected response(s)?
228 if(logger.isDebugEnabled()){
229 logger.debug(testName + ": url=" + url +
230 " status=" + statusCode);
232 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
233 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
234 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
238 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
239 dependsOnMethods = {"create", "testSubmitRequest"})
240 public void createWithMalformedXml(String testName) throws Exception {
242 if (logger.isDebugEnabled()) {
243 logger.debug(testBanner(testName, CLASS_NAME));
246 setupCreateWithMalformedXml();
248 // Submit the request to the service and store the response.
249 String method = REQUEST_TYPE.httpMethodName();
250 String url = getServiceRootURL();
251 String mediaType = MediaType.APPLICATION_XML;
252 final String entity = MALFORMED_XML_DATA; // Constant from base class.
253 int statusCode = submitRequest(method, url, mediaType, entity);
255 // Check the status code of the response: does it match
256 // the expected response(s)?
257 if(logger.isDebugEnabled()){
258 logger.debug(testName + ": url=" + url +
259 " status=" + statusCode);
261 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
262 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
263 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
267 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
268 dependsOnMethods = {"create", "testSubmitRequest"})
269 public void createWithWrongXmlSchema(String testName) throws Exception {
271 if (logger.isDebugEnabled()) {
272 logger.debug(testBanner(testName, CLASS_NAME));
275 setupCreateWithWrongXmlSchema();
277 // Submit the request to the service and store the response.
278 String method = REQUEST_TYPE.httpMethodName();
279 String url = getServiceRootURL();
280 String mediaType = MediaType.APPLICATION_XML;
281 final String entity = WRONG_XML_SCHEMA_DATA;
282 int statusCode = submitRequest(method, url, mediaType, entity);
284 // Check the status code of the response: does it match
285 // the expected response(s)?
286 if(logger.isDebugEnabled()){
287 logger.debug(testName + ": url=" + url +
288 " status=" + statusCode);
290 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
291 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
292 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
296 // ---------------------------------------------------------------
297 // CRUD tests : READ tests
298 // ---------------------------------------------------------------
301 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
304 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
305 dependsOnMethods = {"create"})
306 public void read(String testName) throws Exception {
308 if (logger.isDebugEnabled()) {
309 logger.debug(testBanner(testName, CLASS_NAME));
314 // Submit the request to the service and store the response.
315 RelationClient client = new RelationClient();
316 ClientResponse<MultipartInput> res = client.read(knownResourceId);
317 int statusCode = res.getStatus();
319 // Check the status code of the response: does it match
320 // the expected response(s)?
321 if(logger.isDebugEnabled()){
322 logger.debug(testName + ": status = " + statusCode);
324 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
325 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
326 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
328 // Verify that the resource identifier ...
329 MultipartInput input = (MultipartInput) res.getEntity();
330 RelationsCommon relation = (RelationsCommon) extractPart(input,
331 client.getCommonPartName(), RelationsCommon.class);
332 Assert.assertNotNull(relation);
338 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
341 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
342 dependsOnMethods = {"read"})
343 public void readNonExistent(String testName) throws Exception {
345 if (logger.isDebugEnabled()) {
346 logger.debug(testBanner(testName, CLASS_NAME));
349 setupReadNonExistent();
351 // Submit the request to the service and store the response.
352 RelationClient client = new RelationClient();
353 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
354 int statusCode = res.getStatus();
356 // Check the status code of the response: does it match
357 // the expected response(s)?
358 if(logger.isDebugEnabled()){
359 logger.debug(testName + ": status = " + statusCode);
361 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
362 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
363 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
366 // ---------------------------------------------------------------
367 // CRUD tests : READ_LIST tests
368 // ---------------------------------------------------------------
371 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
374 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
375 dependsOnMethods = {"createList", "read"})
376 public void readList(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 RelationClient client = new RelationClient();
386 ClientResponse<RelationsCommonList> res = client.readList();
387 RelationsCommonList list = res.getEntity();
388 int statusCode = res.getStatus();
390 // Check the status code of the response: does it match
391 // the expected response(s)?
392 if(logger.isDebugEnabled()){
393 logger.debug(testName + ": status = " + statusCode);
395 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
396 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
397 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
399 // Optionally output additional data about list members for debugging.
400 boolean iterateThroughList = false;
401 if(iterateThroughList && logger.isDebugEnabled()){
402 List<RelationsCommonList.RelationListItem> items =
403 list.getRelationListItem();
405 for(RelationsCommonList.RelationListItem item : items){
406 logger.debug(testName + ": list-item[" + i + "] csid=" +
408 logger.debug(testName + ": list-item[" + i + "] URI=" +
417 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
418 dependsOnMethods = {"createList", "read"})
419 public void readListPaginated(String testName) throws Exception {
421 if (logger.isDebugEnabled()) {
422 logger.debug(testBanner(testName, CLASS_NAME));
429 RelationClient client = new RelationClient();
430 ClientResponse<RelationsCommonList> res = client.readList("", //subjectCsid,
438 RelationsCommonList list = res.getEntity();
439 int statusCode = res.getStatus();
441 // Check the status code of the response: does it match
442 // the expected response(s)?
443 if(logger.isDebugEnabled()){
444 logger.debug(testName + ": status = " + statusCode);
446 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
447 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
448 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
450 // Optionally output additional data about list members for debugging.
451 boolean iterateThroughList = false;
452 if(iterateThroughList && logger.isDebugEnabled()){
453 List<RelationsCommonList.RelationListItem> items =
454 list.getRelationListItem();
456 for(RelationsCommonList.RelationListItem item : items){
457 logger.debug(testName + ": list-item[" + i + "] csid=" +
459 logger.debug(testName + ": list-item[" + i + "] URI=" +
471 // ---------------------------------------------------------------
472 // CRUD tests : UPDATE tests
473 // ---------------------------------------------------------------
477 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
480 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
481 dependsOnMethods = {"read"})
482 public void update(String testName) throws Exception {
484 if (logger.isDebugEnabled()) {
485 logger.debug(testBanner(testName, CLASS_NAME));
490 // Retrieve an existing resource that we can update.
491 RelationClient client = new RelationClient();
492 ClientResponse<MultipartInput> res =
493 client.read(knownResourceId);
494 if(logger.isDebugEnabled()){
495 logger.debug(testName + ": read status = " + res.getStatus());
497 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
498 if(logger.isDebugEnabled()){
499 logger.debug("Got object to update with ID: " + knownResourceId);
501 MultipartInput input = (MultipartInput) res.getEntity();
502 RelationsCommon relation = (RelationsCommon) extractPart(input,
503 client.getCommonPartName(), RelationsCommon.class);
504 Assert.assertNotNull(relation);
506 // Update the content of this resource.
507 relation.setDocumentId1("updated-" + relation.getDocumentId1());
508 relation.setDocumentType1("updated-" + relation.getDocumentType1());
509 relation.setDocumentId2("updated-" + relation.getDocumentId2());
510 relation.setDocumentType2("updated-" + relation.getDocumentType2());
511 relation.setPredicateDisplayName("updated-" + relation.getPredicateDisplayName());
512 if(logger.isDebugEnabled()){
513 logger.debug("updated object");
514 logger.debug(objectAsXmlString(relation, RelationsCommon.class));
517 // Submit the request to the service and store the response.
518 MultipartOutput output = new MultipartOutput();
519 OutputPart commonPart = output.addPart(relation, MediaType.APPLICATION_XML_TYPE);
520 commonPart.getHeaders().add("label", client.getCommonPartName());
521 res = client.update(knownResourceId, output);
522 int statusCode = res.getStatus();
524 // Check the status code of the response: does it match the expected response(s)?
525 if(logger.isDebugEnabled()){
526 logger.debug(testName + ": status = " + statusCode);
528 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
529 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
530 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
532 input = (MultipartInput) res.getEntity();
533 RelationsCommon updatedObject = (RelationsCommon) extractPart(
534 input, client.getCommonPartName(),
535 RelationsCommon.class);
536 Assert.assertNotNull(updatedObject);
539 "Data in updated object did not match submitted data.";
541 updatedObject.getDocumentId1(), relation.getDocumentId1(), msg);
543 updatedObject.getDocumentType1(), relation.getDocumentType1(), msg);
545 updatedObject.getDocumentId2(), relation.getDocumentId2(), msg);
547 updatedObject.getDocumentType2(), relation.getDocumentType2(), msg);
549 updatedObject.getPredicateDisplayName(), relation.getPredicateDisplayName(), msg);
554 // Placeholders until the three tests below can be uncommented.
555 // See Issue CSPACE-401.
557 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
560 public void updateWithEmptyEntityBody(String testName) throws Exception {
561 //Should this test really be empty?
565 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
568 public void updateWithMalformedXml(String testName) throws Exception {
569 //Should this test really be empty?
573 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
576 public void updateWithWrongXmlSchema(String testName) throws Exception {
577 //Should this test really be empty?
582 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
583 dependsOnMethods = {"create", "update", "testSubmitRequest"})
584 public void updateWithEmptyEntityBody(String testName) throws Exception {
586 if (logger.isDebugEnabled()) {
587 logger.debug(testBanner(testName, CLASS_NAME));
590 setupUpdateWithEmptyEntityBody();
592 // Submit the request to the service and store the response.
593 String method = REQUEST_TYPE.httpMethodName();
594 String url = getResourceURL(knownResourceId);
595 String mediaType = MediaType.APPLICATION_XML;
596 final String entity = "";
597 int statusCode = submitRequest(method, url, mediaType, entity);
599 // Check the status code of the response: does it match
600 // the expected response(s)?
601 if(logger.isDebugEnabled()){
602 logger.debug(testName + ": url=" + url +
603 " status=" + statusCode);
605 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
606 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
607 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
611 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
612 dependsOnMethods = {"create", "update", "testSubmitRequest"})
613 public void updateWithMalformedXml(String testName) throws Exception {
615 if (logger.isDebugEnabled()) {
616 logger.debug(testBanner(testName, CLASS_NAME));
619 setupUpdateWithMalformedXml();
621 // Submit the request to the service and store the response.
622 String method = REQUEST_TYPE.httpMethodName();
623 String url = getResourceURL(knownResourceId);
624 String mediaType = MediaType.APPLICATION_XML;
625 final String entity = MALFORMED_XML_DATA; // Constant from abstract base class.
626 int statusCode = submitRequest(method, url, mediaType, entity);
628 // Check the status code of the response: does it match
629 // the expected response(s)?
630 if(logger.isDebugEnabled()){
631 logger.debug(testName + ": url=" + url +
632 " status=" + statusCode);
634 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
635 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
636 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
640 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
641 dependsOnMethods = {"create", "update", "testSubmitRequest"})
642 public void updateWithWrongXmlSchema(String testName) throws Exception {
644 if (logger.isDebugEnabled()) {
645 logger.debug(testBanner(testName, CLASS_NAME));
648 setupUpdateWithWrongXmlSchema();
650 // Submit the request to the service and store the response.
651 String method = REQUEST_TYPE.httpMethodName();
652 String url = getResourceURL(knownResourceId);
653 String mediaType = MediaType.APPLICATION_XML;
654 final String entity = WRONG_XML_SCHEMA_DATA; // Constant from abstract base class.
655 int statusCode = submitRequest(method, url, mediaType, entity);
657 // Check the status code of the response: does it match
658 // the expected response(s)?
659 if(logger.isDebugEnabled()){
660 logger.debug(testName + ": url=" + url +
661 " status=" + statusCode);
663 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
664 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
665 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
670 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
673 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
674 dependsOnMethods = {"update", "testSubmitRequest"})
675 public void updateNonExistent(String testName) throws Exception {
677 if (logger.isDebugEnabled()) {
678 logger.debug(testBanner(testName, CLASS_NAME));
681 setupUpdateNonExistent();
683 // Submit the request to the service and store the response.
684 // Note: The ID used in this 'create' call may be arbitrary.
685 // The only relevant ID may be the one used in update(), below.
686 RelationClient client = new RelationClient();
687 MultipartOutput multipart = createRelationInstance(NON_EXISTENT_ID);
688 ClientResponse<MultipartInput> res =
689 client.update(NON_EXISTENT_ID, multipart);
690 int statusCode = res.getStatus();
692 // Check the status code of the response: does it match
693 // the expected response(s)?
694 if(logger.isDebugEnabled()){
695 logger.debug(testName + ": status = " + statusCode);
697 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
698 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
699 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
702 // ---------------------------------------------------------------
703 // CRUD tests : DELETE tests
704 // ---------------------------------------------------------------
707 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
710 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
711 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
712 public void delete(String testName) throws Exception {
714 if (logger.isDebugEnabled()) {
715 logger.debug(testBanner(testName, CLASS_NAME));
720 // Submit the request to the service and store the response.
721 RelationClient client = new RelationClient();
722 ClientResponse<Response> res = client.delete(knownResourceId);
723 int statusCode = res.getStatus();
725 // Check the status code of the response: does it match
726 // the expected response(s)?
727 if(logger.isDebugEnabled()){
728 logger.debug(testName + ": status = " + statusCode);
730 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
731 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
732 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
737 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
740 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
741 dependsOnMethods = {"delete"})
742 public void deleteNonExistent(String testName) throws Exception {
744 if (logger.isDebugEnabled()) {
745 logger.debug(testBanner(testName, CLASS_NAME));
748 setupDeleteNonExistent();
750 // Submit the request to the service and store the response.
751 RelationClient client = new RelationClient();
752 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
753 int statusCode = res.getStatus();
755 // Check the status code of the response: does it match
756 // the expected response(s)?
757 if(logger.isDebugEnabled()){
758 logger.debug(testName + ": status = " + statusCode);
760 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
761 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
762 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
765 // ---------------------------------------------------------------
766 // RELATE_OBJECT tests
767 // ---------------------------------------------------------------
771 @Test(dependsOnMethods = {"create"})
772 public void relateObjects() {
773 //Should this test really be empty?
776 // ---------------------------------------------------------------
777 // Utility tests : tests of code used in tests above
778 // ---------------------------------------------------------------
780 * Tests the code for manually submitting data that is used by several
781 * of the methods above.
783 @Test(dependsOnMethods = {"create", "read"})
784 public void testSubmitRequest() {
788 // Submit the request to the service and store the response.
789 String method = ServiceRequestType.READ.httpMethodName();
790 String url = getResourceURL(knownResourceId);
791 int statusCode = submitRequest(method, url);
793 // Check the status code of the response: does it match
794 // the expected response(s)?
795 if(logger.isDebugEnabled()){
796 logger.debug("testSubmitRequest: url=" + url +
797 " status=" + statusCode);
799 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
802 // ---------------------------------------------------------------
803 // Utility methods used by tests above
804 // ---------------------------------------------------------------
806 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
809 public String getServicePathComponent() {
810 return SERVICE_PATH_COMPONENT;
813 private RelationsCommon createRelationsCommon(String identifier) {
814 RelationsCommon result = new RelationsCommon();
815 fillRelation(result, identifier);
819 private MultipartOutput createRelationInstance(RelationsCommon relation) {
820 MultipartOutput result = new MultipartOutput();
821 OutputPart commonPart =
822 result.addPart(relation, MediaType.APPLICATION_XML_TYPE);
823 commonPart.getHeaders().add("label", new RelationClient().getCommonPartName());
824 if(logger.isDebugEnabled()){
825 logger.debug("to be created, relation common");
826 logger.debug(objectAsXmlString(relation, RelationsCommon.class));
832 * Creates the relation instance.
834 * @param identifier the identifier
835 * @return the multipart output
837 private MultipartOutput createRelationInstance(String identifier) {
838 RelationsCommon relation = createRelationsCommon(identifier);
839 MultipartOutput result = createRelationInstance(relation);
844 * Fills the relation.
846 * @param relation the relation
847 * @param identifier the identifier
849 private void fillRelation(RelationsCommon relation, String identifier) {
850 fillRelation(relation, "Subject-" + identifier,
851 "SubjectType-" + identifier + "-type",
852 "Object-" + identifier,
853 "ObjectType-" + identifier + "-type",
854 RelationshipType.COLLECTIONOBJECT_INTAKE.toString(),
855 RelationshipType.COLLECTIONOBJECT_INTAKE + ".displayName");
859 * Fills the relation.
861 * @param relation the relation
862 * @param documentId1 the document id1
863 * @param documentType1 the document type1
864 * @param documentId2 the document id2
865 * @param documentType2 the document type2
868 private void fillRelation(RelationsCommon relation,
869 String documentId1, String documentType1,
870 String documentId2, String documentType2,
872 String rtDisplayName) {
873 relation.setDocumentId1(documentId1);
874 relation.setDocumentType1(documentType1);
875 relation.setDocumentId2(documentId2);
876 relation.setDocumentType2(documentType2);
878 relation.setRelationshipType(rt);
879 relation.setPredicateDisplayName(rtDisplayName);