use of org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties in project components by Talend.
the class JDBCInputTestIT method testGetSchemaNames.
@Test
public void testGetSchemaNames() 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));
JDBCSource source = DBTestUtils.createCommonJDBCSource(properties);
List<NamedThing> schemaNames = source.getSchemaNames(null);
assertTrue(schemaNames != null);
assertTrue(!schemaNames.isEmpty());
boolean exists = false;
for (NamedThing name : schemaNames) {
if (tablename.equals(name.getName().toUpperCase())) {
exists = true;
break;
}
}
assertTrue(exists);
}
use of org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties in project components by Talend.
the class JDBCInputTestIT method testGetSchemaFromQueryWithException2.
@Test(expected = ComponentException.class)
public void testGetSchemaFromQueryWithException2() throws Exception {
TJDBCInputDefinition definition = new TJDBCInputDefinition();
TJDBCInputProperties properties = DBTestUtils.createCommonJDBCInputProperties(allSetting, definition);
properties.connection.driverClass.setValue("notexist");
JDBCSource source = DBTestUtils.createCommonJDBCSource(properties);
try {
source.getSchemaFromQuery(null, "select * from " + tablename);
} catch (ComponentException e) {
String message = CommonUtils.getClearExceptionInfo(e);
assertTrue(message.contains("notexist"));
throw e;
}
}
use of org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties in project components by Talend.
the class JDBCInputTestIT method testGetSchemaWithException.
@Test(expected = ComponentException.class)
public void testGetSchemaWithException() throws Exception {
TJDBCInputDefinition definition = new TJDBCInputDefinition();
TJDBCInputProperties properties = DBTestUtils.createCommonJDBCInputProperties(allSetting, definition);
properties.connection.driverClass.setValue("notexist");
JDBCSource source = DBTestUtils.createCommonJDBCSource(properties);
try {
source.getEndpointSchema(null, tablename);
} catch (ComponentException e) {
String message = CommonUtils.getClearExceptionInfo(e);
assertTrue(message.contains("notexist"));
throw e;
}
}
use of org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties in project components by Talend.
the class JDBCInputTestIT method testReaderAllTypesString.
/**
* Checks {@link JDBCInputReader} outputs {@link IndexedRecord} which contains nullable String type data for every SQL/JDBC
* type
*/
@Test
public void testReaderAllTypesString() throws IOException {
TJDBCInputDefinition definition = new TJDBCInputDefinition();
TJDBCInputProperties properties = DBTestUtils.createCommonJDBCInputProperties(allSetting, definition);
properties.main.schema.setValue(DBTestUtils.createAllTypesSchema(tablename_all_type));
properties.tableSelection.tablename.setValue(tablename_all_type);
properties.sql.setValue(DBTestUtils.getSQL(tablename_all_type));
Reader reader = DBTestUtils.createCommonJDBCInputReader(properties);
reader.start();
IndexedRecord record = (IndexedRecord) reader.getCurrent();
Short col0 = (Short) record.get(0);
Integer col1 = (Integer) record.get(1);
Long col2 = (Long) record.get(2);
Float col3 = (Float) record.get(3);
Double col4 = (Double) record.get(4);
BigDecimal col5 = (BigDecimal) record.get(5);
String col6 = (String) record.get(6);
String col7 = (String) record.get(7);
String col8 = (String) record.get(8);
String col9 = (String) record.get(9);
Long col10 = (Long) record.get(10);
Long col11 = (Long) record.get(11);
Long col12 = (Long) record.get(12);
Boolean col13 = (Boolean) record.get(13);
assertEquals(32767, col0.shortValue());
assertEquals(2147483647, col1.intValue());
assertEquals(9223372036854775807l, col2.longValue());
assertTrue(col3 > 1);
assertTrue(col4 > 2);
assertEquals(new BigDecimal("1234567890.1234567890"), col5);
assertEquals("abcd", col6);
assertEquals("abcdefg", col7);
assertEquals("00010203040506070809", col8);
assertEquals("abcdefg", col9);
assertEquals("2016-12-28", new SimpleDateFormat("yyyy-MM-dd").format(new Date(col10)));
assertEquals("14:30:33", new SimpleDateFormat("HH:mm:ss").format(new Date(col11)));
assertEquals("2016-12-28 14:31:56.123", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date(col12)));
assertEquals(true, col13);
Schema actualSchema = record.getSchema();
List<Field> actualFields = actualSchema.getFields();
assertEquals(14, actualFields.size());
reader.close();
}
use of org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties in project components by Talend.
the class JDBCRowTestIT method commonAssert.
private void commonAssert(TJDBCRowProperties properties, Schema schema) throws IOException {
JDBCRowSink sink = new JDBCRowSink();
sink.initialize(null, properties);
ValidationResult result = sink.validate(null);
Assert.assertTrue(result.getStatus() == ValidationResult.Result.OK);
WriteOperation operation = sink.createWriteOperation();
JDBCRowWriter writer = (JDBCRowWriter) operation.createWriter(null);
try {
writer.open("wid");
IndexedRecord r1 = new GenericData.Record(properties.main.schema.getValue());
r1.put(0, 4);
r1.put(1, "xiaoming");
writer.write(r1);
DBTestUtils.assertSuccessRecord(writer, r1);
IndexedRecord r2 = new GenericData.Record(properties.main.schema.getValue());
r2.put(0, 5);
r2.put(1, "xiaobai");
writer.write(r2);
DBTestUtils.assertSuccessRecord(writer, r2);
writer.close();
} finally {
writer.close();
}
TJDBCInputDefinition definition1 = new TJDBCInputDefinition();
TJDBCInputProperties properties1 = DBTestUtils.createCommonJDBCInputProperties(allSetting, definition1);
List<IndexedRecord> records = DBTestUtils.fetchDataByReaderFromTable(tablename, schema, definition1, properties1);
assertThat(records, hasSize(5));
Assert.assertEquals(new Integer(4), records.get(3).get(0));
Assert.assertEquals("momo", records.get(3).get(1));
Assert.assertEquals(new Integer(4), records.get(4).get(0));
Assert.assertEquals("momo", records.get(4).get(1));
}
Aggregations