Search in sources :

Example 1 with ParserRule

use of org.talend.dataquality.rules.ParserRule 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 2 with ParserRule

use of org.talend.dataquality.rules.ParserRule 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 3 with ParserRule

use of org.talend.dataquality.rules.ParserRule 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 4 with ParserRule

use of org.talend.dataquality.rules.ParserRule in project tdq-studio-se by Talend.

the class ImportFactoryTest method testImportParserRuleToStuctureEmptyWithoutDoubleQuote.

/**
 * 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 Without Double Quote.
 */
@Test
public void testImportParserRuleToStuctureEmptyWithoutDoubleQuote() throws IOException {
    // the parser rule name, use it to get the imported file name
    // $NON-NLS-1$
    String parserRuleName = "parserRule2";
    // $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 = "\"\"";
    // $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 without 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) {
        assertTrue(name.equals(expression.getName()));
        assertTrue(lang.equals(expression.getLanguage()));
        assertTrue(body.equals(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 5 with ParserRule

use of org.talend.dataquality.rules.ParserRule in project tdq-studio-se by Talend.

the class AElementPersistanceRealTest method testCreateItemParserRule.

/**
 * Test method for
 * {@link org.talend.dq.writer.AElementPersistance#createItem(orgomg.cwm.objectmodel.core.ModelElement)}.
 */
@Test
public void testCreateItemParserRule() {
    DQRuleWriter createdRuleWriter = ElementWriterFactory.getInstance().createdRuleWriter();
    // test normal name
    // $NON-NLS-1$
    String parserRuleName = "parserRule1";
    // $NON-NLS-1$
    String exceptedFileName = parserRuleName + "_0.1.rules";
    ParserRule createParserRule = RulesFactory.eINSTANCE.createParserRule();
    createParserRule.setName(parserRuleName);
    Item createItem = createdRuleWriter.createItem(createParserRule);
    assertTrue(createItem instanceof TDQBusinessRuleItem);
    TDQBusinessRuleItem ruleItem = (TDQBusinessRuleItem) createItem;
    assertTrue(ruleItem.getFilename().equals(exceptedFileName));
    // test special name
    // $NON-NLS-1$
    String parserRuleName2 = "parserRule1:;\".";
    // $NON-NLS-1$
    String exceptedFileName2 = "parserRule1_____0.1.rules";
    ParserRule createParserRule2 = RulesFactory.eINSTANCE.createParserRule();
    createParserRule2.setName(parserRuleName2);
    Item createItem2 = createdRuleWriter.createItem(createParserRule2);
    assertTrue(createItem2 instanceof TDQBusinessRuleItem);
    TDQBusinessRuleItem ruleItem2 = (TDQBusinessRuleItem) createItem2;
    assertTrue(ruleItem2.getFilename().equals(exceptedFileName2));
}
Also used : ParserRule(org.talend.dataquality.rules.ParserRule) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem) Item(org.talend.core.model.properties.Item) TDQIndicatorDefinitionItem(org.talend.dataquality.properties.TDQIndicatorDefinitionItem) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) DQRuleWriter(org.talend.dq.writer.impl.DQRuleWriter) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem) Test(org.junit.Test)

Aggregations

ParserRule (org.talend.dataquality.rules.ParserRule)16 ArrayList (java.util.ArrayList)7 IFile (org.eclipse.core.resources.IFile)7 TdExpression (org.talend.cwm.relational.TdExpression)7 File (java.io.File)6 IFolder (org.eclipse.core.resources.IFolder)6 Test (org.junit.Test)6 BufferedWriter (java.io.BufferedWriter)4 FileWriter (java.io.FileWriter)4 ImportObject (org.talend.dataprofiler.core.ui.action.actions.ImportObject)4 ReturnCode (org.talend.utils.sugars.ReturnCode)4 IndicatorCategory (org.talend.dataquality.indicators.definition.IndicatorCategory)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)2 MatchRuleDefinition (org.talend.dataquality.rules.MatchRuleDefinition)2 DqRuleBuilder (org.talend.dq.dqrule.DqRuleBuilder)2 RuleRepNode (org.talend.dq.nodes.RuleRepNode)2 CSVWriter (com.talend.csv.CSVWriter)1 FileNotFoundException (java.io.FileNotFoundException)1