Search in sources :

Example 21 with AnalysisResult

use of org.talend.dataquality.analysis.AnalysisResult 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 22 with AnalysisResult

use of org.talend.dataquality.analysis.AnalysisResult 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 23 with AnalysisResult

use of org.talend.dataquality.analysis.AnalysisResult 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 24 with AnalysisResult

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

the class RowMatchExplorerTest method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    // analysis
    analysis = AnalysisFactory.eINSTANCE.createAnalysis();
    AnalysisContext context = AnalysisFactory.eINSTANCE.createAnalysisContext();
    analysis.setContext(context);
    AnalysisResult mockResults = AnalysisFactory.eINSTANCE.createAnalysisResult();
    analysis.setResults(mockResults);
    // connection
    connection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
    analysis.getContext().setConnection(connection);
    TaggedValueHelper.setTaggedValue(connection, TaggedValueHelper.DB_PRODUCT_NAME, TaggedValueHelper.DB_PRODUCT_NAME);
    // ------------------------- table A ------------------------------
    Catalog catalogA = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createCatalog();
    // $NON-NLS-1$
    catalogA.setName("catalogA");
    Schema schemaA = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createSchema();
    // $NON-NLS-1$
    schemaA.setName("schemaA");
    catalogA.getOwnedElement().add(schemaA);
    TdTable tableA = RelationalFactory.eINSTANCE.createTdTable();
    // $NON-NLS-1$
    tableA.setName("tableA");
    schemaA.getOwnedElement().add(tableA);
    TdColumn tdColumnA = RelationalFactory.eINSTANCE.createTdColumn();
    // $NON-NLS-1$
    tdColumnA.setName("columnA");
    tableA.getFeature().add(tdColumnA);
    // ------------------------- table B ------------------------------
    Catalog catalogB = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createCatalog();
    // $NON-NLS-1$
    catalogB.setName("catalogB");
    Schema schemaB = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createSchema();
    // $NON-NLS-1$
    schemaB.setName("schemaB");
    catalogB.getOwnedElement().add(schemaB);
    TdTable tableB = org.talend.cwm.relational.RelationalFactory.eINSTANCE.createTdTable();
    // $NON-NLS-1$
    tableB.setName("tableB");
    schemaB.getOwnedElement().add(tableB);
    TdColumn tdColumnB = org.talend.cwm.relational.RelationalFactory.eINSTANCE.createTdColumn();
    // $NON-NLS-1$
    tdColumnB.setName("columnB");
    tableB.getFeature().add(tdColumnB);
    // indicator
    RowMatchingIndicator rowMatchingIndicator = ColumnsetFactory.eINSTANCE.createRowMatchingIndicator();
    // create indicatorDefinition
    IndicatorDefinition testIndicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    // $NON-NLS-1$
    testIndicatorDefinition.setName("RowMatchingIndicator");
    rowMatchingIndicator.setIndicatorDefinition(testIndicatorDefinition);
    analysis.getResults().getIndicators().add(rowMatchingIndicator);
    TaggedValueHelper.setTaggedValue(analysis, TaggedValueHelper.PURPOSE, TaggedValueHelper.PURPOSE);
    TaggedValueHelper.setTaggedValue(analysis, TaggedValueHelper.DESCRIPTION, TaggedValueHelper.DESCRIPTION);
    rowMatchingIndicator.setAnalyzedElement(tableA);
    rowMatchingIndicator.getColumnSetA().add(tdColumnA);
    rowMatchingIndicator.getColumnSetB().add(tdColumnB);
    explorer = new RowMatchExplorer();
    entity = new ChartDataEntity();
    entity.setIndicator(rowMatchingIndicator);
}
Also used : TdTable(org.talend.cwm.relational.TdTable) TdColumn(org.talend.cwm.relational.TdColumn) Schema(orgomg.cwm.resource.relational.Schema) RowMatchingIndicator(org.talend.dataquality.indicators.columnset.RowMatchingIndicator) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) ChartDataEntity(org.talend.dq.indicators.preview.table.ChartDataEntity) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) Catalog(orgomg.cwm.resource.relational.Catalog) BeforeClass(org.junit.BeforeClass)

Example 25 with AnalysisResult

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

the class SimpleStatisticsExplorerTest method testGetQueryMap.

/**
 * Test method for {@link org.talend.dq.analysis.explore.SimpleStatisticsExplorer#getQueryMap()}.
 */
