Search in sources :

Example 6 with TDQIndicatorDefinitionItem

use of org.talend.dataquality.properties.TDQIndicatorDefinitionItem in project tdq-studio-se by Talend.

the class InidcatorUnitTest method testGetFormsCase1.

/**
 * Test method for {@link org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit#getForms()}.
 *
 * test case 1: Get Forms from ColumnSetIndicatorUnit
 */
@Test
public void testGetFormsCase1() {
    RowCountIndicator rowCountIndicator = IndicatorsFactory.eINSTANCE.createRowCountIndicator();
    IRepositoryViewObject rowCountRepositoryViewObject = null;
    try {
        List<IRepositoryViewObject> all = ProxyRepositoryFactory.getInstance().getAll(ERepositoryObjectType.SYSTEM_INDICATORS_SIMPLE_STATISTICS);
        Assert.assertEquals(10, all.size());
        rowCountRepositoryViewObject = all.get(7);
    } catch (PersistenceException e) {
        Assert.fail(e.getMessage());
    }
    Assert.assertNotNull(rowCountRepositoryViewObject);
    TDQIndicatorDefinitionItem rowCountItem = (TDQIndicatorDefinitionItem) rowCountRepositoryViewObject.getProperty().getItem();
    rowCountIndicator.setIndicatorDefinition(rowCountItem.getIndicatorDefinition());
    ColumnSetIndicatorUnit columnSetIndicatorUnit = new ColumnSetIndicatorUnit(IndicatorEnum.RowCountIndicatorEnum, rowCountIndicator);
    FormEnum[] forms = new FormEnum[] { FormEnum.IndicatorThresholdsForm };
    FormEnum[] resultforms = columnSetIndicatorUnit.getForms();
    Assert.assertEquals(forms.length, resultforms.length);
    for (int index = 0; index < forms.length; index++) {
        Assert.assertEquals(forms[index], resultforms[index]);
    }
}
Also used : TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) RowCountIndicator(org.talend.dataquality.indicators.RowCountIndicator) FormEnum(org.talend.dataprofiler.core.ui.wizard.indicator.forms.FormEnum) Test(org.junit.Test)

Example 7 with TDQIndicatorDefinitionItem

use of org.talend.dataquality.properties.TDQIndicatorDefinitionItem in project tdq-studio-se by Talend.

the class InidcatorUnitTest method testGetIndicatorNameCase2.

/**
 * Test method for {@link org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit#getIndicatorName()}.
 *
 * test case 2: Get Indicator Name from ColumnIndicatorUnit
 */
@Test
public void testGetIndicatorNameCase2() {
    RowCountIndicator rowCountIndicator = IndicatorsFactory.eINSTANCE.createRowCountIndicator();
    IRepositoryViewObject rowCountRepositoryViewObject = null;
    try {
        List<IRepositoryViewObject> all = ProxyRepositoryFactory.getInstance().getAll(ERepositoryObjectType.SYSTEM_INDICATORS_SIMPLE_STATISTICS);
        Assert.assertEquals(10, all.size());
        rowCountRepositoryViewObject = all.get(7);
    } catch (PersistenceException e) {
        Assert.fail(e.getMessage());
    }
    Assert.assertNotNull(rowCountRepositoryViewObject);
    TDQIndicatorDefinitionItem rowCountItem = (TDQIndicatorDefinitionItem) rowCountRepositoryViewObject.getProperty().getItem();
    rowCountIndicator.setIndicatorDefinition(rowCountItem.getIndicatorDefinition());
    ColumnIndicatorUnit columnIndicatorUnit = new ColumnIndicatorUnit(IndicatorEnum.RowCountIndicatorEnum, rowCountIndicator, null);
    Assert.assertEquals(org.talend.cwm.management.i18n.Messages.getString(rowCountItem.getProperty().getLabel()), columnIndicatorUnit.getIndicatorName());
}
Also used : TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) RowCountIndicator(org.talend.dataquality.indicators.RowCountIndicator) Test(org.junit.Test)

Example 8 with TDQIndicatorDefinitionItem

use of org.talend.dataquality.properties.TDQIndicatorDefinitionItem in project tdq-studio-se by Talend.

the class BenfordLawFrequencyStateTest method setUp.

