use of org.talend.components.jdbc.runtime.JDBCCloseSourceOrSink in project components by Talend.
the class JDBCloseTestIT method testClose.
@Test
public void testClose() {
TJDBCConnectionDefinition connectionDefinition = new TJDBCConnectionDefinition();
TJDBCConnectionProperties properties = DBTestUtils.createCommonJDBCConnectionProperties(allSetting, connectionDefinition);
JDBCSourceOrSink sourceOrSink = new JDBCSourceOrSink();
sourceOrSink.initialize(null, properties);
ValidationResult result = sourceOrSink.validate(container);
assertTrue(result.getStatus() == ValidationResult.Result.OK);
TJDBCCloseDefinition closeDefinition = new TJDBCCloseDefinition();
TJDBCCloseProperties closeProperties = (TJDBCCloseProperties) closeDefinition.createRuntimeProperties();
closeProperties.referencedComponent.componentInstanceId.setValue(refComponentId);
JDBCCloseSourceOrSink closeSourceOrSink = new JDBCCloseSourceOrSink();
closeSourceOrSink.initialize(container, closeProperties);
closeSourceOrSink.validate(container);
try (java.sql.Connection conn = (java.sql.Connection) container.getComponentData(ComponentConstants.CONNECTION_KEY, refComponentId)) {
if (conn != null) {
Assert.assertTrue(conn.isClosed());
}
} catch (SQLException e) {
Assert.fail(e.getMessage());
}
}
Aggregations