Arquillian and existing TomEE


Sometimes you don’t want to start/stop TomEE from Arquillian but you want either to do it manually or from maven. This post is about this use case and how TomEE adapters answer to it.

If the Arquillian TomEE adapter detects that a TomEE is already running on the http TomEE port (defined in arquillian.xml) it will not start/stop the TomEE and try to use the existing one.

So first you need to define explicitly the port (by default we use the http port ‘8080’):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<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="tomee" default="true">
           <configuration>
               <property name="httpPort">1234</property> <!-- default 8080 -->
               <property name="appWorkingDir">target/arquillian-test-working-dir</property>
           </configuration>
       </container>
</arquillian>

Then be sure a TomEE is running on this port and run your tests: you’ll gain the start/stop time of the container. For a lot of tests it can be interesting.

That’s great but how to start/stop a TomEE in your build? First you can use Tomcat maven plugins…but you can also use the TomEE maven plugin.

Simply map the start goal on a phase before your tests and the stop one on a phase after your tests and that’s all.

If you use integration-test as test phase (with failsafe plugin for instance) it will probably look like:

<plugin>
  <groupId>org.apache.openejb.maven</groupId>
  <artifactId>tomee-maven-plugin</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <executions>
    <execution>
      <id>start</id>
      <phase>pre-integration-test</phase>
      <goals>
        <goal>start</goal>
      </goals>
    </execution>
    <execution>
      <id>stop</id>
      <phase>post-integration-test</phase>
      <goals>
        <goal>stop</goal>
      </goals>
   </execution>
  </executions>
  <configuration>
    <tomeeHttpPort>1234</tomeeHttpPort>
    <tomeeShutdownPort>5678</tomeeShutdownPort>
  </configuration>
</plugin>
Advertisements

7 thoughts on “Arquillian and existing TomEE

  1. Helmut

    Hi,
    please give me a hint. I don’t get CDI in the test class get to work. Server is found. Test deployed and run (even debug is possible). But injected beans in the test class don’t work.
    What i’m missing?

    Reply
      1. Helmut

        Thank you for your response.
        Yes, i’m sure that there is a beans.xml.
        I have replied to this blog because it was the only example I’ve found so far.
        Most likely it is an error in my configuration. I made an example to reproduce this, basen on the maven archetype for tomee. Please see here:
        https://github.com/helmut-at-work/test-tomee

      2. rmannibucau Post author

        are you sure you don’t have another “thing” running and holding port 8080? sounds like you have a port conflict

      3. rmannibucau Post author

        works fine with the snapshot. IIRC this issue was fixed. You can workaround it using @inject i think (or just use the snapshot)

  2. Helmut

    Just for info:
    – @Inject dosen’t work either in 1.5.1
    – 1.6.0-SNAPSHOT works 🙂
    – Other Workaraound is to use ‘mini = InitialContext.doLookup (“java:global/MiniBeanIT/MiniBean”);’ instead of CDI.
    Thank You!

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s