Search in sources :

Example 86 with Assembler

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

the class AppResourceProducer method produce.

public void produce(@Observes final BeforeClass bs) {
    try {
        final Assembler a = SystemInstance.get().getComponent(Assembler.class);
        context.set(a.getContainerSystem().getJNDIContext());
        beanManager.set(a.getContainerSystem().getAppContext(a.getDeployedApplications().iterator().next().appId).getBeanManager());
    } catch (final Exception e) {
    // no-op
    }
}
Also used : Assembler(org.apache.openejb.assembler.classic.Assembler)

Example 87 with Assembler

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

the class InvokeMethod method setUp.

private void setUp() throws Exception {
    config = new ConfigurationFactory();
    assembler = new Assembler();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
}
Also used : TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo)

Example 88 with Assembler

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

the class ServiceProviderInheritanceTest method test.

public void test() throws Exception {
    SystemInstance.get().setComponent(ProviderManager.class, new ProviderManager(new ProviderLoader() {

        final ProviderLoader loader = new ServiceJarXmlLoader();

        @Override
        public ServiceProvider load(final ID id) {
            {
                // try the regular loader
                final ServiceProvider provider = loader.load(id);
                if (provider != null)
                    return provider;
            }
            if ("color".equalsIgnoreCase(id.getName())) {
                final ServiceProvider color = new ServiceProvider(Color.class, "Color", "Resource");
                color.getProperties().setProperty("red", "0");
                color.getProperties().setProperty("green", "0");
                color.getProperties().setProperty("blue", "0");
                color.getTypes().add(Color.class.getName());
                return color;
            }
            if ("red".equalsIgnoreCase(id.getName())) {
                final ServiceProvider red = new ServiceProvider();
                red.setId("Red");
                red.setParent("Color");
                red.getProperties().setProperty("red", "255");
                return red;
            }
            if ("orange".equalsIgnoreCase(id.getName())) {
                final ServiceProvider orange = new ServiceProvider();
                orange.setId("Orange");
                orange.setParent("Red");
                orange.getProperties().setProperty("green", "200");
                return orange;
            }
            throw new IllegalStateException(id.toString());
        }

        @Override
        public List<ServiceProvider> load(final String namespace) {
            final List<ServiceProvider> list = loader.load(namespace);
            list.add(load(new ID(namespace, "color")));
            list.add(load(new ID(namespace, "red")));
            list.add(load(new ID(namespace, "orange")));
            return list;
        }
    }));
    final ConfigurationFactory factory = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createSecurityService(factory.configureService(SecurityServiceInfo.class));
    assembler.createTransactionManager(factory.configureService(TransactionServiceInfo.class));
    {
        final Resource orange = new Resource("Orange", Color.class.getName(), "Orange");
        final ResourceInfo resourceInfo = factory.configureService(orange, ResourceInfo.class);
        assertEquals(Color.class.getName(), resourceInfo.className);
        assertEquals("Orange", resourceInfo.id);
        assertEquals(3, resourceInfo.properties.size());
        assertEquals("255", resourceInfo.properties.get("red"));
        assertEquals("200", resourceInfo.properties.get("green"));
        assertEquals("0", resourceInfo.properties.get("blue"));
        assembler.createResource(resourceInfo);
    }
    {
        final EjbJar ejbJar = new EjbJar();
        ejbJar.addEnterpriseBean(new SingletonBean(MyBean.class));
        final AppContext application = assembler.createApplication(factory.configureApplication(new EjbModule(ejbJar)));
        final MyBean myBean = (MyBean) application.getBeanContexts().get(0).getBusinessLocalBeanHome().create();
        final Color color = myBean.getColor();
        assertNotNull(color);
        assertEquals(255, color.getRed());
        assertEquals(200, color.getGreen());
        assertEquals(0, color.getBlue());
    }
}
Also used : ResourceInfo(org.apache.openejb.assembler.classic.ResourceInfo) AppContext(org.apache.openejb.AppContext) EjbModule(org.apache.openejb.config.EjbModule) ProviderLoader(org.apache.openejb.config.provider.ProviderLoader) SingletonBean(org.apache.openejb.jee.SingletonBean) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) ProviderManager(org.apache.openejb.config.provider.ProviderManager) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) ID(org.apache.openejb.config.provider.ID) Assembler(org.apache.openejb.assembler.classic.Assembler) ServiceJarXmlLoader(org.apache.openejb.config.provider.ServiceJarXmlLoader) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 89 with Assembler

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

the class EjbContextTest method test.

public void test() throws Exception {
    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatefulBean("Stateful", MySessionBean.class));
    ejbJar.addEnterpriseBean(new StatelessBean("Stateless", MySessionBean.class));
    ejbJar.addEnterpriseBean(new SingletonBean("Singleton", MySessionBean.class));
    assembler.createApplication(config.configureApplication(ejbJar));
    final Properties properties = new Properties();
    properties.put(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
    final InitialContext context = new InitialContext(properties);
    {
        final MySessionBean bean = (MySessionBean) context.lookup("StatefulLocalBean");
        bean.test();
    }
    {
        final MySessionBean bean = (MySessionBean) context.lookup("StatelessLocalBean");
        bean.test();
    }
    {
        final MySessionBean bean = (MySessionBean) context.lookup("SingletonLocalBean");
        bean.test();
    }
}
Also used : SingletonBean(org.apache.openejb.jee.SingletonBean) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) StatefulBean(org.apache.openejb.jee.StatefulBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) Properties(java.util.Properties) LocalInitialContextFactory(org.apache.openejb.osgi.client.LocalInitialContextFactory) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) InitialContext(javax.naming.InitialContext) EjbJar(org.apache.openejb.jee.EjbJar)

Example 90 with Assembler

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

the class AsynchTest method beforeTest.

@Before
public void beforeTest() throws Exception {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
    config = new ConfigurationFactory();
    assembler = new Assembler();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
}
Also used : TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) LocalInitialContextFactory(org.apache.openejb.core.LocalInitialContextFactory) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) Before(org.junit.Before)

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