+/** \r
+ * CollectionSpaceIntegrationTest.java\r
+ *\r
+ * {Purpose of This Class}\r
+ *\r
+ * {Other Notes Relating to This Class (Optional)}\r
+ *\r
+ * $LastChangedBy: $\r
+ * $LastChangedRevision: $\r
+ * $LastChangedDate: $\r
+ *\r
+ * This document is a part of the source code and related artifacts\r
+ * for CollectionSpace, an open source collections management system\r
+ * for museums and related institutions:\r
+ *\r
+ * http://www.collectionspace.org\r
+ * http://wiki.collectionspace.org\r
+ *\r
+ * Copyright © 2009 {Contributing Institution}\r
+ *\r
+ * Licensed under the Educational Community License (ECL), Version 2.0.\r
+ * You may not use this file except in compliance with this License.\r
+ *\r
+ * You may obtain a copy of the ECL 2.0 License at\r
+ * https://source.collectionspace.org/collection-space/LICENSE.txt\r
+ */\r
package org.collectionspace.services.ItegrationTests.test;\r
\r
import java.util.ArrayList;\r
import javax.xml.bind.JAXBContext;\r
import javax.xml.bind.Marshaller;\r
\r
-import org.collectionspace.services.collectionobject.CollectionObject;\r
-import org.collectionspace.services.intake.Intake;\r
-import org.collectionspace.services.relation.Relation;\r
+import org.collectionspace.services.collectionobject.CollectionobjectsCommon;\r
+import org.collectionspace.services.intake.IntakesCommon;\r
+import org.collectionspace.services.relation.RelationsCommon;\r
import org.collectionspace.services.relation.RelationshipType;\r
import org.jboss.resteasy.client.ClientResponse;\r
+import org.jboss.resteasy.plugins.providers.multipart.InputPart;\r
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\r
\r
+/**\r
+ * The Class CollectionSpaceIntegrationTest.\r
+ */\r
public abstract class CollectionSpaceIntegrationTest {\r
\r
/*\r
* Package scoped methods.\r
*/\r
\r
- void fillCollectionObject(CollectionObject co, String identifier) {\r
+ /**\r
+ * Fill collection object.\r
+ * \r
+ * @param co the co\r
+ * @param identifier the identifier\r
+ */\r
+ void fillCollectionObject(CollectionobjectsCommon co, String identifier) {\r
fillCollectionObject(co, "objectNumber-" + identifier, "objectName-"\r
+ identifier);\r
}\r
\r
- void fillCollectionObject(CollectionObject co, String objectNumber,\r
+ /**\r
+ * Fill collection object.\r
+ * \r
+ * @param co the co\r
+ * @param objectNumber the object number\r
+ * @param objectName the object name\r
+ */\r
+ void fillCollectionObject(CollectionobjectsCommon co, String objectNumber,\r
String objectName) {\r
co.setObjectNumber(objectNumber);\r
co.setObjectName(objectName);\r
}\r
\r
- void fillIntake(Intake theIntake, String identifier) {\r
+ /**\r
+ * Fill intake.\r
+ * \r
+ * @param theIntake the the intake\r
+ * @param identifier the identifier\r
+ */\r
+ void fillIntake(IntakesCommon theIntake, String identifier) {\r
fillIntake(theIntake, "entryNumber-" + identifier, "entryDate-"\r
+ identifier);\r
}\r
\r
- void fillIntake(Intake theIntake, String entryNumber, String entryDate) {\r
+ /**\r
+ * Fill intake.\r
+ * \r
+ * @param theIntake the the intake\r
+ * @param entryNumber the entry number\r
+ * @param entryDate the entry date\r
+ */\r
+ void fillIntake(IntakesCommon theIntake, String entryNumber, String entryDate) {\r
theIntake.setEntryNumber(entryNumber);\r
theIntake.setEntryDate(entryDate);\r
}\r
\r
- void fillRelation(Relation relation, String documentId1, String documentType1,\r
+ /**\r
+ * Fill relation.\r
+ * \r
+ * @param relation the relation\r
+ * @param documentId1 the document id1\r
+ * @param documentType1 the document type1\r
+ * @param documentId2 the document id2\r
+ * @param documentType2 the document type2\r
+ * @param rt the rt\r
+ */\r
+ void fillRelation(RelationsCommon relation, String documentId1, String documentType1,\r
String documentId2, String documentType2, RelationshipType rt)\r
{\r
relation.setDocumentId1(documentId1);\r
relation.setRelationshipType(rt);\r
}\r
\r
+ /**\r
+ * Creates the identifier.\r
+ * \r
+ * @return the string\r
+ */\r
String createIdentifier() {\r
long identifier = System.currentTimeMillis();\r
return Long.toString(identifier);\r
}\r
\r
+ /**\r
+ * Extract id.\r
+ * \r
+ * @param res the res\r
+ * \r
+ * @return the string\r
+ */\r
String extractId(ClientResponse<Response> res) {\r
String result = null;\r
\r
return result;\r
}\r
\r
+ /**\r
+ * Extract part.\r
+ * \r
+ * @param input\r
+ * the input\r
+ * @param label\r
+ * the label\r
+ * @param clazz\r
+ * the clazz\r
+ * \r
+ * @return the object\r
+ * \r
+ * @throws Exception\r
+ * the exception\r
+ */\r
+ static Object extractPart(MultipartInput input, String label, Class clazz) {\r
+ Object obj = null;\r
+ \r
+ try {\r
+ for (InputPart part : input.getParts()) {\r
+ String partLabel = part.getHeaders().getFirst("label");\r
+ if (label.equalsIgnoreCase(partLabel)) {\r
+ String partStr = part.getBodyAsString();\r
+ obj = part.getBody(clazz, null);\r
+ break;\r
+ }\r
+ }\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ }\r
+\r
+ return obj;\r
+ }\r
+ \r
+ /**\r
+ * Verbose.\r
+ * \r
+ * @param msg the msg\r
+ */\r
void verbose(String msg) {\r
System.out.println(msg);\r
}\r
\r
+ /**\r
+ * Verbose.\r
+ * \r
+ * @param msg the msg\r
+ * @param o the o\r
+ * @param clazz the clazz\r
+ */\r
void verbose(String msg, Object o, Class clazz) {\r
try {\r
verbose(msg);\r
}\r
}\r
\r
+ /**\r
+ * Verbose map.\r
+ * \r
+ * @param map the map\r
+ */\r
void verboseMap(MultivaluedMap map) {\r
for (Object entry : map.entrySet()) {\r
MultivaluedMap.Entry mentry = (MultivaluedMap.Entry) entry;\r
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+
+import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import javax.xml.bind.JAXBContext;
import org.slf4j.LoggerFactory;
import org.jboss.resteasy.client.ClientResponse;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
+import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
import org.collectionspace.services.client.TestServiceClient;
import org.collectionspace.services.CollectionObjectJAXBSchema;
import org.collectionspace.services.client.CollectionObjectClient;
-import org.collectionspace.services.collectionobject.CollectionObject;
-import org.collectionspace.services.collectionobject.CollectionObjectList;
+import org.collectionspace.services.collectionobject.CollectionobjectsCommon;
+import org.collectionspace.services.collectionobject.CollectionobjectsCommonList;
import org.collectionspace.services.IntakeJAXBSchema;
import org.collectionspace.services.client.IntakeClient;
-import org.collectionspace.services.intake.Intake;
-import org.collectionspace.services.intake.IntakeList;
+import org.collectionspace.services.intake.IntakesCommon;
+import org.collectionspace.services.intake.IntakesCommonList;
import org.collectionspace.services.common.relation.RelationJAXBSchema;
import org.collectionspace.services.client.RelationClient;
-import org.collectionspace.services.relation.Relation;
-import org.collectionspace.services.relation.RelationList;
+import org.collectionspace.services.relation.RelationsCommon;
+import org.collectionspace.services.relation.RelationsCommonList;
import org.collectionspace.services.relation.RelationshipType;
/**
//
// First create a CollectionObject
//
- CollectionObject co = new CollectionObject();
+ CollectionobjectsCommon co = new CollectionobjectsCommon();
fillCollectionObject(co, createIdentifier());
- ClientResponse<Response> coResponse = collectionObjectClient.create(co);
- Assert.assertEquals(coResponse.getStatus(), Response.Status.CREATED.getStatusCode());
- String collectionObjectCsid = extractId(coResponse);
+
+ // Next, create a part object
+ MultipartOutput multipart = new MultipartOutput();
+ OutputPart commonPart = multipart.addPart(co, MediaType.APPLICATION_XML_TYPE);
+ commonPart.getHeaders().add("label", collectionObjectClient.getCommonPartName());
+ // Make the create call and check the response
+ ClientResponse<Response> response = collectionObjectClient.create(multipart);
+ Assert.assertEquals(response.getStatus(), Response.Status.CREATED
+ .getStatusCode());
+ String collectionObjectCsid = extractId(response);
+
- // Next, create an Intake record
- Intake intake = new Intake();
+ // Next, create an Intake object
+ IntakesCommon intake = new IntakesCommon();
fillIntake(intake, createIdentifier());
- ClientResponse<Response> intakeResponse = intakeClient.create(intake);
- Assert.assertEquals(intakeResponse.getStatus(), Response.Status.CREATED.getStatusCode());
- String intakeCsid = extractId(intakeResponse);
+ // Create the a part object
+ multipart = new MultipartOutput();
+ commonPart = multipart.addPart(intake, MediaType.APPLICATION_XML_TYPE);
+ commonPart.getHeaders().add("label", intakeClient.getCommonPartName());
+ // Make the call to create and check the response
+ response = intakeClient.create(multipart);
+ Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
+ String intakeCsid = extractId(response);
- // Lastly, relate the two entities
- Relation relation = new Relation();
- fillRelation(relation, collectionObjectCsid, CollectionObject.class.getSimpleName(),
- intakeCsid, Intake.class.getSimpleName(),
+ // Lastly, relate the two entities, by creating a new relation object
+ RelationsCommon relation = new RelationsCommon();
+ fillRelation(relation, collectionObjectCsid, CollectionobjectsCommon.class.getSimpleName(),
+ intakeCsid, IntakesCommon.class.getSimpleName(),
RelationshipType.COLLECTIONOBJECT_INTAKE);
- ClientResponse<Response> relationResponse = relationClient.create(relation);
- Assert.assertEquals(relationResponse.getStatus(), Response.Status.CREATED.getStatusCode());
- String relationCsid = extractId(relationResponse);
+ // Create the part and fill it with the relation object
+ multipart = new MultipartOutput();
+ commonPart = multipart.addPart(relation, MediaType.APPLICATION_XML_TYPE);
+ commonPart.getHeaders().add("label", relationClient.getCommonPartName());
+ // Make the call to crate
+ response = relationClient.create(multipart);
+ Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
+ String relationCsid = extractId(response);
//
// Now try to retrieve the Intake record of the CollectionObject.
//
String predicate = RelationshipType.COLLECTIONOBJECT_INTAKE.value();
- ClientResponse<RelationList> resultResponse = relationClient.readList_SPO(collectionObjectCsid,
+ ClientResponse<RelationsCommonList> resultResponse = relationClient.readList_SPO(collectionObjectCsid,
predicate,
intakeCsid);
+ Assert.assertEquals(resultResponse.getStatus(), Response.Status.OK.getStatusCode());
//
// Each relation returned in the list needs to match what we
// requested.
//
- RelationList relationList = resultResponse.getEntity();
- List<RelationList.RelationListItem> relationListItems = relationList.getRelationListItem();
- ClientResponse<Relation> resultRelationResponse;
- Relation resultRelation = null;
+ RelationsCommonList relationList = resultResponse.getEntity();
+ List<RelationsCommonList.RelationListItem> relationListItems = relationList.getRelationListItem();
+ Assert.assertFalse(relationListItems.isEmpty());
+
+ ClientResponse<RelationsCommon> resultRelationResponse;
+ RelationsCommon resultRelation = null;
int i = 0;
- for(RelationList.RelationListItem listItem : relationListItems){
+ for(RelationsCommonList.RelationListItem listItem : relationListItems){
String foundCsid = listItem.getCsid();
try {
- resultRelationResponse = relationClient.read(foundCsid);
- resultRelation = resultRelationResponse.getEntity();
+ ClientResponse<MultipartInput> multiPartResponse = relationClient.read(foundCsid);
+ int responseStatus = multiPartResponse.getStatus();
+ Assert.assertEquals(responseStatus, Response.Status.OK.getStatusCode());
+ MultipartInput input = (MultipartInput) multiPartResponse.getEntity();
+ resultRelation = (RelationsCommon) extractPart(input,
+ relationClient.getCommonPartName(),
+ RelationsCommon.class);
} catch (Exception e) {
e.printStackTrace();
}