Search in sources :

Example 91 with ConfigurationFactory

use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.

the class AccessTimeoutTest method test.

public void test() throws Exception {
    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));
    // TODO alternative to hack in CidBuilder to initialize if missing
    // SystemInstance.get().setComponent(ThreadSingletonService.class, new ThreadSingletonServiceImpl(getClass().getClassLoader()));
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new SingletonBean(Color.class));
    ejbJar.addEnterpriseBean(new SingletonBean(Red.class));
    ejbJar.addEnterpriseBean(new SingletonBean(Crimson.class));
    ejbJar.addEnterpriseBean(new SingletonBean(Scarlet.class));
    final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
    assembler.createApplication(ejbJarInfo);
    loadAttributes(ejbJarInfo, "Color");
    assertAttribute(2, TimeUnit.SECONDS, Color.class.getMethod("color"));
    assertAttribute(3, TimeUnit.SECONDS, Color.class.getMethod("color", Object.class));
    assertAttribute(1, TimeUnit.SECONDS, Color.class.getMethod("color", String.class));
    assertAttribute(1, TimeUnit.SECONDS, Color.class.getMethod("color", Boolean.class));
    assertAttribute(1, TimeUnit.SECONDS, Color.class.getMethod("color", Integer.class));
    loadAttributes(ejbJarInfo, "Red");
    assertAttribute(2, TimeUnit.SECONDS, Red.class.getMethod("color"));
    assertNullAttribute(Red.class.getMethod("color", Object.class));
    assertAttribute(1, TimeUnit.SECONDS, Red.class.getMethod("color", String.class));
    assertAttribute(1, TimeUnit.SECONDS, Red.class.getMethod("color", Boolean.class));
    assertAttribute(1, TimeUnit.SECONDS, Red.class.getMethod("color", Integer.class));
    assertAttribute(1, TimeUnit.MINUTES, Red.class.getMethod("red"));
    assertNullAttribute(Red.class.getMethod("red", Object.class));
    assertNullAttribute(Red.class.getMethod("red", String.class));
    loadAttributes(ejbJarInfo, "Crimson");
    assertAttribute(1, TimeUnit.HOURS, Crimson.class.getMethod("color"));
    assertNullAttribute(Crimson.class.getMethod("color", Object.class));
    assertAttribute(1, TimeUnit.HOURS, Crimson.class.getMethod("color", String.class));
    assertAttribute(1, TimeUnit.SECONDS, Crimson.class.getMethod("color", Boolean.class));
    assertAttribute(1, TimeUnit.SECONDS, Crimson.class.getMethod("color", Integer.class));
    assertAttribute(1, TimeUnit.MINUTES, Crimson.class.getMethod("red"));
    assertNullAttribute(Crimson.class.getMethod("red", Object.class));
    assertNullAttribute(Crimson.class.getMethod("red", String.class));
    assertAttribute(2, TimeUnit.HOURS, Crimson.class.getMethod("crimson"));
    assertAttribute(1, TimeUnit.HOURS, Crimson.class.getMethod("crimson", String.class));
    loadAttributes(ejbJarInfo, "Scarlet");
    assertAttribute(2, TimeUnit.SECONDS, Scarlet.class.getMethod("color"));
    assertNullAttribute(Scarlet.class.getMethod("color", Object.class));
    assertAttribute(1, TimeUnit.SECONDS, Scarlet.class.getMethod("color", String.class));
    assertAttribute(1, TimeUnit.SECONDS, Scarlet.class.getMethod("color", Boolean.class));
    assertAttribute(1, TimeUnit.SECONDS, Scarlet.class.getMethod("color", Integer.class));
    assertAttribute(1, TimeUnit.MINUTES, Scarlet.class.getMethod("red"));
    assertNullAttribute(Scarlet.class.getMethod("red", Object.class));
    assertNullAttribute(Scarlet.class.getMethod("red", String.class));
    assertAttribute(2, TimeUnit.DAYS, Scarlet.class.getMethod("scarlet"));
    assertAttribute(1, TimeUnit.DAYS, Scarlet.class.getMethod("scarlet", String.class));
}
Also used : SingletonBean(org.apache.openejb.jee.SingletonBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbJar(org.apache.openejb.jee.EjbJar)

Example 92 with ConfigurationFactory

use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.

the class ConcurrentLockTypeTest method test.

public void test() throws Exception {
    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));
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new SingletonBean(Color.class));
    ejbJar.addEnterpriseBean(new SingletonBean(Red.class));
    ejbJar.addEnterpriseBean(new SingletonBean(Crimson.class));
    ejbJar.addEnterpriseBean(new SingletonBean(Scarlet.class));
    final List<ContainerConcurrency> declared = ejbJar.getAssemblyDescriptor().getContainerConcurrency();
    declared.add(new ContainerConcurrency(ConcurrentLockType.WRITE, "*", "*", "*"));
    declared.add(new ContainerConcurrency(ConcurrentLockType.READ, "*", "Crimson", "*"));
    declared.add(new ContainerConcurrency(ConcurrentLockType.READ, Color.class.getName(), "Scarlet", "*"));
    declared.add(new ContainerConcurrency(ConcurrentLockType.READ, Red.class.getName(), "Scarlet", "red"));
    declared.add(new ContainerConcurrency(ConcurrentLockType.WRITE, "Scarlet", Scarlet.class.getMethod("scarlet")));
    final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
    assembler.createApplication(ejbJarInfo);
    loadAttributes(ejbJarInfo, "Color");
    assertAttribute("Read", Color.class.getMethod("color"));
    assertAttribute("Write", Color.class.getMethod("color", Object.class));
    assertAttribute("Write", Color.class.getMethod("color", String.class));
    assertAttribute("Write", Color.class.getMethod("color", Boolean.class));
    assertAttribute("Write", Color.class.getMethod("color", Integer.class));
    loadAttributes(ejbJarInfo, "Red");
    assertAttribute("Read", Red.class.getMethod("color"));
    assertAttribute("Write", Red.class.getMethod("color", Object.class));
    assertAttribute("Write", Red.class.getMethod("color", String.class));
    assertAttribute("Write", Red.class.getMethod("color", Boolean.class));
    assertAttribute("Write", Red.class.getMethod("color", Integer.class));
    assertAttribute("Write", Red.class.getMethod("red"));
    assertAttribute("Write", Red.class.getMethod("red", Object.class));
    assertAttribute("Write", Red.class.getMethod("red", String.class));
    loadAttributes(ejbJarInfo, "Crimson");
    assertAttribute("Read", Crimson.class.getMethod("color"));
    assertAttribute("Read", Crimson.class.getMethod("color", Object.class));
    assertAttribute("Read", Crimson.class.getMethod("color", String.class));
    assertAttribute("Read", Crimson.class.getMethod("color", Boolean.class));
    assertAttribute("Read", Crimson.class.getMethod("color", Integer.class));
    assertAttribute("Write", Crimson.class.getMethod("red"));
    assertAttribute("Read", Crimson.class.getMethod("red", Object.class));
    assertAttribute("Read", Crimson.class.getMethod("red", String.class));
    assertAttribute("Write", Crimson.class.getMethod("crimson"));
    assertAttribute("Read", Crimson.class.getMethod("crimson", String.class));
    loadAttributes(ejbJarInfo, "Scarlet");
    assertAttribute("Read", Scarlet.class.getMethod("color"));
    assertAttribute("Write", Scarlet.class.getMethod("color", Object.class));
    assertAttribute("Read", Scarlet.class.getMethod("color", String.class));
    assertAttribute("Read", Scarlet.class.getMethod("color", Boolean.class));
    assertAttribute("Read", Scarlet.class.getMethod("color", Integer.class));
    assertAttribute("Write", Scarlet.class.getMethod("red"));
    assertAttribute("Read", Scarlet.class.getMethod("red", Object.class));
    assertAttribute("Read", Scarlet.class.getMethod("red", String.class));
    assertAttribute("Write", Scarlet.class.getMethod("scarlet"));
    assertAttribute("Read", Scarlet.class.getMethod("scarlet", String.class));
}
Also used : SingletonBean(org.apache.openejb.jee.SingletonBean) ContainerConcurrency(org.apache.openejb.jee.ContainerConcurrency) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbJar(org.apache.openejb.jee.EjbJar)

