Skip to content

Commit

Permalink
Adds integration test support to kitchen sink.
Browse files Browse the repository at this point in the history
  • Loading branch information
Edwin Shin committed Apr 29, 2013
1 parent 01d79fd commit ed697f0
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 9 deletions.
55 changes: 54 additions & 1 deletion pom.xml
Expand Up @@ -13,6 +13,9 @@
<properties>
<project_name>fcrepo-kitchen-sink</project_name>
<opencmis.version>0.7.0</opencmis.version>

<!-- integration test properties -->
<test.context.path>/</test.context.path>
</properties>
<dependencies>
<dependency>
Expand All @@ -26,11 +29,13 @@
<artifactId>fcrepo-rss</artifactId>
<version>${project.version}</version>
</dependency>
<!--
<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-legacy-api</artifactId>
<version>${project.version}</version>
</dependency>
-->
<dependency>
<groupId>org.fcrepo</groupId>
<artifactId>fcrepo-webhooks</artifactId>
Expand Down Expand Up @@ -150,16 +155,64 @@
</overlays>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<configuration>
<portNames>
<portName>test.port</portName>
<!-- reserves the stop port for jetty-maven-plugin -->
<portName>jetty.port.stop</portName>
</portNames>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<loginServices>
<loginService implementation="org.eclipse.jetty.security.HashLoginService">
<name>fcrepo</name>
<config>${project.build.directory}/test-classes/jetty-users.properties</config>
</loginService>
</loginServices>
<scanIntervalSeconds>2</scanIntervalSeconds>
<stopKey>STOP</stopKey>
<webApp>
<contextPath>/</contextPath>
<allowDuplicateFragmentNames>true</allowDuplicateFragmentNames>
<contextPath>${test.context.path}</contextPath>
</webApp>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>stop</goal>
<goal>start</goal>
</goals>
<configuration>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>${test.port}</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
<daemon>true</daemon>
<stopPort>${jetty.port.stop}</stopPort>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
<configuration>
<stopPort>${jetty.port.stop}</stopPort>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
@@ -1,5 +1,5 @@

package org.fcrepo.example.cmis;
package org.fcrepo.integration;

import static org.junit.Assert.assertEquals;

Expand All @@ -25,15 +25,25 @@
import org.junit.Test;
import org.w3c.dom.Element;


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

private Session session;
/**
* The server port of the application, set as system property by
* maven-failsafe-plugin.
*/
private static final String SERVER_PORT = System.getProperty("test.port");

/**
* The context path of the application (including the leading "/"), set as
* system property by maven-failsafe-plugin.
*/
private static final String CONTEXT_PATH = System
.getProperty("test.context.path");

private static final String BASE_URL = "http://localhost:8080";
protected static final String HOSTNAME = "localhost";

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

protected static HttpClient client;

Expand All @@ -47,10 +57,13 @@ public class CmisIT {
client = new DefaultHttpClient(connectionManager);
}

private Session session;

@Before
public void setUp() throws Exception {
assertEquals(201,
getStatus(new HttpPost(BASE_URL + "/rest/objects/new")));
getStatus(new HttpPost(BASE_URL + CONTEXT_PATH +
"/rest/objects/new")));

// default factory implementation
SessionFactoryImpl factory = SessionFactoryImpl.newInstance();
Expand Down
71 changes: 71 additions & 0 deletions src/test/java/org/fcrepo/integration/KitchenSinkIT.java
@@ -0,0 +1,71 @@

package org.fcrepo.integration;

import static org.junit.Assert.assertEquals;

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

import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class KitchenSinkIT {

/**
* The server port of the application, set as system property by
* maven-failsafe-plugin.
*/
private static final String SERVER_PORT = System.getProperty("test.port");

/**
* The context path of the application (including the leading "/"), set as
* system property by maven-failsafe-plugin.
*/
private static final String CONTEXT_PATH = System
.getProperty("test.context.path");

protected Logger logger;

@Before
public void setLogger() {
logger = LoggerFactory.getLogger(this.getClass());
}

protected static final String HOSTNAME = "localhost";

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

protected static final PoolingClientConnectionManager connectionManager =
new PoolingClientConnectionManager();

protected static HttpClient client;

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

@Test
public void doASanityCheck() throws IOException {
assertEquals(200, getStatus(new HttpGet(serverAddress +
"/rest/fcr:describe")));
}

protected int getStatus(final HttpUriRequest method)
throws ClientProtocolException, IOException {
logger.debug("Executing: " + method.getMethod() + " to " +
method.getURI());
return client.execute(method).getStatusLine().getStatusCode();
}
}
9 changes: 9 additions & 0 deletions src/test/java/org/fcrepo/integration/package-info.java
@@ -0,0 +1,9 @@
/**
*
*/
/**
* @author Edwin Shin
*
*/

package org.fcrepo.integration;

0 comments on commit ed697f0

Please sign in to comment.