View Javadoc
1   package org.dbunit;
2   
3   import org.dbunit.database.MockDatabaseConnection;
4   import org.dbunit.database.statement.IBatchStatement;
5   import org.dbunit.database.statement.MockBatchStatement;
6   import org.dbunit.database.statement.MockStatementFactory;
7   import org.dbunit.dataset.DataSetException;
8   import org.dbunit.dataset.DefaultTable;
9   import org.dbunit.dataset.IDataSet;
10  import org.dbunit.dataset.ITable;
11  import org.dbunit.util.fileloader.DataFileLoader;
12  import org.dbunit.util.fileloader.FlatXmlDataFileLoader;
13  
14  import com.mockobjects.sql.MockConnection;
15  
16  import junit.framework.TestCase;
17  
18  public class DefaultPrepAndExpectedTestCaseTest extends TestCase
19  {
20      private static final String PREP_DATA_FILE_NAME = "/xml/flatXmlDataSetTest.xml";
21      private static final String EXP_DATA_FILE_NAME = "/xml/flatXmlDataSetTest.xml";
22  
23      private final DataFileLoader dataFileLoader = new FlatXmlDataFileLoader();
24      // private final IDatabaseTester databaseTester = new
25      // JdbcDatabaseTester(driverClass, connectionUrl);
26  
27      private final DefaultPrepAndExpectedTestCase tc = new DefaultPrepAndExpectedTestCase();
28  
29      @Override
30      protected void setUp() throws Exception
31      {
32          super.setUp();
33          // tc.setDatabaseTester(databaseTester);
34          tc.setDataFileLoader(dataFileLoader);
35      }
36  
37      public void testConfigureTest() throws Exception
38      {
39          String[] prepDataFiles = {PREP_DATA_FILE_NAME};
40          String[] expectedDataFiles = {EXP_DATA_FILE_NAME};
41          VerifyTableDefinition[] tables = {};
42  
43          tc.configureTest(tables, prepDataFiles, expectedDataFiles);
44  
45          assertEquals("Configured tables do not match expected.", tables,
46                  tc.getVerifyTableDefs());
47  
48          IDataSet expPrepDs = dataFileLoader.load(PREP_DATA_FILE_NAME);
49          Assertion.assertEquals(expPrepDs, tc.getPrepDataset());
50  
51          IDataSet expExpDs = dataFileLoader.load(EXP_DATA_FILE_NAME);
52          Assertion.assertEquals(expExpDs, tc.getExpectedDataset());
53      }
54  
55      public void testPreTest() throws Exception
56      {
57          // TODO implement test
58      }
59  
60      public void testRunTest() throws Exception
61      {
62          VerifyTableDefinition[] tables = {};
63          String[] prepDataFiles = {};
64          String[] expectedDataFiles = {};
65          PrepAndExpectedTestCaseSteps testSteps = new PrepAndExpectedTestCaseSteps()
66          {
67              public Object run() throws Exception
68              {
69                  System.out.println("This message represents the test steps.");
70                  return Boolean.TRUE;
71              }
72          };
73  
74          MockDatabaseConnection mockDbConnection = makeMockDatabaseConnection();
75          IDatabaseTester databaseTester = new DefaultDatabaseTester(mockDbConnection);
76  
77          tc.setDatabaseTester(databaseTester);
78          Boolean actual = (Boolean) tc.runTest(tables, prepDataFiles, expectedDataFiles, testSteps);
79  
80          assertTrue("Did not receive expected value from runTest().", actual);
81      }
82  
83      public void testPostTest()
84      {
85          // TODO implement test
86      }
87  
88      public void testPostTest_false()
89      {
90          // TODO implement test
91      }
92  
93      public void testSetupData()
94      {
95          // TODO implement test
96      }
97  
98      public void testVerifyData()
99      {
100         // TODO implement test
101     }
102 
103     public void testVerifyDataITableITableStringArrayStringArray()
104     {
105         // TODO implement test
106     }
107 
108     public void testCleanupData()
109     {
110         // TODO implement test
111     }
112 
113     public void testMakeCompositeDataSet()
114     {
115         // TODO implement test
116     }
117 
118     // TODO implement test - doesn't test anything yet
119     public void testApplyColumnFiltersBothNull() throws DataSetException
120     {
121         final ITable table = new DefaultTable("test_table");
122         final String[] excludeColumns = null;
123         final String[] includeColumns = null;
124         tc.applyColumnFilters(table, excludeColumns, includeColumns);
125     }
126 
127     // TODO implement test - doesn't test anything yet
128     public void testApplyColumnFiltersBothNotNull() throws DataSetException
129     {
130         final ITable table = new DefaultTable("test_table");
131         final String[] excludeColumns = {"COL1"};
132         final String[] includeColumns = {"COL2"};
133         tc.applyColumnFilters(table, excludeColumns, includeColumns);
134     }
135 
136     private MockDatabaseConnection makeMockDatabaseConnection()
137     {
138         MockConnection mockConnection = new MockConnection();
139 
140         MockStatementFactory mockStatementFactory = new MockStatementFactory();
141         IBatchStatement mockBatchStatement = new MockBatchStatement();
142         mockStatementFactory.setupStatement(mockBatchStatement);
143 
144         MockDatabaseConnection mockDbConnection = new MockDatabaseConnection();
145         mockDbConnection.setupConnection(mockConnection);
146         mockDbConnection.setupStatementFactory(mockStatementFactory);
147         return mockDbConnection;
148     }
149 }