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());
}
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());
}
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));
}
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);
}
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"));
}
Aggregations