Search in sources :

Example 11 with AnalysisParameters

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

the class EObjectHelperTest method testGetFirstDependency.

/**
 * Test method for
 * {@link org.talend.dq.helper.EObjectHelper#getFirstDependency(org.talend.repository.model.IRepositoryNode)}.
 */
@Test
public void testGetFirstDependency() {
    // test when the node is null
    List<ModelElement> firstDependency = EObjectHelper.getFirstDependency(null);
    assertTrue(firstDependency.isEmpty());
    IRepositoryNode tableNode = mock(IRepositoryNode.class);
    MetadataTable mod = mock(MetadataTable.class);
    // $NON-NLS-1$
    when(mod.getName()).thenReturn("mod");
    PowerMockito.mockStatic(RepositoryNodeHelper.class);
    when(RepositoryNodeHelper.getMetadataElement(tableNode)).thenReturn(mod);
    Connection connection = mock(Connection.class);
    PowerMockito.mockStatic(ModelElementHelper.class);
    when(ModelElementHelper.getConnection(mod)).thenReturn(connection);
    EList<Dependency> supplierDependency = new BasicEList<Dependency>();
    when(connection.getSupplierDependency()).thenReturn(supplierDependency);
    // when there is no SupplierDependency for this node
    assertTrue(EObjectHelper.getFirstDependency(tableNode).isEmpty());
    // add some analysis to use this table node
    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);
    supplierDependency.add(dependency);
    when(connection.getSupplierDependency()).thenReturn(supplierDependency);
    AnalysisParameters parameters = mock(AnalysisParameters.class);
    when(parameters.getExecutionLanguage()).thenReturn(ExecutionLanguage.SQL);
    when(analysis.getParameters()).thenReturn(parameters);
    AnalysisContext context = mock(AnalysisContext.class);
    when(analysis.getContext()).thenReturn(context);
    EList<ModelElement> modList = new BasicEList<ModelElement>();
    modList.add(mod);
    when(ModelElementHelper.compareUUID(mod, mod)).thenReturn(true);
    MetadataTable mod1 = mock(MetadataTable.class);
    // $NON-NLS-1$
    when(mod1.getName()).thenReturn("mod1");
    when(mod1.eIsProxy()).thenReturn(false);
    modList.add(mod1);
    MetadataTable mod2 = mock(MetadataTable.class);
    // $NON-NLS-1$
    when(mod2.getName()).thenReturn("mod2");
    when(mod2.eIsProxy()).thenReturn(false);
    modList.add(mod2);
    when(context.getAnalysedElements()).thenReturn(modList);
    assertFalse(EObjectHelper.getFirstDependency(tableNode).isEmpty());
    assertEquals(analysis, EObjectHelper.getFirstDependency(tableNode).get(0));
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) IRepositoryNode(org.talend.repository.model.IRepositoryNode) Analysis(org.talend.dataquality.analysis.Analysis) AnalysisParameters(org.talend.dataquality.analysis.AnalysisParameters) BasicEList(org.eclipse.emf.common.util.BasicEList) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) Connection(org.talend.core.model.metadata.builder.connection.Connection) Dependency(orgomg.cwm.objectmodel.core.Dependency) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 12 with AnalysisParameters

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

the class UnitTestBuildHelper method createAndInitAnalysis.

public static Analysis createAndInitAnalysis() {
    Analysis ana = UnitTestBuildHelper.createRealAnalysis("anaA", null, false);
    AnalysisParameters parameters = AnalysisFactory.eINSTANCE.createAnalysisParameters();
    parameters.setExecutionLanguage(ExecutionLanguage.SQL);
    ana.setParameters(parameters);
    AnalysisContext context = AnalysisFactory.eINSTANCE.createAnalysisContext();
    ana.setContext(context);
    Connection createConnection = ConnectionFactory.eINSTANCE.createConnection();
    createConnection.setName("MySQL");
    context.setConnection(createConnection);
    return ana;
}
Also used : Analysis(org.talend.dataquality.analysis.Analysis) AnalysisParameters(org.talend.dataquality.analysis.AnalysisParameters) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext)

Example 13 with AnalysisParameters

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

the class AnalysisHandleTest method testUpdate.

/**
 * Test method for
 * {@link org.talend.dataprofiler.core.ui.action.actions.handle.AnalysisDuplicateHandle#update(orgomg.cwm.objectmodel.core.ModelElement, orgomg.cwm.objectmodel.core.ModelElement)}
 * .
 */
