Search in sources :

Example 6 with TJDBCConnectionDefinition

use of org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionDefinition in project components by Talend.

the class JDBCConnectionTestIT method testConnectionWithEmptyJDBCURL.

@Test
public void testConnectionWithEmptyJDBCURL() {
    TJDBCConnectionDefinition definition = new TJDBCConnectionDefinition();
    TJDBCConnectionProperties properties = (TJDBCConnectionProperties) definition.createRuntimeProperties();
    properties.connection.jdbcUrl.setValue("");
    properties.connection.driverClass.setValue(allSetting.getDriverClass());
    properties.connection.userPassword.userId.setValue(allSetting.getUsername());
    properties.connection.userPassword.password.setValue(allSetting.getPassword());
    JDBCSourceOrSink sourceOrSink = new JDBCSourceOrSink();
    sourceOrSink.initialize(null, properties);
    ValidationResult result = sourceOrSink.validate(null);
    assertTrue(result.getStatus() == ValidationResult.Result.ERROR);
    assertTrue(result.getMessage() != null && result.getMessage().contains("JDBC URL"));
}
Also used : JDBCSourceOrSink(org.talend.components.jdbc.runtime.JDBCSourceOrSink) TJDBCConnectionProperties(org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionProperties) ValidationResult(org.talend.daikon.properties.ValidationResult) TJDBCConnectionDefinition(org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionDefinition) Test(org.junit.Test)

Example 7 with TJDBCConnectionDefinition

use of org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionDefinition in project components by Talend.

the class JDBCConnectionTestIT method testNotAutoCommit.

