01: package com.mockrunner.example.jdbc;
02:
03: import java.sql.Date;
04: import java.util.List;
05:
06: import com.mockrunner.jdbc.BasicJDBCTestCaseAdapter;
07: import com.mockrunner.jdbc.CallableStatementResultSetHandler;
08: import com.mockrunner.mock.jdbc.MockResultSet;
09:
10: /**
11: * Example test for {@link OrderDB}. Demonstrates the usage of
12: * {@link com.mockrunner.jdbc.JDBCTestModule}
13: * and {@link com.mockrunner.jdbc.BasicJDBCTestCaseAdapter} with
14: * stored procdures.
15: */
16: public class OrderDBTest extends BasicJDBCTestCaseAdapter {
17: private CallableStatementResultSetHandler statementHandler;
18:
19: protected void setUp() throws Exception {
20: super .setUp();
21: statementHandler = getJDBCMockObjectFactory()
22: .getMockConnection()
23: .getCallableStatementResultSetHandler();
24: }
25:
26: private void prepareResult() {
27: MockResultSet result = statementHandler.createResultSet();
28: result.addColumn("name", new String[] { "MyName1", "MyName2",
29: "MyName3" });
30: statementHandler.prepareResultSet("call getnames", result);
31: }
32:
33: public void testCallStoredProc() throws Exception {
34: prepareResult();
35: List result = OrderDB.getNames(Date.valueOf("2004-01-01"));
36: assertEquals("MyName1", result.get(0));
37: assertEquals("MyName2", result.get(1));
38: assertEquals("MyName3", result.get(2));
39: verifyCallableStatementParameter("call getnames", 1, Date
40: .valueOf("2004-01-01"));
41: verifyCallableStatementClosed("call getnames");
42: verifyAllResultSetsClosed();
43: verifyConnectionClosed();
44: }
45: }
|