Search in sources :

Example 1 with EJBContainer

use of javax.ejb.embeddable.EJBContainer in project javaee7-samples by javaee-samples.

the class MyBeanTest method testSayHello.

/**
     * Test of sayHello method, of class MyBean.
     * 
     * Commented for now as support for this API is optional
     */
//    @Test
public void testSayHello() throws Exception {
    System.out.println("sayHello");
    String name = "Duke";
    try (EJBContainer container = javax.ejb.embeddable.EJBContainer.createEJBContainer()) {
        MyBean instance = (MyBean) container.getContext().lookup("java:global/classes/MyBean");
        String expResult = "Hello " + name;
        String result = instance.sayHello(name);
        assertEquals(expResult, result);
    }
}
Also used : EJBContainer(javax.ejb.embeddable.EJBContainer)

Example 2 with EJBContainer

use of javax.ejb.embeddable.EJBContainer in project tomee by apache.

the class OpenEjbContainerNoRestartTest method noRestart.

@Test
public void noRestart() throws Exception {
    final EJBContainer container1 = EJBContainer.createEJBContainer(new Properties() {

        {
            put(EJBContainer.MODULES, new EjbJar());
            put(OpenEjbContainer.OPENEJB_EJBCONTAINER_CLOSE, OpenEjbContainer.OPENEJB_EJBCONTAINER_CLOSE_SINGLE);
        }
    });
    container1.close();
    final EJBContainer container2 = EJBContainer.createEJBContainer(new Properties() {

        {
            put(EJBContainer.MODULES, new EjbJar());
        }
    });
    container2.close();
    assertTrue(SystemInstance.isInitialized());
    assertSame(container1, container2);
    Reflections.invokeByReflection(container2, "doClose", new Class<?>[0], null);
    assertFalse(SystemInstance.isInitialized());
}
Also used : EJBContainer(javax.ejb.embeddable.EJBContainer) Properties(java.util.Properties) EjbJar(org.apache.openejb.jee.EjbJar) Test(org.junit.Test)

Example 3 with EJBContainer

use of javax.ejb.embeddable.EJBContainer in project tomee by apache.

the class OpenEjbContainerNoRestartTest method normalRestart.

@Test
public void normalRestart() throws Exception {
    final EJBContainer container1 = EJBContainer.createEJBContainer(new Properties() {

        {
            put(EJBContainer.MODULES, new EjbJar());
        }
    });
    container1.close();
    final EJBContainer container2 = EJBContainer.createEJBContainer(new Properties() {

        {
            put(EJBContainer.MODULES, new EjbJar());
        }
    });
    container2.close();
    assertNotSame(container1, container2);
}
Also used : EJBContainer(javax.ejb.embeddable.EJBContainer) Properties(java.util.Properties) EjbJar(org.apache.openejb.jee.EjbJar) Test(org.junit.Test)

Example 4 with EJBContainer

use of javax.ejb.embeddable.EJBContainer in project tomee by apache.

the class MoviesTest method test.

public void test() throws Exception {
    final Properties p = new Properties();
    p.put("movieDatabase", "new://Resource?type=DataSource");
    p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
    p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
    EJBContainer container = EJBContainer.createEJBContainer(p);
    final Context context = container.getContext();
    final Movies movies = (Movies) context.lookup("java:global/jpa-enumerated/Movies");
    movies.addMovie(new Movie("James Frawley", "The Muppet Movie", 1979, Rating.G));
    movies.addMovie(new Movie("Jim Henson", "The Great Muppet Caper", 1981, Rating.G));
    movies.addMovie(new Movie("Frank Oz", "The Muppets Take Manhattan", 1984, Rating.G));
    movies.addMovie(new Movie("James Bobin", "The Muppets", 2011, Rating.PG));
    assertEquals("List.size()", 4, movies.getMovies().size());
    assertEquals("List.size()", 3, movies.findByRating(Rating.G).size());
    assertEquals("List.size()", 1, movies.findByRating(Rating.PG).size());
    assertEquals("List.size()", 0, movies.findByRating(Rating.R).size());
    container.close();
}
Also used : Context(javax.naming.Context) EJBContainer(javax.ejb.embeddable.EJBContainer) Properties(java.util.Properties)

Example 5 with EJBContainer

use of javax.ejb.embeddable.EJBContainer in project tomee by apache.

the class OpenEJBEmbeddedMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    MavenLogStreamFactory.setLogger(getLog());
    final ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(createClassLoader(oldCl));
    EJBContainer container = null;
    try {
        container = EJBContainer.createEJBContainer(map());
        if (await) {
            final CountDownLatch latch = new CountDownLatch(1);
            Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

                @Override
                public void run() {
                    latch.countDown();
                }
            }));
            try {
                latch.await();
            } catch (final InterruptedException e) {
            // ignored
            }
        }
    } finally {
        if (container != null) {
            container.close();
        }
        Thread.currentThread().setContextClassLoader(oldCl);
    }
}
Also used : URLClassLoader(java.net.URLClassLoader) EJBContainer(javax.ejb.embeddable.EJBContainer) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

EJBContainer (javax.ejb.embeddable.EJBContainer)14 Test (org.junit.Test)11 Properties (java.util.Properties)10 Context (javax.naming.Context)5 IOException (java.io.IOException)2 URL (java.net.URL)2 HashMap (java.util.HashMap)2 EjbJar (org.apache.openejb.jee.EjbJar)2 File (java.io.File)1 URLClassLoader (java.net.URLClassLoader)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Attribute (javax.management.Attribute)1 MBeanServer (javax.management.MBeanServer)1 ObjectName (javax.management.ObjectName)1 InitialContext (javax.naming.InitialContext)1 Callback (javax.security.auth.callback.Callback)1 CallbackHandler (javax.security.auth.callback.CallbackHandler)1 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)1 QName (javax.xml.namespace.QName)1 Service (javax.xml.ws.Service)1