Search in sources :

Example 56 with EjbJar$JAXB

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

the class LocalClientNoInjectionTest method setUp.

public void setUp() throws OpenEJBException, NamingException, IOException {
    // avoid linkage error on mac, only used for tests so don't need to add it in Core
    JULLoggerFactory.class.getName();
    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(this.getClass().getClassLoader(), "test-app");
    final Persistence persistence = new Persistence(new org.apache.openejb.jee.jpa.unit.PersistenceUnit("foo-unit"));
    app.addPersistenceModule(new PersistenceModule("root", persistence));
    final EjbJar ejbJar = new EjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean(SuperBean.class));
    app.getEjbModules().add(new EjbModule(ejbJar));
    final ClientModule clientModule = new ClientModule(null, app.getClassLoader(), app.getJarLocation(), null, null);
    clientModule.getLocalClients().add(this.getClass().getName());
    app.getClientModules().add(clientModule);
    assembler.createApplication(config.configureApplication(app));
}
Also used : Persistence(org.apache.openejb.jee.jpa.unit.Persistence) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 57 with EjbJar$JAXB

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

the class MappedNameTest method test.

public void test() throws Exception {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
    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(GreenBean.class));
    ejbJar.addEnterpriseBean(new StatelessBean(RedBean.class));
    final EjbModule ejbModule = new EjbModule(ejbJar, new OpenejbJar());
    ejbModule.getOpenejbJar().addEjbDeployment(new EjbDeployment(null, "foo/bar/baz/Green", "GreenBean"));
    ejbModule.getOpenejbJar().addEjbDeployment(new EjbDeployment(null, "foo/bar/baz/Red", "RedBean"));
    final EjbJarInfo info = config.configureApplication(ejbModule);
    assembler.createApplication(info);
    final InitialContext initialContext = new InitialContext();
    final Color green = (Color) initialContext.lookup("foo/bar/baz/GreenLocal");
    final Color red = (Color) initialContext.lookup("foo/bar/baz/RedLocal");
    red.test();
}
Also used : LocalInitialContextFactory(org.apache.openejb.core.LocalInitialContextFactory) InitialContext(javax.naming.InitialContext) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) StatelessBean(org.apache.openejb.jee.StatelessBean) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) EjbJar(org.apache.openejb.jee.EjbJar)

Example 58 with EjbJar$JAXB

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

the class OutputGeneratedDescriptorsTest method testOutputDescriptor.

