-
15. How to Junit test EJB class
djheisterberg Mar 7, 2011 5:17 PM (in response to samwun9988)You're missing something from the classpath: org.jnp.interfaces.NamingContextFactory isn't found. Are you using maven? Once you get the JNDI issues fixed you'll need to configure a datasource and bind it. For the openejb case that's also done in the jndi.properties file with an odd syntax.
-
16. How to Junit test EJB class
samwun9988 Mar 8, 2011 3:19 AM (in response to djheisterberg)I think the following reference is a good tutorial. But i wil have to see how it goes in my hand.
Sam.
-
-
18. How to Junit test EJB class
samwun9988 Mar 8, 2011 7:24 AM (in response to samwun9988)Hello,
In reference to the following tutorial:
I meant this link.
http://javahowto.blogspot.com/2011/02/ejb-lite-jpa-datasource-embedded-in.html
I tried to test it in netbeans 7 + Jboss 6.0, but it failed with the following exception:
Testsuite: au.com.houseware.server.ejb.entity.bean.RoleFacadeTest4
Tests run: 0, Failures: 0, Errors: 1, Time elapsed: 0.759 sec
Testcase: au.com.houseware.server.ejb.entity.bean.RoleFacadeTest4: Caused an ERROR
Unable to instantiate container with factories []
javax.ejb.EJBException: Unable to instantiate container with factories []
at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:97)
at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:75)
at au.com.houseware.server.ejb.entity.bean.RoleFacadeTest4.setUpClass(RoleFacadeTest4.java:36)
at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:97)
Test au.com.houseware.server.ejb.entity.bean.RoleFacadeTest4 FAILED
test:
Deleting: C:\Users\sam\AppData\Local\Temp\TEST-au.com.houseware.server.ejb.entity.bean.RoleFacadeTest4.xml
BUILD SUCCESSFUL (total time: 11 seconds)
It is unbelivable JUnit testing with EJB.
Does anyone got a working setup/example to test EJBContainer using Junit test?
Thanks a lot
Sam
-
19. How to Junit test EJB class
samwun9988 Mar 8, 2011 7:45 AM (in response to samwun9988)After added all client/* jar file to the library, I come up with some new exception:
Testcase: au.com.houseware.server.ejb.entity.bean.RoleFacadeTest4: Caused an ERROR
java.lang.NoSuchMethodException: javax.annotation.Resource.lookup()
javax.ejb.EJBException: java.lang.NoSuchMethodException: javax.annotation.Resource.lookup()
at org.jboss.ejb3.embedded.impl.standalone.JBossStandaloneEJBContainerProvider.createEJBContainer(JBossStandaloneEJBContainerProvider.java:149)
at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:93)
at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:75)
at au.com.houseware.server.ejb.entity.bean.RoleFacadeTest4.setUpClass(RoleFacadeTest4.java:36)
Caused by: java.lang.NoSuchMethodException: javax.annotation.Resource.lookup()
at java.lang.Class.getMethod(Class.java:1605)
at org.jboss.ejb3.embedded.impl.standalone.JBossStandaloneEJBContainerProvider.createEJBContainer(JBossStandaloneEJBContainerProvider.java:133)
at org.jboss.ejb3.embedded.impl.standalone.JBossStandaloneEJBContainerProvider.createEJBContainer(JBossStandaloneEJBContainerProvider.java:149)
Test au.com.houseware.server.ejb.entity.bean.RoleFacadeTest4 FAILED
Interesting, what is "EJBException: java.lang.NoSuchMethodException: javax.annotation.Resource.lookup()"??
Am I runnign something out of date?
I am running jdk 6.0_21 and jboss 6.0!
Sam
-
20. How to Junit test EJB class
nickarls Mar 8, 2011 7:50 AM (in response to samwun9988)conflict between SE Resource class and EE resource class. google around for "endorsed libs resource"
-
21. How to Junit test EJB class
samwun9988 Mar 8, 2011 8:24 AM (in response to nickarls)Since I added all client/* to the libraries, that might be the problem.
Should I use endorsed libs instead?
Thanks
Sam
-
22. How to Junit test EJB class
samwun9988 Mar 8, 2011 8:43 AM (in response to nickarls)I googled around, but couldn't find anything useful in the search result.
I have tried to replace all client/* with endorse/* jar file in netbeans libs, and also have tried to use all common/libs/ files , but it still thrown exceptions badly.
Thanks
Sam
-
23. How to Junit test EJB class
wolfc Mar 8, 2011 8:50 AM (in response to samwun9988)See item 2 under 'Common Problems' of http://community.jboss.org/wiki/EJB31Embeddable
-
24. How to Junit test EJB class
samwun9988 Mar 8, 2011 9:07 AM (in response to wolfc)Carlo de Wolf wrote:
See item 2 under 'Common Problems' of http://community.jboss.org/wiki/EJB31Embeddable
Thanks for the reference.
In netbeans, how to setup the following java commandline to execute my Junit test?
-Xmx512m -XX:MaxPermSize=256m -Djava.endorsed.dirs=$JBOSS_HOME/lib/endorsed
Thanks
Sam
-
25. How to Junit test EJB class
samwun9988 Mar 9, 2011 4:05 AM (in response to wolfc)Carlo de Wolf wrote:
See item 2 under 'Common Problems' of http://community.jboss.org/wiki/EJB31Embeddable
Hello,
I am not sure how to resolve the following example:
C:\work\NetBeansProjects70b2\ejb-test\classes>java -Djava.util.logging.manager=o
rg.jboss.logmanager.LogManager -Djava.endorsed.dirs=$JBOSS_HOME/lib/endorsed -cp "C:\jboss-6.0.0.Final\client\*;." test.Client
Exception in thread "main" javax.ejb.EJBException: java.lang.reflect.InvocationT
argetException
at org.jboss.ejb3.embedded.impl.standalone.JBossStandaloneEJBContainerProvider.createEJBContainer(JBossStandaloneEJBContainerProvider.java:153)
at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:93)
at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:75)
at test.Client.main(Client.java:7)
Caused by: java.lang.reflect.InvocationTargetException
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.jboss.ejb3.embedded.impl.standalone.JBossStandaloneEJBContainerProvider.createEJBContainer(JBossStandaloneEJBContainerProvider.java:141)
... 3 more
Caused by: java.lang.NoClassDefFoundError: org/jboss/logmanager/Logger$AttachmentKey
at org.jboss.logging.JBossLogManagerProvider.<clinit>(JBossLogManagerPro
vider.java:36)
at org.jboss.logging.LoggerProviders.findProvider(LoggerProviders.java:3
3)
at org.jboss.logging.LoggerProviders.<clinit>(LoggerProviders.java:28)
at org.jboss.logging.Logger.getLogger(Logger.java:2164)
at org.jboss.logging.Logger.getLogger(Logger.java:2189)
at org.jboss.ejb3.embedded.impl.base.scanner.ClassPathEjbJarScanner.<clinit>(ClassPathEjbJarScanner.java:80)
at org.jboss.ejb3.embedded.sub.JBossSubmersibleEJBContainer.createEJBContainer(JBossSubmersibleEJBContainer.java:117)
... 8 more
Caused by: java.lang.ClassNotFoundException: org.jboss.logmanager.Logger$AttachmentKey
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 15 more
C:\work\NetBeansProjects70b2\ejb-test\classes>
Any idea?
Thanks
Sam
-
26. How to Junit test EJB class
samwun9988 Mar 9, 2011 5:07 AM (in response to samwun9988)Here I got a problem with classpath:
[ClassPathEjbJarScanner] Dev Hack Alert: Ignoring class on ClassPath which can't be loaded due to java.lang.NoClassDefFoundError: net/sf/cglib/proxy/MethodInterceptor while loading org.apache.cxf.common.util.CglibProxyHelper$1; configure an exclusion filter so "/C:/jboss-6.0.0.Final/client/cxf-common-utilities.jar" is not processed
[ClassPathEjbJarScanner] Dev Hack Alert: Ignoring class on ClassPath which can't be loaded due to java.lang.NoClassDefFoundError: org/springframework/beans/factory/xml/AbstractSingleBeanDefinitionParser while loading org.apache.cxf.configuration.spring.AbstractBeanDefinitionParser; configure an exclusion filter so "/C:/jboss-6.0.0.Final/client/cxf-common-utilities.jar" is not processed
[ClassPathEjbJarScanner] Dev Hack Alert: Ignoring class on ClassPath which can't be loaded due to java.lang.NoClassDefFoundError: org/springframework/beans/factory/xml/AbstractSingleBeanDefinitionParser while loading org.apache.cxf.configuration.spring.SimpleBeanDefinitionParser; configure an exclusion filter so "/C:/jboss-6.0.0.Final/client/cxf-common-utilities.jar" is not processed
[ClassPathEjbJarScanner] Dev Hack Alert: Ignoring class on ClassPath which can't be loaded due to java.lang.NoClassDefFoundError: org/springframework/beans/factory/xml/AbstractSingleBeanDefinitionParser while loading org.apache.cxf.configuration.spring.StringBeanDefinitionParser; configure an exclusion filter so "/C:/jboss-6.0.0.Final/client/cxf-common-utilities.jar" is not processed
.....
Exception in thread "main" javax.ejb.EJBException: java.lang.reflect.InvocationTargetException
at org.jboss.ejb3.embedded.impl.standalone.JBossStandaloneEJBContainerProvider.createEJBContainer(JBossStandaloneEJBContainerProvider.java:153)
at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:93)
at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:75)
at test.Client.main(Client.java:7)
Caused by: java.lang.reflect.InvocationTargetException
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.jboss.ejb3.embedded.impl.standalone.JBossStandaloneEJBContainerProvider.createEJBContainer(JBossStandaloneEJBContainerProvider.java:141)
... 3 more
Caused by: java.lang.RuntimeException: Found .class on ClassPath which could not be found by the TCCL
at org.jboss.ejb3.embedded.impl.base.scanner.ClassPathEjbJarScanner.containsEjbComponentClass(ClassPathEjbJarScanner.java:371)
at org.jboss.ejb3.embedded.impl.base.scanner.ClassPathEjbJarScanner.containsEjbComponentClass(ClassPathEjbJarScanner.java:349)
at org.jboss.ejb3.embedded.impl.base.scanner.ClassPathEjbJarScanner.containsEjbComponentClass(ClassPathEjbJarScanner.java:349)
at org.jboss.ejb3.embedded.impl.base.scanner.ClassPathEjbJarScanner.containsEjbComponentClass(ClassPathEjbJarScanner.java:349)
at org.jboss.ejb3.embedded.impl.base.scanner.ClassPathEjbJarScanner.containsEjbComponentClass(ClassPathEjbJarScanner.java:349)
at org.jboss.ejb3.embedded.impl.base.scanner.ClassPathEjbJarScanner.containsEjbComponentClass(ClassPathEjbJarScanner.java:324)
at org.jboss.ejb3.embedded.impl.base.scanner.ClassPathEjbJarScanner.isEjbJar(ClassPathEjbJarScanner.java:285)
at org.jboss.ejb3.embedded.impl.base.scanner.ClassPathEjbJarScanner.getEjbJars(ClassPathEjbJarScanner.java:174)
at org.jboss.ejb3.embedded.sub.JBossSubmersibleEJBContainer.createEJBContainer(JBossSubmersibleEJBContainer.java:117)
... 8 more
Caused by: java.lang.ClassNotFoundException: 1.0.com.sun.codemodel.JConditional
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.jboss.ejb3.embedded.impl.base.scanner.ClassPathEjbJarScanner.containsEjbComponentClass(ClassPathEjbJarScanner.java:367)
... 16 more
My classpath is shown as follow:
CLASSPATH=c:\jboss-6.0.0.Final\client\;c:\jboss-6.0.0.Final\lib\endorsed\;.;C:\work\NetBeansProjects70b2\ejb-test\classes\test\
Command to execute this test:
java -Djava.util.logging.manager=org.jboss.logmanager.LogManager -Djava.endorsed.dirs=$JBOSS_HOME/lib/endorsed -cp "C:\jboss-6.0.0.Final\client\;.;C:\jboss-6.0.0.Final\lib\" test.Client > out.txt 2<&1
Thanks
Sam
-
27. How to Junit test EJB class
drdar Apr 13, 2011 4:36 AM (in response to samwun9988)Is it possible to make JUnit test run from maven without installed JBoss server on the same machine?
Darek
-
28. How to Junit test EJB class
peterj Apr 13, 2011 12:00 PM (in response to drdar)EJB3 beans are POJOs so you should be able to unit test them (yes, even via Maven) provided that the beans don't rely or require app server-specific functionality. I do this quite often.
-
29. How to Junit test EJB class
drdar Apr 13, 2011 4:41 PM (in response to peterj)That's I know, and I do like that.
But I'd like to learn sth new about JEE6 and how to use EJBContainer in JUnit.
I found solution how to do that with Glassfish, but my company and me is oriented to JBoss server.