On 8/6/06, Vasiliy Kiryanov <[EMAIL PROTECTED]> 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();
}
}
Vasilly,
I spent some time looking into this issue, and was able to successfully use
an expression like "#{jndi['jdbc/travel']}" to retrieve a data source from
Tomcat. The details are in the JIRA issue[1] that I filed about this
problem. As you'll see the issue is resolved as "cannot reproduce" ... feel
free to reopen it if you can provide a complete test case where this is
failing for you.
Craig
[1] http://issues.apache.org/struts/browse/SHALE-253