struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "rahul" <>
Subject junit test for database service classes
Date Mon, 03 Oct 2005 06:19:00 GMT
Hi all,

In my struts application I am using JNDI for fetching database connections.
I did this by defining a context in META-INF/context.xml of my application.

Here is what lies in my context.xml file:
<Context path="/myApp" docBase="myApp" debug="5" reloadable="true"

privileged="true" crossContext="true">

<Resource name="jdbc/myApp" auth="Container"

type="javax.sql.DataSource" maxActive="30" maxIdle="10" maxWait="6000"

username="myApp_user" password="myApp_password"


url="jdbc:mysql://localhost:3306/myDatabase" removeAbandoned="true"

autoReconnect="true" />


And this is the code  I use to get a connection :

Context ctx = (Context) new InitialContext().lookup("java:comp/env");
   if (ctx == null)
    throw new Exception("No context available");

Connection connection = ((DataSource) ctx.lookup("jdbc/myApp"))

It is working fine for me.

But now I want to write some unit tests of my DatabaseService classes which

uses the above code to get a database connection.

But I don't know how to load the above context parameter, in a junit test

because without doing this I wont be able to get a database connection.

Any Suggestions ?


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message