From: Richard Millet Date: Tue, 11 Aug 2009 04:54:50 +0000 (+0000) Subject: CSPACE-275: Added IntegrationTests module for performing inter-services call tests. X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=2706af03c6a79d796108afc9cc1d96d0ff8d955b;p=tmp%2Fjakarta-migration.git CSPACE-275: Added IntegrationTests module for performing inter-services call tests. --- diff --git a/services/IntegrationTests/.classpath b/services/IntegrationTests/.classpath new file mode 100644 index 000000000..425cd1620 --- /dev/null +++ b/services/IntegrationTests/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/services/IntegrationTests/.project b/services/IntegrationTests/.project new file mode 100644 index 000000000..1f0c4f201 --- /dev/null +++ b/services/IntegrationTests/.project @@ -0,0 +1,23 @@ + + + IntegrationTests + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.maven.ide.eclipse.maven2Nature + + diff --git a/services/IntegrationTests/.settings/org.eclipse.jdt.core.prefs b/services/IntegrationTests/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..0899025a2 --- /dev/null +++ b/services/IntegrationTests/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +#Thu Mar 26 13:03:04 PDT 2009 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/services/IntegrationTests/.settings/org.maven.ide.eclipse.prefs b/services/IntegrationTests/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 000000000..c6e4123cd --- /dev/null +++ b/services/IntegrationTests/.settings/org.maven.ide.eclipse.prefs @@ -0,0 +1,8 @@ +#Thu Feb 26 16:30:28 PST 2009 +activeProfiles= +eclipse.preferences.version=1 +fullBuildGoals=process-test-resources +includeModules=false +resolveWorkspaceProjects=true +resourceFilterGoals=process-resources resources\:testResources +version=1 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 index 000000000..475f881f9 --- /dev/null +++ b/services/IntegrationTests/src/test/java/org/collectionspace/services/ItegrationTests/test/CollectionSpaceIntegrationTest.java @@ -0,0 +1,95 @@ +package org.collectionspace.services.ItegrationTests.test; + +import java.util.ArrayList; + +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; + +import org.collectionspace.services.collectionobject.CollectionObject; +import org.collectionspace.services.intake.Intake; +import org.collectionspace.services.relation.Relation; +import org.collectionspace.services.relation.RelationshipType; +import org.jboss.resteasy.client.ClientResponse; + +public abstract class CollectionSpaceIntegrationTest { + + /* + * Package scoped methods. + */ + + void fillCollectionObject(CollectionObject co, String identifier) { + fillCollectionObject(co, "objectNumber-" + identifier, "objectName-" + + identifier); + } + + void fillCollectionObject(CollectionObject co, String objectNumber, + String objectName) { + co.setObjectNumber(objectNumber); + co.setObjectName(objectName); + } + + void fillIntake(Intake theIntake, String identifier) { + fillIntake(theIntake, "entryNumber-" + identifier, "entryDate-" + + identifier); + } + + void fillIntake(Intake theIntake, String entryNumber, String entryDate) { + theIntake.setEntryNumber(entryNumber); + theIntake.setEntryDate(entryDate); + } + + void fillRelation(Relation relation, String documentId1, String documentType1, + String documentId2, String documentType2, RelationshipType rt) + { + relation.setDocumentId1(documentId1); + relation.setDocumentType1(documentType1); + relation.setDocumentId2(documentId2); + relation.setDocumentType2(documentType2); + + relation.setRelationshipType(rt); + } + + String createIdentifier() { + long identifier = System.currentTimeMillis(); + return Long.toString(identifier); + } + + String extractId(ClientResponse res) { + String result = null; + + MultivaluedMap mvm = res.getMetadata(); + String uri = (String) ((ArrayList) mvm.get("Location")).get(0); + verbose("extractId:uri=" + uri); + String[] segments = uri.split("/"); + result = segments[segments.length - 1]; + verbose("id=" + result); + + return result; + } + + void verbose(String msg) { + System.out.println(msg); + } + + void verbose(String msg, Object o, Class clazz) { + try { + verbose(msg); + JAXBContext jc = JAXBContext.newInstance(clazz); + Marshaller m = jc.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + m.marshal(o, System.out); + } catch (Exception e) { + e.printStackTrace(); + } + } + + void verboseMap(MultivaluedMap map) { + for (Object entry : map.entrySet()) { + MultivaluedMap.Entry mentry = (MultivaluedMap.Entry) entry; + verbose(" name=" + mentry.getKey() + " value=" + mentry.getValue()); + } + } + +} 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 index 000000000..c8e3044b7 --- /dev/null +++ b/services/IntegrationTests/src/test/java/org/collectionspace/services/ItegrationTests/test/RelationIntegrationTest.java @@ -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 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 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 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 resultResponse = relationClient.getRelationList_SPO(collectionObjectCsid, + predicate, + intakeCsid); + + // + // Each relation returned in the list needs to match what we + // requested. + // + RelationList relationList = resultResponse.getEntity(); + List relationListItems = relationList.getRelationListItem(); + ClientResponse 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 index 000000000..18c510350 --- /dev/null +++ b/services/IntegrationTests/src/test/resources/log4j.properties @@ -0,0 +1,23 @@ +log4j.rootLogger=debug, stdout, R + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout + +# Pattern to output the caller's file name and line number. +log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n + +log4j.appender.R=org.apache.log4j.RollingFileAppender +log4j.appender.R.File=target/test-client.log + +log4j.appender.R.MaxFileSize=100KB +# Keep one backup file +log4j.appender.R.MaxBackupIndex=1 + +log4j.appender.R.layout=org.apache.log4j.PatternLayout +log4j.appender.R.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n + +#packages +log4j.logger.org.collectionspace=DEBUG +log4j.logger.org.apache=INFO +log4j.logger.httpclient=INFO +log4j.logger.org.jboss.resteasy=INFO