Search in sources :

Example 16 with Pattern

use of org.talend.dataquality.domain.pattern.Pattern in project tdq-studio-se by Talend.

the class DbmsLanguageTest method testGetRegexpGetNullWhenRegexStringIsNull.

/**
 * Test method for
 * {@link org.talend.dq.dbms.DbmsLanguage#getRegexp(org.talend.dataquality.domain.pattern.Pattern, boolean)}.
 */
@Test
public void testGetRegexpGetNullWhenRegexStringIsNull() {
    // Pattern
    Pattern createPattern = PatternFactory.eINSTANCE.createPattern();
    // ~Pattern
    // init sql Expression data
    RegularExpression createSqlRegularExpression = PatternFactory.eINSTANCE.createRegularExpression();
    EList<PatternComponent> components = createPattern.getComponents();
    components.add(createSqlRegularExpression);
    // ~init sql Expression data
    try {
        DbmsLanguage dbms = DbmsLanguageFactory.createDbmsLanguage(SupportDBUrlType.MSSQLDEFAULTURL);
        Assert.assertTrue(null == dbms.getRegexp(createPattern));
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) Test(org.junit.Test)

Example 17 with Pattern

use of org.talend.dataquality.domain.pattern.Pattern in project tdq-studio-se by Talend.

the class DbmsLanguageTest method testGetRegexpGetJavaFromContainDefault.

/**
 * Test method for
 * {@link org.talend.dq.dbms.DbmsLanguage#getRegexp(org.talend.dataquality.domain.pattern.Pattern, boolean)}.
 */
@Test
public void testGetRegexpGetJavaFromContainDefault() {
    // 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 mssql Expression data
    RegularExpression createMssqlRegularExpression = PatternFactory.eINSTANCE.createRegularExpression();
    TdExpression createMssqlTdExpression = RelationalFactory.eINSTANCE.createTdExpression();
    createMssqlTdExpression.setBody(MssqlRegex);
    createMssqlTdExpression.setLanguage(SupportDBUrlType.MSSQLDEFAULTURL.getLanguage());
    createMssqlRegularExpression.setExpression(createMssqlTdExpression);
    createMssqlRegularExpression.setExpressionType(ExpressionType.REGEXP.getLiteral());
    components = createPattern.getComponents();
    components.add(createMssqlRegularExpression);
    // ~init mssql 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.JAVADEFAULTURL);
        Assert.assertTrue(JavaRegex.equalsIgnoreCase(dbms.getRegexp(createPattern).getBody()));
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) TdExpression(org.talend.cwm.relational.TdExpression) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) Test(org.junit.Test)

Example 18 with Pattern

use of org.talend.dataquality.domain.pattern.Pattern in project tdq-studio-se by Talend.

the class UnitTestBuildHelper method createRealPattern.

public static Pattern createRealPattern() {
    Pattern pattern = PatternFactory.eINSTANCE.createPattern();
    // $NON-NLS-1$
    pattern.setName("My Pattern");
    RegularExpression regularExpr = PatternFactory.eINSTANCE.createRegularExpression();
    TdExpression expression = createRealExpression();
    regularExpr.setExpression(expression);
    pattern.getComponents().add(regularExpr);
    return pattern;
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) TdExpression(org.talend.cwm.relational.TdExpression)

Example 19 with Pattern

use of org.talend.dataquality.domain.pattern.Pattern in project tdq-studio-se by Talend.

the class FileSystemImportWriterTest method testMergePattern.

/**
 * Test method for
 * {@link org.talend.dataprofiler.core.ui.imex.model.FileSystemImportWriter#mergePattern(org.talend.dataprofiler.core.ui.imex.model.ItemRecord, org.talend.dataquality.domain.pattern.Pattern)}
 * .
 *
 * @throws MalformedURLException
 */
