use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.
the class JmsMdbContainerTest 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();
// define props for RA in order to change the default activeMQ port
final Properties props = new Properties();
final String brokerAddress = NetworkUtil.getLocalAddress("tcp://", "");
final String brokerXmlConfig = "broker:(" + brokerAddress + ")?useJmx=false";
props.put("BrokerXmlConfig", brokerXmlConfig);
props.put("StartupTimeout", 10000);
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
assembler.createResource(config.configureService(ResourceInfo.class, "Default Unmanaged JDBC Database", new Properties(), "Default Unmanaged JDBC Database", "DataSource"));
assembler.createResource(config.configureService(ResourceInfo.class, "Default JMS Resource Adapter", props, "Default JMS Resource Adapter", "ActiveMQResourceAdapter"));
// Setup the descriptor information
WidgetBean.lifecycle.clear();
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new MessageDrivenBean(WidgetBean.class));
assembler.createApplication(config.configureApplication(ejbJar));
final InitialContext initialContext = new InitialContext();
final ConnectionFactory connectionFactory = (ConnectionFactory) initialContext.lookup("java:openejb/Resource/Default JMS Connection Factory");
sendMessage(connectionFactory, "WidgetBean", "test");
final Stack<Lifecycle> lifecycle = WidgetBean.lifecycle;
final List expected = Arrays.asList(Lifecycle.values());
assertEquals(join("\n", expected), join("\n", lifecycle));
}
use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.
the class NoMessageDeliveryTest 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.CONSTRUCTOR, Lifecycle.INJECTION, Lifecycle.POST_CONSTRUCT);
Assert.assertEquals(Join.join("\n", expected), Join.join("\n", lifecycle));
}
use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.
the class SecurityTest method configureAssembler.
private Assembler configureAssembler(final String defaultUser) throws Exception {
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
final SecurityServiceInfo serviceInfo = new SecurityServiceInfo();
serviceInfo.service = "SecurityService";
serviceInfo.className = SecurityServiceImpl.class.getName();
serviceInfo.id = "New Security Service";
serviceInfo.properties = new Properties();
if (defaultUser != null) {
// override the default user
serviceInfo.properties.setProperty("DefaultUser", defaultUser);
}
assembler.createSecurityService(serviceInfo);
// containers
assembler.createContainer(config.configureService(StatelessSessionContainerInfo.class));
final EjbJar ejbJar = new EjbJar("SecurityTest");
ejbJar.addEnterpriseBean(new StatelessBean(FooBean.class));
ejbJar.addEnterpriseBean(new StatelessBean(BarBean.class));
final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
assembler.createApplication(ejbJarInfo);
return assembler;
}
use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.
the class DependsOnTest method testNoSuchEjb.
public void testNoSuchEjb() throws Exception {
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
final Assembler assembler = new Assembler();
final ConfigurationFactory config = new ConfigurationFactory();
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
// containers
assembler.createContainer(config.configureService(SingletonSessionContainerInfo.class));
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new SingletonBean(One.class));
ejbJar.addEnterpriseBean(new SingletonBean(Two.class));
ejbJar.addEnterpriseBean(new SingletonBean(Three.class));
ejbJar.addEnterpriseBean(new SingletonBean(Four.class)).setDependsOn("Five");
try {
config.configureApplication(ejbJar);
fail("Validation should have found a circular reference");
} catch (final ValidationFailedException e) {
final ValidationFailure[] failures = e.getFailures();
assertEquals(1, failures.length);
assertEquals("dependsOn.noSuchEjb", failures[0].getMessageKey());
}
}
use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.
the class SingletonCircularTest method test.
public void test() throws Exception {
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
final Assembler assembler = new Assembler();
final ConfigurationFactory config = new ConfigurationFactory();
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
// containers
assembler.createContainer(config.configureService(SingletonSessionContainerInfo.class));
actual.clear();
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new SingletonBean(Two.class));
ejbJar.addEnterpriseBean(new SingletonBean(One.class));
// startup and trigger @PostConstruct
assembler.createApplication(config.configureApplication(ejbJar));
assertTrue(one, actual.contains(one));
assertTrue(two, actual.contains(two));
}
Aggregations