Question: how are you testing?
The reason i am asking = the Transactional Proxy - your case "pmis1" - needs to be referenced, where the bean "userLogic", if you want transactional behaviour.
In the following a TestCase, which works fine ... eventually selecting from the database manually, to check if anything is there ;-)
So the connection stuff was really misleading, sorry about that...
The testcase works both against SingleConnectionDataSource and DriverManagerDataSource.
import junit.framework.TestCase;
import org.springframework.context.support.FileSystemXmlA pplicationContext;
import org.springframework.dao.DataAccessException;
public class TestInsert extends TestCase
{
private FileSystemXmlApplicationContext ctx;
private JdbcUser userLogic;
/*
* @see TestCase#setUp()
*/
protected void setUp() throws Exception
{
super.setUp();
String path[] = {"/war/WEB-INF/applicationContext.xml"};
ctx = new FileSystemXmlApplicationContext(path);
ctx.refresh();
Object obj = ctx.getBean("pmis1"); // and not userLogic
if (!(obj instanceof JdbcUser))
{
throw new Exception("Bean Configuration wrong");
}
userLogic = (JdbcUser) obj;
}
public void testInsert() throws Exception
{
try {
final User aUser = new User();
aUser.setName("Some name");
aUser.setPasswd("Some Passwd");
userLogic.storeUsers(aUser);
fail("Unexpected");
} catch (DataAccessException e)
{
System.out.println(e.toString());
// Ok, but test some more
}
}
/*
* @see TestCase#tearDown()
*/
protected void tearDown() throws Exception
{
super.tearDown();
ctx = null;
userLogic = null;
}
}


Reply With Quote