use of org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties 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.TJDBCInputProperties in project components by Talend.
the class CommonUtilsTest method testGetMainSchemaFromOutputConnector.
@Test
public void testGetMainSchemaFromOutputConnector() {
TJDBCInputProperties properties = new TJDBCInputProperties("input");
properties.init();
Schema schema = CommonUtils.getMainSchemaFromOutputConnector(properties);
Assert.assertNotNull(schema);
}
use of org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties in project components by Talend.
the class CommonUtilsTest method testGetOutputSchema.
@Test
public void testGetOutputSchema() {
TJDBCInputProperties properties = new TJDBCInputProperties("input");
properties.init();
Schema schema = CommonUtils.getOutputSchema(properties);
Assert.assertNotNull(schema);
}
use of org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties 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.TJDBCInputProperties 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;
}
}
Aggregations