Search in sources :

Example 31 with IndicatorDefinition

use of org.talend.dataquality.indicators.definition.IndicatorDefinition in project tdq-studio-se by Talend.

the class InidcatorUnitTest method testIsExsitingFormCase1.

/**
 * Test method for {@link org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit#isExsitingForm()}.
 *
 * test case 1:ColumnIndicatorUnit
 */
@Test
public void testIsExsitingFormCase1() {
    Indicator indicator = IndicatorsFactory.eINSTANCE.createIndicator();
    ModelElementIndicator modelElementIndicator = UnitTestBuildHelper.createModelElementIndicator();
    // Count UDI case
    IndicatorDefinition createIndicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    createIndicatorDefinition.getCategories().add(DefinitionHandler.getInstance().getUserDefinedCountIndicatorCategory());
    indicator.setIndicatorDefinition(createIndicatorDefinition);
    ColumnIndicatorUnit colUnit = new ColumnIndicatorUnit(IndicatorEnum.UserDefinedIndicatorEnum, indicator, modelElementIndicator);
    boolean exsitingForm = colUnit.isExsitingForm();
    // TDQ-10557: Allow set threshold option on UDIs
    Assert.assertEquals("indicator " + IndicatorEnum.UserDefinedIndicatorEnum.getLabel() + " User Defined Count exists Form enum", true, exsitingForm);
}
Also used : IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator) Indicator(org.talend.dataquality.indicators.Indicator) RowCountIndicator(org.talend.dataquality.indicators.RowCountIndicator) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator) Test(org.junit.Test)

Example 32 with IndicatorDefinition

use of org.talend.dataquality.indicators.definition.IndicatorDefinition in project tdq-studio-se by Talend.

the class FileSystemImportWriterTest method testPopulate_1.

/**
 * 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)}
 * . check: if it is a indicator and checkExist=false(overwrite), then this method should return 0 record.
 *
 * @throws Exception
 */
@Test
public void testPopulate_1() throws Exception {
    List<ItemRecord> itemRecords = new ArrayList<ItemRecord>();
    ItemRecord item1 = mock(ItemRecord.class);
    itemRecords.add(item1);
    IndicatorDefinition importedDef = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    when(item1.getElement()).thenReturn(importedDef);
    when(item1.getProperty()).thenReturn(null);
    when(item1.getErrors()).thenReturn(new ArrayList<String>());
    ItemRecord[] result = this.writer.populate(itemRecords.toArray(new ItemRecord[itemRecords.size()]), false);
    Assert.assertEquals(result.length, 0);
}
Also used : ArrayList(java.util.ArrayList) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 33 with IndicatorDefinition

use of org.talend.dataquality.indicators.definition.IndicatorDefinition in project tdq-studio-se by Talend.

the class FileSystemImportWriterTest method testPopulate_2.

@Test
public void testPopulate_2() throws Exception {
    List<ItemRecord> itemRecords = new ArrayList<ItemRecord>();
    ItemRecord item1 = mock(ItemRecord.class);
    itemRecords.add(item1);
    IndicatorDefinition importedDef = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    when(item1.getElement()).thenReturn(importedDef);
    when(item1.getProperty()).thenReturn(null);
    when(item1.getErrors()).thenReturn(new ArrayList<String>());
    // if checkExist = true , should return 1
    when(item1.isValid()).thenReturn(false);
    when(item1.getConflictObject()).thenReturn(mock(IRepositoryViewObject.class));
    // $NON-NLS-1$
    when(item1.getName()).thenReturn("name");
    PowerMockito.spy(item1);
    PowerMockito.doNothing().when(item1).addError(anyString());
    ResourceBundle rb2 = mock(ResourceBundle.class);
    // $NON-NLS-1$
    stub(method(ResourceBundle.class, "getBundle", String.class)).toReturn(rb2);
    PowerMockito.mockStatic(DefaultMessagesImpl.class);
    // $NON-NLS-1$
    when(DefaultMessagesImpl.getString(anyString())).thenReturn("name");
    ItemRecord[] result2 = this.writer.populate(itemRecords.toArray(new ItemRecord[itemRecords.size()]), true);
    Assert.assertEquals(result2.length, 1);
}
Also used : ArrayList(java.util.ArrayList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ResourceBundle(java.util.ResourceBundle) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 34 with IndicatorDefinition

use of org.talend.dataquality.indicators.definition.IndicatorDefinition 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 35 with IndicatorDefinition

use of org.talend.dataquality.indicators.definition.IndicatorDefinition 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

IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)141 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)37 Test (org.junit.Test)35 ArrayList (java.util.ArrayList)34 TdExpression (org.talend.cwm.relational.TdExpression)31 File (java.io.File)22 Analysis (org.talend.dataquality.analysis.Analysis)16 IFile (org.eclipse.core.resources.IFile)15 Property (org.talend.core.model.properties.Property)14 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)14 TDQIndicatorDefinitionItem (org.talend.dataquality.properties.TDQIndicatorDefinitionItem)14 PersistenceException (org.talend.commons.exception.PersistenceException)13 Indicator (org.talend.dataquality.indicators.Indicator)12 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)12 Path (org.eclipse.core.runtime.Path)10 IFolder (org.eclipse.core.resources.IFolder)9 BasicEList (org.eclipse.emf.common.util.BasicEList)9 TdColumn (org.talend.cwm.relational.TdColumn)9 UserDefIndicator (org.talend.dataquality.indicators.sql.UserDefIndicator)7 TDQAnalysisItem (org.talend.dataquality.properties.TDQAnalysisItem)7