use of org.glassfish.distributions.test.ejb.SampleEjb in project Payara by payara.
the class EmbeddedTest method testEjb.
@Test
public void testEjb() throws GlassFishException {
Deployer deployer = glassfish.getDeployer();
URL source = SampleEjb.class.getClassLoader().getResource("org/glassfish/distributions/test/ejb/SampleEjb.class");
String p = source.getPath().substring(0, source.getPath().length() - "org/glassfish/distributions/test/ejb/SimpleEjb.class".length());
String appName = deployer.deploy(new File(p).toURI(), "--name=sample");
Assert.assertNotNull("AppName is null from deployer of type " + deployer.getClass().getName(), appName);
// ok now let's look up the EJB...
try {
InitialContext ic = new InitialContext();
SampleEjb ejb = (SampleEjb) ic.lookup("java:global/sample/SampleEjb");
if (ejb != null) {
try {
System.out.println(ejb.saySomething());
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (NamingException e) {
// To change body of catch statement use File | Settings | File Templates.
e.printStackTrace();
}
deployer.undeploy(appName);
System.out.println("Done with EJB");
}
use of org.glassfish.distributions.test.ejb.SampleEjb in project Payara by payara.
the class UnitTest method test.
@Test
public void test() {
// Calculate test-classes location
String cname = "org/glassfish/distributions/test/UnitTest.class";
URL source = UnitTest.class.getClassLoader().getResource(cname);
String dir = source.getPath().substring(0, source.getPath().length() - cname.length());
Map<String, File> p = new HashMap<String, File>();
p.put(EJBContainer.MODULES, new File(dir));
EJBContainer c = EJBContainer.createEJBContainer(p);
// ok now let's look up the EJB...
Context ic = c.getContext();
try {
System.out.println("Looking up EJB...");
SampleEjb ejb = (SampleEjb) ic.lookup("java:global/classes/SampleEjb");
if (ejb != null) {
System.out.println("Invoking EJB...");
System.out.println(ejb.saySomething());
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Done calling EJB");
try {
System.out.println("Creating another container without closing...");
EJBContainer c0 = EJBContainer.createEJBContainer();
if (c0 != null)
throw new RuntimeException("Create another container");
} catch (EJBException e) {
System.out.println("Caught expected: " + e.getMessage());
}
c.close();
System.out.println("Creating container after closing the previous...");
c = EJBContainer.createEJBContainer(p);
c.close();
}
Aggregations