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"));
}
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());
}
}
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"));
}
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());
}
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());
}
}
Aggregations