Simple EJB client or Junit not working with IBM websphere - exception

My ejb is deployed in websphere and i want to call it from another webserver, but the remote lookup code is not working. So i tried a simple client to see whether it works, i have set the context properties, but still its not working. Am i missing something?
My node location is WMSPBLDJ00327Node03Cell\WMSPBLDJ00327Node03\server1
The below jndi works perfectly from web code deployed in websphere.. ejb/WgePasEar/WgePasEjb.jar/EmplFacade#com.company.crw.wge.pas.ejb.cmn.empl.EmplFacadeHome
but not from client. I tried different options as in the below code. Can you help?
EJB start up log
[5/8/14 16:31:33:487 CDT] 0000004b AbstractEJBRu I WSVR0037I: Starting EJB jar: WgePasEjb.jar
[5/8/14 16:31:34:101 CDT] 0000004b EJBContainerI I CNTR0167I: The server is binding the com.company.crw.wge.pas.ejb.cmn.empl.EmplFacadeHome interface of the EmplFacade enterprise bean in the WgePasEjb.jar module of the WgePasEar application. The binding location is: ejb/WgePasEar/WgePasEjb.jar/EmplFacade#com.company.crw.wge.pas.ejb.cmn.empl.EmplFacadeHome
[5/8/14 16:31:34:105 CDT] 0000004b EJBContainerI I CNTR0167I: The server is binding the com.company.crw.wge.pas.ejb.cmn.empl.EmplFacadeHome interface of the EmplFacade enterprise bean in the WgePasEjb.jar module of the WgePasEar application. The binding location is: com.company.crw.wge.pas.ejb.cmn.empl.EmplFacadeHome
[5/8/14 16:31:34:106 CDT] 0000004b AbstractEJBRu I CNTR0167I: The server is binding the com.company.crw.wge.pas.ejb.cmn.empl.EmplFacadeHome interface of the EmplFacade enterprise bean in the WgePasEjb.jar module of the WgePasEar application. The binding location is: java:global/WgePasEar/WgePasEjb/EmplFacade!com.company.crw.wge.pas.ejb.cmn.empl.EmplFacadeHome
import java.util.Properties;import javax.ejb.embeddable.EJBContainer;import javax.naming.Context;import org.junit.Test; public class TestJunit {
#Test
public void testContactBean() {
// Create the embeddable container
Properties env1 = new Properties();
env1.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");
env1.put(Context.PROVIDER_URL, "iiop://localhost:9102");
env1.put("com.ibm.CORBA.Debug", "true");
env1.put("com.ibm.CORBA.CommTrace", "true");
env1.put("com.ibm.CORBA.Debug.Output", "client.log");
env1.put(
"com.ibm.SSL.ConfigURL",
"file:/C:/IBM/WebSphere/AppServer_1/profiles/AppSrv1/properties/ssl.client.props");
env1.put("com.ibm.CORBA.loginUserid", "admin");
env1.put("com.ibm.CORBA.loginPassword", "admin");
env1.put("com.ibm.CORBA.loginSource", "properties");
EJBContainer ec = EJBContainer.createEJBContainer(env1);
try {
Object ejbHome = null;
try {
ejbHome = ec
.getContext()
.lookup("java:global/WgePasEar/WgePasEjb.jar/EmplFacade#com.company.crw.wge.pas.ejb.cmn.scty.EmplFacadeHome");
System.out.println("******************" + ejbHome);
} catch (Exception e) {
e.printStackTrace();
}
try {
ejbHome = ec
.getContext()
.lookup("java:global/WgePasEar/WgePasEjb/EmplFacade!com.company.crw.wge.pas.ejb.cmn.empl.EmplFacadeHome");
System.out.println("******************" + ejbHome);
} catch (Exception e) {
e.printStackTrace();
}
Object contactBean = (Object) ec
.getContext()
.lookup("java:global/WgePasEar/WgePasEjb/EmplFacade!com.company.crw.wge.pas.ejb.cmn.empl.EmplFacadeHome");
System.out.println("******************" + contactBean);
} catch (Throwable t) {
t.printStackTrace();
} finally {
ec.close();
}
}}
All of these are giving me exceptions as name
javax.naming.NameNotFoundException: Name WgePasEar not found in context "java:global".
at com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java:1969)
at com.ibm.ws.naming.ipbase.NameSpace.retrieveBinding(NameSpace.java:1376)
at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1219)
at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:1141)
at com.ibm.ws.naming.urlbase.UrlContextImpl.lookupExt(UrlContextImpl.java:1436)
at com.ibm.ws.naming.java.javaURLContextImpl.lookupExt(javaURLContextImpl.java:477)
at com.ibm.ws.naming.java.javaURLContextRoot.lookupExt(javaURLContextRoot.java:485)
at com.ibm.ws.naming.java.javaURLContextRoot.lookupExt(javaURLContextRoot.java:468)
at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:370)
at TestJunit.testContactBean(TestJunit.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:88)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:613)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
javax.naming.NameNotFoundException: Name WgePasEar not found in context "java:global".
at com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java:1969)
at com.ibm.ws.naming.ipbase.NameSpace.retrieveBinding(NameSpace.java:1376)
at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1219)
at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:1141)
at com.ibm.ws.naming.urlbase.UrlContextImpl.lookupExt(UrlContextImpl.java:1436)
at com.ibm.ws.naming.java.javaURLContextImpl.lookupExt(javaURLContextImpl.java:477)
at com.ibm.ws.naming.java.javaURLContextRoot.lookupExt(javaURLContextRoot.java:485)
at com.ibm.ws.naming.java.javaURLContextRoot.lookupExt(javaURLContextRoot.java:468)
at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:370)
at TestJunit.testContactBean(TestJunit.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:88)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:613)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
javax.naming.NameNotFoundException: Name WgePasEar not found in context "java:global".
at com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java:1969)
at com.ibm.ws.naming.ipbase.NameSpace.retrieveBinding(NameSpace.java:1376)
at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1219)
at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:1141)
at com.ibm.ws.naming.urlbase.UrlContextImpl.lookupExt(UrlContextImpl.java:1436)
at com.ibm.ws.naming.java.javaURLContextImpl.lookupExt(javaURLContextImpl.java:477)
at com.ibm.ws.naming.java.javaURLContextRoot.lookupExt(javaURLContextRoot.java:485)
at com.ibm.ws.naming.java.javaURLContextRoot.lookupExt(javaURLContextRoot.java:468)
at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:370)
at TestJunit.testContactBean(TestJunit.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:88)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:613)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

