use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class ConnectionUtilsTest method testCheckGeneralJdbcJarFilePathDriverClassNameCase2.
/**
* Test method for
* {@link org.talend.cwm.db.connection.ConnectionUtils#checkGeneralJdbcJarFilePathDriverClassName(org.talend.core.model.metadata.builder.connection.DatabaseConnection)}
* . case 2 driverClass is null or empty
*/
@Test
public void testCheckGeneralJdbcJarFilePathDriverClassNameCase2() {
String driverClass = StringUtils.EMPTY;
// $NON-NLS-1$
String driverName = "mysql-connector-java-5.1.12-bin.jar";
CopyTheJarFile();
DatabaseConnection createDatabaseConnection = ConnectionFactoryImpl.eINSTANCE.createDatabaseConnection();
createDatabaseConnection.setDriverClass(driverClass);
createDatabaseConnection.setDriverJarPath(driverName);
// driver class is empty case
ReturnCode rc = ConnectionUtils.checkJdbcJarFilePathDriverClassName(createDatabaseConnection);
// $NON-NLS-1$
Assert.assertFalse("The driver of conection is empty so that should not be found", rc.isOk());
// $NON-NLS-1$
Assert.assertEquals(Messages.getString("ConnectionUtils.DriverClassEmpty"), rc.getMessage());
// driver class is Null case
driverClass = null;
createDatabaseConnection.setDriverClass(driverClass);
rc = ConnectionUtils.checkJdbcJarFilePathDriverClassName(createDatabaseConnection);
// $NON-NLS-1$
Assert.assertFalse("The driver of conection is Null so that should not be found", rc.isOk());
// $NON-NLS-1$
Assert.assertEquals(Messages.getString("ConnectionUtils.DriverClassEmpty"), rc.getMessage());
}
use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class ConnectionUtilsTest method testCheckGeneralJdbcJarFilePathDriverClassNameCase4.
/**
* Test method for
* {@link org.talend.cwm.db.connection.ConnectionUtils#checkGeneralJdbcJarFilePathDriverClassName(org.talend.core.model.metadata.builder.connection.DatabaseConnection)}
* . case 4 The jar can not be found case
*/
@Test
public void testCheckGeneralJdbcJarFilePathDriverClassNameCase4() {
// $NON-NLS-1$
String driverClass = "om.mysql.jdbc.Driver";
// $NON-NLS-1$
String driverName = "mysql-connector-java-5.1.12-bin111111.jar";
CopyTheJarFile();
DatabaseConnection createDatabaseConnection = ConnectionFactoryImpl.eINSTANCE.createDatabaseConnection();
createDatabaseConnection.setDriverClass(driverClass);
createDatabaseConnection.setDriverJarPath(driverName);
ReturnCode rc = ConnectionUtils.checkJdbcJarFilePathDriverClassName(createDatabaseConnection);
// $NON-NLS-1$
Assert.assertFalse("The driver is not exist so that should not be found", rc.isOk());
// $NON-NLS-1$
Assert.assertEquals(Messages.getString("ConnectionUtils.JarFileCanNotBeFound"), rc.getMessage());
}
use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class ConnectionUtilsTest method testCheckGeneralJdbcJarFilePathDriverClassNameCase3.
/**
* Test method for
* {@link org.talend.cwm.db.connection.ConnectionUtils#checkGeneralJdbcJarFilePathDriverClassName(org.talend.core.model.metadata.builder.connection.DatabaseConnection)}
* . case 3 driverName is null or empty
*/
@Test
public void testCheckGeneralJdbcJarFilePathDriverClassNameCase3() {
// $NON-NLS-1$
String driverClass = "om.mysql.jdbc.Driver";
String driverName = StringUtils.EMPTY;
CopyTheJarFile();
DatabaseConnection createDatabaseConnection = ConnectionFactoryImpl.eINSTANCE.createDatabaseConnection();
createDatabaseConnection.setDriverClass(driverClass);
createDatabaseConnection.setDriverJarPath(driverName);
// driver name is empty case
ReturnCode rc = ConnectionUtils.checkJdbcJarFilePathDriverClassName(createDatabaseConnection);
// $NON-NLS-1$
Assert.assertFalse("The class of driver is empty so that should not be found", rc.isOk());
// $NON-NLS-1$
Assert.assertEquals(Messages.getString("ConnectionUtils.DriverJarFileEmpty"), rc.getMessage());
// driver name is Null case
driverClass = null;
createDatabaseConnection.setDriverJarPath(driverName);
rc = ConnectionUtils.checkJdbcJarFilePathDriverClassName(createDatabaseConnection);
// $NON-NLS-1$
Assert.assertFalse("The class of driver is Null so that should not be found", rc.isOk());
// $NON-NLS-1$
Assert.assertEquals(Messages.getString("ConnectionUtils.DriverJarFileEmpty"), rc.getMessage());
}
use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class UDIHelper method validate.
public static ReturnCode validate(IndicatorDefinition indicatorDefinition) {
ReturnCode rc = new ReturnCode(true);
List<String> errorList = new ArrayList<String>();
// MOD mzhao feature 11128, In case of Java UDI, No expression is allowed to be saved.
if (!containsJavaUDI(indicatorDefinition)) {
if (0 == indicatorDefinition.getSqlGenericExpression().size()) {
// $NON-NLS-1$
errorList.add(Messages.getString("UDIHelper.validateNoExpression"));
rc.setOk(false);
}
}
if (PluginConstant.EMPTY_STRING.equals(indicatorDefinition.getName())) {
// $NON-NLS-1$
errorList.add(Messages.getString("UDIHelper.validateNoName"));
rc.setOk(false);
}
for (Expression exp : indicatorDefinition.getSqlGenericExpression()) {
if (null == exp.getBody() || exp.getBody().length() + 1 < MIN_EXPRESSION_LENGTH) {
// $NON-NLS-1$
errorList.add(Messages.getString("UDIHelper.validateTooShort"));
rc.setOk(false);
}
}
// $NON-NLS-1$
String message = Messages.getString("UDIHelper.validateCannotSave");
// $NON-NLS-1$
String wrap = System.getProperty("line.separator");
for (int i = 0; i < errorList.size(); i++) {
message += wrap + (i + 1) + org.talend.dataquality.PluginConstant.DOT_STRING + errorList.get(i);
}
rc.setMessage(message);
return rc;
}
use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.
the class AbstractSchemaEvaluator method reloadConnectionAfterException.
/**
* DOC scorreia Comment method "reloadConnection".
*
* @param catalog
*/
protected void reloadConnectionAfterException(String catalog) {
nbExceptions++;
if (nbExceptions < MAX_EXCEPTION) {
// not yet
return;
}
ReturnCode connClosed = super.closeConnection();
if (!connClosed.isOk()) {
// $NON-NLS-1$
log.error(Messages.getString("AbstractSchemaEvaluator.ReloadProblem", connClosed.getMessage()));
}
Connection dp = this.getDataManager();
TypedReturnCode<java.sql.Connection> conn = JavaSqlFactory.createConnection(dp);
if (!conn.isOk()) {
log.error(conn.getMessage());
return;
}
// else ok
this.setConnection(conn.getObject());
this.selectCatalog(catalog);
// reset the number of exceptions
nbExceptions = 0;
}
Aggregations