Search in sources :

Example 11 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class ImportFactoryTest method testImportIndicatorToStuctureImportFileExtensionIsNotCsv.

/**
 * Test method for
 * {@link org.talend.dataprofiler.core.pattern.ImportFactory#importIndicatorToStucture(org.talend.dataprofiler.core.ui.action.actions.ImportObject, org.eclipse.core.resources.IFolder, boolean, boolean, java.lang.String)}
 * non-normal condition: the import file's extension is not csv.
 */
@Test
public void testImportIndicatorToStuctureImportFileExtensionIsNotCsv() throws Exception {
    // $NON-NLS-1$
    File importFile = createImportFile(UDI_NAME, StringUtilities.getRandomString(8) + ".nonCsv");
    List<File> pJarfiles = new ArrayList<File>();
    ImportObject importObject = ImportObject.createImportObject(importFile, pJarfiles);
    IFolder udiFolder = ResourceManager.getUDIFolder();
    boolean skip = false;
    boolean rename = true;
    List<ReturnCode> rc = ImportFactory.importIndicatorToStucture(importObject, udiFolder, skip, rename, UDI_NAME);
    assertTrue(rc.size() == 1);
    assertFalse(rc.get(0).isOk());
    importFile.delete();
}
Also used : ImportObject(org.talend.dataprofiler.core.ui.action.actions.ImportObject) ReturnCode(org.talend.utils.sugars.ReturnCode) ArrayList(java.util.ArrayList) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 12 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class ImportFactoryTest method testImportParserRuleToStuctureNoneEmptyWithoutDoubleQuote.

/**
 * Test method for
 * {@link org.talend.dataprofiler.core.pattern.ImportFactory#importParserRuleToStucture(org.talend.dataprofiler.core.ui.action.actions.ImportObject, org.eclipse.core.resources.IFolder, boolean, boolean, java.lang.String)}
 * None Empty Without Double Quote.
 */
@Test
public void testImportParserRuleToStuctureNoneEmptyWithoutDoubleQuote() throws IOException {
    // the parser rule name, use it to get the imported file name
    // $NON-NLS-1$
    String parserRuleName = "parserRule";
    // $NON-NLS-1$
    String parserRuleFileName = parserRuleName + "_0.1.rules";
    // the expect expression's values: name and body will add double quote after import, lang will not add double
    // quote after import
    // $NON-NLS-1$
    String name = "\"a\"";
    // $NON-NLS-1$
    String lang = "Enumeration";
    // $NON-NLS-1$
    String body = "\"'a'|'b'\"";
    // $NON-NLS-1$
    File dict = new File("");
    // $NON-NLS-1$
    File importFile = new File(dict.getAbsolutePath() + File.separator + "paser_rule.csv");
    if (importFile.exists()) {
        importFile.delete();
    }
    importFile.createNewFile();
    // set the csv file's head
    // $NON-NLS-1$
    String content = "\"Label\"\t\"Purpose\"\t\"Description\"\t\"Author\"\t\"Relative_Path\"\t\"Name\"\t\"Type\"\t\"Value\"\n";
    // set the csv file's content: the clumn's value is none empty without double quote
    content += // $NON-NLS-1$
    "\"" + parserRuleName + // $NON-NLS-1$
    "\"\t\"\"\t\"\"\t\"trunk@talend.com\"\t\"\"\t\"a\"\t\"Enumeration\"\t\"'a'|'b'\"";
    BufferedWriter output = new BufferedWriter(new FileWriter(importFile));
    output.write(content);
    output.close();
    List<File> pJarfilesMock = new ArrayList<File>();
    ImportObject importObject = ImportObject.createImportObject(importFile, pJarfilesMock);
    IFolder parserRuleFolder = ResourceManager.getOneFolder(EResourceConstant.RULES_PARSER);
    boolean skip = false;
    boolean rename = true;
    // $NON-NLS-1$
    String importItemName = "importItemName";
    List<ReturnCode> importParserRuleToStucture = ImportFactory.importParserRuleToStucture(importObject, parserRuleFolder, skip, rename, importItemName);
    for (ReturnCode rc : importParserRuleToStucture) {
        assertTrue(rc.isOk());
    }
    // the imported parser rule's name is a
    IFile parserRuleFile = parserRuleFolder.getFile(parserRuleFileName);
    ParserRule parserRule = (ParserRule) DQRuleResourceFileHelper.getInstance().findDQRule(parserRuleFile);
    List<TdExpression> expressions = parserRule.getExpression();
    for (TdExpression expression : expressions) {
        assertEquals(name, expression.getName());
        assertEquals(lang, expression.getLanguage());
        assertEquals(body, expression.getBody());
    }
}
Also used : ParserRule(org.talend.dataquality.rules.ParserRule) ReturnCode(org.talend.utils.sugars.ReturnCode) IFile(org.eclipse.core.resources.IFile) TdExpression(org.talend.cwm.relational.TdExpression) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) BufferedWriter(java.io.BufferedWriter) ImportObject(org.talend.dataprofiler.core.ui.action.actions.ImportObject) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 13 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class ImportFactoryTest method testImportParserRuleToStuctureNoneEmptyWithDoubleQuote.

