Skip to content

Commit

Permalink
wield a giant hammer and add an integration test.
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Feb 27, 2013
1 parent 7e712de commit dcb6295
Show file tree
Hide file tree
Showing 11 changed files with 296 additions and 11 deletions.
47 changes: 47 additions & 0 deletions pom.xml
Expand Up @@ -7,6 +7,14 @@
<groupId>fcrepo-jms-indexer-solr</groupId>
<artifactId>fcrepo-jms-indexer-solr</artifactId>
<version>4.0-SNAPSHOT</version>

<parent>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo</artifactId>
<version>4.0-SNAPSHOT</version>
</parent>


<properties>

<solr.version>4.1.0</solr.version>
Expand Down Expand Up @@ -97,13 +105,40 @@
<groupId>org.apache.abdera</groupId>
<artifactId>abdera-core</artifactId>
<version>${abdera.version}</version>

<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.abdera</groupId>
<artifactId>abdera-parser</artifactId>
<version>${abdera.version}</version>

<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-legacy-api</artifactId>
<version>4.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-jms</artifactId>
<version>4.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby-complete</artifactId>
Expand All @@ -127,6 +162,18 @@
<artifactId>guava-collections</artifactId>
<version>r03</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-extension-providers</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Expand Up @@ -4,12 +4,15 @@
import static com.google.common.collect.Iterators.all;
import static javax.jms.Session.AUTO_ACKNOWLEDGE;
import static org.apache.abdera.model.Text.Type.TEXT;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;

import java.io.IOException;
import java.io.StringWriter;
import java.util.concurrent.TimeUnit;

import javax.inject.Inject;
import javax.jms.Connection;
Expand All @@ -20,6 +23,11 @@
import org.apache.abdera.Abdera;
import org.apache.abdera.model.Entry;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.common.SolrInputDocument;
Expand All @@ -38,9 +46,25 @@
import com.google.common.base.Predicate;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"/spring-test/solr-indexer.xml"})
@ContextConfiguration({"/spring-test/master.xml"})
public class DemoRubySolrIndexerTest {


protected static final int SERVER_PORT = Integer.parseInt(System
.getProperty("test.port", "8080"));

protected static final String HOSTNAME = "localhost";

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


protected final PoolingClientConnectionManager connectionManager =
new PoolingClientConnectionManager();

protected static HttpClient client;


final private Logger logger = LoggerFactory
.getLogger(DemoRubySolrIndexerTest.class);

Expand All @@ -56,6 +80,14 @@ public class DemoRubySolrIndexerTest {
@Inject
private ScriptingSolrIndexer indexer;


public DemoRubySolrIndexerTest() {
connectionManager.setMaxTotal(Integer.MAX_VALUE);
connectionManager.setDefaultMaxPerRoute(5);
connectionManager.closeIdleConnections(3, TimeUnit.SECONDS);
client = new DefaultHttpClient(connectionManager);
}

private static Message getAddMessage(Session session) throws JMSException {
return getTestMessage(session, "addDatastream");
}
Expand Down Expand Up @@ -100,6 +132,25 @@ public void testSimpleScriptingSolrIndexer() throws JMSException,
verify(s).add(argThat(new MatchesSolrDocument(doc)));
}

@Test
public void testIntegrationScriptingSolrIndexer() throws JMSException,
IOException, SolrServerException {

SolrServer s = mock(SolrServer.class);
indexer.setSolrServer(s);

final HttpPost method = new HttpPost(serverAddress + "objects/" + "IndexingIntegrationTestObject1");
final HttpResponse response = client.execute(method);
assertEquals(201, response.getStatusLine().getStatusCode());


SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "IndexingIntegrationTestObject1");
doc.addField("__org.fcrepo.indexer.solr.class__", "DemoRubySolrIndexer");

verify(s, timeout(5000)).add(argThat(new MatchesSolrDocument(doc)));
}

