use of org.talend.dataquality.analysis.AnalysisContext 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.AnalysisContext in project tdq-studio-se by Talend.
the class PatternExplorerRealTest method setUp.
/**
* DOC zshen Comment method "setUp".
*
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
patternExplorer = new RegexPatternExplorer();
// mock setEntity
PatternMatchingIndicator indicator = IndicatorsFactoryImpl.eINSTANCE.createRegexpMatchingIndicator();
// create pattern parameter
IndicatorParameters createIndicatorParameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
indicator.setParameters(createIndicatorParameters);
Domain createDomain = DomainFactoryImpl.eINSTANCE.createDomain();
createIndicatorParameters.setDataValidDomain(createDomain);
Pattern createPattern = PatternFactoryImpl.eINSTANCE.createPattern();
createDomain.getPatterns().add(createPattern);
RegularExpression createPatternComponent = PatternFactoryImpl.eINSTANCE.createRegularExpression();
createPattern.getComponents().add(createPatternComponent);
TdExpression createTdExpression = RelationalFactoryImpl.eINSTANCE.createTdExpression();
createPatternComponent.setExpression(createTdExpression);
createTdExpression.setLanguage(SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
// $NON-NLS-1$
createTdExpression.setBody("`su.*`");
ModelElement element = RelationalFactoryImpl.eINSTANCE.createTdColumn();
// $NON-NLS-1$
element.setName("lname");
indicator.setAnalyzedElement(element);
Expression createIndiExpression = CoreFactoryImpl.eINSTANCE.createExpression();
createIndiExpression.setLanguage(SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
// $NON-NLS-1$
createIndiExpression.setBody("SELECT * FROM `tbi`.`customer` WHERE (customer.lname = \"sunny\")");
indicator.setInstantiatedExpression(createIndiExpression);
Analysis analysis = AnalysisFactoryImpl.eINSTANCE.createAnalysis();
AnalysisContext createAnalysisContext = AnalysisFactoryImpl.eINSTANCE.createAnalysisContext();
analysis.setContext(createAnalysisContext);
DatabaseConnection createDatabaseConnection = ConnectionFactoryImpl.eINSTANCE.createDatabaseConnection();
TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_PRODUCT_NAME, SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
// $NON-NLS-1$
TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_PRODUCT_VERSION, "1.0");
// $NON-NLS-1$
TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_IDENTIFIER_QUOTE_STRING, "`");
createAnalysisContext.setConnection(createDatabaseConnection);
patternExplorer.setAnalysis(analysis);
ChartDataEntity cdEntity = new ChartDataEntity();
cdEntity.setIndicator(indicator);
patternExplorer.setEnitty(cdEntity);
}
use of org.talend.dataquality.analysis.AnalysisContext in project tdq-studio-se by Talend.
the class PatternExplorerRealTest method testGetValidValuesStatement_2.
/**
* Test method for {@link org.talend.dq.analysis.explore.PatternExplorer#getValidValuesStatement()}. when the test
* for indicator is user define indicator
*/
@Test
public void testGetValidValuesStatement_2() {
patternExplorer = new RegexPatternExplorer();
// mock setEntity
PatternMatchingIndicator indicator = IndicatorsFactoryImpl.eINSTANCE.createRegexpMatchingIndicator();
UDIndicatorDefinition indicatorDef = UserdefineFactoryImpl.eINSTANCE.createUDIndicatorDefinition();
indicator.setIndicatorDefinition(indicatorDef);
TdExpression udiTdExpression = RelationalFactoryImpl.eINSTANCE.createTdExpression();
udiTdExpression.setLanguage(SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
udiTdExpression.setBody(ViewValidValues);
indicatorDef.getViewValidValuesExpression().add(udiTdExpression);
// create pattern parameter
IndicatorParameters createIndicatorParameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
indicator.setParameters(createIndicatorParameters);
Domain createDomain = DomainFactoryImpl.eINSTANCE.createDomain();
createIndicatorParameters.setDataValidDomain(createDomain);
Pattern createPattern = PatternFactoryImpl.eINSTANCE.createPattern();
createDomain.getPatterns().add(createPattern);
RegularExpression createPatternComponent = PatternFactoryImpl.eINSTANCE.createRegularExpression();
createPattern.getComponents().add(createPatternComponent);
TdExpression createTdExpression = RelationalFactoryImpl.eINSTANCE.createTdExpression();
createPatternComponent.setExpression(createTdExpression);
createTdExpression.setLanguage(SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
// $NON-NLS-1$
createTdExpression.setBody("`su.*`");
TdColumn element = RelationalFactoryImpl.eINSTANCE.createTdColumn();
// $NON-NLS-1$
element.setName("lname");
TdTable createTdTable = RelationalFactoryImpl.eINSTANCE.createTdTable();
// $NON-NLS-1$
createTdTable.setName("table1");
TableHelper.addColumn(createTdTable, element);
Catalog createCatalog = orgomg.cwm.resource.relational.impl.RelationalFactoryImpl.eINSTANCE.createCatalog();
// $NON-NLS-1$
createCatalog.setName("catalog1");
List<TdTable> tableList = new ArrayList<TdTable>();
tableList.add(createTdTable);
CatalogHelper.addTables(tableList, createCatalog);
indicator.setAnalyzedElement(element);
Expression createIndiExpression = CoreFactoryImpl.eINSTANCE.createExpression();
createIndiExpression.setLanguage(SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
// $NON-NLS-1$
createIndiExpression.setBody("SELECT * FROM `tbi`.`customer` WHERE (customer.lname = \"sunny\")");
indicator.setInstantiatedExpression(createIndiExpression);
Analysis analysis = AnalysisFactoryImpl.eINSTANCE.createAnalysis();
AnalysisContext createAnalysisContext = AnalysisFactoryImpl.eINSTANCE.createAnalysisContext();
analysis.setContext(createAnalysisContext);
DatabaseConnection createDatabaseConnection = ConnectionFactoryImpl.eINSTANCE.createDatabaseConnection();
TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_PRODUCT_NAME, SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
// $NON-NLS-1$
TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_PRODUCT_VERSION, "1.0");
// $NON-NLS-1$
TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_IDENTIFIER_QUOTE_STRING, "`");
createAnalysisContext.setConnection(createDatabaseConnection);
patternExplorer.setAnalysis(analysis);
ChartDataEntity cdEntity = new ChartDataEntity();
cdEntity.setIndicator(indicator);
patternExplorer.setEnitty(cdEntity);
Assert.assertTrue(patternExplorer.setAnalysis(analysis));
String clause = patternExplorer.getValidValuesStatement();
// $NON-NLS-1$
assertEquals("SELECT `lname` FROM `catalog1`.`table1` ", clause);
}
use of org.talend.dataquality.analysis.AnalysisContext in project tdq-studio-se by Talend.
the class PatternExplorerRealTest method testGetInvalidRowsStatement_4.
/**
* Test method for {@link org.talend.dq.analysis.explore.PatternExplorer#getInvalidRowsStatement()}. when the test
* for indicator is user define indicator
*/
@Test
public void testGetInvalidRowsStatement_4() {
patternExplorer = new RegexPatternExplorer();
// mock setEntity
PatternMatchingIndicator indicator = IndicatorsFactoryImpl.eINSTANCE.createRegexpMatchingIndicator();
UDIndicatorDefinition indicatorDef = UserdefineFactoryImpl.eINSTANCE.createUDIndicatorDefinition();
indicator.setIndicatorDefinition(indicatorDef);
TdExpression udiTdExpression = RelationalFactoryImpl.eINSTANCE.createTdExpression();
udiTdExpression.setLanguage(SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
udiTdExpression.setBody(ViewInvalidRows);
indicatorDef.getViewInvalidRowsExpression().add(udiTdExpression);
// create pattern parameter
IndicatorParameters createIndicatorParameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
indicator.setParameters(createIndicatorParameters);
Domain createDomain = DomainFactoryImpl.eINSTANCE.createDomain();
createIndicatorParameters.setDataValidDomain(createDomain);
Pattern createPattern = PatternFactoryImpl.eINSTANCE.createPattern();
createDomain.getPatterns().add(createPattern);
RegularExpression createPatternComponent = PatternFactoryImpl.eINSTANCE.createRegularExpression();
createPattern.getComponents().add(createPatternComponent);
TdExpression createTdExpression = RelationalFactoryImpl.eINSTANCE.createTdExpression();
createPatternComponent.setExpression(createTdExpression);
createTdExpression.setLanguage(SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
// $NON-NLS-1$
createTdExpression.setBody("`su.*`");
TdColumn element = RelationalFactoryImpl.eINSTANCE.createTdColumn();
// $NON-NLS-1$
element.setName("lname");
TdTable createTdTable = RelationalFactoryImpl.eINSTANCE.createTdTable();
// $NON-NLS-1$
createTdTable.setName("table1");
TableHelper.addColumn(createTdTable, element);
Catalog createCatalog = orgomg.cwm.resource.relational.impl.RelationalFactoryImpl.eINSTANCE.createCatalog();
// $NON-NLS-1$
createCatalog.setName("catalog1");
List<TdTable> tableList = new ArrayList<TdTable>();
tableList.add(createTdTable);
CatalogHelper.addTables(tableList, createCatalog);
indicator.setAnalyzedElement(element);
Expression createIndiExpression = CoreFactoryImpl.eINSTANCE.createExpression();
createIndiExpression.setLanguage(SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
// $NON-NLS-1$
createIndiExpression.setBody("SELECT * FROM `tbi`.`customer` WHERE (customer.lname = \"sunny\")");
indicator.setInstantiatedExpression(createIndiExpression);
Analysis analysis = AnalysisFactoryImpl.eINSTANCE.createAnalysis();
AnalysisContext createAnalysisContext = AnalysisFactoryImpl.eINSTANCE.createAnalysisContext();
analysis.setContext(createAnalysisContext);
DatabaseConnection createDatabaseConnection = ConnectionFactoryImpl.eINSTANCE.createDatabaseConnection();
TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_PRODUCT_NAME, SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
// $NON-NLS-1$
TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_PRODUCT_VERSION, "1.0");
// $NON-NLS-1$
TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_IDENTIFIER_QUOTE_STRING, "`");
createAnalysisContext.setConnection(createDatabaseConnection);
ChartDataEntity cdEntity = new ChartDataEntity();
cdEntity.setIndicator(indicator);
Assert.assertTrue(patternExplorer.setAnalysis(analysis));
patternExplorer.setEnitty(cdEntity);
String clause = patternExplorer.getInvalidRowsStatement();
// $NON-NLS-1$
assertEquals("SELECT * FROM `catalog1`.`table1` WHERE NOT (id>=1) ", clause);
}
use of org.talend.dataquality.analysis.AnalysisContext 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));
}
Aggregations