use of org.talend.dataquality.analysis.AnalysisContext in project tdq-studio-se by Talend.
the class DelimitedFileIndicatorEvaluatorTest method testExecuteSqlQuery_delimetd.
@Ignore
@Test
public void testExecuteSqlQuery_delimetd() throws Exception {
// $NON-NLS-1$
String empty = "";
Analysis analysis = mock(Analysis.class);
DelimitedFileIndicatorEvaluator delFileIndiEvaluator = new DelimitedFileIndicatorEvaluator(analysis);
DelimitedFileIndicatorEvaluator spyEvaluator = Mockito.spy(delFileIndiEvaluator);
// $NON-NLS-1$
stub(method(DelimitedFileIndicatorEvaluator.class, "handleByARow"));
// $NON-NLS-1$
stub(method(DelimitedFileIndicatorEvaluator.class, "addResultToIndicatorToRowMap", Indicator.class, EMap.class));
AnalysisContext context = mock(AnalysisContext.class);
when(analysis.getContext()).thenReturn(context);
DelimitedFileConnection deliFileConn = mock(DelimitedFileConnection.class);
when(context.getConnection()).thenReturn(deliFileConn);
when(deliFileConn.isContextMode()).thenReturn(false);
// $NON-NLS-1$
String path = "test.txt";
PowerMockito.mockStatic(JavaSqlFactory.class);
when(JavaSqlFactory.getURL(deliFileConn)).thenReturn(path);
IPath iPath = mock(IPath.class);
File file = new File(path);
BufferedWriter output = new BufferedWriter(new FileWriter(file));
String str = // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
"id;Cocust(Tests);owner_id\n" + "1;yellow;3301\n" + "2;blue;3302\n" + " 4;red;3307\n" + "5;white;4563\n" + "6;pink2;457883\n" + // $NON-NLS-1$ //$NON-NLS-2$
"7;blank;231233\n";
output.write(str);
output.close();
when(iPath.toFile()).thenReturn(file);
// $NON-NLS-1$
when(deliFileConn.getFieldSeparatorValue()).thenReturn(";");
// $NON-NLS-1$
when(deliFileConn.getEncoding()).thenReturn("US-ASCII");
AnalysisResult results = mock(AnalysisResult.class);
when(analysis.getResults()).thenReturn(results);
EMap<Indicator, AnalyzedDataSet> indicToRowMap = mock(EMap.class);
when(results.getIndicToRowMap()).thenReturn(indicToRowMap);
List<ModelElement> columnElementList = new BasicEList<ModelElement>();
List<MetadataColumn> columnElementList2 = new BasicEList<MetadataColumn>();
MetadataColumn mc0 = mock(MetadataColumn.class);
MetadataColumn mc1 = mock(MetadataColumn.class);
MetadataColumn mc2 = mock(MetadataColumn.class);
columnElementList.add(mc0);
columnElementList.add(mc1);
columnElementList.add(mc2);
columnElementList2.add(mc0);
columnElementList2.add(mc1);
columnElementList2.add(mc2);
EList<ModelElement> eLs = (EList<ModelElement>) columnElementList;
when(context.getAnalysedElements()).thenReturn(eLs);
PowerMockito.mockStatic(ColumnHelper.class);
MetadataTable mTable = mock(MetadataTable.class);
when(mTable.getColumns()).thenReturn((EList<MetadataColumn>) columnElementList2);
when(ColumnHelper.getColumnOwnerAsMetadataTable(mc0)).thenReturn(mTable);
when(ColumnHelper.getColumnOwnerAsMetadataTable(mc1)).thenReturn(mTable);
when(deliFileConn.getHeaderValue()).thenReturn(empty);
when(deliFileConn.getFooterValue()).thenReturn(empty);
when(deliFileConn.getLimitValue()).thenReturn(empty);
when(deliFileConn.getEscapeType()).thenReturn(Escape.DELIMITED);
// $NON-NLS-1$
when(deliFileConn.getRowSeparatorValue()).thenReturn("\\n");
when(deliFileConn.isRemoveEmptyRow()).thenReturn(false);
when(deliFileConn.isSplitRecord()).thenReturn(false);
PowerMockito.mockStatic(LanguageManager.class);
when(LanguageManager.getCurrentLanguage()).thenReturn(ECodeLanguage.JAVA);
Mockito.doReturn(true).when(spyEvaluator).continueRun();
spyEvaluator.executeSqlQuery(empty);
}
use of org.talend.dataquality.analysis.AnalysisContext in project tdq-studio-se by Talend.
the class WorkbenchUtilsTest method testUpdateDependAnalysisOfDelimitedFile.
// test for 2 remained columns
@Test
public void testUpdateDependAnalysisOfDelimitedFile() throws IOException, URISyntaxException, PartInitException, BusinessException {
// create a file connection
DelimitedFileConnection fileConnection = ConnectionPackage.eINSTANCE.getConnectionFactory().createDelimitedFileConnection();
// $NON-NLS-1$
URL fileUrl = this.getClass().getResource("file1");
MetadataTable metadataTable = UnitTestBuildHelper.initFileConnection(fileUrl, fileConnection);
UnitTestBuildHelper.initColumns(metadataTable);
IFile file = WorkspaceUtils.fileToIFile(new File(FileLocator.toFileURL(fileUrl).toURI()));
IPath itemPath = file.getFullPath();
Property connectionProperty = PropertiesFactory.eINSTANCE.createProperty();
connectionProperty.setAuthor(((RepositoryContext) CoreRuntimePlugin.getInstance().getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
connectionProperty.setVersion(VersionUtils.DEFAULT_VERSION);
// $NON-NLS-1$
connectionProperty.setStatusCode("");
connectionProperty.setLabel("file1");
DelimitedFileConnectionItem connectionItem = PropertiesFactory.eINSTANCE.createDelimitedFileConnectionItem();
connectionItem.setProperty(connectionProperty);
connectionItem.setConnection(fileConnection);
try {
ProxyRepositoryFactory.getInstance().create(connectionItem, itemPath.removeFirstSegments(3).removeLastSegments(1));
} catch (PersistenceException e) {
Assert.fail(e.getMessage());
}
// create an analysis which use the columns in the file connection
Analysis analysis = UnitTestBuildHelper.createRealAnalysis("Ana01", null, false);
AnalysisContext context = AnalysisPackage.eINSTANCE.getAnalysisFactory().createAnalysisContext();
context.setConnection(fileConnection);
analysis.setContext(context);
context.getAnalysedElements().addAll(metadataTable.getColumns());
DependenciesHandler.getInstance().setDependencyOn(analysis, fileConnection);
ElementWriterFactory.getInstance().createAnalysisWrite().save(analysis);
// change the file's schema
List<MetadataColumn> tempNewColumns = new ArrayList<MetadataColumn>();
MetadataColumn name = ConnectionPackage.eINSTANCE.getConnectionFactory().createMetadataColumn();
name.setName("name");
name.setLabel("name");
tempNewColumns.add(name);
MetadataColumn country = ConnectionPackage.eINSTANCE.getConnectionFactory().createMetadataColumn();
country.setName("country");
country.setLabel("country");
tempNewColumns.add(country);
MetadataColumn country1 = ConnectionPackage.eINSTANCE.getConnectionFactory().createMetadataColumn();
country1.setName("country1");
country1.setLabel("country1");
tempNewColumns.add(country1);
MetadataColumn company = ConnectionPackage.eINSTANCE.getConnectionFactory().createMetadataColumn();
company.setName("new column");
company.setLabel("new column");
tempNewColumns.add(company);
metadataTable.getFeature().clear();
metadataTable.getFeature().addAll(tempNewColumns);
// before compare, the analysis has 5 analyzed elements
Assert.assertEquals(5, analysis.getContext().getAnalysedElements().size());
// call the tested method
WorkbenchUtils.reloadMetadataOfDelimitedFile(metadataTable);
List<MetadataColumn> afterCompareColumns = metadataTable.getColumns();
// check the columns
Assert.assertEquals(4, afterCompareColumns.size());
Assert.assertEquals("name", afterCompareColumns.get(0).getLabel());
Assert.assertEquals("country", afterCompareColumns.get(1).getLabel());
Assert.assertEquals("country1", afterCompareColumns.get(2).getLabel());
Assert.assertEquals("new column", afterCompareColumns.get(3).getLabel());
metadataTable.getColumns().clear();
metadataTable.getColumns().addAll(afterCompareColumns);
WorkbenchUtils.impactExistingAnalyses(fileConnection);
// check the depended analysis
EList<Dependency> clientDependencies = fileConnection.getSupplierDependency();
for (Dependency dep : clientDependencies) {
for (ModelElement mod : dep.getClient()) {
if (!(mod instanceof Analysis)) {
continue;
}
Analysis ana = (Analysis) mod;
// assert the column with same name still in the analysis
Assert.assertNotNull(ana.getContext().getAnalysedElements());
// should be: only 2 with same name remained
Assert.assertEquals(2, ana.getContext().getAnalysedElements().size());
Assert.assertEquals("name", ana.getContext().getAnalysedElements().get(0).getName());
Assert.assertEquals("country", ana.getContext().getAnalysedElements().get(1).getName());
}
}
}
use of org.talend.dataquality.analysis.AnalysisContext in project tdq-studio-se by Talend.
the class WorkbenchUtilsTest method testUpdateDependAnalysisOfDelimitedFile_2.
// test for last column remained
@Test
public void testUpdateDependAnalysisOfDelimitedFile_2() throws IOException, URISyntaxException, PartInitException, BusinessException {
// create a file connection
DelimitedFileConnection fileConnection = ConnectionPackage.eINSTANCE.getConnectionFactory().createDelimitedFileConnection();
// $NON-NLS-1$
URL fileUrl = this.getClass().getResource("file1");
MetadataTable metadataTable = UnitTestBuildHelper.initFileConnection(fileUrl, fileConnection);
UnitTestBuildHelper.initColumns(metadataTable);
IFile file = WorkspaceUtils.fileToIFile(new File(FileLocator.toFileURL(fileUrl).toURI()));
IPath itemPath = file.getFullPath();
Property connectionProperty = PropertiesFactory.eINSTANCE.createProperty();
connectionProperty.setAuthor(((RepositoryContext) CoreRuntimePlugin.getInstance().getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
connectionProperty.setVersion(VersionUtils.DEFAULT_VERSION);
// $NON-NLS-1$
connectionProperty.setStatusCode("");
connectionProperty.setLabel("file2");
DelimitedFileConnectionItem connectionItem = PropertiesFactory.eINSTANCE.createDelimitedFileConnectionItem();
connectionItem.setProperty(connectionProperty);
connectionItem.setConnection(fileConnection);
try {
ProxyRepositoryFactory.getInstance().create(connectionItem, itemPath.removeFirstSegments(3).removeLastSegments(1));
} catch (PersistenceException e) {
Assert.fail(e.getMessage());
}
// create an analysis which use the columns in the file connection
Analysis analysis = UnitTestBuildHelper.createRealAnalysis("Ana01", null, false);
AnalysisContext context = AnalysisPackage.eINSTANCE.getAnalysisFactory().createAnalysisContext();
context.setConnection(fileConnection);
analysis.setContext(context);
context.getAnalysedElements().addAll(metadataTable.getColumns());
DependenciesHandler.getInstance().setDependencyOn(analysis, fileConnection);
ElementWriterFactory.getInstance().createAnalysisWrite().save(analysis);
// change the file's schema
List<MetadataColumn> tempNewColumns = new ArrayList<MetadataColumn>();
MetadataColumn name = ConnectionPackage.eINSTANCE.getConnectionFactory().createMetadataColumn();
name.setName("name2");
name.setLabel("name2");
tempNewColumns.add(name);
MetadataColumn country = ConnectionPackage.eINSTANCE.getConnectionFactory().createMetadataColumn();
country.setName("country2");
country.setLabel("country2");
tempNewColumns.add(country);
MetadataColumn country1 = ConnectionPackage.eINSTANCE.getConnectionFactory().createMetadataColumn();
country1.setName("country1");
country1.setLabel("country1");
tempNewColumns.add(country1);
MetadataColumn company = ConnectionPackage.eINSTANCE.getConnectionFactory().createMetadataColumn();
company.setName("name");
company.setLabel("name");
tempNewColumns.add(company);
metadataTable.getFeature().clear();
metadataTable.getFeature().addAll(tempNewColumns);
// before compare, the analysis has 5 analyzed elements
Assert.assertEquals(5, analysis.getContext().getAnalysedElements().size());
// call the tested method
WorkbenchUtils.reloadMetadataOfDelimitedFile(metadataTable);
List<MetadataColumn> afterCompareColumns = metadataTable.getColumns();
// check the columns
Assert.assertEquals(4, afterCompareColumns.size());
Assert.assertEquals("name", afterCompareColumns.get(0).getLabel());
Assert.assertEquals("country2", afterCompareColumns.get(2).getLabel());
Assert.assertEquals("country1", afterCompareColumns.get(3).getLabel());
Assert.assertEquals("name2", afterCompareColumns.get(1).getLabel());
metadataTable.getColumns().clear();
metadataTable.getColumns().addAll(afterCompareColumns);
WorkbenchUtils.impactExistingAnalyses(fileConnection);
// check the depended analysis
EList<Dependency> clientDependencies = fileConnection.getSupplierDependency();
for (Dependency dep : clientDependencies) {
for (ModelElement mod : dep.getClient()) {
if (!(mod instanceof Analysis)) {
continue;
}
Analysis ana = (Analysis) mod;
// assert the column with same name still in the analysis
Assert.assertNotNull(ana.getContext().getAnalysedElements());
// should be: only 2 with same name remained
Assert.assertEquals(1, ana.getContext().getAnalysedElements().size());
Assert.assertEquals("name", ana.getContext().getAnalysedElements().get(0).getName());
}
}
}
use of org.talend.dataquality.analysis.AnalysisContext 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;
}
use of org.talend.dataquality.analysis.AnalysisContext in project tdq-studio-se by Talend.
the class ItemRecordTest method createAnalysis.
private Property createAnalysis(String name) throws PersistenceException {
// create analysis
Analysis createAnalysis = AnalysisFactory.eINSTANCE.createAnalysis();
AnalysisResult createAnalysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
AnalysisContext createAnalysisContext = AnalysisFactory.eINSTANCE.createAnalysisContext();
createAnalysis.setResults(createAnalysisResult);
createAnalysis.setContext(createAnalysisContext);
createAnalysis.setName(name);
// create analysis item
TDQAnalysisItem createTDQAnalysisItem = PropertiesFactory.eINSTANCE.createTDQAnalysisItem();
createTDQAnalysisItem.setAnalysis(createAnalysis);
Property createAnalysisProperty = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createProperty();
createAnalysisProperty.setLabel(name);
createTDQAnalysisItem.setProperty(createAnalysisProperty);
createAnalysisProperty.setId(EcoreUtil.generateUUID());
ProxyRepositoryFactory.getInstance().create(createTDQAnalysisItem, Path.EMPTY, false);
return createAnalysisProperty;
}
Aggregations