Search in sources :

Example 96 with ConfigurationFactory

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

the class TransactionAttributesTest 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 StatelessBean(Color.class));
    ejbJar.addEnterpriseBean(new StatelessBean(Red.class));
    ejbJar.addEnterpriseBean(new StatelessBean(Crimson.class));
    ejbJar.addEnterpriseBean(new StatelessBean(Scarlet.class));
    final List<ContainerTransaction> declared = ejbJar.getAssemblyDescriptor().getContainerTransaction();
    declared.add(new ContainerTransaction(TransAttribute.REQUIRED, "*", "*", "*"));
    declared.add(new ContainerTransaction(TransAttribute.SUPPORTS, "*", "Crimson", "*"));
    declared.add(new ContainerTransaction(TransAttribute.SUPPORTS, Color.class.getName(), "Scarlet", "*"));
    declared.add(new ContainerTransaction(TransAttribute.NEVER, Red.class.getName(), "Scarlet", "red"));
    declared.add(new ContainerTransaction(TransAttribute.REQUIRED, "Scarlet", Scarlet.class.getMethod("scarlet")));
    ejbJar.getAssemblyDescriptor().addInterceptorBinding(new InterceptorBinding("*", AttributeInterceptor.class.getName()));
    final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
    assembler.createApplication(ejbJarInfo);
    loadAttributes(ejbJarInfo, "Color");
    assertAttribute("Never", Color.class.getMethod("color"));
    assertAttribute("RequiresNew", Color.class.getMethod("color", Object.class));
    assertAttribute("Mandatory", Color.class.getMethod("color", String.class));
    assertAttribute("Mandatory", Color.class.getMethod("color", Boolean.class));
    assertAttribute("Mandatory", Color.class.getMethod("color", Integer.class));
    loadAttributes(ejbJarInfo, "Red");
    assertAttribute("Never", Red.class.getMethod("color"));
    assertAttribute("Required", Red.class.getMethod("color", Object.class));
    assertAttribute("Mandatory", Red.class.getMethod("color", String.class));
    assertAttribute("Mandatory", Red.class.getMethod("color", Boolean.class));
    assertAttribute("Mandatory", Red.class.getMethod("color", Integer.class));
    assertAttribute("RequiresNew", Red.class.getMethod("red"));
    assertAttribute("Required", Red.class.getMethod("red", Object.class));
    assertAttribute("Required", Red.class.getMethod("red", String.class));
    loadAttributes(ejbJarInfo, "Crimson");
    assertAttribute("Supports", Crimson.class.getMethod("color"));
    assertAttribute("Supports", Crimson.class.getMethod("color", Object.class));
    assertAttribute("Supports", Crimson.class.getMethod("color", String.class));
    assertAttribute("Supports", Crimson.class.getMethod("color", Boolean.class));
    assertAttribute("Supports", Crimson.class.getMethod("color", Integer.class));
    assertAttribute("RequiresNew", Crimson.class.getMethod("red"));
    assertAttribute("Supports", Crimson.class.getMethod("red", Object.class));
    assertAttribute("Supports", Crimson.class.getMethod("red", String.class));
    assertAttribute("RequiresNew", Crimson.class.getMethod("crimson"));
    assertAttribute("Supports", Crimson.class.getMethod("crimson", String.class));
    loadAttributes(ejbJarInfo, "Scarlet");
    assertAttribute("Never", Scarlet.class.getMethod("color"));
    assertAttribute("Required", Scarlet.class.getMethod("color", Object.class));
    assertAttribute("Supports", Scarlet.class.getMethod("color", String.class));
    assertAttribute("Supports", Scarlet.class.getMethod("color", Boolean.class));
    assertAttribute("Supports", Scarlet.class.getMethod("color", Integer.class));
    assertAttribute("RequiresNew", Scarlet.class.getMethod("red"));
    assertAttribute("Never", Scarlet.class.getMethod("red", Object.class));
    assertAttribute("Never", Scarlet.class.getMethod("red", String.class));
    assertAttribute("Required", Scarlet.class.getMethod("scarlet"));
    assertAttribute("NotSupported", Scarlet.class.getMethod("scarlet", String.class));
}
Also used : InterceptorBinding(org.apache.openejb.jee.InterceptorBinding) StatelessBean(org.apache.openejb.jee.StatelessBean) ContainerTransaction(org.apache.openejb.jee.ContainerTransaction) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbJar(org.apache.openejb.jee.EjbJar)

Example 97 with ConfigurationFactory

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

the class SimpleCdiTest method setUp.