@Test
public void testMergePattern() throws MalformedURLException {
    // import object
    ItemRecord importItem = mock(ItemRecord.class);
    Pattern importPattern = mock(Pattern.class);
    when(importItem.getElement()).thenReturn(importPattern);
    // old object
    TDQPatternItem oldPatternItem = mock(TDQPatternItem.class);
    Pattern oldPattern = mock(Pattern.class);
    when(oldPatternItem.getPattern()).thenReturn(oldPattern);
    // for imported pattern's expression
    InternalEObject eo = mock(InternalEObject.class);
    EList<PatternComponent> importComponents = new EObjectContainmentEList<PatternComponent>(PatternComponent.class, eo, PatternPackage.PATTERN__COMPONENTS);
    RegularExpression re = PatternFactory.eINSTANCE.createRegularExpression();
    TdExpression td = RelationalFactory.eINSTANCE.createTdExpression();
    // $NON-NLS-1$
    td.setBody("sql body");
    // $NON-NLS-1$
    td.setLanguage("SQL");
    // $NON-NLS-1$
    td.setModificationDate("20130101");
    re.setExpression(td);
    importComponents.add(re);
    RegularExpression re3 = PatternFactory.eINSTANCE.createRegularExpression();
    TdExpression td3 = RelationalFactory.eINSTANCE.createTdExpression();
    // $NON-NLS-1$
    td3.setBody("imported body");
    // $NON-NLS-1$
    td3.setLanguage("MYSQL");
    // $NON-NLS-1$
    td3.setModificationDate("20130101");
    re3.setExpression(td3);
    importComponents.add(re3);
    RegularExpression re4 = PatternFactory.eINSTANCE.createRegularExpression();
    TdExpression td4 = RelationalFactory.eINSTANCE.createTdExpression();
    // $NON-NLS-1$
    td4.setBody("imported 4 body");
    // $NON-NLS-1$
    td4.setLanguage("Default");
    td4.setModificationDate(null);
    re4.setExpression(td4);
    importComponents.add(re4);
    when(importPattern.getComponents()).thenReturn(importComponents);
    // for imported pattern's supplierDependencies
    Analysis analysis = mock(Analysis.class);
    Dependency dependency = mock(Dependency.class);
    when(dependency.getKind()).thenReturn(DependenciesHandler.USAGE);
    EList<ModelElement> analysisList = new BasicEList<ModelElement>();
    analysisList.add(analysis);
    when(dependency.getClient()).thenReturn(analysisList);
    when(analysis.eIsProxy()).thenReturn(false);
    // $NON-NLS-1$
    File file = new File("C://Users//msjian//Desktop//myusetest//AA//TDQ_Data Profiling//Analyses//k_0.1.ana");
    org.eclipse.emf.common.util.URI uri = URI.createFileURI(file.toURL().getPath().substring(1));
    Resource resource = mock(Resource.class);
    when(analysis.eResource()).thenReturn(resource);
    when(resource.getURI()).thenReturn(uri);
    PowerMockito.mockStatic(ResourceManager.class);
    IProject pro = mock(IProject.class);
    when(ResourceManager.getRootProject()).thenReturn(pro);
    // $NON-NLS-1$
    when(pro.getLocation()).thenReturn(new Path("D:\\worspace\\workspace_TDQEE_5.3\\A"));
    EList<ModelElement> patternlist = mock(EObjectContainmentEList.class);
    patternlist.add(importPattern);
    when(dependency.getSupplier()).thenReturn(patternlist);
    EList<Dependency> supplierDependencies_old = new BasicEList<Dependency>();
    when(oldPattern.getSupplierDependency()).thenReturn(supplierDependencies_old);
    Assert.assertEquals(0, oldPattern.getSupplierDependency().size());
    EList<Dependency> supplierDependencies_import = new BasicEList<Dependency>();
    supplierDependencies_import.add(dependency);
    when(importPattern.getSupplierDependency()).thenReturn(supplierDependencies_import);
    Assert.assertEquals(1, importPattern.getSupplierDependency().size());
    PowerMockito.mockStatic(DependenciesHandler.class);
    DependenciesHandler instance = mock(DependenciesHandler.class);
    when(DependenciesHandler.getInstance()).thenReturn(instance);
    TypedReturnCode<Dependency> rc = new TypedReturnCode<Dependency>();
    rc.setObject(dependency);
    when(instance.setUsageDependencyOn(analysis, oldPattern)).thenReturn(rc);
    when(oldPattern.getSupplierDependency()).thenReturn(supplierDependencies_import);
    // for system pattern's expression
    EList<PatternComponent> components = new EObjectContainmentEList<PatternComponent>(PatternComponent.class, eo, PatternPackage.PATTERN__COMPONENTS);
    RegularExpression re2 = PatternFactory.eINSTANCE.createRegularExpression();
    TdExpression td2 = RelationalFactory.eINSTANCE.createTdExpression();
    // $NON-NLS-1$
    td2.setBody("system 2 body");
    // $NON-NLS-1$
    td2.setLanguage("MYSQL");
    // $NON-NLS-1$
    td2.setModificationDate("20120101");
    re2.setExpression(td2);
    components.add(re2);
    // for re5: should be replace by re4
    RegularExpression re5 = PatternFactory.eINSTANCE.createRegularExpression();
    TdExpression td5 = RelationalFactory.eINSTANCE.createTdExpression();
    // $NON-NLS-1$
    td5.setBody("system 5 body");
    // $NON-NLS-1$
    td5.setLanguage("Default");
    td5.setModificationDate(null);
    re5.setExpression(td5);
    components.add(re5);
    when(oldPattern.getComponents()).thenReturn(components);
    ElementWriterFactory ewFactory = mock(ElementWriterFactory.class);
    PatternWriter pw = mock(PatternWriter.class);
    when(pw.save(oldPatternItem, true)).thenReturn(null);
    // $NON-NLS-1$
    stub(method(ElementWriterFactory.class, "getInstance")).toReturn(ewFactory);
    when(ewFactory.createPatternWriter()).thenReturn(pw);
    writer.mergePattern(importItem, oldPatternItem);
    for (PatternComponent component : components) {
        TdExpression ex = ((RegularExpression) component).getExpression();
        if (ex.getLanguage().equals("SQL")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            Assert.assertEquals("sql body", ex.getBody());
        } else if (ex.getLanguage().equals("MYSQL")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            Assert.assertEquals("imported body", ex.getBody());
        } else if (ex.getLanguage().equals("Default")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            Assert.assertEquals("imported 4 body", ex.getBody());
        }
    }
    Assert.assertNotNull(oldPattern.getSupplierDependency());
    Assert.assertEquals(1, oldPattern.getSupplierDependency().size());
}
Also used : URI(org.eclipse.emf.common.util.URI) PatternWriter(org.talend.dq.writer.impl.PatternWriter) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) ElementWriterFactory(org.talend.dq.writer.impl.ElementWriterFactory) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) EObjectContainmentEList(org.eclipse.emf.ecore.util.EObjectContainmentEList) DependenciesHandler(org.talend.cwm.dependencies.DependenciesHandler) Path(org.eclipse.core.runtime.Path) Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) TdExpression(org.talend.cwm.relational.TdExpression) BasicEList(org.eclipse.emf.common.util.BasicEList) Resource(org.eclipse.emf.ecore.resource.Resource) Dependency(orgomg.cwm.objectmodel.core.Dependency) IProject(org.eclipse.core.resources.IProject) Analysis(org.talend.dataquality.analysis.Analysis) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) File(java.io.File) InternalEObject(org.eclipse.emf.ecore.InternalEObject) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 20 with Pattern

