Search in sources :

Example 86 with Analysis

use of org.talend.dataquality.analysis.Analysis in project tdq-studio-se by Talend.

the class DependenciesHandlerTest method testSetUsageDependencyOnModelElementModelElementCase2.

/**
 * Test method for
 * {@link org.talend.cwm.dependencies.DependenciesHandler#setUsageDependencyOn(ModelElement, ModelElement)} . 、
 * case2 supplier side is lost
 */
@Test
public void testSetUsageDependencyOnModelElementModelElementCase2() {
    // analysis init
    TDQAnalysisItem analysisItem = PropertiesFactoryImpl.eINSTANCE.createTDQAnalysisItem();
    Analysis analysis = AnalysisFactory.eINSTANCE.createAnalysis();
    // $NON-NLS-1$
    analysis.setName("DependenciesHandlerTest.testSetUsageDependencyOnModelElementModelElementCase2Analysis");
    analysisItem.setAnalysis(analysis);
    Property propertyAna = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createProperty();
    propertyAna.setId(EcoreUtil.generateUUID());
    // $NON-NLS-1$
    propertyAna.setLabel("DependenciesHandlerTest.testSetUsageDependencyOnModelElementModelElementCase2Analysis");
    analysisItem.setProperty(propertyAna);
    ItemState itemState = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createItemState();
    itemState.setDeleted(false);
    analysisItem.setState(itemState);
    AnalysisResult analysisResult1 = AnalysisFactory.eINSTANCE.createAnalysisResult();
    analysis.setResults(analysisResult1);
    analysis.setContext(AnalysisFactory.eINSTANCE.createAnalysisContext());
    try {
        ProxyRepositoryFactory.getInstance().create(analysisItem, Path.EMPTY, false);
    } catch (PersistenceException e) {
        Assert.fail(e.getMessage());
    }
    // UDI init
    TDQIndicatorDefinitionItem createTDQIndicatorDefinitionItem = PropertiesFactoryImpl.eINSTANCE.createTDQIndicatorDefinitionItem();
    UserDefIndicator createUserDefIndicator = IndicatorSqlFactory.eINSTANCE.createUserDefIndicator();
    IndicatorDefinition createIndicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    // $NON-NLS-1$
    createIndicatorDefinition.setName("DependenciesHandlerTest.testSetUsageDependencyOnModelElementModelElementCase2UDI");
    createTDQIndicatorDefinitionItem.setIndicatorDefinition(createIndicatorDefinition);
    createUserDefIndicator.setIndicatorDefinition(createIndicatorDefinition);
    Property propertyUDI = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createProperty();
    propertyUDI.setId(EcoreUtil.generateUUID());
    // $NON-NLS-1$
    propertyUDI.setLabel("DependenciesHandlerTest.testSetUsageDependencyOnModelElementModelElementCase2UDI");
    createTDQIndicatorDefinitionItem.setProperty(propertyUDI);
    try {
        ProxyRepositoryFactory.getInstance().create(createTDQIndicatorDefinitionItem, new Path(EResourceConstant.USER_DEFINED_INDICATORS.getName()), false);
    } catch (PersistenceException e) {
        Assert.fail(e.getMessage());
    }
    // init UDI supplier Dependency
    analysisResult1.getIndicators().add(createUserDefIndicator);
    ElementWriterFactory.getInstance().createAnalysisWrite().save(analysisItem, true);
    if (!createIndicatorDefinition.getSupplierDependency().isEmpty()) {
        createIndicatorDefinition.getSupplierDependency().get(0).getClient().clear();
    }
    Analysis analysisFromFile = AnalysisFactory.eINSTANCE.createAnalysis();
    try {
        analysis.eResource().unload();
        IRepositoryViewObject lastVersion = ProxyRepositoryFactory.getInstance().getLastVersion(propertyAna.getId());
        analysisFromFile = ((TDQAnalysisItem) lastVersion.getProperty().getItem()).getAnalysis();
    } catch (PersistenceException e) {
        Assert.fail(e.getMessage());
    }
    // call the test method
    TypedReturnCode<Dependency> setUsageDependencyOn = DependenciesHandler.getInstance().setUsageDependencyOn(analysisFromFile, createIndicatorDefinition);
    // $NON-NLS-1$
    Assert.assertEquals("call setUsageDependencyOn method should return ok stauts", true, setUsageDependencyOn.isOk());
    Assert.assertEquals(analysisFromFile, setUsageDependencyOn.getObject().getClient().get(0));
    Assert.assertEquals(1, setUsageDependencyOn.getObject().getClient().size());
    Assert.assertEquals(createIndicatorDefinition, setUsageDependencyOn.getObject().getSupplier().get(0));
    Assert.assertEquals(1, setUsageDependencyOn.getObject().getSupplier().size());
}
Also used : Path(org.eclipse.core.runtime.Path) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) Dependency(orgomg.cwm.objectmodel.core.Dependency) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) Analysis(org.talend.dataquality.analysis.Analysis) ItemState(org.talend.core.model.properties.ItemState) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Property(org.talend.core.model.properties.Property) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem) Test(org.junit.Test)