/**
 * init the state.
 *
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    UnitTestBuildHelper.initProjectStructure();
    List<IndicatorUnit> units = new ArrayList<IndicatorUnit>();
    BenfordLawFrequencyIndicator benfordLawFrequencyIndicator = IndicatorsFactory.eINSTANCE.createBenfordLawFrequencyIndicator();
    List<IRepositoryViewObject> all = ProxyRepositoryFactory.getInstance().getAll(ERepositoryObjectType.SYSTEM_INDICATORS_FRAUDDETECTION);
    Assert.assertEquals(1, all.size());
    IRepositoryViewObject iRepositoryViewObject = all.get(0);
    Assert.assertNotNull(iRepositoryViewObject);
    TDQIndicatorDefinitionItem benfordItem = (TDQIndicatorDefinitionItem) iRepositoryViewObject.getProperty().getItem();
    benfordLawFrequencyIndicator.setIndicatorDefinition(benfordItem.getIndicatorDefinition());
    ModelElementIndicator modelElementIndicator = UnitTestBuildHelper.createModelElementIndicator();
    ColumnIndicatorUnit columnIndicatorUnit = new ColumnIndicatorUnit(IndicatorEnum.BenfordLawFrequencyIndicatorEnum, benfordLawFrequencyIndicator, modelElementIndicator);
    // IndicatorUnit unit = mock(IndicatorUnit.class);
    units.add(columnIndicatorUnit);
    for (int i = 0; i < 10; i++) {
        benfordLawFrequencyIndicator.handle(i);
    }
    benState = new BenfordLawFrequencyState(units);
}
Also used : TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) BenfordLawFrequencyIndicator(org.talend.dataquality.indicators.BenfordLawFrequencyIndicator) ColumnIndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.ColumnIndicatorUnit) IndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit) ArrayList(java.util.ArrayList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ColumnIndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.ColumnIndicatorUnit) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator) Before(org.junit.Before)

Example 9 with TDQIndicatorDefinitionItem

use of org.talend.dataquality.properties.TDQIndicatorDefinitionItem 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 10 with TDQIndicatorDefinitionItem

use of org.talend.dataquality.properties.TDQIndicatorDefinitionItem in project tdq-studio-se by Talend.

the class ItemRecordTest method saveIndicatorDefintion.

private void saveIndicatorDefintion(String uuid, String name) throws PersistenceException {
    // create definition
    IndicatorDefinition createIndicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    TDQIndicatorDefinitionItem createTDQIndicatorDefinitionItem = PropertiesFactory.eINSTANCE.createTDQIndicatorDefinitionItem();
    createTDQIndicatorDefinitionItem.setIndicatorDefinition(createIndicatorDefinition);
    Property createProperty = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createProperty();
    createProperty.setLabel(name);
    createIndicatorDefinition.setLabel(name);
    createIndicatorDefinition.setName(name);
    createTDQIndicatorDefinitionItem.setProperty(createProperty);
    createProperty.setId(uuid);
    ProxyRepositoryFactory.getInstance().create(createTDQIndicatorDefinitionItem, new Path(ERepositoryObjectType.TDQ_SYSTEM_INDICATORS.getFolder()).removeFirstSegments(2), false);
}
Also used : Path(org.eclipse.core.runtime.Path) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) Property(org.talend.core.model.properties.Property)

Aggregations

TDQIndicatorDefinitionItem (org.talend.dataquality.properties.TDQIndicatorDefinitionItem)28 PersistenceException (org.talend.commons.exception.PersistenceException)13 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)13 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)13 Test (org.junit.Test)12 Item (org.talend.core.model.properties.Item)9 Property (org.talend.core.model.properties.Property)8 TDQAnalysisItem (org.talend.dataquality.properties.TDQAnalysisItem)8 Path (org.eclipse.core.runtime.Path)7 TDQPatternItem (org.talend.dataquality.properties.TDQPatternItem)7 Analysis (org.talend.dataquality.analysis.Analysis)6 RowCountIndicator (org.talend.dataquality.indicators.RowCountIndicator)6 TDQBusinessRuleItem (org.talend.dataquality.properties.TDQBusinessRuleItem)5 TDQReportItem (org.talend.dataquality.properties.TDQReportItem)5 File (java.io.File)4 IPath (org.eclipse.core.runtime.IPath)4 Resource (org.eclipse.emf.ecore.resource.Resource)4 ItemState (org.talend.core.model.properties.ItemState)4 TDQItem (org.talend.core.model.properties.TDQItem)4 ReturnCode (org.talend.utils.sugars.ReturnCode)4