]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
6c174f5db7a11ef4f617daf2a9dd279a2bcf2552
[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 (c) 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.IntegrationTests.test;
24
25 import java.io.StringWriter;
26 import java.math.BigDecimal;
27 import java.util.ArrayList;
28 import java.util.List;
29
30 import javax.ws.rs.core.MediaType;
31 import javax.ws.rs.core.Response;
32 import javax.xml.bind.JAXBContext;
33 import javax.xml.bind.Marshaller;
34
35 import org.testng.Assert;
36 import org.testng.annotations.AfterClass;
37 import org.testng.annotations.Test;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40 import org.collectionspace.services.client.CollectionObjectClient;
41 import org.collectionspace.services.client.DimensionClient;
42 import org.collectionspace.services.client.DimensionFactory;
43 import org.collectionspace.services.client.PayloadOutputPart;
44 import org.collectionspace.services.client.PoxPayloadIn;
45 import org.collectionspace.services.client.PoxPayloadOut;
46 import org.collectionspace.services.collectionobject.CollectionobjectsCommon;
47 import org.collectionspace.services.client.IntakeClient;
48 import org.collectionspace.services.intake.IntakesCommon;
49 import org.collectionspace.services.client.RelationClient;
50 import org.collectionspace.services.client.workflow.WorkflowClient;
51 import org.collectionspace.services.dimension.DimensionsCommon;
52 import org.collectionspace.services.relation.RelationsCommon;
53 import org.collectionspace.services.relation.RelationsCommonList;
54 import org.collectionspace.services.relation.RelationshipType;
55
56 /**
57  * A ServiceTest.
58  * 
59  * @version $Revision:$
60  */
61 public class RelationIntegrationTest extends CollectionSpaceIntegrationTest {
62
63         final Logger logger = LoggerFactory
64                         .getLogger(RelationIntegrationTest.class);
65         //
66         // Get clients for the CollectionSpace services
67         //
68         private CollectionObjectClient collectionObjectClient;
69         private RelationClient relationClient;
70         private IntakeClient intakeClient;
71         private DimensionClient dimensionClient;
72         
73         private static final int OBJECTS_TO_INTAKE = 1;
74         
75         public RelationIntegrationTest() throws Exception {
76                 collectionObjectClient = new CollectionObjectClient();
77                 relationClient = new RelationClient();
78                 intakeClient = new IntakeClient();
79                 dimensionClient = new DimensionClient();
80         }
81         
82     @AfterClass(alwaysRun = true)
83     public void cleanUp() {
84         relationClient.cleanup();
85         collectionObjectClient.cleanup();
86         intakeClient.cleanup();
87         dimensionClient.cleanup();
88     }
89     
90     /**
91      * Object as xml string.
92      *
93      * @param o the o
94      * @param clazz the clazz
95      * @return the string
96      */
97     static protected String objectAsXmlString(Object o, Class<?> clazz) {
98         StringWriter sw = new StringWriter();
99         try {
100             JAXBContext jc = JAXBContext.newInstance(clazz);
101             Marshaller m = jc.createMarshaller();
102             m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
103                     Boolean.TRUE);
104             m.marshal(o, sw);
105         } catch (Exception e) {
106             e.printStackTrace();
107         }
108         return sw.toString();
109     }
110         
111     private PoxPayloadOut createDimensionInstance(String commonPartName, String dimensionType, String dimensionValue, String entryDate) {
112         DimensionsCommon dimensionsCommon = new DimensionsCommon();
113         dimensionsCommon.setDimension(dimensionType);
114         dimensionsCommon.setValue(new BigDecimal(dimensionValue));
115         dimensionsCommon.setValueDate(entryDate);
116         PoxPayloadOut multipart = DimensionFactory.createDimensionInstance(
117                 commonPartName, dimensionsCommon);
118
119         if (logger.isDebugEnabled()) {
120             logger.debug("to be created, dimension common");
121             logger.debug(objectAsXmlString(dimensionsCommon,
122                     DimensionsCommon.class));
123         }
124
125         return multipart;
126     }
127         
128     protected PoxPayloadOut createDimensionInstance(String identifier) throws Exception {
129         DimensionClient client = new DimensionClient();
130         return createDimensionInstance(client.getCommonPartName(), identifier);
131     }
132     
133     /**
134      * Creates the dimension instance.
135      *
136      * @param identifier the identifier
137      * @return the multipart output
138      */
139     protected PoxPayloadOut createDimensionInstance(String commonPartName, String identifier) {
140         final String dimensionValue = Long.toString(System.currentTimeMillis());
141         
142         return createDimensionInstance(commonPartName, 
143                 "dimensionType-" + identifier,
144                 dimensionValue,
145                 "entryDate-" + identifier);
146     }
147     
148         @Test void deleteCollectionObjectRelationshipToLockedDimension() throws Exception {
149                 // First create a CollectionObject
150                 CollectionobjectsCommon co = new CollectionobjectsCommon();
151                 fillCollectionObject(co, createIdentifier());           
152                 PoxPayloadOut multipart = new PoxPayloadOut(CollectionObjectClient.SERVICE_PAYLOAD_NAME);
153                 PayloadOutputPart commonPart = multipart.addPart(collectionObjectClient.getCommonPartName(), co);
154                 
155                 // Make the "create" call and check the response
156                 Response response = collectionObjectClient.create(multipart);
157                 String collectionObjectCsid = null;
158                 try {
159                         Assert.assertEquals(response.getStatus(), Response.Status.CREATED
160                                         .getStatusCode());
161                         collectionObjectCsid = extractId(response);
162                         collectionObjectClient.addToCleanup(collectionObjectCsid);
163                 } finally {
164                         response.close();
165                 }
166                 
167                 // Create a new dimension record
168             multipart = this.createDimensionInstance(createIdentifier());
169             // Make the call to create and check the response
170             response = dimensionClient.create(multipart);
171             String dimensionCsid1 = null;
172             try {
173                     Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
174                     dimensionCsid1 = extractId(response);
175                     dimensionClient.addToCleanup(dimensionCsid1);
176             } finally {
177                 response.close();
178             }
179             
180             // Relate the entities, by creating a new relation object
181             RelationsCommon relation = new RelationsCommon();
182             fillRelation(relation, collectionObjectCsid, CollectionobjectsCommon.class.getSimpleName(),
183                         dimensionCsid1, DimensionsCommon.class.getSimpleName(),
184                         "collectionobject-dimension");
185             // Create the part and fill it with the relation object
186             multipart = new PoxPayloadOut(RelationClient.SERVICE_PAYLOAD_NAME);
187             commonPart = multipart.addPart(relationClient.getCommonPartName(), relation);
188             // Create the relationship
189             response = relationClient.create(multipart);
190             String relationCsid1 = null;
191             try {
192                     Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
193                     relationCsid1 = extractId(response);
194                     relationClient.addToCleanup(relationCsid1);
195             } finally {
196                 response.close();
197             }       
198             
199             // Now lock the dimension record.
200             
201             Response workflowResponse = null;
202             try {
203                         workflowResponse = dimensionClient.updateWorkflowWithTransition(
204                                         dimensionCsid1, WorkflowClient.WORKFLOWTRANSITION_LOCK);
205                     System.out.println("Locked dimension record with CSID=" + dimensionCsid1);
206             } finally {
207                 workflowResponse.close();
208             }
209             
210             // Finally, try to delete the relationship
211             
212             // Try to delete the relationship -should fail because we don't allow delete if one of the sides is locked.
213             response = relationClient.delete(relationCsid1);
214             try {
215                     Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
216             } finally {
217                 response.close();
218             }
219             
220             // Also, try to soft-delete.  This should also fail.
221                 workflowResponse = dimensionClient.updateWorkflowWithTransition(dimensionCsid1, WorkflowClient.WORKFLOWTRANSITION_DELETE);
222             System.out.println("Locked dimension record with CSID=" + dimensionCsid1);
223             workflowResponse.close();
224             
225             // Now unlock the dimension record so we can cleanup all the records after the test suite completes.
226             try {
227                         workflowResponse = dimensionClient.updateWorkflowWithTransition(
228                                         dimensionCsid1, WorkflowClient.WORKFLOWTRANSITION_UNLOCK);
229             } finally {
230                 workflowResponse.close();
231             }
232         }
233         
234         @Test void createCollectionObjectRelationshipToManyDimensions() throws Exception {
235                 //
236                 // First create a CollectionObject
237                 //
238                 CollectionobjectsCommon co = new CollectionobjectsCommon();
239                 fillCollectionObject(co, createIdentifier());           
240                 PoxPayloadOut multipart = new PoxPayloadOut(CollectionObjectClient.SERVICE_PAYLOAD_NAME);
241                 PayloadOutputPart commonPart = multipart.addPart(collectionObjectClient.getCommonPartName(), co);
242                 
243                 // Make the create call and check the response
244                 Response response = collectionObjectClient.create(multipart);
245                 String collectionObjectCsid = null;
246                 try {
247                         Assert.assertEquals(response.getStatus(), Response.Status.CREATED
248                                         .getStatusCode());
249                         collectionObjectCsid = extractId(response);
250                         collectionObjectClient.addToCleanup(collectionObjectCsid);
251                 } finally {
252                         response.close();
253                 }
254                 
255                 //Next, create the first of three Dimension records to relate the collection object record
256             multipart = this.createDimensionInstance(createIdentifier());
257             // Make the call to create and check the response
258             response = dimensionClient.create(multipart);
259             String dimensionCsid1 = null;
260             try {
261                     Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
262                     dimensionCsid1 = extractId(response);
263                     dimensionClient.addToCleanup(dimensionCsid1);
264             } finally {
265                 response.close();
266             }
267             
268                 //Next, create a the second Dimension record
269             multipart = this.createDimensionInstance(createIdentifier());
270             // Make the call to create and check the response
271             response = dimensionClient.create(multipart);
272             String dimensionCsid2 = null;
273             try {
274                     Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
275                     dimensionCsid2 = extractId(response);
276                     dimensionClient.addToCleanup(dimensionCsid2);
277             } finally {
278                 response.close();
279             }
280             
281                 //Next, create a the 3rd Dimension record
282             multipart = this.createDimensionInstance(createIdentifier());
283             // Make the call to create and check the response
284             response = dimensionClient.create(multipart);
285             String dimensionCsid3 = null;
286             try {
287                     Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
288                     dimensionCsid3 = extractId(response);
289                     dimensionClient.addToCleanup(dimensionCsid3);
290             } finally {
291                 response.close();
292             }
293             
294             // Relate the entities, by creating a new relation object
295             RelationsCommon relation = new RelationsCommon();
296             fillRelation(relation,
297                         collectionObjectCsid, CollectionobjectsCommon.class.getSimpleName(), // the subject of the relationship
298                         dimensionCsid1, DimensionsCommon.class.getSimpleName(), // the object of the relationship
299                         "collectionobject-dimension");
300             // Create the part and fill it with the relation object
301             multipart = new PoxPayloadOut(RelationClient.SERVICE_PAYLOAD_NAME);
302             commonPart = multipart.addPart(relationClient.getCommonPartName(), relation);
303             // Create the relationship
304             response = relationClient.create(multipart);
305             String relationCsid1 = null;
306             try {
307                     Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
308                     relationCsid1 = extractId(response);
309                     relationClient.addToCleanup(relationCsid1);
310             } finally {
311                 response.close();
312             }
313             // Wait 1 second and create the second relationship
314             try {
315                         Thread.sleep(1001);
316                 } catch (InterruptedException e) {
317                         // TODO Auto-generated catch block
318                         e.printStackTrace();
319                 }
320             relation = new RelationsCommon();
321             fillRelation(relation,
322                         collectionObjectCsid, CollectionobjectsCommon.class.getSimpleName(), // the subject of the relationship
323                         dimensionCsid2, DimensionsCommon.class.getSimpleName(), // the object of the relationship
324                         "collectionobject-dimension");
325             // Create the part and fill it with the relation object
326             multipart = new PoxPayloadOut(RelationClient.SERVICE_PAYLOAD_NAME);
327             commonPart = multipart.addPart(relationClient.getCommonPartName(), relation);
328             // Create the relationship
329             response = relationClient.create(multipart);
330
331                 String relationCsid2 = null;
332             try {
333                     Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
334                     relationCsid2 = extractId(response);
335                     relationClient.addToCleanup(relationCsid2);
336             } finally {
337                 response.close();
338             }
339             // Wait 1 second and create the 3rd relationship
340             try {
341                         Thread.sleep(1001);
342                 } catch (InterruptedException e) {
343                         // TODO Auto-generated catch block
344                         e.printStackTrace();
345                 }
346             relation = new RelationsCommon();
347             fillRelation(relation,
348                         collectionObjectCsid, CollectionobjectsCommon.class.getSimpleName(), // the subject of the relationship
349                         dimensionCsid3, DimensionsCommon.class.getSimpleName(), // the object of the relationship
350                         "collectionobject-dimension");
351             // Create the part and fill it with the relation object
352             multipart = new PoxPayloadOut(RelationClient.SERVICE_PAYLOAD_NAME);
353             commonPart = multipart.addPart(relationClient.getCommonPartName(), relation);
354             // Create the relationship
355             response = relationClient.create(multipart);
356
357                 String relationCsid3 = null;
358             try {
359                     Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
360                     relationCsid3 = extractId(response);
361                     relationClient.addToCleanup(relationCsid3);
362             } finally {
363                 response.close();
364             }               
365         }    
366         
367         @Test void releteCollectionObjectToLockedDimension() throws Exception {
368                 //
369                 // First create a CollectionObject
370                 //
371                 CollectionobjectsCommon co = new CollectionobjectsCommon();
372                 fillCollectionObject(co, createIdentifier());
373                 
374                 // Next, create a part object
375                 PoxPayloadOut multipart = new PoxPayloadOut(CollectionObjectClient.SERVICE_PAYLOAD_NAME);
376                 PayloadOutputPart commonPart = multipart.addPart(co, MediaType.APPLICATION_XML_TYPE);
377                 commonPart.setLabel(collectionObjectClient.getCommonPartName());
378                 
379                 // Make the create call and check the response
380                 Response response = collectionObjectClient.create(multipart);
381                 String collectionObjectCsid = null;
382                 try {
383                         Assert.assertEquals(response.getStatus(), Response.Status.CREATED
384                                         .getStatusCode());
385                         collectionObjectCsid = extractId(response);
386                         collectionObjectClient.addToCleanup(collectionObjectCsid);
387                 } finally {
388                         response.close();
389                 }
390                 
391                 //Next, create a Dimension record to relate the collection object to
392             multipart = this.createDimensionInstance(createIdentifier());
393             // Make the call to create and check the response
394             response = dimensionClient.create(multipart);
395             String dimensionCsid = null;
396             try {
397                     Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
398                     dimensionCsid = extractId(response);
399             } finally {
400                 response.close();
401             }
402             
403             @SuppressWarnings("unused")
404             Response workflowResponse = dimensionClient.updateWorkflowWithTransition(dimensionCsid, 
405                                 WorkflowClient.WORKFLOWTRANSITION_LOCK);
406             workflowResponse.close();
407             System.out.println("Locked dimension record with CSID=" + dimensionCsid);
408             
409             // Lastly, relate the two entities, by creating a new relation object
410             RelationsCommon relation = new RelationsCommon();
411             fillRelation(relation, collectionObjectCsid, CollectionobjectsCommon.class.getSimpleName(),
412                         dimensionCsid, DimensionsCommon.class.getSimpleName(),
413                         "collectionobject-dimension");
414             // Create the part and fill it with the relation object
415             multipart = new PoxPayloadOut(RelationClient.SERVICE_PAYLOAD_NAME);
416             commonPart = multipart.addPart(relation, MediaType.APPLICATION_XML_TYPE);
417             commonPart.setLabel(relationClient.getCommonPartName());
418
419             // Make the call to create the relationship
420             Response relationresponse = relationClient.create(multipart);
421                 String relationCsid = null;
422             try {
423                     Assert.assertEquals(relationresponse.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
424                     relationCsid = extractId(response);
425                     relationClient.addToCleanup(relationCsid);
426             } finally {
427                 relationresponse.close();
428             }
429             
430             // Now unlock the dimension record so we can cleanup all the records after the test suite completes.
431             try {
432                         workflowResponse = dimensionClient.updateWorkflowWithTransition(
433                                         dimensionCsid, WorkflowClient.WORKFLOWTRANSITION_UNLOCK);
434             } finally {
435                 workflowResponse.close();
436             }
437         }
438         
439         @Test
440         public void relateCollectionObjectToIntake() {
441                 //
442                 // First create a CollectionObject
443                 //
444                 CollectionobjectsCommon co = new CollectionobjectsCommon();
445                 fillCollectionObject(co, createIdentifier());
446                 
447                 // Next, create a part object
448                 PoxPayloadOut multipart = new PoxPayloadOut(CollectionObjectClient.SERVICE_PAYLOAD_NAME);
449                 PayloadOutputPart commonPart = multipart.addPart(co, MediaType.APPLICATION_XML_TYPE);
450                 commonPart.setLabel(collectionObjectClient.getCommonPartName());
451                 
452                 // Make the create call and check the response
453                 Response response = collectionObjectClient.create(multipart);
454                 String collectionObjectCsid = null;
455                 try {
456                         Assert.assertEquals(response.getStatus(), Response.Status.CREATED
457                                         .getStatusCode());
458                         collectionObjectCsid = extractId(response);
459                         collectionObjectClient.addToCleanup(collectionObjectCsid);
460                 } finally {
461                         response.close();
462                 }
463             
464             // Next, create an Intake object
465             IntakesCommon intake = new IntakesCommon();
466             fillIntake(intake, createIdentifier());
467             // Create the a part object
468             multipart = new PoxPayloadOut(IntakeClient.SERVICE_PAYLOAD_NAME);
469             commonPart = multipart.addPart(intake, MediaType.APPLICATION_XML_TYPE);
470             commonPart.setLabel(intakeClient.getCommonPartName());
471
472             // Make the call to create and check the response
473             response = intakeClient.create(multipart);
474             String intakeCsid = null;
475             try {
476                     Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
477                     intakeCsid = extractId(response);
478                     intakeClient.addToCleanup(intakeCsid);
479             } finally {
480                 response.close();
481             }
482             
483             // Lastly, relate the two entities, by creating a new relation object
484             RelationsCommon relation = new RelationsCommon();
485             fillRelation(relation, collectionObjectCsid, CollectionobjectsCommon.class.getSimpleName(),
486                         intakeCsid, IntakesCommon.class.getSimpleName(),
487                         RelationshipType.COLLECTIONOBJECT_INTAKE.toString());
488             // Create the part and fill it with the relation object
489             multipart = new PoxPayloadOut(RelationClient.SERVICE_PAYLOAD_NAME);
490             commonPart = multipart.addPart(relation, MediaType.APPLICATION_XML_TYPE);
491             commonPart.setLabel(relationClient.getCommonPartName());
492
493             // Make the call to crate
494             response = relationClient.create(multipart);
495             String relationCsid = null;
496             try {
497                     Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
498                     relationCsid = extractId(response);
499                     relationClient.addToCleanup(relationCsid);
500             } finally {
501                 response.close();
502             }
503             
504             //
505             // Now try to retrieve the Intake record of the CollectionObject.
506             //
507             String predicate = RelationshipType.COLLECTIONOBJECT_INTAKE.toString();
508             Response resultResponse = relationClient.readList(
509                         collectionObjectCsid,
510                         null, //CollectionobjectsCommon.class.getSimpleName(),
511                         predicate,
512                         intakeCsid,
513                         null ); //IntakesCommon.class.getSimpleName());
514         RelationsCommonList relationList = null;
515             try {
516                 Assert.assertEquals(resultResponse.getStatus(), Response.Status.OK.getStatusCode());
517                 relationList = resultResponse.readEntity(RelationsCommonList.class);
518             } finally {
519                 resultResponse.close();
520             }
521             
522             //
523             // Each relation returned in the list needs to match what we
524             // requested.
525             //
526         List<RelationsCommonList.RelationListItem> relationListItems = relationList.getRelationListItem();
527         Assert.assertFalse(relationListItems.isEmpty());
528         
529         int i = 0;
530         RelationsCommon resultRelation = null;
531         for(RelationsCommonList.RelationListItem listItem : relationListItems){
532                 
533                 String foundCsid = listItem.getCsid();
534                 Response multiPartResponse = null;
535                 try {
536                         multiPartResponse = relationClient.read(foundCsid);
537                         int responseStatus = multiPartResponse.getStatus();
538                         Assert.assertEquals(responseStatus, Response.Status.OK.getStatusCode());
539                         PoxPayloadIn input = new PoxPayloadIn(multiPartResponse.readEntity(String.class));
540                         resultRelation = (RelationsCommon) extractPart(input,
541                                         relationClient.getCommonPartName());
542                 } catch (Exception e) {
543                         e.printStackTrace();
544                 } finally {
545                         multiPartResponse.close();
546                 }
547                 
548                 Assert.assertEquals(resultRelation.getSubjectCsid(), collectionObjectCsid);
549                 Assert.assertEquals(resultRelation.getRelationshipType(), RelationshipType.COLLECTIONOBJECT_INTAKE.toString());
550                 Assert.assertEquals(resultRelation.getObjectCsid(), intakeCsid);
551             System.out.println();
552                 i++;            
553         }
554         }
555         
556         @Test
557         public void relateCollectionObjectsToIntake() {
558                 relateCollectionObjectsToIntake(OBJECTS_TO_INTAKE);
559         }
560
561         private void relateCollectionObjectsToIntake(int numberOfObjects) {
562                 
563                 //
564                 // First create a list of CollectionObjects
565                 //
566                 CollectionobjectsCommon co = new CollectionobjectsCommon();
567                 ArrayList<String>collectionObjectIDList = new ArrayList<String>(numberOfObjects);
568                 for (int i = 0; i < numberOfObjects; i++) {
569                         fillCollectionObject(co, createIdentifier());
570                         
571                         // Next, create a part object
572                         PoxPayloadOut multipart = new PoxPayloadOut(CollectionObjectClient.SERVICE_PAYLOAD_NAME);
573                         PayloadOutputPart commonPart = multipart.addPart(co, MediaType.APPLICATION_XML_TYPE);
574                         commonPart.setLabel(collectionObjectClient.getCommonPartName());
575                         
576                         // Make the create call and check the response
577                         Response response = collectionObjectClient.create(multipart);
578                         String collectionObjectCsid = null;
579                         try {
580                                 Assert.assertEquals(response.getStatus(), Response.Status.CREATED
581                                                 .getStatusCode());
582                                 collectionObjectCsid = extractId(response);
583                                 collectionObjectIDList.add(collectionObjectCsid);
584                                 collectionObjectClient.addToCleanup(collectionObjectCsid);
585                         } finally {
586                                 response.close();
587                         }
588                 }
589             
590             
591             // Next, create an Intake object
592             IntakesCommon intake = new IntakesCommon();
593             fillIntake(intake, createIdentifier());
594             // Create the a part object
595             PoxPayloadOut multipart = new PoxPayloadOut(IntakeClient.SERVICE_PAYLOAD_NAME);
596             PayloadOutputPart commonPart = multipart.addPart(intake, MediaType.APPLICATION_XML_TYPE);
597             commonPart.setLabel(intakeClient.getCommonPartName());
598
599             // Make the call to create and check the response
600             Response response = intakeClient.create(multipart);
601             String intakeCsid = null;
602             try {
603                     Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
604                     intakeCsid = extractId(response);
605                     intakeClient.addToCleanup(intakeCsid);
606             } finally {
607                 response.close();
608             }
609             
610             // Lastly, relate the two entities, by creating a new relation object
611             RelationsCommon relation = new RelationsCommon();
612             for (String collectionObjectCsid : collectionObjectIDList) {
613                     fillRelation(relation,
614                                 intakeCsid, IntakesCommon.class.getSimpleName(), //subject
615                                 collectionObjectCsid, CollectionobjectsCommon.class.getSimpleName(), //object                           
616                                 RelationshipType.COLLECTIONOBJECT_INTAKE.toString()); //predicate
617                     // Create the part and fill it with the relation object
618                     multipart = new PoxPayloadOut(RelationClient.SERVICE_PAYLOAD_NAME);
619                     commonPart = multipart.addPart(relation, MediaType.APPLICATION_XML_TYPE);
620                     commonPart.setLabel(relationClient.getCommonPartName());
621         
622                     // Make the call to crate
623                     response = relationClient.create(multipart);
624                     String relationCsid = null;
625                     try {
626                             Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
627                             relationCsid = extractId(response);
628                             relationClient.addToCleanup(relationCsid);
629                     } finally {
630                         response.close();
631                     }
632             }
633             
634             //
635             // Now try to retrieve the Intake record of the CollectionObject.
636             //
637             String predicate = RelationshipType.COLLECTIONOBJECT_INTAKE.toString();
638                 RelationsCommonList relationList = null;
639             for (String collectionObjectCsid : collectionObjectIDList) {
640                     Response resultResponse = relationClient.readList(
641                                 intakeCsid,
642                                 null, //IntakesCommon.class.getSimpleName(), //subject
643                                 predicate,
644                                 collectionObjectCsid,
645                                 null); //CollectionobjectsCommon.class.getSimpleName()); //object
646
647                     try {
648                         Assert.assertEquals(resultResponse.getStatus(), Response.Status.OK.getStatusCode());
649                         relationList = resultResponse.readEntity(RelationsCommonList.class);
650                     } finally {
651                         resultResponse.close();
652                     }
653             
654                     //
655                     // Each relation returned in the list needs to match what we
656                     // requested.
657                     //
658                 List<RelationsCommonList.RelationListItem> relationListItems = relationList.getRelationListItem();
659                 Assert.assertFalse(relationListItems.isEmpty());
660                 
661                 int i = 0;
662                 RelationsCommon resultRelation = null;
663                 for(RelationsCommonList.RelationListItem listItem : relationListItems){
664                         String foundCsid = listItem.getCsid();
665                         Response multiPartResponse = null;
666                         try {
667                                 multiPartResponse = relationClient.read(foundCsid);
668                                 int responseStatus = multiPartResponse.getStatus();
669                                 Assert.assertEquals(responseStatus, Response.Status.OK.getStatusCode());
670                                 PoxPayloadIn input = new PoxPayloadIn(multiPartResponse.readEntity(String.class));
671                                 resultRelation = (RelationsCommon) extractPart(input, relationClient.getCommonPartName());
672                         } catch (Exception e) {
673                                 e.printStackTrace();
674                         } finally {
675                                 multiPartResponse.close();
676                         }
677         
678                         Assert.assertEquals(resultRelation.getSubjectCsid(), intakeCsid);
679                         Assert.assertEquals(resultRelation.getRelationshipType(), RelationshipType.COLLECTIONOBJECT_INTAKE.toString());
680                         Assert.assertEquals(resultRelation.getObjectCsid(), collectionObjectCsid);
681                         System.out.println();
682                         i++;            
683                 }
684             }
685         }
686         
687
688         /*
689          * Private Methods
690          */
691
692 }