001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.commons.dbutils; 018 019 import java.math.BigInteger; 020 import java.sql.ResultSet; 021 import java.sql.ResultSetMetaData; 022 import java.util.Date; 023 024 import junit.framework.TestCase; 025 026 /** 027 * BaseTestCase is the base class for all test cases as well as the "all tests" 028 * runner. 029 */ 030 public class BaseTestCase extends TestCase { 031 032 private static final String[] columnNames = 033 new String[] { 034 "one", 035 "two", 036 "three", 037 "notInBean", 038 "intTest", 039 "integerTest", 040 "nullObjectTest", 041 "nullPrimitiveTest", 042 "notDate", 043 "columnProcessorDoubleTest" }; 044 045 /** 046 * The number of columns in the MockResultSet. 047 */ 048 protected static final int COLS = columnNames.length; 049 050 protected static final ResultSetMetaData metaData = 051 MockResultSetMetaData.create(columnNames); 052 053 private static final Object[] row1 = 054 new Object[] { 055 "1", 056 "2", 057 "3", 058 " notInBean ", 059 new Integer(1), 060 new Integer(2), 061 null, 062 null, 063 new Date(), 064 BigInteger.valueOf(13)}; 065 066 private static final Object[] row2 = 067 new Object[] { 068 "4", 069 "5", 070 "6", 071 " notInBean ", 072 new Integer(3), 073 new Integer(4), 074 null, 075 null, 076 new Date(), 077 BigInteger.valueOf(13)}; 078 079 private static final Object[][] rows = new Object[][] { row1, row2 }; 080 081 /** 082 * The number of rows in the MockResultSet. 083 */ 084 protected static final int ROWS = rows.length; 085 086 /** 087 * The ResultSet all test methods will use. 088 */ 089 protected ResultSet rs = null; 090 091 /** 092 * A ResultSet with 0 rows. 093 */ 094 protected ResultSet emptyResultSet = null; 095 096 /** 097 * This is called before each test method so ResultSet will be fresh each 098 * time. 099 * @see junit.framework.TestCase#setUp() 100 */ 101 protected void setUp() throws Exception { 102 super.setUp(); 103 104 rs = this.createMockResultSet(); 105 emptyResultSet = MockResultSet.create(metaData, null); 106 } 107 108 /** 109 * Creates a freshly initialized ResultSet. 110 */ 111 protected ResultSet createMockResultSet() { 112 return MockResultSet.create(metaData, rows); 113 } 114 115 }