use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.
the class JavaLookupTest method test.
public void test() throws Exception {
final Assembler assembler = new Assembler();
final ConfigurationFactory config = new ConfigurationFactory();
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
final InitialContext context = new InitialContext();
assertTrue(context.lookup("java:openejb/TransactionManager") instanceof TransactionManager);
assertTrue(context.lookup("java:comp/TransactionManager") instanceof TransactionManager);
assertTrue(context.lookup("java:comp/UserTransaction") instanceof UserTransaction);
assertTrue(context.lookup("java:comp/TransactionSynchronizationRegistry") instanceof TransactionSynchronizationRegistry);
}
use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.
the class JavaLookupTest method testLinking.
public void testLinking() throws Exception {
final Assembler assembler = new Assembler();
final ConfigurationFactory config = new ConfigurationFactory();
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
final InitialContext context = new InitialContext();
final Context javaContext = (Context) context.lookup("java:");
javaContext.bind("java:TransactionManager", new JndiUrlReference("java:comp/TransactionManager"));
javaContext.bind("java:TransactionManagerLink", new LinkRef("java:comp/TransactionManager"));
assertTrue(context.lookup("java:TransactionManager") instanceof TransactionManager);
assertTrue(context.lookup("java:TransactionManagerLink") instanceof TransactionManager);
new InitialContext().bind("java:foo", new LinkRef("java:comp/TransactionManager"));
assertTrue(context.lookup("java:foo") instanceof TransactionManager);
}
use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.
the class OpenejbLookupTest method testLocalInitialContext.
public void testLocalInitialContext() throws Exception {
final Assembler assembler = new Assembler();
final ConfigurationFactory config = new ConfigurationFactory();
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean(FooBean.class));
assembler.createApplication(config.configureApplication(ejbJar));
final Properties properties = new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
Context context = new InitialContext(properties);
// This is still the jvm InitialContext delegating to the openejbURLContextFactory
assertTrue(context instanceof InitialContext);
assertOpenejbUrlLookups(context);
// Now we have effectively unwrapped the InitalContext, openejb: lookups should still work.
context = (Context) context.lookup("");
assertTrue(context instanceof IvmContext);
assertOpenejbUrlLookups(context);
// Test that an EJB can lookup items from openejb:
final FooLocal fooLocal = (FooLocal) context.lookup("FooBeanLocal");
fooLocal.test();
}
use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.
the class ManagedBeanTest method setUp.
@Override
protected void setUp() throws Exception {
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new ManagedBean(MyBean.class));
assembler.createApplication(config.configureApplication(ejbJar));
}
use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.
the class CustomMdbContainerTest method test.
public void test() throws Exception {
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
// Setup the descriptor information
EmailBean.lifecycle.clear();
final AppModule app = new AppModule(this.getClass().getClassLoader(), "testapp");
final Connector connector = new Connector("email-ra");
final ResourceAdapter adapter = new ResourceAdapter(EmailResourceAdapter.class);
connector.setResourceAdapter(adapter);
final InboundResourceadapter inbound = adapter.setInboundResourceAdapter(new InboundResourceadapter());
final MessageAdapter messageAdapter = inbound.setMessageAdapter(new MessageAdapter());
final MessageListener listener = messageAdapter.addMessageListener(new MessageListener(EmailConsumer.class, EmailAccountInfo.class));
listener.getActivationSpec().addRequiredConfigProperty("address");
app.getConnectorModules().add(new ConnectorModule(connector));
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new MessageDrivenBean(EmailBean.class));
app.getEjbModules().add(new EjbModule(ejbJar));
final AppInfo appInfo = config.configureApplication(app);
assembler.createApplication(appInfo);
final InitialContext initialContext = new InitialContext();
final EmailResourceAdapter ra = (EmailResourceAdapter) initialContext.lookup("java:openejb/Resource/email-raRA");
final Properties headers = new Properties();
headers.put("To", "dblevins@apache.org");
headers.put("From", "dblevins@visi.com");
headers.put("Subject", "Hello");
ra.deliverEmail(headers, "How's it going?");
final Stack<Lifecycle> lifecycle = EmailBean.lifecycle;
final List expected = Arrays.asList(Lifecycle.values());
Assert.assertEquals(Join.join("\n", expected), Join.join("\n", lifecycle));
}
Aggregations