Example 87 with Analysis

use of org.talend.dataquality.analysis.Analysis in project tdq-studio-se by Talend.

the class DependenciesHandlerTest method testSetUsageDependencyOnModelElementModelElementCase1.

/**
 * Test method for
 * {@link org.talend.cwm.dependencies.DependenciesHandler#setUsageDependencyOn(ModelElement, ModelElement)} . case1
 * noraml case the dependency has been set between clint and supplier
 */
@Test
public void testSetUsageDependencyOnModelElementModelElementCase1() {
    // analysis init
    TDQAnalysisItem analysisItem = PropertiesFactoryImpl.eINSTANCE.createTDQAnalysisItem();
    Analysis analysis = AnalysisFactory.eINSTANCE.createAnalysis();
    // $NON-NLS-1$
    analysis.setName("DependenciesHandlerTest.testSetUsageDependencyOnModelElementModelElementCase1Analysis");
    analysisItem.setAnalysis(analysis);
    Property propertyAna = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createProperty();
    propertyAna.setId(EcoreUtil.generateUUID());
    // $NON-NLS-1$
    propertyAna.setLabel("DependenciesHandlerTest.testSetUsageDependencyOnModelElementModelElementCase1Analysis");
    analysisItem.setProperty(propertyAna);
    ItemState itemState = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createItemState();
    itemState.setDeleted(false);
    analysisItem.setState(itemState);
    AnalysisResult analysisResult1 = AnalysisFactory.eINSTANCE.createAnalysisResult();
    analysis.setResults(analysisResult1);
    analysis.setContext(AnalysisFactory.eINSTANCE.createAnalysisContext());
    try {
        ProxyRepositoryFactory.getInstance().create(analysisItem, Path.EMPTY, false);
    } catch (PersistenceException e) {
        Assert.fail(e.getMessage());
    }
    // UDI init
    TDQIndicatorDefinitionItem createTDQIndicatorDefinitionItem = PropertiesFactoryImpl.eINSTANCE.createTDQIndicatorDefinitionItem();
    UserDefIndicator createUserDefIndicator = IndicatorSqlFactory.eINSTANCE.createUserDefIndicator();
    IndicatorDefinition createIndicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    // $NON-NLS-1$
    createIndicatorDefinition.setName("DependenciesHandlerTest.testSetUsageDependencyOnModelElementModelElementCase1UDI");
    createTDQIndicatorDefinitionItem.setIndicatorDefinition(createIndicatorDefinition);
    createUserDefIndicator.setIndicatorDefinition(createIndicatorDefinition);
    Property propertyUDI = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createProperty();
    propertyUDI.setId(EcoreUtil.generateUUID());
    // $NON-NLS-1$
    propertyUDI.setLabel("DependenciesHandlerTest.testSetUsageDependencyOnModelElementModelElementCase1UDI");
    createTDQIndicatorDefinitionItem.setProperty(propertyUDI);
    try {
        ProxyRepositoryFactory.getInstance().create(createTDQIndicatorDefinitionItem, new Path(EResourceConstant.USER_DEFINED_INDICATORS.getName()), false);
    } catch (PersistenceException e) {
        Assert.fail(e.getMessage());
    }
    // init UDI supplier Dependency
    analysisResult1.getIndicators().add(createUserDefIndicator);
    ElementWriterFactory.getInstance().createAnalysisWrite().save(analysisItem, true);
    if (!createIndicatorDefinition.getSupplierDependency().isEmpty()) {
        createIndicatorDefinition.getSupplierDependency().get(0).getClient().clear();
    }
    // call the test method
    TypedReturnCode<Dependency> setUsageDependencyOn = DependenciesHandler.getInstance().setUsageDependencyOn(analysis, createIndicatorDefinition);
    // $NON-NLS-1$
    Assert.assertEquals("call setUsageDependencyOn method should return ok stauts", true, setUsageDependencyOn.isOk());
    Assert.assertEquals(analysis, setUsageDependencyOn.getObject().getClient().get(0));
    Assert.assertEquals(1, setUsageDependencyOn.getObject().getClient().size());
    Assert.assertEquals(createIndicatorDefinition, setUsageDependencyOn.getObject().getSupplier().get(0));
    Assert.assertEquals(1, setUsageDependencyOn.getObject().getSupplier().size());
}
Also used : Path(org.eclipse.core.runtime.Path) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) Analysis(org.talend.dataquality.analysis.Analysis) ItemState(org.talend.core.model.properties.ItemState) PersistenceException(org.talend.commons.exception.PersistenceException) Dependency(orgomg.cwm.objectmodel.core.Dependency) Property(org.talend.core.model.properties.Property) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem) Test(org.junit.Test)

