use of org.talend.components.jdbc.runtime.JDBCRowSource in project components by Talend.
the class JDBCRowTestIT method test_basic_as_input.
@SuppressWarnings("rawtypes")
@Test
public void test_basic_as_input() throws Exception {
TJDBCRowDefinition definition = new TJDBCRowDefinition();
TJDBCRowProperties properties = DBTestUtils.createCommonJDBCRowProperties(allSetting, definition);
Schema schema = DBTestUtils.createTestSchema4(tablename);
properties.main.schema.setValue(schema);
properties.updateOutputSchemas();
properties.tableSelection.tablename.setValue(tablename);
properties.sql.setValue("select id, name from " + tablename);
properties.dieOnError.setValue(true);
randomCommit(properties);
// the field is the unique reason to use the component as a input
properties.propagateQueryResultSet.setValue(true);
// component
properties.beforeUseColumn();
properties.useColumn.setValue(properties.useColumn.getPossibleValues().get(0).toString());
JDBCRowSource source = new JDBCRowSource();
source.initialize(null, properties);
ValidationResult result = source.validate(null);
Assert.assertTrue(result.getStatus() == ValidationResult.Result.OK);
Reader reader = source.createReader(null);
try {
reader.start();
IndexedRecord row = (IndexedRecord) reader.getCurrent();
ResultSet resultSet = (ResultSet) row.get(0);
resultSet.next();
Assert.assertEquals(1, resultSet.getInt(1));
Assert.assertEquals("wangwei", resultSet.getString(2));
resultSet.next();
Assert.assertEquals(2, resultSet.getInt(1));
Assert.assertEquals("gaoyan", resultSet.getString(2));
resultSet.next();
Assert.assertEquals(3, resultSet.getInt(1));
Assert.assertEquals("dabao", resultSet.getString(2));
resultSet.close();
// only output one row when it works as a input component
Assert.assertFalse(reader.advance());
reader.close();
} finally {
reader.close();
}
}
Aggregations