use of org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties 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.TJDBCInputProperties in project components by Talend.
the class DBTestUtils method createCommonJDBCInputProperties.
public static TJDBCInputProperties createCommonJDBCInputProperties(AllSetting allSetting, TJDBCInputDefinition definition) {
TJDBCInputProperties properties = (TJDBCInputProperties) definition.createRuntimeProperties();
// TODO now framework doesn't support to load the JDBC jar by the setting
// properties.connection.driverJar.setValue(null);
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.tjdbcinput.TJDBCInputProperties 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);
}
use of org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties in project components by Talend.
the class JDBCTypeMappingTestIT 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);
}
use of org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties in project components by Talend.
the class JDBCInputTestIT method testGetSchemaFromQueryWithException3.
@Test(expected = ComponentException.class)
public void testGetSchemaFromQueryWithException3() throws Exception {
TJDBCInputDefinition definition = new TJDBCInputDefinition();
TJDBCInputProperties properties = DBTestUtils.createCommonJDBCInputProperties(allSetting, definition);
properties.connection.jdbcUrl.setValue("wrongone");
JDBCSource source = DBTestUtils.createCommonJDBCSource(properties);
try {
source.getSchemaFromQuery(null, "select * from " + tablename);
} catch (ComponentException e) {
String message = CommonUtils.getClearExceptionInfo(e);
assertTrue(message != null && !message.isEmpty());
throw e;
}
}
Aggregations