use of org.talend.components.jdbc.tjdbcinput.TJDBCInputDefinition in project components by Talend.
the class JdbcRowTestIT method test_use_preparedstatement_no_connector.
@Test
public void test_use_preparedstatement_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(?, ?)");
properties.dieOnError.setValue(true);
randomCommit(properties);
properties.usePreparedStatement.setValue(true);
properties.preparedStatementTable.indexs.setValue(Arrays.asList(1, 2));
properties.preparedStatementTable.types.setValue(Arrays.asList(PreparedStatementTable.Type.Int.name(), PreparedStatementTable.Type.String.name()));
properties.preparedStatementTable.values.setValue(Arrays.<Object>asList(4, "momo"));
try (SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClass(definition.getRuntimeInfo(ExecutionEngine.DI, properties, ConnectorTopology.NONE), properties.getClass().getClassLoader())) {
JDBCRowSourceOrSink sourceOrSink = (JDBCRowSourceOrSink) sandboxedInstance.getInstance();
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));
}
use of org.talend.components.jdbc.tjdbcinput.TJDBCInputDefinition in project components by Talend.
the class JDBCInputTestIT method testGetSchemaNamesWithException.
@Test(expected = ComponentException.class)
public void testGetSchemaNamesWithException() throws Exception {
TJDBCInputDefinition definition = new TJDBCInputDefinition();
TJDBCInputProperties properties = DBTestUtils.createCommonJDBCInputProperties(allSetting, definition);
properties.connection.driverClass.setValue("notexist");
JDBCSource source = DBTestUtils.createCommonJDBCSource(properties);
try {
source.getSchemaNames(null);
} catch (ComponentException e) {
String message = CommonUtils.getClearExceptionInfo(e);
assertTrue(message.contains("notexist"));
throw e;
}
}
use of org.talend.components.jdbc.tjdbcinput.TJDBCInputDefinition in project components by Talend.
the class JDBCInputTestIT method testGetSchemaFromQueryWithException1.
@Test(expected = ComponentException.class)
public void testGetSchemaFromQueryWithException1() throws Exception {
TJDBCInputDefinition definition = new TJDBCInputDefinition();
TJDBCInputProperties properties = DBTestUtils.createCommonJDBCInputProperties(allSetting, definition);
JDBCSource source = DBTestUtils.createCommonJDBCSource(properties);
try {
source.getSchemaFromQuery(null, "select * from notexist");
} catch (ComponentException e) {
String message = CommonUtils.getClearExceptionInfo(e);
assertTrue(message != null && !message.isEmpty());
throw e;
}
}
use of org.talend.components.jdbc.tjdbcinput.TJDBCInputDefinition in project components by Talend.
the class JDBCInputTestIT method testType.
@SuppressWarnings({ "rawtypes" })
@Test
public void testType() throws Exception {
TJDBCInputDefinition definition = new TJDBCInputDefinition();
TJDBCInputProperties properties = DBTestUtils.createCommonJDBCInputProperties(allSetting, definition);
properties.main.schema.setValue(DBTestUtils.createTestSchema(tablename));
properties.tableSelection.tablename.setValue(tablename);
properties.sql.setValue(DBTestUtils.getSQL(tablename));
Reader reader = DBTestUtils.createCommonJDBCInputReader(properties);
try {
IndexedRecordConverter<Object, ? extends IndexedRecord> converter = null;
for (boolean available = reader.start(); available; available = reader.advance()) {
converter = DBTestUtils.getIndexRecordConverter(reader, converter);
IndexedRecord record = converter.convertToAvro(reader.getCurrent());
assertEquals(Integer.class, record.get(0).getClass());
assertEquals(String.class, record.get(1).getClass());
}
reader.close();
} finally {
reader.close();
}
}
use of org.talend.components.jdbc.tjdbcinput.TJDBCInputDefinition in project components by Talend.
the class JDBCSchemaTestIT method testGetSchema.
@Test
public void testGetSchema() throws Exception {
TJDBCInputDefinition definition = new TJDBCInputDefinition();
TJDBCInputProperties properties = DBTestUtils.createCommonJDBCInputProperties(allSetting, definition);
properties.main.schema.setValue(DBTestUtils.createTestSchema3(true, tablename));
properties.tableSelection.tablename.setValue(tablename);
properties.sql.setValue(DBTestUtils.getSQL(tablename));
JDBCSource source = DBTestUtils.createCommonJDBCSource(properties);
RuntimeContainer container = new DefaultComponentRuntimeContainerImpl() {
@Override
public String getCurrentComponentId() {
return "tJDBCInput1";
}
};
java.net.URL mappings_url = this.getClass().getResource("/mappings");
mappings_url = DBTestUtils.correctURL(mappings_url);
container.setComponentData(container.getCurrentComponentId(), ComponentConstants.MAPPING_URL_SUBFIX, mappings_url);
Schema schema = source.getEndpointSchema(container, tablename);
assertEquals(tablename, schema.getName().toUpperCase());
List<Field> columns = schema.getFields();
testMetadata(columns);
}
Aggregations