Search in sources :

Example 1 with EjbJar$JAXB

use of org.apache.openejb.jee.EjbJar$JAXB in project tomee by apache.

the class TestClassDiscoverer method discover.

@Override
public AppModule discover(final AppModule module) {
    final Set<Class<?>> testClasses = new HashSet<>();
    final Map<Class<?>, WebModule> webTestClasses = new HashMap<>();
    final Set<ClassLoader> saw = new HashSet<>();
    if (module.getClassLoader() != null) {
        addTests(findMarkers(module.getClassLoader()), findClassMarkers(module.getClassLoader()), module.getEarLibFinder(), testClasses);
        saw.add(module.getClassLoader());
    }
    for (final WebModule web : module.getWebModules()) {
        if (web.getClassLoader() != null && !saw.contains(web.getClassLoader())) {
            final Set<Class<?>> classes = new HashSet<>();
            addTests(findMarkers(web.getClassLoader()), findClassMarkers(web.getClassLoader()), web.getFinder(), classes);
            saw.add(web.getClassLoader());
            for (final Class<?> c : classes) {
                webTestClasses.put(c, web);
            }
            // in case of an ear if we find the same test class in a webapp we don't want it in lib part
            // this case can happen in tomee-embedded mainly
            final Iterator<Class<?>> c = testClasses.iterator();
            while (c.hasNext()) {
                final String cl = c.next().getName();
                for (final Class<?> wc : classes) {
                    if (cl.equals(wc.getName())) {
                        c.remove();
                        break;
                    }
                }
            }
            testClasses.addAll(classes);
        }
    }
    for (final EjbModule ejb : module.getEjbModules()) {
        if (ejb.getClassLoader() != null && !saw.contains(ejb.getClassLoader())) {
            addTests(findMarkers(ejb.getClassLoader()), findClassMarkers(ejb.getClassLoader()), ejb.getFinder(), testClasses);
            saw.add(ejb.getClassLoader());
        }
    }
    for (final ConnectorModule connector : module.getConnectorModules()) {
        if (connector.getClassLoader() != null && !saw.contains(connector.getClassLoader())) {
            addTests(findMarkers(connector.getClassLoader()), findClassMarkers(connector.getClassLoader()), connector.getFinder(), testClasses);
            saw.add(connector.getClassLoader());
        }
    }
    // keep it since CukeSpace doesn't rely on JUnit or TestNG @Test so it stays mandatory
    final File file = module.getFile();
    final String line = findTestName(file, module.getClassLoader());
    if (line != null) {
        String name;
        final int endIndex = line.indexOf('#');
        if (endIndex > 0) {
            name = line.substring(0, endIndex);
            if (file != null && !file.getName().equals(line.substring(endIndex + 1, line.length()))) {
                name = null;
            }
        } else {
            name = line;
        }
        if (name != null) {
            boolean found = false;
            for (final WebModule web : module.getWebModules()) {
                try {
                    testClasses.add(web.getClassLoader().loadClass(name));
                    found = true;
                    break;
                } catch (final Throwable e) {
                // no-op
                }
            }
            if (!found) {
                try {
                    testClasses.add(module.getClassLoader().loadClass(name));
                } catch (final Throwable e) {
                // no-op
                }
            }
        }
    }
    final Iterator<Class<?>> it = testClasses.iterator();
    while (it.hasNext()) {
        try {
            // call some reflection methods to make it fail if some dep are missing...
            Class<?> current = it.next();
            if (!AnnotationDeployer.isInstantiable(current)) {
                it.remove();
                continue;
            }
            while (current != null) {
                current.getDeclaredFields();
                current.getDeclaredMethods();
                current.getCanonicalName();
                current = current.getSuperclass();
            // TODO: more validations
            }
        } catch (final NoClassDefFoundError ncdfe) {
            it.remove();
        }
    }
    for (final Class<?> test : testClasses) {
        final EjbJar ejbJar = new EjbJar();
        final OpenejbJar openejbJar = new OpenejbJar();
        final String name = test.getName();
        final String ejbName = module.getModuleId() + "_" + name;
        final ManagedBean bean = ejbJar.addEnterpriseBean(new ManagedBean(ejbName, name, true));
        bean.localBean();
        bean.setTransactionType(TransactionType.BEAN);
        final EjbDeployment ejbDeployment = openejbJar.addEjbDeployment(bean);
        ejbDeployment.setDeploymentId(ejbName);
        final EjbModule ejbModule = new EjbModule(ejbJar, openejbJar);
        ejbModule.setClassLoader(test.getClassLoader());
        final WebModule webModule = webTestClasses.get(test);
        if (webModule != null) {
            ejbModule.setWebapp(true);
            ejbModule.getProperties().put("openejb.ejbmodule.webappId", webModule.getModuleId());
        }
        ejbModule.getProperties().put("openejb.ejbmodule.MergeWebappJndiContext", "true");
        module.getEjbModules().add(ejbModule);
    }
    return module;
}
Also used : HashMap(java.util.HashMap) EjbModule(org.apache.openejb.config.EjbModule) WebModule(org.apache.openejb.config.WebModule) ConnectorModule(org.apache.openejb.config.ConnectorModule) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) ManagedBean(org.apache.openejb.jee.ManagedBean) File(java.io.File) HashSet(java.util.HashSet) EjbJar(org.apache.openejb.jee.EjbJar)

Example 2 with EjbJar$JAXB

use of org.apache.openejb.jee.EjbJar$JAXB in project tomee by apache.

the class CdiDecoratorMultipleDelegateCallsTest method classes.

@Module
@Classes({ ServiceImpl.class })
public EjbModule classes() {
    final Beans beans = new Beans();
    beans.addDecorator(ServiceDecorator.class);
    final EjbModule jar = new EjbModule(new EjbJar());
    jar.setBeans(beans);
    return jar;
}
Also used : Beans(org.apache.openejb.jee.Beans) EjbModule(org.apache.openejb.config.EjbModule) EjbJar(org.apache.openejb.jee.EjbJar) EjbModule(org.apache.openejb.config.EjbModule) Module(org.apache.openejb.testing.Module) Classes(org.apache.openejb.testing.Classes)

Example 3 with EjbJar$JAXB

use of org.apache.openejb.jee.EjbJar$JAXB 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 4 with EjbJar$JAXB

use of org.apache.openejb.jee.EjbJar$JAXB in project tomee by apache.

the class ActivationConfigPropertyOverrideTest method testEjbNameOverrideSystem.

public void testEjbNameOverrideSystem() throws Exception {
    SystemInstance.reset();
    final Properties properties = SystemInstance.get().getProperties();
    properties.setProperty("Orange.activation.maxSessions", "20");
    properties.setProperty("Orange.activation.maxMessagesPerSessions", "100");
    properties.setProperty("Orange.activation.destinationType", "javax.jms.Queue");
    properties.setProperty("Orange.activation.destination", "OVERRIDDEN.QUEUE");
    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    final EjbJar ejbJar = new EjbJar();
    // just to make sure class name is not used
    ejbJar.addEnterpriseBean(new MessageDrivenBean("Yellow", Orange.class));
    // just to make sure class name is not used
    ejbJar.addEnterpriseBean(new MessageDrivenBean("Orange", Yellow.class));
    final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
    assertEquals(2, ejbJarInfo.enterpriseBeans.size());
    final MessageDrivenBeanInfo orange = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(0);
    final MessageDrivenBeanInfo yellow = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(1);
    assertEquals("7", orange.activationProperties.get("maxSessions"));
    assertEquals("4", orange.activationProperties.get("maxMessagesPerSessions"));
    assertEquals("javax.jms.Queue", orange.activationProperties.get("destinationType"));
    assertEquals("ORANGE.QUEUE", orange.activationProperties.get("destination"));
    assertEquals("20", yellow.activationProperties.get("maxSessions"));
    assertEquals("100", yellow.activationProperties.get("maxMessagesPerSessions"));
    assertEquals("javax.jms.Queue", yellow.activationProperties.get("destinationType"));
    assertEquals("OVERRIDDEN.QUEUE", yellow.activationProperties.get("destination"));
}
Also used : TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) MessageDrivenBeanInfo(org.apache.openejb.assembler.classic.MessageDrivenBeanInfo) Assembler(org.apache.openejb.assembler.classic.Assembler) Properties(java.util.Properties) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 5 with EjbJar$JAXB

use of org.apache.openejb.jee.EjbJar$JAXB in project tomee by apache.

the class ActivationConfigPropertyOverrideTest method testEjbNameOverrideOpenejbJar.