Example 93 with ConfigurationFactory

use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.

the class JdbcConfigTest method test.

public void test() throws Exception {
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    // System services
    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    // managed JDBC
    assembler.createResource(config.configureService("Default JDBC Database", ResourceInfo.class));
    // unmanaged JDBC
    assembler.createResource(config.configureService("Default Unmanaged JDBC Database", ResourceInfo.class));
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    final DataSource managedDS = (DataSource) containerSystem.getJNDIContext().lookup("openejb/Resource/Default JDBC Database");
    assertNotNull("managedDS is null", managedDS);
    final DataSource unmanagedDS = (DataSource) containerSystem.getJNDIContext().lookup("openejb/Resource/Default Unmanaged JDBC Database");
    assertNotNull("unmanagedDS is null", unmanagedDS);
    // test without a transaction
    // NOTE: without a transaction all connections work as unmanaged
    verifyUnmanagedConnections(managedDS);
    verifyUnmanagedConnections(unmanagedDS);
    // test in the context of a transaction
    final TransactionManager transactionManager = SystemInstance.get().getComponent(TransactionManager.class);
    transactionManager.begin();
    try {
        verifyManagedConnections(managedDS);
        verifyUnmanagedConnections(unmanagedDS);
    } finally {
        // commit the transaction
        transactionManager.commit();
    }
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) TransactionManager(javax.transaction.TransactionManager) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) DataSource(javax.sql.DataSource)