@Test
public void testOutputDescriptor() throws Exception {
    final OutputGeneratedDescriptors dynamicDeployer = new OutputGeneratedDescriptors();
    final EjbJar ejbJar = new EjbJar();
    final StatelessBean redBean = new StatelessBean();
    redBean.setEjbClass("com.foo.Red");
    redBean.setEjbName("Red");
    redBean.setRemote("com.foo.Color");
    final ManagedBean orangeBean = new ManagedBean("Orange", "com.foo.Orange");
    final StatefulBean yellowBean = new StatefulBean();
    yellowBean.setEjbClass("com.foo.Yellow");
    yellowBean.setEjbName("Yellow");
    yellowBean.setRemote("com.foo.Color");
    final SingletonBean greenBean = new SingletonBean();
    greenBean.setEjbClass("com.foo.Green");
    greenBean.setEjbName("Green");
    greenBean.setRemote("com.foo.Color");
    ejbJar.addEnterpriseBean(redBean);
    ejbJar.addEnterpriseBean(orangeBean);
    ejbJar.addEnterpriseBean(yellowBean);
    ejbJar.addEnterpriseBean(greenBean);
    final OpenejbJar openejbJar = new OpenejbJar();
    final EjbModule ejbModule = new EjbModule(ejbJar, openejbJar);
    final AppModule appModule = new AppModule(ejbModule);
    File tempFolder = File.createTempFile("tmp", "ogd");
    tempFolder.delete();
    Assert.assertTrue("unable to create temp folder", tempFolder.mkdirs());
    try {
        Properties properties = ejbModule.getOpenejbJar().getProperties();
        properties.setProperty(OutputGeneratedDescriptors.OUTPUT_DESCRIPTORS, "true");
        properties.setProperty(OutputGeneratedDescriptors.OUTPUT_DESCRIPTORS_FOLDER, tempFolder.getAbsolutePath());
        SystemInstance.get().setProperty(OutputGeneratedDescriptors.OUTPUT_DESCRIPTORS_FOLDER, tempFolder.getAbsolutePath());
        dynamicDeployer.deploy(appModule);
        boolean seenEjbJarXml = false;
        boolean seenOpenejbJarXml = false;
        File[] listFiles = tempFolder.listFiles();
        for (File file : listFiles) {
            if (file.getName().startsWith("ejb-jar-")) {
                seenEjbJarXml = true;
                assertEjbFileCorrect(file);
            }
            if (file.getName().startsWith("openejb-jar-")) {
                seenOpenejbJarXml = true;
            }
        }
        Assert.assertTrue("No ejb-jar.xml file produced", seenEjbJarXml);
        Assert.assertTrue("No openejb-jar.xml file produced", seenOpenejbJarXml);
    } finally {
        // clean up temporary folder
        Files.delete(tempFolder);
    }
}
Also used : StatefulBean(org.apache.openejb.jee.StatefulBean) Properties(java.util.Properties) SingletonBean(org.apache.openejb.jee.SingletonBean) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) StatelessBean(org.apache.openejb.jee.StatelessBean) ManagedBean(org.apache.openejb.jee.ManagedBean) File(java.io.File) EjbJar(org.apache.openejb.jee.EjbJar) Test(org.junit.Test)

Example 59 with EjbJar$JAXB

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

the class SunCmpConversionTest method convert.

private EntityMappings convert(final String ejbJarFileName, final String sunEjbJarFileName, final String sunCmpMappingsFileName, final String expectedFileName) throws Exception {
    InputStream in = getClass().getClassLoader().getResourceAsStream(ejbJarFileName);
    final EjbJar ejbJar = (EjbJar) JaxbJavaee.unmarshalJavaee(EjbJar.class, new ByteArrayInputStream(readContent(in).getBytes()));
    // create and configure the module
    final EjbModule ejbModule = new EjbModule(getClass().getClassLoader(), "TestModule", null, ejbJar, new OpenejbJar());
    final InitEjbDeployments initEjbDeployments = new InitEjbDeployments();
    initEjbDeployments.deploy(ejbModule);
    final AppModule appModule = new AppModule(getClass().getClassLoader(), "TestModule");
    appModule.getEjbModules().add(ejbModule);
    // add the altDD
    ejbModule.getAltDDs().put("sun-cmp-mappings.xml", getClass().getClassLoader().getResource(sunCmpMappingsFileName));
    ejbModule.getAltDDs().put("sun-ejb-jar.xml", getClass().getClassLoader().getResource(sunEjbJarFileName));
    // convert the cmp declarations into jpa entity declarations
    final CmpJpaConversion cmpJpaConversion = new CmpJpaConversion();
    cmpJpaConversion.deploy(appModule);
    // EntityMappings entityMappings = cmpJpaConversion.generateEntityMappings(ejbModule);
    // // load the sun-cmp-mappings.xml file
    // String sunCmpMappingsXml = readContent(getClass().getClassLoader().getResourceAsStream(sunCmpMappingsFileName));
    // SunCmpMappings sunCmpMappings = (SunCmpMappings) JaxbSun.unmarshal(SunCmpMappings.class, new ByteArrayInputStream(sunCmpMappingsXml.getBytes()));
    // fill in the jpa entity declarations with database mappings from the sun-cmp-mappings.xml file
    final SunConversion sunConversion = new SunConversion();
    // sunCmpConversion.mergeEntityMappings(ejbModule, entityMappings);
    sunConversion.deploy(appModule);
    // compare the results to the expected results
    if (expectedFileName != null) {
        in = getClass().getClassLoader().getResourceAsStream(expectedFileName);
        final String expected = readContent(in);
        // Sun doen't really support generated primary keys, so we need to add them by hand here
        final Set<String> generatedPks = new HashSet<String>(Arrays.asList("BasicCmp2", "AOBasicCmp2", "EncCmp2", "Cmp2RmiIiop"));
        final EntityMappings cmpMappings = appModule.getCmpMappings();
        for (final Entity entity : cmpMappings.getEntity()) {
            if (generatedPks.contains(entity.getName())) {
                entity.getAttributes().getId().get(0).setGeneratedValue(new GeneratedValue(GenerationType.IDENTITY));
            }
        }
        final String actual = toString(cmpMappings);
        XMLUnit.setIgnoreWhitespace(true);
        try {
            final Diff myDiff = new DetailedDiff(new Diff(expected, actual));
            assertTrue("Files are not similar " + myDiff, myDiff.similar());
        } catch (final AssertionFailedError e) {
            assertEquals(expected, actual);
        }
    }
    return appModule.getCmpMappings();
}
Also used : Entity(org.apache.openejb.jee.jpa.Entity) DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) DetailedDiff(org.custommonkey.xmlunit.DetailedDiff) Diff(org.custommonkey.xmlunit.Diff) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) GeneratedValue(org.apache.openejb.jee.jpa.GeneratedValue) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) ByteArrayInputStream(java.io.ByteArrayInputStream) EntityMappings(org.apache.openejb.jee.jpa.EntityMappings) AssertionFailedError(junit.framework.AssertionFailedError) EjbJar(org.apache.openejb.jee.EjbJar) HashSet(java.util.HashSet)

