> From: David Blevins <[email protected]>

> 
> Correct on both counts.  And the  implication as you notice is that you
> cannot use "java:comp/env" lookups in  your test case, just your EJBs.
> 
> Bottom line is that your testing code and  your production code will be
> using slightly different techniques to lookup  things.  The testcase
> will use the LocalInitialContextFactory approach  and the EJBs will use
> the no-arg "new InitialContext()" approach.

Still not able to do EJB lookup using OpenEJB inside a JUnit test.  Below is my 
actual code.  

- The lookup is failing 
- Noticed that in the stack trace, openejb is referenced, even though I used 
the 
no-arg initial context for the EJB stuff.  Appearantly something about 
embedding 
it in the test case setup does cause OpenEJB to be used with the no-arg version 
as well???
- I'm assuming that I have to tell OpenEJB somehow to use the java:comp/env 
name?
- Further assuming I tell OpenEJB this via the ejb-jar.xml file  (Currently 
JBoss gets this from <ejb-local-ref> blocks in web.xml, should I remove that in 
favor of ejb-jar.xml???)
- Tried including "java:" in my ejb name in the ejb-jar.xml file, but get an 
error that ':' is an invalid character.  



So, here's the code that's failing and some of the output (trimmed to the 
relevant parts)...

JNDI name I've been using with JBoss w/o problems & want my tests to make use 
of 
as well
-----------------------------------------------------------------------------------------

java:comp/env/ProductFamilyRegistrationFacade


One entry in the ejb-jar.xml - trying to setup the same name
-----------------------------------------------------------------------------------------

<?xml version="1.0"?>
<ejb-jar>
    <enterprise-beans>
        <session>
            <ejb-name>comp/env/ProductFamilyRegistrationFacade</ejb-name>
             
<business-local>com.<<snipped>>.ejb.facade.ProductFamilyRegistrationFacadeLocal</business-local>

            
<ejb-class>com.<<snipped>>.ejb.jdbc.ProductFamilyRegistrationFacade</ejb-class>
            <session-type>Stateless</session-type>
            <transaction-type>Bean</transaction-type>
        </session>
    </enterprise-beans>
</ejb-jar>


Failing JUnit test
-----------------------------------------------------------------------------------------

    @Test
    public void testCallStoredProcedure() {
        System.out.println("callStoredProcedure");
        IProcedureEntity sp = new ProductFamilyRegistrationProcedure(new 
BigDecimal("0"));
        int expResultSize = 0;
        List result = EJBUtils.callStoredProcedure(sp, DataHandler.OPEN_DATA);
    }



Output Window
-----------------------------------------------------------------------------------------

...
INFO - Auto-creating a container for bean 
comp/env/ProductFamilyRegistrationFacade: Container(type=STATELESS, id=Default 
Stateless Container)
...
INFO - Jndi(name=comp/env/ProductFamilyRegistrationFacadeLocal) --> 
Ejb(deployment-id=comp/env/ProductFamilyRegistrationFacade)
...
INFO - Created Ejb(deployment-id=comp/env/ProductFamilyRegistrationFacade, 
ejb-name=comp/env/ProductFamilyRegistrationFacade, container=Default Stateless 
Container)
...
callStoredProcedure
lookupStoredProcedure: java:comp/env/ProductFamilyRegistrationFacade
Nov 29, 2010 8:10:15 AM com.<<snipped>>.EJBUtils lookupStoredProcedure
SEVERE: exception caught
javax.naming.NameNotFoundException: Name 
"comp/env/ProductFamilyRegistrationFacade" not found.
        at 
org.apache.openejb.core.ivm.naming.IvmContext.federate(IvmContext.java:193)
        at 
org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:150)
        at 
org.apache.openejb.core.ivm.naming.IvmContext.lookup(IvmContext.java:124)
        at javax.naming.InitialContext.lookup(InitialContext.java:392)
        at com.<<snipped>>.EJBUtils.lookupStoredProcedure(EJBUtils.java:33)


Helper method
-----------------------------------------------------------------------------------------

    private static IProcedureFacade lookupStoredProcedure(String jndiName) {
        System.out.println("lookupStoredProcedure: " + jndiName);

        try {
            InitialContext c = new InitialContext();                      // 
<== 
using no-arg version here
            return (IProcedureFacade) c.lookup(jndiName);         // <== Line 
33 
referenced in output above; Name not found exception
        } catch (NamingException ne) {
            Logger.getLogger(EJBUtils.class.getName()).log(Level.SEVERE, 
"exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

Reply via email to