Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed fcrepo-dc so that build works: https://www.pivotaltracker.com/s…
  • Loading branch information
ajs6f committed Feb 8, 2013
1 parent c65b26f commit 73b7e66
Show file tree
Hide file tree
Showing 9 changed files with 273 additions and 58 deletions.
8 changes: 8 additions & 0 deletions fcrepo-dc/pom.xml
Expand Up @@ -15,6 +15,10 @@
<artifactId>fcrepo-kernel</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
Expand All @@ -23,6 +27,10 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
Expand Down
3 changes: 1 addition & 2 deletions fcrepo-dc/src/main/java/org/fcrepo/generator/DublinCore.java
Expand Up @@ -19,15 +19,14 @@
import org.fcrepo.AbstractResource;
import org.fcrepo.generator.dublincore.AbstractIndexer;

@Path("/objects/{pid}")
@Path("/objects/{pid}/oai_dc")
public class DublinCore extends AbstractResource {

@Resource
List<AbstractIndexer> indexers;

@GET
@Produces(TEXT_XML)
@Path("/oai_dc")
public Response getObjectAsDublinCore(@PathParam("pid") final String pid)
throws RepositoryException {
final Session session = repo.login();
Expand Down
121 changes: 71 additions & 50 deletions fcrepo-dc/src/test/java/org/fcrepo/generator/DublinCoreTest.java
@@ -1,3 +1,4 @@

package org.fcrepo.generator;

import static java.util.regex.Pattern.DOTALL;
Expand All @@ -6,60 +7,80 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.fcrepo.AbstractResourceTest;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"/spring-test/generator.xml", "/spring-test/repo.xml"})
public class DublinCoreTest {

protected static final int SERVER_PORT = 8080;

protected static final String HOSTNAME = "localhost";

protected static final String serverAddress = "http://" + HOSTNAME + ":" +
SERVER_PORT + "/";

protected final HttpClient client = new HttpClient();

protected static Logger logger;

@BeforeClass
public static void setLogger() {
logger = LoggerFactory.getLogger(DublinCoreTest.class);
}

@Test
public void testJcrPropertiesBasedOaiDc() throws Exception {
PostMethod createObjMethod =
new PostMethod(serverAddress + "objects/fdsa");
client.executeMethod(createObjMethod);

GetMethod getWorstCaseOaiMethod =
new GetMethod(serverAddress + "objects/fdsa/oai_dc");
getWorstCaseOaiMethod.setRequestHeader("Accept", TEXT_XML);
int status = client.executeMethod(getWorstCaseOaiMethod);
assertEquals(200, status);

final String response = getWorstCaseOaiMethod.getResponseBodyAsString();
assertTrue("Didn't find oai_dc!", compile("oai_dc", DOTALL).matcher(
response).find());

assertTrue("Didn't find dc:identifier!", compile("dc:identifier",
DOTALL).matcher(response).find());
}

@Test
public void testWellKnownPathOaiDc() throws Exception {
PostMethod createObjMethod =
new PostMethod(serverAddress + "objects/lkjh");
client.executeMethod(createObjMethod);

PostMethod createDSMethod =
new PostMethod(serverAddress + "objects/lkjh/datastreams/DC");

createDSMethod.setRequestEntity(new StringRequestEntity(
"marbles for everyone", null, null));

client.executeMethod(createDSMethod);

GetMethod getWorstCaseOaiMethod =
new GetMethod(serverAddress + "objects/lkjh/oai_dc");
getWorstCaseOaiMethod.setRequestHeader("Accept", TEXT_XML);
int status = client.executeMethod(getWorstCaseOaiMethod);
assertEquals(200, status);

@ContextConfiguration({ "/spring-test/indexer.xml", "/spring-test/rest.xml",
"/spring-test/repo.xml" })
public class DublinCoreTest extends AbstractResourceTest {

@Test
public void testJcrPropertiesBasedOaiDc() throws Exception {
PostMethod createObjMethod = new PostMethod(serverAddress
+ "objects/fdsa");
client.executeMethod(createObjMethod);

GetMethod getWorstCaseOaiMethod = new GetMethod(serverAddress
+ "objects/fdsa/oai_dc");
getWorstCaseOaiMethod.setRequestHeader("Accept", TEXT_XML);
int status = client.executeMethod(getWorstCaseOaiMethod);
assertEquals(200, status);

final String response = getWorstCaseOaiMethod.getResponseBodyAsString();
assertTrue("Didn't find oai_dc!",
compile("oai_dc", DOTALL).matcher(response).find());

assertTrue("Didn't find dc:identifier!",
compile("dc:identifier", DOTALL).matcher(response).find());
}

@Test
public void testWellKnownPathOaiDc() throws Exception {
PostMethod createObjMethod = new PostMethod(serverAddress
+ "objects/lkjh");
client.executeMethod(createObjMethod);

PostMethod createDSMethod = new PostMethod(serverAddress
+ "objects/lkjh/datastreams/DC");

createDSMethod.setRequestEntity(new StringRequestEntity(
"marbles for everyone", null, null));

client.executeMethod(createDSMethod);

GetMethod getWorstCaseOaiMethod = new GetMethod(serverAddress
+ "objects/lkjh/oai_dc");
getWorstCaseOaiMethod.setRequestHeader("Accept", TEXT_XML);
int status = client.executeMethod(getWorstCaseOaiMethod);
assertEquals(200, status);

final String response = getWorstCaseOaiMethod.getResponseBodyAsString();
assertTrue("Didn't find our datastream!",
compile("marbles for everyone", DOTALL).matcher(response)
.find());
}
final String response = getWorstCaseOaiMethod.getResponseBodyAsString();
assertTrue("Didn't find our datastream!", compile(
"marbles for everyone", DOTALL).matcher(response).find());
}
}
91 changes: 91 additions & 0 deletions fcrepo-dc/src/test/resources/infinispan_configuration.xml
@@ -0,0 +1,91 @@
<infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:infinispan:config:5.2 http://www.infinispan.org/schemas/infinispan-config-5.2.xsd"
xmlns="urn:infinispan:config:5.2">

<global>
<!-- Defines the global settings shared by all caches -->
<transport>
<properties>
<property name="configurationFile" value="${fcrepo.modeshape.ispn.configuration:jgroups-infinispan.xml}"/>
</properties>
</transport>
</global>

<default>
<!--
Defines the default behavior for all caches, including those created dynamically (e.g., when a
repository uses a cache that doesn't exist in this configuration).
-->
<clustering mode="distribution">
<sync/>
<l1 enabled="false" lifespan="0" onRehash="false"/>
<hash numOwners="1"/>
<stateTransfer fetchInMemoryState="true"/>
</clustering>
</default>

<namedCache name="FedoraRepository">
<!--
Our Infinispan cache needs to be transactional. However, we'll also configure it to
use pessimistic locking, which is required whenever applications will be concurrently
updating nodes within the same process. If you're not sure, use pessimistic locking.
-->
<clustering mode="distribution">
<sync/>
<l1 enabled="false" lifespan="0" onRehash="false"/>
<hash numOwners="1"/>
<stateTransfer fetchInMemoryState="true"/>
</clustering>

<eviction maxEntries="100" strategy="LRU" threadPolicy="DEFAULT"/>

<transaction
transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"
transactionMode="TRANSACTIONAL" lockingMode="PESSIMISTIC"/>
<!--
Define the cache loaders (i.e., cache stores). Passivation is false because we want *all*
data to be persisted, not just what doesn't fit into memory. Shared is false because there
are no other caches sharing this file store. We set preload to false for lazy loading;
may be improved by preloading and configuring eviction.
We can have multiple cache loaders, which get chained. But we'll define just one.
-->

<loaders passivation="false" shared="false" preload="true">

<!--
The 'fetchPersistentState' attribute applies when this cache joins the cluster; the value doesn't
really matter to us in this case. See the documentation for more options.
-->
<loader class="org.infinispan.loaders.file.FileCacheStore" fetchPersistentState="false"
purgeOnStartup="true">
<!-- See the documentation for more configuration examples and flags. -->
<properties>
<!-- We have to set the location where we want to store the data. -->
<property name="location" value="target/FedoraRepository/storage"/>

<property name="fsyncMode" value="perWrite"/>
</properties>
<!-- This repository isn't clustered, so we could set up the SingletonStore.
singletonStore enabled="true" pushStateWhenCoordinator="true" pushStateTimeout="20000"/>
-->
<!--
We could use "write-behind", which actually writes to the file system asynchronously,
which can improve performance as seen by the JCR client.
Plus changes are coalesced, meaning that if multiple changes are enqueued for the
same node, only the last one is written. (This is good much of the time, but not
always.)
<async enabled="true" flushLockTimeout="15000" threadPoolSize="5"/>
-->
</loader>
<!-- fall back to other nodes if we don't have this data -->
<loader class="org.infinispan.loaders.cluster.ClusterCacheLoader"
fetchPersistentState="false" purgeOnStartup="false">
<properties>
<property name="remoteCallTimeout" value="20000"/>
</properties>

</loader>
</loaders>
</namedCache>
</infinispan>
16 changes: 16 additions & 0 deletions fcrepo-dc/src/test/resources/logback-test.xml
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%p %d{HH:mm:ss.SSS} \(%c{0}\) %m%n</pattern>
</encoder>
</appender>

<logger name="org.fcrepo" additivity="false" level="DEBUG">
<appender-ref ref="STDOUT"/>
</logger>
<root additivity="false" level="WARN">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
42 changes: 42 additions & 0 deletions fcrepo-dc/src/test/resources/my_repository.json
@@ -0,0 +1,42 @@
{
"name" : "repo",
"jndiName" : "",
"workspaces" : {
"predefined" : ["fedora"],
"default" : "fedora",
"allowCreation" : true
},
"clustering" : {
"clusterName" : "modeshape",
"channelConfiguration" : "${fcrepo.modeshape.jgroups.configuration:jgroups-modeshape.xml}"
},
"query" : {
"enabled" : true,
"rebuildUponStartup" : "if_missing",
"indexStorage" : {
"type" : "filesystem",
"location" : "${fcrepo.modeshape.index.location:indexes}",
"lockingStrategy" : "native",
"fileSystemAccessType" : "auto"
}
},
"storage" : {
"cacheName" : "FedoraRepository",
"cacheConfiguration" : "infinispan_configuration.xml",
"binaryStorage" : {
"type" : "cache",
"dataCacheName" : "FedoraRepository",
"metadataCacheName" : "FedoraRepository"
}
},
"security" : {
"anonymous" : {
"roles" : ["readonly","readwrite","admin"],
"useOnFailedLogin" : false
},
"providers" : [
{ "classname" : "servlet" }
]
},
"node-types" : ["fedora-node-types.cnd"]
}
Expand Up @@ -14,18 +14,26 @@

<context:annotation-config/>

<jaxrs:server address="http://localhost:8080/" bus="cxf">
<jaxrs:server address="http://localhost:8080">
<jaxrs:serviceBeans>
<bean class="org.fcrepo.modeshape.indexer.DublinCore"/>
<bean class="org.fcrepo.generator.DublinCore"/>
<bean class="org.fcrepo.FedoraObjects"/>
<bean class="org.fcrepo.FedoraDatastreams"/>
</jaxrs:serviceBeans>
</jaxrs:server>

<util:list id="indexers" value-type="org.fcrepo.modeshape.indexer.dublincore.AbstractIndexer">
<bean id="wkpIndexer" class="org.fcrepo.modeshape.indexer.dublincore.IndexFromWellKnownPath">
<util:list id="indexers" value-type="org.fcrepo.generator.dublincore.AbstractIndexer">
<bean class="org.fcrepo.generator.dublincore.IndexFromWellKnownPath">
<property name="wellKnownPath" value="DC"/>
</bean>
<bean id="DCfromJcrPropertiesIndexer"
class="org.fcrepo.modeshape.indexer.dublincore.IndexFromJcrProperties"/>
<bean class="org.fcrepo.generator.dublincore.IndexFromJcrProperties"/>
</util:list>

<!-- Supports JSON output for API methods. Should be replaced with a properly-
configured JAX-RS Provider-->
<bean class="org.codehaus.jackson.map.ObjectMapper"/>

<!-- Mints PIDs-->
<bean class="org.fcrepo.identifiers.UUIDPidMinter"/>

</beans>
24 changes: 24 additions & 0 deletions fcrepo-dc/src/test/resources/spring-test/repo.xml
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<!-- Context that supports the actual ModeShape JCR itself -->

<context:annotation-config/>

<bean name="modeshapeRepofactory"
class="org.fcrepo.spring.ModeShapeRepositoryFactoryBean"/>

<bean class="org.modeshape.jcr.JcrRepositoryFactory"/>

<bean class="org.springframework.core.io.ClassPathResource">
<qualifier type="ModeShapeRepositoryConfiguration"/>
<constructor-arg type="String" value="my_repository.json"/>
</bean>


</beans>
6 changes: 6 additions & 0 deletions pom.xml
Expand Up @@ -92,6 +92,12 @@
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${cxf.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
Expand Down

0 comments on commit 73b7e66

Please sign in to comment.