Skip to content

Commit 45399ac

Browse files
committed
Merge pull request ocpsoft#45 from chkal/tomcat
CDI setup for Tomcat integration tests
2 parents 985a0ed + f1c9b9a commit 45399ac

4 files changed

Lines changed: 59 additions & 3 deletions

File tree

‎pom.xml‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,6 @@
366366

367367
<profile>
368368
<id>TOMCAT-EMBEDDED_7.x</id>
369-
<activation>
370-
<activeByDefault>true</activeByDefault>
371-
</activation>
372369
<dependencies>
373370
<dependency>
374371
<groupId>org.jboss.arquillian.container</groupId>
@@ -411,6 +408,12 @@
411408
<version>1.1.4.Final</version>
412409
<scope>test</scope>
413410
</dependency>
411+
<dependency>
412+
<groupId>org.slf4j</groupId>
413+
<artifactId>slf4j-simple</artifactId>
414+
<version>1.5.10</version>
415+
<scope>test</scope>
416+
</dependency>
414417
</dependencies>
415418
</profile>
416419

‎test-harness/src/main/java/org/ocpsoft/rewrite/test/RewriteTest.java‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ public static WebArchive getDeploymentNoWebXml(String name)
8888
archive.addAsWebInfResource("jetty-log4j.xml", "log4j.xml");
8989

9090
}
91+
92+
// Tomcat specific stuff
93+
if (isTomcat()) {
94+
95+
// add Weld dependency
96+
archive.addAsLibraries(resolveDependencies("org.jboss.weld.servlet:weld-servlet:1.1.4.Final"));
97+
98+
// setup BeanManager in JNDI
99+
archive.addAsWebResource("tomcat-context.xml", "META-INF/context.xml");
100+
101+
// make it a CDI archive
102+
archive.addAsWebInfResource(new StringAsset("<beans/>"), "beans.xml");
103+
104+
}
91105

92106
return archive;
93107
}
@@ -104,6 +118,18 @@ public static boolean isJetty()
104118
}
105119
}
106120

121+
public static boolean isTomcat()
122+
{
123+
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
124+
try {
125+
classLoader.loadClass("org.jboss.arquillian.container.tomcat.embedded_7.TomcatContainer");
126+
return true;
127+
}
128+
catch (ClassNotFoundException e) {
129+
return false;
130+
}
131+
}
132+
107133
protected static JavaArchive getContainerArchive()
108134
{
109135

@@ -113,6 +139,11 @@ protected static JavaArchive getContainerArchive()
113139
{
114140
archive.addAsManifestResource("jetty-web-fragment.xml", "web-fragment.xml");
115141
}
142+
143+
if (isTomcat())
144+
{
145+
archive.addAsManifestResource("tomcat-web-fragment.xml", "web-fragment.xml");
146+
}
116147

117148
return archive.addAsResource(new StringAsset("placeholder"), "README");
118149
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Context>
3+
4+
<Resource name="BeanManager" auth="Container" type="javax.enterprise.inject.spi.BeanManager"
5+
factory="org.jboss.weld.resources.ManagerObjectFactory" />
6+
7+
</Context>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<web-fragment xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd" version="3.0">
4+
5+
<listener>
6+
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
7+
</listener>
8+
9+
<resource-env-ref>
10+
<description>Object factory for the CDI Bean Manager</description>
11+
<resource-env-ref-name>BeanManager</resource-env-ref-name>
12+
<resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
13+
</resource-env-ref>
14+
15+
</web-fragment>

0 commit comments

Comments
 (0)