]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
551a2ff00ac494be4f30f17b21309111d5197431
[tmp/jakarta-migration.git] /
1 /**
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:
5  *
6  * http://www.collectionspace.org
7  * http://wiki.collectionspace.org
8  *
9  * Copyright © 2009 Regents of the University of California
10  *
11  * Licensed under the Educational Community License (ECL), Version 2.0.
12  * You may not use this file except in compliance with this License.
13  *
14  * You may obtain a copy of the ECL 2.0 License at
15  * https://source.collectionspace.org/collection-space/LICENSE.txt
16  *
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.
22  */
23 package org.collectionspace.services.client.test;
24
25 import java.util.ArrayList;
26 import java.util.List;
27 import javax.ws.rs.core.MediaType;
28 import javax.ws.rs.core.Response;
29
30 import org.collectionspace.services.client.RelationClient;
31 import org.collectionspace.services.relation.RelationsCommon;
32 import org.collectionspace.services.relation.RelationsCommonList;
33 import org.collectionspace.services.relation.RelationshipType;
34
35 import org.jboss.resteasy.client.ClientResponse;
36
37 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
38 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
39 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
40 import org.testng.Assert;
41 import org.testng.annotations.AfterClass;
42 import org.testng.annotations.Test;
43
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
46
47 /**
48  * RelationServiceTest, carries out tests against a
49  * deployed and running Relation Service.
50  * 
51  * $LastChangedRevision$
52  * $LastChangedDate$
53  */
54 public class RelationServiceTest extends AbstractServiceTestImpl {
55
56    private final Logger logger =
57         LoggerFactory.getLogger(RelationServiceTest.class);
58
59     final String SERVICE_PATH_COMPONENT = "relations";
60     private String knownResourceId = null;
61     private List<String> allResourceIdsCreated = new ArrayList();
62
63     // ---------------------------------------------------------------
64     // CRUD tests : CREATE tests
65     // ---------------------------------------------------------------
66     // Success outcomes
67     @Override
68     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
69     public void create(String testName) throws Exception {
70
71         // Perform setup, such as initializing the type of service request
72         // (e.g. CREATE, DELETE), its valid and expected status codes, and
73         // its associated HTTP method name (e.g. POST, DELETE).
74         setupCreate(testName);
75
76         // Submit the request to the service and store the response.
77         RelationClient client = new RelationClient();
78         String identifier = createIdentifier();
79         MultipartOutput multipart = createRelationInstance(identifier);
80         ClientResponse<Response> res = client.create(multipart);
81         int statusCode = res.getStatus();
82
83         // Check the status code of the response: does it match
84         // the expected response(s)?
85         //
86         // Does it fall within the set of valid status codes?
87         // Does it exactly match the expected status code?
88         if(logger.isDebugEnabled()){
89             logger.debug(testName + ": status = " + statusCode);
90         }
91         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
92                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
93         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
94
95         // Store the ID returned from the first resource created
96         // for additional tests below.
97         if (knownResourceId == null){
98             knownResourceId = extractId(res);
99             if (logger.isDebugEnabled()) {
100                 logger.debug(testName + ": knownResourceId=" + knownResourceId);
101             }
102         }
103
104         // Store the IDs from every resource created by tests,
105         // so they can be deleted after tests have been run.
106         allResourceIdsCreated.add(extractId(res));
107     }
108
109     @Override
110     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
111         dependsOnMethods = {"create"})
112     public void createList(String testName) throws Exception {
113         for(int i = 0; i < 3; i++){
114             create(testName);
115         }
116     }
117
118     // Failure outcomes
119     // Placeholders until the three tests below can be uncommented.
120     // See Issue CSPACE-401.
121     public void createWithEmptyEntityBody(String testName) throws Exception {
122     }
123
124     public void createWithMalformedXml(String testName) throws Exception {
125     }
126
127     public void createWithWrongXmlSchema(String testName) throws Exception {
128     }
129
130     /*
131     @Override
132     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
133         dependsOnMethods = {"create", "testSubmitRequest"})
134     public void createWithEmptyEntityBody(String testName) throws Exception {
135     
136     // Perform setup.
137     setupCreateWithEmptyEntityBody(testName);
138
139     // Submit the request to the service and store the response.
140     String method = REQUEST_TYPE.httpMethodName();
141     String url = getServiceRootURL();
142     String mediaType = MediaType.APPLICATION_XML;
143     final String entity = "";
144     int statusCode = submitRequest(method, url, mediaType, entity);
145
146     // Check the status code of the response: does it match
147     // the expected response(s)?
148     if(logger.isDebugEnabled()){
149         logger.debug(testName + ": url=" + url +
150             " status=" + statusCode);
151      }
152     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
153     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
154     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
155     }
156
157     @Override
158     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
159         dependsOnMethods = {"create", "testSubmitRequest"})
160     public void createWithMalformedXml(String testName) throws Exception {
161     
162     // Perform setup.
163     setupCreateWithMalformedXml(testName);
164
165     // Submit the request to the service and store the response.
166     String method = REQUEST_TYPE.httpMethodName();
167     String url = getServiceRootURL();
168     String mediaType = MediaType.APPLICATION_XML;
169     final String entity = MALFORMED_XML_DATA; // Constant from base class.
170     int statusCode = submitRequest(method, url, mediaType, entity);
171
172     // Check the status code of the response: does it match
173     // the expected response(s)?
174     if(logger.isDebugEnabled()){
175         logger.debug(testName + ": url=" + url +
176             " status=" + statusCode);
177      }
178     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
179     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
180     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
181     }
182
183     @Override
184     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
185         dependsOnMethods = {"create", "testSubmitRequest"})
186     public void createWithWrongXmlSchema(String testName) throws Exception {
187     
188     // Perform setup.
189     setupCreateWithWrongXmlSchema(testName);
190
191     // Submit the request to the service and store the response.
192     String method = REQUEST_TYPE.httpMethodName();
193     String url = getServiceRootURL();
194     String mediaType = MediaType.APPLICATION_XML;
195     final String entity = WRONG_XML_SCHEMA_DATA;
196     int statusCode = submitRequest(method, url, mediaType, entity);
197
198     // Check the status code of the response: does it match
199     // the expected response(s)?
200     if(logger.isDebugEnabled()){
201       logger.debug(testName + ": url=" + url +
202           " status=" + statusCode);
203      }
204     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
205     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
206     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
207     }
208      */
209
210     // ---------------------------------------------------------------
211     // CRUD tests : READ tests
212     // ---------------------------------------------------------------
213     // Success outcomes
214     @Override
215     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
216         dependsOnMethods = {"create"})
217     public void read(String testName) throws Exception {
218
219         // Perform setup.
220         setupRead(testName);
221
222         // Submit the request to the service and store the response.
223         RelationClient client = new RelationClient();
224         ClientResponse<MultipartInput> res = client.read(knownResourceId);
225         int statusCode = res.getStatus();
226
227         // Check the status code of the response: does it match
228         // the expected response(s)?
229         if(logger.isDebugEnabled()){
230             logger.debug(testName + ": status = " + statusCode);
231         }
232         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
233                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
234         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
235
236         // Verify that the resource identifier ...
237         MultipartInput input = (MultipartInput) res.getEntity();
238         RelationsCommon relation = (RelationsCommon) extractPart(input,
239                 client.getCommonPartName(), RelationsCommon.class);
240         Assert.assertNotNull(relation);
241
242     }
243
244     // Failure outcomes
245     @Override
246     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
247         dependsOnMethods = {"read"})
248     public void readNonExistent(String testName) throws Exception {
249
250         // Perform setup.
251         setupReadNonExistent(testName);
252
253         // Submit the request to the service and store the response.
254         RelationClient client = new RelationClient();
255         ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
256         int statusCode = res.getStatus();
257
258         // Check the status code of the response: does it match
259         // the expected response(s)?
260         if(logger.isDebugEnabled()){
261             logger.debug(testName + ": status = " + statusCode);
262         }
263         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
264                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
265         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
266     }
267
268     // ---------------------------------------------------------------
269     // CRUD tests : READ_LIST tests
270     // ---------------------------------------------------------------
271     // Success outcomes
272     @Override
273     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
274         dependsOnMethods = {"createList", "read"})
275     public void readList(String testName) throws Exception {
276
277         // Perform setup.
278         setupReadList(testName);
279
280         // Submit the request to the service and store the response.
281         RelationClient client = new RelationClient();
282         ClientResponse<RelationsCommonList> res = client.readList();
283         RelationsCommonList list = res.getEntity();
284         int statusCode = res.getStatus();
285
286         // Check the status code of the response: does it match
287         // the expected response(s)?
288         if(logger.isDebugEnabled()){
289             logger.debug(testName + ": status = " + statusCode);
290         }
291         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
292                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
293         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
294
295         // Optionally output additional data about list members for debugging.
296         boolean iterateThroughList = false;
297         if(iterateThroughList && logger.isDebugEnabled()){
298             List<RelationsCommonList.RelationListItem> items =
299                     list.getRelationListItem();
300             int i = 0;
301             for(RelationsCommonList.RelationListItem item : items){
302                 logger.debug(testName + ": list-item[" + i + "] csid=" +
303                         item.getCsid());
304                 logger.debug(testName + ": list-item[" + i + "] URI=" +
305                         item.getUri());
306                 i++;
307             }
308         }
309
310     }
311
312     // Failure outcomes
313     // None at present.
314
315     // ---------------------------------------------------------------
316     // CRUD tests : UPDATE tests
317     // ---------------------------------------------------------------
318
319     // Success outcomes
320     @Override
321     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
322         dependsOnMethods = {"read"})
323     public void update(String testName) throws Exception {
324
325         // Perform setup.
326         setupUpdate(testName);
327
328         // Retrieve an existing resource that we can update.
329         RelationClient client = new RelationClient();
330         ClientResponse<MultipartInput> res =
331                 client.read(knownResourceId);
332         if(logger.isDebugEnabled()){
333             logger.debug(testName + ": read status = " + res.getStatus());
334         }
335         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
336         if(logger.isDebugEnabled()){
337             logger.debug("Got object to update with ID: " + knownResourceId);
338         }
339         MultipartInput input = (MultipartInput) res.getEntity();
340         RelationsCommon relation = (RelationsCommon) extractPart(input,
341                 client.getCommonPartName(), RelationsCommon.class);
342         Assert.assertNotNull(relation);
343
344         // Update the content of this resource.
345         relation.setDocumentId1("updated-" + relation.getDocumentId1());
346         relation.setDocumentType1("updated-" + relation.getDocumentType1());
347         relation.setDocumentId2("updated-" + relation.getDocumentId2());
348         relation.setDocumentType2("updated-" + relation.getDocumentType2());
349         if(logger.isDebugEnabled()){
350             logger.debug("updated object");
351             logger.debug(objectAsXmlString(relation, RelationsCommon.class));
352         }
353
354         // Submit the request to the service and store the response.
355         MultipartOutput output = new MultipartOutput();
356         OutputPart commonPart = output.addPart(relation, MediaType.APPLICATION_XML_TYPE);
357         commonPart.getHeaders().add("label", client.getCommonPartName());
358         res = client.update(knownResourceId, output);
359         int statusCode = res.getStatus();
360
361         // Check the status code of the response: does it match the expected response(s)?
362         if(logger.isDebugEnabled()){
363             logger.debug(testName + ": status = " + statusCode);
364         }
365         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
366                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
367         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
368
369         input = (MultipartInput) res.getEntity();
370         RelationsCommon updatedObject = (RelationsCommon) extractPart(
371                 input, client.getCommonPartName(),
372                 RelationsCommon.class);
373         Assert.assertNotNull(updatedObject);
374
375         final String msg =
376                 "Data in updated object did not match submitted data.";
377         Assert.assertEquals(
378                 updatedObject.getDocumentId1(), relation.getDocumentId1(), msg);
379         Assert.assertEquals(
380                 updatedObject.getDocumentType1(), relation.getDocumentType1(), msg);
381         Assert.assertEquals(
382                 updatedObject.getDocumentId2(), relation.getDocumentId2(), msg);
383         Assert.assertEquals(
384                 updatedObject.getDocumentType2(), relation.getDocumentType2(), msg);
385
386     }
387
388     // Failure outcomes
389     // Placeholders until the three tests below can be uncommented.
390     // See Issue CSPACE-401.
391     public void updateWithEmptyEntityBody(String testName) throws Exception {
392     }
393
394     public void updateWithMalformedXml(String testName) throws Exception {
395     }
396
397     public void updateWithWrongXmlSchema(String testName) throws Exception {
398     }
399
400     /*
401     @Override
402     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
403         dependsOnMethods = {"create", "update", "testSubmitRequest"})
404     public void updateWithEmptyEntityBody(String testName) throws Exception {
405     
406     // Perform setup.
407     setupUpdateWithEmptyEntityBody(testName);
408
409     // Submit the request to the service and store the response.
410     String method = REQUEST_TYPE.httpMethodName();
411     String url = getResourceURL(knownResourceId);
412     String mediaType = MediaType.APPLICATION_XML;
413     final String entity = "";
414     int statusCode = submitRequest(method, url, mediaType, entity);
415
416     // Check the status code of the response: does it match
417     // the expected response(s)?
418     if(logger.isDebugEnabled()){
419        logger.debug(testName + ": url=" + url +
420            " status=" + statusCode);
421      }
422     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
423     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
424     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
425     }
426
427     @Override
428     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
429         dependsOnMethods = {"create", "update", "testSubmitRequest"})
430     public void updateWithMalformedXml(String testName) throws Exception {
431
432     // Perform setup.
433     setupUpdateWithMalformedXml(testName);
434
435     // Submit the request to the service and store the response.
436     String method = REQUEST_TYPE.httpMethodName();
437     String url = getResourceURL(knownResourceId);
438     String mediaType = MediaType.APPLICATION_XML;
439     final String entity = MALFORMED_XML_DATA; // Constant from abstract base class.
440     int statusCode = submitRequest(method, url, mediaType, entity);
441
442     // Check the status code of the response: does it match
443     // the expected response(s)?
444     if(logger.isDebugEnabled()){
445         logger.debug(testName + ": url=" + url +
446         " status=" + statusCode);
447      }
448     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
449     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
450     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
451     }
452
453     @Override
454     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
455         dependsOnMethods = {"create", "update", "testSubmitRequest"})
456     public void updateWithWrongXmlSchema(String testName) throws Exception {
457     
458     // Perform setup.
459     setupUpdateWithWrongXmlSchema(testName);
460
461     // Submit the request to the service and store the response.
462     String method = REQUEST_TYPE.httpMethodName();
463     String url = getResourceURL(knownResourceId);
464     String mediaType = MediaType.APPLICATION_XML;
465     final String entity = WRONG_XML_SCHEMA_DATA; // Constant from abstract base class.
466     int statusCode = submitRequest(method, url, mediaType, entity);
467
468     // Check the status code of the response: does it match
469     // the expected response(s)?
470     if(logger.isDebugEnabled()){
471         logger.debug(testName + ": url=" + url +
472         " status=" + statusCode);
473      }
474     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
475     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
476     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
477     }
478      */
479
480     @Override
481     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
482         dependsOnMethods = {"update", "testSubmitRequest"})
483     public void updateNonExistent(String testName) throws Exception {
484
485         // Perform setup.
486         setupUpdateNonExistent(testName);
487
488         // Submit the request to the service and store the response.
489         // Note: The ID used in this 'create' call may be arbitrary.
490         // The only relevant ID may be the one used in update(), below.
491         RelationClient client = new RelationClient();
492         MultipartOutput multipart = createRelationInstance(NON_EXISTENT_ID);
493         ClientResponse<MultipartInput> res =
494                 client.update(NON_EXISTENT_ID, multipart);
495         int statusCode = res.getStatus();
496
497         // Check the status code of the response: does it match
498         // the expected response(s)?
499         if(logger.isDebugEnabled()){
500             logger.debug(testName + ": status = " + statusCode);
501         }
502         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
503                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
504         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
505     }
506
507     // ---------------------------------------------------------------
508     // CRUD tests : DELETE tests
509     // ---------------------------------------------------------------
510     // Success outcomes
511     @Override
512     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
513         dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
514     public void delete(String testName) throws Exception {
515
516         // Perform setup.
517         setupDelete(testName);
518
519         // Submit the request to the service and store the response.
520         RelationClient client = new RelationClient();
521         ClientResponse<Response> res = client.delete(knownResourceId);
522         int statusCode = res.getStatus();
523
524         // Check the status code of the response: does it match
525         // the expected response(s)?
526         if(logger.isDebugEnabled()){
527             logger.debug(testName + ": status = " + statusCode);
528         }
529         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
530                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
531         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
532     }
533
534     // Failure outcomes
535     @Override
536     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
537         dependsOnMethods = {"delete"})
538     public void deleteNonExistent(String testName) throws Exception {
539
540         // Perform setup.
541         setupDeleteNonExistent(testName);
542
543         // Submit the request to the service and store the response.
544         RelationClient client = new RelationClient();
545         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
546         int statusCode = res.getStatus();
547
548         // Check the status code of the response: does it match
549         // the expected response(s)?
550         if(logger.isDebugEnabled()){
551             logger.debug(testName + ": status = " + statusCode);
552         }
553         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
554                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
555         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
556     }
557
558     // ---------------------------------------------------------------
559     // RELATE_OBJECT tests
560     // ---------------------------------------------------------------
561     @Test(dependsOnMethods = {"create"})
562     public void relateObjects() {
563     }
564
565     // ---------------------------------------------------------------
566     // Utility tests : tests of code used in tests above
567     // ---------------------------------------------------------------
568     /**
569      * Tests the code for manually submitting data that is used by several
570      * of the methods above.
571      */
572     @Test(dependsOnMethods = {"create", "read"})
573     public void testSubmitRequest() {
574
575         // Expected status code: 200 OK
576         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
577
578         // Submit the request to the service and store the response.
579         String method = ServiceRequestType.READ.httpMethodName();
580         String url = getResourceURL(knownResourceId);
581         int statusCode = submitRequest(method, url);
582
583         // Check the status code of the response: does it match
584         // the expected response(s)?
585         if(logger.isDebugEnabled()){
586             logger.debug("testSubmitRequest: url=" + url +
587                 " status=" + statusCode);
588         }
589         Assert.assertEquals(statusCode, EXPECTED_STATUS);
590
591     }
592
593     // ---------------------------------------------------------------
594     // Cleanup of resources created during testing
595     // ---------------------------------------------------------------
596
597     /**
598      * Deletes all resources created by tests, after all tests have been run.
599      *
600      * This cleanup method will always be run, even if one or more tests fail.
601      * For this reason, it attempts to remove all resources created
602      * at any point during testing, even if some of those resources
603      * may be expected to be deleted by certain tests.
604      */
605     @AfterClass(alwaysRun=true)
606     public void cleanUp() {
607         String noTest = System.getProperty("noTestCleanup");
608         if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
609             if (logger.isDebugEnabled()) {
610                 logger.debug("Skipping Cleanup phase ...");
611             }
612             return;
613         }
614         if (logger.isDebugEnabled()) {
615             logger.debug("Cleaning up temporary resources created for testing ...");
616         }
617         RelationClient client = new RelationClient();
618         for (String resourceId : allResourceIdsCreated) {
619             // Note: Any non-success responses are ignored and not reported.
620             ClientResponse<Response> res = client.delete(resourceId);
621         }
622     }
623
624     // ---------------------------------------------------------------
625     // Utility methods used by tests above
626     // ---------------------------------------------------------------
627     @Override
628     public String getServicePathComponent() {
629         return SERVICE_PATH_COMPONENT;
630     }
631
632     private MultipartOutput createRelationInstance(String identifier) {
633         RelationsCommon relation = new RelationsCommon();
634         fillRelation(relation, identifier);
635
636         MultipartOutput multipart = new MultipartOutput();
637         OutputPart commonPart =
638                 multipart.addPart(relation, MediaType.APPLICATION_XML_TYPE);
639         commonPart.getHeaders().add("label", new RelationClient().getCommonPartName());
640         if(logger.isDebugEnabled()){
641           logger.debug("to be created, relation common");
642           logger.debug(objectAsXmlString(relation, RelationsCommon.class));
643         }
644         return multipart;
645     }
646
647     /**
648      * Fills the relation.
649      * 
650      * @param identifier the identifier
651      * 
652      * @return the relation
653      */
654     private void fillRelation(RelationsCommon relation, String identifier) {
655         fillRelation(relation, "Subject-" + identifier,
656                 "SubjectType-" + identifier + "-type",
657                 "Object-" + identifier,
658                 "ObjectType-" + identifier + "-type",
659                 RelationshipType.COLLECTIONOBJECT_INTAKE);
660     }
661
662     /**
663      * Fills the relation.
664      * 
665      * @param documentId1 the document id1
666      * @param documentType1 the document type1
667      * @param documentId2 the document id2
668      * @param documentType2 the document type2
669      * @param rt the rt
670      * 
671      * @return the relation
672      */
673     private void fillRelation(RelationsCommon relation,
674             String documentId1, String documentType1,
675             String documentId2, String documentType2,
676             RelationshipType rt) {
677         relation.setDocumentId1(documentId1);
678         relation.setDocumentType1(documentType1);
679         relation.setDocumentId2(documentId2);
680         relation.setDocumentType2(documentType2);
681
682         relation.setRelationshipType(rt);
683     }
684 }