Preloader image

Getting Started page gives you already a lot of inputs but you can even go further.

@Descriptors

You can reuse existing file descriptors using @Descriptors. The name is the file name and the path either a classpath path or a file path:

// runner if needed etc...
@Descriptors(@Descriptor(name = "persistence.xml", path = "META-INF/persistence.xml"))
public class MyTest {
   //...
}

Note: this can be put in a @Module method as well.

Services

@EnableServices starts the listed server services. Each service needs its module on the classpath, for instance openejb-ejbd for ejbd (remote EJB clients):

<dependency>
  <groupId>org.apache.tomee</groupId>
  <artifactId>openejb-ejbd</artifactId>
  <version>${openejb.version}</version>
</dependency>
// runner if needed etc...
@EnableServices("ejbd")
public class MyTest {
   //...
}

@RandomPort picks a free port for the named service and injects it as an int or as a URL (http://localhost:<port>/):

@EnableServices("ejbd")
public class MyTest {
   @RandomPort("ejbd")
   private int port;
}

The ApplicationComposer has no HTTP server, so it doesn’t deploy JAXRS or JAXWS endpoints. To test them over HTTP, use the TomEE Embedded runners (tomee-embedded), which support @RandomPort("http") to get a random HTTP port, or the Arquillian TomEE Embedded/Remote adapters.

Nice logs

@SimpleLog annotation allows you to have one-liner logs

Dependencies without hacky code

@Jars allows you to add dependencies (scanned) to your application automatically (like CDI libraries):

@Module
@Classes(cdi = true, value = { C1.class, C2.class, E1.class })
@Jars("deltaspike-")
public WebApp app() {
    return new WebApp();
}

@Default

@Default automatically adds in the application target/classes as binaries and src/main/webapp as resources for maven projects.

@CdiExtensions

This annotation allows you to control which extensions are activated during the test.

@AppResource

This annotation allows injection of few particular test resources like:

  • the test AppModule (application meta)

  • the test Context (JNDI)

  • the test ApplicationComposers (underlying runner)

  • ContextProvider: allow to mock JAXRS contexts

@MockInjector

Allows to mock EJB injections. It decorates a dedicated method returning an instance (or Class) implementing FallbackPropertyInjector.

@WebResource

Sets the folder containing the web resources (docBase) of the web application. Only the TomEE Embedded runners use it, with a single folder.

Limitations for Single Instance Application Composer

For a single instance in test suites, test classes must be scanned for injections to be prepared as any bean.

Therefore, test classes need to be either added in the @Classes annotation or marked as a CDI bean (@Dependent) annotation.

You can find an example in SingleAppComposerResourceInjectionTest in openejb-junit5.