DummyTransactionManager tm = new DummyTransactionManager();
InitialContext ic = new InitialContext(ctxProperties);
ic.bind("java:/TransactionManager", tm);
EmbeddedTestMcBootstrap bootstrap = EmbeddedTestMcBootstrap.createEmbeddedMcBootstrap();
Ejb3RegistrarLocator.bindRegistrar(new Ejb3McRegistrar(bootstrap.getKernel()));
ClassLoader cl = Thread.currentThread().getContextClassLoader();
Class<?> beanClass = MockBean.class;
String beanClassName = beanClass.getName();
String ejbName = beanClass.getSimpleName();
Domain domain = new Domain(new AspectManager(), "Test", false);
Map<String, Class<? extends PersistenceManagerFactory>> factories = new HashMap<String, Class<? extends PersistenceManagerFactory>>();
factories.put("MyStatefulSessionFilePersistenceManager", MyStatefulSessionFilePersistenceManagerFactory.class);
PersistenceManagerFactoryRegistry persistenceManagerFactoryRegistry = new PersistenceManagerFactoryRegistry();
persistenceManagerFactoryRegistry.setFactories(factories);
Ejb3Deployment deployment = new MockEjb3Deployment(new MockDeploymentUnit());
deployment.setPersistenceManagerFactoryRegistry(persistenceManagerFactoryRegistry);
MockStatefulContainer container = new MockStatefulContainer(cl, beanClassName, ejbName, domain, ctxProperties,
deployment);
container.instantiated();
container.processMetadata();
System.out.println("injectors = " + container.getInjectors());
Ejb3Registry.register(container);
try
{
container.create();
container.setJaccContextId("none");
container.start();
Object id = container.createSession();
StatefulBeanContext ctx = container.getCache().get(id, false);
System.out.println("inUse = " + ctx.isInUse());
MockBean bean = (MockBean) ctx.getInstance();
System.out.println(bean.ctx);
ctx.setInUse(false);
ctx = null;
synchronized (MockBean.notification)
{
MockBean.notification.wait(5000);
}
Thread.sleep(500);
ctx = container.getCache().get(id, false);
bean = (MockBean) ctx.getInstance();
String a = ctx.getEJBContext().toString();
String b = bean.ctx.toString();
System.out.println(ctx.getEJBContext());
System.out.println(bean.ctx);
assertTrue(a.regionMatches(a.indexOf('{'), b, b.indexOf('{'), a.length() - a.indexOf('{')));
}
finally
{
bootstrap.shutdown();
// container.stop();
// container.destroy();
// Ejb3Registry.unregister(container);
}
}