use of org.talend.dataquality.indicators.definition.IndicatorDefinition in project tdq-studio-se by Talend.
the class DbmsLanguageTest method testGetSqlExpressionRedshiftCase1.
/**
* Test method for
* {@link org.talend.dq.dbms.DbmsLanguage#getSqlExpression(IndicatorDefinition, String, EList, ProductVersion)} .
*/
@Test
public void testGetSqlExpressionRedshiftCase1() {
// TDQ-11558 msjian: test for get sql expresstion for redshift database
// $NON-NLS-1$
String sqlLang = "SQL";
// $NON-NLS-1$
String sqlBody = "SQL body";
String redshiftLang = SupportDBUrlType.REDSHIFT.getLanguage();
// $NON-NLS-1$
String redshiftBody = "Amazon redshift body";
String postgresqlLang = SupportDBUrlType.POSTGRESQLEFAULTURL.getLanguage();
// $NON-NLS-1$
String postgresqlBody = "PostgreSQL body";
IndicatorDefinition indicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
EList<TdExpression> sqlGenericExpression = new BasicEList<TdExpression>();
TdExpression tdExpression1 = RelationalFactory.eINSTANCE.createTdExpression();
tdExpression1.setLanguage(sqlLang);
tdExpression1.setBody(sqlBody);
sqlGenericExpression.add(tdExpression1);
TdExpression tdExpression3 = RelationalFactory.eINSTANCE.createTdExpression();
tdExpression3.setLanguage(postgresqlLang);
tdExpression3.setBody(postgresqlBody);
sqlGenericExpression.add(tdExpression3);
TdExpression tdExpression4 = RelationalFactory.eINSTANCE.createTdExpression();
tdExpression4.setLanguage(redshiftLang);
tdExpression4.setBody(redshiftBody);
sqlGenericExpression.add(tdExpression4);
ProductVersion dbVersion = new ProductVersion(1, 0);
TdExpression sqlExpression = DbmsLanguage.getSqlExpression(indicatorDefinition, redshiftLang, sqlGenericExpression, dbVersion);
Assert.assertEquals(tdExpression4, sqlExpression);
}
use of org.talend.dataquality.indicators.definition.IndicatorDefinition in project tdq-studio-se by Talend.
the class DbmsLanguageTest method testGetSqlExpressionRedshiftCase3.
/**
* Test method for
* {@link org.talend.dq.dbms.DbmsLanguage#getSqlExpression(IndicatorDefinition, String, EList, ProductVersion)} .
*/
@Test
public void testGetSqlExpressionRedshiftCase3() {
// TDQ-11558 msjian: test for get sql expresstion for redshift database when there is no redshift and ParAccel
// and PostgreSQL defined
// $NON-NLS-1$
String sqlLang = "SQL";
// $NON-NLS-1$
String sqlBody = "SQL body";
String redshiftLang = SupportDBUrlType.REDSHIFT.getLanguage();
IndicatorDefinition indicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
EList<TdExpression> sqlGenericExpression = new BasicEList<TdExpression>();
TdExpression tdExpression1 = RelationalFactory.eINSTANCE.createTdExpression();
tdExpression1.setLanguage(sqlLang);
tdExpression1.setBody(sqlBody);
sqlGenericExpression.add(tdExpression1);
ProductVersion dbVersion = new ProductVersion(1, 0);
TdExpression sqlExpression = DbmsLanguage.getSqlExpression(indicatorDefinition, redshiftLang, sqlGenericExpression, dbVersion);
Assert.assertEquals(tdExpression1, sqlExpression);
}
use of org.talend.dataquality.indicators.definition.IndicatorDefinition in project tdq-studio-se by Talend.
the class ExportFactoryTest method testExportFolderIFolderIndicatorDefinitionArrayNonNormalFolderNotExist.
/**
* Test method for
* {@link org.talend.dataprofiler.core.pattern.ExportFactory#export(java.io.File, org.eclipse.core.resources.IFolder, org.talend.dataquality.indicators.definition.IndicatorDefinition[])}
* non-normal condition: exportFile is a folder and this folder does not exist.
*/
@Test
public void testExportFolderIFolderIndicatorDefinitionArrayNonNormalFolderNotExist() throws Exception {
String udiName = getRandomUdiName();
File exportFolder = new File(File.separator + StringUtilities.getRandomString(8));
IFolder udiFolder = ResourceManager.getUDIFolder();
IndicatorDefinition indDef = createExportIndicaorDefinition(udiFolder, udiName);
ExportFactory.export(exportFolder, udiFolder, indDef);
// $NON-NLS-1$
File exportFile = new File(exportFolder.getAbsolutePath() + File.separator + udiName + ".csv");
assertFalse(exportFile.exists());
}
use of org.talend.dataquality.indicators.definition.IndicatorDefinition in project tdq-studio-se by Talend.
the class ExportFactoryTest method createExportIndicaorDefinition.
/**
* create the IndicaorDefinition for test.
*
* @return
*/
private IndicatorDefinition createExportIndicaorDefinition(IFolder folder, String udiName) {
IndicatorDefinition indDef = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
indDef.setName(udiName);
Map<String, String> indDefParaMap = getIndDefParaMap();
for (String key : indDefParaMap.keySet()) {
IndicatorDefinitionParameter indDefPara = DefinitionFactory.eINSTANCE.createIndicatorDefinitionParameter();
indDefPara.setKey(key);
indDefPara.setValue(indDefParaMap.get(key));
indDef.getIndicatorDefinitionParameter().add(indDefPara);
}
UDIHelper.setUDICategory(indDef, DefinitionHandler.getInstance().getUserDefinedCountIndicatorCategory());
ElementWriterFactory.getInstance().createIndicatorDefinitionWriter().create(indDef, folder);
DefinitionHandler.getInstance().reloadIndicatorsDefinitions();
return indDef;
}
use of org.talend.dataquality.indicators.definition.IndicatorDefinition in project tdq-studio-se by Talend.
the class ExportFactoryTest method testExportFolderIFolderIndicatorDefinitionArray.
/**
* Test method for
* {@link org.talend.dataprofiler.core.pattern.ExportFactory#export(java.io.File, org.eclipse.core.resources.IFolder, org.talend.dataquality.indicators.definition.IndicatorDefinition[])}
* normal condition: exportFile is a folder(not a file).
*/
@Test
public void testExportFolderIFolderIndicatorDefinitionArray() throws Exception {
String udiName = getRandomUdiName();
// $NON-NLS-1$
File exportFolder = new File(System.getProperty("java.io.tmpdir") + File.separator + StringUtilities.getRandomString(8));
if (!exportFolder.exists()) {
exportFolder.mkdirs();
}
IFolder udiFolder = ResourceManager.getUDIFolder();
IndicatorDefinition indDef = createExportIndicaorDefinition(udiFolder, udiName);
ExportFactory.export(exportFolder, udiFolder, indDef);
// $NON-NLS-1$
File exportFile = new File(exportFolder.getAbsolutePath() + File.separator + udiName + ".csv");
assertTrue(exportFile.exists());
assertTrue(exportFile.isFile());
assertTrue(exportFile.length() > 0);
CSVReader reader = FileUtils.createCSVReader(exportFile, FileUtils.TEXT_QUAL, FileUtils.TEXT_QUAL);
reader.setSkipEmptyRecords(true);
reader.readHeaders();
boolean haveRecord = false;
while (reader.readNext()) {
haveRecord = true;
String name = reader.get(PatternToExcelEnum.Label.getLiteral());
assertEquals(name, indDef.getName());
String paraString = reader.get(PatternToExcelEnum.IndicatorDefinitionParameter.getLiteral());
EList<IndicatorDefinitionParameter> indDefParas = indDef.getIndicatorDefinitionParameter();
for (IndicatorDefinitionParameter indDefPara : indDefParas) {
String temp = indDefPara.getKey() + UDIHelper.PARA_SEPARATE_1 + indDefPara.getValue() + UDIHelper.PARA_SEPARATE_2;
assertTrue(paraString.indexOf(temp) > -1);
}
}
reader.close();
assertTrue(haveRecord);
}
Aggregations