dgraham 2003/10/22 18:15:34
Modified: dbutils/src/test/org/apache/commons/dbutils
ResultSetIteratorTest.java
BasicRowProcessorTest.java ProxyFactoryTest.java
Added: dbutils/src/test/org/apache/commons/dbutils/handlers
ArrayListHandlerTest.java ArrayHandlerTest.java
dbutils/src/test/org/apache/commons/dbutils
BaseTestCase.java
Log:
Added a BaseTestCase class that other tests should extend.
This also acts as the "all tests" runner. Added tests for
Array handler implementations.
Revision Changes Path
1.1
jakarta-commons-sandbox/dbutils/src/test/org/apache/commons/dbutils/handlers/ArrayListHandlerTest.java
Index: ArrayListHandlerTest.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-commons-sandbox/dbutils/src/test/org/apache/commons/dbutils/handlers/ArrayListHandlerTest.java,v
1.1 2003/10/23 01:15:34 dgraham Exp $
* $Revision: 1.1 $
* $Date: 2003/10/23 01:15:34 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgement may appear in the software itself,
* if and wherever such third-party acknowledgements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.dbutils.handlers;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.dbutils.BaseTestCase;
import org.apache.commons.dbutils.ResultSetHandler;
/**
* ArrayListHandlerTest
*
* @author David Graham
*/
public class ArrayListHandlerTest extends BaseTestCase {
/**
* Constructor for ArrayListHandlerTest.
*/
public ArrayListHandlerTest(String name) {
super(name);
}
public void testHandle() throws SQLException {
ResultSetHandler h = new ArrayListHandler();
List results = (List) h.handle(this.rs);
assertNotNull(results);
assertEquals(2, results.size());
Iterator iter = results.iterator();
Object[] row = null;
while (iter.hasNext()) {
row = (Object[]) iter.next();
assertEquals(4, row.length);
}
assertEquals("4", row[0]);
assertEquals("5", row[1]);
assertEquals("6", row[2]);
}
public void testEmptyResultSetHandle() throws SQLException {
ResultSetHandler h = new ArrayListHandler();
List results = (List) h.handle(this.emptyResultSet);
assertNotNull(results);
assertTrue(results.isEmpty());
}
}
1.1
jakarta-commons-sandbox/dbutils/src/test/org/apache/commons/dbutils/handlers/ArrayHandlerTest.java
Index: ArrayHandlerTest.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-commons-sandbox/dbutils/src/test/org/apache/commons/dbutils/handlers/ArrayHandlerTest.java,v
1.1 2003/10/23 01:15:34 dgraham Exp $
* $Revision: 1.1 $
* $Date: 2003/10/23 01:15:34 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgement may appear in the software itself,
* if and wherever such third-party acknowledgements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.dbutils.handlers;
import java.sql.SQLException;
import org.apache.commons.dbutils.BaseTestCase;
import org.apache.commons.dbutils.ResultSetHandler;
/**
* ArrayHandlerTest
*
* @author David Graham
*/
public class ArrayHandlerTest extends BaseTestCase {
/**
* Constructor for ArrayHandlerTest.
*/
public ArrayHandlerTest(String name) {
super(name);
}
public void testHandle() throws SQLException {
ResultSetHandler h = new ArrayHandler();
Object[] results = (Object[]) h.handle(this.rs);
assertNotNull(results);
assertEquals(4, results.length);
assertEquals("1", results[0]);
assertEquals("2", results[1]);
assertEquals("3", results[2]);
}
public void testEmptyResultSetHandle() throws SQLException {
ResultSetHandler h = new ArrayHandler();
Object[] results = (Object[]) h.handle(this.emptyResultSet);
assertNull(results);
}
}
1.2 +6 -25
jakarta-commons-sandbox/dbutils/src/test/org/apache/commons/dbutils/ResultSetIteratorTest.java
Index: ResultSetIteratorTest.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/dbutils/src/test/org/apache/commons/dbutils/ResultSetIteratorTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ResultSetIteratorTest.java 22 Oct 2003 23:54:53 -0000 1.1
+++ ResultSetIteratorTest.java 23 Oct 2003 01:15:34 -0000 1.2
@@ -61,22 +61,14 @@
package org.apache.commons.dbutils;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
import java.util.Iterator;
-import junit.framework.TestCase;
-
/**
* ResultSetIteratorTest
*
* @author David Graham
*/
-public class ResultSetIteratorTest extends TestCase {
-
- private static ResultSetMetaData metaData = null;
-
- private static Object[][] rows = null;
+public class ResultSetIteratorTest extends BaseTestCase {
/**
* Constructor for ResultSetIteratorTest.
@@ -86,20 +78,9 @@
super(arg0);
}
- protected void setUp() throws Exception {
- super.setUp();
-
- String[] columnNames = new String[] { "one", "two", "three" };
- metaData = MockResultSetMetaData.create(columnNames);
-
- rows = new Object[][] { { "1", "2", "3" }, {
- "4", "5", "6" }
- };
- }
-
public void testNext() {
- ResultSet rs = MockResultSet.create(metaData, rows);
- Iterator iter = new ResultSetIterator(rs);
+
+ Iterator iter = new ResultSetIterator(this.rs);
int rowCount = 0;
Object[] row = null;
@@ -108,7 +89,7 @@
row = (Object[]) iter.next();
assertNotNull(row);
- assertEquals(3, row.length);
+ assertEquals(4, row.length);
}
assertEquals(2, rowCount);
1.2 +75 -101
jakarta-commons-sandbox/dbutils/src/test/org/apache/commons/dbutils/BasicRowProcessorTest.java
Index: BasicRowProcessorTest.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/dbutils/src/test/org/apache/commons/dbutils/BasicRowProcessorTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BasicRowProcessorTest.java 22 Oct 2003 04:16:04 -0000 1.1
+++ BasicRowProcessorTest.java 23 Oct 2003 01:15:34 -0000 1.2
@@ -61,115 +61,89 @@
package org.apache.commons.dbutils;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
-import junit.framework.TestCase;
-
/**
* Test the BasicRowProcessor class.
*
* @author David Graham
*/
-public class BasicRowProcessorTest extends TestCase {
-
- private static final RowProcessor processor = BasicRowProcessor.instance();
-
- private static ResultSetMetaData metaData = null;
+public class BasicRowProcessorTest extends BaseTestCase {
- private static Object[][] rows = null;
+ private static final RowProcessor processor = BasicRowProcessor.instance();
- /**
- * Constructor for BasicRowProcessorTest.
- * @param name
- */
- public BasicRowProcessorTest(String name) {
- super(name);
- }
-
- /**
- * @throws java.lang.Exception
- * @see junit.framework.TestCase#setUp()
- */
- protected void setUp() throws Exception {
- super.setUp();
- String[] columnNames = new String[] { "one", "two", "three", "notInBean" };
- metaData = MockResultSetMetaData.create(columnNames);
- rows = new Object[][] { { "1", "2", "3", "notInBean1" }, {
- "4", "5", "6", "notInBean2" }
- };
- }
-
- public void testToArray() throws SQLException {
-
- ResultSet rs = MockResultSet.create(metaData, rows);
-
- int rowCount = 0;
- Object[] a = null;
- while (rs.next()) {
- a = processor.toArray(rs);
- assertEquals(4, a.length);
- rowCount++;
- }
-
- assertEquals(2, rowCount);
- assertEquals("4", a[0]);
- assertEquals("5", a[1]);
- assertEquals("6", a[2]);
- }
-
- public void testToBean() throws SQLException {
- ResultSet rs = MockResultSet.create(metaData, rows);
-
- int rowCount = 0;
- TestBean b = null;
- while (rs.next()) {
- b = (TestBean) processor.toBean(rs, TestBean.class);
- assertNotNull(b);
- rowCount++;
- }
-
- assertEquals(2, rowCount);
- assertEquals("4", b.getOne());
- assertEquals("5", b.getTwo());
- assertEquals("6", b.getThree());
- assertEquals("not set", b.getDoNotSet());
- }
-
- public void testToBeanList() throws SQLException {
- ResultSet rs = MockResultSet.create(metaData, rows);
-
- List list = processor.toBeanList(rs, TestBean.class);
- assertNotNull(list);
- assertEquals(2, list.size());
-
- TestBean b = (TestBean) list.get(1);
-
- assertEquals("4", b.getOne());
- assertEquals("5", b.getTwo());
- assertEquals("6", b.getThree());
- assertEquals("not set", b.getDoNotSet());
- }
-
- public void testToMap() throws SQLException {
- ResultSet rs = MockResultSet.create(metaData, rows);
-
- int rowCount = 0;
- Map m = null;
- while (rs.next()) {
- m = processor.toMap(rs);
- assertNotNull(m);
- assertEquals(4, m.keySet().size());
- rowCount++;
- }
-
- assertEquals(2, rowCount);
- assertEquals("4", m.get("One")); // case shouldn't matter
- assertEquals("5", m.get("two"));
- assertEquals("6", m.get("THREE"));
- }
+ /**
+ * Constructor for BasicRowProcessorTest.
+ * @param name
+ */
+ public BasicRowProcessorTest(String name) {
+ super(name);
+ }
+
+ public void testToArray() throws SQLException {
+
+ int rowCount = 0;
+ Object[] a = null;
+ while (this.rs.next()) {
+ a = processor.toArray(this.rs);
+ assertEquals(4, a.length);
+ rowCount++;
+ }
+
+ assertEquals(2, rowCount);
+ assertEquals("4", a[0]);
+ assertEquals("5", a[1]);
+ assertEquals("6", a[2]);
+ }
+
+ public void testToBean() throws SQLException {
+
+ int rowCount = 0;
+ TestBean b = null;
+ while (this.rs.next()) {
+ b = (TestBean) processor.toBean(this.rs, TestBean.class);
+ assertNotNull(b);
+ rowCount++;
+ }
+
+ assertEquals(2, rowCount);
+ assertEquals("4", b.getOne());
+ assertEquals("5", b.getTwo());
+ assertEquals("6", b.getThree());
+ assertEquals("not set", b.getDoNotSet());
+ }
+
+ public void testToBeanList() throws SQLException {
+
+ List list = processor.toBeanList(this.rs, TestBean.class);
+ assertNotNull(list);
+ assertEquals(2, list.size());
+
+ TestBean b = (TestBean) list.get(1);
+
+ assertEquals("4", b.getOne());
+ assertEquals("5", b.getTwo());
+ assertEquals("6", b.getThree());
+ assertEquals("not set", b.getDoNotSet());
+ }
+
+ public void testToMap() throws SQLException {
+
+ int rowCount = 0;
+ Map m = null;
+ while (this.rs.next()) {
+ m = processor.toMap(this.rs);
+ assertNotNull(m);
+ assertEquals(4, m.keySet().size());
+ rowCount++;
+ }
+
+ assertEquals(2, rowCount);
+ assertEquals("4", m.get("One")); // case shouldn't matter
+ assertEquals("5", m.get("two"));
+ assertEquals("6", m.get("THREE"));
+ }
}
1.2 +4 -6
jakarta-commons-sandbox/dbutils/src/test/org/apache/commons/dbutils/ProxyFactoryTest.java
Index: ProxyFactoryTest.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/dbutils/src/test/org/apache/commons/dbutils/ProxyFactoryTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ProxyFactoryTest.java 23 Oct 2003 00:10:37 -0000 1.1
+++ ProxyFactoryTest.java 23 Oct 2003 01:15:34 -0000 1.2
@@ -70,15 +70,13 @@
import java.sql.ResultSetMetaData;
import java.sql.Statement;
-import junit.framework.TestCase;
-
/**
* ProxyFactoryTest performs simple type checking on proxy objects returned
* from a ProxyFactory.
*
* @author David Graham
*/
-public class ProxyFactoryTest extends TestCase {
+public class ProxyFactoryTest extends BaseTestCase {
private static final InvocationHandler stub = new InvocationHandler() {
1.1
jakarta-commons-sandbox/dbutils/src/test/org/apache/commons/dbutils/BaseTestCase.java
Index: BaseTestCase.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-commons-sandbox/dbutils/src/test/org/apache/commons/dbutils/BaseTestCase.java,v
1.1 2003/10/23 01:15:34 dgraham Exp $
* $Revision: 1.1 $
* $Date: 2003/10/23 01:15:34 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgement may appear in the software itself,
* if and wherever such third-party acknowledgements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.dbutils;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.commons.dbutils.handlers.ArrayHandlerTest;
import org.apache.commons.dbutils.handlers.ArrayListHandlerTest;
/**
* BaseTestCase is the base class for all test cases as well as the "all tests"
* runner.
*
* @author David Graham
*/
public class BaseTestCase extends TestCase {
private static final String[] columnNames =
new String[] { "one", "two", "three", "notInBean" };
private static final ResultSetMetaData metaData =
MockResultSetMetaData.create(columnNames);
private static final Object[][] rows =
new Object[][] { { "1", "2", "3", "notInBean1" }, {
"4", "5", "6", "notInBean2" }
};
/**
* The ResultSet all test methods will use.
*/
protected ResultSet rs = null;
/**
* A ResultSet with 0 rows.
*/
protected ResultSet emptyResultSet = null;
/**
* Constructor for BaseTestCase.
*/
public BaseTestCase(String name) {
super(name);
}
/**
* This is called before each test method so ResultSet will be fresh each
* time.
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
rs = MockResultSet.create(metaData, rows);
emptyResultSet = MockResultSet.create(metaData, null);
}
/**
* Return a TestSuite containing all of our test cases.
*/
public static Test suite() {
TestSuite suite = new TestSuite("All DbUtils Tests");
suite.addTestSuite(BasicRowProcessorTest.class);
suite.addTestSuite(ProxyFactoryTest.class);
suite.addTestSuite(ResultSetIteratorTest.class);
// test handler implementations
suite.addTestSuite(ArrayHandlerTest.class);
suite.addTestSuite(ArrayListHandlerTest.class);
return suite;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]