The EJBContainer API should only be used from a standalone JVM, and it can only be used to access EJBs locally in that process (for unit-testing purposes for example), not remote EJBs in a server. It's not exactly clear what the problem is in your Eclipse environment, but you might try setting the trace system properties (e.g., traceSpecification of *=info) in order to observe the CNTR0167I messages in the embeddable scenario.
For remote access, you should use the EJB thinclient or the application client container. It is not possible to use java:global names with the EJB thinclient.

Related

Testing Dropwizard Resources gives NPE

I am trying to unit test a resource by creating a ResourceTestRule as follows
#ClassRule
public static final ResourceTestRule RESOURCES =
ResourceTestRule.builder().addResource(new UserRequestsResource(edao, udao)).build();
#Test
public void invalidEnvironment_NameWithUnderscore_Returns400() throws Exception {
Entity<?> entity = Entity.entity(userRequest, MediaType.APPLICATION_JSON_TYPE);
Response response = RESOURCES.client().target(getDeploysPath()).request().post(entity);
assertEquals(response.getStatus(), 400);
assertEquals(response.getStatusInfo(), Status.BAD_REQUEST);
assertThat(response.readEntity(String.class), containsString(
"{\"Status\":\"'Invalid_Env' contains an underscore; 'Invalid_Env' contains an upper-case letter\"}"));
}
This gives an NPPE at Resource.client()
Following is the stack trace
java.lang.NullPointerException
at java.util.Objects.requireNonNull(Objects.java:203)
at io.dropwizard.testing.common.Resource.getJerseyTest(Resource.java:174)
at io.dropwizard.testing.common.Resource.client(Resource.java:164)
at io.dropwizard.testing.junit.ResourceTestRule.client(ResourceTestRule.java:80)
at com.mathworks.batup.deployer.resources.TestBadEnvironmentName.setup(TestBadEnvironmentName.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
What am I missing?

junit.framework.AssertionFailedError: null in JUnit test using eclipse

I'm new to JUnit and am trying to get some tests running. I have the following codes. After running the codes the test failed and shows AssertionFailedError: null
package com.seleniumsimplified.webdriver;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import static junit.framework.Assert.assertTrue;
public class FirstTest {
#Test
public void driverIsTheKing(){
WebDriver driver = new HtmlUnitDriver();
driver.get("http://www.compendiumdev.co.uk/selenium");
assertTrue(driver.getTitle().startsWith("Selenium simplified") );
}
}
This test always fails in the last line and the stacktrace is the following
junit.framework.AssertionFailedError: null
at junit.framework.Assert.fail(Assert.java:47)
at junit.framework.Assert.assertTrue(Assert.java:20)
at junit.framework.Assert.assertTrue(Assert.java:27)
at com.seleniumsimplified.webdriver.FirstTest.driverIsTheKing(FirstTest.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
assertTrue(driver.getTitle().startsWith("Selenium simplified") );
It seems the title is something else.
Try to output the actual title and see what you get.
String title = driver.getTitle()
assertTrue(title, title.startsWith("Selenium simplified") );
(I wish there was a assertStartWith that does this automatically, just like assertEqual does).

PaxExam exception running tests

I am new to Pax Exam and trying to run tests by calling my OSGI service. I am getting following exception when running paxexam test in eclipse.
java.lang.ClassNotFoundException: org.ops4j.pax.swissbox.framework.ServiceLookupException (no security manager: RMI class loader disabled)
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:373)
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:163)
at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:620)
at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:247)
at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:197)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1574)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1495)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1731)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1946)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1870)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:225)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:142)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:178)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:132)
at $Proxy9.remoteCall(Unknown Source)
at org.ops4j.pax.exam.rbc.client.intern.RemoteBundleContextClientImpl$1.invoke(RemoteBundleContextClientImpl.java:112)
at $Proxy10.call(Unknown Source)
at org.ops4j.pax.exam.rbc.client.intern.RemoteBundleContextClientImpl.call(RemoteBundleContextClientImpl.java:287)
at org.ops4j.pax.exam.container.remote.RBCRemoteTarget.call(RBCRemoteTarget.java:70)
at org.ops4j.pax.exam.container.def.internal.PaxRunnerTestContainer.call(PaxRunnerTestContainer.java:187)
at org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactor.invoke(AllConfinedStagedReactor.java:74)
at org.ops4j.pax.exam.junit.JUnit4TestRunner$2.evaluate(JUnit4TestRunner.java:284)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:69)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:48)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
at org.ops4j.pax.exam.junit.JUnit4TestRunner.run(JUnit4TestRunner.java:93)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Any ideas why this could happen? This happens when I have the #Inject DataGenerator line enabled in the following code.
#RunWith(JUnit4TestRunner.class)
#ExamReactorStrategy(AllConfinedStagedReactorFactory.class)
public class SampleTest{
#Inject
private DataGenerator dataService;
#Inject
private BundleContext bundleContext;
Thanks,
Rahul
As per PAXEXAM-493, the underlying cause of the Exception is that your DataGenerator service is not found by the container. However, normally Pax Exam would report this service failure lookup "nicely". In this case, when Pax Exam tries to load the class ServiceLookupException in order to do that, the class lookup of the ServiceLookupException itself fails (for some reason not yet identified by the Pax developers).

Unit Test is not working

Can someone please tell me why my Unit Test is not working. I'm very new to Unit testing. It's the query that's not running and I'm not sure why ???
public class ContactsServiceTest {
#Autowired
private ContactsService contactsService;
#Test
public void testGetContactsById() {
Contacts con = contactsService.getContactsById(59);
assertTrue(con.getFirstName().equals("Jon"));
}
}
This is the error I get;
java.lang.NullPointerException
at com.logicalideas.myapp.ContactsServiceTest.testGetContactsById(ContactsServiceTest.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
According to your error stacktrace and as long as line 45 is
Contacts con = contactsService.getContactsById(59);
then id 59 you are trying to retrieve does not hold any information or there is an issue with the connection.
Unless you post more information of your system it is difficult to figure out what is the exact problem causing this.
java.lang.NullPointerException
private ContactsService contactsService = new ContactsService();

Running playframework tests as a IntelliJ IDEA JUnit run configuration

I've been trying to run the unit tests in a play application from IntelliJ directly from the built in test runner. (To get the nice UI, click through etc.)
This works for very basic FunctionalTest tests and when it starts it gives the following logging:
16:18:08,353 INFO ~ Starting /home/sindrit/projects/testapp/.
16:18:08,370 INFO ~ Module crud is available (/home/sindrit/play-1.2.3/modules/crud)
16:18:08,949 WARN ~ You're running Play! in DEV mode
16:18:10,242 INFO ~ Connected to jdbc:h2:mem:play;MODE=MYSQL;LOCK_MODE=0
16:18:11,033 INFO ~ Application 'testapp' is now started !
Indicating play is actually starting.
However more complicated tests using database access fail with exceptions like this:
java.lang.UnsupportedOperationException: Please annotate your JPA model with #javax.persistence.Entity annotation.
at play.db.jpa.GenericModel.count(GenericModel.java:232)
at model.BeanTest.testCreate(BeanTest.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at play.test.PlayJUnitRunner$StartPlay$1$1$1.execute(PlayJUnitRunner.java:73)
at play.Invoker$Invocation.run(Invoker.java:265)
at play.Invoker.invokeInThread(Invoker.java:67)
at play.test.PlayJUnitRunner$StartPlay$1$1.evaluate(PlayJUnitRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at play.test.PlayJUnitRunner.run(PlayJUnitRunner.java:48)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:24)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:94)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:192)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:115)
I expect this is because the instrumentation is not working as it does when running play. The same test runs fine in play auto-test.
Through some google searches I've found that I should need at lest the following parameters:
-javaagent:/home/sindrit/play-1.2.3/framework/play-1.2.3.jar
-Dfile.encoding=utf-8
-Dplay.debug=yes
-Dplay.id=test
-Dapplication.path=/home/sindrit/projects/testapp
Has anyone here gotten this to work?
What JVM parameters or classpath or other things do I need to make the IntelliJ test runner emulate the play runtime environment?
If I add play-testrunner.jar to the dependencies I get the following error:
play.exceptions.CompilationException: The type BasicTest is already defined
at play.classloading.ApplicationCompiler$2.acceptResult(ApplicationCompiler.java:246)
at org.eclipse.jdt.internal.compiler.Compiler.handleInternalException(Compiler.java:672)
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:516)
at play.classloading.ApplicationCompiler.compile(ApplicationCompiler.java:278)
at play.classloading.ApplicationClassloader.getAllClasses(ApplicationClassloader.java:412)
at play.Play.start(Play.java:485)
at play.test.PlayJUnitRunner.<init>(PlayJUnitRunner.java:31)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:31)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:93)
at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:84)
at org.junit.runners.Suite.<init>(Suite.java:79)
at com.intellij.junit4.IdeaSuite.<init>(IdeaSuite.java:37)
at com.intellij.junit4.JUnit46ClassesRequestBuilder.getClassesRequest(JUnit46ClassesRequestBuilder.java:34)
at com.intellij.junit4.JUnit4TestRunnerUtil.buildRequest(JUnit4TestRunnerUtil.java:81)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:61)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:192)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:115)
I maybe over simplifying this but it seems you may have forgotten the Entity annotation on your database models.
Your models should look like this.
#Entity
#Table( name = "pkg_load" )
public class PkgLoad extends Model {
}
Or this if you don't want to use the built in ID in model.
#Entity
#Table( name = "pkg_load" )
public class PkgLoad extends GenericModel {
#Id
#GeneratedValue( strategy = GenerationType.IDENTITY )
#Basic( optional = false )
#Column( name = "pkg_load_id" )
public Long pkgLoadId;
}
http://www.playframework.org/documentation/1.2.3/jpa
The Entity annotation is found in the javax.persistence library.