public void testEjbNameOverrideOpenejbJar() throws Exception {
    SystemInstance.reset();
    final Assembler assembler = new Assembler();
    final ConfigurationFactory config = new ConfigurationFactory();
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
    {
        final EjbJar ejbJar = new EjbJar();
        ejbJar.addEnterpriseBean(new MessageDrivenBean(Orange.class));
        ejbJar.addEnterpriseBean(new MessageDrivenBean(Yellow.class));
        final OpenejbJar openejbJar = new OpenejbJar();
        final Properties properties = openejbJar.getProperties();
        properties.setProperty("mdb.activation.maxSessions", "20");
        properties.setProperty("mdb.activation.maxMessagesPerSessions", "100");
        properties.setProperty("mdb.activation.destinationType", "javax.jms.Queue");
        properties.setProperty("mdb.activation.destination", "OVERRIDDEN.QUEUE");
        final EjbModule ejbModule = new EjbModule(ejbJar, openejbJar);
        final EjbJarInfo ejbJarInfo = config.configureApplication(ejbModule);
        assertEquals(2, ejbJarInfo.enterpriseBeans.size());
        final MessageDrivenBeanInfo orange = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(0);
        final MessageDrivenBeanInfo yellow = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(1);
        assertEquals("20", orange.activationProperties.get("maxSessions"));
        assertEquals("100", orange.activationProperties.get("maxMessagesPerSessions"));
        assertEquals("javax.jms.Queue", orange.activationProperties.get("destinationType"));
        assertEquals("OVERRIDDEN.QUEUE", orange.activationProperties.get("destination"));
        assertEquals("20", yellow.activationProperties.get("maxSessions"));
        assertEquals("100", yellow.activationProperties.get("maxMessagesPerSessions"));
        assertEquals("javax.jms.Queue", yellow.activationProperties.get("destinationType"));
        assertEquals("OVERRIDDEN.QUEUE", yellow.activationProperties.get("destination"));
    }
    // Verify the openejb-jar level overrides do not affect other apps
    {
        final EjbJar ejbJar = new EjbJar();
        ejbJar.addEnterpriseBean(new MessageDrivenBean(Orange.class));
        ejbJar.addEnterpriseBean(new MessageDrivenBean(Yellow.class));
        final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
        assertEquals(2, ejbJarInfo.enterpriseBeans.size());
        final MessageDrivenBeanInfo orange = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(0);
        final MessageDrivenBeanInfo yellow = (MessageDrivenBeanInfo) ejbJarInfo.enterpriseBeans.get(1);
        assertEquals("7", orange.activationProperties.get("maxSessions"));
        assertEquals("4", orange.activationProperties.get("maxMessagesPerSessions"));
        assertEquals("javax.jms.Queue", orange.activationProperties.get("destinationType"));
        assertEquals("ORANGE.QUEUE", orange.activationProperties.get("destination"));
        assertEquals("5", yellow.activationProperties.get("maxSessions"));
        assertEquals("10", yellow.activationProperties.get("maxMessagesPerSessions"));
        assertEquals("javax.jms.Topic", yellow.activationProperties.get("destinationType"));
        assertEquals("YELLOW.TOPIC", yellow.activationProperties.get("destination"));
    }
}
Also used : OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) MessageDrivenBean(org.apache.openejb.jee.MessageDrivenBean) MessageDrivenBeanInfo(org.apache.openejb.assembler.classic.MessageDrivenBeanInfo) Assembler(org.apache.openejb.assembler.classic.Assembler) Properties(java.util.Properties) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Aggregations

EjbJar (org.apache.openejb.jee.EjbJar)233 StatelessBean (org.apache.openejb.jee.StatelessBean)113 Assembler (org.apache.openejb.assembler.classic.Assembler)90 EjbModule (org.apache.openejb.config.EjbModule)78 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)75 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)64 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)64 Properties (java.util.Properties)48 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)47 InitialContext (javax.naming.InitialContext)42 SingletonBean (org.apache.openejb.jee.SingletonBean)42 AppModule (org.apache.openejb.config.AppModule)39 StatefulBean (org.apache.openejb.jee.StatefulBean)33 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)31 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)27 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)26 Module (org.apache.openejb.testing.Module)26 LocalInitialContextFactory (org.apache.openejb.core.LocalInitialContextFactory)25 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)23 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)19