use of org.talend.dataquality.analysis.AnalysisResult in project tdq-studio-se by Talend.
the class UnitTestBuildHelper method createRealAnalysis.
/**
* DOC qiongli Comment method "createRealAnalysis".
*
* @param name
* @param folder
* @param isDelete
* @return
*/
public static Analysis createRealAnalysis(String name, IFolder folder, Boolean isDelete) {
IPath createPath = Path.EMPTY;
if (folder != null) {
createPath = new Path(folder.getFullPath().lastSegment());
}
Analysis analysis1 = AnalysisHelper.createAnalysis(name);
TDQAnalysisItem item1 = PropertiesFactoryImpl.eINSTANCE.createTDQAnalysisItem();
org.talend.core.model.properties.Property property1 = PropertiesFactory.eINSTANCE.createProperty();
property1.setId(EcoreUtil.generateUUID());
property1.setItem(item1);
property1.setLabel(analysis1.getName());
item1.setProperty(property1);
item1.setAnalysis(analysis1);
ItemState itemState = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createItemState();
itemState.setDeleted(isDelete);
item1.setState(itemState);
AnalysisResult analysisResult1 = AnalysisFactory.eINSTANCE.createAnalysisResult();
analysis1.setResults(analysisResult1);
try {
ProxyRepositoryFactory.getInstance().create(item1, createPath, false);
} catch (PersistenceException e) {
Assert.fail(e.getMessage());
}
return analysis1;
}
use of org.talend.dataquality.analysis.AnalysisResult in project tdq-studio-se by Talend.
the class TableAnalysisSqlExecutorTest method setUp.
/**
* DOC xqliu Comment method "setUp".
*
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
// create TdTable
TdTable testTdTable = RelationalFactory.eINSTANCE.createTdTable();
// $NON-NLS-1$
testTdTable.setName("generateTable");
// create connection
DatabaseConnection testDatabaseConnection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
TaggedValueHelper.setTaggedValue(testDatabaseConnection, TaggedValueHelper.DB_PRODUCT_NAME, SupportDBUrlType.MYSQLDEFAULTURL.getDBKey());
// create catalog
Catalog testCatalog = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createCatalog();
// $NON-NLS-1$
testCatalog.setName("TBI");
testTdTable.setNamespace(testCatalog);
testCatalog.setNamespace(testDatabaseConnection);
testCatalog.getDataManager().add(testDatabaseConnection);
// create analysis
testAnalysis = AnalysisFactory.eINSTANCE.createAnalysis();
// create Analaysis result
AnalysisResult testAnalysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
testAnalysis.setResults(testAnalysisResult);
// create analysis parameter
AnalysisParameters testAnalysisParameters = AnalysisFactory.eINSTANCE.createAnalysisParameters();
testAnalysis.setParameters(testAnalysisParameters);
// create analysis Content
AnalysisContext testAnalysisContext = AnalysisFactory.eINSTANCE.createAnalysisContext();
testAnalysis.setContext(testAnalysisContext);
testAnalysisContext.setConnection(testDatabaseConnection);
// create WhereRuleAide indicatorDefinition
testWhereRuleIndicatorDefinition = RulesFactory.eINSTANCE.createWhereRule();
// $NON-NLS-1$
testWhereRuleIndicatorDefinition.setLabel("rule1");
// create WhereRule indicator
testWhereRuleIndicator = IndicatorSqlFactory.eINSTANCE.createWhereRuleIndicator();
testAnalysisResult.getIndicators().add(testWhereRuleIndicator);
testWhereRuleIndicator.setAnalyzedElement(testTdTable);
testWhereRuleIndicator.setIndicatorDefinition(testWhereRuleIndicatorDefinition);
}
use of org.talend.dataquality.analysis.AnalysisResult in project tdq-studio-se by Talend.
the class TdqAnalysisConnectionPoolTest method setUp.
/**
* DOC yyin Comment method "setUp".
*
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
analysis = mock(Analysis.class);
AnalysisContext context = mock(AnalysisContext.class);
AnalysisResult result = mock(AnalysisResult.class);
dataManager = mock(org.talend.core.model.metadata.builder.connection.Connection.class);
ExecutionInformations resultMetadata = mock(ExecutionInformations.class);
PowerMockito.mockStatic(AnalysisHandler.class);
AnalysisHandler mockHandler = mock(AnalysisHandler.class);
when(AnalysisHandler.createHandler(analysis)).thenReturn(mockHandler);
when(mockHandler.getNumberOfConnectionsPerAnalysis()).thenReturn(5);
when(context.getConnection()).thenReturn(dataManager);
when(analysis.getContext()).thenReturn(context);
when(analysis.getResults()).thenReturn(result);
when(result.getResultMetadata()).thenReturn(resultMetadata);
connPool = new TdqAnalysisConnectionPool(analysis, 5);
}
use of org.talend.dataquality.analysis.AnalysisResult in project tdq-studio-se by Talend.
the class FrequencyStatisticsExplorerTest method testGetFreqRowsStatement_4.
/**
* Test method for {@link org.talend.dq.analysis.explore.FrequencyStatisticsExplorer#getFreqRowsStatement()} case_3:
* for UDIndicatorDefinition
*/
@Test
public void testGetFreqRowsStatement_4() {
// create database construction
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 indicator
UserDefIndicator userDefIndicator = IndicatorSqlFactory.eINSTANCE.createUserDefIndicator();
UDIndicatorDefinition indicatorDefinition = UserdefineFactory.eINSTANCE.createUDIndicatorDefinition();
// $NON-NLS-1$
indicatorDefinition.setName("user define count");
userDefIndicator.setName(indicatorDefinition.getName());
userDefIndicator.setIndicatorDefinition(indicatorDefinition);
TdExpression newTdExp = // $NON-NLS-1$
BooleanExpressionHelper.createTdExpression(// $NON-NLS-1$
"SQL", "SELECT * FROM <%=__TABLE_NAME__%> <%=__WHERE_CLAUSE__%>", // $NON-NLS-1$
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");
assertFalse(chartDataEntity.isLabelNull());
userDefIndicator.setAnalyzedElement(column);
IndicatorParameters indicatorParameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
indicatorParameters.setDateParameters(null);
userDefIndicator.setParameters(indicatorParameters);
assertNull(indicatorParameters.getDateParameters());
AnalysisResult createAnalysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
ExecutionInformations createExecutionInformations = AnalysisFactory.eINSTANCE.createExecutionInformations();
createAnalysisResult.setResultMetadata(createExecutionInformations);
createAnalysisResult.getIndicators().add(userDefIndicator);
userDefIndicator.setAnalyzedElement(column);
ana.setResults(createAnalysisResult);
freqExp = new FrequencyStatisticsExplorer();
freqExp.setAnalysis(ana);
freqExp.setEnitty(chartDataEntity);
String clause = freqExp.getFreqRowsStatement();
// $NON-NLS-1$
assertEquals("SELECT * FROM TDQ_CALENDAR ", clause);
}
use of org.talend.dataquality.analysis.AnalysisResult in project tdq-studio-se by Talend.
the class DependenciesHandlerTest method testSetUsageDependencyOnModelElementModelElementCase2.
/**
* Test method for
* {@link org.talend.cwm.dependencies.DependenciesHandler#setUsageDependencyOn(ModelElement, ModelElement)} . 、
* case2 supplier side is lost
*/
@Test
public void testSetUsageDependencyOnModelElementModelElementCase2() {
// analysis init
TDQAnalysisItem analysisItem = PropertiesFactoryImpl.eINSTANCE.createTDQAnalysisItem();
Analysis analysis = AnalysisFactory.eINSTANCE.createAnalysis();
// $NON-NLS-1$
analysis.setName("DependenciesHandlerTest.testSetUsageDependencyOnModelElementModelElementCase2Analysis");
analysisItem.setAnalysis(analysis);
Property propertyAna = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createProperty();
propertyAna.setId(EcoreUtil.generateUUID());
// $NON-NLS-1$
propertyAna.setLabel("DependenciesHandlerTest.testSetUsageDependencyOnModelElementModelElementCase2Analysis");
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.testSetUsageDependencyOnModelElementModelElementCase2UDI");
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.testSetUsageDependencyOnModelElementModelElementCase2UDI");
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();
}
Analysis analysisFromFile = AnalysisFactory.eINSTANCE.createAnalysis();
try {
analysis.eResource().unload();
IRepositoryViewObject lastVersion = ProxyRepositoryFactory.getInstance().getLastVersion(propertyAna.getId());
analysisFromFile = ((TDQAnalysisItem) lastVersion.getProperty().getItem()).getAnalysis();
} catch (PersistenceException e) {
Assert.fail(e.getMessage());
}
// call the test method
TypedReturnCode<Dependency> setUsageDependencyOn = DependenciesHandler.getInstance().setUsageDependencyOn(analysisFromFile, createIndicatorDefinition);
// $NON-NLS-1$
Assert.assertEquals("call setUsageDependencyOn method should return ok stauts", true, setUsageDependencyOn.isOk());
Assert.assertEquals(analysisFromFile, 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());
}
Aggregations