use of org.talend.dataquality.analysis.AnalysisResult in project tdq-studio-se by Talend.
the class ColumnSetIndicatorEvaluatorTest method testExecuteSqlQuery_file.
/**
* Test method for {@link org.talend.dq.indicators.ColumnSetIndicatorEvaluator#executeSqlQuery(String)} .
*/
@Test
public void testExecuteSqlQuery_file() throws Exception {
Analysis analysis = mock(Analysis.class);
// $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(true);
when(deliFileConn.getFilePath()).thenReturn(context_fd1_File);
when(deliFileConn.getFieldSeparatorValue()).thenReturn(context_fd1_FieldSeparator);
when(deliFileConn.getEncoding()).thenReturn(context_fd1_Encoding);
IPath iPath = mock(IPath.class);
File file = new File(realFile);
BufferedWriter output = new BufferedWriter(new FileWriter(file));
String str = "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" + "7;blank;231233\n";
output.write(str);
output.close();
when(iPath.toFile()).thenReturn(file);
assertTrue(file.exists());
PowerMockito.mockStatic(JavaSqlFactory.class);
when(JavaSqlFactory.getURL(deliFileConn)).thenReturn(realFile);
when(JavaSqlFactory.getFieldSeparatorValue(deliFileConn)).thenReturn(realFieldSeparator);
when(JavaSqlFactory.getEncoding(deliFileConn)).thenReturn(realEncoding);
PowerMockito.mockStatic(ResourceBundle.class);
ResourceBundle bundle = mock(ResourceBundle.class);
// $NON-NLS-1$
when(ResourceBundle.getBundle("Messages")).thenReturn(bundle);
PowerMockito.mockStatic(Messages.class);
// $NON-NLS-1$
when(Messages.getString(anyString())).thenReturn("testString");
AnalysisResult results = mock(AnalysisResult.class);
when(analysis.getResults()).thenReturn(results);
EMap<Indicator, AnalyzedDataSet> indicToRowMap = mock(EMap.class);
when(results.getIndicToRowMap()).thenReturn(indicToRowMap);
when(deliFileConn.getHeaderValue()).thenReturn(context_fd1_Header);
when(deliFileConn.getFooterValue()).thenReturn(zero);
when(deliFileConn.getLimitValue()).thenReturn(zero);
when(deliFileConn.getEscapeType()).thenReturn(Escape.DELIMITED);
when(deliFileConn.getRowSeparatorValue()).thenReturn(context_fd1_RowSeparator);
when(deliFileConn.isSplitRecord()).thenReturn(false);
when(deliFileConn.isRemoveEmptyRow()).thenReturn(false);
when(JavaSqlFactory.getHeadValue(deliFileConn)).thenReturn(realHeading);
when(JavaSqlFactory.getRowSeparatorValue(deliFileConn)).thenReturn(realRowSeparator);
PowerMockito.mockStatic(LanguageManager.class);
when(LanguageManager.getCurrentLanguage()).thenReturn(ECodeLanguage.JAVA);
PowerMockito.mockStatic(ParameterUtil.class);
when(ParameterUtil.trimParameter(realFile)).thenReturn(realFile);
when(ParameterUtil.trimParameter(realEncoding)).thenReturn(realEncoding);
PowerMockito.mockStatic(StringUtils.class);
when(StringUtils.loadConvert(realFieldSeparator, ECodeLanguage.JAVA.getName())).thenReturn(realFieldSeparator);
when(ParameterUtil.trimParameter(realFieldSeparator)).thenReturn(realFieldSeparator);
when(StringUtils.loadConvert(realRowSeparator, ECodeLanguage.JAVA.getName())).thenReturn(realRowSeparator);
when(ParameterUtil.trimParameter(realRowSeparator)).thenReturn(realRowSeparator);
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(ColumnHelper.getColumnOwnerAsMetadataTable(mc2)).thenReturn(mTable);
ColumnSetIndicatorEvaluator evaluator = new ColumnSetIndicatorEvaluator(analysis);
ColumnSetIndicatorEvaluator spyEvaluator = Mockito.spy(evaluator);
Mockito.doReturn(true).when(spyEvaluator).continueRun();
ReturnCode rc = spyEvaluator.executeSqlQuery(empty);
assertTrue(rc.isOk());
}
use of org.talend.dataquality.analysis.AnalysisResult 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.AnalysisResult in project tdq-studio-se by Talend.
the class UnitTestBuildHelper method createRealAnalysis.
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 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.AnalysisResult in project tdq-studio-se by Talend.
the class ItemRecordTest method testLoadProperty.
/**
* Test method for {@link org.talend.dataprofiler.core.ui.imex.model.ItemRecord#loadProperty()}.
*
* @throws PersistenceException
*/
@Test
public void testLoadProperty() throws PersistenceException {
chooseRightProject();
// $NON-NLS-1$
Property analysisProperty = createAnalysis("ItemRecordTestanalysis1");
TDQAnalysisItem item = (TDQAnalysisItem) analysisProperty.getItem();
Analysis analysis = item.getAnalysis();
AnalysisResult createAnalysisResult = analysis.getResults();
Assert.assertEquals(0, createAnalysisResult.getIndicators().size());
// create Indicator
RowCountIndicator rowCountIndicator = IndicatorsFactory.eINSTANCE.createRowCountIndicator();
String rowCountPropertyID = EcoreUtil.generateUUID();
// $NON-NLS-1$
saveIndicatorDefintion(rowCountPropertyID, "ItemRecordWithRefreshedTestIndicatorDefinition1");
rowCountIndicator.setIndicatorDefinition(((TDQIndicatorDefinitionItem) ProxyRepositoryFactory.getInstance().getLastVersion(rowCountPropertyID).getProperty().getItem()).getIndicatorDefinition());
// $NON-NLS-1$
Assert.assertNotNull("Row count indicator definition should not be null", rowCountIndicator.getIndicatorDefinition());
Assert.assertEquals("ItemRecordWithRefreshedTestIndicatorDefinition1", // $NON-NLS-1$
rowCountIndicator.getIndicatorDefinition().getLabel());
createAnalysisResult.getIndicators().add(rowCountIndicator);
Assert.assertEquals(1, createAnalysisResult.getIndicators().size());
ReturnCode saveAnalysis = saveAnalysis(analysis);
Assert.assertEquals(1, ((TDQAnalysisItem) analysisProperty.getItem()).getAnalysis().getResults().getIndicators().size());
// $NON-NLS-1$
Assert.assertTrue("The analysis first time saving is not work", saveAnalysis.isOk());
File analysisFile = WorkspaceUtils.ifileToFile(PropertyHelper.getItemFile(analysisProperty));
ItemRecord itemRecord = new ItemRecord(analysisFile);
Assert.assertEquals(1, itemRecord.getDependencySet().size());
// create Indicator
NullCountIndicator nullCountIndicator = IndicatorsFactory.eINSTANCE.createNullCountIndicator();
String nullCountPropertyID = EcoreUtil.generateUUID();
// $NON-NLS-1$
saveIndicatorDefintion(nullCountPropertyID, "ItemRecordWithRefreshedTestIndicatorDefinition2");
nullCountIndicator.setIndicatorDefinition(((TDQIndicatorDefinitionItem) ProxyRepositoryFactory.getInstance().getLastVersion(nullCountPropertyID).getProperty().getItem()).getIndicatorDefinition());
analysis = item.getAnalysis();
analysis.getResults().getIndicators().add(nullCountIndicator);
ReturnCode saveAnalysis2 = saveAnalysis(analysis);
// $NON-NLS-1$
Assert.assertTrue("The analysis second time saving is not work", saveAnalysis2.isOk());
// get last resource so that the dependecy will not changed
itemRecord = new ItemRecord(analysisFile);
Assert.assertEquals(1, itemRecord.getDependencySet().size());
// after clear the resource will be lastest so that the dependency is added
ItemRecord.clear();
itemRecord = new ItemRecord(analysisFile);
Assert.assertEquals(2, itemRecord.getDependencySet().size());
}
Aggregations