Search in sources :

Example 1 with JDBCCloseSourceOrSink

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());
    }
}
Also used : JDBCSourceOrSink(org.talend.components.jdbc.runtime.JDBCSourceOrSink) TJDBCConnectionProperties(org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionProperties) SQLException(java.sql.SQLException) JDBCCloseSourceOrSink(org.talend.components.jdbc.runtime.JDBCCloseSourceOrSink) TJDBCCloseProperties(org.talend.components.jdbc.tjdbcclose.TJDBCCloseProperties) ValidationResult(org.talend.daikon.properties.ValidationResult) TJDBCConnectionDefinition(org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionDefinition) TJDBCCloseDefinition(org.talend.components.jdbc.tjdbcclose.TJDBCCloseDefinition) Test(org.junit.Test)

Aggregations

SQLException (java.sql.SQLException)1 Test (org.junit.Test)1 JDBCCloseSourceOrSink (org.talend.components.jdbc.runtime.JDBCCloseSourceOrSink)1 JDBCSourceOrSink (org.talend.components.jdbc.runtime.JDBCSourceOrSink)1 TJDBCCloseDefinition (org.talend.components.jdbc.tjdbcclose.TJDBCCloseDefinition)1 TJDBCCloseProperties (org.talend.components.jdbc.tjdbcclose.TJDBCCloseProperties)1 TJDBCConnectionDefinition (org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionDefinition)1 TJDBCConnectionProperties (org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionProperties)1 ValidationResult (org.talend.daikon.properties.ValidationResult)1