/** * Tests that a SLSB method which is marked as asynchronous and returns a {@link * java.util.concurrent.Future} is invoked asynchronously and the client isn't blocked for the * lifetime of the method * * @throws Exception */ @Test public void testAsyncFutureMethodOnSLSB() throws Exception { final StatelessEJBLocator<EchoRemote> locator = new StatelessEJBLocator<EchoRemote>( EchoRemote.class, APP_NAME, MODULE_NAME, EchoBean.class.getSimpleName(), ""); final EchoRemote echoRemote = EJBClient.createProxy(locator); Assert.assertNotNull("Received a null proxy", echoRemote); final String message = "You are supposed to be an asynchronous method"; final long DELAY = 5000; final long start = System.currentTimeMillis(); // invoke the asynchronous method final Future<String> futureEcho = echoRemote.asyncEcho(message, DELAY); final long end = System.currentTimeMillis(); logger.info( "Asynchronous invocation returned a Future: " + futureEcho + " in " + (end - start) + " milli seconds"); // test that the invocation did not act like a synchronous invocation and instead returned // "immediately" Assert.assertFalse( "Asynchronous invocation behaved like a synchronous invocation", (end - start) >= DELAY); Assert.assertNotNull("Future is null", futureEcho); // Check if the result is marked as complete (it shouldn't be this soon) Assert.assertFalse("Future result is unexpectedly completed", futureEcho.isDone()); // wait for the result final String echo = futureEcho.get(); Assert.assertEquals("Unexpected echo message", message, echo); }
/** * AS7-3129 * * <p>Make sure that the CDI request scope is activated for remote EJB invocations */ @Test public void testCdiRequestScopeActive() { final StatelessEJBLocator<EchoRemote> locator = new StatelessEJBLocator( EchoRemote.class, APP_NAME, MODULE_NAME, EchoBean.class.getSimpleName(), ""); final EchoRemote proxy = EJBClient.createProxy(locator); Assert.assertTrue(proxy.testRequestScopeActive()); }
/** * Test bean returning a value object with a transient field. Will test that the transient field * is set to null (just like java serialization would do) instead of a non-null value (non-null * came ValueWrapper class initializer if this fails). * * @throws Exception */ @Test public void testValueObjectWithTransientField() throws Exception { final StatelessEJBLocator<EchoRemote> locator = new StatelessEJBLocator( EchoRemote.class, APP_NAME, MODULE_NAME, EchoBean.class.getSimpleName(), ""); final EchoRemote proxy = EJBClient.createProxy(locator); String shouldBeNil = proxy.getValue().getShouldBeNilAfterUnmarshalling(); Assert.assertNull( "transient field should be serialized as null but was '" + shouldBeNil + "'", shouldBeNil); }
/** * Test a simple invocation on a remote view of a Stateless session bean method * * @throws Exception */ @Test public void testRemoteSLSBInvocation() throws Exception { final StatelessEJBLocator<EchoRemote> locator = new StatelessEJBLocator( EchoRemote.class, APP_NAME, MODULE_NAME, EchoBean.class.getSimpleName(), ""); final EchoRemote proxy = EJBClient.createProxy(locator); Assert.assertNotNull("Received a null proxy", proxy); final String message = "Hello world from a really remote client"; final String echo = proxy.echo(message); Assert.assertEquals("Unexpected echo message", message, echo); }
/** * Test a invocation on the remote view of a stateless bean which is configured for user * interceptors * * @throws Exception */ @Test public void testRemoteSLSBWithInterceptors() throws Exception { final StatelessEJBLocator<EchoRemote> locator = new StatelessEJBLocator( EchoRemote.class, APP_NAME, MODULE_NAME, InterceptedEchoBean.class.getSimpleName(), ""); final EchoRemote proxy = EJBClient.createProxy(locator); Assert.assertNotNull("Received a null proxy", proxy); final String message = "Hello world from a really remote client"; final String echo = proxy.echo(message); final String expectedEcho = message + InterceptorTwo.MESSAGE_SEPARATOR + InterceptorOne.class.getSimpleName() + InterceptorOne.MESSAGE_SEPARATOR + InterceptorTwo.class.getSimpleName(); Assert.assertEquals("Unexpected echo message", expectedEcho, echo); }