@Test
public void testUpdate() {
    // $NON-NLS-1$
    Analysis newAnalysis = AnalysisHelper.createAnalysis("new ana");
    AnalysisParameters parameters = AnalysisFactory.eINSTANCE.createAnalysisParameters();
    newAnalysis.setParameters(parameters);
    // make the new analysis use the old domain
    EList<Domain> oldDataFilters = oldAnalysis.getParameters().getDataFilter();
    assertEquals(2, oldDataFilters.size());
    EList<Domain> newFilter = parameters.getDataFilter();
    for (Domain domain : oldDataFilters) {
        newFilter.add(domain);
    }
    ModelElement copiedAna = handle.update(oldAnalysis, newAnalysis);
    EList<Domain> newDataFilters = ((Analysis) copiedAna).getParameters().getDataFilter();
    assertEquals(2, newDataFilters.size());
    // after update, the old domain should be replaced by a new one, but with same body& language
    for (int i = 0; i < newDataFilters.size(); i++) {
        Domain domain = newDataFilters.get(i);
        Domain oldDomain = oldDataFilters.get(i);
        Assert.assertNotSame(oldDomain, domain);
        // $NON-NLS-1$
        assertTrue(domain.getName().equals("Analysis Data Filter"));
        // the expressions are different instances, with same boby&language.
        if (domain.getRanges() != null && oldDomain.getRanges() != null) {
            Expression ex = domain.getRanges().get(0).getExpressions().getExpression();
            Expression oldex = oldDomain.getRanges().get(0).getExpressions().getExpression();
            Assert.assertNotSame(oldex, ex);
            assertTrue(ex.getBody().equals(oldex.getBody()));
            assertTrue(ex.getLanguage().equals(oldex.getLanguage()));
        }
    }
    // check the patterns
    String tablePattern = DomainHelper.getTablePattern(newDataFilters);
    assertEquals(TABLE_PATTERN_FILTER, tablePattern);
    String viewPattern = DomainHelper.getViewPattern(newDataFilters);
    assertEquals(VIEW_PATTERN_FILTER, viewPattern);
}
Also used : ModelElement(orgomg.cwm.objectmodel.core.ModelElement) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) Expression(orgomg.cwm.objectmodel.core.Expression) Analysis(org.talend.dataquality.analysis.Analysis) AnalysisParameters(org.talend.dataquality.analysis.AnalysisParameters) Domain(org.talend.dataquality.domain.Domain) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with AnalysisParameters

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

the class AnalysisHandleTest method setUp.

