use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class FileSystemImportWriterTest method testMergeSystemIndicator.
/**
* Test method for
* {@link org.talend.dataprofiler.core.ui.imex.model.FileSystemImportWriter#mergeSystemIndicator(org.talend.dataprofiler.core.ui.imex.model.ItemRecord, org.talend.dataquality.indicators.definition.IndicatorDefinition)}
* .
*/
@Test
public void testMergeSystemIndicator() {
ItemRecord mockItem = mock(ItemRecord.class);
TDQIndicatorDefinitionItem siItem = PropertiesFactory.eINSTANCE.createTDQIndicatorDefinitionItem();
Property siProp = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createProperty();
IndicatorDefinition SIdef = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
siItem.setIndicatorDefinition(SIdef);
siItem.setProperty(siProp);
IndicatorDefinition importedDef = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
// make mockItem has: one new template, one modified newer template, one modified older template.
// $NON-NLS-1$ //$NON-NLS-2$
TdExpression e0 = BooleanExpressionHelper.createTdExpression("new", "new body");
// $NON-NLS-1$
e0.setModificationDate("20130101");
// $NON-NLS-1$ //$NON-NLS-2$
TdExpression e1 = BooleanExpressionHelper.createTdExpression("tem_1", "modified newer body");
// $NON-NLS-1$
e1.setModificationDate("20130101");
// $NON-NLS-1$ //$NON-NLS-2$
TdExpression e2 = BooleanExpressionHelper.createTdExpression("tem_2", "modified older body");
// $NON-NLS-1$
e2.setModificationDate("20110101");
importedDef.getSqlGenericExpression().add(e0);
importedDef.getSqlGenericExpression().add(e1);
importedDef.getSqlGenericExpression().add(e2);
when(mockItem.getElement()).thenReturn(importedDef);
// $NON-NLS-1$ //$NON-NLS-2$
TdExpression e3 = BooleanExpressionHelper.createTdExpression("tem_1", "should be replaced");
// $NON-NLS-1$
e3.setModificationDate("20120101");
// $NON-NLS-1$ //$NON-NLS-2$
TdExpression e4 = BooleanExpressionHelper.createTdExpression("tem_2", "should keep this");
// $NON-NLS-1$
e4.setModificationDate("20120101");
SIdef.getSqlGenericExpression().add(e3);
SIdef.getSqlGenericExpression().add(e4);
ReturnCode rc = mock(ReturnCode.class);
when(rc.isOk()).thenReturn(true);
ElementWriterFactory ewFactory = mock(ElementWriterFactory.class);
IndicatorDefinitionWriter indWriter = mock(IndicatorDefinitionWriter.class);
when(indWriter.save(siItem, false)).thenReturn(rc);
// $NON-NLS-1$
stub(method(ElementWriterFactory.class, "getInstance")).toReturn(ewFactory);
when(ewFactory.createIndicatorDefinitionWriter()).thenReturn(indWriter);
// before merge
Assert.assertEquals(SIdef.getSqlGenericExpression().size(), 2);
writer.mergeSystemIndicator(mockItem, siItem);
// after merge
Assert.assertEquals(SIdef.getSqlGenericExpression().size(), 3);
for (TdExpression ex : SIdef.getSqlGenericExpression()) {
if (ex.getLanguage().equals("new")) {
// $NON-NLS-1$
// $NON-NLS-1$
Assert.assertEquals("new body", ex.getBody());
} else if (ex.getLanguage().equals("tem_1")) {
// $NON-NLS-1$
// $NON-NLS-1$
Assert.assertEquals("modified newer body", ex.getBody());
} else if (ex.getLanguage().equals("tem_2")) {
// $NON-NLS-1$
// $NON-NLS-1$
Assert.assertEquals("should keep this", ex.getBody());
}
}
// other type?not SI
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class UDIUtilsTest method testIsCurrentLanguageAndVersionIsNull.
/**
* Test version is null or empty
*/
@Test
public void testIsCurrentLanguageAndVersionIsNull() {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
TdExpression tdExpression = UDIUtils.createNewTdExpression("MySQL", null, "select * from test");
// $NON-NLS-1$ //$NON-NLS-2$
assertTrue(UDIUtils.isCurrentLanguageAndVersion(tdExpression, "MySQL", " "));
// $NON-NLS-1$ //$NON-NLS-2$
assertTrue(UDIUtils.isCurrentLanguageAndVersion(tdExpression, "MySQL", null));
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
tdExpression = UDIUtils.createNewTdExpression("MySQL", "", "select * from test");
// $NON-NLS-1$ //$NON-NLS-2$
assertTrue(UDIUtils.isCurrentLanguageAndVersion(tdExpression, "MySQL", ""));
// $NON-NLS-1$
assertTrue(UDIUtils.isCurrentLanguageAndVersion(tdExpression, "MySQL", null));
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class UDIUtilsTest method testCheckExistInList.
/**
* Test method for {@link
* org.talend.dataprofiler.core.ui.utils.UDIUtils#checkExistInList(EList<org.talend.cwm.relational.TdExpression>,
* java.lang.String, java.lang.String)} .
*/
@Test
public void testCheckExistInList() {
// create user define 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);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
TdExpression tdExpression = UDIUtils.createNewTdExpression("MySQL", "5.0.2", "select * from test");
indicatorDefinition.getViewRowsExpression().add(tdExpression);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
TdExpression tdExpression_2 = UDIUtils.createNewTdExpression("Oracle", "5.0.2", "select * from test");
indicatorDefinition.getViewRowsExpression().add(tdExpression_2);
// $NON-NLS-1$ //$NON-NLS-2$
assertTrue(UDIUtils.checkExistInList(indicatorDefinition.getViewRowsExpression(), "Oracle", "5.0.2"));
// $NON-NLS-1$ //$NON-NLS-2$
assertFalse(UDIUtils.checkExistInList(indicatorDefinition.getViewRowsExpression(), "MySQL", "5.1.2"));
// $NON-NLS-1$
assertFalse(UDIUtils.checkExistInList(indicatorDefinition.getViewRowsExpression(), "Oracle", null));
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class UDIUtilsTest method testCreateNewTdExpression.
/**
* Test method for
* {@link org.talend.dataprofiler.core.ui.utils.UDIUtils#createNewTdExpression(java.lang.String, java.lang.String, java.lang.String)}
* .
*/
@Test
public void testCreateNewTdExpression() {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
TdExpression tdExpression = UDIUtils.createNewTdExpression("MySQL", "5.0.2", "select * from test");
assertNotNull(tdExpression);
// $NON-NLS-1$
assertEquals("5.0.2", tdExpression.getVersion());
// $NON-NLS-1$
assertEquals("MySQL", tdExpression.getLanguage());
// $NON-NLS-1$
assertEquals("select * from test", tdExpression.getBody());
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class RegexpMatchingIndicatorImplTest method testGetRegexFail1NotJavaRegex.
/**
* Test method for {@link org.talend.dataquality.indicators.impl.RegexpMatchingIndicatorImpl#getJavaRegex()}.
*/
@Test
public void testGetRegexFail1NotJavaRegex() {
// RegexpMatchingIndicator
RegexpMatchingIndicator createRegexpMatchingIndicator = IndicatorsFactory.eINSTANCE.createRegexpMatchingIndicator();
// ~RegexpMatchingIndicator
// IndicatorParameters
IndicatorParameters createIndicatorParameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
// ~IndicatorParameters
// Domain
Domain createDomain = DomainFactory.eINSTANCE.createDomain();
EList<Pattern> patterns = createDomain.getPatterns();
// ~Domain
// Pattern
Pattern createJavaPattern = PatternFactory.eINSTANCE.createPattern();
Pattern createSQLPattern = PatternFactory.eINSTANCE.createPattern();
Pattern createMSSQLPattern = PatternFactory.eINSTANCE.createPattern();
patterns.add(createJavaPattern);
patterns.add(createSQLPattern);
patterns.add(createMSSQLPattern);
// ~Pattern
// init java Pattern data
RegularExpression createJavaRegularExpression = PatternFactory.eINSTANCE.createRegularExpression();
TdExpression createJavaTdExpression = RelationalFactory.eINSTANCE.createTdExpression();
createJavaTdExpression.setBody(JavaRegex);
createJavaTdExpression.setLanguage("Microsoft SQL Server");
createJavaRegularExpression.setExpression(createJavaTdExpression);
createJavaRegularExpression.setExpressionType(ExpressionType.REGEXP.getLiteral());
EList<PatternComponent> components = createJavaPattern.getComponents();
components.add(createJavaRegularExpression);
// ~init java Pattern data
createIndicatorParameters.setDataValidDomain(createDomain);
createRegexpMatchingIndicator.setParameters(createIndicatorParameters);
TdColumn column = RelationalFactory.eINSTANCE.createTdColumn();
MetadataTable mdColumn = RelationalFactory.eINSTANCE.createTdTable();
column.setTable(mdColumn);
createRegexpMatchingIndicator.setAnalyzedElement(column);
// call getRegex()
String regexResult = createRegexpMatchingIndicator.getRegex();
// ~call getRegex()
Assert.assertTrue(regexResult == null);
}
Aggregations