You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by ritesh <ri...@sbcglobal.net> on 2012/08/24 23:32:44 UTC

need help in unit testing EJB + ibatis.

Hi.
     Here is my setup.

     2 EJBs ( A , B ). B gets injected into A and I'm unit testing A. 
Everything gets injected properly but during testing when EJB B trys to 
initialize Ibatis and
     I get this exception.  How do I bind java:comp/env/jdbc/realdeal 
using the context created by 
org.apache.openejb.core.LocalInitialContextFactory ? 
context.bind("java:comp/env/jdbc/realdeal, BasicDataSource) doesn't seem 
to work.


Exception

Caused by: javax.naming.NameNotFoundException: Name 
"comp/env/jdbc/realdeal" not found.
     at 
org.apache.openejb.core.ivm.naming.IvmContext.federate(IvmContext.java:195)
     at 
org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:149)
     at 
org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:124)
     at javax.naming.InitialContext.lookup(InitialContext.java:409)
     at 
org.apache.openejb.core.ivm.naming.JndiUrlReference.getObject(JndiUrlReference.java:29)
     at 
org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:173)
     at 
org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:124)
     at javax.naming.InitialContext.lookup(InitialContext.java:409)
     at 
org.apache.ibatis.datasource.jndi.JndiDataSourceFactory.setProperties(JndiDataSourceFactory.java:38)
     ... 76 more


EJB B configuration.

<ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:ejb="http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"
     version="3.1">
<module-name>party</module-name>
<enterprise-beans>
<session>
               ....
<resource-ref>
<res-ref-name>jdbc/database</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
<lookup-name>java:comp/env/jdbc/realdeal</lookup-name>
</resource-ref>
</session>
</enterprise-beans>
</ejb-jar>




Re: need help in unit testing EJB + ibatis.

Posted by Jean-Louis MONTEIRO <je...@gmail.com>.
It should be more likely due to the namespace used.
java:comp/env/ is only accessible from managed object which is obviously
not the case in UnitTest.
Try using the fully qualified name instead.

Jean-Louis

2012/8/25 stratwine <to...@gmail.com>

> Hi Ritesh,
>
> Looks like the datasource is not configured correctly.
>
>
> ritesh wrote
> >
> > context.bind("java:comp/env/jdbc/realdeal, BasicDataSource) doesn't seem
> > to work.
> >
>
> For unit tests, you could configure the datasources for your tests as
> described here
> http://tomee.apache.org/configuring-datasources-in-tests.html
>
> If you decide to use the newer EJBContainer API, it would look like in this
> example
>
> http://openejb.apache.org/examples-trunk/injection-of-datasource/README.html
>
> Cheers,
> Vishwa
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/need-help-in-unit-testing-EJB-ibatis-tp4657093p4657099.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: need help in unit testing EJB + ibatis.

Posted by stratwine <to...@gmail.com>.
Hi Ritesh,

Looks like the datasource is not configured correctly.


ritesh wrote
> 
> context.bind("java:comp/env/jdbc/realdeal, BasicDataSource) doesn't seem 
> to work.
> 

For unit tests, you could configure the datasources for your tests as
described here http://tomee.apache.org/configuring-datasources-in-tests.html

If you decide to use the newer EJBContainer API, it would look like in this
example
http://openejb.apache.org/examples-trunk/injection-of-datasource/README.html

Cheers,
Vishwa



--
View this message in context: http://openejb.979440.n4.nabble.com/need-help-in-unit-testing-EJB-ibatis-tp4657093p4657099.html
Sent from the OpenEJB User mailing list archive at Nabble.com.