Hi all,
We are using IBM websphere studio ver 5.0 for our development.
We plan to use
Junit for our
testing.
In my testcase while trying to lookup bean from testcase, I am getting this exception. The code and exception as follows,
*************** CODE ***************
package ejbTestCase;
import junit.framework.TestCase;
import java.util.*;
import junit.framework.*;
import junit.extensions.*;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import com.imantras.ejbJunit.*;
/**
* @author Krishna
*
* To change this generated comment edit the template variable "typecomment":
* Window>Preferences>
Java>Templates.
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
public class EJBTestCase extends TestCase {
protected StatelessFundmanagerEJBHome statelessFundmanagerEJBHome;
/**
* Constructor for EJBTestCase.
* @param arg0
*/
public EJBTestCase(
String name) {
super(name);
}
public static void main(String[] args) {
junit.textui.TestRunner.run(EJBTestCase.class);
}
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new EJBTestCase("testaddFunds"));
return suite;
}
/**
* @see TestCase#setUp()
*/
protected void setUp() {
System.out.println("Entering in to ICF");
java.util.Hashtable properties = new java.util.Hashtable(2);
properties.put(javax.naming.Context.PROVIDER_URL, "iiop:///");
properties.put(
javax.naming.Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");
System.out.println("Get away from ICF");
try
{
System.out.println("Entering in to lookup");
javax.naming.InitialContext ctx =
new javax.naming.InitialContext(properties);
System.out.println("Entering in to lookup**************222222222");
Object home = ctx.lookup("ejb/com/imantras/ejbJunit/StatelessFundmanagerEJBHome");
System.out.println("Entering in to lookup***************3333333333");
statelessFundmanagerEJBHome = null;
statelessFundmanagerEJBHome =(StatelessFundmanagerEJBHome) PortableRemoteObject.narrow(home,StatelessFundmanagerEJBHome.class);
System.out.println("statelessFundManagerEJBHome" + statelessFundmanagerEJBHome);
}
catch (Exception e)
{
System.out.println(e);
}
}
public void testaddFunds()
{
double amount=0;
double balance=100;
try{
StatelessFundmanagerEJB statelessFundmanagerEJB= statelessFundmanagerEJBHome.create();
double balance1 = statelessFundmanagerEJB.addFunds(100,100);
double balance2 = statelessFundmanagerEJB.withdrawFunds(100,100);
assertTrue(balance1==balance2);
System.out.println("Balance == " +balance);
System.out.println("Balance 2 == " +balance2);
}
catch(Exception e)
{
System.out.println(e);
}
}
/**
* @see TestCase#tearDown()
*/
protected void tearDown() {
statelessFundmanagerEJBHome = null;
}
}
******************* EXCEPTION ***************
"javax.naming.ConfigurationException: The property com.ibm.ws.naming.wsn.factory.initial is not set. The most likely cause is that the jar which contains the file com/ibm/websphere/naming/jndiprovider.properties cannot be found by the class loader.
java.lang.NullPointerException"
Even I tried by placing my test case in both
ejb jar and web war with the enterprise project, still I use to get the same exception
Can you give solution for this.
Regards,
Krishnaraj.M
iMantras India pvt Limited
Chennai -41
Ph.No : 044 - 52125245
krishnaraj@imantras.com