Search in sources :

Example 46 with Assembler

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

the class ModulePropertiesTest method testOverrideReplace.

public void testOverrideReplace() throws Exception {
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    {
        // setup the system
        assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
        assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    }
    {
        SystemInstance.get().getProperties().put("fooModule.color", "orange");
        final Map<String, String> map = new HashMap<String, String>();
        map.put("META-INF/ejb-jar.xml", "<ejb-jar id=\"fooModule\"/>");
        map.put("META-INF/module.properties", "color=white");
        final File module = Archives.fileArchive(map, WidgetBean.class);
        final AppModule appModule = config.loadApplication(this.getClass().getClassLoader(), "fooApp", Arrays.asList(module));
        final AppInfo appInfo = config.configureApplication(appModule);
        assembler.createApplication(appInfo);
    }
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    assertContexts(containerSystem);
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) Assembler(org.apache.openejb.assembler.classic.Assembler) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 47 with Assembler

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

the class ModulePropertiesTest method testOverrideFromApplicationProperties.

public void testOverrideFromApplicationProperties() throws Exception {
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    {
        // setup the system
        assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
        assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    }
    {
        final Map<String, String> map = new HashMap<String, String>();
        map.put("META-INF/ejb-jar.xml", "<ejb-jar id=\"fooModule\"/>");
        map.put("META-INF/module.properties", "color=white");
        final File module = Archives.fileArchive(map, WidgetBean.class);
        final AppModule appModule = config.loadApplication(this.getClass().getClassLoader(), "fooApp", Arrays.asList(module));
        appModule.getProperties().put("fooModule.color", "orange");
        final AppInfo appInfo = config.configureApplication(appModule);
        assembler.createApplication(appInfo);
    }
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    assertContexts(containerSystem);
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) Assembler(org.apache.openejb.assembler.classic.Assembler) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 48 with Assembler

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

the class ServiceClasspathTest method testJson.

@Test
public void testJson() throws Exception {
    final String className = "org.superbiz.foo.Orange";
    final File jar = subclass(Color.class, className);
    final File json = File.createTempFile("config-", ".json");
    json.deleteOnExit();
    final PrintStream out = new PrintStream(IO.write(json));
    out.println("{\n" + "    \"resources\":{\n" + "        \"Orange\":{\n" + "            \"type\":\"org.superbiz.foo.Orange\",\n" + "            \"class-name\":\"org.superbiz.foo.Orange\",\n" + "            \"classpath\":\"" + jar.getAbsolutePath() + "\",\n" + "            \"properties\":{\n" + "                \"red\":\"FF\",\n" + "                \"green\":\"99\",\n" + "                \"blue\":\"00\"\n" + "            }\n" + "        }\n" + "    }\n" + "}\n");
    out.close();
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    createEnvrt();
    assembler.buildContainerSystem(config.getOpenEjbConfiguration(json));
    final InitialContext initialContext = new InitialContext();
    final Color color = (Color) initialContext.lookup("openejb:Resource/Orange");
    assertNotNull(color);
    assertEquals("Orange.FF", color.getRed());
    assertEquals("Orange.99", color.getGreen());
    assertEquals("Orange.00", color.getBlue());
}
Also used : PrintStream(java.io.PrintStream) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) File(java.io.File) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 49 with Assembler

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

the class CdiDecoratorTest method setUp.

@Before
public void setUp() throws Exception {
    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.createContainer(config.configureService(StatelessSessionContainerInfo.class));
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean("HelloOne", RedBean.class));
    ejbJar.addEnterpriseBean(new StatelessBean("HelloTwo", RedBean.class));
    ejbJar.addEnterpriseBean(new StatelessBean(OrangeBean.class));
    final Beans beans = new Beans();
    beans.addInterceptor(OrangeCdiInterceptor.class);
    beans.addDecorator(OrangeOneDecorator.class);
    beans.addDecorator(OrangeTwoDecorator.class);
    beans.addManagedClass(YellowBean.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 : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) EjbModule(org.apache.openejb.config.EjbModule) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) 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) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar) Before(org.junit.Before)

Example 50 with Assembler

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

the class AltDDPrefixTest method testMultitplePrefixes.

public void testMultitplePrefixes() throws Exception {
    System.out.println("*** testMultitplePrefixes ***");
    final Assembler assmbler = new Assembler();
    SystemInstance.get().setProperty("openejb.altdd.prefix", "footest, test");
    DeploymentLoader.reloadAltDD();
    final ConfigurationFactory factory = new ConfigurationFactory();
    final URL resource = AltDDPrefixTest.class.getClassLoader().getResource("altddapp2");
    final File file = URLs.toFile(resource);
    final AppInfo appInfo = factory.configureApplication(file);
    assertNotNull(appInfo);
    assertEquals(1, appInfo.ejbJars.size());
    final EjbJarInfo ejbJar = appInfo.ejbJars.get(0);
    // was the footest.ejb-jar.xml picked up
    assertEquals("EjbJar.enterpriseBeans", 1, ejbJar.enterpriseBeans.size());
    assertEquals("EjbJar.interceptors.size()", 1, ejbJar.interceptors.size());
    // was the test.env-entries.properties picked up
    // 4 + ComponentName
    assertEquals("EjbJar.enterpriseBeans.get(0).jndiEnc.envEntries.size()", 5, ejbJar.enterpriseBeans.get(0).jndiEnc.envEntries.size());
}
Also used : Assembler(org.apache.openejb.assembler.classic.Assembler) File(java.io.File) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) URL(java.net.URL) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

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