Skip to content

Commit

Permalink
Added basic sanity integration test.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedurbin committed May 1, 2015
1 parent c4cba57 commit 5284e9c
Show file tree
Hide file tree
Showing 5 changed files with 334 additions and 49 deletions.
209 changes: 174 additions & 35 deletions pom.xml
@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -52,7 +53,7 @@
<version>4.3.6</version>
</dependency>


<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
Expand Down Expand Up @@ -101,6 +102,13 @@
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-webapp</artifactId>
<version>${project.version}</version>
<type>war</type>
<scope>test</scope>
</dependency>
</dependencies>

<repositories>
Expand All @@ -116,7 +124,7 @@
<enabled>true</enabled>
</snapshots>
</repository>

</repositories>

<pluginRepositories>
Expand All @@ -133,49 +141,180 @@
</pluginRepository>
</pluginRepositories>


<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.4.12</version>
<configuration>
<configuration>
<properties>
<cargo.servlet.port>${fcrepo.dynamic.test.port}</cargo.servlet.port>
</properties>
</configuration>
<deployables>
<deployable>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-webapp</artifactId>
<type>war</type>
</deployable>
</deployables>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${checkstyle.plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-build-tools</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<configuration>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<consoleOutput>true</consoleOutput>
<logViolationsToConsole>true</logViolationsToConsole>
<failsOnError>true</failsOnError>
<failOnViolation>true</failOnViolation>
<violationSeverity>warning</violationSeverity>
<configLocation>fcrepo-checkstyle/checkstyle.xml</configLocation>
<suppressionsLocation>fcrepo-checkstyle/checkstyle-suppressions.xml</suppressionsLocation>
</configuration>
<executions>
<execution>
<id>checkstyle</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${checkstyle.plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-build-tools</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<configuration>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<consoleOutput>true</consoleOutput>
<logViolationsToConsole>true</logViolationsToConsole>
<failsOnError>true</failsOnError>
<failOnViolation>true</failOnViolation>
<violationSeverity>warning</violationSeverity>
<configLocation>fcrepo-checkstyle/checkstyle.xml</configLocation>
<suppressionsLocation>fcrepo-checkstyle/checkstyle-suppressions.xml</suppressionsLocation>
</configuration>
<executions>
<execution>
<id>checkstyle</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>reserve-network-port</id>
<goals>
<goal>reserve-network-port</goal>
</goals>
<phase>process-test-resources</phase>
<configuration>
<portNames>
<!-- reserve ports for integration tests -->
<portName>fcrepo.dynamic.jms.port</portName>
<portName>fcrepo.dynamic.test.port</portName>
<portName>fcrepo.dynamic.stomp.port</portName>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<!-- export ports for integration tests to system.env-->
<systemPropertyVariables>
<fcrepo.dynamic.jms.port>${fcrepo.dynamic.jms.port}</fcrepo.dynamic.jms.port>
<fcrepo.dynamic.test.port>${fcrepo.dynamic.test.port}</fcrepo.dynamic.test.port>
<fcrepo.dynamic.stomp.port>${fcrepo.dynamic.stomp.port}</fcrepo.dynamic.stomp.port>
<integration-test>true</integration-test>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<id>perform-it</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify-it</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<executions>
<execution>
<id>start-cargo</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-cargo</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>jetty7x</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<container>
<containerId>jetty7x</containerId>
<artifactInstaller>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-distribution</artifactId>
<version>7.6.15.v20140411</version>
</artifactInstaller>
<systemProperties>
<fcrepo.dynamic.jms.port>${fcrepo.dynamic.jms.port}</fcrepo.dynamic.jms.port>
<fcrepo.dynamic.stomp.port>${fcrepo.dynamic.stomp.port}</fcrepo.dynamic.stomp.port>
</systemProperties>
</container>
</configuration>
<dependencies>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>
Expand Up @@ -110,21 +110,13 @@ public void processObjectVersions(final Iterable<ObjectVersionReference> version

final String objectPath = idMapper.mapObjectPath(version.getObjectInfo().getPid());
if (object == null) {
try {
object = repo.createObject(objectPath);
} catch (FedoraException ex) {
// perhaps the resource already exists for a good reason....
if (repo.exists(objectPath)) {
object = repo.getObject(objectPath);
if (isPlaceholder(object)) {
// this is cool, the object was created just as a placeholder
// for outbound relationships on other objects.
} else {
throw new RuntimeException("An object already exists at \"" + objectPath + "\"!", ex);
}
} else {
throw ex;
if (repo.exists(objectPath)) {
object = repo.getObject(objectPath);
if (!isPlaceholder(object)) {
throw new RuntimeException("An object already exists at \"" + objectPath + "\"!");
}
} else {
object = repo.createObject(objectPath);
}
}

Expand Down
@@ -0,0 +1,54 @@
package org.fcrepo.migration.handlers;

import junit.framework.Assert;
import org.fcrepo.client.FedoraException;
import org.fcrepo.client.FedoraRepository;
import org.fcrepo.migration.Migrator;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.xml.stream.XMLStreamException;

import static org.slf4j.LoggerFactory.getLogger;

/**
* @author mdurbin
*/
public class BasicObjectVersionHandlerIT {

final static Logger LOGGER = getLogger(BasicObjectVersionHandlerIT.class);

private static FedoraRepository repo;

@BeforeClass
public static void migrateTestData() throws XMLStreamException {
final ConfigurableApplicationContext context =
new ClassPathXmlApplicationContext("spring/it-setup.xml");
final Migrator m = (Migrator) context.getBean("migrator");
repo = (FedoraRepository) context.getBean("fedora4Client");
m.run();
context.close();
}

@Test
public void testObjectsWereCreated() throws FedoraException {
Assert.assertTrue(repo.exists("migrated-fedora3/example/1"));
Assert.assertTrue(repo.exists("migrated-fedora3/example/2"));
}

@Test
public void testPlaceholdersWereCreated() throws FedoraException {
Assert.assertTrue(repo.exists("migrated-fedora3/cmodel/1"));
}

@Test
public void testExample1DatastreamsWereCreated() throws FedoraException {
for (String dsid : new String[] { "DS1", "DS2", "DS3", "DS4" }) {
Assert.assertTrue(repo.exists("migrated-fedora3/example/1/" + dsid));
}
}

}
48 changes: 48 additions & 0 deletions src/test/resources/exported/example2-foxml.xml
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<foxml:digitalObject VERSION="1.1" PID="example:2" xmlns:foxml="info:fedora/fedora-system:def/foxml#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="info:fedora/fedora-system:def/foxml# http://www.fedora.info/definitions/1/0/foxml1-1.xsd">
<foxml:objectProperties>
<foxml:property NAME="info:fedora/fedora-system:def/model#state" VALUE="Active"/>
<foxml:property NAME="info:fedora/fedora-system:def/model#label" VALUE="This is an an example object with a relationship to another object."/>
<foxml:property NAME="info:fedora/fedora-system:def/model#ownerId" VALUE=""/>
<foxml:property NAME="info:fedora/fedora-system:def/model#createdDate" VALUE="2015-05-01T15:43:28.868Z"/>
<foxml:property NAME="info:fedora/fedora-system:def/view#lastModifiedDate" VALUE="2015-05-01T19:22:14.507Z"/>
</foxml:objectProperties>
<foxml:datastream ID="AUDIT" STATE="A" CONTROL_GROUP="X" VERSIONABLE="false">
<foxml:datastreamVersion ID="AUDIT.0" LABEL="Audit Trail for this object" CREATED="2015-05-01T15:43:28.868Z" MIMETYPE="text/xml" FORMAT_URI="info:fedora/fedora-system:format/xml.fedora.audit">
<foxml:xmlContent>
<audit:auditTrail xmlns:audit="info:fedora/fedora-system:def/audit#">
<audit:record ID="AUDREC1">
<audit:process type="Fedora API-M"/>
<audit:action>addDatastream</audit:action>
<audit:componentID>RELS-EXT</audit:componentID>
<audit:responsibility>fedoraAdmin</audit:responsibility>
<audit:date>2015-05-01T19:22:14.507Z</audit:date>
<audit:justification/>
</audit:record>
</audit:auditTrail>
</foxml:xmlContent>
</foxml:datastreamVersion>
</foxml:datastream>
<foxml:datastream ID="DC" STATE="A" CONTROL_GROUP="X" VERSIONABLE="true">
<foxml:datastreamVersion ID="DC1.0" LABEL="Dublin Core Record for this object" CREATED="2015-05-01T15:43:28.868Z" MIMETYPE="text/xml" FORMAT_URI="http://www.openarchives.org/OAI/2.0/oai_dc/" SIZE="429">
<foxml:xmlContent>
<oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd">
<dc:title>This is an an example object with a relationship to another object.</dc:title>
<dc:identifier>example:2</dc:identifier>
</oai_dc:dc>
</foxml:xmlContent>
</foxml:datastreamVersion>
</foxml:datastream>
<foxml:datastream ID="RELS-EXT" STATE="A" CONTROL_GROUP="X" VERSIONABLE="true">
<foxml:datastreamVersion ID="RELS-EXT.0" LABEL="Fedora object to object relationships." CREATED="2015-05-01T19:22:14.507Z" MIMETYPE="application/rdf+xml" SIZE="381">
<foxml:xmlContent>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="info:fedora/example:2">
<isPartOf xmlns="info:fedora/fedora-system:def/relations-external#" rdf:resource="info:fedora/example:1"/>
<hasModel xmlns="info:fedora/fedora-system:def/model#" rdf:resource="info:fedora/cmodel:1"/>
</rdf:Description>
</rdf:RDF>
</foxml:xmlContent>
</foxml:datastreamVersion>
</foxml:datastream>
</foxml:digitalObject>

0 comments on commit 5284e9c

Please sign in to comment.