java ee - Remote EJB testing with JUnit and glassfish 4 -


i working on automated testing of ejb3 beans. have managed create sample application, following code:

(the test enviroment based on 4 modules: ejb client, ejb, ear - containing ejb client & ejb - , junit tester project).

interface:

package remote.test; import javax.ejb.remote; @remote public interface testbeanremote { public void method1();   public int method2();    } 

ejb:

package remote.test import javax.ejb.remote; import javax.ejb.stateless; @remote @stateless public class testbean implements testbeanremote { public testbean() { } @override public void method1() { } @override public int method2() { return 42; } } 

for helping junit testing, use glassfish4 orb/iiop port default settings.

i have utility class setting up:

import java.util.properties; public class util { public static properties getinitproperties() { properties result = new properties(); result.setproperty("java.naming.factory.initial",                    "com.sun.enterprise.naming.serialinitcontextfactory"); result.setproperty("java.naming.factory.url.pkgs",                 "com.sun.enterprise.naming"); result.setproperty("java.naming.factory.state",                 "com.sun.corba.ee.impl.presentation.rmi.jndistatefactoryimpl"); result.setproperty("org.omg.corba.orbinitialhost", "localhost"); result.setproperty("org.omg.corba.orbinitialport", "3700"); return result; } } 

and here testing code:

import static org.junit.assert.*; import javax.naming.initialcontext; import org.junit.before; import org.junit.test; import remote.test; public class junittester { private testbeanremote testbean; @before     public void setup() throws exception { initialcontext context = new initialcontext(util.getinitproperties()); testbean = (testbeanremote ) context.lookup("java:global/.../testbean!...testbeanremote"); } @test public void methodtest(){     long n = testbean.method2();     assertequals(42, n); } } 

('...' above means shortening of full package)

and @ point works. should sound good, want implement in specific application, problems.

so, have existing application, have following modules: ear: jpa module ejb client module ejb impl. module war module

plus, have created simple java application project, implement same testing, above. have added same utility class above, , added same junit testing code, have changed the

 private testbeanremote testbean; 

to existing remote interfaced bean of application, , changed jndi name corresponding name (the jdni names given glassfish).

and doesn't work, nullpointerexception @ .lookup() method:

java.lang.nullpointerexception @ com.sun.enterprise.naming.impl.serialcontext.getorb(serialcontext.java:347) @ com.sun.enterprise.naming.impl.serialcontext.getprovidercachekey(serialcontext.java:354) @ com.sun.enterprise.naming.impl.serialcontext.getremoteprovider(serialcontext.java:384) @ com.sun.enterprise.naming.impl.serialcontext.getprovider(serialcontext.java:329) @ com.sun.enterprise.naming.impl.serialcontext.lookup(serialcontext.java:477) @ com.sun.enterprise.naming.impl.serialcontext.lookup(serialcontext.java:438) @ javax.naming.initialcontext.lookup(initialcontext.java:411) 

and can't find why. 2 applications running in same glassfish server. have tried compare codes, difference existing remote bean has entitymanager persistencecontext.

anyone has idea on should problems? cause error?

thanks help!

i have found differences. reason, both projects referencing gf-client-module.jar glassfish 3.1 (the 2 glassfish installations near each other).

the bigger project didn't run, because referencing newer apis (like jpa2 or jsf 2.2), got given error.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -