Search in sources :

Example 1 with SampleEjb

use of org.glassfish.tests.embedded.ejb.remoteejb.SampleEjb in project Payara by payara.

the class EJBTest method test.

@Test
public void test() throws Exception {
    glassfish = GlassFishRuntime.bootstrap().newGlassFish();
    glassfish.start();
    Deployer deployer = glassfish.getDeployer();
    URI uri = new File(System.getProperty("user.dir"), "target/remoteejb.jar").toURI();
    System.out.println("Deploying [" + uri + "]");
    deployer.deploy(uri);
    InitialContext ic = new InitialContext();
    System.out.println("Looking up SampleEJB.");
    SampleEjb sampleEjb = (SampleEjb) ic.lookup("java:global/remoteejb/SampleEjb");
    System.out.println("Invoking SampleEjb [" + sampleEjb + "]");
    Assert.assertEquals(sampleEjb.saySomething(), "Hello World");
    System.out.println("SampleEjb tested successfully");
    System.out.println("Looking up TimerEjb.");
    TimerEjb timerEjb = (TimerEjb) ic.lookup("java:global/remoteejb/TimerEjb");
    System.out.println("Invoking TimerEjb [" + timerEjb + "]");
    timerEjb.createTimer();
    System.out.println("Verifying TimerEjb [" + timerEjb + "]");
    Thread.sleep(4000);
    boolean result = timerEjb.verifyTimer();
    Assert.assertTrue(result);
    System.out.println("TimerEJB tested successfully.");
    // ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
    // try {
    System.out.println("Looking up RemoteEJB.");
    // Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
    RemoteEJBInf remoteEjb = (RemoteEJBInf) ic.lookup("java:global/remoteejb/RemoteEJB");
    System.out.println("Invoking RemoteEJB [" + remoteEjb + "]");
    Assert.assertEquals(remoteEjb.sayHi(), "Hi Bhavani");
    System.out.println("RemoteEjb tested successfully");
    // } finally {
    // Thread.currentThread().setContextClassLoader(oldCL);
    // }
    glassfish.stop();
    glassfish.dispose();
    System.out.println("EmbeddedTest completed.");
}
Also used : RemoteEJBInf(org.glassfish.tests.embedded.ejb.remoteejb.RemoteEJBInf) SampleEjb(org.glassfish.tests.embedded.ejb.remoteejb.SampleEjb) URI(java.net.URI) File(java.io.File) TimerEjb(org.glassfish.tests.embedded.ejb.remoteejb.TimerEjb) Deployer(org.glassfish.embeddable.Deployer) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Aggregations

File (java.io.File)1 URI (java.net.URI)1 InitialContext (javax.naming.InitialContext)1 Deployer (org.glassfish.embeddable.Deployer)1 RemoteEJBInf (org.glassfish.tests.embedded.ejb.remoteejb.RemoteEJBInf)1 SampleEjb (org.glassfish.tests.embedded.ejb.remoteejb.SampleEjb)1 TimerEjb (org.glassfish.tests.embedded.ejb.remoteejb.TimerEjb)1 Test (org.junit.Test)1