use of org.talend.dataquality.analysis.Analysis in project tdq-studio-se by Talend.
the class AnalysisExecutorHelperTest method testCheckPatternWithOutDependencyFilesAndBuiltIn.
@Test
public void testCheckPatternWithOutDependencyFilesAndBuiltIn() {
// Load analysis item/property model from test file.
// $NON-NLS-1$
String anaPropertyFile = "/data/builtin/pattern_without_dep_builtin/TDQ_Data_Profiling/Analyses/patternMatchAna_0.1.properties";
Resource anaPropertyResource = getPlatformResource(anaPropertyFile);
Analysis ana = null;
Property anaProperty = null;
while (anaPropertyResource.getAllContents().hasNext()) {
EObject eobj = anaPropertyResource.getAllContents().next();
if (eobj instanceof Property) {
anaProperty = (Property) eobj;
ana = ((TDQAnalysisItem) anaProperty.getItem()).getAnalysis();
break;
}
}
if (ana == null) {
Assert.fail("The analysis is null!");
}
if (ana.getResults() == null) {
Assert.fail("The result of analysis is null!");
}
if (ana.getResults().getIndicators() == null) {
Assert.fail("The indicators of analysis is null!");
}
assertTrue(ana.getResults().getIndicators().get(0).getParameters().getDataValidDomain().getPatterns().get(0).getName() == null);
ReturnCode rc = AnalysisExecutorHelper.check(ana);
assertFalse(rc.isOk());
assertTrue(ana.getResults().getIndicators().get(0).getParameters().getDataValidDomain().getPatterns().get(0).getName() == null);
}
use of org.talend.dataquality.analysis.Analysis in project tdq-studio-se by Talend.
the class AnalysisExecutorHelperTest method testCheckPatternDependencyFiles.
@Test
public void testCheckPatternDependencyFiles() {
// Load analysis item/property model from test file.
// $NON-NLS-1$
String anaPropertyFile = "/data/builtin/pattern_with_dep/TDQ_Data_Profiling/Analyses/patternMatchAna_0.1.properties";
Resource anaPropertyResource = getPlatformResource(anaPropertyFile);
Analysis ana = null;
Property anaProperty = null;
while (anaPropertyResource.getAllContents().hasNext()) {
EObject eobj = anaPropertyResource.getAllContents().next();
if (eobj instanceof Property) {
anaProperty = (Property) eobj;
ana = ((TDQAnalysisItem) anaProperty.getItem()).getAnalysis();
break;
}
}
if (ana == null) {
Assert.fail("The analysis is null!");
}
if (ana.getResults() == null) {
Assert.fail("The result of analysis is null!");
}
if (ana.getResults().getIndicators() == null) {
Assert.fail("The indicators of analysis is null!");
}
assertTrue(ana.getResults().getIndicators().get(0).getParameters().getDataValidDomain().getBuiltInPatterns().size() == 0);
ReturnCode rc = AnalysisExecutorHelper.check(ana);
assertTrue(rc.isOk());
assertTrue(ana.getResults().getIndicators().get(0).getParameters().getDataValidDomain().getBuiltInPatterns().size() > 0);
ana.getResults().getIndicators().get(0).getParameters().getDataValidDomain().getBuiltInPatterns().clear();
EMFUtil.saveResource(ana.eResource());
}
use of org.talend.dataquality.analysis.Analysis 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));
}
use of org.talend.dataquality.analysis.Analysis 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"));
}
use of org.talend.dataquality.analysis.Analysis in project tdq-studio-se by Talend.
the class AnalysisWriter method save.
/**
* Save analysis item and update the dependencies(optional). <B>To update dependencies of the analysis the
* #careDependency must be set as TRUE.</B>
*
* @see org.talend.dq.writer.AElementPersistance#save(org.talend.core.model.properties.Item, boolean[])
*/
@Override
public ReturnCode save(final Item item, final boolean careDependency) {
ReturnCode rc = new ReturnCode();
RepositoryWorkUnit<Object> repositoryWorkUnit = new // $NON-NLS-1$
RepositoryWorkUnit<Object>(// $NON-NLS-1$
"save Analysis item") {
@Override
protected void run() throws LoginException, PersistenceException {
// MOD yyi 2012-02-07 TDQ-4621:Update dependencies(connection) when careDependency is true.
TDQAnalysisItem anaItem = (TDQAnalysisItem) item;
Analysis analysis = anaItem.getAnalysis();
if (careDependency) {
saveWithDependencies(anaItem, analysis);
} else {
saveWithoutDependencies(anaItem, analysis);
}
}
};
repositoryWorkUnit.setAvoidUnloadResources(true);
ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(repositoryWorkUnit);
try {
repositoryWorkUnit.throwPersistenceExceptionIfAny();
} catch (PersistenceException e) {
log.error(e, e);
rc.setOk(Boolean.FALSE);
rc.setMessage(e.getMessage());
}
return rc;
}
Aggregations