]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-275: Added IntegrationTests module for performing inter-services call tests.
authorRichard Millet <richard.millet@berkeley.edu>
Tue, 11 Aug 2009 04:54:50 +0000 (04:54 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Tue, 11 Aug 2009 04:54:50 +0000 (04:54 +0000)
services/IntegrationTests/.classpath [new file with mode: 0644]
services/IntegrationTests/.project [new file with mode: 0644]
services/IntegrationTests/.settings/org.eclipse.jdt.core.prefs [new file with mode: 0644]
services/IntegrationTests/.settings/org.maven.ide.eclipse.prefs [new file with mode: 0644]
services/IntegrationTests/src/test/java/org/collectionspace/services/ItegrationTests/test/CollectionSpaceIntegrationTest.java [new file with mode: 0644]
services/IntegrationTests/src/test/java/org/collectionspace/services/ItegrationTests/test/RelationIntegrationTest.java [new file with mode: 0644]
services/IntegrationTests/src/test/resources/log4j.properties [new file with mode: 0644]

diff --git a/services/IntegrationTests/.classpath b/services/IntegrationTests/.classpath
new file mode 100644 (file)
index 0000000..425cd16
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<classpath>\r
+       <classpathentry kind="src" output="target/classes" path="src/main/java"/>\r
+       <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>\r
+       <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>\r
+       <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>\r
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>\r
+       <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>\r
+       <classpathentry kind="output" path="target/classes"/>\r
+</classpath>\r
diff --git a/services/IntegrationTests/.project b/services/IntegrationTests/.project
new file mode 100644 (file)
index 0000000..1f0c4f2
--- /dev/null
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<projectDescription>\r
+       <name>IntegrationTests</name>\r
+       <comment></comment>\r
+       <projects>\r
+       </projects>\r
+       <buildSpec>\r
+               <buildCommand>\r
+                       <name>org.eclipse.jdt.core.javabuilder</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
+               <buildCommand>\r
+                       <name>org.maven.ide.eclipse.maven2Builder</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
+       </buildSpec>\r
+       <natures>\r
+               <nature>org.eclipse.jdt.core.javanature</nature>\r
+               <nature>org.maven.ide.eclipse.maven2Nature</nature>\r
+       </natures>\r
+</projectDescription>\r
diff --git a/services/IntegrationTests/.settings/org.eclipse.jdt.core.prefs b/services/IntegrationTests/.settings/org.eclipse.jdt.core.prefs
new file mode 100644 (file)
index 0000000..0899025
--- /dev/null
@@ -0,0 +1,12 @@
+#Thu Mar 26 13:03:04 PDT 2009\r
+eclipse.preferences.version=1\r
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled\r
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6\r
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve\r
+org.eclipse.jdt.core.compiler.compliance=1.6\r
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate\r
+org.eclipse.jdt.core.compiler.debug.localVariable=generate\r
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate\r
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error\r
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error\r
+org.eclipse.jdt.core.compiler.source=1.6\r
diff --git a/services/IntegrationTests/.settings/org.maven.ide.eclipse.prefs b/services/IntegrationTests/.settings/org.maven.ide.eclipse.prefs
new file mode 100644 (file)
index 0000000..c6e4123
--- /dev/null
@@ -0,0 +1,8 @@
+#Thu Feb 26 16:30:28 PST 2009\r
+activeProfiles=\r
+eclipse.preferences.version=1\r
+fullBuildGoals=process-test-resources\r
+includeModules=false\r
+resolveWorkspaceProjects=true\r
+resourceFilterGoals=process-resources resources\:testResources\r
+version=1\r
diff --git a/services/IntegrationTests/src/test/java/org/collectionspace/services/ItegrationTests/test/CollectionSpaceIntegrationTest.java b/services/IntegrationTests/src/test/java/org/collectionspace/services/ItegrationTests/test/CollectionSpaceIntegrationTest.java
new file mode 100644 (file)
index 0000000..475f881
--- /dev/null
@@ -0,0 +1,95 @@
+package org.collectionspace.services.ItegrationTests.test;\r
+\r
+import java.util.ArrayList;\r
+\r
+import javax.ws.rs.core.MultivaluedMap;\r
+import javax.ws.rs.core.Response;\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.relation.RelationshipType;\r
+import org.jboss.resteasy.client.ClientResponse;\r
+\r
+public abstract class CollectionSpaceIntegrationTest {\r
+\r
+       /*\r
+        * Package scoped methods.\r
+        */\r
+\r
+       void fillCollectionObject(CollectionObject co, String identifier) {\r
+               fillCollectionObject(co, "objectNumber-" + identifier, "objectName-"\r
+                               + identifier);\r
+       }\r
+\r
+       void fillCollectionObject(CollectionObject co, String objectNumber,\r
+                       String objectName) {\r
+               co.setObjectNumber(objectNumber);\r
+               co.setObjectName(objectName);\r
+       }\r
+\r
+       void fillIntake(Intake theIntake, String identifier) {\r
+               fillIntake(theIntake, "entryNumber-" + identifier, "entryDate-"\r
+                               + identifier);\r
+       }\r
+\r
+       void fillIntake(Intake 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
+               String documentId2, String documentType2, RelationshipType rt)\r
+    {\r
+        relation.setDocumentId1(documentId1);\r
+        relation.setDocumentType1(documentType1);\r
+        relation.setDocumentId2(documentId2);\r
+        relation.setDocumentType2(documentType2);\r
+        \r
+        relation.setRelationshipType(rt);\r
+    }\r
+       \r
+       String createIdentifier() {\r
+               long identifier = System.currentTimeMillis();\r
+               return Long.toString(identifier);\r
+       }\r
+\r
+       String extractId(ClientResponse<Response> res) {\r
+               String result = null;\r
+               \r
+               MultivaluedMap mvm = res.getMetadata();\r
+               String uri = (String) ((ArrayList) mvm.get("Location")).get(0);\r
+               verbose("extractId:uri=" + uri);\r
+               String[] segments = uri.split("/");\r
+               result = segments[segments.length - 1];\r
+               verbose("id=" + result);\r
+               \r
+               return result;\r
+       }\r
+\r
+       void verbose(String msg) {\r
+               System.out.println(msg);\r
+       }\r
+\r
+       void verbose(String msg, Object o, Class clazz) {\r
+               try {\r
+                       verbose(msg);\r
+                       JAXBContext jc = JAXBContext.newInstance(clazz);\r
+                       Marshaller m = jc.createMarshaller();\r
+                       m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);\r
+                       m.marshal(o, System.out);\r
+               } catch (Exception e) {\r
+                       e.printStackTrace();\r
+               }\r
+       }\r
+\r
+       void verboseMap(MultivaluedMap map) {\r
+               for (Object entry : map.entrySet()) {\r
+                       MultivaluedMap.Entry mentry = (MultivaluedMap.Entry) entry;\r
+                       verbose("  name=" + mentry.getKey() + " value=" + mentry.getValue());\r
+               }\r
+       }\r
+\r
+}\r
diff --git a/services/IntegrationTests/src/test/java/org/collectionspace/services/ItegrationTests/test/RelationIntegrationTest.java b/services/IntegrationTests/src/test/java/org/collectionspace/services/ItegrationTests/test/RelationIntegrationTest.java
new file mode 100644 (file)
index 0000000..c8e3044
--- /dev/null
@@ -0,0 +1,154 @@
+/**
+ * This document is a part of the source code and related artifacts
+ * for CollectionSpace, an open source collections management system
+ * for museums and related institutions:
+ *
+ * http://www.collectionspace.org
+ * http://wiki.collectionspace.org
+ *
+ * Copyright © 2009 Regents of the University of California
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.collectionspace.services.ItegrationTests.test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.HeadMethod;
+import org.apache.commons.httpclient.methods.OptionsMethod;
+import org.apache.commons.httpclient.methods.TraceMethod;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.jboss.resteasy.client.ClientResponse;
+
+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.IntakeJAXBSchema;
+import org.collectionspace.services.client.IntakeClient;
+import org.collectionspace.services.intake.Intake;
+import org.collectionspace.services.intake.IntakeList;
+
+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.RelationshipType;
+
+/**
+ * A ServiceTest.
+ * 
+ * @version $Revision:$
+ */
+public class RelationIntegrationTest extends CollectionSpaceIntegrationTest {
+
+       final Logger logger = LoggerFactory
+                       .getLogger(RelationIntegrationTest.class);
+       //
+       // Get clients for the CollectionSpace services
+       //
+       private CollectionObjectClient collectionObjectClient = new CollectionObjectClient();
+       private RelationClient relationClient = new RelationClient();
+       private IntakeClient intakeClient = new IntakeClient();
+       
+       @Test
+       public void relateCollectionObjectToIntake() {
+               
+               //
+               // First create a CollectionObject
+               //
+               CollectionObject co = new CollectionObject();
+               fillCollectionObject(co, createIdentifier());
+           ClientResponse<Response> coResponse = collectionObjectClient.createCollectionObject(co);
+           Assert.assertEquals(coResponse.getStatus(), Response.Status.CREATED.getStatusCode());
+           String collectionObjectCsid = extractId(coResponse);
+           
+           // Next, create an Intake record
+           Intake intake = new Intake();
+           fillIntake(intake, createIdentifier());
+           ClientResponse<Response> intakeResponse = intakeClient.createIntake(intake);
+           Assert.assertEquals(intakeResponse.getStatus(), Response.Status.CREATED.getStatusCode());
+           String intakeCsid = extractId(intakeResponse);
+           
+           // Lastly, relate the two entities
+           Relation relation = new Relation();
+           fillRelation(relation, collectionObjectCsid, CollectionObject.class.getSimpleName(),
+                       intakeCsid, Intake.class.getSimpleName(),
+                       RelationshipType.COLLECTIONOBJECT_INTAKE);
+           ClientResponse<Response> relationResponse = relationClient.createRelation(relation); 
+           Assert.assertEquals(relationResponse.getStatus(), Response.Status.CREATED.getStatusCode());
+           String relationCsid = extractId(relationResponse);
+           
+           //
+           // Now try to retrieve the Intake record of the CollectionObject.
+           //
+           String predicate = RelationshipType.COLLECTIONOBJECT_INTAKE.value();
+           ClientResponse<RelationList> resultResponse = relationClient.getRelationList_SPO(collectionObjectCsid,
+                       predicate,
+                       intakeCsid);
+           
+           //
+           // 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;
+        int i = 0;
+        for(RelationList.RelationListItem listItem : relationListItems){
+               
+               String foundCsid = listItem.getCsid();
+               try {
+                       resultRelationResponse = relationClient.getRelation(foundCsid);
+                       resultRelation = resultRelationResponse.getEntity();
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+               Assert.assertEquals(resultRelation.getDocumentId1(), collectionObjectCsid);
+               Assert.assertEquals(resultRelation.getRelationshipType(), RelationshipType.COLLECTIONOBJECT_INTAKE);
+               Assert.assertEquals(resultRelation.getDocumentId2(), intakeCsid);
+            System.out.println();
+               i++;            
+        }
+       }
+
+       /*
+        * Private Methods
+        */
+
+}
diff --git a/services/IntegrationTests/src/test/resources/log4j.properties b/services/IntegrationTests/src/test/resources/log4j.properties
new file mode 100644 (file)
index 0000000..18c5103
--- /dev/null
@@ -0,0 +1,23 @@
+log4j.rootLogger=debug, stdout, R\r
+\r
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender\r
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout\r
+\r
+# Pattern to output the caller's file name and line number.\r
+log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n\r
+\r
+log4j.appender.R=org.apache.log4j.RollingFileAppender\r
+log4j.appender.R.File=target/test-client.log\r
+\r
+log4j.appender.R.MaxFileSize=100KB\r
+# Keep one backup file\r
+log4j.appender.R.MaxBackupIndex=1\r
+\r
+log4j.appender.R.layout=org.apache.log4j.PatternLayout\r
+log4j.appender.R.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n\r
+\r
+#packages\r
+log4j.logger.org.collectionspace=DEBUG\r
+log4j.logger.org.apache=INFO\r
+log4j.logger.httpclient=INFO\r
+log4j.logger.org.jboss.resteasy=INFO\r