use of org.talend.components.jdbc.tjdbcrow.TJDBCRowProperties in project components by Talend.
the class DBTestUtils method createCommonJDBCRowProperties.
public static TJDBCRowProperties createCommonJDBCRowProperties(AllSetting allSetting, TJDBCRowDefinition definition) {
TJDBCRowProperties properties = (TJDBCRowProperties) definition.createRuntimeProperties();
// properties.connection.driverTable.drivers.setValue(Arrays.asList(driverPath));
properties.connection.driverClass.setValue(allSetting.getDriverClass());
properties.connection.jdbcUrl.setValue(allSetting.getJdbcUrl());
properties.connection.userPassword.userId.setValue(allSetting.getUsername());
properties.connection.userPassword.password.setValue(allSetting.getPassword());
return properties;
}
use of org.talend.components.jdbc.tjdbcrow.TJDBCRowProperties in project components by Talend.
the class JDBCRowTestIT method test_basic_not_use_prepared_statement_as_output.
@SuppressWarnings("rawtypes")
@Test
public void test_basic_not_use_prepared_statement_as_output() throws Exception {
TJDBCRowDefinition definition = new TJDBCRowDefinition();
TJDBCRowProperties properties = DBTestUtils.createCommonJDBCRowProperties(allSetting, definition);
Schema schema = DBTestUtils.createTestSchema(tablename);
properties.main.schema.setValue(schema);
properties.updateOutputSchemas();
properties.tableSelection.tablename.setValue(tablename);
properties.sql.setValue("insert into " + tablename + " values(4,'momo')");
properties.dieOnError.setValue(true);
randomCommit(properties);
properties.usePreparedStatement.setValue(false);
commonAssert(properties, schema);
}
use of org.talend.components.jdbc.tjdbcrow.TJDBCRowProperties in project components by Talend.
the class JDBCRowTestIT method test_reject_as_input.
@SuppressWarnings("rawtypes")
@Test
public void test_reject_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 notexists");
properties.dieOnError.setValue(false);
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();
reader.getCurrent();
// should go to the exception before current statement
Assert.fail();
reader.advance();
reader.close();
} catch (DataRejectException e) {
Map<String, Object> info = e.getRejectInfo();
IndexedRecord data = (IndexedRecord) info.get("talend_record");
Assert.assertNull(data.get(0));
Assert.assertNotNull(data.get(1));
Assert.assertNotNull(data.get(2));
} finally {
reader.close();
}
}
use of org.talend.components.jdbc.tjdbcrow.TJDBCRowProperties in project components by Talend.
the class JDBCRowTestIT method test_die_on_error_no_connector.
@Test
public void test_die_on_error_no_connector() throws Exception {
TJDBCRowDefinition definition = new TJDBCRowDefinition();
TJDBCRowProperties properties = DBTestUtils.createCommonJDBCRowProperties(allSetting, definition);
properties.tableSelection.tablename.setValue(tablename);
properties.sql.setValue("insert into " + tablename + " values(4, 'a too long value')");
properties.dieOnError.setValue(true);
randomCommit(properties);
JDBCRowSourceOrSink sourceOrSink = new JDBCRowSourceOrSink();
sourceOrSink.initialize(null, properties);
ValidationResult result = sourceOrSink.validate(null);
Assert.assertTrue(result.getStatus() == ValidationResult.Result.ERROR);
Assert.assertNotNull(result.getMessage());
}
use of org.talend.components.jdbc.tjdbcrow.TJDBCRowProperties in project components by Talend.
the class JDBCRowTestIT method test_basic_no_connector.
@Test
public void test_basic_no_connector() throws Exception {
TJDBCRowDefinition definition = new TJDBCRowDefinition();
TJDBCRowProperties properties = DBTestUtils.createCommonJDBCRowProperties(allSetting, definition);
properties.tableSelection.tablename.setValue(tablename);
properties.sql.setValue("insert into " + tablename + " values(4, 'momo')");
properties.dieOnError.setValue(true);
randomCommit(properties);
JDBCRowSourceOrSink sourceOrSink = new JDBCRowSourceOrSink();
sourceOrSink.initialize(null, properties);
ValidationResult result = sourceOrSink.validate(null);
Assert.assertTrue(result.getStatus() == ValidationResult.Result.OK);
TJDBCInputDefinition definition1 = new TJDBCInputDefinition();
TJDBCInputProperties properties1 = DBTestUtils.createCommonJDBCInputProperties(allSetting, definition1);
List<IndexedRecord> records = DBTestUtils.fetchDataByReaderFromTable(tablename, DBTestUtils.createTestSchema(tablename), definition1, properties1);
assertThat(records, hasSize(4));
Assert.assertEquals(new Integer(4), records.get(3).get(0));
Assert.assertEquals("momo", records.get(3).get(1));
}
Aggregations