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.ArrayList;
26 import java.util.List;
27 import javax.ws.rs.core.MediaType;
28 import javax.ws.rs.core.Response;
30 import org.collectionspace.services.client.CollectionSpaceClient;
31 import org.collectionspace.services.client.RelationClient;
32 import org.collectionspace.services.jaxb.AbstractCommonList;
33 import org.collectionspace.services.relation.RelationsCommon;
34 import org.collectionspace.services.relation.RelationsCommonList;
35 import org.collectionspace.services.relation.RelationshipType;
37 import org.jboss.resteasy.client.ClientResponse;
39 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
40 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
41 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
42 import org.testng.Assert;
43 import org.testng.annotations.AfterClass;
44 import org.testng.annotations.Test;
46 import org.slf4j.Logger;
47 import org.slf4j.LoggerFactory;
50 * RelationServiceTest, carries out tests against a
51 * deployed and running Relation Service.
53 * $LastChangedRevision$
56 public class RelationServiceTest extends AbstractServiceTestImpl {
59 private final Logger logger =
60 LoggerFactory.getLogger(RelationServiceTest.class);
62 /** The SERVIC e_ pat h_ component. */
63 final String SERVICE_PATH_COMPONENT = "relations";
65 /** The known resource id. */
66 private String knownResourceId = null;
68 /** The all resource ids created. */
69 private List<String> allResourceIdsCreated = new ArrayList<String>();
72 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
75 protected CollectionSpaceClient getClientInstance() {
76 return new RelationClient();
80 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
83 protected AbstractCommonList getAbstractCommonList(
84 ClientResponse<AbstractCommonList> response) {
85 return response.getEntity(RelationsCommonList.class);
88 // ---------------------------------------------------------------
89 // CRUD tests : CREATE tests
90 // ---------------------------------------------------------------
93 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
95 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
97 public void create(String testName) throws Exception {
99 // Perform setup, such as initializing the type of service request
100 // (e.g. CREATE, DELETE), its valid and expected status codes, and
101 // its associated HTTP method name (e.g. POST, DELETE).
102 setupCreate(testName);
104 // Submit the request to the service and store the response.
105 RelationClient client = new RelationClient();
106 String identifier = createIdentifier();
107 MultipartOutput multipart = createRelationInstance(identifier);
108 ClientResponse<Response> res = client.create(multipart);
109 int statusCode = res.getStatus();
111 // Check the status code of the response: does it match
112 // the expected response(s)?
114 // Does it fall within the set of valid status codes?
115 // Does it exactly match the expected status code?
116 if(logger.isDebugEnabled()){
117 logger.debug(testName + ": status = " + statusCode);
119 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
120 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
121 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
123 // Store the ID returned from the first resource created
124 // for additional tests below.
125 if (knownResourceId == null){
126 knownResourceId = extractId(res);
127 if (logger.isDebugEnabled()) {
128 logger.debug(testName + ": knownResourceId=" + knownResourceId);
132 // Store the IDs from every resource created by tests,
133 // so they can be deleted after tests have been run.
134 allResourceIdsCreated.add(extractId(res));
138 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
141 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
142 dependsOnMethods = {"create"})
143 public void createList(String testName) throws Exception {
144 for(int i = 0; i < 3; i++){
150 // Placeholders until the three tests below can be uncommented.
151 // See Issue CSPACE-401.
153 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
156 public void createWithEmptyEntityBody(String testName) throws Exception {
157 //Should this test really be empty?
161 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
164 public void createWithMalformedXml(String testName) throws Exception {
165 //Should this test really be empty?
169 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
172 public void createWithWrongXmlSchema(String testName) throws Exception {
173 //Should this test really be empty?
178 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
179 dependsOnMethods = {"create", "testSubmitRequest"})
180 public void createWithEmptyEntityBody(String testName) throws Exception {
183 setupCreateWithEmptyEntityBody(testName);
185 // Submit the request to the service and store the response.
186 String method = REQUEST_TYPE.httpMethodName();
187 String url = getServiceRootURL();
188 String mediaType = MediaType.APPLICATION_XML;
189 final String entity = "";
190 int statusCode = submitRequest(method, url, mediaType, entity);
192 // Check the status code of the response: does it match
193 // the expected response(s)?
194 if(logger.isDebugEnabled()){
195 logger.debug(testName + ": url=" + url +
196 " status=" + statusCode);
198 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
199 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
200 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
204 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
205 dependsOnMethods = {"create", "testSubmitRequest"})
206 public void createWithMalformedXml(String testName) throws Exception {
209 setupCreateWithMalformedXml(testName);
211 // Submit the request to the service and store the response.
212 String method = REQUEST_TYPE.httpMethodName();
213 String url = getServiceRootURL();
214 String mediaType = MediaType.APPLICATION_XML;
215 final String entity = MALFORMED_XML_DATA; // Constant from base class.
216 int statusCode = submitRequest(method, url, mediaType, entity);
218 // Check the status code of the response: does it match
219 // the expected response(s)?
220 if(logger.isDebugEnabled()){
221 logger.debug(testName + ": url=" + url +
222 " status=" + statusCode);
224 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
225 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
226 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
230 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
231 dependsOnMethods = {"create", "testSubmitRequest"})
232 public void createWithWrongXmlSchema(String testName) throws Exception {
235 setupCreateWithWrongXmlSchema(testName);
237 // Submit the request to the service and store the response.
238 String method = REQUEST_TYPE.httpMethodName();
239 String url = getServiceRootURL();
240 String mediaType = MediaType.APPLICATION_XML;
241 final String entity = WRONG_XML_SCHEMA_DATA;
242 int statusCode = submitRequest(method, url, mediaType, entity);
244 // Check the status code of the response: does it match
245 // the expected response(s)?
246 if(logger.isDebugEnabled()){
247 logger.debug(testName + ": url=" + url +
248 " status=" + statusCode);
250 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
251 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
252 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
256 // ---------------------------------------------------------------
257 // CRUD tests : READ tests
258 // ---------------------------------------------------------------
261 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
264 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
265 dependsOnMethods = {"create"})
266 public void read(String testName) throws Exception {
271 // Submit the request to the service and store the response.
272 RelationClient client = new RelationClient();
273 ClientResponse<MultipartInput> res = client.read(knownResourceId);
274 int statusCode = res.getStatus();
276 // Check the status code of the response: does it match
277 // the expected response(s)?
278 if(logger.isDebugEnabled()){
279 logger.debug(testName + ": status = " + statusCode);
281 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
282 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
283 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
285 // Verify that the resource identifier ...
286 MultipartInput input = (MultipartInput) res.getEntity();
287 RelationsCommon relation = (RelationsCommon) extractPart(input,
288 client.getCommonPartName(), RelationsCommon.class);
289 Assert.assertNotNull(relation);
295 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
298 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
299 dependsOnMethods = {"read"})
300 public void readNonExistent(String testName) throws Exception {
303 setupReadNonExistent(testName);
305 // Submit the request to the service and store the response.
306 RelationClient client = new RelationClient();
307 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
308 int statusCode = res.getStatus();
310 // Check the status code of the response: does it match
311 // the expected response(s)?
312 if(logger.isDebugEnabled()){
313 logger.debug(testName + ": status = " + statusCode);
315 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
316 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
317 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
321 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String)
323 @Test(dataProvider = "testName")
325 * FIXME: Until the Relation service uses NXQL queries to get results,
326 * we need to skip the pagination tests
329 public void readPaginatedList(String testName) throws Exception {
330 //Override and skip the pagination tests
333 // ---------------------------------------------------------------
334 // CRUD tests : READ_LIST tests
335 // ---------------------------------------------------------------
338 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
341 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
342 dependsOnMethods = {"createList", "read"})
343 public void readList(String testName) throws Exception {
346 setupReadList(testName);
348 // Submit the request to the service and store the response.
349 RelationClient client = new RelationClient();
350 ClientResponse<RelationsCommonList> res = client.readList();
351 RelationsCommonList list = res.getEntity();
352 int statusCode = res.getStatus();
354 // Check the status code of the response: does it match
355 // the expected response(s)?
356 if(logger.isDebugEnabled()){
357 logger.debug(testName + ": status = " + statusCode);
359 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
360 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
361 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
363 // Optionally output additional data about list members for debugging.
364 boolean iterateThroughList = false;
365 if(iterateThroughList && logger.isDebugEnabled()){
366 List<RelationsCommonList.RelationListItem> items =
367 list.getRelationListItem();
369 for(RelationsCommonList.RelationListItem item : items){
370 logger.debug(testName + ": list-item[" + i + "] csid=" +
372 logger.debug(testName + ": list-item[" + i + "] URI=" +
383 // ---------------------------------------------------------------
384 // CRUD tests : UPDATE tests
385 // ---------------------------------------------------------------
389 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
392 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
393 dependsOnMethods = {"read"})
394 public void update(String testName) throws Exception {
397 setupUpdate(testName);
399 // Retrieve an existing resource that we can update.
400 RelationClient client = new RelationClient();
401 ClientResponse<MultipartInput> res =
402 client.read(knownResourceId);
403 if(logger.isDebugEnabled()){
404 logger.debug(testName + ": read status = " + res.getStatus());
406 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
407 if(logger.isDebugEnabled()){
408 logger.debug("Got object to update with ID: " + knownResourceId);
410 MultipartInput input = (MultipartInput) res.getEntity();
411 RelationsCommon relation = (RelationsCommon) extractPart(input,
412 client.getCommonPartName(), RelationsCommon.class);
413 Assert.assertNotNull(relation);
415 // Update the content of this resource.
416 relation.setDocumentId1("updated-" + relation.getDocumentId1());
417 relation.setDocumentType1("updated-" + relation.getDocumentType1());
418 relation.setDocumentId2("updated-" + relation.getDocumentId2());
419 relation.setDocumentType2("updated-" + relation.getDocumentType2());
420 if(logger.isDebugEnabled()){
421 logger.debug("updated object");
422 logger.debug(objectAsXmlString(relation, RelationsCommon.class));
425 // Submit the request to the service and store the response.
426 MultipartOutput output = new MultipartOutput();
427 OutputPart commonPart = output.addPart(relation, MediaType.APPLICATION_XML_TYPE);
428 commonPart.getHeaders().add("label", client.getCommonPartName());
429 res = client.update(knownResourceId, output);
430 int statusCode = res.getStatus();
432 // Check the status code of the response: does it match 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);
440 input = (MultipartInput) res.getEntity();
441 RelationsCommon updatedObject = (RelationsCommon) extractPart(
442 input, client.getCommonPartName(),
443 RelationsCommon.class);
444 Assert.assertNotNull(updatedObject);
447 "Data in updated object did not match submitted data.";
449 updatedObject.getDocumentId1(), relation.getDocumentId1(), msg);
451 updatedObject.getDocumentType1(), relation.getDocumentType1(), msg);
453 updatedObject.getDocumentId2(), relation.getDocumentId2(), msg);
455 updatedObject.getDocumentType2(), relation.getDocumentType2(), msg);
460 // Placeholders until the three tests below can be uncommented.
461 // See Issue CSPACE-401.
463 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
466 public void updateWithEmptyEntityBody(String testName) throws Exception {
467 //Should this test really be empty?
471 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
474 public void updateWithMalformedXml(String testName) throws Exception {
475 //Should this test really be empty?
479 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
482 public void updateWithWrongXmlSchema(String testName) throws Exception {
483 //Should this test really be empty?
488 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
489 dependsOnMethods = {"create", "update", "testSubmitRequest"})
490 public void updateWithEmptyEntityBody(String testName) throws Exception {
493 setupUpdateWithEmptyEntityBody(testName);
495 // Submit the request to the service and store the response.
496 String method = REQUEST_TYPE.httpMethodName();
497 String url = getResourceURL(knownResourceId);
498 String mediaType = MediaType.APPLICATION_XML;
499 final String entity = "";
500 int statusCode = submitRequest(method, url, mediaType, entity);
502 // Check the status code of the response: does it match
503 // the expected response(s)?
504 if(logger.isDebugEnabled()){
505 logger.debug(testName + ": url=" + url +
506 " status=" + statusCode);
508 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
509 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
510 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
514 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
515 dependsOnMethods = {"create", "update", "testSubmitRequest"})
516 public void updateWithMalformedXml(String testName) throws Exception {
519 setupUpdateWithMalformedXml(testName);
521 // Submit the request to the service and store the response.
522 String method = REQUEST_TYPE.httpMethodName();
523 String url = getResourceURL(knownResourceId);
524 String mediaType = MediaType.APPLICATION_XML;
525 final String entity = MALFORMED_XML_DATA; // Constant from abstract base class.
526 int statusCode = submitRequest(method, url, mediaType, entity);
528 // Check the status code of the response: does it match
529 // the expected response(s)?
530 if(logger.isDebugEnabled()){
531 logger.debug(testName + ": url=" + url +
532 " status=" + statusCode);
534 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
535 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
536 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
540 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
541 dependsOnMethods = {"create", "update", "testSubmitRequest"})
542 public void updateWithWrongXmlSchema(String testName) throws Exception {
545 setupUpdateWithWrongXmlSchema(testName);
547 // Submit the request to the service and store the response.
548 String method = REQUEST_TYPE.httpMethodName();
549 String url = getResourceURL(knownResourceId);
550 String mediaType = MediaType.APPLICATION_XML;
551 final String entity = WRONG_XML_SCHEMA_DATA; // Constant from abstract base class.
552 int statusCode = submitRequest(method, url, mediaType, entity);
554 // Check the status code of the response: does it match
555 // the expected response(s)?
556 if(logger.isDebugEnabled()){
557 logger.debug(testName + ": url=" + url +
558 " status=" + statusCode);
560 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
561 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
562 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
567 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
570 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
571 dependsOnMethods = {"update", "testSubmitRequest"})
572 public void updateNonExistent(String testName) throws Exception {
575 setupUpdateNonExistent(testName);
577 // Submit the request to the service and store the response.
578 // Note: The ID used in this 'create' call may be arbitrary.
579 // The only relevant ID may be the one used in update(), below.
580 RelationClient client = new RelationClient();
581 MultipartOutput multipart = createRelationInstance(NON_EXISTENT_ID);
582 ClientResponse<MultipartInput> res =
583 client.update(NON_EXISTENT_ID, multipart);
584 int statusCode = res.getStatus();
586 // Check the status code of the response: does it match
587 // the expected response(s)?
588 if(logger.isDebugEnabled()){
589 logger.debug(testName + ": status = " + statusCode);
591 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
592 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
593 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
596 // ---------------------------------------------------------------
597 // CRUD tests : DELETE tests
598 // ---------------------------------------------------------------
601 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
604 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
605 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
606 public void delete(String testName) throws Exception {
609 setupDelete(testName);
611 // Submit the request to the service and store the response.
612 RelationClient client = new RelationClient();
613 ClientResponse<Response> res = client.delete(knownResourceId);
614 int statusCode = res.getStatus();
616 // Check the status code of the response: does it match
617 // the expected response(s)?
618 if(logger.isDebugEnabled()){
619 logger.debug(testName + ": status = " + statusCode);
621 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
622 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
623 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
628 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
631 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
632 dependsOnMethods = {"delete"})
633 public void deleteNonExistent(String testName) throws Exception {
636 setupDeleteNonExistent(testName);
638 // Submit the request to the service and store the response.
639 RelationClient client = new RelationClient();
640 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
641 int statusCode = res.getStatus();
643 // Check the status code of the response: does it match
644 // the expected response(s)?
645 if(logger.isDebugEnabled()){
646 logger.debug(testName + ": status = " + statusCode);
648 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
649 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
650 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
653 // ---------------------------------------------------------------
654 // RELATE_OBJECT tests
655 // ---------------------------------------------------------------
659 @Test(dependsOnMethods = {"create"})
660 public void relateObjects() {
661 //Should this test really be empty?
664 // ---------------------------------------------------------------
665 // Utility tests : tests of code used in tests above
666 // ---------------------------------------------------------------
668 * Tests the code for manually submitting data that is used by several
669 * of the methods above.
671 @Test(dependsOnMethods = {"create", "read"})
672 public void testSubmitRequest() {
674 // Expected status code: 200 OK
675 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
677 // Submit the request to the service and store the response.
678 String method = ServiceRequestType.READ.httpMethodName();
679 String url = getResourceURL(knownResourceId);
680 int statusCode = submitRequest(method, url);
682 // Check the status code of the response: does it match
683 // the expected response(s)?
684 if(logger.isDebugEnabled()){
685 logger.debug("testSubmitRequest: url=" + url +
686 " status=" + statusCode);
688 Assert.assertEquals(statusCode, EXPECTED_STATUS);
692 // ---------------------------------------------------------------
693 // Cleanup of resources created during testing
694 // ---------------------------------------------------------------
697 * Deletes all resources created by tests, after all tests have been run.
699 * This cleanup method will always be run, even if one or more tests fail.
700 * For this reason, it attempts to remove all resources created
701 * at any point during testing, even if some of those resources
702 * may be expected to be deleted by certain tests.
704 @AfterClass(alwaysRun=true)
705 public void cleanUp() {
706 String noTest = System.getProperty("noTestCleanup");
707 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
708 if (logger.isDebugEnabled()) {
709 logger.debug("Skipping Cleanup phase ...");
713 if (logger.isDebugEnabled()) {
714 logger.debug("Cleaning up temporary resources created for testing ...");
716 RelationClient client = new RelationClient();
717 for (String resourceId : allResourceIdsCreated) {
718 // Note: Any non-success responses are ignored and not reported.
719 ClientResponse<Response> res = client.delete(resourceId);
723 // ---------------------------------------------------------------
724 // Utility methods used by tests above
725 // ---------------------------------------------------------------
727 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
730 public String getServicePathComponent() {
731 return SERVICE_PATH_COMPONENT;
735 * Creates the relation instance.
737 * @param identifier the identifier
738 * @return the multipart output
740 private MultipartOutput createRelationInstance(String identifier) {
741 RelationsCommon relation = new RelationsCommon();
742 fillRelation(relation, identifier);
744 MultipartOutput multipart = new MultipartOutput();
745 OutputPart commonPart =
746 multipart.addPart(relation, MediaType.APPLICATION_XML_TYPE);
747 commonPart.getHeaders().add("label", new RelationClient().getCommonPartName());
748 if(logger.isDebugEnabled()){
749 logger.debug("to be created, relation common");
750 logger.debug(objectAsXmlString(relation, RelationsCommon.class));
756 * Fills the relation.
758 * @param relation the relation
759 * @param identifier the identifier
761 private void fillRelation(RelationsCommon relation, String identifier) {
762 fillRelation(relation, "Subject-" + identifier,
763 "SubjectType-" + identifier + "-type",
764 "Object-" + identifier,
765 "ObjectType-" + identifier + "-type",
766 RelationshipType.COLLECTIONOBJECT_INTAKE);
770 * Fills the relation.
772 * @param relation the relation
773 * @param documentId1 the document id1
774 * @param documentType1 the document type1
775 * @param documentId2 the document id2
776 * @param documentType2 the document type2
779 private void fillRelation(RelationsCommon relation,
780 String documentId1, String documentType1,
781 String documentId2, String documentType2,
782 RelationshipType rt) {
783 relation.setDocumentId1(documentId1);
784 relation.setDocumentType1(documentType1);
785 relation.setDocumentId2(documentId2);
786 relation.setDocumentType2(documentType2);
788 relation.setRelationshipType(rt);