use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.
the class TransactionAttributesTest method test.
public void test() throws Exception {
final Assembler assembler = new Assembler();
final ConfigurationFactory config = new ConfigurationFactory();
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean(Color.class));
ejbJar.addEnterpriseBean(new StatelessBean(Red.class));
ejbJar.addEnterpriseBean(new StatelessBean(Crimson.class));
ejbJar.addEnterpriseBean(new StatelessBean(Scarlet.class));
final List<ContainerTransaction> declared = ejbJar.getAssemblyDescriptor().getContainerTransaction();
declared.add(new ContainerTransaction(TransAttribute.REQUIRED, "*", "*", "*"));
declared.add(new ContainerTransaction(TransAttribute.SUPPORTS, "*", "Crimson", "*"));
declared.add(new ContainerTransaction(TransAttribute.SUPPORTS, Color.class.getName(), "Scarlet", "*"));
declared.add(new ContainerTransaction(TransAttribute.NEVER, Red.class.getName(), "Scarlet", "red"));
declared.add(new ContainerTransaction(TransAttribute.REQUIRED, "Scarlet", Scarlet.class.getMethod("scarlet")));
ejbJar.getAssemblyDescriptor().addInterceptorBinding(new InterceptorBinding("*", AttributeInterceptor.class.getName()));
final EjbJarInfo ejbJarInfo = config.configureApplication(ejbJar);
assembler.createApplication(ejbJarInfo);
loadAttributes(ejbJarInfo, "Color");
assertAttribute("Never", Color.class.getMethod("color"));
assertAttribute("RequiresNew", Color.class.getMethod("color", Object.class));
assertAttribute("Mandatory", Color.class.getMethod("color", String.class));
assertAttribute("Mandatory", Color.class.getMethod("color", Boolean.class));
assertAttribute("Mandatory", Color.class.getMethod("color", Integer.class));
loadAttributes(ejbJarInfo, "Red");
assertAttribute("Never", Red.class.getMethod("color"));
assertAttribute("Required", Red.class.getMethod("color", Object.class));
assertAttribute("Mandatory", Red.class.getMethod("color", String.class));
assertAttribute("Mandatory", Red.class.getMethod("color", Boolean.class));
assertAttribute("Mandatory", Red.class.getMethod("color", Integer.class));
assertAttribute("RequiresNew", Red.class.getMethod("red"));
assertAttribute("Required", Red.class.getMethod("red", Object.class));
assertAttribute("Required", Red.class.getMethod("red", String.class));
loadAttributes(ejbJarInfo, "Crimson");
assertAttribute("Supports", Crimson.class.getMethod("color"));
assertAttribute("Supports", Crimson.class.getMethod("color", Object.class));
assertAttribute("Supports", Crimson.class.getMethod("color", String.class));
assertAttribute("Supports", Crimson.class.getMethod("color", Boolean.class));
assertAttribute("Supports", Crimson.class.getMethod("color", Integer.class));
assertAttribute("RequiresNew", Crimson.class.getMethod("red"));
assertAttribute("Supports", Crimson.class.getMethod("red", Object.class));
assertAttribute("Supports", Crimson.class.getMethod("red", String.class));
assertAttribute("RequiresNew", Crimson.class.getMethod("crimson"));
assertAttribute("Supports", Crimson.class.getMethod("crimson", String.class));
loadAttributes(ejbJarInfo, "Scarlet");
assertAttribute("Never", Scarlet.class.getMethod("color"));
assertAttribute("Required", Scarlet.class.getMethod("color", Object.class));
assertAttribute("Supports", Scarlet.class.getMethod("color", String.class));
assertAttribute("Supports", Scarlet.class.getMethod("color", Boolean.class));
assertAttribute("Supports", Scarlet.class.getMethod("color", Integer.class));
assertAttribute("RequiresNew", Scarlet.class.getMethod("red"));
assertAttribute("Never", Scarlet.class.getMethod("red", Object.class));
assertAttribute("Never", Scarlet.class.getMethod("red", String.class));
assertAttribute("Required", Scarlet.class.getMethod("scarlet"));
assertAttribute("NotSupported", Scarlet.class.getMethod("scarlet", String.class));
}
use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.
the class SimpleCdiTest method setUp.
@Before
public void setUp() throws Exception {
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean(Echo.class));
final Beans beans = new Beans();
beans.addInterceptor(EchoInterceptor.class);
beans.addDecorator(EchoDecorator.class);
beans.addManagedClass(SimpleModel.class);
beans.addManagedClass(ProducesEjbInjector.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.config.ConfigurationFactory in project tomee by apache.
the class DeploymentContextOptionsTest method testAllLevels.
public void testAllLevels() throws Exception {
SystemInstance.get().setProperty("color", "orangeSystem");
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 StatelessBean statelessBean = ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
{
// Set at BeanContext level
final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
final EjbDeployment deployment = openejbJar.addEjbDeployment(statelessBean);
deployment.getProperties().put("color", "orangeBean");
}
{
// Set at ModuleContext level
final OpenejbJar openejbJar = ejbModule.getOpenejbJar();
openejbJar.getProperties().put("color", "orangeModule");
}
final AppModule appModule = new AppModule(ejbModule);
{
// Set at AppContext level
appModule.getProperties().put("color", "orangeApp");
}
assembler.createApplication(config.configureApplication(appModule));
}
final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
final BeanContext beanContext = containerSystem.getBeanContext("WidgetBean");
assertOption(beanContext.getOptions(), "color", "orangeBean");
assertOption(beanContext.getModuleContext().getOptions(), "color", "orangeModule");
assertOption(beanContext.getModuleContext().getAppContext().getOptions(), "color", "orangeApp");
assertOption(SystemInstance.get().getOptions(), "color", "orangeSystem");
}
use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.
the class DeploymentContextOptionsTest method testSystemInstanceOptions.
public void testSystemInstanceOptions() throws Exception {
SystemInstance.get().setProperty("color", "orange");
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();
ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
final AppModule appModule = new AppModule(ejbModule);
assembler.createApplication(config.configureApplication(appModule));
}
final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
final BeanContext beanContext = containerSystem.getBeanContext("WidgetBean");
assertOption(beanContext.getOptions(), "color", "orange");
assertOption(beanContext.getModuleContext().getOptions(), "color", "orange");
assertOption(beanContext.getModuleContext().getAppContext().getOptions(), "color", "orange");
assertOption(SystemInstance.get().getOptions(), "color", "orange");
}
use of org.apache.openejb.config.ConfigurationFactory in project tomee by apache.
the class DeploymentContextPropertiesTest method testAppContextProperties.
public void testAppContextProperties() 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();
ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
final AppModule appModule = new AppModule(ejbModule);
appModule.getProperties().setProperty("color", "orange");
final AppInfo appInfo = config.configureApplication(appModule);
assertProperty(appInfo.properties, "color", "orange");
assembler.createApplication(appInfo);
}
final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
final BeanContext beanContext = containerSystem.getBeanContext("WidgetBean");
final Properties properties = beanContext.getModuleContext().getAppContext().getProperties();
assertProperty(properties, "color", "orange");
}
Aggregations