/* * Validate that readObject returns the correct value */ @Test() public void test05() throws Exception { Object[] values = {hero}; SQLInputImpl sqli = new SQLInputImpl(values, map); Object o = sqli.readObject(); assertTrue(hero.equals(o)); }
/** * @tests {@link javax.sql.rowset.serial.SQLInputImpl#readSQLXML()} * @since 1.6 */ public void testReadSQLXML() throws SQLException { SQLXML sqlXML = new MockSQLXML(); Object[] attributes = new Object[] {null, sqlXML}; SQLInputImpl impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>()); try { impl.readSQLXML(); fail("should throw UnsupportedOperationException"); } catch (UnsupportedOperationException e) { // expected } try { impl.readSQLXML(); fail("should throw UnsupportedOperationException"); } catch (UnsupportedOperationException e) { // expected } try { impl.readSQLXML(); fail("should throw UnsupportedOperationException"); } catch (UnsupportedOperationException e) { // expected } }
/* * Validate a Blob can be read */ @Test(enabled = true) public void test07() throws Exception { Blob b = new StubBlob(); Object[] values = {b}; SQLInputImpl sqli = new SQLInputImpl(values, map); Blob b2 = sqli.readBlob(); assertTrue(Arrays.equals(b.getBytes(1, (int) b.length()), b2.getBytes(1, (int) b2.length()))); }
/* * Validate a Clob can be read */ @Test(enabled = true) public void test08() throws Exception { Clob c = new StubClob(); Object[] values = {c}; SQLInputImpl sqli = new SQLInputImpl(values, map); Clob c2 = sqli.readClob(); assertTrue(c.getSubString(1, (int) c.length()).equals(c2.getSubString(1, (int) c2.length()))); }
/* * Validate a Ref can be read */ @Test(enabled = true) public void test09() throws Exception { Ref ref = new StubRef(sqlType, hero); Object[] values = {ref}; SQLInputImpl sqli = new SQLInputImpl(values, map); Ref ref2 = sqli.readRef(); assertTrue(ref.getObject().equals(ref2.getObject())); assertTrue(ref.getBaseTypeName().equals(ref2.getBaseTypeName())); }
/* * Validate a Array can be read */ @Test(enabled = true) public void test06() throws Exception { Object[] coffees = new Object[] {"Espresso", "Colombian", "French Roast", "Cappuccino"}; Array a = new StubArray("VARCHAR", coffees); Object[] values = {a}; SQLInputImpl sqli = new SQLInputImpl(values, map); Array a2 = sqli.readArray(); assertTrue(Arrays.equals((Object[]) a2.getArray(), (Object[]) a.getArray())); assertTrue(a.getBaseTypeName().equals(a2.getBaseTypeName())); }
/** @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()); attributes = new Object[] {null}; impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>()); assertNull(impl.readBinaryStream()); }
/* * Validate a URL can be read */ @Test(enabled = true) public void test10() throws Exception { URL u = new URL("http://www.oracle.com/"); ; Object[] values = {u}; SQLInputImpl sqli = new SQLInputImpl(values, map); URL u2 = sqli.readURL(); assertTrue(u2.equals(u)); assertTrue(u2.sameFile(u)); }
/* * Validate that readObject returns the correct value when a Struct is * next on the stream */ @Test() public void test11() throws Exception { Object[] attributes = new Object[] {"Bruce", "Wayne", 1939, "Batman"}; map.put(sqlType, Class.forName("util.SuperHero")); Struct struct = new StubStruct(sqlType, attributes); Object[] values = {struct}; SQLInputImpl sqli = new SQLInputImpl(values, map); Object o = sqli.readObject(); assertTrue(hero.equals(o)); }
/** @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#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 } attributes = new Object[] {null}; impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>()); assertEquals((short) 0, impl.readShort()); }
/** @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 } attributes = new Object[] {null}; impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>()); assertFalse(impl.readBoolean()); }
/** @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 } attributes = new Object[] {null}; impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>()); assertNull(impl.readString()); }
/** @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 } attributes = new Object[] {null}; impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>()); assertNull(impl.readAsciiStream()); }
/** @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 } attributes = new Object[] {null}; impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>()); assertNull(impl.readBytes()); }
/** @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 } attributes = new Object[] {null}; impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>()); assertNull(impl.readCharacterStream()); }
/** @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 } attributes = new Object[] {null}; impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>()); assertNull(impl.readArray()); }
/** @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 } attributes = new Object[] {null}; impl = new SQLInputImpl(attributes, new HashMap<String, Class<?>>()); assertNull(impl.readBigDecimal()); }
/** @tests {@link javax.sql.rowset.serial.SQLInputImpl#readURL()} */ public void testReadURL() throws SQLException, MalformedURLException { URL url = new URL("http://www.apache.org"); SerialDatalink link = new SerialDatalink(url); Object[] attributes = new Object[] {link}; 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 } }
/* * Validate that wasNull indicates if a null was read in */ @Test() public void test04() throws Exception { Object[] values = {"Hello", null, 1}; SQLInputImpl sqli = new SQLInputImpl(values, map); String s = sqli.readString(); assertFalse(sqli.wasNull()); s = sqli.readString(); assertTrue(sqli.wasNull()); int i = sqli.readInt(); assertFalse(sqli.wasNull()); }
/** @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); }