}
}
public void testSetMatchColumn_Index() throws Exception {
JdbcRowSet noInitalJrs = noInitalJdbcRowSet();
JdbcRowSet jrs = newJdbcRowSet();
try {
noInitalJrs.setMatchColumn(-2);
fail("Should throw SQLException");
} catch (SQLException e) {
// expected, Match columns should be greater than 0
}
int[] indexes = null;
try {
noInitalJrs.setMatchColumn(indexes);
fail("Should throw NullPointerException");
} catch (NullPointerException e) {
// expected
}
// TODO 0 is valid index 0f column?
noInitalJrs.setMatchColumn(0);
indexes = noInitalJrs.getMatchColumnIndexes();
assertNotNull(indexes);
assertEquals(10, indexes.length);
for (int i = 0; i < indexes.length; i++) {
if (i == 0) {
assertEquals(0, indexes[i]);
} else {
assertEquals(-1, indexes[i]);
}
}
noInitalJrs.setMatchColumn(1);
indexes = noInitalJrs.getMatchColumnIndexes();
assertNotNull(indexes);
assertEquals(10, indexes.length);
for (int i = 0; i < indexes.length; i++) {
if (i == 0) {
assertEquals(1, indexes[i]);
} else {
assertEquals(-1, indexes[i]);
}
}
noInitalJrs.setMatchColumn(new int[] { 3, 4, 5 });
indexes = noInitalJrs.getMatchColumnIndexes();
try {
noInitalJrs.setMatchColumn(new int[] { 3, -3 });
fail("Should throw SQLException");
} catch (SQLException e) {
// expected, Match columns should be greater than 0
}
assertNotNull(indexes);
assertEquals(13, indexes.length);
assertEquals(3, indexes[0]);
assertEquals(4, indexes[1]);
assertEquals(5, indexes[2]);
assertEquals(1, indexes[3]);
for (int i = 4; i < indexes.length; i++) {
assertEquals(-1, indexes[i]);
}
noInitalJrs.setMatchColumn(6);
indexes = noInitalJrs.getMatchColumnIndexes();
assertNotNull(indexes);
assertEquals(13, indexes.length);
assertEquals(6, indexes[0]);
assertEquals(4, indexes[1]);
assertEquals(5, indexes[2]);
assertEquals(1, indexes[3]);
noInitalJrs.setMatchColumn(new int[] { 7, 8 });
indexes = noInitalJrs.getMatchColumnIndexes();
assertNotNull(indexes);
assertEquals(15, indexes.length);
assertEquals(7, indexes[0]);
assertEquals(8, indexes[1]);
assertEquals(6, indexes[2]);
assertEquals(4, indexes[3]);
assertEquals(5, indexes[4]);
assertEquals(1, indexes[5]);
for (int i = 6; i < indexes.length; i++) {
assertEquals(-1, indexes[i]);
}
noInitalJrs.setMatchColumn(9);
indexes = noInitalJrs.getMatchColumnIndexes();
assertNotNull(indexes);
assertEquals(15, indexes.length);
assertEquals(9, indexes[0]);
assertEquals(8, indexes[1]);
assertEquals(6, indexes[2]);
assertEquals(4, indexes[3]);
assertEquals(5, indexes[4]);
assertEquals(1, indexes[5]);
for (int i = 6; i < indexes.length; i++) {
assertEquals(-1, indexes[i]);
}
try {
jrs.setMatchColumn(-2);
fail("Should throw SQLException");
} catch (SQLException e) {
// expected, Match columns should be greater than 0
}
indexes = null;
try {
jrs.setMatchColumn(indexes);
fail("Should throw NullPointerException");
} catch (NullPointerException e) {
// expected
}
jrs.setMatchColumn(0);
indexes = jrs.getMatchColumnIndexes();
assertNotNull(indexes);
assertEquals(10, indexes.length);
for (int i = 0; i < indexes.length; i++) {
if (i == 0) {
assertEquals(0, indexes[i]);
} else {
assertEquals(-1, indexes[i]);
}
}
jrs.setMatchColumn(1);
indexes = jrs.getMatchColumnIndexes();
assertNotNull(indexes);
assertEquals(10, indexes.length);
for (int i = 0; i < indexes.length; i++) {
if (i == 0) {
assertEquals(1, indexes[i]);
} else {
assertEquals(-1, indexes[i]);
}
}
jrs.setMatchColumn(new int[] { 3, 4, 5 });
indexes = jrs.getMatchColumnIndexes();
assertNotNull(indexes);
assertEquals(13, indexes.length);
assertEquals(3, indexes[0]);
assertEquals(4, indexes[1]);
assertEquals(5, indexes[2]);
assertEquals(1, indexes[3]);
for (int i = 4; i < indexes.length; i++) {
assertEquals(-1, indexes[i]);
}
jrs.setMatchColumn(6);
indexes = jrs.getMatchColumnIndexes();
assertNotNull(indexes);
assertEquals(13, indexes.length);
assertEquals(6, indexes[0]);
assertEquals(4, indexes[1]);
assertEquals(5, indexes[2]);
assertEquals(1, indexes[3]);
for (int i = 4; i < indexes.length; i++) {
assertEquals(-1, indexes[i]);
}
jrs.setMatchColumn(new int[] { 7, 8 });
indexes = jrs.getMatchColumnIndexes();
assertNotNull(indexes);
assertEquals(15, indexes.length);
assertEquals(7, indexes[0]);
assertEquals(8, indexes[1]);
assertEquals(6, indexes[2]);
assertEquals(4, indexes[3]);
assertEquals(5, indexes[4]);
assertEquals(1, indexes[5]);
for (int i = 6; i < indexes.length; i++) {
assertEquals(-1, indexes[i]);
}
jrs.setMatchColumn(9);
indexes = jrs.getMatchColumnIndexes();
assertNotNull(indexes);
assertEquals(15, indexes.length);
assertEquals(9, indexes[0]);
assertEquals(8, indexes[1]);
assertEquals(6, indexes[2]);
assertEquals(4, indexes[3]);
assertEquals(5, indexes[4]);
assertEquals(1, indexes[5]);
for (int i = 6; i < indexes.length; i++) {
assertEquals(-1, indexes[i]);
}
// exceed column count
jrs.setMatchColumn(100);
assertEquals(100, jrs.getMatchColumnIndexes()[0]);
noInitalJrs = noInitalJdbcRowSet();
noInitalJrs.setMatchColumn(new int[] { 1, 2, 3 });
indexes = noInitalJrs.getMatchColumnIndexes();