use of org.talend.dataquality.analysis.AnalysisParameters 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.AnalysisParameters in project tdq-studio-se by Talend.
the class UnitTestBuildHelper method createAndInitAnalysis.
public static Analysis createAndInitAnalysis() {
Analysis ana = UnitTestBuildHelper.createRealAnalysis("anaA", null, false);
AnalysisParameters parameters = AnalysisFactory.eINSTANCE.createAnalysisParameters();
parameters.setExecutionLanguage(ExecutionLanguage.SQL);
ana.setParameters(parameters);
AnalysisContext context = AnalysisFactory.eINSTANCE.createAnalysisContext();
ana.setContext(context);
Connection createConnection = ConnectionFactory.eINSTANCE.createConnection();
createConnection.setName("MySQL");
context.setConnection(createConnection);
return ana;
}
use of org.talend.dataquality.analysis.AnalysisParameters in project tdq-studio-se by Talend.
the class AnalysisHandleTest method testUpdate.
/**
* Test method for
* {@link org.talend.dataprofiler.core.ui.action.actions.handle.AnalysisDuplicateHandle#update(orgomg.cwm.objectmodel.core.ModelElement, orgomg.cwm.objectmodel.core.ModelElement)}
* .
*/
@Test
public void testUpdate() {
// $NON-NLS-1$
Analysis newAnalysis = AnalysisHelper.createAnalysis("new ana");
AnalysisParameters parameters = AnalysisFactory.eINSTANCE.createAnalysisParameters();
newAnalysis.setParameters(parameters);
// make the new analysis use the old domain
EList<Domain> oldDataFilters = oldAnalysis.getParameters().getDataFilter();
assertEquals(2, oldDataFilters.size());
EList<Domain> newFilter = parameters.getDataFilter();
for (Domain domain : oldDataFilters) {
newFilter.add(domain);
}
ModelElement copiedAna = handle.update(oldAnalysis, newAnalysis);
EList<Domain> newDataFilters = ((Analysis) copiedAna).getParameters().getDataFilter();
assertEquals(2, newDataFilters.size());
// after update, the old domain should be replaced by a new one, but with same body& language
for (int i = 0; i < newDataFilters.size(); i++) {
Domain domain = newDataFilters.get(i);
Domain oldDomain = oldDataFilters.get(i);
Assert.assertNotSame(oldDomain, domain);
// $NON-NLS-1$
assertTrue(domain.getName().equals("Analysis Data Filter"));
// the expressions are different instances, with same boby&language.
if (domain.getRanges() != null && oldDomain.getRanges() != null) {
Expression ex = domain.getRanges().get(0).getExpressions().getExpression();
Expression oldex = oldDomain.getRanges().get(0).getExpressions().getExpression();
Assert.assertNotSame(oldex, ex);
assertTrue(ex.getBody().equals(oldex.getBody()));
assertTrue(ex.getLanguage().equals(oldex.getLanguage()));
}
}
// check the patterns
String tablePattern = DomainHelper.getTablePattern(newDataFilters);
assertEquals(TABLE_PATTERN_FILTER, tablePattern);
String viewPattern = DomainHelper.getViewPattern(newDataFilters);
assertEquals(VIEW_PATTERN_FILTER, viewPattern);
}
use of org.talend.dataquality.analysis.AnalysisParameters in project tdq-studio-se by Talend.
the class AnalysisHandleTest method setUp.
/**
* DOC yyin Comment method "setUp".
*
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
// init the analysis
// $NON-NLS-1$
oldAnalysis = AnalysisHelper.createAnalysis("Analysis Data Filter");
AnalysisParameters parameters = AnalysisFactory.eINSTANCE.createAnalysisParameters();
oldAnalysis.setParameters(parameters);
// add two filters which type is ranges
// $NON-NLS-1$
AnalysisHelper.setStringDataFilter(oldAnalysis, "filter1", 0);
// $NON-NLS-1$
AnalysisHelper.setStringDataFilter(oldAnalysis, "filter2", 1);
// add one filter which type is pattern and contains two patterns
EList<Domain> dataFilters = oldAnalysis.getParameters().getDataFilter();
RegularExpression tablePattern = BooleanExpressionHelper.createRegularExpression(null, TABLE_PATTERN_FILTER);
// $NON-NLS-1$
addPatternToDomain(dataFilters.get(0), tablePattern, "Table Pattern");
RegularExpression viewPattern = BooleanExpressionHelper.createRegularExpression(null, VIEW_PATTERN_FILTER);
// $NON-NLS-1$
addPatternToDomain(dataFilters.get(0), viewPattern, "View Pattern");
// create a handle
IRepositoryNode node = mock(IRepositoryNode.class);
IRepositoryViewObject object = mock(IRepositoryViewObject.class);
when(node.getObject()).thenReturn(object);
Property pro = mock(Property.class);
when(object.getProperty()).thenReturn(pro);
IPath itemPath = mock(IPath.class);
PowerMockito.mockStatic(WorkbenchUtils.class);
when(WorkbenchUtils.getFilePath(node)).thenReturn(itemPath);
PowerMockito.mockStatic(ResourceManager.class);
IWorkspaceRoot root = mock(IWorkspaceRoot.class);
when(ResourceManager.getRoot()).thenReturn(root);
when(root.getFile(itemPath)).thenReturn(null);
PowerMockito.mockStatic(RepositoryNodeHelper.class);
when(RepositoryNodeHelper.getModelElementFromRepositoryNode(node)).thenReturn(oldAnalysis);
handle = new AnalysisDuplicateHandle();
}
use of org.talend.dataquality.analysis.AnalysisParameters in project tdq-studio-se by Talend.
the class AbstractCommonActionProviderTest method createAnalysisNode.
private RepositoryNode createAnalysisNode(String name, IFolder folder, boolean isDelete) {
IPath createPath = Path.EMPTY;
if (folder != null) {
createPath = new Path(folder.getFullPath().lastSegment());
}
// connection
Analysis createAnalysis = AnalysisFactory.eINSTANCE.createAnalysis();
createAnalysis.setName(name);
// ~connection
TDQAnalysisItem createAnalysisItem = org.talend.dataquality.properties.PropertiesFactory.eINSTANCE.createTDQAnalysisItem();
org.talend.core.model.properties.Property createAnaProperty = PropertiesFactory.eINSTANCE.createProperty();
createAnaProperty.setId(EcoreUtil.generateUUID());
createAnaProperty.setItem(createAnalysisItem);
createAnaProperty.setLabel(createAnalysis.getName());
createAnalysisItem.setProperty(createAnaProperty);
createAnalysisItem.setAnalysis(createAnalysis);
ItemState createItemState = PropertiesFactory.eINSTANCE.createItemState();
createItemState.setDeleted(isDelete);
createAnalysisItem.setState(createItemState);
// Indicator
CountsIndicator createCountsIndicator = IndicatorsFactory.eINSTANCE.createCountsIndicator();
List<IRepositoryViewObject> all = null;
IndicatorDefinition createIndicatorDefinition = null;
try {
all = factory.getAll(ERepositoryObjectType.TDQ_SYSTEM_INDICATORS);
for (IRepositoryViewObject indicatorViewObject : all) {
if (indicatorViewObject.getLabel().equalsIgnoreCase("ROW COUNT")) {
// $NON-NLS-1$
createIndicatorDefinition = (IndicatorDefinition) PropertyHelper.getModelElement(indicatorViewObject.getProperty());
break;
}
}
} catch (PersistenceException e1) {
e1.printStackTrace();
Assert.fail(e1.getMessage());
}
createCountsIndicator.setIndicatorDefinition(createIndicatorDefinition);
AnalysisParameters createAnalysisParameters = AnalysisFactory.eINSTANCE.createAnalysisParameters();
AnalysisContext createAnalysisContext = AnalysisFactory.eINSTANCE.createAnalysisContext();
createAnalysis.setContext(createAnalysisContext);
AnalysisResult createAnalysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
ExecutionInformations createExecutionInformations = AnalysisFactory.eINSTANCE.createExecutionInformations();
createAnalysisResult.setResultMetadata(createExecutionInformations);
createAnalysisResult.getIndicators().add(createCountsIndicator);
createAnalysis.setResults(createAnalysisResult);
createAnalysis.setParameters(createAnalysisParameters);
IRepositoryViewObject repViewObject = null;
try {
factory.create(createAnalysisItem, createPath, false);
repViewObject = factory.getLastVersion(createAnaProperty.getId());
} catch (PersistenceException e) {
Assert.fail(e.getMessage());
}
RepositoryNode anaRepNode = new AnalysisRepNode(repViewObject, null, ENodeType.TDQ_REPOSITORY_ELEMENT, null);
// set the contentType for anaRepNode from its parentNode
setParentNode(anaRepNode, ERepositoryObjectType.TDQ_ANALYSIS_ELEMENT);
// ~
return anaRepNode;
}
Aggregations