Example 88 with Analysis

use of org.talend.dataquality.analysis.Analysis in project tdq-studio-se by Talend.

the class DependenciesHandlerTest method testSetUsageDependencyOnModelElementModelElementCase3.

/**
 * Test method for
 * {@link org.talend.cwm.dependencies.DependenciesHandler#setUsageDependencyOn(ModelElement, ModelElement)} . case3
 * client side is lost
 */
@Test
public void testSetUsageDependencyOnModelElementModelElementCase3() {
    // analysis init
    TDQAnalysisItem analysisItem = PropertiesFactoryImpl.eINSTANCE.createTDQAnalysisItem();
    Analysis analysis = AnalysisFactory.eINSTANCE.createAnalysis();
    // $NON-NLS-1$
    analysis.setName("DependenciesHandlerTest.testSetUsageDependencyOnModelElementModelElementCase3Analysis");
    analysisItem.setAnalysis(analysis);
    Property propertyAna = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createProperty();
    propertyAna.setId(EcoreUtil.generateUUID());
    // $NON-NLS-1$
    propertyAna.setLabel("DependenciesHandlerTest.testSetUsageDependencyOnModelElementModelElementCase3Analysis");
    analysisItem.setProperty(propertyAna);
    ItemState itemState = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createItemState();
    itemState.setDeleted(false);
    analysisItem.setState(itemState);
    AnalysisResult analysisResult1 = AnalysisFactory.eINSTANCE.createAnalysisResult();
    analysis.setResults(analysisResult1);
    analysis.setContext(AnalysisFactory.eINSTANCE.createAnalysisContext());
    try {
        ProxyRepositoryFactory.getInstance().create(analysisItem, Path.EMPTY, false);
    } catch (PersistenceException e) {
        Assert.fail(e.getMessage());
    }
    // UDI init
    TDQIndicatorDefinitionItem createTDQIndicatorDefinitionItem = PropertiesFactoryImpl.eINSTANCE.createTDQIndicatorDefinitionItem();
    UserDefIndicator createUserDefIndicator = IndicatorSqlFactory.eINSTANCE.createUserDefIndicator();
    IndicatorDefinition createIndicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    // $NON-NLS-1$
    createIndicatorDefinition.setName("DependenciesHandlerTest.testSetUsageDependencyOnModelElementModelElementCase3UDI");
    createTDQIndicatorDefinitionItem.setIndicatorDefinition(createIndicatorDefinition);
    createUserDefIndicator.setIndicatorDefinition(createIndicatorDefinition);
    Property propertyUDI = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createProperty();
    propertyUDI.setId(EcoreUtil.generateUUID());
    // $NON-NLS-1$
    propertyUDI.setLabel("DependenciesHandlerTest.testSetUsageDependencyOnModelElementModelElementCase3UDI");
    createTDQIndicatorDefinitionItem.setProperty(propertyUDI);
    try {
        ProxyRepositoryFactory.getInstance().create(createTDQIndicatorDefinitionItem, new Path(EResourceConstant.USER_DEFINED_INDICATORS.getName()), false);
    } catch (PersistenceException e) {
        Assert.fail(e.getMessage());
    }
    // init UDI supplier Dependency
    analysisResult1.getIndicators().add(createUserDefIndicator);
    ElementWriterFactory.getInstance().createAnalysisWrite().save(analysisItem, true);
    if (!analysis.getClientDependency().isEmpty()) {
        analysis.getClientDependency().get(0).getSupplier().clear();
    }
    IndicatorDefinition createIndicatorDefinitionFromFile = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    try {
        createIndicatorDefinition.eResource().unload();
        IRepositoryViewObject lastVersion = ProxyRepositoryFactory.getInstance().getLastVersion(propertyUDI.getId());
        createIndicatorDefinitionFromFile = ((TDQIndicatorDefinitionItem) lastVersion.getProperty().getItem()).getIndicatorDefinition();
    } catch (PersistenceException e) {
        Assert.fail(e.getMessage());
    }
    // call the test method
    TypedReturnCode<Dependency> setUsageDependencyOn = DependenciesHandler.getInstance().setUsageDependencyOn(analysis, createIndicatorDefinitionFromFile);
    // $NON-NLS-1$
    Assert.assertEquals("call setUsageDependencyOn method should return ok stauts", true, setUsageDependencyOn.isOk());
    Assert.assertEquals(analysis, setUsageDependencyOn.getObject().getClient().get(0));
    Assert.assertEquals(1, setUsageDependencyOn.getObject().getClient().size());
    Assert.assertEquals(createIndicatorDefinitionFromFile, setUsageDependencyOn.getObject().getSupplier().get(0));
    Assert.assertEquals(1, setUsageDependencyOn.getObject().getSupplier().size());
}
Also used : Path(org.eclipse.core.runtime.Path) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) Dependency(orgomg.cwm.objectmodel.core.Dependency) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) Analysis(org.talend.dataquality.analysis.Analysis) ItemState(org.talend.core.model.properties.ItemState) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Property(org.talend.core.model.properties.Property) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem) Test(org.junit.Test)

