CDI problem using Arquillian with Tomcat 6.0 and JSFUnit
jtmarch Mar 28, 2011 5:07 AMHi guys,
I'm having a problem while using CDI with Arquillian, Tomcat 6.0 and JSFUnit. I think I am almost there but it is constantly saying that the JSFServerSession cannot be resolved:
org.jboss.arquillian.spi.ArquillianProxyException: org.jboss.weld.exceptions.UnsatisfiedResolutionException : WELD-001308 Unable to resolve managed beans for Types: [class org.jboss.jsfunit.jsfsession.JSFServerSession]; Bindings: [@javax.enterprise.inject.Default()] [Proxied because : Could not find suitable constructor]
at org.jboss.weld.manager.BeanManagerImpl.getBean(BeanManagerImpl.java:807)
at org.jboss.weld.manager.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:793)
My test looks like:
@RunWith(Arquillian.class)
public class ArquillianTest {
@Deployment
public static WebArchive createDeployment() {
System.setProperty("java.io.tmpdir", "c:\\data\\temp\\");
System.setProperty("maven.repo.local", "c:\\repository");
return ShrinkWrap.create(WebArchive.class, "TestProject.war")
.setWebXML(new File("src/main/webapp/WEB-INF/web.xml"))
.addPackage(Package.getPackage("test.example"))
.addClasses(BackingBean.class)
.addAsLibraries(MavenArtifactResolver.resolveQualifiedIds("org.jboss.jsfunit:jboss-jsfunit-core:2.0.0.Beta1"))
.addAsResource(new File("src/main/webapp/views", "test.xhtml"))
.addAsWebResource(new ByteArrayAsset("<beans/>".getBytes()), "beans.xml")
.addAsManifestResource(new ByteArrayAsset("<beans/>".getBytes()), ArchivePaths.create("beans.xml"))
.addAsManifestResource(new File("src/main/webapp/META-INF/context.xml"))
.addAsWebResource(new File("src/main/webapp/WEB-INF/faces-config.xml"), "faces-config.xml");
}
@Test
@InitialPage("/test.xhtml")
public void testInitialPage(JSFServerSession server) throws IOException {
Assert.assertEquals("request", server.getManagedBeanValue("#{requestBean.scope}"));
}
}
I have set the context.xml for tomcat:
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<!-- disable storage of sessions across restarts -->
<Manager pathname="" />
<Resource name="BeanManager" auth="Container"
type="javax.enterprise.inject.spi.BeanManager" factory="org.jboss.weld.resources.ManagerObjectFactory" />
<!-- Uncomment to enable injection into Servlets, Servlet Listeners and Filters in Tomcat -->
<Listener className="org.jboss.weld.environment.tomcat.WeldLifecycleListener"/>
</Context>
And added the things to web.xml:
<listener>
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>
<resource-env-ref>
<resource-env-ref-name>BeanManager</resource-env-ref-name>
<resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
</resource-env-ref>
My arquillian.xml file contains:
<tomcat6:container>
<!-- unpackArchive must be true if using the Weld Servlet module -->
<tomcat6:unpackArchive>true</tomcat6:unpackArchive>
</tomcat6:container>
And my maven dependencies are:
<!-- Test -->
<dependency>
<groupId>org.jboss.jsfunit</groupId>
<artifactId>jsfunit-arquillian</artifactId>
<version>2.0.0.Beta1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-junit</artifactId>
<version>${arquillian.version}</version>
<scope>test</scope>
</dependency>
<!-- Container specific dependencies -->
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-tomcat-embedded-6</artifactId>
<version>1.0.0.Alpha5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>catalina</artifactId>
<version>6.0.29</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>coyote</artifactId>
<version>6.0.29</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>jasper</artifactId>
<version>6.0.29</version>
<scope>provided</scope>
</dependency>
<!-- Weld servlet, EL and JSP required for testing CDI injections -->
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet</artifactId>
<version>1.0.1-Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-tomcat-support</artifactId>
<version>1.0.1-CR2</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>el-impl</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
So what did I do wrong? Maybe it is a classpath issue? Hope somebody can help me.
Kind regards,
Jelle