public class TestXMLContext extends TestCase {
static String resultSetName = "ResultSet"; //$NON-NLS-1$
public void testGetCurrentRow() throws Exception{
XMLContext context = new XMLContext();
List[] rows = new List[] {
Arrays.asList( new Object[] { "Lamp", new Integer(5), null } ), //$NON-NLS-1$
Arrays.asList( new Object[] { "Screwdriver", new Integer(100), null } ), //$NON-NLS-1$
Arrays.asList( new Object[] { "Goat", new Integer(4), null } ) //$NON-NLS-1$
};
FakePlanExecutor executor = new FakePlanExecutor(resultSetName, rows);
context.setResultSet(resultSetName, executor);
List currentRow = context.getCurrentRow(resultSetName);
// this is only behaviour of the Fake Plan executor
assertNull(currentRow);
// move cursor forward
currentRow = context.getNextRow(resultSetName);
assertEquals(Arrays.asList( new Object[] { "Lamp", new Integer(5), null } ), currentRow); //$NON-NLS-1$
// check the cursor again should be same as previous.
currentRow = context.getCurrentRow(resultSetName);
assertEquals(Arrays.asList( new Object[] { "Lamp", new Integer(5), null } ), currentRow); //$NON-NLS-1$
// check the cursor 2nd again, make sure it is not moved
currentRow = context.getCurrentRow(resultSetName);
assertEquals(Arrays.asList( new Object[] { "Lamp", new Integer(5), null } ), currentRow); //$NON-NLS-1$
// test remove
context.removeResultSet(resultSetName);
try {
currentRow = context.getCurrentRow(resultSetName);
fail("must have failed because the results are removed."); //$NON-NLS-1$
}catch(TeiidComponentException e) {
}
}