Search in sources :

Example 61 with Assembler

use of org.apache.openejb.assembler.classic.Assembler in project tomee by apache.

the class DeploymentContextPropertiesTest method testBeanContextProperties.

public void testBeanContextProperties() 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();
        final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
        final StatelessBean statelessBean = ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
        final EjbDeployment deployment = openejbJar.addEjbDeployment(statelessBean);
        deployment.getProperties().put("color", "orange");
        assembler.createApplication(config.configureApplication(ejbModule));
    }
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    final BeanContext beanContext = containerSystem.getBeanContext("WidgetBean");
    final Properties properties = beanContext.getProperties();
    assertProperty(properties, "color", "orange");
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) 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) Properties(java.util.Properties) EjbJar(org.apache.openejb.jee.EjbJar)

Example 62 with Assembler

use of org.apache.openejb.assembler.classic.Assembler in project tomee by apache.

the class DeploymentContextPropertiesTest method testModuleContextProperties.

public void testModuleContextProperties() 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();
        final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
        openejbJar.getProperties().setProperty("color", "orange");
        ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
        final EjbJarInfo moduleInfo = config.configureApplication(ejbModule);
        assertProperty(moduleInfo.properties, "color", "orange");
        assembler.createApplication(moduleInfo);
    }
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    final BeanContext beanContext = containerSystem.getBeanContext("WidgetBean");
    final Properties properties = beanContext.getModuleContext().getProperties();
    assertProperty(properties, "color", "orange");
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) 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) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 63 with Assembler

use of org.apache.openejb.assembler.classic.Assembler in project tomee by apache.

the class AutoConfigResourceRefsTest 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.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    assembler.createResource(config.configureService(new org.apache.openejb.config.sys.Resource("defaultDataSource", "DataSource", null), ResourceInfo.class));
    assembler.createResource(config.configureService(new org.apache.openejb.config.sys.Resource("yellowDataSource", "DataSource", null), ResourceInfo.class));
    assembler.createResource(config.configureService(new org.apache.openejb.config.sys.Resource("PurpleDataSource", "DataSource", null), ResourceInfo.class));
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
    final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
    final EnterpriseBeanInfo beanInfo = ejbJarInfo.enterpriseBeans.get(0);
    final Map<String, ResourceReferenceInfo> refs = new HashMap<String, ResourceReferenceInfo>();
    for (final ResourceReferenceInfo ref : beanInfo.jndiEnc.resourceRefs) {
        refs.put(ref.referenceName.replaceAll(".*/", ""), ref);
    }
    ResourceReferenceInfo info;
    info = refs.get("yellowDataSource");
    assertNotNull(info);
    assertEquals("yellowDataSource", info.resourceID);
    info = refs.get("orangeDataSource");
    assertNotNull(info);
    assertEquals("defaultDataSource", info.resourceID);
    info = refs.get("purpleDataSource");
    assertNotNull(info);
    assertEquals("PurpleDataSource", info.resourceID);
}
Also used : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) HashMap(java.util.HashMap) Resource(javax.annotation.Resource) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) ResourceReferenceInfo(org.apache.openejb.assembler.classic.ResourceReferenceInfo) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 64 with Assembler

use of org.apache.openejb.assembler.classic.Assembler in project tomee by apache.

the class AutoConfigResourceRefsTest method testCaseInsensitive.

public void testCaseInsensitive() throws Exception {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    assembler.createResource(config.configureService(new org.apache.openejb.config.sys.Resource("DeFAultDataSource", "DataSource", null), ResourceInfo.class));
    assembler.createResource(config.configureService(new org.apache.openejb.config.sys.Resource("YeLLowDataSource", "DataSource", null), ResourceInfo.class));
    assembler.createResource(config.configureService(new org.apache.openejb.config.sys.Resource("PurpLEDataSource", "DataSource", null), ResourceInfo.class));
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
    final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
    final EnterpriseBeanInfo beanInfo = ejbJarInfo.enterpriseBeans.get(0);
    final Map<String, ResourceReferenceInfo> refs = new HashMap<String, ResourceReferenceInfo>();
    for (final ResourceReferenceInfo ref : beanInfo.jndiEnc.resourceRefs) {
        refs.put(ref.referenceName.replaceAll(".*/", ""), ref);
    }
    ResourceReferenceInfo info;
    info = refs.get("yellowDataSource");
    assertNotNull(info);
    assertEquals("YeLLowDataSource", info.resourceID);
    info = refs.get("orangeDataSource");
    assertNotNull(info);
    assertEquals("DeFAultDataSource", info.resourceID);
    info = refs.get("purpleDataSource");
    assertNotNull(info);
    assertEquals("PurpLEDataSource", info.resourceID);
}
Also used : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) HashMap(java.util.HashMap) Resource(javax.annotation.Resource) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) ResourceReferenceInfo(org.apache.openejb.assembler.classic.ResourceReferenceInfo) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 65 with Assembler