Example 89 with Analysis

use of org.talend.dataquality.analysis.Analysis in project tdq-studio-se by Talend.

the class AnalysisHandlerTest method testGetDefaultLoadedRowCount.

/**
 * Test method for {@link org.talend.dq.analysis.AnalysisHandler#getDefaultLoadedRowCount()}.
 */
@Test
public void testGetDefaultLoadedRowCount() {
    int rowCountValue = 100;
    Analysis createAna = AnalysisFactory.eINSTANCE.createAnalysis();
    AnalysisResult createAnalysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
    createAna.setResults(createAnalysisResult);
    ExecutionInformations createExecutionInformations = AnalysisFactory.eINSTANCE.createExecutionInformations();
    createAnalysisResult.setResultMetadata(createExecutionInformations);
    AnalysisHandler createHandler = AnalysisHandler.createHandler(createAna);
    // default case the value should be 50
    String defaultLoadedRowCount = createHandler.getDefaultLoadedRowCount();
    Assert.assertEquals(Integer.valueOf(50), Integer.valueOf(defaultLoadedRowCount));
    // after setting the value the result should be changed
    TaggedValueHelper.setTaggedValue(createAna, TaggedValueHelper.PREVIEW_ROW_NUMBER, String.valueOf(rowCountValue));
    defaultLoadedRowCount = createHandler.getDefaultLoadedRowCount();
    Assert.assertEquals(Integer.valueOf(rowCountValue), Integer.valueOf(defaultLoadedRowCount));
}
Also used : ExecutionInformations(org.talend.dataquality.analysis.ExecutionInformations) Analysis(org.talend.dataquality.analysis.Analysis) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) Test(org.junit.Test)

