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);
}
}
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());
}
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);
}
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();
}
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);
}
}
Aggregations