@Before
public void acquireConnection() throws JMSException {
logger.debug(this.getClass().getName() + " acquiring JMS connection.");
Expand Down
File renamed without changes.
16 changes: 16 additions & 0 deletions src/test/resources/config/test_infinispan_configuration.xml
@@ -0,0 +1,16 @@
<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>

</global>

<default>

<transaction
transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"
transactionMode="TRANSACTIONAL" lockingMode="PESSIMISTIC"/>
</default>

</infinispan>
28 changes: 28 additions & 0 deletions src/test/resources/config/test_repository.json
@@ -0,0 +1,28 @@
{
"name" : "repo",
"jndiName" : "",
"workspaces" : {
"predefined" : ["fedora"],
"default" : "fedora",
"allowCreation" : true
},
"storage" : {
"cacheName" : "FedoraRepository",
"cacheConfiguration" : "config/test_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"]
}
24 changes: 24 additions & 0 deletions src/test/resources/spring-test/eventing.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 suports event management, including the internal
event bus (fedoraInternalEventBus) -->

<context:annotation-config/>

<!-- listener that moves JCR Events to the Fedora internal event bus -->
<bean class="org.fcrepo.observer.SimpleObserver"/>

<!-- used by bean above to filter which events get put on the bus -->
<bean name="fedoraEventFilter" class="org.fcrepo.observer.DefaultFilter"/>

<!-- Fedora's lightweight internal event bus. Currently memory-resident.-->
<bean name="fedoraInternalEventBus" class="com.google.common.eventbus.EventBus"/>


</beans>
30 changes: 30 additions & 0 deletions src/test/resources/spring-test/jms.xml
@@ -0,0 +1,30 @@
<?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 suports JMS publication-->

<context:annotation-config/>

<!-- publishes events from the internal bus to JMS -->
<bean class="org.fcrepo.observer.JMSTopicPublisher"/>

<!-- translates events from the internal bus to JMS, in Atom format -->
<bean class="org.fcrepo.messaging.legacy.LegacyMethodEventFactory" />


<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"
depends-on="jmsBroker">
<property name="brokerURL" value="vm://localhost"/>
</bean>

<bean name="jmsBroker" class="org.apache.activemq.xbean.BrokerFactoryBean">
<property name="config" value="classpath:/config/activemq.xml"/>
<property name="start" value="true"/>
</bean>

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

<!-- Master context for the test application. -->

<import resource="classpath:/spring-test/repo.xml"/>
<import resource="classpath:/spring-test/rest.xml"/>
<import resource="classpath:/spring-test/eventing.xml"/>
<import resource="classpath:/spring-test/jms.xml"/>
<import resource="classpath:/spring-test/solr-indexer.xml"/>

</beans>
25 changes: 25 additions & 0 deletions src/test/resources/spring-test/repo.xml
@@ -0,0 +1,25 @@
<?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="config/test_repository.json"/>
</bean>

<bean class="org.fcrepo.services.ObjectService"/>
<bean class="org.fcrepo.services.DatastreamService"/>

</beans>
59 changes: 59 additions & 0 deletions src/test/resources/spring-test/rest.xml
@@ -0,0 +1,59 @@
<?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"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:util="http://www.springframework.org/schema/util"
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
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

<import resource="classpath:META-INF/cxf/cxf.xml"/>

<context:property-placeholder/>

<!-- Context that houses JAX-RS Resources that compose the API
as well as some utility gear. -->

<context:annotation-config/>

<jaxrs:server address="http://localhost:${test.port:8080}/rest">
<jaxrs:serviceBeans>
<bean class="org.fcrepo.api.legacy.FedoraRepository"/>
<bean class="org.fcrepo.api.legacy.FedoraDatastreams"/>
<bean class="org.fcrepo.api.legacy.FedoraIdentifiers"/>
<bean class="org.fcrepo.api.legacy.FedoraNamespaces"/>
<bean class="org.fcrepo.api.legacy.FedoraObjects"/>
</jaxrs:serviceBeans>
<jaxrs:extensionMappings>
<entry key="json" value="application/json"/>
<entry key="xml" value="application/xml"/>
</jaxrs:extensionMappings>
<jaxrs:providers>
<bean class="org.fcrepo.exceptionhandlers.PathNotFoundExceptionMapper"/>
<bean class="org.fcrepo.exceptionhandlers.AccessControlExceptionMapper"/>
<bean class="org.fcrepo.exceptionhandlers.WildcardExceptionMapper">
<property name="showStackTrace" value="true"/>
</bean>
<bean class="org.apache.cxf.jaxrs.provider.JAXBElementProvider">
<property name="marshallerProperties">
<util:map>
<entry key="jaxb.formatted.output">
<value type="java.lang.Boolean">true</value>
</entry>
</util:map>
</property>
</bean>
<!--<bean class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
<property name="ignoreNamespaces" value="true"/>
</bean>-->
</jaxrs:providers>
</jaxrs:server>

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


</beans>
10 changes: 0 additions & 10 deletions src/test/resources/spring-test/solr-indexer.xml
Expand Up @@ -29,16 +29,6 @@
<!-- this is the Message Driven POJO (MDP) -->
<bean id="solrIndexer" class="org.fcrepo.indexer.solr.ScriptingSolrIndexer" />

<bean name="jmsBroker" class="org.apache.activemq.xbean.BrokerFactoryBean">
<property name="config" value="classpath:activemq.xml"/>
<property name="start" value="true"/>
</bean>

<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"
depends-on="jmsBroker">
<property name="brokerURL" value="vm://localhost?create=false"/>
</bean>

<bean id="destination" class="org.apache.activemq.command.ActiveMQTopic">
<constructor-arg value="fedora" />
</bean>
Expand Down

0 comments on commit dcb6295

Please sign in to comment.