Author: ekoneil
Date: Mon Mar 7 08:11:05 2005
New Revision: 156432
URL: http://svn.apache.org/viewcvs?view=rev&rev=156432
Log:
Final part of the bug fix for J406. Adding tests of the ResultSetIterator.
Also turning part of the PagerRenderer base class from public to protected.
There are methods there that are exposing data which shouldn't be obtained from
the Renderer class.
BB: self
DRT: NetUI pass
BVT: NetUI pass
Added:
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/iterator/ResultSetTestSupport.java
(with props)
Modified:
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/rendering/PagerRenderer.java
incubator/beehive/trunk/netui/test/ant/junitCore.xml
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/databinding/expression/IndexedNameTest.java
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/iterator/IteratorFactoryTest.java
Modified:
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/rendering/PagerRenderer.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/rendering/PagerRenderer.java?view=diff&r1=156431&r2=156432
==============================================================================
---
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/rendering/PagerRenderer.java
(original)
+++
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/rendering/PagerRenderer.java
Mon Mar 7 08:11:05 2005
@@ -43,14 +43,6 @@
private TagRenderingBase _anchorTag = null;
private AnchorTag.State _anchorState = new AnchorTag.State();
- public PagerModel getPagerModel() {
- return _pagerModel;
- }
-
- public DataGridTagModel getDataGridTagModel() {
- return _gridModel;
- }
-
public void setDataGridTagModel(DataGridTagModel gridModel) {
assert gridModel != null;
@@ -67,6 +59,14 @@
return internalRender();
}
+ protected PagerModel getPagerModel() {
+ return _pagerModel;
+ }
+
+ protected DataGridTagModel getDataGridTagModel() {
+ return _gridModel;
+ }
+
protected String internalRender() {
return "";
}
Modified: incubator/beehive/trunk/netui/test/ant/junitCore.xml
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/ant/junitCore.xml?view=diff&r1=156431&r2=156432
==============================================================================
--- incubator/beehive/trunk/netui/test/ant/junitCore.xml (original)
+++ incubator/beehive/trunk/netui/test/ant/junitCore.xml Mon Mar 7 08:11:05
2005
@@ -40,6 +40,7 @@
<sysproperty key="log4j.configuration"
value="file:${log4j.config}"/>
<sysproperty key="netuidrt.logdir" path="${testout.dir}"/>
<test name="org.apache.beehive.netui.test.util.type.TypeUtilsTest"
todir="${testout.dir}"/>
+ <test
name="org.apache.beehive.netui.test.util.iterator.IteratorFactoryTest"
todir="${testout.dir}"/>
<test name="org.apache.beehive.netui.test.util.config.ConfigTest"
todir="${testout.dir}"/>
<batchtest fork="yes" todir="${testout.dir}">
<fileset dir="${test.classes.dir}/junitTests">
Modified:
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/databinding/expression/IndexedNameTest.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/databinding/expression/IndexedNameTest.java?view=diff&r1=156431&r2=156432
==============================================================================
---
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/databinding/expression/IndexedNameTest.java
(original)
+++
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/databinding/expression/IndexedNameTest.java
Mon Mar 7 08:11:05 2005
@@ -422,7 +422,6 @@
* classes in a test case.
*/
public static interface ILeafFactory {
-
public Leaf createLeaf(IExpressionQualifier qualifier);
}
Modified:
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/iterator/IteratorFactoryTest.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/iterator/IteratorFactoryTest.java?view=diff&r1=156431&r2=156432
==============================================================================
---
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/iterator/IteratorFactoryTest.java
(original)
+++
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/iterator/IteratorFactoryTest.java
Mon Mar 7 08:11:05 2005
@@ -20,12 +20,14 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import java.sql.ResultSet;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.beehive.netui.util.iterator.*;
+import org.apache.beehive.netui.test.util.config.TestConfigUtil;
/**
*
@@ -33,30 +35,52 @@
public class IteratorFactoryTest
extends TestCase {
- public void testMapIterator()
- throws Exception {
+ public void testMapIterator() {
Map map = new HashMap();
Iterator i = IteratorFactory.createIterator(map);
-
assertTrue(i instanceof MapIterator);
assertNotNull(i);
}
- public void testAtomicObjectIterator()
- throws Exception {
- String s = new String("atomic");
- Iterator i = null;
- i = IteratorFactory.createIterator(s);
+ public void testAtomicObjectIterator() {
+ String s = "atomic";
+ Iterator i = IteratorFactory.createIterator(s);
assertTrue(i instanceof AtomicObjectIterator);
assertNotNull(i);
i = IteratorFactory.createIterator(null);
-
assertNull(i);
}
+ public void testResultSetIterator() {
+ ResultSet rs = ResultSetTestSupport.getResultSet();
+ Iterator iterator = IteratorFactory.createIterator(rs);
+
+ assertNotNull(iterator);
+ assertTrue(iterator.hasNext());
+
+ Map map = (Map)iterator.next();
+ assertNotNull(map);
+ assertEquals("bob", map.get("name"));
+ assertEquals(1, map.get("id"));
+ assertTrue(iterator.hasNext());
+
+ int rowCount = 1;
+ while(iterator.hasNext()) {
+ map = (Map)iterator.next();
+ rowCount++;
+ }
+
+ assertNotNull(map);
+ assertEquals("harry", map.get("name"));
+ assertEquals(6, map.get("id"));
+ assertFalse(iterator.hasNext());
+
+ assertEquals(6, rowCount);
+ }
+
public IteratorFactoryTest(String name) {
super(name);
}
@@ -70,6 +94,7 @@
}
protected void setUp() {
+ TestConfigUtil.testInit();
}
protected void tearDown() {
Added:
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/iterator/ResultSetTestSupport.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/iterator/ResultSetTestSupport.java?view=auto&rev=156432
==============================================================================
---
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/iterator/ResultSetTestSupport.java
(added)
+++
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/iterator/ResultSetTestSupport.java
Mon Mar 7 08:11:05 2005
@@ -0,0 +1,140 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.netui.test.util.iterator;
+
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.lang.reflect.Proxy;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ *
+ */
+final class ResultSetTestSupport {
+
+ static final ResultSet getResultSet() {
+ MockResultSet rs = new MockResultSet();
+ return (ResultSet)
Proxy.newProxyInstance(rs.getClass().getClassLoader(),
+ new Class[]{ResultSet.class},
+ rs);
+ }
+
+ private static final ResultSetMetaData getResultSetMetaData() {
+ MockResultSetMetaData rsmd = new MockResultSetMetaData();
+ return (ResultSetMetaData)
Proxy.newProxyInstance(rsmd.getClass().getClassLoader(),
+ new Class[]{ResultSetMetaData.class},
+ rsmd);
+ }
+
+ static class MockResultSet
+ implements InvocationHandler {
+
+ private static List<CustomerBean> DATA = new ArrayList<CustomerBean>();
+
+ static {
+ DATA.add(new CustomerBean(1, "bob"));
+ DATA.add(new CustomerBean(2, "frank"));
+ DATA.add(new CustomerBean(3, "joe"));
+ DATA.add(new CustomerBean(4, "tom"));
+ DATA.add(new CustomerBean(5, "dick"));
+ DATA.add(new CustomerBean(6, "harry"));
+ }
+
+ private int _row = -1;
+ private ResultSetMetaData _rsmd =
ResultSetTestSupport.getResultSetMetaData();
+
+ public Object invoke(Object proxy, Method method, Object[] args)
+ throws Throwable {
+
+ String methodName = method.getName();
+ if (methodName.equals("getMetaData"))
+ return _rsmd;
+ else if(methodName.equals("isLast"))
+ return _row+1 == DATA.size();
+ else if(methodName.equals("wasNull"))
+ return false;
+ else if(methodName.equals("getObject")) {
+ int col = (Integer)args[0];
+ /* the order of the indices here must match the order of the
COLUMN_NAMES in the metadata */
+ if(col == 1)
+ return DATA.get(_row).getName();
+ else if(col == 2)
+ return DATA.get(_row).getId();
+ else throw new SQLException("Invalid column value \"" + col +
"\"");
+ }
+ else if(methodName.equals("next")) {
+ _row++;
+ return _row < DATA.size();
+ }
+ else throw new UnsupportedOperationException("Can not invoke the
method \"" + methodName + "\" as it is not supported");
+ }
+ }
+
+ static class MockResultSetMetaData
+ implements InvocationHandler {
+
+ private static final int COLUMN_COUNT = 2;
+ private static final String[] COLUMN_NAMES = new String[] {"NAME",
"ID"};
+
+ private int _index = 0;
+
+ public Object invoke(Object proxy, Method method, Object[] args)
+ throws Throwable {
+
+ String methodName = method.getName();
+ if (methodName.equals("getColumnCount"))
+ return COLUMN_COUNT;
+ else if(methodName.equals("getColumnName")) {
+ int col = (Integer)args[0];
+ return COLUMN_NAMES[col-1];
+ }
+ else throw new UnsupportedOperationException("Can not invoke the
method \"" + methodName + "\" as it is not supported");
+ }
+ }
+
+ static class CustomerBean {
+
+ private Integer _id;
+ private String _name;
+
+ CustomerBean(int id, String name) {
+ _id = new Integer(id);
+ _name = name;
+ }
+
+ public Integer getId() {
+ return _id;
+ }
+
+ public void setId(Integer id) {
+ _id = id;
+ }
+
+ public String getName() {
+ return _name;
+ }
+
+ public void setName(String name) {
+ _name = name;
+ }
+ }
+}
Propchange:
incubator/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/util/iterator/ResultSetTestSupport.java
------------------------------------------------------------------------------
svn:eol-style = native