Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
388 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/test/java/org/fcrepo/federation/bagit/AbstractResourceIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
|
||
package org.fcrepo.federation.bagit; | ||
|
||
import java.io.IOException; | ||
import java.io.UnsupportedEncodingException; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.ClientProtocolException; | ||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.client.methods.HttpPost; | ||
import org.apache.http.client.methods.HttpPut; | ||
import org.apache.http.client.methods.HttpUriRequest; | ||
import org.apache.http.entity.StringEntity; | ||
import org.apache.http.impl.client.DefaultHttpClient; | ||
import org.apache.http.impl.conn.PoolingClientConnectionManager; | ||
import org.junit.Before; | ||
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/master.xml") | ||
public abstract class AbstractResourceIT { | ||
|
||
protected Logger logger; | ||
|
||
@Before | ||
public void setLogger() { | ||
logger = LoggerFactory.getLogger(this.getClass()); | ||
} | ||
|
||
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; | ||
|
||
public AbstractResourceIT() { | ||
connectionManager.setMaxTotal(Integer.MAX_VALUE); | ||
connectionManager.setDefaultMaxPerRoute(5); | ||
connectionManager.closeIdleConnections(3, TimeUnit.SECONDS); | ||
client = new DefaultHttpClient(connectionManager); | ||
} | ||
|
||
protected static HttpPost postObjMethod(final String pid) { | ||
return new HttpPost(serverAddress + "objects/" + pid); | ||
} | ||
|
||
protected static HttpPost postDSMethod(final String pid, final String ds, | ||
final String content) throws UnsupportedEncodingException { | ||
final HttpPost post = | ||
new HttpPost(serverAddress + "objects/" + pid + | ||
"/datastreams/" + ds); | ||
post.setEntity(new StringEntity(content)); | ||
return post; | ||
} | ||
|
||
protected static HttpPut putDSMethod(final String pid, final String ds) { | ||
return new HttpPut(serverAddress + "objects/" + pid + "/datastreams/" + | ||
ds); | ||
} | ||
|
||
protected HttpResponse execute(HttpUriRequest method) | ||
throws ClientProtocolException, IOException { | ||
logger.debug("Executing: " + method.getMethod() + " to " + | ||
method.getURI()); | ||
return client.execute(method); | ||
} | ||
|
||
protected int getStatus(HttpUriRequest method) | ||
throws ClientProtocolException, IOException { | ||
return execute(method).getStatusLine().getStatusCode(); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/test/java/org/fcrepo/federation/bagit/BagItConnectorIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
package org.fcrepo.federation.bagit; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.ClientProtocolException; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.util.EntityUtils; | ||
import org.fcrepo.federation.bagit.AbstractResourceIT; | ||
import org.junit.Test; | ||
|
||
public class BagItConnectorIT extends AbstractResourceIT { | ||
|
||
@Test | ||
public void tryOneObject() throws ClientProtocolException, IOException { | ||
logger.debug("Found objects: " + | ||
EntityUtils.toString(client.execute( | ||
new HttpGet(serverAddress + "objects/")).getEntity())); | ||
final String objName = "BagItFed1"; | ||
final HttpResponse response = | ||
client.execute(new HttpGet(serverAddress + "objects/" + objName)); | ||
assertEquals("Couldn't find federated object!", 200, response | ||
.getStatusLine().getStatusCode()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?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="TRACE"> | ||
<appender-ref ref="STDOUT"/> | ||
</logger> | ||
<logger name="gov.loc" additivity="false" level="TRACE"> | ||
<appender-ref ref="STDOUT"/> | ||
</logger> | ||
<logger name="org.modeshape" additivity="false" level="WARN"> | ||
<appender-ref ref="STDOUT"/> | ||
</logger> | ||
<logger name="org.apache.cxf" additivity="false" level="WARN"> | ||
<appender-ref ref="STDOUT"/> | ||
</logger> | ||
<logger name="org.apache.http.client" additivity="false" level="DEBUG"> | ||
<appender-ref ref="STDOUT"/> | ||
</logger> | ||
<root additivity="false" level="INFO"> | ||
<appender-ref ref="STDOUT"/> | ||
</root> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?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"/> | ||
|
||
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?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"> | ||
<property name="repositoryConfiguration" value="${fcrepo.modeshape.configuration:test_repository.json}"/> | ||
</bean> | ||
|
||
<bean class="org.modeshape.jcr.JcrRepositoryFactory"/> | ||
<bean class="org.fcrepo.services.ObjectService"/> | ||
<bean class="org.fcrepo.services.LowLevelStorageService"/> | ||
<bean class="org.fcrepo.services.DatastreamService"/> | ||
|
||
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?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.FedoraDatastreams"/> | ||
<bean class="org.fcrepo.api.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> | ||
</jaxrs:providers> | ||
</jaxrs:server> | ||
|
||
<bean class="org.fcrepo.session.SessionFactory" /> | ||
|
||
<!-- Mints PIDs--> | ||
<bean class="org.fcrepo.identifiers.UUIDPidMinter"/> | ||
|
||
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Test datastream 1 |
Oops, something went wrong.