@Test
public void testNotAutoCommit() {
    TJDBCConnectionDefinition definition = new TJDBCConnectionDefinition();
    TJDBCConnectionProperties properties = DBTestUtils.createCommonJDBCConnectionProperties(allSetting, definition);
    properties.useAutoCommit.setValue(true);
    properties.autocommit.setValue(false);
    JDBCSourceOrSink sourceOrSink = new JDBCSourceOrSink();
    sourceOrSink.initialize(null, properties);
    ValidationResult result = sourceOrSink.validate(null);
    assertTrue(result.getStatus() == ValidationResult.Result.OK);
    try (Connection conn = sourceOrSink.getConnection(null)) {
        assertTrue(!conn.getAutoCommit());
        assertTrue(!conn.isClosed());
    } catch (ClassNotFoundException | 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) Connection(java.sql.Connection) ValidationResult(org.talend.daikon.properties.ValidationResult) TJDBCConnectionDefinition(org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionDefinition) Test(org.junit.Test)

Example 8 with TJDBCConnectionDefinition

use of org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionDefinition in project components by Talend.

the class JDBCConnectionTestIT method testConnectionWithEmptyDriver.

@Test
public void testConnectionWithEmptyDriver() {
    TJDBCConnectionDefinition definition = new TJDBCConnectionDefinition();
    TJDBCConnectionProperties properties = (TJDBCConnectionProperties) definition.createRuntimeProperties();
    properties.connection.jdbcUrl.setValue(allSetting.getJdbcUrl());
    properties.connection.driverClass.setValue(null);
    properties.connection.userPassword.userId.setValue(allSetting.getUsername());
    properties.connection.userPassword.password.setValue(allSetting.getPassword());
    JDBCSourceOrSink sourceOrSink = new JDBCSourceOrSink();
    sourceOrSink.initialize(null, properties);
    ValidationResult result = sourceOrSink.validate(null);
    assertTrue(result.getStatus() == ValidationResult.Result.ERROR);
    assertTrue(result.getMessage() != null && result.getMessage().contains("Driver Class"));
}
Also used : JDBCSourceOrSink(org.talend.components.jdbc.runtime.JDBCSourceOrSink) TJDBCConnectionProperties(org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionProperties) ValidationResult(org.talend.daikon.properties.ValidationResult) TJDBCConnectionDefinition(org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionDefinition) Test(org.junit.Test)

Example 9 with TJDBCConnectionDefinition

use of org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionDefinition in project components by Talend.

the class JDBCConnectionTestIT method testConnectionWithWrongURL.

@Test
public void testConnectionWithWrongURL() {
    TJDBCConnectionDefinition definition = new TJDBCConnectionDefinition();
    TJDBCConnectionProperties properties = (TJDBCConnectionProperties) definition.createRuntimeProperties();
    properties.connection.driverClass.setValue(allSetting.getDriverClass());
    properties.connection.jdbcUrl.setValue("wrongUrl");
    properties.connection.userPassword.userId.setValue(allSetting.getUsername());
    properties.connection.userPassword.password.setValue(allSetting.getPassword());
    JDBCSourceOrSink sourceOrSink = new JDBCSourceOrSink();
    sourceOrSink.initialize(null, properties);
    ValidationResult result = sourceOrSink.validate(null);
    assertTrue(result.getStatus() == ValidationResult.Result.ERROR);
    assertTrue(result.getMessage() != null && !result.getMessage().isEmpty());
}
Also used : JDBCSourceOrSink(org.talend.components.jdbc.runtime.JDBCSourceOrSink) TJDBCConnectionProperties(org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionProperties) ValidationResult(org.talend.daikon.properties.ValidationResult) TJDBCConnectionDefinition(org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionDefinition) Test(org.junit.Test)

Example 10 with TJDBCConnectionDefinition

use of org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionDefinition in project components by Talend.

the class JDBCConnectionTestIT method testAutoCommit.

@Test
public void testAutoCommit() {
    TJDBCConnectionDefinition definition = new TJDBCConnectionDefinition();
    TJDBCConnectionProperties properties = DBTestUtils.createCommonJDBCConnectionProperties(allSetting, definition);
    properties.useAutoCommit.setValue(true);
    properties.autocommit.setValue(true);
    JDBCSourceOrSink sourceOrSink = new JDBCSourceOrSink();
    sourceOrSink.initialize(null, properties);
    ValidationResult result = sourceOrSink.validate(null);
    assertTrue(result.getStatus() == ValidationResult.Result.OK);
    try (Connection conn = sourceOrSink.getConnection(null)) {
        assertTrue(conn.getAutoCommit());
        assertTrue(!conn.isClosed());
    } catch (ClassNotFoundException | 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) Connection(java.sql.Connection) ValidationResult(org.talend.daikon.properties.ValidationResult) TJDBCConnectionDefinition(org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionDefinition) Test(org.junit.Test)

Aggregations

TJDBCConnectionDefinition (org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionDefinition)14 TJDBCConnectionProperties (org.talend.components.jdbc.tjdbcconnection.TJDBCConnectionProperties)14 Test (org.junit.Test)13 JDBCSourceOrSink (org.talend.components.jdbc.runtime.JDBCSourceOrSink)12 ValidationResult (org.talend.daikon.properties.ValidationResult)12 Connection (java.sql.Connection)7 SQLException (java.sql.SQLException)4 ResultSet (java.sql.ResultSet)2 Statement (java.sql.Statement)2 IndexedRecord (org.apache.avro.generic.IndexedRecord)2 WriteOperation (org.talend.components.api.component.runtime.WriteOperation)2 JDBCCommitSourceOrSink (org.talend.components.jdbc.runtime.JDBCCommitSourceOrSink)2 JDBCRollbackSourceOrSink (org.talend.components.jdbc.runtime.JDBCRollbackSourceOrSink)2 JDBCSink (org.talend.components.jdbc.runtime.JDBCSink)2 JDBCOutputInsertWriter (org.talend.components.jdbc.runtime.writer.JDBCOutputInsertWriter)2 TJDBCCommitDefinition (org.talend.components.jdbc.tjdbccommit.TJDBCCommitDefinition)2 TJDBCCommitProperties (org.talend.components.jdbc.tjdbccommit.TJDBCCommitProperties)2 TJDBCOutputDefinition (org.talend.components.jdbc.tjdbcoutput.TJDBCOutputDefinition)2 TJDBCOutputProperties (org.talend.components.jdbc.tjdbcoutput.TJDBCOutputProperties)2 TJDBCRollbackDefinition (org.talend.components.jdbc.tjdbcrollback.TJDBCRollbackDefinition)2