Search in sources :

Example 36 with TdExpression

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
}
Also used : TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) ReturnCode(org.talend.utils.sugars.ReturnCode) TdExpression(org.talend.cwm.relational.TdExpression) IndicatorDefinitionWriter(org.talend.dq.writer.impl.IndicatorDefinitionWriter) Property(org.talend.core.model.properties.Property) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) ElementWriterFactory(org.talend.dq.writer.impl.ElementWriterFactory) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 37 with TdExpression

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));
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) Test(org.junit.Test)

Example 38 with TdExpression

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));
}
Also used : UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) TdExpression(org.talend.cwm.relational.TdExpression) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) Test(org.junit.Test)

Example 39 with TdExpression

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());
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) Test(org.junit.Test)

Example 40 with TdExpression

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);
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) TdColumn(org.talend.cwm.relational.TdColumn) TdExpression(org.talend.cwm.relational.TdExpression) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) RegexpMatchingIndicator(org.talend.dataquality.indicators.RegexpMatchingIndicator) Domain(org.talend.dataquality.domain.Domain) Test(org.junit.Test)

Aggregations

TdExpression (org.talend.cwm.relational.TdExpression)121 Test (org.junit.Test)51 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)30 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)29 ArrayList (java.util.ArrayList)19 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)19 Pattern (org.talend.dataquality.domain.pattern.Pattern)16 TdColumn (org.talend.cwm.relational.TdColumn)12 Expression (orgomg.cwm.objectmodel.core.Expression)12 BasicEList (org.eclipse.emf.common.util.BasicEList)11 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)11 Domain (org.talend.dataquality.domain.Domain)10 TdTable (org.talend.cwm.relational.TdTable)9 ProductVersion (org.talend.utils.ProductVersion)9 Analysis (org.talend.dataquality.analysis.Analysis)8 PatternComponent (org.talend.dataquality.domain.pattern.PatternComponent)8 ChartDataEntity (org.talend.dq.indicators.preview.table.ChartDataEntity)8 File (java.io.File)7 IFile (org.eclipse.core.resources.IFile)6 IFolder (org.eclipse.core.resources.IFolder)6