Failing junit tests of EJB project


(gospodin bodurov) #1

Hi all, I have a problem with gradle junit testing and openEJB. It has really strange behaviour.

  1. Everything works fine under STS environment 2) If I compile whole project like an application and start junit from java class everything is fine 3) If I build the project with gradle test under console I got the following output:

********* > test FAILED

javax.naming.NamingException

Caused by: org.apache.openejb.OpenEJBException

or

javax.naming.NamingException

Caused by: org.apache.openejb.OpenEJBException

java.lang.NullPointerException

And the stacktrace into test report is:

javax.naming.NamingException: Injection failed [Root exception is org.apache.openejb.OpenEJBException: Unable to find injection meta-data for ******. Ensure that class was annotated with @org.apache.openejb.api.LocalClient and was successfully discovered and deployed. See http://openejb.apache.org/3.0/local-client-injection.html]

at org.apache.openejb.core.LocalInitialContext.inject(LocalInitialContext.java:189)

at org.apache.openejb.core.LocalInitialContext.bind(LocalInitialContext.java:179)

at javax.naming.InitialContext.bind(InitialContext.java:419)

at **************

at sun.reflect.GeneratedMethodAccessor100.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:606)

at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)

at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)

at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)

at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)

at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)

at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)

at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)

at org.junit.runners.ParentRunner.run(ParentRunner.java:309)

at org.junit.runners.Suite.runChild(Suite.java:127)

at org.junit.runners.Suite.runChild(Suite.java:26)

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)

at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)

at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)

at org.junit.runners.ParentRunner.run(ParentRunner.java:309)

at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:80)

at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:47)

at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:69)

at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:49)

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:606)

at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)

at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)

at org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)

at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)

at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)

at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:103)

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:606)

at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)

at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)

at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:355)

at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

at java.lang.Thread.run(Thread.java:744)

I have apllication-client.xml inserted into src/test/resources/META-INF but it doesn’t help.

Thanks at advance.

Best Regards, Gospodin Bodurov


(gospodin bodurov) #2

And this is my build.gradle

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
    task wrapper(type: Wrapper) {
    gradleVersion = '1.8'
}
  sourceCompatibility = 7
targetCompatibility = 7
  dependencies {
    compile 'net.sf.ehcache:ehcache-terracotta:2.6.0'
  compile 'net.sf.ehcache:ehcache-core:2.6.0'
  compile 'net.sf.ehcache:ehcache:2.6.0'
    compile 'net.sf.supercsv:super-csv:2.0.0-beta-1'
      compile 'org.jboss.spec.javax.ejb:jboss-ejb-api_3.1_spec:1.0.2.Final'
  compile 'org.jboss.spec.javax.interceptor:jboss-interceptors-api_1.1_spec:1.0.1.Final'
    compile 'org.jboss.spec.javax.jms:jboss-jms-api_1.1_spec:1.0.1.Final'
  compile 'org.jboss.jbossas:jboss-as-ejb3-ext-API:0.1.2.Beta1'
      compile 'com.paypal.sdk:merchantsdk:2.4.103'
    compile 'org.apache.httpcomponents:httpclient:4.2.2'
    compile 'com.google.code.gson:gson:2.2.2'
    compile 'org.hibernate:hibernate-validator:4.0.0.GA'
    compile
files(fileTree(dir: 'extLib', includes: ['*.jar']))
    compile 'junit:junit:4.10'
      testCompile 'org.mockito:mockito-all:1.9.0'
  testCompile 'org.apache.openejb:openejb-core:4.5.0'
  testCompile 'org.postgresql:postgresql:9.2-1002-jdbc4'
  testCompile 'xerces:xerces:2.4.0'
}

(Peter Niederwieser) #3

Try:

sourceSets.main.output.resourcesDir = sourceSets.main.output.classesDir
sourceSets.test.output.resourcesDir = sourceSets.test.output.classesDir

(gospodin bodurov) #4

Hi Peter, Thank you for this fix. It works (happy). If you have ever come to Bulgaria, you have minimum couple of beers from me .

Best Regards, Gospodin Bodurov