Application folder structure:
-your-application
-your-application-ear
-your-application-ejb
-your-application-web
Maven dependency management in your-application/pom.xml:
<dependencyManagement>
<dependencies>
<!– https://mvnrepository.com/artifact/org.jboss.shrinkwrap.resolver/shrinkwrap-resolver-impl-maven –>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-impl–maven</artifactId>
<version>2.2.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-api–maven</artifactId>
<version>2.2.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-api</artifactId>
<version>2.2.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-spi–maven</artifactId>
<version>2.2.6</version>
<scope>test</scope>
</dependency>
<!– https://mvnrepository.com/artifact/org.jboss.shrinkwrap.resolver/shrinkwrap-resolver-spi –>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-spi</artifactId>
<version>2.2.6</version>
</dependency>
</dependencies>
</dependencyManagement>
Maven dependencies in your-application-ejb/pom.xml:
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian–junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet</artifactId>
<scope>test</scope>
</dependency>
<!–exclude default older versions of dependencies coming with the lib–>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-impl–maven</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-spi</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-spi–maven</artifactId>
</exclusion>
</exclusions>
</dependency>
<!–include newer versions of dependencies after excluding older ones before–>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-api–maven</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-api</artifactId>
<scope>test</scope>
</dependency>
<!– https://mvnrepository.com/artifact/org.jboss.shrinkwrap.resolver/shrinkwrap-resolver-spi –>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-spi–maven</artifactId>
<exclusions>
<exclusion>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-spi</artifactId>
</exclusion>
</exclusions>
</dependency>
<!– https://mvnrepository.com/artifact/org.jboss.shrinkwrap.resolver/shrinkwrap-resolver-spi –>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-spi</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-impl–maven-archive</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Enable remote container test in your-application-ejb/pom.xml:
<profiles>
<profile>
<!– The default profile skips all tests, though you can tune it to run
just unit tests based on a custom pattern –>
<!– Seperate profiles are provided for running all tests, including Arquillian
tests that execute in the specified container –>
<id>default</id>
<!– <activation> <activeByDefault>true</activeByDefault> </activation> –>
<build>
<plugins>
<plugin>
<artifactId>maven–surefire–plugin</artifactId>
<version>${version.surefire.plugin}</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!– An optional Arquillian testing profile that executes tests in your
WildFly instance –>
<!– This profile will start a new WildFly instance, and execute the test,
shutting it down when done –>
<!– Run with: mvn clean test –Parq–wildfly-managed –>
<id>arq–wildfly-managed</id>
<dependencies>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly–arquillian-container-managed</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<profile>
<!– An optional Arquillian testing profile that executes tests in a remote
WildFly instance –>
<!– Run with: mvn clean test –Parq–wildfly-remote –>
<id>arq–wildfly-remote</id>
<!–enable this one–>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly–arquillian-container-remote</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>
Create tests in src/test/java in your-application-ejb:
@RunWith(Arquillian.class)
public class YourTest {
@Inject
private TestService testService;
private static Logger log = Logger.getLogger(TestService.class.getName());
@Deployment
public static Archive<?> createDeploymentFromPom() {
//pay attention here: which pom.xml file is loaded
PomEquippedResolveStage mavenResolver = Maven.configureResolver().loadPomFromFile(“../your-application-ear/pom.xml”);
EnterpriseArchive archive = mavenResolver.resolve(“G:A:ear:V”)
.withoutTransitivity().as(EnterpriseArchive.class)[0];
JavaArchive testLibraryHelper = ShrinkWrap.create(JavaArchive.class)
archive.addAsLibrary(testLibraryHelper);
return archive;
}
@Test
@RunAsClient//This tells Arquillian to run the test as a client against the remote server and not within the remote server.
public void testBeanInstance() {
System.out.print(“run as-client test”);
}
@Test
public void testTestService() {
log.info(“run in-container test”);
Assert.assertNotNull(testService);
}
}
Read Full Post »