use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class DbmsLanguageTest method testGetRegexpGetMssqlFromContainDefaultAndWithoutMssql.
/**
* Test method for
* {@link org.talend.dq.dbms.DbmsLanguage#getRegexp(org.talend.dataquality.domain.pattern.Pattern, boolean)}.
*/
@Test
public void testGetRegexpGetMssqlFromContainDefaultAndWithoutMssql() {
// Pattern
Pattern createPattern = PatternFactory.eINSTANCE.createPattern();
// ~Pattern
// init sql Expression data
RegularExpression createSqlRegularExpression = PatternFactory.eINSTANCE.createRegularExpression();
TdExpression createSqlTdExpression = RelationalFactory.eINSTANCE.createTdExpression();
createSqlTdExpression.setBody(SqlRegex);
createSqlTdExpression.setLanguage(ExecutionLanguage.SQL.getName());
createSqlRegularExpression.setExpression(createSqlTdExpression);
createSqlRegularExpression.setExpressionType(ExpressionType.REGEXP.getLiteral());
EList<PatternComponent> components = createPattern.getComponents();
components.add(createSqlRegularExpression);
// ~init sql Expression data
// init java Expression data
RegularExpression createJavaRegularExpression = PatternFactory.eINSTANCE.createRegularExpression();
TdExpression createJavaTdExpression = RelationalFactory.eINSTANCE.createTdExpression();
createJavaTdExpression.setBody(JavaRegex);
createJavaTdExpression.setLanguage(SupportDBUrlType.JAVADEFAULTURL.getLanguage());
createJavaRegularExpression.setExpression(createJavaTdExpression);
createJavaRegularExpression.setExpressionType(ExpressionType.REGEXP.getLiteral());
components = createPattern.getComponents();
components.add(createJavaRegularExpression);
try {
DbmsLanguage dbms = DbmsLanguageFactory.createDbmsLanguage(SupportDBUrlType.MSSQLDEFAULTURL);
Assert.assertTrue(SqlRegex.equalsIgnoreCase(dbms.getRegexp(createPattern).getBody()));
} catch (Exception e) {
fail(e.getMessage());
}
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class DbmsLanguageTest method testGetSqlExpressionDB2Case5.
/**
* Test method for
* {@link org.talend.dq.dbms.DbmsLanguage#getSqlExpression(IndicatorDefinition, String, EList, ProductVersion)} .
*/
@Test
public void testGetSqlExpressionDB2Case5() {
// $NON-NLS-1$
String sqlLang = "SQL";
// $NON-NLS-1$
String sqlBody = "SQL body";
// $NON-NLS-1$
String db2Lang = "DB2";
// $NON-NLS-1$
String db2Body = "DB2 body";
// $NON-NLS-1$
String db2NTLang = "DB2/NT";
// $NON-NLS-1$
String db2NTBody = "DB2/NT body";
IndicatorDefinition indicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
// $NON-NLS-1$
String language = "unknown";
EList<TdExpression> sqlGenericExpression = new BasicEList<TdExpression>();
TdExpression tdExpression1 = RelationalFactory.eINSTANCE.createTdExpression();
tdExpression1.setLanguage(sqlLang);
tdExpression1.setBody(sqlBody);
sqlGenericExpression.add(tdExpression1);
TdExpression tdExpression2 = RelationalFactory.eINSTANCE.createTdExpression();
tdExpression2.setLanguage(db2Lang);
tdExpression2.setBody(db2Body);
sqlGenericExpression.add(tdExpression2);
TdExpression tdExpression3 = RelationalFactory.eINSTANCE.createTdExpression();
tdExpression3.setLanguage(db2NTLang);
tdExpression3.setBody(db2NTBody);
sqlGenericExpression.add(tdExpression3);
ProductVersion dbVersion = new ProductVersion(1, 0);
TdExpression sqlExpression = DbmsLanguage.getSqlExpression(indicatorDefinition, language, sqlGenericExpression, dbVersion);
Assert.assertEquals(tdExpression1, sqlExpression);
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class DbmsLanguageTest method testGetSqlExpressionUserDefineCase2.
/**
* Test method for
* {@link org.talend.dq.dbms.DbmsLanguage#getSqlExpression(org.talend.dataquality.indicators.definition.IndicatorDefinition)}
* .
*/
@Test
public void testGetSqlExpressionUserDefineCase2() {
// test for can not get sql expression(means: both database type and default type don't exist)
// create indicator
UserDefIndicator userDefIndicator = IndicatorSqlFactory.eINSTANCE.createUserDefIndicator();
UDIndicatorDefinition indicatorDefinition = UserdefineFactory.eINSTANCE.createUDIndicatorDefinition();
// $NON-NLS-1$
indicatorDefinition.setName("user define");
userDefIndicator.setName(indicatorDefinition.getName());
userDefIndicator.setIndicatorDefinition(indicatorDefinition);
TdExpression newTdExp = // $NON-NLS-1$
BooleanExpressionHelper.createTdExpression(// $NON-NLS-1$
"Ingres", sql_1, null);
newTdExp.setModificationDate(DateUtils.getCurrentDate(DateUtils.PATTERN_5));
indicatorDefinition.getSqlGenericExpression().add(newTdExp);
DbmsLanguage dbms = getMysqlDbmsLanguage();
Expression sqlExpression = dbms.getSqlExpression(indicatorDefinition);
Assert.assertNull(sqlExpression);
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class DbmsLanguageTest method testGetSqlExpressionDB2Case3.
/**
* Test method for
* {@link org.talend.dq.dbms.DbmsLanguage#getSqlExpression(IndicatorDefinition, String, EList, ProductVersion)} .
*/
@Test
public void testGetSqlExpressionDB2Case3() {
// $NON-NLS-1$
String sqlLang = "SQL";
// $NON-NLS-1$
String sqlBody = "SQL body";
// $NON-NLS-1$
String db2Lang = "DB2";
// $NON-NLS-1$
String db2Body = "DB2 body";
// $NON-NLS-1$
String db2NTLang = "DB2/NT";
IndicatorDefinition indicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
String language = db2NTLang;
EList<TdExpression> sqlGenericExpression = new BasicEList<TdExpression>();
TdExpression tdExpression1 = RelationalFactory.eINSTANCE.createTdExpression();
tdExpression1.setLanguage(sqlLang);
tdExpression1.setBody(sqlBody);
sqlGenericExpression.add(tdExpression1);
TdExpression tdExpression2 = RelationalFactory.eINSTANCE.createTdExpression();
tdExpression2.setLanguage(db2Lang);
tdExpression2.setBody(db2Body);
sqlGenericExpression.add(tdExpression2);
ProductVersion dbVersion = new ProductVersion(1, 0);
TdExpression sqlExpression = DbmsLanguage.getSqlExpression(indicatorDefinition, language, sqlGenericExpression, dbVersion);
Assert.assertEquals(tdExpression2, sqlExpression);
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class DbmsLanguageTest method createExpression.
/**
* create a default expression for test
*
* @return
*/
private TdExpression createExpression(String language) {
TdExpression expression = RelationalFactory.eINSTANCE.createTdExpression();
expression.setBody(REGEXP);
expression.setLanguage(language);
return expression;
}
Aggregations