use of org.apache.openejb.config.EjbModule in project tomee by apache.
the class ResourcesJsonTest method setUp.
@Before
public void setUp() throws OpenEJBException, NamingException, IOException {
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
final AppModule app = new AppModule(ResourcesJsonTest.class.getClassLoader(), ResourcesJsonTest.class.getSimpleName());
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new SingletonBean(ConfiguredThroughJSonBean.class));
app.getEjbModules().add(new EjbModule(ejbJar));
app.getEjbModules().iterator().next().getAltDDs().put("resources.json", getClass().getClassLoader().getResource("appresource.resources.json"));
assembler.createApplication(config.configureApplication(app));
final Properties properties = new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
properties.setProperty("openejb.embedded.initialcontext.close", "destroy");
// some hack to be sure to call destroy()
context = new InitialContext(properties);
bean = (ConfiguredThroughJSonBean) context.lookup("ConfiguredThroughJSonBeanLocalBean");
}
use of org.apache.openejb.config.EjbModule in project tomee by apache.
the class CheckPersistenceContextUsageTest method noUnitName.
@Keys({ @Key(value = "persistenceContextRef.noUnitName"), @Key(value = "persistenceContextRef.noMatches") })
public AppModule noUnitName() {
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean(FooStatelessOne.class));
final EjbModule ejbModule = new EjbModule(ejbJar);
final AppModule appModule = new AppModule(ejbModule.getClassLoader(), ejbModule.getJarLocation());
appModule.getEjbModules().add(ejbModule);
final PersistenceUnit pu = new PersistenceUnit("fooUnit");
final PersistenceUnit pu1 = new PersistenceUnit("fooUnit1");
final PersistenceUnit pu2 = new PersistenceUnit("fooUnit");
final org.apache.openejb.jee.jpa.unit.Persistence p = new org.apache.openejb.jee.jpa.unit.Persistence(pu, pu1, pu2);
final PersistenceModule pm = new PersistenceModule("foo", p);
appModule.addPersistenceModule(pm);
return appModule;
}
use of org.apache.openejb.config.EjbModule in project tomee by apache.
the class CheckPersistenceContextUsageTest method vagueMatches.
@Keys({ @Key(value = "persistenceContextRef.vagueMatches") })
public AppModule vagueMatches() {
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean(FooStatelessTwo.class));
final EjbModule ejbModule = new EjbModule(ejbJar);
final AppModule appModule = new AppModule(ejbModule.getClassLoader(), ejbModule.getJarLocation());
appModule.getEjbModules().add(ejbModule);
final PersistenceUnit pu = new PersistenceUnit("fooUnit");
final org.apache.openejb.jee.jpa.unit.Persistence p = new org.apache.openejb.jee.jpa.unit.Persistence(pu);
final PersistenceModule pm = new PersistenceModule("foo", p);
appModule.getPersistenceModules().add(pm);
final PersistenceUnit pu1 = new PersistenceUnit("fooUnit");
final org.apache.openejb.jee.jpa.unit.Persistence p1 = new org.apache.openejb.jee.jpa.unit.Persistence(pu1);
final PersistenceModule pm1 = new PersistenceModule("foo1", p1);
appModule.addPersistenceModule(pm1);
return appModule;
}
use of org.apache.openejb.config.EjbModule in project tomee by apache.
the class CheckPersistenceUnitUsageTest method vagueMatches.
@Keys({ @Key(value = "persistenceUnitRef.vagueMatches") })
public AppModule vagueMatches() {
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean(FooStatelessTwo.class));
final EjbModule ejbModule = new EjbModule(ejbJar);
final AppModule appModule = new AppModule(ejbModule.getClassLoader(), ejbModule.getJarLocation());
appModule.getEjbModules().add(ejbModule);
final PersistenceUnit pu = new PersistenceUnit("fooUnit");
final org.apache.openejb.jee.jpa.unit.Persistence p = new org.apache.openejb.jee.jpa.unit.Persistence(pu);
final PersistenceModule pm = new PersistenceModule("foo", p);
appModule.getPersistenceModules().add(pm);
final PersistenceUnit pu1 = new PersistenceUnit("fooUnit");
final org.apache.openejb.jee.jpa.unit.Persistence p1 = new org.apache.openejb.jee.jpa.unit.Persistence(pu1);
final PersistenceModule pm1 = new PersistenceModule("foo1", p1);
appModule.addPersistenceModule(pm1);
return appModule;
}
use of org.apache.openejb.config.EjbModule in project tomee by apache.
the class InvokeMethod method evaluate.
@Override
public void evaluate() throws Throwable {
final Map<Integer, List<String>> expectedKeys = validateKeys();
setUp();
final Object obj = testMethod.invokeExplosively(target);
final String outputDescriptors = SystemInstance.get().getProperty(OutputGeneratedDescriptors.OUTPUT_DESCRIPTORS, "false");
try {
SystemInstance.get().setProperty(OutputGeneratedDescriptors.OUTPUT_DESCRIPTORS, "false");
ValidationContext vc = null;
if (obj instanceof EjbJar) {
final EjbJar ejbJar = (EjbJar) obj;
final EjbModule ejbModule = new EjbModule(ejbJar);
vc = ejbModule.getValidation();
assembler.createApplication(config.configureApplication(ejbModule));
} else if (obj instanceof EjbModule) {
final EjbModule ejbModule = (EjbModule) obj;
vc = ejbModule.getValidation();
assembler.createApplication(config.configureApplication(ejbModule));
} else if (obj instanceof AppModule) {
final AppModule appModule = (AppModule) obj;
vc = appModule.getValidation();
assembler.createApplication(config.configureApplication(appModule));
}
if (!isEmpty(expectedKeys)) {
if (vc != null && expectedKeys.get(KeyType.FAILURE).isEmpty() && expectedKeys.get(KeyType.ERROR).isEmpty()) {
if (!expectedKeys.get(KeyType.WARNING).isEmpty()) {
assertWarnings(expectedKeys.get(KeyType.WARNING), new ValidationFailedException("", vc));
}
} else {
fail("A ValidationFailedException should have been thrown");
}
}
} catch (final ValidationFailedException vfe) {
if (!isEmpty(expectedKeys)) {
if (!expectedKeys.get(KeyType.FAILURE).isEmpty()) {
assertFailures(expectedKeys.get(KeyType.FAILURE), vfe);
}
if (!expectedKeys.get(KeyType.WARNING).isEmpty()) {
assertWarnings(expectedKeys.get(KeyType.WARNING), vfe);
}
if (!expectedKeys.get(KeyType.ERROR).isEmpty()) {
assertErrors(expectedKeys.get(KeyType.ERROR), vfe);
}
} else {
for (final ValidationFailure failure : vfe.getFailures()) {
System.out.println("failure = " + failure.getMessageKey());
}
fail("There should be no validation failures");
}
} finally {
SystemInstance.get().setProperty(OutputGeneratedDescriptors.OUTPUT_DESCRIPTORS, outputDescriptors);
}
tearDown();
}
Aggregations