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