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