@Test
public void testGetQueryMap() {
    Analysis ana = UnitTestBuildHelper.createAndInitAnalysis();
    TdTable table = org.talend.cwm.relational.RelationalFactory.eINSTANCE.createTdTable();
    // $NON-NLS-1$
    table.setName("TDQ_CALENDAR");
    TdColumn column = org.talend.cwm.relational.RelationalFactory.eINSTANCE.createTdColumn();
    // $NON-NLS-1$
    column.setName("CAL_DATE");
    TdSqlDataType tdsql = org.talend.cwm.relational.RelationalFactory.eINSTANCE.createTdSqlDataType();
    // $NON-NLS-1$
    tdsql.setName("DATE");
    tdsql.setJavaDataType(Types.DATE);
    column.setSqlDataType(tdsql);
    table.getOwnedElement().add(column);
    column.setOwner(table);
    // 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$
    TdExpression newTdExp = BooleanExpressionHelper.createTdExpression("SQL", body, null);
    newTdExp.setModificationDate(DateUtils.getCurrentDate(DateUtils.PATTERN_5));
    indicatorDefinition.getViewRowsExpression().add(newTdExp);
    // $NON-NLS-1$  //$NON-NLS-2$
    ChartDataEntity chartDataEntity = new ChartDataEntity(userDefIndicator, "2012-06-05", "1");
    chartDataEntity.setLabelNull(false);
    // $NON-NLS-1$
    chartDataEntity.setKey("2012-06-05");
    userDefIndicator.setAnalyzedElement(column);
    AnalysisResult createAnalysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
    ExecutionInformations createExecutionInformations = AnalysisFactory.eINSTANCE.createExecutionInformations();
    createAnalysisResult.setResultMetadata(createExecutionInformations);
    createAnalysisResult.getIndicators().add(userDefIndicator);
    userDefIndicator.setAnalyzedElement(column);
    ana.setResults(createAnalysisResult);
    SimpleStatisticsExplorer simpleStatisticsExplorer = new SimpleStatisticsExplorer();
    Assert.assertTrue(simpleStatisticsExplorer.setAnalysis(ana));
    simpleStatisticsExplorer.setEnitty(chartDataEntity);
    Map<String, String> queryMap = simpleStatisticsExplorer.getQueryMap();
    assertFalse(queryMap.isEmpty());
    assertEquals(1, queryMap.size());
    System.err.println(queryMap.get("View rows"));
    assertEquals(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    "-- Analysis: anaA ;\n" + "-- Type of Analysis: Column Analysis ;\n" + "-- Purpose:  ;\n" + "-- Description:  ;\n" + "-- AnalyzedElement: CAL_DATE ;\n" + "-- Indicator: user define ;\n" + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    "-- Showing: View rows ;\n" + "SELECT * FROM TDQ_CALENDAR ", // $NON-NLS-1$ //$NON-NLS-2$
    queryMap.get("View rows"));
    // test when is not sql engine
    ana.getParameters().setExecutionLanguage(ExecutionLanguage.JAVA);
    Map<String, String> queryMap_java = simpleStatisticsExplorer.getQueryMap();
    assertFalse(queryMap_java.isEmpty());
    assertEquals(1, queryMap_java.size());
    // $NON-NLS-1$
    assertEquals(null, queryMap_java.get("View rows"));
}
Also used : TdTable(org.talend.cwm.relational.TdTable) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) TdExpression(org.talend.cwm.relational.TdExpression) ChartDataEntity(org.talend.dq.indicators.preview.table.ChartDataEntity) TdSqlDataType(org.talend.cwm.relational.TdSqlDataType) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) ExecutionInformations(org.talend.dataquality.analysis.ExecutionInformations) TdColumn(org.talend.cwm.relational.TdColumn) Analysis(org.talend.dataquality.analysis.Analysis) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) Test(org.junit.Test)

Aggregations

AnalysisResult (org.talend.dataquality.analysis.AnalysisResult)40 Analysis (org.talend.dataquality.analysis.Analysis)26 Test (org.junit.Test)15 AnalysisContext (org.talend.dataquality.analysis.AnalysisContext)15 TDQAnalysisItem (org.talend.dataquality.properties.TDQAnalysisItem)14 ExecutionInformations (org.talend.dataquality.analysis.ExecutionInformations)13 Property (org.talend.core.model.properties.Property)11 PersistenceException (org.talend.commons.exception.PersistenceException)10 ItemState (org.talend.core.model.properties.ItemState)10 Path (org.eclipse.core.runtime.Path)8 TdColumn (org.talend.cwm.relational.TdColumn)8 TdTable (org.talend.cwm.relational.TdTable)8 Indicator (org.talend.dataquality.indicators.Indicator)8 IPath (org.eclipse.core.runtime.IPath)7 AnalysisParameters (org.talend.dataquality.analysis.AnalysisParameters)7 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)7 ReturnCode (org.talend.utils.sugars.ReturnCode)7 UserDefIndicator (org.talend.dataquality.indicators.sql.UserDefIndicator)6 Before (org.junit.Before)5 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)4