L
lolveley
hi there!
I created a test project : a "enterprise application" containing an "EJB
module".In this module, there is a bean, and an interface ("remote"),
and a JUnit test class. this test class tries to access to the bean
method using JNDI, and this call fails.
here are the main files :
*****************************
plus_2bBean.java:
package moi.un;
import javax.ejb.Stateless;
/**
*
* @author oliviersaint-eve
*/
@Stateless
public class plus_2bBean implements plus_2bRemote {
public int plus(int x, int y) {
return x+y;
}
// Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Business Method" or "Web Service > Add
Operation")
}
*************************
plus_2bBeanTest.java:
package moi.un;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author oliviersaint-eve
*/
public class plus_2bBeanTest {
public plus_2bBeanTest() {
}
@BeforeClass
public static void setUpClass() throws Exception {
}
@AfterClass
public static void tearDownClass() throws Exception {
}
/**
* Test of plus method, of class plus_2bBean.
*/
@Test
public void testPlus() {
System.out.println("plus");
int x = 1;
int y = 2;
plus_2bBean instance = new plus_2bBean();
int expResult = 3;
int result = instance.plus(x, y);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default
call to fail.
try {
Properties props = new Properties();
props.setProperty("java.naming.factory.initial",
"com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("java.naming.factory.url.pkgs",
"com.sun.enterprise.naming");
props.setProperty("java.naming.factory.state",
"com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
// optional. Defaults to 3700. Only needed if target orb port is not 3700.
props.setProperty("org.omg.CORBA.ORBInitialPort", "3721");
props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
InitialContext ctx = new InitialContext(props);
Object ref = ctx.lookup("moi.un.plus_2bRemote");
moi.un.plus_2bRemote calc = (moi.un.plus_2bRemote)
PortableRemoteObject.narrow(ref, moi.un.plus_2bRemote.class);
x = 3;
y = 5;
int res = calc.plus(x, y);
assertTrue(res == 8);
} catch (NamingException ex) {
fail(ex.getMessage());
}
}
}
******************************
thank you for any help,
lolveley.
I created a test project : a "enterprise application" containing an "EJB
module".In this module, there is a bean, and an interface ("remote"),
and a JUnit test class. this test class tries to access to the bean
method using JNDI, and this call fails.
here are the main files :
*****************************
plus_2bBean.java:
package moi.un;
import javax.ejb.Stateless;
/**
*
* @author oliviersaint-eve
*/
@Stateless
public class plus_2bBean implements plus_2bRemote {
public int plus(int x, int y) {
return x+y;
}
// Add business logic below. (Right-click in editor and choose
// "Insert Code > Add Business Method" or "Web Service > Add
Operation")
}
*************************
plus_2bBeanTest.java:
package moi.un;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author oliviersaint-eve
*/
public class plus_2bBeanTest {
public plus_2bBeanTest() {
}
@BeforeClass
public static void setUpClass() throws Exception {
}
@AfterClass
public static void tearDownClass() throws Exception {
}
/**
* Test of plus method, of class plus_2bBean.
*/
@Test
public void testPlus() {
System.out.println("plus");
int x = 1;
int y = 2;
plus_2bBean instance = new plus_2bBean();
int expResult = 3;
int result = instance.plus(x, y);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default
call to fail.
try {
Properties props = new Properties();
props.setProperty("java.naming.factory.initial",
"com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("java.naming.factory.url.pkgs",
"com.sun.enterprise.naming");
props.setProperty("java.naming.factory.state",
"com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
// optional. Defaults to 3700. Only needed if target orb port is not 3700.
props.setProperty("org.omg.CORBA.ORBInitialPort", "3721");
props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
InitialContext ctx = new InitialContext(props);
Object ref = ctx.lookup("moi.un.plus_2bRemote");
moi.un.plus_2bRemote calc = (moi.un.plus_2bRemote)
PortableRemoteObject.narrow(ref, moi.un.plus_2bRemote.class);
x = 3;
y = 5;
int res = calc.plus(x, y);
assertTrue(res == 8);
} catch (NamingException ex) {
fail(ex.getMessage());
}
}
}
******************************
thank you for any help,
lolveley.