public class JdbcRowSetJoinTest extends CachedRowSetTestCase {
public void testSetMatchColumn_Name() throws Exception {
String name = null;
JdbcRowSet noInitalJrs = noInitalJdbcRowSet();
JdbcRowSet jrs = newJdbcRowSet();
/*
* TODO spec: throw SQLException, RI throw NullPointerException, Harmony
* follow spec
*/
if (!"true".equals(System.getProperty("Testing Harmony"))) {
try {
noInitalJrs.setMatchColumn(name);
fail("Should throw NullPointerException");
} catch (NullPointerException e) {
// expected
}
} else {
try {
noInitalJrs.setMatchColumn(name);
fail("Should throw SQLException");
} catch (SQLException e) {
// expected, Match columns should not be empty or null string
}
}
try {
noInitalJrs.setMatchColumn("");
fail("Should throw SQLException");
} catch (SQLException e) {
// expected, Match columns should not be empty or null string
}
noInitalJrs.setMatchColumn("not exist");
String[] names = noInitalJrs.getMatchColumnNames();
assertNotNull(names);
assertEquals(10, names.length);
assertEquals("not exist", names[0]);
for (int i = 1; i < names.length; i++) {
assertNull(names[i]);
}
noInitalJrs.setMatchColumn("id");
names = noInitalJrs.getMatchColumnNames();
assertNotNull(names);
assertEquals(10, names.length);
assertEquals("id", names[0]);
for (int i = 1; i < names.length; i++) {
assertNull(names[i]);
}
noInitalJrs.setMatchColumn(new String[] { "ID", "NAME" });
names = null;
try {
noInitalJrs.setMatchColumn(names);
fail("Should throw NullPointerException");
} catch (NullPointerException e) {
// expected
}
names = noInitalJrs.getMatchColumnNames();
assertNotNull(names);
assertEquals(12, names.length);
assertEquals("ID", names[0]);
assertEquals("NAME", names[1]);
assertEquals("id", names[2]);
for (int i = 3; i < names.length; i++) {
assertNull(names[i]);
}
try {
noInitalJrs.setMatchColumn(new String[] { "ID", "" });
fail("Should throw SQLException");
} catch (SQLException e) {
// expected, Match columns should not be empty or null string
}
try {
noInitalJrs.setMatchColumn(new String[] { "ID", null });
fail("Should throw SQLException");
} catch (SQLException e) {
// expected, Match columns should not be empty or null string
}
noInitalJrs.setMatchColumn("NAME");
names = noInitalJrs.getMatchColumnNames();
assertNotNull(names);
assertEquals(12, names.length);
assertEquals("NAME", names[0]);
assertEquals("NAME", names[1]);
assertEquals("id", names[2]);
for (int i = 3; i < names.length; i++) {
assertNull(names[i]);
}
if (!"true".equals(System.getProperty("Testing Harmony"))) {
try {
jrs.setMatchColumn(name);
fail("Should throw NullPointerException");
} catch (NullPointerException e) {
// expected
}
} else {
try {
jrs.setMatchColumn(name);
fail("Should throw SQLException");
} catch (SQLException e) {
// expected, Match columns should not be empty or null string
}
}
try {
jrs.setMatchColumn("");
fail("Should throw SQLException");
} catch (SQLException e) {
// expected, Match columns should not be empty or null string
}
jrs.setMatchColumn("not exist");
names = jrs.getMatchColumnNames();
assertNotNull(names);
assertEquals(10, names.length);
assertEquals("not exist", names[0]);
for (int i = 1; i < names.length; i++) {
assertNull(names[i]);
}
jrs.setMatchColumn("id");
names = jrs.getMatchColumnNames();
assertNotNull(names);
assertEquals(10, names.length);
assertEquals("id", names[0]);
for (int i = 1; i < names.length; i++) {
assertNull(names[i]);
}
jrs.setMatchColumn(new String[] { "ID", "NAME" });
names = jrs.getMatchColumnNames();
assertNotNull(names);
assertEquals(12, names.length);
assertEquals("ID", names[0]);
assertEquals("NAME", names[1]);
assertEquals("id", names[2]);
for (int i = 3; i < names.length; i++) {
assertNull(names[i]);
}
try {
jrs.setMatchColumn(new String[] { "ID", "" });
fail("Should throw SQLException");
} catch (SQLException e) {
// expected, Match columns should not be empty or null string
}
try {
jrs.setMatchColumn(new String[] { "ID", null });
fail("Should throw SQLException");
} catch (SQLException e) {
// expected, Match columns should not be empty or null string
}
jrs.setMatchColumn("NAME");
names = jrs.getMatchColumnNames();
assertNotNull(names);
assertEquals(12, names.length);
assertEquals("NAME", names[0]);
assertEquals("NAME", names[1]);
assertEquals("id", names[2]);