use of javax.ejb.embeddable.EJBContainer in project tomee by apache.
the class CounterCallbacksTest method test.
@Test
public void test() throws Exception {
final Map<String, Object> p = new HashMap<String, Object>();
p.put("MySTATEFUL", "new://Container?type=STATEFUL");
//How many instances of Stateful beans can our server hold in memory?
p.put("MySTATEFUL.Capacity", "2");
//Interval in seconds between checks
p.put("MySTATEFUL.Frequency", "1");
//No bulkPassivate - just passivate entities whenever it is needed
p.put("MySTATEFUL.BulkPassivate", "0");
final EJBContainer container = EJBContainer.createEJBContainer(p);
//this is going to track the execution
ExecutionChannel.getInstance().addObserver(this);
{
final Context context = getContext();
CallbackCounter counterA = (CallbackCounter) context.lookup("java:global/simple-stateful-callbacks/CallbackCounter");
Assert.assertNotNull(counterA);
Assert.assertEquals("postConstruct", this.received.remove(0));
Assert.assertEquals(0, counterA.count());
Assert.assertEquals("count", this.received.remove(0));
Assert.assertEquals(1, counterA.increment());
Assert.assertEquals("increment", this.received.remove(0));
Assert.assertEquals(0, counterA.reset());
Assert.assertEquals("reset", this.received.remove(0));
Assert.assertEquals(1, counterA.increment());
Assert.assertEquals("increment", this.received.remove(0));
System.out.println("Waiting 2 seconds...");
Thread.sleep(2000);
Assert.assertEquals("preDestroy", this.received.remove(0));
try {
counterA.increment();
Assert.fail("The ejb is not supposed to be there.");
} catch (javax.ejb.NoSuchEJBException e) {
//excepted
}
context.close();
}
{
final Context context = getContext();
CallbackCounter counterA = (CallbackCounter) context.lookup("java:global/simple-stateful-callbacks/CallbackCounter");
Assert.assertEquals("postConstruct", this.received.remove(0));
Assert.assertEquals(1, counterA.increment());
Assert.assertEquals("increment", this.received.remove(0));
((CallbackCounter) context.lookup("java:global/simple-stateful-callbacks/CallbackCounter")).count();
Assert.assertEquals("postConstruct", this.received.remove(0));
Assert.assertEquals("count", this.received.remove(0));
((CallbackCounter) context.lookup("java:global/simple-stateful-callbacks/CallbackCounter")).count();
Assert.assertEquals("postConstruct", this.received.remove(0));
Assert.assertEquals("count", this.received.remove(0));
System.out.println("Waiting 2 seconds...");
Thread.sleep(2000);
Assert.assertEquals("prePassivate", this.received.remove(0));
context.close();
}
container.close();
Assert.assertEquals(this.received.toString(), 2, this.received.size());
Assert.assertEquals("preDestroy", this.received.remove(0));
Assert.assertEquals("preDestroy", this.received.remove(0));
Assert.assertTrue(this.received.toString(), this.received.isEmpty());
}
use of javax.ejb.embeddable.EJBContainer in project tomee by apache.
the class EmbeddedTomEEContainerTest method classpath.
@Test
public void classpath() throws Exception {
final Properties p = new Properties();
p.setProperty(EJBContainer.PROVIDER, EmbeddedTomEEContainer.class.getName());
p.setProperty(DeploymentsResolver.CLASSPATH_INCLUDE, ".*tomee-embedded.*");
p.setProperty(EmbeddedTomEEContainer.TOMEE_EJBCONTAINER_HTTP_PORT, "-1");
EJBContainer container = null;
try {
container = EJBContainer.createEJBContainer(p);
assertNotNull(container);
assertNotNull(container.getContext());
final ABean bean = ABean.class.cast(container.getContext().lookup("java:global/tomee-embedded/ABean"));
assertNotNull(bean);
assertEquals("ok", bean.embedded());
} finally {
if (container != null) {
container.close();
}
}
}
use of javax.ejb.embeddable.EJBContainer in project tomee by apache.
the class EmbeddedTomEEContainerTest method containerTest.
@Test
public void containerTest() throws Exception {
final File war = createWar();
final Properties p = new Properties();
p.setProperty(EJBContainer.APP_NAME, "test");
p.setProperty(EJBContainer.PROVIDER, EmbeddedTomEEContainer.class.getName());
p.put(EJBContainer.MODULES, war.getAbsolutePath());
p.setProperty(EmbeddedTomEEContainer.TOMEE_EJBCONTAINER_HTTP_PORT, "-1");
EJBContainer container = null;
try {
container = EJBContainer.createEJBContainer(p);
assertNotNull(container);
assertNotNull(container.getContext());
final URL url = new URL("http://127.0.0.1:" + System.getProperty(EmbeddedTomEEContainer.TOMEE_EJBCONTAINER_HTTP_PORT) + "/test/index.html");
assertEquals("true", getOk(url, 2));
} finally {
if (container != null) {
container.close();
}
try {
FileUtils.forceDelete(war);
} catch (final IOException e) {
FileUtils.deleteQuietly(war);
}
}
}
use of javax.ejb.embeddable.EJBContainer in project tomee by apache.
the class DataSourceCipheredExampleTest method accessDatasource.
@Test
public void accessDatasource() throws Exception {
// define the datasource
Properties properties = new Properties();
properties.setProperty("ProtectedDatasource", "new://Resource?type=DataSource");
properties.setProperty("ProtectedDatasource.JdbcDriver", "org.hsqldb.jdbcDriver");
properties.setProperty("ProtectedDatasource.JdbcUrl", DATASOURCE_URL);
properties.setProperty("ProtectedDatasource.UserName", USER);
properties.setProperty("ProtectedDatasource.Password", "fEroTNXjaL5SOTyRQ92x3DNVS/ksbtgs");
properties.setProperty("ProtectedDatasource.PasswordCipher", "Static3DES");
properties.setProperty("ProtectedDatasource.JtaManaged", "true");
// start the context and makes junit test injections
EJBContainer container = EJBContainer.createEJBContainer(properties);
Context context = container.getContext();
context.bind("inject", this);
// test the datasource
assertNotNull(dataSource);
assertNotNull(dataSource.getConnection());
// closing the context
container.close();
}
use of javax.ejb.embeddable.EJBContainer in project tomee by apache.
the class MoviesTest method test.
@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");
final EJBContainer container = EJBContainer.createEJBContainer(p);
final Context context = container.getContext();
context.bind("inject", this);
assertTrue(((ReloadableEntityManagerFactory) emf).getManagedClasses().contains(Movie.class.getName()));
container.close();
}
Aggregations