FYI -- this was hung in the moderation queue, I sent this one through, but you (Vasiliy Kiryanov) will not be able to reply. Please sign up on the mailing list.

 http://shale.apache.org/mail-lists.html


Thanks

--
James Mitchell
678.910.8017




On Aug 7, 2006, at 2:24 AM, Vasiliy Kiryanov wrote:

Good afternoon.

In my BackBeans I use InitialContext from which i aquire datasource, shale
mock InitialContext and
therefore I try to find a way to test my BackBeans using Shale ..

[ http://shale.apache.org/features-jndi-integration.html] link says to me
that I can aquire a java.sql.Connection ..

but integration using way from that link is constantly return null.


from the myfaces BackBean this datasource resolves good using ussual jndi
way:
------------------------------------------
public String Perform()
{
   try
   {
        InitialContext initialContext = new InitialContext();
        if (initialContext == null)
        {
             ...
        }
           DataSource dataSource = (DataSource) initialContext.lookup
("java:/comp/env/jdbc/postgres");
     ...
------------------------------------------


I have next entry in the web.xml
       <resource-ref>
               <description>postgreSQL Datasource</description>
               <res-ref-name>jdbc/postgres</res-ref-name>
               <res-type>javax.sql.DataSource</res-type>
               <res-auth>Container</res-auth>
       </resource-ref>



and use next class:
public class jndiTest extends AbstractViewController
{
   public jndiTest()
   {
       try
       {

       FacesContext context = FacesContext.getCurrentInstance();
       Application appl = context.getApplication();
       ValueBinding vb =
context.getApplication().createValueBinding("#{jndi['jdbc/ postgres'].connection}");


       Connection conn = (Connection) vb.getValue(context);
       }
       catch (Exception e)
       {
           e.printStackTrace();
       }
   }
}

and I call object of this class in this way:
public class TestLoginBackBean extends AbstractViewControllerTestCase
{

   LoginBackBean loginBackBean;

   public TestLoginBackBean(String name)
   {
       super(name);
   }

   public static Test suite()
   {
       return (new TestSuite(TestLoginBackBean.class));
   }

   public void setUp()
   {
       super.setUp();
       loginBackBean = new LoginBackBean();
   }

   public void tearDown()
   {
       loginBackBean = null;
       super.tearDown();
   }

   public void testLoginBackBean_one()
   {
       jndiTest jnditest = new jndiTest();
   }
}

Reply via email to