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>
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?
Hi
that’s typically something for the tomee mailing list.
are you sure you added a beans.xml?
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
are you sure you don’t have another “thing” running and holding port 8080? sounds like you have a port conflict
Yes I’m sure. If you like try the sample at https://github.com/helmut-at-work/test-tomee
works fine with the snapshot. IIRC this issue was fixed. You can workaround it using @inject i think (or just use the snapshot)
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!