Example 94 with ConfigurationFactory

use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.

the class MdbConfigTest method test.

public void test() throws Exception {
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    // System services
    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    // JMS persistence datasource
    final ResourceInfo dataSourceInfo = config.configureService("Default Unmanaged JDBC Database", ResourceInfo.class);
    dataSourceInfo.properties.setProperty("JdbcUrl", "jdbc:hsqldb:mem:MdbConfigTest");
    assembler.createResource(dataSourceInfo);
    // JMS
    assembler.createResource(config.configureService("Default JMS Resource Adapter", ResourceInfo.class));
    // JMS Container
    final MdbContainerInfo mdbContainerInfo = config.configureService(MdbContainerInfo.class);
    assembler.createContainer(mdbContainerInfo);
    // FakeRA
    final ResourceInfo resourceInfo = new ResourceInfo();
    resourceInfo.service = "Resource";
    resourceInfo.className = FakeRA.class.getName();
    resourceInfo.id = "FakeRA";
    resourceInfo.properties = new Properties();
    assembler.createResource(resourceInfo);
    // FakeRA container
    final ContainerInfo containerInfo = config.configureService(MdbContainerInfo.class);
    containerInfo.id = "FakeContainer";
    containerInfo.displayName = "Fake Container";
    containerInfo.properties.setProperty("ResourceAdapter", "FakeRA");
    containerInfo.properties.setProperty("MessageListenerInterface", FakeMessageListener.class.getName());
    containerInfo.properties.setProperty("ActivationSpecClass", FakeActivationSpec.class.getName());
    assembler.createContainer(containerInfo);
    // generate ejb jar application
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(createJaxbMdb("JmsMdb", BasicMdbBean.class.getName(), MessageListener.class.getName()));
    ejbJar.addEnterpriseBean(createJaxbMdb("FakeMdb", FakeMdb.class.getName(), FakeMessageListener.class.getName()));
    final EjbModule ejbModule = new EjbModule(getClass().getClassLoader(), "FakeEjbJar", "fake.jar", ejbJar, null);
    // configure and deploy it
    final EjbJarInfo info = config.configureApplication(ejbModule);
    assembler.createEjbJar(info);
}
Also used : EjbModule(org.apache.openejb.config.EjbModule) Properties(java.util.Properties) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbJar(org.apache.openejb.jee.EjbJar)

Example 95 with ConfigurationFactory

use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.

the class OpenEJBXmlByModuleTest method setUp.

@Before
public void setUp() throws OpenEJBException, NamingException, IOException {
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    final AppModule app = new AppModule(OpenEJBXmlByModuleTest.class.getClassLoader(), OpenEJBXmlByModuleTest.class.getSimpleName());
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new SingletonBean(UselessBean.class));
    app.getEjbModules().add(new EjbModule(ejbJar));
    app.getEjbModules().iterator().next().getAltDDs().put("resources.xml", getClass().getClassLoader().getResource("META-INF/resource/appresource.openejb.xml"));
    assembler.createApplication(config.configureApplication(app));
    final Properties properties = new Properties();
    properties.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
    properties.setProperty("openejb.embedded.initialcontext.close", "destroy");
    // some hack to be sure to call destroy()
    context = new InitialContext(properties);
    bean = (UselessBean) context.lookup("UselessBeanLocalBean");
}
Also used : AppModule(org.apache.openejb.config.AppModule) EjbModule(org.apache.openejb.config.EjbModule) Properties(java.util.Properties) LocalInitialContextFactory(org.apache.openejb.core.LocalInitialContextFactory) InitialContext(javax.naming.InitialContext) SingletonBean(org.apache.openejb.jee.SingletonBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbJar(org.apache.openejb.jee.EjbJar) Before(org.junit.Before)

Aggregations

ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)100 Assembler (org.apache.openejb.assembler.classic.Assembler)84 EjbJar (org.apache.openejb.jee.EjbJar)76 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)57 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)57 StatelessBean (org.apache.openejb.jee.StatelessBean)44 InitialContext (javax.naming.InitialContext)41 Properties (java.util.Properties)37 EjbModule (org.apache.openejb.config.EjbModule)30 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)29 LocalInitialContextFactory (org.apache.openejb.core.LocalInitialContextFactory)29 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)21 StatelessSessionContainerInfo (org.apache.openejb.assembler.classic.StatelessSessionContainerInfo)18 SingletonBean (org.apache.openejb.jee.SingletonBean)18 Context (javax.naming.Context)17 StatefulBean (org.apache.openejb.jee.StatefulBean)16 AppModule (org.apache.openejb.config.AppModule)15 ServerFederation (org.apache.openejb.core.ServerFederation)15 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)14 ContainerSystem (org.apache.openejb.spi.ContainerSystem)13