- Follow the Using Arquillian without Maven Guide to export the jar files for the Tomcat Managed container adapter
- Create a User Library named Arquillian Tomcat Managed with the jar files exported by Maven
- Add the Arquillian Tomcat Managed User Library to the project
- Edit conf/tomcat-users.xml in the Tomcat installation directory to add a deploy user:
<user username="arquillian" password="arquillian" roles="manager-script"/>
- Create an arquillian.xml file in the source (or resources) directory in your project to configure the deploy credentials and Tomcat installation directory (unless CATALINA_HOME is already set)
<arquillian xmlns="http://jboss.org/schema/arquillian"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://jboss.org/schema/arquillian
http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<container qualifier="tomcat-remote-7" default="true">
<configuration>
<property name="catalinaHome">${user.home}/tomcat</property>
<property name="user">arquillian</property>
<property name="pass">arquillian</property>
</configuration>
</container>
</arquillian>
- Copy your custom context.xml file to conf/context.xml in the Tomcat installation directory. Let's assume it has the following entry:
<Environment name="alienName" override="false" type="java.lang.String" value="Ike"/>
- Create a test to lookup the JNDI name
package org.arquillian.example;
import javax.annotation.Resource;
import junit.framework.Assert;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(Arquillian.class)
public class JNDILookupTest {
@Deployment
public static WebArchive createDeployment()
{
return ShrinkWrap.create(WebArchive.class, "test.war");
}
@Resource(name = "alienName")
String alienName;
@Test
public void testJNDILookup() {
Assert.assertEquals("Ike", alienName);
}
}
- Make sure Tomcat is stopped, then run the test using "Run As > JUnit Test"
Green bar.