Search in sources :

Example 46 with EjbModule

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");
}
Also used : AppModule(org.apache.openejb.config.AppModule) EjbModule(org.apache.openejb.config.EjbModule) Properties(java.util.Properties) LocalInitialContextFactory(org.apache.openejb.core.LocalInitialContextFactory) InitialContext(javax.naming.InitialContext) SingletonBean(org.apache.openejb.jee.SingletonBean) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbJar(org.apache.openejb.jee.EjbJar) Before(org.junit.Before)

Example 47 with EjbModule

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;
}
Also used : AppModule(org.apache.openejb.config.AppModule) EjbModule(org.apache.openejb.config.EjbModule) PersistenceModule(org.apache.openejb.config.PersistenceModule) PersistenceUnit(org.apache.openejb.jee.jpa.unit.PersistenceUnit) StatelessBean(org.apache.openejb.jee.StatelessBean) EjbJar(org.apache.openejb.jee.EjbJar)

Example 48 with EjbModule

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;
}
Also used : AppModule(org.apache.openejb.config.AppModule) EjbModule(org.apache.openejb.config.EjbModule) PersistenceModule(org.apache.openejb.config.PersistenceModule) PersistenceUnit(org.apache.openejb.jee.jpa.unit.PersistenceUnit) StatelessBean(org.apache.openejb.jee.StatelessBean) EjbJar(org.apache.openejb.jee.EjbJar)

Example 49 with EjbModule

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;
}
Also used : AppModule(org.apache.openejb.config.AppModule) EjbModule(org.apache.openejb.config.EjbModule) PersistenceModule(org.apache.openejb.config.PersistenceModule) PersistenceUnit(org.apache.openejb.jee.jpa.unit.PersistenceUnit) StatelessBean(org.apache.openejb.jee.StatelessBean) EjbJar(org.apache.openejb.jee.EjbJar)

Example 50 with EjbModule

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();
}
Also used : AppModule(org.apache.openejb.config.AppModule) ValidationFailedException(org.apache.openejb.config.ValidationFailedException) EjbModule(org.apache.openejb.config.EjbModule) ArrayList(java.util.ArrayList) List(java.util.List) ValidationContext(org.apache.openejb.config.ValidationContext) EjbJar(org.apache.openejb.jee.EjbJar) ValidationFailure(org.apache.openejb.config.ValidationFailure)

Aggregations

EjbModule (org.apache.openejb.config.EjbModule)91 EjbJar (org.apache.openejb.jee.EjbJar)81 AppModule (org.apache.openejb.config.AppModule)41 StatelessBean (org.apache.openejb.jee.StatelessBean)37 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)30 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)29 Assembler (org.apache.openejb.assembler.classic.Assembler)27 Properties (java.util.Properties)24 SingletonBean (org.apache.openejb.jee.SingletonBean)21 InitialContext (javax.naming.InitialContext)20 Module (org.apache.openejb.testing.Module)18 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)15 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)13 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)13 Beans (org.apache.openejb.jee.Beans)12 AppInfo (org.apache.openejb.assembler.classic.AppInfo)11 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)10 ContainerSystem (org.apache.openejb.spi.ContainerSystem)10 ArrayList (java.util.ArrayList)9 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)9