/**
 * Test method for
 * {@link org.talend.dataprofiler.core.pattern.ImportFactory#importParserRuleToStucture(org.talend.dataprofiler.core.ui.action.actions.ImportObject, org.eclipse.core.resources.IFolder, boolean, boolean, java.lang.String)}
 * None Empty With Double Quote.
 */
@Test
public void testImportParserRuleToStuctureNoneEmptyWithDoubleQuote() throws IOException {
    // the parser rule name, use it to get the imported file name
    // $NON-NLS-1$
    String parserRuleName = "parserRule";
    // $NON-NLS-1$
    String parserRuleFileName = parserRuleName + "_0.1.rules";
    // the expect expression's values: name and body will add double quote after import, lang will not add double
    // quote after import
    // $NON-NLS-1$
    String name = "\"a\"";
    // $NON-NLS-1$
    String lang = "Enumeration";
    // $NON-NLS-1$
    String body = "\"'a'|'b'\"";
    // $NON-NLS-1$
    File dict = new File("");
    // $NON-NLS-1$
    File importFile = new File(dict.getAbsolutePath() + File.separator + "paser_rule.csv");
    if (importFile.exists()) {
        importFile.delete();
    }
    importFile.createNewFile();
    // set the csv file's head
    // $NON-NLS-1$
    String content = "\"Label\"\t\"Purpose\"\t\"Description\"\t\"Author\"\t\"Relative_Path\"\t\"Name\"\t\"Type\"\t\"Value\"\n";
    // set the csv file's content: the clumn's value is none empty with double quote
    content += // $NON-NLS-1$
    "\"" + parserRuleName + // $NON-NLS-1$
    "\"\t\"\"\t\"\"\t\"trunk@talend.com\"\t\"\"\t\"\\\"a\\\"\"\t\"\\\"Enumeration\\\"\"\t\"\\\"'a'|'b'\\\"\"";
    BufferedWriter output = new BufferedWriter(new FileWriter(importFile));
    output.write(content);
    output.close();
    List<File> pJarfilesMock = new ArrayList<File>();
    ImportObject importObject = ImportObject.createImportObject(importFile, pJarfilesMock);
    IFolder parserRuleFolder = ResourceManager.getOneFolder(EResourceConstant.RULES_PARSER);
    boolean skip = false;
    boolean rename = true;
    // $NON-NLS-1$
    String importItemName = "importItemName";
    List<ReturnCode> importParserRuleToStucture = ImportFactory.importParserRuleToStucture(importObject, parserRuleFolder, skip, rename, importItemName);
    for (ReturnCode rc : importParserRuleToStucture) {
        assertTrue(rc.isOk());
    }
    // the imported parser rule's name is a
    IFile parserRuleFile = parserRuleFolder.getFile(parserRuleFileName);
    ParserRule parserRule = (ParserRule) DQRuleResourceFileHelper.getInstance().findDQRule(parserRuleFile);
    List<TdExpression> expressions = parserRule.getExpression();
    for (TdExpression expression : expressions) {
        assertEquals(name, expression.getName());
        assertEquals(lang, expression.getLanguage());
        assertEquals(body, expression.getBody());
    }
}
Also used : ParserRule(org.talend.dataquality.rules.ParserRule) ReturnCode(org.talend.utils.sugars.ReturnCode) IFile(org.eclipse.core.resources.IFile) TdExpression(org.talend.cwm.relational.TdExpression) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) BufferedWriter(java.io.BufferedWriter) ImportObject(org.talend.dataprofiler.core.ui.action.actions.ImportObject) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 14 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class ImportFactoryTest method testImportParserRuleToStuctureEmptyWithDoubleQuote.

/**
 * Test method for
 * {@link org.talend.dataprofiler.core.pattern.ImportFactory#importParserRuleToStucture(org.talend.dataprofiler.core.ui.action.actions.ImportObject, org.eclipse.core.resources.IFolder, boolean, boolean, java.lang.String)}
 * Empty With Double Quote.
 */
