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, tc.getTableDefs());
46  
47          IDataSet expPrepDs = dataFileLoader.load(PREP_DATA_FILE_NAME);
48          Assertion.assertEquals(expPrepDs, tc.getPrepDataset());
49  
50          IDataSet expExpDs = dataFileLoader.load(EXP_DATA_FILE_NAME);
51          Assertion.assertEquals(expExpDs, tc.getExpectedDataset());
52      }
53  
54      public void testPreTest() throws Exception
55      {
56          // TODO implement test
57      }
58  
59      public void testRunTest() throws Exception
60      {
61          VerifyTableDefinition[] tables = {};
62          String[] prepDataFiles = {};
63          String[] expectedDataFiles = {};
64          PrepAndExpectedTestCaseSteps testSteps = new PrepAndExpectedTestCaseSteps()
65          {
66              public Object run() throws Exception
67              {
68                  System.out.println("This message represents the test steps.");
69                  return Boolean.TRUE;
70              }
71          };
72  
73          MockDatabaseConnection mockDbConnection = makeMockDatabaseConnection();
74          IDatabaseTester databaseTester = new DefaultDatabaseTester(mockDbConnection);
75  
76          tc.setDatabaseTester(databaseTester);
77          Boolean actual = (Boolean) tc.runTest(tables, prepDataFiles, expectedDataFiles, testSteps);
78  
79          assertTrue("Did not receive expected value from runTest().", actual);
80      }
81  
82      public void testPostTest()
83      {
84          // TODO implement test
85      }
86  
87      public void testPostTest_false()
88      {
89          // TODO implement test
90      }
91  
92      public void testSetupData()
93      {
94          // TODO implement test
95      }
96  
97      public void testVerifyData()
98      {
99          // TODO implement test
100     }
101 
102     public void testVerifyDataITableITableStringArrayStringArray()
103     {
104         // TODO implement test
105     }
106 
107     public void testCleanupData()
108     {
109         // TODO implement test
110     }
111 
112     public void testMakeCompositeDataSet()
113     {
114         // TODO implement test
115     }
116 
117     // TODO implement test - doesn't test anything yet
118     public void testApplyColumnFiltersBothNull() throws DataSetException
119     {
120         final ITable table = new DefaultTable("test_table");
121         final String[] excludeColumns = null;
122         final String[] includeColumns = null;
123         tc.applyColumnFilters(table, excludeColumns, includeColumns);
124     }
125 
126     // TODO implement test - doesn't test anything yet
127     public void testApplyColumnFiltersBothNotNull() throws DataSetException
128     {
129         final ITable table = new DefaultTable("test_table");
130         final String[] excludeColumns = {"COL1"};
131         final String[] includeColumns = {"COL2"};
132         tc.applyColumnFilters(table, excludeColumns, includeColumns);
133     }
134 
135     private MockDatabaseConnection makeMockDatabaseConnection()
136     {
137         MockConnection mockConnection = new MockConnection();
138 
139         MockStatementFactory mockStatementFactory = new MockStatementFactory();
140         IBatchStatement mockBatchStatement = new MockBatchStatement();
141         mockStatementFactory.setupStatement(mockBatchStatement);
142 
143         MockDatabaseConnection mockDbConnection = new MockDatabaseConnection();
144         mockDbConnection.setupConnection(mockConnection);
145         mockDbConnection.setupStatementFactory(mockStatementFactory);
146         return mockDbConnection;
147     }
148 }