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;
}
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;
}
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);
}
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"));
}
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"));
}
}
Aggregations