@Test
public void testImportParserRuleToStuctureEmptyWithDoubleQuote() throws IOException {
    // the parser rule name, use it to get the imported file name
    // $NON-NLS-1$
    String parserRuleName = "parserRule1";
    // $NON-NLS-1$
    String parserRuleFileName = parserRuleName + "_0.1.rules";
    // the expect expression's values: name and body will add double quote after import, lang will remove any double
    // quote after import(why???)
    // $NON-NLS-1$
    String name = "\"\"\"\"";
    // $NON-NLS-1$
    String lang = "";
    // $NON-NLS-1$
    String body = "\"\"\"\"";
    // $NON-NLS-1$
    File dict = new File("");
    // $NON-NLS-1$
    File importFile = new File(dict.getAbsolutePath() + File.separator + "paser_rule.csv");
    if (importFile.exists()) {
        importFile.delete();
    }
    importFile.createNewFile();
    // set the csv file's head
    // $NON-NLS-1$
    String content = "\"Label\"\t\"Purpose\"\t\"Description\"\t\"Author\"\t\"Relative_Path\"\t\"Name\"\t\"Type\"\t\"Value\"\n";
    // set the csv file's content: the clumn's value is empty with double quote
    content += // $NON-NLS-1$
    "\"" + parserRuleName + // $NON-NLS-1$
    "\"\t\"\"\t\"\"\t\"trunk@talend.com\"\t\"\"\t\"\\\"\\\"\"\t\"\\\"\\\"\"\t\"\\\"\\\"\"";
    BufferedWriter output = new BufferedWriter(new FileWriter(importFile));
    output.write(content);
    output.close();
    List<File> pJarfilesMock = new ArrayList<File>();
    ImportObject importObject = ImportObject.createImportObject(importFile, pJarfilesMock);
    IFolder parserRuleFolder = ResourceManager.getOneFolder(EResourceConstant.RULES_PARSER);
    boolean skip = false;
    boolean rename = true;
    // $NON-NLS-1$
    String importItemName = "importItemName";
    List<ReturnCode> importParserRuleToStucture = ImportFactory.importParserRuleToStucture(importObject, parserRuleFolder, skip, rename, importItemName);
    for (ReturnCode rc : importParserRuleToStucture) {
        assertTrue(rc.isOk());
    }
    // the imported parser rule's name is a
    IFile parserRuleFile = parserRuleFolder.getFile(parserRuleFileName);
    ParserRule parserRule = (ParserRule) DQRuleResourceFileHelper.getInstance().findDQRule(parserRuleFile);
    List<TdExpression> expressions = parserRule.getExpression();
    for (TdExpression expression : expressions) {
        assertEquals(name, expression.getName());
        assertEquals(lang, expression.getLanguage());
        assertEquals(body, expression.getBody());
    }
}
Also used : ParserRule(org.talend.dataquality.rules.ParserRule) ReturnCode(org.talend.utils.sugars.ReturnCode) IFile(org.eclipse.core.resources.IFile) TdExpression(org.talend.cwm.relational.TdExpression) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) BufferedWriter(java.io.BufferedWriter) ImportObject(org.talend.dataprofiler.core.ui.action.actions.ImportObject) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 15 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class ImportFactoryTest method testImportIndicatorToStuctureImportFileIsNotExist.

/**
 * Test method for
 * {@link org.talend.dataprofiler.core.pattern.ImportFactory#importIndicatorToStucture(org.talend.dataprofiler.core.ui.action.actions.ImportObject, org.eclipse.core.resources.IFolder, boolean, boolean, java.lang.String)}
 * non-normal condition: the import file is not exist.
 */
@Test
public void testImportIndicatorToStuctureImportFileIsNotExist() throws Exception {
    // $NON-NLS-1$
    File importFile = new File(File.separator + StringUtilities.getRandomString(8) + ".csv");
    List<File> pJarfiles = new ArrayList<File>();
    ImportObject importObject = ImportObject.createImportObject(importFile, pJarfiles);
    IFolder udiFolder = ResourceManager.getUDIFolder();
    boolean skip = false;
    boolean rename = true;
    List<ReturnCode> rc = ImportFactory.importIndicatorToStucture(importObject, udiFolder, skip, rename, UDI_NAME);
    assertTrue(rc.size() == 1);
    assertFalse(rc.get(0).isOk());
    importFile.delete();
}
Also used : ImportObject(org.talend.dataprofiler.core.ui.action.actions.ImportObject) ReturnCode(org.talend.utils.sugars.ReturnCode) ArrayList(java.util.ArrayList) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Aggregations

ReturnCode (org.talend.utils.sugars.ReturnCode)175 ArrayList (java.util.ArrayList)42 TypedReturnCode (org.talend.utils.sugars.TypedReturnCode)42 Test (org.junit.Test)29 File (java.io.File)26 Connection (org.talend.core.model.metadata.builder.connection.Connection)26 Indicator (org.talend.dataquality.indicators.Indicator)25 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)20 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)18 Analysis (org.talend.dataquality.analysis.Analysis)18 Property (org.talend.core.model.properties.Property)17 IFile (org.eclipse.core.resources.IFile)16 IRepositoryNode (org.talend.repository.model.IRepositoryNode)16 IFolder (org.eclipse.core.resources.IFolder)15 SQLException (java.sql.SQLException)14 PersistenceException (org.talend.commons.exception.PersistenceException)11 TdColumn (org.talend.cwm.relational.TdColumn)11 IOException (java.io.IOException)10 EObject (org.eclipse.emf.ecore.EObject)10 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)10