harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r535252 - in /harmony/enhanced/classlib/trunk/modules/sql/src: main/java/javax/sql/rowset/serial/ test/java/org/apache/harmony/sql/tests/javax/sql/rowset/ test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/
Date Fri, 04 May 2007 14:21:05 GMT
Author: tellison
Date: Fri May  4 07:21:05 2007
New Revision: 535252

URL: http://svn.apache.org/viewvc?view=rev&rev=535252
Log:
Apply patch HARMONY-3810 ([classlib] [sql] Implementation and tests for javax.sql.rowset.serial.SQLInputImpl)

Added:
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/MockArray.java   (with props)
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/MockBlob.java   (with props)
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/MockClob.java   (with props)
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/MockRef.java   (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SQLInputImpl.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/BaseRowSetTest.java
    harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SQLInputImplTest.java

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SQLInputImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SQLInputImpl.java?view=diff&rev=535252&r1=535251&r2=535252
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SQLInputImpl.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/serial/SQLInputImpl.java Fri May  4 07:21:05 2007
@@ -26,113 +26,403 @@
 import java.sql.Clob;
 import java.sql.Date;
 import java.sql.Ref;
+import java.sql.SQLData;
 import java.sql.SQLException;
 import java.sql.SQLInput;
+import java.sql.Struct;
 import java.sql.Time;
 import java.sql.Timestamp;
 import java.util.Map;
 
 import org.apache.harmony.luni.util.NotImplementedException;
+import org.apache.harmony.sql.internal.nls.Messages;
 
+/**
+ * A concrete implementation of SQLInput. The readXXX methods will be called
+ * by SQLData.readSQL, which read different objects such as Array, BigDecimal
+ * from this SQLInputImpl object.
+ * 
+ * Different JDBC drivers may have their own implementation of SQLInput and
+ * won't use this class.
+ */
 public class SQLInputImpl implements SQLInput {
-    public SQLInputImpl(Object[] attributes, Map<String,Class<?>> map) throws SQLException, NotImplementedException {
-    }
-
-    public Array readArray() throws SQLException, NotImplementedException {
-        throw new NotImplementedException();
-    }
-
-    public InputStream readAsciiStream() throws SQLException,
-            NotImplementedException {
-        throw new NotImplementedException();
-    }
-
-    public BigDecimal readBigDecimal() throws SQLException,
-            NotImplementedException {
-        throw new NotImplementedException();
-    }
-
-    public InputStream readBinaryStream() throws SQLException,
-            NotImplementedException {
-        throw new NotImplementedException();
-    }
-
-    public Blob readBlob() throws SQLException, NotImplementedException {
-        throw new NotImplementedException();
-    }
-
+    
+    private Object[] attributes;
+    private Map<String,Class<?>> map;
+    private int readPosition = 0;
+    
+    /**
+     * Constructs a new SQLInputImpl object using an array of attributes and a
+     * custom name-type map. 
+     * 
+     * @param attributes -
+     *            the array of given attribute objects.
+     * @param map -
+     *            the UDT(user defined type) name-type map
+     * @throws SQLException -
+     *             if the attributes or the map is null
+     */
+    public SQLInputImpl(Object[] attributes, Map<String,Class<?>> map)throws SQLException {
+        if (null == attributes || null == map) {
+            throw new SQLException(Messages.getString("sql.34")); //$NON-NLS-1$
+        }
+        this.attributes = attributes;
+        this.map = map;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLInput#readArray()
+     */
+    public Array readArray() throws SQLException {
+        if(readPosition >= attributes.length) {
+            throw new SQLException(Messages.getString("sql.35"));
+        }
+        Object o = attributes[readPosition++];
+        if(o == null) {
+            return null;
+        }
+        return (Array) o;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLInput#readAsciiStream()
+     */
+    public InputStream readAsciiStream() throws SQLException {
+        if(readPosition >= attributes.length) {
+            throw new SQLException(Messages.getString("sql.35"));
+        }
+        Object o = attributes[readPosition++];
+        if(o == null) {
+            return null;
+        }
+        return (InputStream) o;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLInput#readBigDecimal()
+     */
+    public BigDecimal readBigDecimal() throws SQLException {
+        if(readPosition >= attributes.length) {
+            throw new SQLException(Messages.getString("sql.35"));
+        }
+        Object o = attributes[readPosition++];
+        if(o == null) {
+            return null;
+        }
+        return (BigDecimal) o;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLInput#readBinaryStream()
+     */
+    public InputStream readBinaryStream() throws SQLException {
+        if(readPosition >= attributes.length) {
+            throw new SQLException(Messages.getString("sql.35"));
+        }
+        Object o = attributes[readPosition++];
+        if(o == null) {
+            return null;
+        }
+        return (InputStream) o;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLInput#readBlob()
+     */
+    public Blob readBlob() throws SQLException {
+        if(readPosition >= attributes.length) {
+            throw new SQLException(Messages.getString("sql.35"));
+        }
+        Object o = attributes[readPosition++];
+        if(o == null) {
+            return null;
+        }
+        return (Blob) o;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLInput#readBoolean()
+     */
     public boolean readBoolean() throws SQLException, NotImplementedException {
-        throw new NotImplementedException();
-    }
-
-    public byte readByte() throws SQLException, NotImplementedException {
-        throw new NotImplementedException();
-    }
-
-    public byte[] readBytes() throws SQLException, NotImplementedException {
-        throw new NotImplementedException();
-    }
-
-    public Reader readCharacterStream() throws SQLException,
-            NotImplementedException {
-        throw new NotImplementedException();
-    }
-
-    public Clob readClob() throws SQLException, NotImplementedException {
-        throw new NotImplementedException();
-    }
-
-    public Date readDate() throws SQLException, NotImplementedException {
-        throw new NotImplementedException();
-    }
-
-    public double readDouble() throws SQLException, NotImplementedException {
-        throw new NotImplementedException();
-    }
-
-    public float readFloat() throws SQLException, NotImplementedException {
-        throw new NotImplementedException();
-    }
-
-    public int readInt() throws SQLException, NotImplementedException {
-        throw new NotImplementedException();
-    }
-
-    public long readLong() throws SQLException, NotImplementedException {
-        throw new NotImplementedException();
-    }
-
-    public Object readObject() throws SQLException, NotImplementedException {
-        throw new NotImplementedException();
-    }
-
-    public Ref readRef() throws SQLException, NotImplementedException {
-        throw new NotImplementedException();
-    }
-
-    public short readShort() throws SQLException, NotImplementedException {
-        throw new NotImplementedException();
-    }
-
-    public String readString() throws SQLException, NotImplementedException {
-        throw new NotImplementedException();
-    }
-
-    public Time readTime() throws SQLException, NotImplementedException {
-        throw new NotImplementedException();
-    }
-
-    public Timestamp readTimestamp() throws SQLException,
-            NotImplementedException {
-        throw new NotImplementedException();
-    }
-
-    public URL readURL() throws SQLException, NotImplementedException {
-        throw new NotImplementedException();
-    }
-
+        if(readPosition >= attributes.length) {
+            throw new SQLException(Messages.getString("sql.35"));
+        }
+        Object o = attributes[readPosition++];
+        return (Boolean) o;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLInput#readByte()
+     */
+    public byte readByte() throws SQLException {
+        if(readPosition >= attributes.length) {
+            throw new SQLException(Messages.getString("sql.35"));
+        }
+        Object o = attributes[readPosition++];
+        return (Byte) o;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLInput#readBytes()
+     */
+    public byte[] readBytes() throws SQLException {
+        if(readPosition >= attributes.length) {
+            throw new SQLException(Messages.getString("sql.35"));
+        }
+        Object o = attributes[readPosition++];
+        if(o == null) {
+            return null;
+        }
+        return (byte[]) o;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLInput#readCharacterStream()
+     */
+    public Reader readCharacterStream() throws SQLException {
+        if(readPosition >= attributes.length) {
+            throw new SQLException(Messages.getString("sql.35"));
+        }
+        Object o = attributes[readPosition++];
+        if(o == null) {
+            return null;
+        }
+        return (Reader) o;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLInput#readClob()
+     */
+    public Clob readClob() throws SQLException {
+        if(readPosition >= attributes.length) {
+            throw new SQLException(Messages.getString("sql.35"));
+        }
+        Object o = attributes[readPosition++];
+        if(o == null) {
+            return null;
+        }
+        return (Clob) o;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLInput#readDate()
+     */
+    public Date readDate() throws SQLException {
+        if(readPosition >= attributes.length) {
+            throw new SQLException(Messages.getString("sql.35"));
+        }
+        Object o = attributes[readPosition++];
+        if(o == null) {
+            return null;
+        }
+        return (Date) o;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLInput#readDouble()
+     */
+    public double readDouble() throws SQLException {
+        if(readPosition >= attributes.length) {
+            throw new SQLException(Messages.getString("sql.35"));
+        }
+        Object o = attributes[readPosition++];
+        return (Double) o;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLInput#readFloat()
+     */
+    public float readFloat() throws SQLException {
+        if(readPosition >= attributes.length) {
+            throw new SQLException(Messages.getString("sql.35"));
+        }
+        Object o = attributes[readPosition++];
+        return (Float) o;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLInput#readInt()
+     */
+    public int readInt() throws SQLException {
+        if(readPosition >= attributes.length) {
+            throw new SQLException(Messages.getString("sql.35"));
+        }
+        Object o = attributes[readPosition++];
+        return (Integer) o;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLInput#readLong()
+     */
+    public long readLong() throws SQLException {
+        if(readPosition >= attributes.length) {
+            throw new SQLException(Messages.getString("sql.35"));
+        }
+        Object o = attributes[readPosition++];
+        return (Long) o;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLInput#readObject()
+     */
+    public Object readObject() throws SQLException {
+        if(readPosition >= attributes.length) {
+            throw new SQLException(Messages.getString("sql.35"));
+        }
+        Object o = attributes[readPosition++];
+        if (o instanceof Struct) {
+            Struct structuredType = (Struct)o;
+            String typeName = structuredType.getSQLTypeName();
+            Class c = map.get(typeName);
+            if(c != null) {
+                try {
+                    SQLData data = (SQLData)c.newInstance();
+                    SQLInputImpl input = new SQLInputImpl(structuredType.getAttributes(), map);
+                    data.readSQL(input, typeName);
+                    return data;
+                } catch (IllegalAccessException e) {
+                    throw new SQLException(e.getMessage());
+                } catch (InstantiationException e) {
+                    throw new SQLException(e.getMessage());
+                }
+                
+            }
+        }
+        return o;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLInput#readRef()
+     */
+    public Ref readRef() throws SQLException {
+        if(readPosition >= attributes.length) {
+            throw new SQLException(Messages.getString("sql.35"));
+        }
+        Object o = attributes[readPosition++];
+        if(o == null) {
+            return null;
+        }
+        return (Ref) o;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLInput#readShort()
+     */
+    public short readShort() throws SQLException {
+        if(readPosition >= attributes.length) {
+            throw new SQLException(Messages.getString("sql.35"));
+        }
+        Object o = attributes[readPosition++];
+        return (Short) o;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLInput#readString()
+     */
+    public String readString() throws SQLException {
+        if(readPosition >= attributes.length) {
+            throw new SQLException(Messages.getString("sql.35"));
+        }
+        Object o = attributes[readPosition++];
+        if(o == null) {
+            return null;
+        }
+        return (String) o;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLInput#readTime()
+     */
+    public Time readTime() throws SQLException {
+        if(readPosition >= attributes.length) {
+            throw new SQLException(Messages.getString("sql.35"));
+        }
+        Object o = attributes[readPosition++];
+        if(o == null) {
+            return null;
+        }
+        return (Time) o;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLInput#readTimestamp()
+     */
+    public Timestamp readTimestamp() throws SQLException {
+        if(readPosition >= attributes.length) {
+            throw new SQLException(Messages.getString("sql.35"));
+        }
+        Object o = attributes[readPosition++];
+        if(o == null) {
+            return null;
+        }
+        return (Timestamp) o;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLInput#readURL()
+     */
+    public URL readURL() throws SQLException {
+        if(readPosition >= attributes.length) {
+            throw new SQLException(Messages.getString("sql.35"));
+        } else {
+            throw new SQLException(Messages.getString("sql.37"));
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see java.sql.SQLInput#wasNull()
+     */
     public boolean wasNull() throws SQLException, NotImplementedException {
-        throw new NotImplementedException();
+        if(readPosition > attributes.length) {
+            throw new SQLException(Messages.getString("sql.35"));
+        }
+        return attributes[readPosition - 1] == null;
     }
 
 }

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/BaseRowSetTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/BaseRowSetTest.java?view=diff&rev=535252&r1=535251&r2=535252
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/BaseRowSetTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/BaseRowSetTest.java Fri May  4 07:21:05 2007
@@ -17,20 +17,12 @@
 
 package org.apache.harmony.sql.tests.javax.sql.rowset;
 
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.StringReader;
-import java.io.Writer;
 import java.sql.Array;
 import java.sql.Blob;
 import java.sql.Clob;
 import java.sql.Ref;
-import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Types;
-import java.util.Map;
 
 import javax.sql.rowset.BaseRowSet;
 import javax.sql.rowset.serial.SerialArray;
@@ -225,159 +217,5 @@
             super.initParams();
         }
     }
-    
-    static class MockArray implements Array {
-
-        public Object getArray() throws SQLException {
-            return new Object[0];
-        }
-
-        public Object getArray(long index, int count) throws SQLException {
-            return null;
-        }
-
-        public Object getArray(long index, int count, Map<String, Class<?>> map)
-                throws SQLException {
-            return null;
-        }
-
-        public Object getArray(Map<String, Class<?>> map) throws SQLException {
-            return null;
-        }
-
-        public int getBaseType() throws SQLException {
-            return 0;
-        }
-
-        public String getBaseTypeName() throws SQLException {
-            return null;
-        }
-
-        public ResultSet getResultSet() throws SQLException {
-            return null;
-        }
 
-        public ResultSet getResultSet(long index, int count)
-                throws SQLException {
-            return null;
-        }
-
-        public ResultSet getResultSet(long index, int count,
-                Map<String, Class<?>> map) throws SQLException {
-            return null;
-        }
-
-        public ResultSet getResultSet(Map<String, Class<?>> map)
-                throws SQLException {
-            return null;
-        }
-
-    }
-    
-    static class MockBlob implements Blob {
-
-        public InputStream getBinaryStream() throws SQLException {
-            return null;
-        }
-
-        public byte[] getBytes(long pos, int length) throws SQLException {
-            return new byte[0];
-        }
-
-        public long length() throws SQLException {
-            return 0;
-        }
-
-        public long position(Blob pattern, long start) throws SQLException {
-            return 0;
-        }
-
-        public long position(byte[] pattern, long start) throws SQLException {
-            return 0;
-        }
-
-        public OutputStream setBinaryStream(long pos) throws SQLException {
-            return null;
-        }
-
-        public int setBytes(long pos, byte[] theBytes) throws SQLException {
-            return 0;
-        }
-
-        public int setBytes(long pos, byte[] theBytes, int offset, int len)
-                throws SQLException {
-            return 0;
-        }
-
-        public void truncate(long len) throws SQLException {
-        }
-    }
-    
-    static class MockClob implements Clob {
-        
-        public Reader characterStreamReader = new StringReader("xys");
-        public InputStream asciiInputStream = new ByteArrayInputStream("hello".getBytes());
-        
-        public InputStream getAsciiStream() throws SQLException {
-            return asciiInputStream;
-        }
-
-        public Reader getCharacterStream() throws SQLException {
-            return characterStreamReader;
-        }
-
-        public String getSubString(long pos, int length) throws SQLException {
-            return null;
-        }
-
-        public long length() throws SQLException {
-            return 3;
-        }
-
-        public long position(Clob searchstr, long start) throws SQLException {
-            return 0;
-        }
-
-        public long position(String searchstr, long start) throws SQLException {
-            return 0;
-        }
-
-        public OutputStream setAsciiStream(long pos) throws SQLException {
-            return null;
-        }
-
-        public Writer setCharacterStream(long pos) throws SQLException {
-            return null;
-        }
-
-        public int setString(long pos, String str) throws SQLException {
-            return 0;
-        }
-
-        public int setString(long pos, String str, int offset, int len)
-                throws SQLException {
-            return 0;
-        }
-
-        public void truncate(long len) throws SQLException {
-        }
-    }
-
-    public class MockRef implements Ref {
-
-        public String getBaseTypeName() throws SQLException {
-            return "ref";
-        }
-
-        public Object getObject() throws SQLException {
-            return null;
-        }
-
-        public Object getObject(Map<String, Class<?>> map) throws SQLException {
-            return null;
-        }
-
-        public void setObject(Object value) throws SQLException {
-        }
-    }
 }

Added: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/MockArray.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/MockArray.java?view=auto&rev=535252
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/MockArray.java (added)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/MockArray.java Fri May  4 07:21:05 2007
@@ -0,0 +1,73 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.
+ */
+package org.apache.harmony.sql.tests.javax.sql.rowset;
+
+import java.sql.Array;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Map;
+
+public class MockArray implements Array {
+
+    public Object getArray() throws SQLException {
+        return new Object[0];
+    }
+
+    public Object getArray(long index, int count) throws SQLException {
+        return null;
+    }
+
+    public Object getArray(long index, int count, Map<String, Class<?>> map)
+            throws SQLException {
+        return null;
+    }
+
+    public Object getArray(Map<String, Class<?>> map) throws SQLException {
+        return null;
+    }
+
+    public int getBaseType() throws SQLException {
+        return 0;
+    }
+
+    public String getBaseTypeName() throws SQLException {
+        return "base";
+    }
+
+    public ResultSet getResultSet() throws SQLException {
+        return null;
+    }
+
+    public ResultSet getResultSet(long index, int count)
+            throws SQLException {
+        return null;
+    }
+
+    public ResultSet getResultSet(long index, int count,
+            Map<String, Class<?>> map) throws SQLException {
+        return null;
+    }
+
+    public ResultSet getResultSet(Map<String, Class<?>> map)
+            throws SQLException {
+        return null;
+    }
+
+    public void free() throws SQLException {
+    }
+
+}
\ No newline at end of file

Propchange: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/MockArray.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/MockBlob.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/MockBlob.java?view=auto&rev=535252
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/MockBlob.java (added)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/MockBlob.java Fri May  4 07:21:05 2007
@@ -0,0 +1,68 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.
+ */
+package org.apache.harmony.sql.tests.javax.sql.rowset;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.sql.Blob;
+import java.sql.SQLException;
+
+public class MockBlob implements Blob {
+
+    public InputStream getBinaryStream() throws SQLException {
+        return null;
+    }
+
+    public byte[] getBytes(long pos, int length) throws SQLException {
+        return new byte[0];
+    }
+
+    public long length() throws SQLException {
+        return 0;
+    }
+
+    public long position(Blob pattern, long start) throws SQLException {
+        return 0;
+    }
+
+    public long position(byte[] pattern, long start) throws SQLException {
+        return 0;
+    }
+
+    public OutputStream setBinaryStream(long pos) throws SQLException {
+        return null;
+    }
+
+    public int setBytes(long pos, byte[] theBytes) throws SQLException {
+        return 0;
+    }
+
+    public int setBytes(long pos, byte[] theBytes, int offset, int len)
+            throws SQLException {
+        return 0;
+    }
+
+    public void truncate(long len) throws SQLException {
+    }
+
+    public void free() throws SQLException {
+    }
+
+    public InputStream getBinaryStream(long pos, long length) throws SQLException {
+        return null;
+    }
+}
\ No newline at end of file

Propchange: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/MockBlob.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/MockClob.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/MockClob.java?view=auto&rev=535252
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/MockClob.java (added)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/MockClob.java Fri May  4 07:21:05 2007
@@ -0,0 +1,83 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.
+ */
+package org.apache.harmony.sql.tests.javax.sql.rowset;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.Writer;
+import java.sql.Clob;
+import java.sql.SQLException;
+
+public class MockClob implements Clob {
+
+    public Reader characterStreamReader = new StringReader("xys");
+    public InputStream asciiInputStream = new ByteArrayInputStream("hello".getBytes());
+
+    public InputStream getAsciiStream() throws SQLException {
+        return asciiInputStream;
+    }
+
+    public Reader getCharacterStream() throws SQLException {
+        return characterStreamReader;
+    }
+
+    public String getSubString(long pos, int length) throws SQLException {
+        return null;
+    }
+
+    public long length() throws SQLException {
+        return 3;
+    }
+
+    public long position(Clob searchstr, long start) throws SQLException {
+        return 0;
+    }
+
+    public long position(String searchstr, long start) throws SQLException {
+        return 0;
+    }
+
+    public OutputStream setAsciiStream(long pos) throws SQLException {
+        return null;
+    }
+
+    public Writer setCharacterStream(long pos) throws SQLException {
+        return null;
+    }
+
+    public int setString(long pos, String str) throws SQLException {
+        return 0;
+    }
+
+    public int setString(long pos, String str, int offset, int len)
+            throws SQLException {
+        return 0;
+    }
+
+    public void truncate(long len) throws SQLException {
+    }
+
+    public void free() throws SQLException {
+    }
+
+    public Reader getCharacterStream(long pos, long length) throws SQLException {
+        return null;
+    }
+}
\ No newline at end of file

Propchange: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/MockClob.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/MockRef.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/MockRef.java?view=auto&rev=535252
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/MockRef.java (added)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/MockRef.java Fri May  4 07:21:05 2007
@@ -0,0 +1,39 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.
+ */
+package org.apache.harmony.sql.tests.javax.sql.rowset;
+
+import java.sql.Ref;
+import java.sql.SQLException;
+import java.util.Map;
+
+public class MockRef implements Ref {
+
+    public String getBaseTypeName() throws SQLException {
+        return "ref";
+    }
+
+    public Object getObject() throws SQLException {
+        return null;
+    }
+
+    public Object getObject(Map<String, Class<?>> map) throws SQLException {
+        return null;
+    }
+
+    public void setObject(Object value) throws SQLException {
+    }
+}
\ No newline at end of file

Propchange: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/MockRef.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SQLInputImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SQLInputImplTest.java?view=diff&rev=535252&r1=535251&r2=535252
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SQLInputImplTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SQLInputImplTest.java Fri May  4 07:21:05 2007
@@ -17,100 +17,513 @@
 
 package org.apache.harmony.sql.tests.javax.sql.rowset.serial;
 
-import junit.framework.TestCase;
-
-public class SQLInputImplTest extends TestCase {
-
-    public void testReadArray() {
-
-    }
-
-    public void testReadAsciiStream() {
-
-    }
-
-    public void testReadBigDecimal() {
-
-    }
-
-    public void testReadBinaryStream() {
-
-    }
-
-    public void testReadBlob() {
-
-    }
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.StringReader;
+import java.math.BigDecimal;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Date;
+import java.sql.Ref;
+import java.sql.SQLData;
+import java.sql.SQLException;
+import java.sql.SQLInput;
+import java.sql.SQLOutput;
+import java.sql.Struct;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.HashMap;
+import java.util.Map;
 
-    public void testReadBoolean() {
-
-    }
-
-    public void testReadByte() {
-
-    }
-
-    public void testReadBytes() {
-
-    }
-
-    public void testReadCharacterStream() {
-
-    }
-
-    public void testReadClob() {
-
-    }
-
-    public void testReadDate() {
-
-    }
+import javax.sql.rowset.serial.SQLInputImpl;
 
-    public void testReadDouble() {
-
-    }
-
-    public void testReadFloat() {
-
-    }
-
-    public void testReadInt() {
-
-    }
-
-    public void testReadLong() {
-
-    }
-
-    public void testReadObject() {
-
-    }
-
-    public void testReadRef() {
-
-    }
-
-    public void testReadShort() {
-
-    }
-
-    public void testReadString() {
-
-    }
-
-    public void testReadTime() {
-
-    }
-
-    public void testReadTimestamp() {
-
-    }
-
-    public void testReadURL() {
+import junit.framework.TestCase;
 
-    }
+import org.apache.harmony.sql.tests.javax.sql.rowset.MockArray;
+import org.apache.harmony.sql.tests.javax.sql.rowset.MockBlob;
+import org.apache.harmony.sql.tests.javax.sql.rowset.MockClob;
+import org.apache.harmony.sql.tests.javax.sql.rowset.MockRef;
 
-    public void testWasNull() {
+public class SQLInputImplTest extends TestCase {
 
+    
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLInputImpl#SQLInputImpl(Object[], Map)}
+     */
+    @SuppressWarnings("unchecked")
+    public void test_Constructor() {
+        
+        try {
+            new SQLInputImpl(null, new HashMap());
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        
+        try {
+            new SQLInputImpl(null, null);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        
+        try {
+            new SQLInputImpl(new Object[0], null);
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+    
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLInputImpl#readArray()}
+     */
+    public void testReadArray() throws SQLException {
+        Array array = new MockArray();
+        Object[] attributes = new Object[] {array};
+        SQLInputImpl impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>());
+        assertEquals(array, impl.readArray());
+        
+        try {
+            impl.readArray();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLInputImpl#readAsciiStream()}
+     */
+    public void testReadAsciiStream() throws SQLException {
+        InputStream stream = new ByteArrayInputStream("abc".getBytes());
+        Object[] attributes = new Object[] {stream};
+        SQLInputImpl impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>());
+        assertEquals(stream, impl.readAsciiStream());
+        
+        try {
+            impl.readAsciiStream();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLInputImpl#readBigDecimal()}
+     */
+    public void testReadBigDecimal() throws SQLException {
+        BigDecimal bd = new BigDecimal("12.5");
+        Object[] attributes = new Object[] {bd};
+        SQLInputImpl impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>());
+        assertEquals(bd, impl.readBigDecimal());
+        
+        try {
+            impl.readBigDecimal();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLInputImpl#readBinaryStream()}
+     */
+    public void testReadBinaryStream() throws SQLException {
+        InputStream stream = new ByteArrayInputStream("abc".getBytes());
+        Object[] attributes = new Object[] {stream};
+        SQLInputImpl impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>());
+        assertEquals(stream, impl.readBinaryStream());
+    }
+
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLInputImpl#readBlob()}
+     */
+    public void testReadBlob() throws SQLException {
+        Blob blob = new MockBlob();
+        Object[] attributes = new Object[] {blob};
+        SQLInputImpl impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>());
+        assertEquals(blob, impl.readBlob());
+        
+        try {
+            impl.readBlob();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLInputImpl#readBoolean()}
+     */
+    public void testReadBoolean() throws SQLException {
+        Object[] attributes = new Object[] {Boolean.TRUE};
+        SQLInputImpl impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>());
+        assertEquals(true, impl.readBoolean());
+        
+        try {
+            impl.readBoolean();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLInputImpl#readByte()}
+     */
+    public void testReadByte() throws SQLException {
+        Object[] attributes = new Object[] {Byte.valueOf("3")};
+        SQLInputImpl impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>());
+        assertEquals((byte)3, impl.readByte());
+        
+        try {
+            impl.readByte();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLInputImpl#readBytes()}
+     */
+    public void testReadBytes() throws SQLException {
+        byte[] bytes = new byte[] {1, 2, 3};
+        Object[] attributes = new Object[] {bytes};
+        SQLInputImpl impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>());
+        assertEquals(bytes, impl.readBytes());
+        
+        try {
+            impl.readBytes();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLInputImpl#readCharacterStream()}
+     */
+    public void testReadCharacterStream() throws SQLException {
+        Reader stream = new StringReader("abc");
+        Object[] attributes = new Object[] {stream};
+        SQLInputImpl impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>());
+        assertEquals(stream, impl.readCharacterStream());
+        
+        try {
+            impl.readCharacterStream();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLInputImpl#readClob()}
+     */
+    public void testReadClob() throws SQLException {
+        Clob clob = new MockClob();
+        Object[] attributes = new Object[] {clob};
+        SQLInputImpl impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>());
+        assertEquals(clob, impl.readClob());
+        
+        try {
+            impl.readClob();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLInputImpl#readDate()}
+     */
+    public void testReadDate() throws SQLException {
+        Date date = new Date(12);
+        Object[] attributes = new Object[] {date};
+        SQLInputImpl impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>());
+        assertEquals(date, impl.readDate());
+        
+        try {
+            impl.readDate();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLInputImpl#readDouble()}
+     */
+    public void testReadDouble() throws SQLException {
+        Object[] attributes = new Object[] {Double.valueOf("3")};
+        SQLInputImpl impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>());
+        assertEquals((double)3, impl.readDouble());
+        
+        try {
+            impl.readDouble();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLInputImpl#readFloat()}
+     */
+    public void testReadFloat() throws SQLException {
+        Object[] attributes = new Object[] {Float.valueOf("3.5")};
+        SQLInputImpl impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>());
+        assertEquals((float)3.5, impl.readFloat());
+        
+        try {
+            impl.readFloat();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLInputImpl#readInt()}
+     */
+    public void testReadInt() throws SQLException {
+        Object[] attributes = new Object[] {Integer.valueOf("3")};
+        SQLInputImpl impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>());
+        assertEquals(3, impl.readInt());
+        
+        try {
+            impl.readInt();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLInputImpl#readLong()}
+     */
+    public void testReadLong() throws SQLException {
+        Object[] attributes = new Object[] {Long.valueOf("3")};
+        SQLInputImpl impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>());
+        assertEquals((long)3, impl.readLong());
+        
+        try {
+            impl.readLong();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLInputImpl#readObject()}
+     */
+    public void testReadObject() throws SQLException {
+        Object[] structAttributes = {"hello", Boolean.TRUE, "abc", Integer.valueOf(99)};
+        Struct struct = new MockStruct(structAttributes, "harmonytests.MockSQLData");
+        Struct struct2 = new MockStruct(structAttributes, "not stored name");
+        HashMap<String, Class<?>> types = new HashMap<String, Class<?>>();
+        types.put("harmonytests.MockSQLData", MockSQLData.class);
+        Object[] attributes = new Object[] {struct, struct2, null, "xyz"};
+        SQLInputImpl impl = new SQLInputImpl(attributes, types);
+        Object obj = impl.readObject();
+        assertTrue(obj instanceof MockSQLData);
+        MockSQLData sqlData = (MockSQLData)obj;
+        assertEquals(structAttributes[0], sqlData.firstAttribute);
+        assertEquals(structAttributes[1], sqlData.secondAttribute);
+        assertEquals(structAttributes[2], sqlData.thirdAttribute);
+        assertEquals(structAttributes[3], sqlData.fourthAttribute);        
+        Object obj2 = impl.readObject();
+        assertEquals(struct2, obj2);
+        Object obj3 = impl.readObject();
+        assertNull(obj3);
+        Object obj4 = impl.readObject();
+        assertEquals(attributes[3], obj4);        
+    }
+
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLInputImpl#readRef()}
+     */
+    public void testReadRef() throws SQLException {
+        Ref ref = new MockRef();
+        Object[] attributes = new Object[] {ref};
+        SQLInputImpl impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>());
+        assertEquals(ref, impl.readRef());
+        
+        try {
+            impl.readRef();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLInputImpl#readShort()}
+     */
+    public void testReadShort() throws SQLException {
+        Object[] attributes = new Object[] {Short.valueOf("3")};
+        SQLInputImpl impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>());
+        assertEquals((short)3, impl.readShort());
+        
+        try {
+            impl.readShort();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLInputImpl#readString()}
+     */
+    public void testReadString() throws SQLException {
+        Object[] attributes = new Object[] {"hello"};
+        SQLInputImpl impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>());
+        assertEquals("hello", impl.readString());
+        
+        try {
+            impl.readString();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLInputImpl#readTime()}
+     */
+    public void testReadTime() throws SQLException {
+        Time time = new Time(345);
+        Object[] attributes = new Object[] {time};
+        SQLInputImpl impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>());
+        assertEquals(time, impl.readTime());
+        
+        try {
+            impl.readTime();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLInputImpl#readTimestamp()}
+     */
+    public void testReadTimestamp() throws SQLException {
+        Timestamp time = new Timestamp(345);
+        Object[] attributes = new Object[] {time};
+        SQLInputImpl impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>());
+        assertEquals(time, impl.readTimestamp());
+        
+        try {
+            impl.readTimestamp();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLInputImpl#readURL()}
+     */
+    public void testReadURL() throws SQLException, MalformedURLException {
+        URL url = new URL("http://www.apache.org");
+        Object[] attributes = new Object[] {url};
+        SQLInputImpl impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>());
+        try {
+            impl.readURL();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        
+        try {
+            impl.readURL();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+    }
+
+    /**
+     * @tests {@link javax.sql.rowset.serial.SQLInputImpl#wasNull()}
+     */
+    public void testWasNull() throws SQLException {
+        Object[] attributes = new Object[] {null, "hello"};
+        SQLInputImpl impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>());
+        assertEquals(null, impl.readString());
+        assertTrue(impl.wasNull());
+        assertEquals("hello", impl.readString());
+        assertFalse(impl.wasNull());
+        try {
+            impl.readString();
+            fail("should throw SQLException");
+        } catch (SQLException e) {
+            // expected
+        }
+        assertFalse(impl.wasNull());
+    }
+
+
+    /*
+     * Mock classes used by both this test and SQLOutputImplTest to test
+     * readObject and writeObject methods respectively.
+     */
+    
+    public static class MockStruct implements Struct {
+        
+        private String sqlTypeName;
+
+        public MockStruct(Object[] attributes, String sqlTypeName) {
+            this.attributes = attributes;
+            this.sqlTypeName = sqlTypeName;
+        }
+        
+        Object[] attributes;
+
+        public Object[] getAttributes() throws SQLException {
+            return attributes;
+        }
+
+        public Object[] getAttributes(Map<String, Class<?>> theMap) throws SQLException {
+            return attributes;
+        }
+
+        public String getSQLTypeName() throws SQLException {
+            return sqlTypeName;
+        }
+    }
+    
+    public static class MockSQLData implements SQLData {
+        
+        public String firstAttribute;
+        public Boolean secondAttribute;
+        public String thirdAttribute;
+        public Integer fourthAttribute;
+
+        public String getSQLTypeName() throws SQLException {
+            return "harmonytests.MockSQLData";
+        }
+
+        public void readSQL(SQLInput stream, String typeName) throws SQLException {
+            firstAttribute = stream.readString();
+            secondAttribute = stream.readBoolean();
+            thirdAttribute = stream.readString();
+            fourthAttribute = stream.readInt();
+        }
+
+        public void writeSQL(SQLOutput stream) throws SQLException {
+            stream.writeString(firstAttribute);
+            stream.writeBoolean(secondAttribute);
+            stream.writeString(thirdAttribute);
+            stream.writeInt(fourthAttribute);
+        }
     }
-
 }



Mime
View raw message