Skip to content

Commit

Permalink
start trying to get Weld to work with ContainerWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
barmintor committed Nov 18, 2013
1 parent 0e33a71 commit 61e29f5
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 32 deletions.
5 changes: 5 additions & 0 deletions fcrepo-http-api/pom.xml
Expand Up @@ -167,6 +167,11 @@
<artifactId>mimepull</artifactId>
<version>1.9.3</version>
</dependency>
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Expand Up @@ -42,17 +42,19 @@
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.util.EntityUtils;
import org.fcrepo.http.commons.IntegrationTestConfigLocation;
import org.fcrepo.http.commons.IntegrationTestPort;
import org.fcrepo.http.commons.WeldJUnit4ClassRunner;
import org.fcrepo.http.commons.domain.RDFMediaType;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.hp.hpl.jena.rdf.model.Model;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/spring-test/test-container.xml")
@RunWith(WeldJUnit4ClassRunner.class)
@IntegrationTestConfigLocation("/web.xml")
@IntegrationTestPort(8080)
public abstract class AbstractResourceIT {

protected Logger logger;
Expand Down
2 changes: 1 addition & 1 deletion fcrepo-http-api/src/test/resources/web.xml
Expand Up @@ -13,7 +13,7 @@
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>

<servlet>
Expand Down
6 changes: 5 additions & 1 deletion fcrepo-http-commons/pom.xml
Expand Up @@ -121,7 +121,6 @@
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
Expand Down Expand Up @@ -233,6 +232,11 @@
<groupId>org.openrdf.sesame</groupId>
<artifactId>sesame-rio-turtle</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Expand Up @@ -16,10 +16,13 @@

package org.fcrepo.http.commons.session;

import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.jcr.Session;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.SecurityContext;
import javax.ws.rs.ext.Provider;

import org.glassfish.hk2.api.Factory;
import org.glassfish.jersey.process.internal.RequestScoped;
Expand All @@ -29,6 +32,7 @@
* credentials.
*/
@RequestScoped
@Provider
public class AuthenticatedSessionProvider implements
Factory<Session> {

Expand All @@ -53,13 +57,14 @@ public AuthenticatedSessionProvider(final SessionFactory sessions,
}

@Override
@Produces
public Session provide() {
Session result = sessions.getSession(securityContext, request);
return result;
}

@Override
public void dispose(Session instance) {
public void dispose(@Disposes Session instance) {
// no-op until we can get this called
// it ought to be where we handle logout
}
Expand Down
@@ -0,0 +1,27 @@
package org.fcrepo.http.commons;

import javax.annotation.ManagedBean;

@ManagedBean
public class IntegrationTestConfig {

private String location = "/web.xml";
private int port = 8080;

public void setLocation(String location) {
this.location = location;
}

public String getLocation() {
return this.location;
}

public void setPort(int port) {
this.port = port;
}

public int getPort() {
return this.port;
}

}
@@ -0,0 +1,15 @@
package org.fcrepo.http.commons;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;


@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)public @interface IntegrationTestConfigLocation {

String value()default "/web.xml";
}
@@ -0,0 +1,15 @@
package org.fcrepo.http.commons;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;


@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)public @interface IntegrationTestPort {

int value() default 8090;
}
@@ -0,0 +1,37 @@
package org.fcrepo.http.commons;

import javax.enterprise.inject.spi.CDI;

import org.fcrepo.http.commons.test.util.ContainerWrapper;
import org.jboss.weld.Weld;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.InitializationError;


public class WeldJUnit4ClassRunner extends BlockJUnit4ClassRunner {
private Class<?> klass;
private Weld weld;
private CDI<Object> container;

public WeldJUnit4ClassRunner(Class<?> klass) throws InitializationError {
super(klass);
this.klass = klass;
this.weld = new Weld();
IntegrationTestConfig config = weld.select(IntegrationTestConfig.class).get();

if (klass.isAnnotationPresent(IntegrationTestPort.class)) {
config.setPort(klass.getAnnotation(IntegrationTestPort.class).value());
}
if (klass.isAnnotationPresent(IntegrationTestConfigLocation.class)) {
config.setLocation(klass.getAnnotation(IntegrationTestConfigLocation.class).value());
}
ContainerWrapper cw = weld.select(ContainerWrapper.class).get();
}


@Override
protected Object createTest() throws Exception {
return this.weld.select(this.klass).get();
}

}
Expand Up @@ -22,11 +22,14 @@
import java.net.URI;
import java.util.Collection;

import javax.annotation.ManagedBean;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;

import org.fcrepo.http.commons.IntegrationTestConfig;
import org.fcrepo.http.commons.webxml.WebAppConfig;
import org.fcrepo.http.commons.webxml.bind.ContextParam;
import org.fcrepo.http.commons.webxml.bind.Filter;
Expand All @@ -40,29 +43,18 @@
import org.glassfish.grizzly.servlet.ServletRegistration;
import org.glassfish.grizzly.servlet.WebappContext;
import org.slf4j.Logger;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class ContainerWrapper implements ApplicationContextAware {
@ManagedBean
public class ContainerWrapper {

private static final Logger logger = getLogger(ContainerWrapper.class);

private int port;

private HttpServer server;

private WebappContext appContext;

private String configLocation;

public void setConfigLocation(final String configLocation) {
this.configLocation = configLocation.replaceFirst("^classpath:", "/");
}

public void setPort(final int port) {
this.port = port;
}
@Inject
private IntegrationTestConfig config;

@PostConstruct
public void start() throws Exception {
Expand All @@ -71,9 +63,9 @@ public void start() throws Exception {
final Unmarshaller u = context.createUnmarshaller();
final WebAppConfig o =
(WebAppConfig) u.unmarshal(getClass().getResource(
this.configLocation));
this.config.getLocation()));

final URI uri = URI.create("http://localhost:" + port);
final URI uri = URI.create("http://localhost:" + config.getPort());
// create a "root" web application
appContext = new WebappContext(o.displayName(), "/");

Expand Down Expand Up @@ -129,6 +121,7 @@ public void start() throws Exception {
}

@PreDestroy
@Deprecated
public void stop() {
try {
appContext.undeploy();
Expand All @@ -139,11 +132,4 @@ public void stop() {
}
}

@Override
public void setApplicationContext(final ApplicationContext applicationContext)
throws BeansException {
// this.applicationContext = applicationContext;

}

}
1 change: 1 addition & 0 deletions fcrepo-jms/pom.xml
Expand Up @@ -67,6 +67,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<classifier>cdi1.0</classifier>
</dependency>
<dependency>
<groupId>org.apache.abdera</groupId>
Expand Down
1 change: 1 addition & 0 deletions fcrepo-kernel/pom.xml
Expand Up @@ -20,6 +20,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<classifier>cdi1.0</classifier>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
19 changes: 18 additions & 1 deletion pom.xml
Expand Up @@ -45,6 +45,7 @@
of checkstyle deployed to fcrepo.maven.org -->
<checkstyle.plugin.version>2.10-fcrepo</checkstyle.plugin.version>
<jersey.grizzly.version>1.17.1</jersey.grizzly.version>
<weld.version>2.1.0.Final</weld.version>
</properties>
<modules>
<module>fcrepo-kernel</module>
Expand Down Expand Up @@ -118,6 +119,7 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>15.0</version>
<classifier>cdi1.0</classifier>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
Expand Down Expand Up @@ -449,6 +451,21 @@
<artifactId>powermock-api-mockito</artifactId>
<version>${powermock.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers.glassfish</groupId>
<artifactId>jersey-gf-cdi</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-osgi-bundle</artifactId>
<version>${weld.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet</artifactId>
<version>${weld.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
Expand Down Expand Up @@ -813,7 +830,7 @@
</goals>
<configuration>
<destFile>${project.basedir}/target/jacoco-it.exec</destFile>
<propertyName>failsafe.argLine</propertyName>
<propertyName>${failsafe.argLine}</propertyName>
</configuration>
</execution>
<execution>
Expand Down

0 comments on commit 61e29f5

Please sign in to comment.