RPC Tests with Errai
vwjugow Mar 24, 2014 9:45 AMHello, we are trying to run integration tests with errai framework that make use of RPC calls, and CDI Events, but we are facing some problems.
We based our work on this archetype: Errai CDI Maven Archetype - Errai - Project Documentation Editor
In that archetype there is a test that for Events that works, and we added another that uses RPC calls and also works. However we were unable to replicate this in our project, even copying the exact same tests. Of course we copied the maven profile in the pom, web.xml, the errai*.properties, beans.xml, but still doesn't work.
The tests:
- RPC
package app.client.local; import app.client.shared.service.AsyncRPCService; import org.jboss.errai.bus.client.api.base.MessageBuilder; import org.jboss.errai.common.client.api.RemoteCallback; import org.jboss.errai.enterprise.client.cdi.AbstractErraiCDITest; import org.junit.Test; public class RPCTest extends AbstractErraiCDITest { @Override public String getModuleName() { return "app.App"; } @Override public void gwtSetUp() throws Exception { super.gwtSetUp(); } @Test public void testButtonClickUpdatesLabel() throws Exception { System.out.println("-- Testing create strategy --"); CDITestHelper.afterCdiInitialized(new Runnable() { @Override public void run() { MessageBuilder.createCall(new RemoteCallback<String>() { @Override public void callback(String response) { System.out.println("-- Got a response! --"); assertEquals("foobar", response); finishTest(); } }, AsyncRPCService.class).doSomeTask(); } }); delayTestFinish(20000); } }
Stack trace: http://pastebin.com/4Y5TH9Gf
- CDI
package app.client.local; import app.server.SimpleCDIService; import org.jboss.errai.enterprise.client.cdi.AbstractErraiCDITest; import org.junit.Test; import javax.inject.Inject; /** * Tests features of the quickstart application. The primary purpose of this * test case is to serve as an example for how to set up real * functional/integration tests in a real application. * * @author Jonathan Fuerth <jfuerth@gmail.com> */ public class AppIntegrationTest extends AbstractErraiCDITest { /** * Reference to the CDI-managed application object {@code CDITestHelper.instance.app}. * Initialized in each individual test case in a {@code CDI.addPostInitTask()} block. */ private AppUI app; @Override public String getModuleName() { return "app.App"; } @Override public void gwtSetUp() throws Exception { super.gwtSetUp(); } @Test public void testInitialSetup() { System.out.println("INIT TEST MAGICK"); CDITestHelper.afterCdiInitialized(new Runnable() { @Override public void run() { app = CDITestHelper.instance.app; assertNotNull(app.getMessageBox()); assertNotNull(app.getResponseLabel()); assertNotNull(app.getSendButton()); assertEquals("", app.getResponseLabel().getText()); System.out.println("ENDED 2 TEST MAGICK"); finishTest(); System.out.println("ENDED 3 TEST MAGICK"); }); System.out.println("ENDING TEST MAGICK"); // This call tells GWT's test runnerwait 20 seconds after the test returns. // We need this delay to give the HelloMessage time to come back from the server. delayTestFinish(20000); System.out.println("ENDED 1 TEST MAGICK"); } @Test public void testButtonClickUpdatesLabel() throws Exception { System.out.println("INIT TEST MAGICK"); CDITestHelper.afterCdiInitialized(new Runnable() { @Override public void run() { System.out.println("POLACOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO2"); app = CDITestHelper.instance.app; app.getResponseLabel().setText("label value before click"); app.getMessageBox().setText("moocow"); app.fireMessage(); } }); CDITestHelper.afterResponseEvent(new Runnable() { @Override public void run() { System.out.println("POLACOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO"); // this is what we sent String messageBoxText = app.getMessageBox().getText(); // this is composed from the server response message String labelText = app.getResponseLabel().getText(); assertTrue("Unexpected label contents after pressing button: \"" + labelText + "\"", labelText.startsWith("HelloMessage from Server: " + messageBoxText.toUpperCase() + " @ TIMEMILLIS: ")); finishTest(); } }); // This call tells GWT's test runner to wait 3000ms after the test returns. // We need this delay to give the HelloMessage time to come back from the server. delayTestFinish(3000); } }
The CDITestHelper is the same as in the archetype, we only changed app field so it is our application's entry point.
The stacktrace: http://pastebin.com/CjTf7N8n
(first test result is 'passed' but it throws an exception when running the @AfterInitialization methods of our classes.)
And if we add an @Inject SimpleCDIService we get http://pastebin.com/2Sf9aHDk
Here is a list of the things we have tried:
- Copying from scratch.
We have the CDI archetype working, even with an injected dummyService. So we tried copying everything (pom, web.xml, Errai*.properties, beans.xml) from that example to appui but still same exception (branch APPUI-812b).
- Added an AfterInitialization method in Archetype project and it is being executed.
- Removed every reference to google.inject.Inject from the project but didn’t work.
- Also tried using google.inject instead of javax.inject.Inject but nothing.
- Adding <Resource><Directory>src/main/java and src/main/resource<....> in the pom
- Adding Additional classpath directories in the surefire plugin
- Commented out everything in UserManagementServiceImpl
- Created a @Remote interface that extends from WorkItemHandler for UpdateAccountWorkItemHandler
- Debugged the UI with the same breakpoints. The UI does not stop in those places.
- Cyclic use of classes: http://pastebin.com/LCZECRAX
If there is anything else I can do to help explain the problem please tell me.