2 * This document is a part of the source code and related artifacts
3 * for CollectionSpace, an open source collections management system
4 * for museums and related institutions:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright (c) 2009 Regents of the University of California
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
15 * https://source.collectionspace.org/collection-space/LICENSE.txt
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 package org.collectionspace.services.ItegrationTests.test;
25 import java.io.IOException;
26 import java.util.ArrayList;
27 import java.util.List;
28 import javax.ws.rs.core.MultivaluedMap;
29 import javax.ws.rs.core.Response;
30 import javax.xml.bind.JAXBContext;
31 import javax.xml.bind.Marshaller;
33 import org.testng.Assert;
34 import org.testng.annotations.Test;
35 import org.testng.Assert;
36 import org.testng.annotations.Test;
38 import org.apache.commons.httpclient.Header;
39 import org.apache.commons.httpclient.HttpClient;
40 import org.apache.commons.httpclient.HttpException;
41 import org.apache.commons.httpclient.HttpStatus;
42 import org.apache.commons.httpclient.methods.GetMethod;
43 import org.apache.commons.httpclient.methods.HeadMethod;
44 import org.apache.commons.httpclient.methods.OptionsMethod;
45 import org.apache.commons.httpclient.methods.TraceMethod;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
49 import org.slf4j.Logger;
50 import org.slf4j.LoggerFactory;
52 import org.jboss.resteasy.client.ClientResponse;
54 import org.collectionspace.services.client.TestServiceClient;
56 import org.collectionspace.services.CollectionObjectJAXBSchema;
57 import org.collectionspace.services.client.CollectionObjectClient;
58 import org.collectionspace.services.collectionobject.CollectionObject;
59 import org.collectionspace.services.collectionobject.CollectionObjectList;
61 import org.collectionspace.services.IntakeJAXBSchema;
62 import org.collectionspace.services.client.IntakeClient;
63 import org.collectionspace.services.intake.Intake;
64 import org.collectionspace.services.intake.IntakeList;
66 import org.collectionspace.services.common.relation.RelationJAXBSchema;
67 import org.collectionspace.services.client.RelationClient;
68 import org.collectionspace.services.relation.Relation;
69 import org.collectionspace.services.relation.RelationList;
70 import org.collectionspace.services.relation.RelationshipType;
75 * @version $Revision:$
77 public class RelationIntegrationTest extends CollectionSpaceIntegrationTest {
79 final Logger logger = LoggerFactory
80 .getLogger(RelationIntegrationTest.class);
82 // Get clients for the CollectionSpace services
84 private CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
85 private RelationClient relationClient = new RelationClient();
86 private IntakeClient intakeClient = new IntakeClient();
89 public void relateCollectionObjectToIntake() {
92 // First create a CollectionObject
94 CollectionObject co = new CollectionObject();
95 fillCollectionObject(co, createIdentifier());
96 ClientResponse<Response> coResponse = collectionObjectClient.create(co);
97 Assert.assertEquals(coResponse.getStatus(), Response.Status.CREATED.getStatusCode());
98 String collectionObjectCsid = extractId(coResponse);
100 // Next, create an Intake record
101 Intake intake = new Intake();
102 fillIntake(intake, createIdentifier());
103 ClientResponse<Response> intakeResponse = intakeClient.create(intake);
104 Assert.assertEquals(intakeResponse.getStatus(), Response.Status.CREATED.getStatusCode());
105 String intakeCsid = extractId(intakeResponse);
107 // Lastly, relate the two entities
108 Relation relation = new Relation();
109 fillRelation(relation, collectionObjectCsid, CollectionObject.class.getSimpleName(),
110 intakeCsid, Intake.class.getSimpleName(),
111 RelationshipType.COLLECTIONOBJECT_INTAKE);
112 ClientResponse<Response> relationResponse = relationClient.create(relation);
113 Assert.assertEquals(relationResponse.getStatus(), Response.Status.CREATED.getStatusCode());
114 String relationCsid = extractId(relationResponse);
117 // Now try to retrieve the Intake record of the CollectionObject.
119 String predicate = RelationshipType.COLLECTIONOBJECT_INTAKE.value();
120 ClientResponse<RelationList> resultResponse = relationClient.readList_SPO(collectionObjectCsid,
125 // Each relation returned in the list needs to match what we
128 RelationList relationList = resultResponse.getEntity();
129 List<RelationList.RelationListItem> relationListItems = relationList.getRelationListItem();
130 ClientResponse<Relation> resultRelationResponse;
131 Relation resultRelation = null;
133 for(RelationList.RelationListItem listItem : relationListItems){
135 String foundCsid = listItem.getCsid();
137 resultRelationResponse = relationClient.read(foundCsid);
138 resultRelation = resultRelationResponse.getEntity();
139 } catch (Exception e) {
142 Assert.assertEquals(resultRelation.getDocumentId1(), collectionObjectCsid);
143 Assert.assertEquals(resultRelation.getRelationshipType(), RelationshipType.COLLECTIONOBJECT_INTAKE);
144 Assert.assertEquals(resultRelation.getDocumentId2(), intakeCsid);
145 System.out.println();