1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.dbutils;
18  
19  import java.math.BigInteger;
20  import java.sql.ResultSet;
21  import java.sql.ResultSetMetaData;
22  import java.util.Date;
23  
24  import junit.framework.Test;
25  import junit.framework.TestCase;
26  import junit.framework.TestSuite;
27  
28  import org.apache.commons.dbutils.handlers.ArrayHandlerTest;
29  import org.apache.commons.dbutils.handlers.ArrayListHandlerTest;
30  import org.apache.commons.dbutils.handlers.BeanHandlerTest;
31  import org.apache.commons.dbutils.handlers.BeanListHandlerTest;
32  import org.apache.commons.dbutils.handlers.ColumnListHandlerTest;
33  import org.apache.commons.dbutils.handlers.KeyedHandlerTest;
34  import org.apache.commons.dbutils.handlers.MapHandlerTest;
35  import org.apache.commons.dbutils.handlers.MapListHandlerTest;
36  import org.apache.commons.dbutils.handlers.ScalarHandlerTest;
37  import org.apache.commons.dbutils.wrappers.SqlNullCheckedResultSetTest;
38  import org.apache.commons.dbutils.wrappers.StringTrimmedResultSetTest;
39  
40  /**
41   * BaseTestCase is the base class for all test cases as well as the "all tests"
42   * runner.
43   */
44  public class BaseTestCase extends TestCase {
45  
46      private static final String[] columnNames =
47          new String[] {
48              "one",
49              "two",
50              "three",
51              "notInBean",
52              "intTest",
53              "integerTest",
54              "nullObjectTest",
55              "nullPrimitiveTest",
56              "notDate",
57              "columnProcessorDoubleTest" };
58  
59      /**
60       * The number of columns in the MockResultSet.
61       */
62      protected static final int COLS = columnNames.length;
63  
64      protected static final ResultSetMetaData metaData =
65          MockResultSetMetaData.create(columnNames);
66  
67      private static final Object[] row1 =
68          new Object[] {
69              "1",
70              "2",
71              "3",
72              "  notInBean  ",
73              new Integer(1),
74              new Integer(2),
75              null,
76              null,
77              new Date(),
78              BigInteger.valueOf(13)};
79  
80      private static final Object[] row2 =
81          new Object[] {
82              "4",
83              "5",
84              "6",
85              "  notInBean  ",
86              new Integer(3),
87              new Integer(4),
88              null,
89              null,
90              new Date(),
91              BigInteger.valueOf(13)};
92  
93      private static final Object[][] rows = new Object[][] { row1, row2 };
94  
95      /**
96       * The number of rows in the MockResultSet.
97       */
98      protected static final int ROWS = rows.length;
99  
100     /**
101      * The ResultSet all test methods will use.
102      */
103     protected ResultSet rs = null;
104 
105     /**
106      * A ResultSet with 0 rows.
107      */
108     protected ResultSet emptyResultSet = null;
109 
110     /**
111      * Constructor for BaseTestCase.
112      */
113     public BaseTestCase(String name) {
114         super(name);
115     }
116 
117     /**
118      * This is called before each test method so ResultSet will be fresh each
119      * time.
120      * @see junit.framework.TestCase#setUp()
121      */
122     protected void setUp() throws Exception {
123         super.setUp();
124 
125         rs = this.createMockResultSet();
126         emptyResultSet = MockResultSet.create(metaData, null);
127     }
128 
129     /**
130      * Creates a freshly initialized ResultSet.
131      */
132     protected ResultSet createMockResultSet() {
133         return MockResultSet.create(metaData, rows);
134     }
135 
136     /**
137      * Return a TestSuite containing all of our test cases.
138      */
139     public static Test suite() {
140         TestSuite suite = new TestSuite("All DbUtils Tests");
141 
142         suite.addTestSuite(BasicRowProcessorTest.class);
143         suite.addTestSuite(BeanProcessorTest.class);
144         suite.addTestSuite(ProxyFactoryTest.class);
145         suite.addTestSuite(ResultSetIteratorTest.class);
146         suite.addTestSuite(QueryLoaderTest.class);
147 
148         // test handler implementations
149         suite.addTestSuite(ArrayHandlerTest.class);
150         suite.addTestSuite(ArrayListHandlerTest.class);
151         suite.addTestSuite(BeanHandlerTest.class);
152         suite.addTestSuite(BeanListHandlerTest.class);
153         suite.addTestSuite(MapHandlerTest.class);
154         suite.addTestSuite(MapListHandlerTest.class);
155         suite.addTestSuite(ScalarHandlerTest.class);
156         suite.addTestSuite(ColumnListHandlerTest.class);
157         suite.addTestSuite(KeyedHandlerTest.class);
158 
159         suite.addTestSuite(StringTrimmedResultSetTest.class);
160         suite.addTestSuite(SqlNullCheckedResultSetTest.class);
161 
162         return suite;
163     }
164 
165 }