@Before
public void setUp() throws Exception {
    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 StatelessBean(Echo.class));
    final Beans beans = new Beans();
    beans.addInterceptor(EchoInterceptor.class);
    beans.addDecorator(EchoDecorator.class);
    beans.addManagedClass(SimpleModel.class);
    beans.addManagedClass(ProducesEjbInjector.class);
    final EjbModule module = new EjbModule(ejbJar);
    module.setBeans(beans);
    assembler.createApplication(config.configureApplication(module));
    final Properties properties = new Properties(System.getProperties());
    properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
    ctx = new InitialContext(properties);
}
Also used : Beans(org.apache.openejb.jee.Beans) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbModule(org.apache.openejb.config.EjbModule) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) Properties(java.util.Properties) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) InitialContext(javax.naming.InitialContext) EjbJar(org.apache.openejb.jee.EjbJar) Before(org.junit.Before)

Example 98 with ConfigurationFactory

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

the class DeploymentContextOptionsTest method testAllLevels.

public void testAllLevels() throws Exception {
    SystemInstance.get().setProperty("color", "orangeSystem");
    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
        final EjbModule ejbModule = new EjbModule(new EjbJar(), new OpenejbJar());
        final EjbJar ejbJar = ejbModule.getEjbJar();
        final StatelessBean statelessBean = ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
        {
            // Set at BeanContext level
            final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
            final EjbDeployment deployment = openejbJar.addEjbDeployment(statelessBean);
            deployment.getProperties().put("color", "orangeBean");
        }
        {
            // Set at ModuleContext level
            final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
            openejbJar.getProperties().put("color", "orangeModule");
        }
        final AppModule appModule = new AppModule(ejbModule);
        {
            // Set at AppContext level
            appModule.getProperties().put("color", "orangeApp");
        }
        assembler.createApplication(config.configureApplication(appModule));
    }
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    final BeanContext beanContext = containerSystem.getBeanContext("WidgetBean");
    assertOption(beanContext.getOptions(), "color", "orangeBean");
    assertOption(beanContext.getModuleContext().getOptions(), "color", "orangeModule");
    assertOption(beanContext.getModuleContext().getAppContext().getOptions(), "color", "orangeApp");
    assertOption(SystemInstance.get().getOptions(), "color", "orangeSystem");
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) AppModule(org.apache.openejb.config.AppModule) StatelessBean(org.apache.openejb.jee.StatelessBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbModule(org.apache.openejb.config.EjbModule) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJar(org.apache.openejb.jee.EjbJar)

Example 99 with ConfigurationFactory

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

the class DeploymentContextOptionsTest method testSystemInstanceOptions.

public void testSystemInstanceOptions() throws Exception {
    SystemInstance.get().setProperty("color", "orange");
    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
        final EjbModule ejbModule = new EjbModule(new EjbJar(), new OpenejbJar());
        final EjbJar ejbJar = ejbModule.getEjbJar();
        ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
        final AppModule appModule = new AppModule(ejbModule);
        assembler.createApplication(config.configureApplication(appModule));
    }
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    final BeanContext beanContext = containerSystem.getBeanContext("WidgetBean");
    assertOption(beanContext.getOptions(), "color", "orange");
    assertOption(beanContext.getModuleContext().getOptions(), "color", "orange");
    assertOption(beanContext.getModuleContext().getAppContext().getOptions(), "color", "orange");
    assertOption(SystemInstance.get().getOptions(), "color", "orange");
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) AppModule(org.apache.openejb.config.AppModule) StatelessBean(org.apache.openejb.jee.StatelessBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbModule(org.apache.openejb.config.EjbModule) Assembler(org.apache.openejb.assembler.classic.Assembler) EjbJar(org.apache.openejb.jee.EjbJar)

Example 100 with ConfigurationFactory

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

the class DeploymentContextPropertiesTest method testAppContextProperties.

public void testAppContextProperties() throws Exception {
    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
        final EjbModule ejbModule = new EjbModule(new EjbJar(), new OpenejbJar());
        final EjbJar ejbJar = ejbModule.getEjbJar();
        ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
        final AppModule appModule = new AppModule(ejbModule);
        appModule.getProperties().setProperty("color", "orange");
        final AppInfo appInfo = config.configureApplication(appModule);
        assertProperty(appInfo.properties, "color", "orange");
        assembler.createApplication(appInfo);
    }
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    final BeanContext beanContext = containerSystem.getBeanContext("WidgetBean");
    final Properties properties = beanContext.getModuleContext().getAppContext().getProperties();
    assertProperty(properties, "color", "orange");
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) AppModule(org.apache.openejb.config.AppModule) StatelessBean(org.apache.openejb.jee.StatelessBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbModule(org.apache.openejb.config.EjbModule) Assembler(org.apache.openejb.assembler.classic.Assembler) Properties(java.util.Properties) EjbJar(org.apache.openejb.jee.EjbJar) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

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