/**
 * DOC yyin Comment method "setUp".
 *
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    // init the analysis
    // $NON-NLS-1$
    oldAnalysis = AnalysisHelper.createAnalysis("Analysis Data Filter");
    AnalysisParameters parameters = AnalysisFactory.eINSTANCE.createAnalysisParameters();
    oldAnalysis.setParameters(parameters);
    // add two filters which type is ranges
    // $NON-NLS-1$
    AnalysisHelper.setStringDataFilter(oldAnalysis, "filter1", 0);
    // $NON-NLS-1$
    AnalysisHelper.setStringDataFilter(oldAnalysis, "filter2", 1);
    // add one filter which type is pattern and contains two patterns
    EList<Domain> dataFilters = oldAnalysis.getParameters().getDataFilter();
    RegularExpression tablePattern = BooleanExpressionHelper.createRegularExpression(null, TABLE_PATTERN_FILTER);
    // $NON-NLS-1$
    addPatternToDomain(dataFilters.get(0), tablePattern, "Table Pattern");
    RegularExpression viewPattern = BooleanExpressionHelper.createRegularExpression(null, VIEW_PATTERN_FILTER);
    // $NON-NLS-1$
    addPatternToDomain(dataFilters.get(0), viewPattern, "View Pattern");
    // create a handle
    IRepositoryNode node = mock(IRepositoryNode.class);
    IRepositoryViewObject object = mock(IRepositoryViewObject.class);
    when(node.getObject()).thenReturn(object);
    Property pro = mock(Property.class);
    when(object.getProperty()).thenReturn(pro);
    IPath itemPath = mock(IPath.class);
    PowerMockito.mockStatic(WorkbenchUtils.class);
    when(WorkbenchUtils.getFilePath(node)).thenReturn(itemPath);
    PowerMockito.mockStatic(ResourceManager.class);
    IWorkspaceRoot root = mock(IWorkspaceRoot.class);
    when(ResourceManager.getRoot()).thenReturn(root);
    when(root.getFile(itemPath)).thenReturn(null);
    PowerMockito.mockStatic(RepositoryNodeHelper.class);
    when(RepositoryNodeHelper.getModelElementFromRepositoryNode(node)).thenReturn(oldAnalysis);
    handle = new AnalysisDuplicateHandle();
}
Also used : RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) IRepositoryNode(org.talend.repository.model.IRepositoryNode) IPath(org.eclipse.core.runtime.IPath) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) AnalysisParameters(org.talend.dataquality.analysis.AnalysisParameters) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Domain(org.talend.dataquality.domain.Domain) Property(org.talend.core.model.properties.Property) Before(org.junit.Before)

Example 15 with AnalysisParameters

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

the class AbstractCommonActionProviderTest method createAnalysisNode.

private RepositoryNode createAnalysisNode(String name, IFolder folder, boolean isDelete) {
    IPath createPath = Path.EMPTY;
    if (folder != null) {
        createPath = new Path(folder.getFullPath().lastSegment());
    }
    // connection
    Analysis createAnalysis = AnalysisFactory.eINSTANCE.createAnalysis();
    createAnalysis.setName(name);
    // ~connection
    TDQAnalysisItem createAnalysisItem = org.talend.dataquality.properties.PropertiesFactory.eINSTANCE.createTDQAnalysisItem();
    org.talend.core.model.properties.Property createAnaProperty = PropertiesFactory.eINSTANCE.createProperty();
    createAnaProperty.setId(EcoreUtil.generateUUID());
    createAnaProperty.setItem(createAnalysisItem);
    createAnaProperty.setLabel(createAnalysis.getName());
    createAnalysisItem.setProperty(createAnaProperty);
    createAnalysisItem.setAnalysis(createAnalysis);
    ItemState createItemState = PropertiesFactory.eINSTANCE.createItemState();
    createItemState.setDeleted(isDelete);
    createAnalysisItem.setState(createItemState);
    // Indicator
    CountsIndicator createCountsIndicator = IndicatorsFactory.eINSTANCE.createCountsIndicator();
    List<IRepositoryViewObject> all = null;
    IndicatorDefinition createIndicatorDefinition = null;
    try {
        all = factory.getAll(ERepositoryObjectType.TDQ_SYSTEM_INDICATORS);
        for (IRepositoryViewObject indicatorViewObject : all) {
            if (indicatorViewObject.getLabel().equalsIgnoreCase("ROW COUNT")) {
                // $NON-NLS-1$
                createIndicatorDefinition = (IndicatorDefinition) PropertyHelper.getModelElement(indicatorViewObject.getProperty());
                break;
            }
        }
    } catch (PersistenceException e1) {
        e1.printStackTrace();
        Assert.fail(e1.getMessage());
    }
    createCountsIndicator.setIndicatorDefinition(createIndicatorDefinition);
    AnalysisParameters createAnalysisParameters = AnalysisFactory.eINSTANCE.createAnalysisParameters();
    AnalysisContext createAnalysisContext = AnalysisFactory.eINSTANCE.createAnalysisContext();
    createAnalysis.setContext(createAnalysisContext);
    AnalysisResult createAnalysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
    ExecutionInformations createExecutionInformations = AnalysisFactory.eINSTANCE.createExecutionInformations();
    createAnalysisResult.setResultMetadata(createExecutionInformations);
    createAnalysisResult.getIndicators().add(createCountsIndicator);
    createAnalysis.setResults(createAnalysisResult);
    createAnalysis.setParameters(createAnalysisParameters);
    IRepositoryViewObject repViewObject = null;
    try {
        factory.create(createAnalysisItem, createPath, false);
        repViewObject = factory.getLastVersion(createAnaProperty.getId());
    } catch (PersistenceException e) {
        Assert.fail(e.getMessage());
    }
    RepositoryNode anaRepNode = new AnalysisRepNode(repViewObject, null, ENodeType.TDQ_REPOSITORY_ELEMENT, null);
    // set the contentType for anaRepNode from its parentNode
    setParentNode(anaRepNode, ERepositoryObjectType.TDQ_ANALYSIS_ELEMENT);
    // ~
    return anaRepNode;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) CountsIndicator(org.talend.dataquality.indicators.CountsIndicator) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) RepositoryNode(org.talend.repository.model.RepositoryNode) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) ExecutionInformations(org.talend.dataquality.analysis.ExecutionInformations) AnalysisRepNode(org.talend.dq.nodes.AnalysisRepNode) Analysis(org.talend.dataquality.analysis.Analysis) AnalysisParameters(org.talend.dataquality.analysis.AnalysisParameters) ItemState(org.talend.core.model.properties.ItemState) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem)

Aggregations

AnalysisParameters (org.talend.dataquality.analysis.AnalysisParameters)19 AnalysisContext (org.talend.dataquality.analysis.AnalysisContext)13 Analysis (org.talend.dataquality.analysis.Analysis)10 AnalysisResult (org.talend.dataquality.analysis.AnalysisResult)7 Test (org.junit.Test)6 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)6 TdTable (org.talend.cwm.relational.TdTable)6 TdColumn (org.talend.cwm.relational.TdColumn)5 ExecutionInformations (org.talend.dataquality.analysis.ExecutionInformations)5 Before (org.junit.Before)4 Connection (org.talend.core.model.metadata.builder.connection.Connection)3 Domain (org.talend.dataquality.domain.Domain)3 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)3 Package (orgomg.cwm.objectmodel.core.Package)3 IPath (org.eclipse.core.runtime.IPath)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 DelimitedFileConnection (org.talend.core.model.metadata.builder.connection.DelimitedFileConnection)2 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)2 TdSqlDataType (org.talend.cwm.relational.TdSqlDataType)2 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)2