Example 90 with Analysis

use of org.talend.dataquality.analysis.Analysis in project tdq-studio-se by Talend.

the class AnalysisExecutorHelperTest method testCheckPatternWithOutDependencyFiles.

@Test
public void testCheckPatternWithOutDependencyFiles() {
    // Load analysis item/property model from test file.
    // $NON-NLS-1$
    String anaPropertyFile = "/data/builtin/pattern_without_dep/TDQ_Data_Profiling/Analyses/patternMatchAna_0.1.properties";
    Resource anaPropertyResource = getPlatformResource(anaPropertyFile);
    Analysis ana = null;
    Property anaProperty = null;
    while (anaPropertyResource.getAllContents().hasNext()) {
        EObject eobj = anaPropertyResource.getAllContents().next();
        if (eobj instanceof Property) {
            anaProperty = (Property) eobj;
            ana = ((TDQAnalysisItem) anaProperty.getItem()).getAnalysis();
            break;
        }
    }
    if (ana == null) {
        Assert.fail("The analysis is null!");
    }
    if (ana.getResults() == null) {
        Assert.fail("The result of analysis is null!");
    }
    if (ana.getResults().getIndicators() == null) {
        Assert.fail("The indicators of analysis is null!");
    }
    assertTrue(ana.getResults().getIndicators().get(0).getParameters().getDataValidDomain().getPatterns().get(0).getName() == null);
    ReturnCode rc = AnalysisExecutorHelper.check(ana);
    assertTrue(rc.isOk());
    assertTrue(ana.getResults().getIndicators().get(0).getParameters().getDataValidDomain().getPatterns().get(0).getName() == null);
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) Analysis(org.talend.dataquality.analysis.Analysis) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) Property(org.talend.core.model.properties.Property) Test(org.junit.Test)

Aggregations

Analysis (org.talend.dataquality.analysis.Analysis)137 Test (org.junit.Test)36 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)36 AnalysisContext (org.talend.dataquality.analysis.AnalysisContext)30 ArrayList (java.util.ArrayList)28 Property (org.talend.core.model.properties.Property)28 Indicator (org.talend.dataquality.indicators.Indicator)27 TDQAnalysisItem (org.talend.dataquality.properties.TDQAnalysisItem)27 AnalysisResult (org.talend.dataquality.analysis.AnalysisResult)26 PersistenceException (org.talend.commons.exception.PersistenceException)19 Connection (org.talend.core.model.metadata.builder.connection.Connection)18 ReturnCode (org.talend.utils.sugars.ReturnCode)18 Dependency (orgomg.cwm.objectmodel.core.Dependency)18 TdColumn (org.talend.cwm.relational.TdColumn)16 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)16 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)15 Pattern (org.talend.dataquality.domain.pattern.Pattern)15 IFile (org.eclipse.core.resources.IFile)14 File (java.io.File)12 IPath (org.eclipse.core.runtime.IPath)12