use of org.talend.dataquality.domain.pattern.Pattern in project tdq-studio-se by Talend.

the class IndicatorHelperTest method testGetPatternName.

/**
 * Test method for get pattern name based on indicator.
 */
@Test
public void testGetPatternName() {
    Indicator indicator = IndicatorsFactory.eINSTANCE.createRegexpMatchingIndicator();
    IndicatorParameters parameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
    Domain validData = DomainFactory.eINSTANCE.createDomain();
    Pattern pattern = PatternFactory.eINSTANCE.createPattern();
    // $NON-NLS-1$
    String pn = "Blank Text";
    pattern.setName(pn);
    validData.getPatterns().add(pattern);
    parameters.setDataValidDomain(validData);
    indicator.setParameters(parameters);
    String patternName = IndicatorHelper.getPatternName(indicator);
    assert (patternName.equals(pn));
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) Domain(org.talend.dataquality.domain.Domain) NullCountIndicator(org.talend.dataquality.indicators.NullCountIndicator) Indicator(org.talend.dataquality.indicators.Indicator) RowCountIndicator(org.talend.dataquality.indicators.RowCountIndicator) Test(org.junit.Test)

Aggregations

Pattern (org.talend.dataquality.domain.pattern.Pattern)75 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)27 Test (org.junit.Test)19 TdExpression (org.talend.cwm.relational.TdExpression)18 Domain (org.talend.dataquality.domain.Domain)16 Analysis (org.talend.dataquality.analysis.Analysis)15 PatternComponent (org.talend.dataquality.domain.pattern.PatternComponent)15 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)14 ArrayList (java.util.ArrayList)13 PatternMatchingIndicator (org.talend.dataquality.indicators.PatternMatchingIndicator)13 IFile (org.eclipse.core.resources.IFile)11 TDQPatternItem (org.talend.dataquality.properties.TDQPatternItem)10 Expression (orgomg.cwm.objectmodel.core.Expression)10 IFolder (org.eclipse.core.resources.IFolder)9 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)9 Indicator (org.talend.dataquality.indicators.Indicator)9 Item (org.talend.core.model.properties.Item)7 TdColumn (org.talend.cwm.relational.TdColumn)7 RegexpMatchingIndicator (org.talend.dataquality.indicators.RegexpMatchingIndicator)6 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)6