use of org.apache.openejb.assembler.classic.Assembler in project tomee by apache.

the class AutoDeployerTest method testAltUnpackDir.

@Test
public void testAltUnpackDir() throws Exception {
    final File tmpdir = Files.tmpdir();
    final File apps = Files.mkdir(tmpdir, "myapps");
    final File conf = Files.mkdir(tmpdir, "conf");
    files.add(apps);
    final Properties properties = new Properties();
    properties.setProperty("openejb.deployments.classpath", "false");
    properties.setProperty("tomee.unpack.dir", "work");
    properties.setProperty("openejb.home", tmpdir.getAbsolutePath());
    properties.setProperty("openejb.base", tmpdir.getAbsolutePath());
    SystemInstance.init(properties);
    {
        // Setup the configuration location
        final File config = new File(conf, "openejb.xml");
        IO.writeString(config, "<openejb><Deployments autoDeploy=\"true\" dir=\"myapps\"/> </openejb>");
        SystemInstance.get().setProperty("openejb.configuration", config.getAbsolutePath());
    }
    final ConfigurationFactory configurationFactory = new ConfigurationFactory();
    configurationFactory.init(properties);
    final OpenEjbConfiguration configuration = configurationFactory.getOpenEjbConfiguration();
    {
        // Check the ContainerSystemInfo
        final List<String> autoDeploy = configuration.containerSystem.autoDeploy;
        assertEquals(1, autoDeploy.size());
        assertEquals("myapps", autoDeploy.get(0));
    }
    final Assembler assembler = new Assembler();
    assembler.buildContainerSystem(configuration);
    // / start with the testing...
    assertFalse(Yellow.deployed);
    assertFalse(Orange.deployed);
    final File deployed = Files.path(apps, "colors.ear");
    deployed.deleteOnExit();
    // Hot deploy the EAR
    final File ear = createEar(tmpdir, Orange.class, State.class);
    ear.deleteOnExit();
    IO.copy(ear, deployed);
    assertTrue(deployed.exists());
    Orange.state.waitForChange(1, TimeUnit.MINUTES);
    assertFalse(Yellow.deployed);
    assertTrue(Orange.deployed);
    Files.delete(deployed);
    Orange.state.waitForChange(1, TimeUnit.MINUTES);
    assertFalse(Yellow.deployed);
    assertFalse(Orange.deployed);
}
Also used : List(java.util.List) Assembler(org.apache.openejb.assembler.classic.Assembler) Properties(java.util.Properties) File(java.io.File) OpenEjbConfiguration(org.apache.openejb.assembler.classic.OpenEjbConfiguration) Test(org.junit.Test)

Aggregations

Assembler (org.apache.openejb.assembler.classic.Assembler)171 EjbJar (org.apache.openejb.jee.EjbJar)88 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)84 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)76 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)76 StatelessBean (org.apache.openejb.jee.StatelessBean)56 InitialContext (javax.naming.InitialContext)50 File (java.io.File)49 AppInfo (org.apache.openejb.assembler.classic.AppInfo)47 Properties (java.util.Properties)42 HashMap (java.util.HashMap)39 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)39 ContainerSystem (org.apache.openejb.spi.ContainerSystem)35 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)29 LocalInitialContextFactory (org.apache.openejb.core.LocalInitialContextFactory)29 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)29 Test (org.junit.Test)29 EjbModule (org.apache.openejb.config.EjbModule)27 StatelessSessionContainerInfo (org.apache.openejb.assembler.classic.StatelessSessionContainerInfo)22 Map (java.util.Map)21