Kohei Nozaki's blog 

Lean example of integration test Maven project for WildFly


Posted on Monday Feb 23, 2015 at 11:20PM in Technology


I created similar example before, but it was redundant. I created more lean version so leave here with some notes. check my GitHub repository for details.

The project contains AppServer class, which extends ExternalResource so it can be used with @Rule annotation of JUnit as follows. note that mavenit is the name of WAR file to be tested.

public class HelloImplIT {

    @ClassRule
    public static AppServer appServer = new AppServer();
    private static Hello sut;

    @BeforeClass
    public static void beforeClass() {
        sut = appServer.lookup("mavenit", HelloImpl.class, Hello.class);
    }

    @Test
    public void test() {
        Assert.assertEquals("Hello world!", sut.hello());
    }
}

The project is easy to use with both of IDE and standalone. to run IT classes with IDE, you need to launch the application server, deploy the project as WAR package, then run a IT class from IDE. if you launched the server at not 8080 port, specify the port in app-server.port system property.

To run IT classes in standalone Maven, use following command. it automatically launches WildFly instance with port offset of 30000, deploy the WAR file, running IT classes, undeploy the WAR and stops WildFly. the command is intended to use from a Jenkins job.

mvn verify -Pintegration-test-with-wildfly \
 -Djava.home=/Library/Java/JavaVirtualMachines/jdk8/Contents/Home/jre \
 -Djboss-as.home=/Users/kyle/servers/wildfly-8.2.0.Final \
 -Dwildfly.port=39990 \
 -Dapp-server.port=38080 \
 -Dwildfly.jvmArgs="-Djboss.server.base.dir=/Users/kyle/servers/wildfly-8.2.0.Final/standalone-mavenit -Djboss.socket.binding.port-offset=30000 -ea"

You can configure following parameters through command line argument:

  • JAVA_HOME-Djava.home

  • WildFly distribution ⇒ -Djboss-as.home

  • jboss.server.base.dir ⇒ inside -Dwildfly.jvmArgs

  • Port offset ⇒ -Djboss.socket.binding.port-offset inside -Dwildfly.jvmArgs. you need to set -Dwildfly.port and -Dapp-server.port accordingly.



Comments:

Hi,
I tried to use your exemple. I imported project in my eclipse IDE then i deployed it on my wildfly 8.2.0 server and i run IT classes with IDE. I got this error,
java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:, moduleName:mavenit, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@3c0da546
at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:749)
at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:116)
...
at mavenit.HelloImplIT.test(HelloImplIT.java:18)

Thank you for help.

Posted by mouldblal on March 05, 2015 at 08:55 AM JST #


Hi mouldblal, thanks for the comment. could you check following conditions?

- The WAR is deployed with the name "mavenit.war"
- WildFly is running and listening on port 8080

Or are there any other related stacktrace or log in the console or server.log?

Posted by Kyle on March 05, 2015 at 09:58 AM JST #


Hi,
thank you for your quick response.
You're alright i was wrong, i forgate to delete "master" from the project name when i downloaded it.
Now it work.
But i have another question now,
Can i use annotations instead of ejb-jar.xml ?
I'm going to test an EJB for a JPA layer deployed on wildfly like an ejb jar.
in this ejb project, i had,
- an implémentation
@Singleton(mappedName = "IDaoRemote")
DaoJpa implements IDaoLocal, IDaoRemote.
with,
@Remote
IDaoRemote

and
@Local
IDaoLocal

how can i use your exemple to test it please ?

Thank you very much.

Posted by mouldblal on March 05, 2015 at 05:40 PM JST #


Yes you can. I guess the lookup code on that case would be following:

appServer.lookup("YOUR_EJB_JAR_NAME", DaoJpa.class, IDaoRemote.class);

If it didn't work, you may need to invoke appServer.lookup() with the name of your remote EJB. it would be something like:

appServer.lookup("ejb:/...")

For detail, refer https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI

Posted by Kyle on March 05, 2015 at 06:00 PM JST #


Thank you for response,
I used lookup with the ejb jndi name like this,
lookup("ejb:/mv-rdvmedecins-ejb-dao-jpa-0.0.1-SNAPSHOT//DaoJpa!rdvmedecins.dao.IDaoRemote");

And it work now !!!

Thank you very much.

Posted by mouldblal on March 05, 2015 at 08:01 PM JST #


Nice, you are welcome :)

Posted by Kyle on March 05, 2015 at 10:20 PM JST #


Leave a Comment

HTML Syntax: NOT allowed