提交 69aee033 authored 作者: Thomas Mueller's avatar Thomas Mueller

Fix parameter order for assertEquals(expected, actual)

上级 6cf69f57
......@@ -8,6 +8,8 @@ package org.h2.test;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.sql.Connection;
......@@ -504,7 +506,7 @@ public abstract class TestBase {
* @throws AssertionError if the values are not equal
*/
protected void assertEquals(byte[] expected, byte[] actual) {
assertEquals("length", expected.length, actual.length);
assertEquals(expected.length, actual.length);
for (int i = 0; i < expected.length; i++) {
if (expected[i] != actual[i]) {
fail("[" + i + "]: expected: " + (int) expected[i] + " actual: " + (int) actual[i]);
......@@ -512,6 +514,57 @@ public abstract class TestBase {
}
}
/**
* Check if two readers are equal, and if not throw an exception.
*
* @param expected the expected value
* @param actual the actual value
* @throws AssertionError if the values are not equal
*/
protected void assertEqualReaders(Reader expected, Reader actual, int len) throws IOException {
for (int i = 0; len < 0 || i < len; i++) {
int ce = expected.read();
int ca = actual.read();
assertEquals(ce, ca);
if (ce == -1) {
break;
}
}
expected.close();
actual.close();
}
/**
* Check if two streams are equal, and if not throw an exception.
*
* @param expected the expected value
* @param actual the actual value
* @throws AssertionError if the values are not equal
*/
protected void assertEqualStreams(InputStream expected, InputStream actual, int len) throws IOException {
// this doesn't actually read anything - just tests reading 0 bytes
actual.read(new byte[0]);
expected.read(new byte[0]);
actual.read(new byte[10], 3, 0);
expected.read(new byte[10], 0, 0);
for (int i = 0; len < 0 || i < len; i++) {
int ca = actual.read();
actual.read(new byte[0]);
int ce = expected.read();
assertEquals(ce, ca);
if (ca == -1) {
break;
}
}
actual.read(new byte[10], 3, 0);
expected.read(new byte[10], 0, 0);
actual.read(new byte[0]);
expected.read(new byte[0]);
actual.close();
expected.close();
}
/**
* Check if two values are equal, and if not throw an exception.
*
......@@ -703,7 +756,7 @@ public abstract class TestBase {
while (rs.next()) {
i++;
}
assertEquals(i, expected);
assertEquals(expected, i);
}
/**
......@@ -724,12 +777,12 @@ public abstract class TestBase {
/**
* Check that the result set of a query is exactly this value.
*
* @param expected the expected result value
* @param stat the statement
* @param sql the SQL statement to execute
* @param expected the expected result value
* @throws AssertionError if a different result value was returned
*/
protected void assertResult(Statement stat, String sql, String expected) throws SQLException {
protected void assertResult(String expected, Statement stat, String sql) throws SQLException {
ResultSet rs = stat.executeQuery(sql);
if (rs.next()) {
String actual = rs.getString(1);
......@@ -773,24 +826,24 @@ public abstract class TestBase {
String className = meta.getColumnClassName(i + 1);
switch (t) {
case Types.INTEGER:
assertEquals(typeName, "INTEGER");
assertEquals(className, "java.lang.Integer");
assertEquals("INTEGER", typeName);
assertEquals("java.lang.Integer", className);
break;
case Types.VARCHAR:
assertEquals(typeName, "VARCHAR");
assertEquals(className, "java.lang.String");
assertEquals("VARCHAR", typeName);
assertEquals("java.lang.String", className);
break;
case Types.SMALLINT:
assertEquals(typeName, "SMALLINT");
assertEquals(className, "java.lang.Short");
assertEquals("SMALLINT", typeName);
assertEquals("java.lang.Short", className);
break;
case Types.TIMESTAMP:
assertEquals(typeName, "TIMESTAMP");
assertEquals(className, "java.sql.Timestamp");
assertEquals("TIMESTAMP", typeName);
assertEquals("java.sql.Timestamp", className);
break;
case Types.DECIMAL:
assertEquals(typeName, "DECIMAL");
assertEquals(className, "java.math.BigDecimal");
assertEquals("DECIMAL", typeName);
assertEquals("java.math.BigDecimal", className);
break;
default:
}
......@@ -1034,7 +1087,7 @@ public abstract class TestBase {
fail("only found in first: " + s);
}
}
assertEquals(list2.size(), 0);
assertEquals(0, list2.size());
assertFalse(rs2.next());
}
......
......@@ -33,12 +33,12 @@ public class TestAutoRecompile extends TestBase {
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY)");
PreparedStatement prep = conn.prepareStatement("SELECT * FROM TEST");
assertEquals(prep.executeQuery().getMetaData().getColumnCount(), 1);
assertEquals(1, prep.executeQuery().getMetaData().getColumnCount());
stat.execute("ALTER TABLE TEST ADD COLUMN NAME VARCHAR(255)");
assertEquals(prep.executeQuery().getMetaData().getColumnCount(), 2);
assertEquals(2, prep.executeQuery().getMetaData().getColumnCount());
stat.execute("DROP TABLE TEST");
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, X INT, Y INT)");
assertEquals(prep.executeQuery().getMetaData().getColumnCount(), 3);
assertEquals(3, prep.executeQuery().getMetaData().getColumnCount());
// TODO test auto-recompile with insert..select, views and so on
prep = conn.prepareStatement("INSERT INTO TEST VALUES(1, 2, 3)");
......
......@@ -412,7 +412,7 @@ public class TestCases extends TestBase {
conn = getConnection("cases");
ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM TEST");
rs.next();
assertEquals(rs.getString(1), "1");
assertEquals("1", rs.getString(1));
assertFalse(rs.next());
stat = conn.createStatement();
stat.execute("drop table test");
......@@ -424,7 +424,7 @@ public class TestCases extends TestBase {
stat = conn.createStatement();
rs = conn.createStatement().executeQuery("SELECT * FROM TEST");
rs.next();
assertEquals(rs.getString(1), "1");
assertEquals("1", rs.getString(1));
assertFalse(rs.next());
stat.execute("drop table test");
stat.execute("create table test(id identity)");
......@@ -439,7 +439,7 @@ public class TestCases extends TestBase {
conn = getConnection("cases");
rs = conn.createStatement().executeQuery("SELECT * FROM TEST");
rs.next();
assertEquals(rs.getString(1), "1");
assertEquals("1", rs.getString(1));
assertFalse(rs.next());
conn.close();
}
......@@ -455,18 +455,18 @@ public class TestCases extends TestBase {
ResultSet rs;
rs = stat.executeQuery("select name from test order by name");
rs.next();
assertEquals(rs.getString(1), "Hello");
assertEquals("Hello", rs.getString(1));
rs.next();
assertEquals(rs.getString(1), "HELLO");
assertEquals("HELLO", rs.getString(1));
rs.next();
assertEquals(rs.getString(1), "World");
assertEquals("World", rs.getString(1));
rs.next();
assertEquals(rs.getString(1), "WORLD");
assertEquals("WORLD", rs.getString(1));
rs = stat.executeQuery("select name from test where name like 'He%'");
rs.next();
assertEquals(rs.getString(1), "Hello");
assertEquals("Hello", rs.getString(1));
rs.next();
assertEquals(rs.getString(1), "HELLO");
assertEquals("HELLO", rs.getString(1));
conn.close();
}
......@@ -555,7 +555,7 @@ public class TestCases extends TestBase {
stat.execute("insert into test(name) values('test')");
ResultSet rs = stat.executeQuery("select * from test");
rs.next();
assertEquals(rs.getInt(1), 2);
assertEquals(2, rs.getInt(1));
assertFalse(rs.next());
conn.close();
}
......@@ -596,17 +596,17 @@ public class TestCases extends TestBase {
prep.execute();
ResultSet rs = stat.executeQuery("SELECT * FROM TEST ORDER BY ID");
rs.next();
assertEquals(rs.getInt(1), 1);
assertEquals(rs.getString(2), big);
assertEquals(readString(rs.getCharacterStream(2)), big);
assertEquals(rs.getString(3), big);
assertEquals(readString(rs.getCharacterStream(3)), big);
assertEquals(1, rs.getInt(1));
assertEquals(big, rs.getString(2));
assertEquals(big, readString(rs.getCharacterStream(2)));
assertEquals(big, rs.getString(3));
assertEquals(big, readString(rs.getCharacterStream(3)));
rs.next();
assertEquals(rs.getInt(1), 2);
assertEquals(rs.getString(2), big);
assertEquals(readString(rs.getCharacterStream(2)), big);
assertEquals(rs.getString(3), big);
assertEquals(readString(rs.getCharacterStream(3)), big);
assertEquals(2, rs.getInt(1));
assertEquals(big, rs.getString(2));
assertEquals(big, readString(rs.getCharacterStream(2)));
assertEquals(big, rs.getString(3));
assertEquals(big, readString(rs.getCharacterStream(3)));
rs.next();
assertFalse(rs.next());
conn.close();
......@@ -779,9 +779,9 @@ public class TestCases extends TestBase {
deleteDb("cases");
Connection conn = getConnection("cases");
Statement stat = conn.createStatement();
stat.execute("create table employee(id int, " + "firstName VARCHAR(50), " + "salary decimal(10, 2), "
+ "superior_id int, " + "CONSTRAINT PK_employee PRIMARY KEY (id), "
+ "CONSTRAINT FK_superior FOREIGN KEY (superior_id) " + "REFERENCES employee(ID))");
stat.execute("create table employee(id int, firstName VARCHAR(50), salary decimal(10, 2), "
+ "superior_id int, CONSTRAINT PK_employee PRIMARY KEY (id), "
+ "CONSTRAINT FK_superior FOREIGN KEY (superior_id) REFERENCES employee(ID))");
stat.execute("DROP TABLE employee");
conn.close();
conn = getConnection("cases");
......@@ -794,17 +794,17 @@ public class TestCases extends TestBase {
Connection c0 = getConnection("cases");
c0.createStatement().executeUpdate("SET AUTOCOMMIT FALSE");
c0
.createStatement()
.executeUpdate(
"create table australia (ID INTEGER NOT NULL, Name VARCHAR(100), firstName VARCHAR(100), Points INTEGER, LicenseID INTEGER, PRIMARY KEY(ID))");
c0.createStatement().executeUpdate(
"create table australia (ID INTEGER NOT NULL, " +
"Name VARCHAR(100), firstName VARCHAR(100), " +
"Points INTEGER, LicenseID INTEGER, PRIMARY KEY(ID))");
c0.createStatement().executeUpdate("COMMIT");
c0.close();
c0 = getConnection("cases");
c0.createStatement().executeUpdate("SET AUTOCOMMIT FALSE");
PreparedStatement p15 = c0
.prepareStatement("insert into australia (id,Name,firstName,Points,LicenseID) values (?,?,?,?,?)");
PreparedStatement p15 = c0.prepareStatement("insert into australia"
+ "(id, Name, firstName, Points, LicenseID) values (?, ?, ?, ?, ?)");
int len = getSize(1, 1000);
for (int i = 0; i < len; i++) {
p15.setInt(1, i);
......@@ -833,17 +833,16 @@ public class TestCases extends TestBase {
c0 = getConnection("cases");
c0.createStatement().executeUpdate("SET AUTOCOMMIT FALSE");
c0.createStatement().executeUpdate("drop table australia");
c0
.createStatement()
.executeUpdate(
"create table australia (ID INTEGER NOT NULL, Name VARCHAR(100), firstName VARCHAR(100), Points INTEGER, LicenseID INTEGER, PRIMARY KEY(ID))");
c0.createStatement().executeUpdate(
"create table australia (ID INTEGER NOT NULL, Name VARCHAR(100), "
+ "firstName VARCHAR(100), Points INTEGER, LicenseID INTEGER, PRIMARY KEY(ID))");
c0.createStatement().executeUpdate("COMMIT");
c0.close();
c0 = getConnection("cases");
c0.createStatement().executeUpdate("SET AUTOCOMMIT FALSE");
PreparedStatement p65 = c0
.prepareStatement("insert into australia (id,Name,FirstName,Points,LicenseID) values (?,?,?,?,?)");
PreparedStatement p65 = c0.prepareStatement("insert into australia"
+ "(id, Name, FirstName, Points, LicenseID) values (?, ?, ?, ?, ?)");
len = getSize(1, 1000);
for (int i = 0; i < len; i++) {
p65.setInt(1, i);
......
......@@ -146,7 +146,7 @@ public class TestCluster extends TestBase {
prep.setInt(1, i);
ResultSet rs = prep.executeQuery();
rs.next();
assertEquals(rs.getString(2), "Data" + i);
assertEquals("Data" + i, rs.getString(2));
assertFalse(rs.next());
}
}
......
......@@ -155,10 +155,10 @@ public class TestCompatibility extends TestBase {
stat.execute("CREATE TABLE TEST(ID INT, NAME VARCHAR)");
stat.execute("INSERT INTO TEST VALUES(1, 'Hello'), (2, 'World')");
org.h2.mode.FunctionsMySQL.register(conn);
assertResult(stat, "SELECT UNIX_TIMESTAMP('2007-11-30 10:30:19Z')", "1196418619");
assertResult(stat, "SELECT UNIX_TIMESTAMP(FROM_UNIXTIME(1196418619))", "1196418619");
assertResult(stat, "SELECT FROM_UNIXTIME(1196300000, '%Y %M')", "2007 November");
assertResult(stat, "SELECT DATE('2003-12-31 11:02:03')", "2003-12-31");
assertResult("1196418619", stat, "SELECT UNIX_TIMESTAMP('2007-11-30 10:30:19Z')");
assertResult("1196418619", stat, "SELECT UNIX_TIMESTAMP(FROM_UNIXTIME(1196418619))");
assertResult("2007 November", stat, "SELECT FROM_UNIXTIME(1196300000, '%Y %M')");
assertResult("2003-12-31", stat, "SELECT DATE('2003-12-31 11:02:03')");
}
......
......@@ -66,7 +66,7 @@ public class TestExclusive extends TestBase {
break;
}
}
assertEquals(state[0], 2);
assertEquals(2, state[0]);
stat.execute("set exclusive true");
conn.close();
......
......@@ -155,28 +155,28 @@ public class TestFullText extends TestBase {
ResultSet rs;
rs = stat.executeQuery("SELECT * FROM " + prefix + "SEARCH('Hello', 0, 0)");
rs.next();
assertEquals(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=1");
assertEquals("\"PUBLIC\".\"TEST\" WHERE \"ID\"=1", rs.getString(1));
assertFalse(rs.next());
rs = stat.executeQuery("SELECT * FROM " + prefix + "SEARCH('Hallo', 0, 0)");
assertFalse(rs.next());
stat.execute("INSERT INTO TEST VALUES(2, 'Hallo Welt')");
rs = stat.executeQuery("SELECT * FROM " + prefix + "SEARCH('Hello', 0, 0)");
rs.next();
assertEquals(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=1");
assertEquals("\"PUBLIC\".\"TEST\" WHERE \"ID\"=1", rs.getString(1));
assertFalse(rs.next());
rs = stat.executeQuery("SELECT * FROM " + prefix + "SEARCH('Hallo', 0, 0)");
rs.next();
assertEquals(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=2");
assertEquals("\"PUBLIC\".\"TEST\" WHERE \"ID\"=2", rs.getString(1));
assertFalse(rs.next());
stat.execute("CALL " + prefix + "REINDEX()");
rs = stat.executeQuery("SELECT * FROM " + prefix + "SEARCH('Hello', 0, 0)");
rs.next();
assertEquals(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=1");
assertEquals("\"PUBLIC\".\"TEST\" WHERE \"ID\"=1", rs.getString(1));
assertFalse(rs.next());
rs = stat.executeQuery("SELECT * FROM " + prefix + "SEARCH('Hallo', 0, 0)");
rs.next();
assertEquals(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=2");
assertEquals("\"PUBLIC\".\"TEST\" WHERE \"ID\"=2", rs.getString(1));
assertFalse(rs.next());
stat.execute("INSERT INTO TEST VALUES(3, 'Hello World')");
......@@ -185,13 +185,13 @@ public class TestFullText extends TestBase {
rs = stat.executeQuery("SELECT * FROM " + prefix + "SEARCH('World', 0, 0) ORDER BY QUERY");
rs.next();
assertEquals(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=1");
assertEquals("\"PUBLIC\".\"TEST\" WHERE \"ID\"=1", rs.getString(1));
rs.next();
assertEquals(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=3");
assertEquals("\"PUBLIC\".\"TEST\" WHERE \"ID\"=3", rs.getString(1));
rs.next();
assertEquals(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=4");
assertEquals("\"PUBLIC\".\"TEST\" WHERE \"ID\"=4", rs.getString(1));
rs.next();
assertEquals(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=5");
assertEquals("\"PUBLIC\".\"TEST\" WHERE \"ID\"=5", rs.getString(1));
assertFalse(rs.next());
rs = stat.executeQuery("SELECT * FROM " + prefix + "SEARCH('World', 1, 0)");
......@@ -215,7 +215,7 @@ public class TestFullText extends TestBase {
rs = stat.executeQuery("SELECT * FROM " + prefix + "SEARCH('1', 0, 0)");
rs.next();
assertEquals(rs.getString(1), "\"PUBLIC\".\"TEST\" WHERE \"ID\"=1");
assertEquals("\"PUBLIC\".\"TEST\" WHERE \"ID\"=1", rs.getString(1));
assertFalse(rs.next());
conn.close();
......
......@@ -291,45 +291,45 @@ public class TestFunctions extends TestBase implements AggregateFunction {
deleteDb("functions");
Connection conn = getConnection("functions");
Statement stat = conn.createStatement();
test(stat, "abs(null)", null);
test(stat, "abs(1)", "1");
test(stat, "abs(1)", "1");
assertCallResult(null, stat, "abs(null)");
assertCallResult("1", stat, "abs(1)");
assertCallResult("1", stat, "abs(1)");
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)");
stat.execute("CREATE ALIAS ADD_ROW FOR \"" + getClass().getName() + ".addRow\"");
ResultSet rs;
rs = stat.executeQuery("CALL ADD_ROW(1, 'Hello')");
rs.next();
assertEquals(rs.getInt(1), 1);
assertEquals(1, rs.getInt(1));
rs = stat.executeQuery("SELECT * FROM TEST");
rs.next();
assertEquals(rs.getInt(1), 1);
assertEquals(rs.getString(2), "Hello");
assertEquals(1, rs.getInt(1));
assertEquals("Hello", rs.getString(2));
assertFalse(rs.next());
rs = stat.executeQuery("CALL ADD_ROW(2, 'World')");
stat.execute("CREATE ALIAS SELECT_F FOR \"" + getClass().getName() + ".select\"");
rs = stat.executeQuery("CALL SELECT_F('SELECT * FROM TEST ORDER BY ID')");
assertEquals(rs.getMetaData().getColumnCount(), 2);
assertEquals(2, rs.getMetaData().getColumnCount());
rs.next();
assertEquals(rs.getInt(1), 1);
assertEquals(rs.getString(2), "Hello");
assertEquals(1, rs.getInt(1));
assertEquals("Hello", rs.getString(2));
rs.next();
assertEquals(rs.getInt(1), 2);
assertEquals(rs.getString(2), "World");
assertEquals(2, rs.getInt(1));
assertEquals("World", rs.getString(2));
assertFalse(rs.next());
rs = stat.executeQuery("SELECT NAME FROM SELECT_F('SELECT * FROM TEST ORDER BY NAME') ORDER BY NAME DESC");
assertEquals(rs.getMetaData().getColumnCount(), 1);
assertEquals(1, rs.getMetaData().getColumnCount());
rs.next();
assertEquals(rs.getString(1), "World");
assertEquals("World", rs.getString(1));
rs.next();
assertEquals(rs.getString(1), "Hello");
assertEquals("Hello", rs.getString(1));
assertFalse(rs.next());
rs = stat.executeQuery("SELECT SELECT_F('SELECT * FROM TEST WHERE ID=' || ID) FROM TEST ORDER BY ID");
assertEquals(rs.getMetaData().getColumnCount(), 1);
assertEquals(1, rs.getMetaData().getColumnCount());
rs.next();
assertEquals("((1, Hello))", rs.getString(1));
rs.next();
......@@ -337,7 +337,7 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertFalse(rs.next());
rs = stat.executeQuery("SELECT SELECT_F('SELECT * FROM TEST ORDER BY ID') FROM DUAL");
assertEquals(rs.getMetaData().getColumnCount(), 1);
assertEquals(1, rs.getMetaData().getColumnCount());
rs.next();
assertEquals("((1, Hello), (2, World))", rs.getString(1));
assertFalse(rs.next());
......@@ -351,50 +351,50 @@ public class TestFunctions extends TestBase implements AggregateFunction {
stat.execute("CREATE ALIAS SIMPLE FOR \"" + getClass().getName() + ".simpleResultSet\"");
rs = stat.executeQuery("CALL SIMPLE(2, 1,1,1,1,1,1,1)");
assertEquals(rs.getMetaData().getColumnCount(), 2);
assertEquals(2, rs.getMetaData().getColumnCount());
rs.next();
assertEquals(rs.getInt(1), 0);
assertEquals(rs.getString(2), "Hello");
assertEquals(0, rs.getInt(1));
assertEquals("Hello", rs.getString(2));
rs.next();
assertEquals(rs.getInt(1), 1);
assertEquals(rs.getString(2), "World");
assertEquals(1, rs.getInt(1));
assertEquals("World", rs.getString(2));
assertFalse(rs.next());
rs = stat.executeQuery("SELECT * FROM SIMPLE(1, 1,1,1,1,1,1,1)");
assertEquals(rs.getMetaData().getColumnCount(), 2);
assertEquals(2, rs.getMetaData().getColumnCount());
rs.next();
assertEquals(rs.getInt(1), 0);
assertEquals(rs.getString(2), "Hello");
assertEquals(0, rs.getInt(1));
assertEquals("Hello", rs.getString(2));
assertFalse(rs.next());
stat.execute("CREATE ALIAS ARRAY FOR \"" + getClass().getName() + ".getArray\"");
rs = stat.executeQuery("CALL ARRAY()");
assertEquals(rs.getMetaData().getColumnCount(), 2);
assertEquals(2, rs.getMetaData().getColumnCount());
rs.next();
assertEquals(rs.getInt(1), 0);
assertEquals(rs.getString(2), "Hello");
assertEquals(0, rs.getInt(1));
assertEquals("Hello", rs.getString(2));
assertFalse(rs.next());
stat.execute("CREATE ALIAS ROOT FOR \"" + getClass().getName() + ".root\"");
rs = stat.executeQuery("CALL ROOT(9)");
rs.next();
assertEquals(rs.getInt(1), 3);
assertEquals(3, rs.getInt(1));
assertFalse(rs.next());
stat.execute("CREATE ALIAS MAX_ID FOR \"" + getClass().getName() + ".selectMaxId\"");
rs = stat.executeQuery("CALL MAX_ID()");
rs.next();
assertEquals(rs.getInt(1), 2);
assertEquals(2, rs.getInt(1));
assertFalse(rs.next());
rs = stat.executeQuery("SELECT * FROM MAX_ID()");
rs.next();
assertEquals(rs.getInt(1), 2);
assertEquals(2, rs.getInt(1));
assertFalse(rs.next());
rs = stat.executeQuery("CALL CASE WHEN -9 < 0 THEN 0 ELSE ROOT(-9) END");
rs.next();
assertEquals(rs.getInt(1), 0);
assertEquals(0, rs.getInt(1));
assertFalse(rs.next());
stat.execute("CREATE ALIAS blob2stream FOR \"" + getClass().getName() + ".blob2stream\"");
......@@ -414,19 +414,19 @@ public class TestFunctions extends TestBase implements AggregateFunction {
stat.execute("CREATE ALIAS NULL_RESULT FOR \"" + getClass().getName() + ".nullResultSet\"");
rs = stat.executeQuery("CALL NULL_RESULT()");
assertEquals(rs.getMetaData().getColumnCount(), 1);
assertEquals(1, rs.getMetaData().getColumnCount());
rs.next();
assertEquals(rs.getString(1), null);
assertEquals(null, rs.getString(1));
assertFalse(rs.next());
conn.close();
}
private void test(Statement stat, String sql, String value) throws SQLException {
private void assertCallResult(String expected, Statement stat, String sql) throws SQLException {
ResultSet rs = stat.executeQuery("CALL " + sql);
rs.next();
String s = rs.getString(1);
assertEquals(value, s);
assertEquals(expected, s);
}
/**
......
......@@ -204,10 +204,10 @@ public class TestLinkedTable extends TestBase {
stat2.execute("CREATE LINKED TABLE two('org.h2.Driver', 'jdbc:h2:mem:one', 'sa', 'sa', 'PUBLIC.A');");
ResultSet rs = stat2.executeQuery("SELECT * FROM one");
rs.next();
assertEquals(rs.getInt(1), 2);
assertEquals(2, rs.getInt(1));
rs = stat2.executeQuery("SELECT * FROM two");
rs.next();
assertEquals(rs.getInt(1), 1);
assertEquals(1, rs.getInt(1));
conn.close();
conn2.close();
}
......@@ -270,29 +270,29 @@ public class TestLinkedTable extends TestBase {
rs = stat2.executeQuery("SELECT * FROM TEST_LINK_DI ORDER BY ID");
rs.next();
assertEquals(rs.getInt(1), 2);
assertEquals(rs.getString(2), "Hello2");
assertEquals(2, rs.getInt(1));
assertEquals("Hello2", rs.getString(2));
rs.next();
assertEquals(rs.getInt(1), 3);
assertEquals(rs.getString(2), "World3");
assertEquals(3, rs.getInt(1));
assertEquals("World3", rs.getString(2));
assertFalse(rs.next());
rs = stat2.executeQuery("SELECT * FROM TEST_LINK_U ORDER BY ID");
rs.next();
assertEquals(rs.getInt(1), 2);
assertEquals(rs.getString(2), "Hello2");
assertEquals(2, rs.getInt(1));
assertEquals("Hello2", rs.getString(2));
rs.next();
assertEquals(rs.getInt(1), 3);
assertEquals(rs.getString(2), "World3");
assertEquals(3, rs.getInt(1));
assertEquals("World3", rs.getString(2));
assertFalse(rs.next());
rs = stat.executeQuery("SELECT * FROM TEST ORDER BY ID");
rs.next();
assertEquals(rs.getInt(1), 2);
assertEquals(rs.getString(2), "Hello2");
assertEquals(2, rs.getInt(1));
assertEquals("Hello2", rs.getString(2));
rs.next();
assertEquals(rs.getInt(1), 3);
assertEquals(rs.getString(2), "World3");
assertEquals(3, rs.getInt(1));
assertEquals("World3", rs.getString(2));
assertFalse(rs.next());
conn.close();
......@@ -385,22 +385,22 @@ public class TestLinkedTable extends TestBase {
rs = stat.executeQuery("SELECT COUNT(*) FROM LINK_TEST");
rs.next();
assertEquals(rs.getInt(1), 4);
assertEquals(4, rs.getInt(1));
rs = stat.executeQuery("SELECT COUNT(*) FROM LINK_TEST WHERE NAME='Link Test'");
rs.next();
assertEquals(rs.getInt(1), 1);
assertEquals(1, rs.getInt(1));
int uc = stat.executeUpdate("DELETE FROM LINK_TEST WHERE ID=3");
assertEquals(uc, 1);
assertEquals(1, uc);
rs = stat.executeQuery("SELECT COUNT(*) FROM LINK_TEST");
rs.next();
assertEquals(rs.getInt(1), 3);
assertEquals(3, rs.getInt(1));
rs = stat.executeQuery("SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='LINK_TEST'");
rs.next();
assertEquals(rs.getString("TABLE_TYPE"), "TABLE LINK");
assertEquals("TABLE LINK", rs.getString("TABLE_TYPE"));
rs.next();
rs = stat.executeQuery("SELECT * FROM LINK_TEST WHERE ID=0");
......@@ -427,7 +427,7 @@ public class TestLinkedTable extends TestBase {
+ "', 'sa1', 'abc abc', '(SELECT COUNT(*) FROM TEST)')");
rs = stat.executeQuery("SELECT * FROM LINK_TEST");
rs.next();
assertEquals(rs.getInt(1), 3);
assertEquals(3, rs.getInt(1));
assertFalse(rs.next());
conn.close();
......@@ -439,23 +439,23 @@ public class TestLinkedTable extends TestBase {
private void testRow(Statement stat, String name) throws SQLException {
ResultSet rs = stat.executeQuery("SELECT * FROM " + name + " WHERE ID=1");
rs.next();
assertEquals(rs.getString("NAME"), "Hello");
assertEquals(rs.getByte("XT"), -1);
assertEquals("Hello", rs.getString("NAME"));
assertEquals(-1, rs.getByte("XT"));
BigDecimal bd = rs.getBigDecimal("XD");
assertTrue(bd.equals(new BigDecimal("10.30")));
Timestamp ts = rs.getTimestamp("XTS");
String s = ts.toString();
assertEquals(s, "2001-02-03 11:22:33.4455");
assertEquals("2001-02-03 11:22:33.4455", s);
assertTrue(ts.equals(Timestamp.valueOf("2001-02-03 11:22:33.4455")));
assertEquals(rs.getBytes("XBY"), new byte[] { (byte) 255, (byte) 1, (byte) 2 });
assertEquals(new byte[] { (byte) 255, (byte) 1, (byte) 2 }, rs.getBytes("XBY"));
assertTrue(rs.getBoolean("XBO"));
assertEquals(rs.getShort("XSM"), 3000);
assertEquals(rs.getLong("XBI"), 1234567890123456789L);
assertEquals(rs.getString("XBL"), "1122aa");
assertEquals(rs.getString("XDA"), "0002-01-01");
assertEquals(rs.getString("XTI"), "00:00:00");
assertEquals(rs.getString("XCL"), "J\u00fcrg");
assertEquals(rs.getString("XDO"), "2.25");
assertEquals(3000, rs.getShort("XSM"));
assertEquals(1234567890123456789L, rs.getLong("XBI"));
assertEquals("1122aa", rs.getString("XBL"));
assertEquals("0002-01-01", rs.getString("XDA"));
assertEquals("00:00:00", rs.getString("XTI"));
assertEquals("J\u00fcrg", rs.getString("XCL"));
assertEquals("2.25", rs.getString("XDO"));
}
}
......@@ -9,7 +9,6 @@ package org.h2.test.db;
import java.io.ByteArrayInputStream;
import java.io.CharArrayReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.StringReader;
......@@ -324,7 +323,7 @@ public class TestLob extends TestBase {
ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM TEST");
assertTrue(rs.next());
rs.getInt(1);
assertEquals(rs.getString(2).length(), 10000);
assertEquals(10000, rs.getString(2).length());
conn.close();
}
......@@ -449,7 +448,7 @@ public class TestLob extends TestBase {
ResultSet rs;
rs = stat.executeQuery("select value from information_schema.settings where NAME='COMPRESS_LOB'");
rs.next();
assertEquals(rs.getString(1), compress ? "LZF" : "NO");
assertEquals(compress ? "LZF" : "NO", rs.getString(1));
assertFalse(rs.next());
stat.execute("create table test(text clob)");
stat.execute("create table test2(text clob)");
......@@ -462,15 +461,15 @@ public class TestLob extends TestBase {
stat.execute("insert into test2 select * from test");
rs = stat.executeQuery("select * from test2");
rs.next();
assertEquals(rs.getString(1), spaces);
assertEquals(spaces, rs.getString(1));
stat.execute("drop table test");
rs = stat.executeQuery("select * from test2");
rs.next();
assertEquals(rs.getString(1), spaces);
assertEquals(spaces, rs.getString(1));
stat.execute("alter table test2 add column id int before text");
rs = stat.executeQuery("select * from test2");
rs.next();
assertEquals(rs.getString("text"), spaces);
assertEquals(spaces, rs.getString("text"));
conn.close();
}
......@@ -545,10 +544,10 @@ public class TestLob extends TestBase {
Blob b = rs.getBlob("B");
Clob c = rs.getClob("C");
int l = i;
assertEquals(b.length(), l);
assertEquals(c.length(), l);
checkStream(b.getBinaryStream(), getRandomStream(l, i), -1);
checkReader(c.getCharacterStream(), getRandomReader(l, i), -1);
assertEquals(l, b.length());
assertEquals(l, c.length());
assertEqualStreams(getRandomStream(l, i), b.getBinaryStream(), -1);
assertEqualReaders(getRandomReader(l, i), c.getCharacterStream(), -1);
}
prep = conn.prepareStatement("UPDATE TEST SET B=?, C=? WHERE ID=?");
......@@ -567,10 +566,10 @@ public class TestLob extends TestBase {
Blob b = rs.getBlob("B");
Clob c = rs.getClob("C");
int l = i;
assertEquals(b.length(), l);
assertEquals(c.length(), l);
checkStream(b.getBinaryStream(), getRandomStream(l, -i), -1);
checkReader(c.getCharacterStream(), getRandomReader(l, -i), -1);
assertEquals(l, b.length());
assertEquals(l, c.length());
assertEqualStreams(getRandomStream(l, -i), b.getBinaryStream(), -1);
assertEqualReaders(getRandomReader(l, -i), c.getCharacterStream(), -1);
}
conn.close();
......@@ -594,21 +593,21 @@ public class TestLob extends TestBase {
ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM TEST ORDER BY ID");
rs.next();
assertEquals("Bohlen", rs.getString("C"));
checkReader(new CharArrayReader("Bohlen".toCharArray()), rs.getCharacterStream("C"), -1);
assertEqualReaders(new CharArrayReader("Bohlen".toCharArray()), rs.getCharacterStream("C"), -1);
rs.next();
checkReader(new CharArrayReader("B\u00f6hlen".toCharArray()), rs.getCharacterStream("C"), -1);
assertEqualReaders(new CharArrayReader("B\u00f6hlen".toCharArray()), rs.getCharacterStream("C"), -1);
rs.next();
checkReader(getRandomReader(501, 1), rs.getCharacterStream("C"), -1);
assertEqualReaders(getRandomReader(501, 1), rs.getCharacterStream("C"), -1);
Clob clob = rs.getClob("C");
checkReader(getRandomReader(501, 1), clob.getCharacterStream(), -1);
assertEquals(clob.length(), 501);
assertEqualReaders(getRandomReader(501, 1), clob.getCharacterStream(), -1);
assertEquals(501, clob.length());
rs.next();
checkReader(getRandomReader(401, 2), rs.getCharacterStream("C"), -1);
checkReader(getRandomReader(1500, 2), rs.getCharacterStream("C"), 401);
assertEqualReaders(getRandomReader(401, 2), rs.getCharacterStream("C"), -1);
assertEqualReaders(getRandomReader(1500, 2), rs.getCharacterStream("C"), 401);
clob = rs.getClob("C");
checkReader(getRandomReader(1501, 2), clob.getCharacterStream(), 401);
checkReader(getRandomReader(401, 2), clob.getCharacterStream(), 401);
assertEquals(clob.length(), 401);
assertEqualReaders(getRandomReader(1501, 2), clob.getCharacterStream(), 401);
assertEqualReaders(getRandomReader(401, 2), clob.getCharacterStream(), 401);
assertEquals(401, clob.length());
assertFalse(rs.next());
conn.close();
}
......@@ -687,7 +686,7 @@ public class TestLob extends TestBase {
stat = conn.createStatement();
ResultSet rs = stat.executeQuery("SELECT * FROM TEST WHERE ID=1");
rs.next();
checkStream(new ByteArrayInputStream(data), rs.getBinaryStream("TEXT"), -1);
assertEqualStreams(rs.getBinaryStream("TEXT"), new ByteArrayInputStream(data), -1);
prep = conn.prepareStatement("UPDATE TEST SET TEXT = ?");
prep.setBinaryStream(1, new ByteArrayInputStream(data), 0);
......@@ -697,7 +696,7 @@ public class TestLob extends TestBase {
stat = conn.createStatement();
rs = stat.executeQuery("SELECT * FROM TEST WHERE ID=1");
rs.next();
checkStream(new ByteArrayInputStream(data), rs.getBinaryStream("TEXT"), -1);
assertEqualStreams(rs.getBinaryStream("TEXT"), new ByteArrayInputStream(data), -1);
stat.execute("DROP TABLE IF EXISTS TEST");
conn.close();
......@@ -743,20 +742,20 @@ public class TestLob extends TestBase {
int size = id * id;
if (clob) {
Reader rt = rs.getCharacterStream(2);
checkReader(rt, getRandomReader(size, id), -1);
assertEqualReaders(getRandomReader(size, id), rt, -1);
Object obj = rs.getObject(2);
if (obj instanceof Clob) {
obj = ((Clob) obj).getCharacterStream();
}
checkReader((Reader) obj, getRandomReader(size, id), -1);
assertEqualReaders(getRandomReader(size, id), (Reader) obj, -1);
} else {
InputStream in = rs.getBinaryStream(2);
checkStream(in, getRandomStream(size, id), -1);
assertEqualStreams(getRandomStream(size, id), in, -1);
Object obj = rs.getObject(2);
if (obj instanceof Blob) {
obj = ((Blob) obj).getBinaryStream();
}
checkStream((InputStream) obj, getRandomStream(size, id), -1);
assertEqualStreams(getRandomStream(size, id), (InputStream) obj, -1);
}
}
trace("select=" + (System.currentTimeMillis() - time));
......@@ -808,49 +807,12 @@ public class TestLob extends TestBase {
TestLobObject a = (TestLobObject) oa;
Object ob = rs.getObject("DATA");
TestLobObject b = (TestLobObject) ob;
assertEquals(a.data, "abc");
assertEquals(b.data, "abc");
assertEquals("abc", a.data);
assertEquals("abc", b.data);
assertFalse(rs.next());
conn.close();
}
private void checkStream(InputStream a, InputStream b, int len) throws IOException {
// this doesn't actually read anything - just tests reading 0 bytes
a.read(new byte[0]);
b.read(new byte[0]);
a.read(new byte[10], 3, 0);
b.read(new byte[10], 0, 0);
for (int i = 0; len < 0 || i < len; i++) {
int ca = a.read();
a.read(new byte[0]);
int cb = b.read();
assertEquals(ca, cb);
if (ca == -1) {
break;
}
}
a.read(new byte[10], 3, 0);
b.read(new byte[10], 0, 0);
a.read(new byte[0]);
b.read(new byte[0]);
a.close();
b.close();
}
private void checkReader(Reader a, Reader b, int len) throws IOException {
for (int i = 0; len < 0 || i < len; i++) {
int ca = a.read();
int cb = b.read();
assertEquals(ca, cb);
if (ca == -1) {
break;
}
}
a.close();
b.close();
}
private Reader getRandomReader(int len, int seed) {
return new CharArrayReader(getRandomChars(len, seed));
}
......
......@@ -79,7 +79,7 @@ public class TestOpenClose extends TestBase implements DatabaseEventListener {
stat = conn.createStatement();
ResultSet rs = stat.executeQuery("SELECT * FROM TEST");
rs.next();
assertEquals(rs.getString(1).length(), 10000);
assertEquals(10000, rs.getString(1).length());
assertFalse(rs.next());
conn.close();
FileUtils.delete(baseDir + "/test.zip");
......@@ -165,7 +165,7 @@ public class TestOpenClose extends TestBase implements DatabaseEventListener {
conn = DriverManager.getConnection(url, user, password);
ResultSet rs = conn.createStatement().executeQuery("select count(*) from employee");
rs.next();
assertEquals(rs.getInt(1), len);
assertEquals(len, rs.getInt(1));
conn.close();
}
......
......@@ -353,15 +353,15 @@ public class TestOptimizations extends TestBase {
PreparedStatement prep = conn.prepareStatement("select * from test where id = (select id from test2)");
ResultSet rs1 = prep.executeQuery();
rs1.next();
assertEquals(rs1.getInt(1), 1);
assertEquals(1, rs1.getInt(1));
rs1.next();
assertEquals(rs1.getInt(1), 1);
assertEquals(1, rs1.getInt(1));
assertFalse(rs1.next());
stat.execute("update test2 set id = 2");
ResultSet rs2 = prep.executeQuery();
rs2.next();
assertEquals(rs2.getInt(1), 2);
assertEquals(2, rs2.getInt(1));
conn.close();
}
......@@ -455,8 +455,8 @@ public class TestOptimizations extends TestBase {
prep.setInt(1, 1);
rs = prep.executeQuery();
rs.next();
assertEquals(rs.getInt(1), 1);
assertEquals(rs.getString(2), "Hello");
assertEquals(1, rs.getInt(1));
assertEquals("Hello", rs.getString(2));
assertFalse(rs.next());
prep = conn.prepareStatement("select * from test t1 where t1.id in(?, ?) order by id");
......@@ -464,29 +464,30 @@ public class TestOptimizations extends TestBase {
prep.setInt(2, 2);
rs = prep.executeQuery();
rs.next();
assertEquals(rs.getInt(1), 1);
assertEquals(rs.getString(2), "Hello");
assertEquals(1, rs.getInt(1));
assertEquals("Hello", rs.getString(2));
rs.next();
assertEquals(rs.getInt(1), 2);
assertEquals(rs.getString(2), "World");
assertEquals(2, rs.getInt(1));
assertEquals("World", rs.getString(2));
assertFalse(rs.next());
prep = conn.prepareStatement("select * from test t1 where t1.id in(select t2.id from test t2 where t2.id=?)");
prep = conn.prepareStatement("select * from test t1 where t1.id "
+ "in(select t2.id from test t2 where t2.id=?)");
prep.setInt(1, 2);
rs = prep.executeQuery();
rs.next();
assertEquals(rs.getInt(1), 2);
assertEquals(rs.getString(2), "World");
assertEquals(2, rs.getInt(1));
assertEquals("World", rs.getString(2));
assertFalse(rs.next());
prep = conn
.prepareStatement("select * from test t1 where t1.id in(select t2.id from test t2 where t2.id=? and t1.id<>t2.id)");
prep = conn.prepareStatement("select * from test t1 where t1.id "
+ "in(select t2.id from test t2 where t2.id=? and t1.id<>t2.id)");
prep.setInt(1, 2);
rs = prep.executeQuery();
assertFalse(rs.next());
prep = conn
.prepareStatement("select * from test t1 where t1.id in(select t2.id from test t2 where t2.id in(cast(?+10 as varchar)))");
prep = conn.prepareStatement("select * from test t1 where t1.id "
+ "in(select t2.id from test t2 where t2.id in(cast(?+10 as varchar)))");
prep.setInt(1, 2);
rs = prep.executeQuery();
assertFalse(rs.next());
......
......@@ -90,14 +90,14 @@ public class TestPowerOff extends TestBase {
ResultSet rs = stat.executeQuery("SELECT * FROM TEST" + i + " ORDER BY ID");
for (int j = 0; j < 10; j++) {
rs.next();
assertEquals(rs.getInt(1), j);
assertEquals(rs.getString(2), "Hello");
assertEquals(j, rs.getInt(1));
assertEquals("Hello", rs.getString(2));
}
if (i == 1) {
for (int j = 0; j < 10; j++) {
rs.next();
assertEquals(rs.getInt(1), j + 10);
assertEquals(rs.getString(2), "World");
assertEquals(j + 10, rs.getInt(1));
assertEquals("World", rs.getString(2));
}
}
assertFalse(rs.next());
......@@ -219,7 +219,7 @@ public class TestPowerOff extends TestBase {
stat = conn.createStatement();
ResultSet rs = stat.executeQuery("SELECT COUNT(*) FROM TEST");
rs.next();
assertEquals(rs.getInt(1), 1);
assertEquals(1, rs.getInt(1));
conn.close();
}
......@@ -317,18 +317,18 @@ public class TestPowerOff extends TestBase {
if (!rs.next()) {
state = 1;
} else {
assertEquals(rs.getInt(1), 1);
assertEquals(1, rs.getInt(1));
String name1 = rs.getString(2);
assertTrue(rs.next());
assertEquals(rs.getInt(1), 2);
assertEquals(2, rs.getInt(1));
String name2 = rs.getString(2);
assertFalse(rs.next());
if ("Hello".equals(name1)) {
assertEquals(name2, "World");
assertEquals("World", name2);
state = 2;
} else {
assertEquals(name1, "Hallo");
assertEquals(name2, "Welt");
assertEquals("Hallo", name1);
assertEquals("Welt", name2);
state = 3;
}
}
......
......@@ -271,7 +271,7 @@ public class TestRights extends TestBase {
ResultSet rs = conn.createStatement().executeQuery(
"SELECT STORAGE_TYPE FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='TEST'");
rs.next();
assertEquals(rs.getString(1), type);
assertEquals(type, rs.getString(1));
executeSuccess("DROP TABLE TEST");
}
......
......@@ -76,11 +76,11 @@ public class TestSequence extends TestBase {
stat.execute("call next value for test_Sequence3");
ResultSet rs = stat.executeQuery("select * from information_schema.sequences order by sequence_name");
rs.next();
assertEquals(rs.getString("SEQUENCE_NAME"), "TEST_SEQUENCE");
assertEquals(rs.getString("CACHE"), "32");
assertEquals("TEST_SEQUENCE", rs.getString("SEQUENCE_NAME"));
assertEquals("32", rs.getString("CACHE"));
rs.next();
assertEquals(rs.getString("SEQUENCE_NAME"), "TEST_SEQUENCE3");
assertEquals(rs.getString("CACHE"), "3");
assertEquals("TEST_SEQUENCE3", rs.getString("SEQUENCE_NAME"));
assertEquals("3", rs.getString("CACHE"));
assertFalse(rs.next());
conn.close();
}
......
......@@ -123,12 +123,12 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
rs = stat.executeQuery("SELECT * FROM TEST");
rs.next();
assertEquals(rs.getString(2), "Hello-updated");
assertEquals("Hello-updated", rs.getString(2));
assertFalse(rs.next());
stat.execute("UPDATE TEST SET NAME=NAME||'-upd'");
rs = stat.executeQuery("SELECT * FROM TEST");
rs.next();
assertEquals(rs.getString(2), "Hello-updated-upd-updated2");
assertEquals("Hello-updated-upd-updated2", rs.getString(2));
assertFalse(rs.next());
mustNotCallTrigger = true;
......
......@@ -52,12 +52,12 @@ public class TestTwoPhaseCommit extends TestBase {
stat.execute("SET WRITE_DELAY 0");
ResultSet rs = stat.executeQuery("SELECT * FROM TEST ORDER BY ID");
rs.next();
assertEquals(rs.getInt(1), 1);
assertEquals(rs.getString(2), "Hello");
assertEquals(1, rs.getInt(1));
assertEquals("Hello", rs.getString(2));
if (!rolledBack) {
rs.next();
assertEquals(rs.getInt(1), 2);
assertEquals(rs.getString(2), "World");
assertEquals(2, rs.getInt(1));
assertEquals("World", rs.getString(2));
}
assertFalse(rs.next());
conn.close();
......
......@@ -193,9 +193,9 @@ public class TestStatement extends TestBase {
// calls are ignored
if (config.jdk14) {
assertEquals(stat.getResultSetHoldability(), ResultSet.HOLD_CURSORS_OVER_COMMIT);
assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, stat.getResultSetHoldability());
}
assertEquals(stat.getResultSetConcurrency(), ResultSet.CONCUR_READ_ONLY);
assertEquals(ResultSet.CONCUR_READ_ONLY, stat.getResultSetConcurrency());
stat.cancel();
stat.setQueryTimeout(10);
......@@ -212,22 +212,22 @@ public class TestStatement extends TestBase {
assertTrue(stat.getQueryTimeout() == 0);
trace("executeUpdate");
count = stat.executeUpdate("CREATE TABLE TEST(ID INT PRIMARY KEY,VALUE VARCHAR(255))");
assertEquals(count, 0);
assertEquals(0, count);
count = stat.executeUpdate("INSERT INTO TEST VALUES(1,'Hello')");
assertEquals(count, 1);
assertEquals(1, count);
count = stat.executeUpdate("INSERT INTO TEST(VALUE,ID) VALUES('JDBC',2)");
assertEquals(count, 1);
assertEquals(1, count);
count = stat.executeUpdate("UPDATE TEST SET VALUE='LDBC' WHERE ID=2 OR ID=1");
assertEquals(count, 2);
assertEquals(2, count);
count = stat.executeUpdate("UPDATE TEST SET VALUE='\\LDBC\\' WHERE VALUE LIKE 'LDBC' ");
assertEquals(count, 2);
assertEquals(2, count);
count = stat.executeUpdate("UPDATE TEST SET VALUE='LDBC' WHERE VALUE LIKE '\\\\LDBC\\\\'");
trace("count:" + count);
assertEquals(count, 2);
assertEquals(2, count);
count = stat.executeUpdate("DELETE FROM TEST WHERE ID=-1");
assertEquals(count, 0);
assertEquals(0, count);
count = stat.executeUpdate("DELETE FROM TEST WHERE ID=2");
assertEquals(count, 1);
assertEquals(1, count);
try {
stat.executeUpdate("SELECT * FROM TEST");
fail("executeUpdate allowed SELECT");
......@@ -349,37 +349,37 @@ public class TestStatement extends TestBase {
stat.execute("INSERT INTO TEST VALUES(NEXT VALUE FOR SEQ)");
ResultSet rs = stat.getGeneratedKeys();
rs.next();
assertEquals(rs.getInt(1), 1);
assertEquals(1, rs.getInt(1));
assertFalse(rs.next());
stat.execute("INSERT INTO TEST VALUES(NEXT VALUE FOR SEQ)", Statement.RETURN_GENERATED_KEYS);
rs = stat.getGeneratedKeys();
rs.next();
assertEquals(rs.getInt(1), 2);
assertEquals(2, rs.getInt(1));
assertFalse(rs.next());
stat.execute("INSERT INTO TEST VALUES(NEXT VALUE FOR SEQ)", new int[] { 1 });
rs = stat.getGeneratedKeys();
rs.next();
assertEquals(rs.getInt(1), 3);
assertEquals(3, rs.getInt(1));
assertFalse(rs.next());
stat.execute("INSERT INTO TEST VALUES(NEXT VALUE FOR SEQ)", new String[] { "ID" });
rs = stat.getGeneratedKeys();
rs.next();
assertEquals(rs.getInt(1), 4);
assertEquals(4, rs.getInt(1));
assertFalse(rs.next());
stat.executeUpdate("INSERT INTO TEST VALUES(NEXT VALUE FOR SEQ)", Statement.RETURN_GENERATED_KEYS);
rs = stat.getGeneratedKeys();
rs.next();
assertEquals(rs.getInt(1), 5);
assertEquals(5, rs.getInt(1));
assertFalse(rs.next());
stat.executeUpdate("INSERT INTO TEST VALUES(NEXT VALUE FOR SEQ)", new int[] { 1 });
rs = stat.getGeneratedKeys();
rs.next();
assertEquals(rs.getInt(1), 6);
assertEquals(6, rs.getInt(1));
assertFalse(rs.next());
stat.executeUpdate("INSERT INTO TEST VALUES(NEXT VALUE FOR SEQ)", new String[] { "ID" });
rs = stat.getGeneratedKeys();
rs.next();
assertEquals(rs.getInt(1), 7);
assertEquals(7, rs.getInt(1));
assertFalse(rs.next());
stat.execute("DROP TABLE TEST");
}
......
......@@ -38,17 +38,17 @@ public class TestTransactionIsolation extends TestBase {
private void testTableLevelLocking() throws SQLException {
deleteDb("transactionIsolation");
conn1 = getConnection("transactionIsolation");
assertEquals(conn1.getTransactionIsolation(), Connection.TRANSACTION_READ_COMMITTED);
assertEquals(Connection.TRANSACTION_READ_COMMITTED, conn1.getTransactionIsolation());
conn1.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
assertEquals(conn1.getTransactionIsolation(), Connection.TRANSACTION_SERIALIZABLE);
assertEquals(Connection.TRANSACTION_SERIALIZABLE, conn1.getTransactionIsolation());
conn1.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
assertEquals(conn1.getTransactionIsolation(), Connection.TRANSACTION_READ_UNCOMMITTED);
assertEquals(Connection.TRANSACTION_READ_UNCOMMITTED, conn1.getTransactionIsolation());
assertSingleValue(conn1.createStatement(), "CALL LOCK_MODE()", 0);
conn1.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
assertSingleValue(conn1.createStatement(), "CALL LOCK_MODE()", 3);
assertEquals(conn1.getTransactionIsolation(), Connection.TRANSACTION_READ_COMMITTED);
assertEquals(Connection.TRANSACTION_READ_COMMITTED, conn1.getTransactionIsolation());
conn1.createStatement().execute("SET LOCK_MODE 1");
assertEquals(conn1.getTransactionIsolation(), Connection.TRANSACTION_SERIALIZABLE);
assertEquals(Connection.TRANSACTION_SERIALIZABLE, conn1.getTransactionIsolation());
conn1.createStatement().execute("CREATE TABLE TEST(ID INT)");
conn1.createStatement().execute("INSERT INTO TEST VALUES(1)");
conn1.setAutoCommit(false);
......
......@@ -67,13 +67,13 @@ public class TestZloty extends TestBase {
prep.execute();
ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM TEST ORDER BY ID");
rs.next();
assertEquals(rs.getInt(1), 0);
assertEquals(rs.getBytes(2)[0], 0);
assertEquals(0, rs.getInt(1));
assertEquals(0, rs.getBytes(2)[0]);
rs.next();
assertEquals(rs.getInt(1), 1);
assertEquals(rs.getBytes(2)[0], 1);
assertEquals(1, rs.getInt(1));
assertEquals(1, rs.getBytes(2)[0]);
rs.getBytes(2)[0] = 2;
assertEquals(rs.getBytes(2)[0], 1);
assertEquals(1, rs.getBytes(2)[0]);
assertFalse(rs.next());
conn.close();
}
......
......@@ -73,7 +73,7 @@ public class TestDataSource extends TestBase {
XAResource res = xaConn.getXAResource();
Connection conn = xaConn.getConnection();
Xid[] list = res.recover(XAResource.TMSTARTRSCAN);
assertEquals(list.length, 0);
assertEquals(0, list.length);
Statement stat = conn.createStatement();
stat.execute("SELECT * FROM DUAL");
conn.close();
......
......@@ -60,13 +60,13 @@ public class TestNestedLoop extends TestBase {
int id = rs.getInt(1);
ResultSet rs2 = stat2.executeQuery("select * from test where id=" + id);
while (rs2.next()) {
assertEquals(rs2.getInt(1), id);
assertEquals(rs2.getString(2), "Hello World");
assertEquals(id, rs2.getInt(1));
assertEquals("Hello World", rs2.getString(2));
}
rs2 = stat2.executeQuery("select * from test where id=" + id);
while (rs2.next()) {
assertEquals(rs2.getInt(1), id);
assertEquals(rs2.getString(2), "Hello World");
assertEquals(id, rs2.getInt(1));
assertEquals("Hello World", rs2.getString(2));
}
}
conn.close();
......
......@@ -125,7 +125,7 @@ public class TestKill extends TestBase {
ResultSet rs2 = prep.executeQuery();
rs2.next();
int sumLog = rs2.getInt(1);
assertEquals(sumLog, sum);
assertEquals(sum, sumLog);
trace("account=" + account + " sum=" + sum);
}
PreparedStatement p1 = conn.prepareStatement("SELECT * FROM TEST_A WHERE ID=?");
......
......@@ -80,7 +80,7 @@ public class TestTimer extends TestBase {
rs = stat.executeQuery("SELECT COUNT(*) FROM TEST");
rs.next();
int c = rs.getInt(1);
assertEquals(c, count);
assertEquals(count, c);
long time = System.currentTimeMillis();
if (time > start + 5000) {
println("rows: " + count);
......
......@@ -136,17 +136,17 @@ public class TestMultiOrder extends TestMultiThread {
conn = base.getConnection();
ResultSet rs = conn.createStatement().executeQuery("select count(*) from customer");
rs.next();
base.assertEquals(rs.getInt(1), customerCount);
base.assertEquals(customerCount, rs.getInt(1));
// System.out.println("customers: " + rs.getInt(1));
rs = conn.createStatement().executeQuery("select count(*) from orders");
rs.next();
base.assertEquals(rs.getInt(1), orderCount);
base.assertEquals(orderCount, rs.getInt(1));
// System.out.println("orders: " + rs.getInt(1));
rs = conn.createStatement().executeQuery("select count(*) from orderLine");
rs.next();
base.assertEquals(rs.getInt(1), orderLineCount);
base.assertEquals(orderLineCount, rs.getInt(1));
// System.out.println("orderLines: " + rs.getInt(1));
conn.close();
......
......@@ -118,9 +118,9 @@ public class TestBitField extends TestBase {
set.clear(idx);
}
} else {
assertEquals(bits.get(idx), set.get(idx));
assertEquals(bits.nextClearBit(idx), set.nextClearBit(idx));
assertEquals(bits.nextSetBit(idx), set.nextSetBit(idx));
assertEquals(set.get(idx), bits.get(idx));
assertEquals(set.nextClearBit(idx), bits.nextClearBit(idx));
assertEquals(set.nextSetBit(idx), bits.nextSetBit(idx));
}
}
}
......@@ -164,7 +164,7 @@ public class TestBitField extends TestBase {
set.set(offset, offset + len, val);
bits.setRange(offset, len, val);
for (int j = 0; j < total; j++) {
assertEquals(bits.get(j), set.get(j));
assertEquals(set.get(j), bits.get(j));
}
}
}
......
......@@ -80,7 +80,7 @@ public class TestCompress extends TestBase {
for (String a : new String[] { "LZF", "Deflate", "No" }) {
byte[] out = utils.compress(buff, a);
byte[] test = utils.expand(out);
assertEquals(test.length, buff.length);
assertEquals(buff.length, test.length);
assertEquals(buff, test);
}
}
......
......@@ -51,7 +51,7 @@ public class TestDataPage extends TestBase implements DataHandler {
String s = new String(data);
page.writeString(s);
int len = page.length();
assertEquals(page.getStringLen(s), len);
assertEquals(len, page.getStringLen(s));
page.reset();
assertEquals(s, page.readString());
page.reset();
......
......@@ -84,7 +84,7 @@ public class TestFileLock extends TestBase implements Runnable {
for (int i = 0; i < threadCount; i++) {
threads[i].join();
}
assertEquals(locks, 0);
assertEquals(0, locks);
}
public void run() {
......
......@@ -146,11 +146,11 @@ public class TestFileSystem extends TestBase {
long lastMod = fs.getLastModified(fsBase + "/test");
if (lastMod < time - 1999) {
// at most 2 seconds difference
assertEquals(lastMod, time);
assertEquals(time, lastMod);
}
assertEquals(fs.length(fsBase + "/test"), 10000);
assertEquals(10000, fs.length(fsBase + "/test"));
String[] list = fs.listFiles(fsBase);
assertEquals(list.length, 1);
assertEquals(1, list.length);
assertTrue(list[0].endsWith("test"));
fs.copy(fsBase + "/test", fsBase + "/test3");
......@@ -279,10 +279,10 @@ public class TestFileSystem extends TestBase {
out.close();
InputStream in = fs.openFileInputStream(s);
for (int i = 0; i < 10000; i++) {
assertEquals(in.read(), 0);
assertEquals(0, in.read());
}
assertEquals(in.read(), 1);
assertEquals(in.read(), -1);
assertEquals(1, in.read());
assertEquals(-1, in.read());
in.close();
out.close();
}
......
......@@ -41,11 +41,11 @@ public class TestFtp extends TestBase implements FtpEventListener {
client.login("sa", "sa");
client.makeDirectory("test");
client.changeWorkingDirectory("test");
assertEquals(lastEvent.getCommand(), "CWD");
assertEquals("CWD", lastEvent.getCommand());
client.makeDirectory("hello");
client.changeWorkingDirectory("hello");
client.changeDirectoryUp();
assertEquals(lastEvent.getCommand(), "CDUP");
assertEquals("CDUP", lastEvent.getCommand());
client.nameList("hello");
client.removeDirectory("hello");
client.close();
......
......@@ -73,11 +73,11 @@ public class TestIntArray extends TestBase {
test = sort(test);
int a = array.findNextIndexSorted(v);
int b = findNextValueIndex(test, v);
assertEquals(a, b);
assertEquals(b, a);
break;
case 4:
if (test.length > idx) {
assertEquals(array.get(idx), get(test, idx));
assertEquals(get(test, idx), array.get(idx));
}
break;
case 5:
......@@ -96,11 +96,11 @@ public class TestIntArray extends TestBase {
test = set(test, idx, v);
break;
case 8:
assertEquals(array.size(), test.length);
assertEquals(test.length, array.size());
break;
default:
}
assertEquals(array.size(), test.length);
assertEquals(test.length, array.size());
for (int j = 0; j < test.length; j++) {
assertEquals(test[j], array.get(j));
}
......
......@@ -69,34 +69,34 @@ public class TestPgServer extends TestBase {
ResultSet rs = stat.executeQuery("select * from test");
rs.next();
prep.close();
assertEquals(rs.getInt(1), 1);
assertEquals(rs.getString(2), "Hello");
assertEquals(1, rs.getInt(1));
assertEquals("Hello", rs.getString(2));
assertFalse(rs.next());
prep = conn.prepareStatement("select * from test where id = ? and name = ?");
prep.setInt(1, 1);
prep.setString(2, "Hello");
rs = prep.executeQuery();
rs.next();
assertEquals(rs.getInt(1), 1);
assertEquals(rs.getString(2), "Hello");
assertEquals(1, rs.getInt(1));
assertEquals("Hello", rs.getString(2));
assertFalse(rs.next());
rs.close();
DatabaseMetaData dbMeta = conn.getMetaData();
rs = dbMeta.getTables(null, null, "TEST", null);
rs.next();
assertEquals(rs.getString("TABLE_NAME"), "TEST");
assertEquals("TEST", rs.getString("TABLE_NAME"));
assertFalse(rs.next());
rs = dbMeta.getColumns(null, null, "TEST", null);
rs.next();
assertEquals(rs.getString("COLUMN_NAME"), "ID");
assertEquals("ID", rs.getString("COLUMN_NAME"));
rs.next();
assertEquals(rs.getString("COLUMN_NAME"), "NAME");
assertEquals("NAME", rs.getString("COLUMN_NAME"));
assertFalse(rs.next());
rs = dbMeta.getIndexInfo(null, null, "TEST", false, false);
rs.next();
assertEquals(rs.getString("TABLE_NAME"), "TEST");
assertEquals("TEST", rs.getString("TABLE_NAME"));
rs.next();
assertEquals(rs.getString("TABLE_NAME"), "TEST");
assertEquals("TEST", rs.getString("TABLE_NAME"));
assertFalse(rs.next());
rs = stat.executeQuery("select version(), pg_postmaster_start_time(), current_schema()");
rs.next();
......
......@@ -37,7 +37,7 @@ public class TestReader extends TestBase {
InputStream in2 = new ByteArrayInputStream(buff);
Reader r2 = IOUtils.getReader(in2);
String s2 = IOUtils.readStringAndClose(r2, Integer.MAX_VALUE);
assertEquals(s2, "\u00ef\u00f6\u00fc");
assertEquals(s, s2);
}
}
......@@ -88,10 +88,10 @@ public class TestSampleApps extends TestBase {
if (expected.endsWith("*")) {
expected = expected.substring(0, expected.length() - 1);
if (!s.startsWith(expected)) {
assertEquals(s.trim(), expected.trim());
assertEquals(expected.trim(), s.trim());
}
} else {
assertEquals(s.trim(), expected.trim());
assertEquals(expected.trim(), s.trim());
}
}
}
......@@ -42,7 +42,7 @@ public class TestSecurity extends TestBase {
private String getHashString(SHA256 sha, byte[] data) {
byte[] result = sha.getHash(data, true);
if (data.length > 0) {
assertEquals(data[0], 0);
assertEquals(0, data[0]);
}
return ByteUtils.convertBytesToString(result);
}
......
......@@ -68,9 +68,9 @@ public class TestValue extends TestBase {
minLow &= uuid.getLow();
}
ValueUuid max = ValueUuid.get(maxHigh, maxLow);
assertEquals(max.getString(), "ffffffff-ffff-4fff-bfff-ffffffffffff");
assertEquals("ffffffff-ffff-4fff-bfff-ffffffffffff", max.getString());
ValueUuid min = ValueUuid.get(minHigh, minLow);
assertEquals(min.getString(), "00000000-0000-4000-8000-000000000000");
assertEquals("00000000-0000-4000-8000-000000000000", min.getString());
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论