Example 60 with EjbJar$JAXB

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

the class XmlDataSourceTest method app.

@Module
public EjbJar app() {
    final EjbJar ejbJar = new EjbJar();
    final StatelessBean statelessBean = ejbJar.addEnterpriseBean(new StatelessBean(Bean.class));
    final org.apache.openejb.jee.DataSource ds = new org.apache.openejb.jee.DataSource();
    ds.setName("java:comp/env/foo");
    ds.setUrl("jdbc:hsqldb:mem:override");
    ds.setClassName("org.hsqldb.jdbcDriver");
    statelessBean.getDataSourceMap().put("foo", ds);
    return ejbJar;
}
Also used : StatelessBean(org.apache.openejb.jee.StatelessBean) EjbJar(org.apache.openejb.jee.EjbJar) StatelessBean(org.apache.openejb.jee.StatelessBean) DataSource(javax.sql.DataSource) Module(org.apache.openejb.testing.Module)

Aggregations

EjbJar (org.apache.openejb.jee.EjbJar)242 StatelessBean (org.apache.openejb.jee.StatelessBean)117 Assembler (org.apache.openejb.assembler.classic.Assembler)88 EjbModule (org.apache.openejb.config.EjbModule)81 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)76 SecurityServiceInfo (org.apache.openejb.assembler.classic.SecurityServiceInfo)60 TransactionServiceInfo (org.apache.openejb.assembler.classic.TransactionServiceInfo)60 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)50 Properties (java.util.Properties)49 InitialContext (javax.naming.InitialContext)43 SingletonBean (org.apache.openejb.jee.SingletonBean)42 AppModule (org.apache.openejb.config.AppModule)40 StatefulBean (org.apache.openejb.jee.StatefulBean)33 ProxyFactoryInfo (org.apache.openejb.assembler.classic.ProxyFactoryInfo)31 Module (org.apache.openejb.testing.Module)30 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)27 Test (org.junit.Test)26 LocalInitialContextFactory (org.apache.openejb.core.LocalInitialContextFactory)25 InitContextFactory (org.apache.openejb.core.ivm.naming.InitContextFactory)24 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)21