Search in sources :

Example 1 with DefaultRuleSheetListener

use of org.drools.decisiontable.parser.DefaultRuleSheetListener in project drools by kiegroup.

the class SpreadsheetCompilerUnitTest method testPropertiesXLS.

@Test
public void testPropertiesXLS() {
    final List<DataListener> listeners = new ArrayList<DataListener>();
    final DefaultRuleSheetListener listener = new DefaultRuleSheetListener();
    listeners.add(listener);
    final ExcelParser parser = new ExcelParser(listeners);
    final InputStream is = this.getClass().getResourceAsStream("Properties.xls");
    parser.parseFile(is);
    listener.getProperties();
    final String rulesetName = listener.getProperties().getSingleProperty(DefaultRuleSheetListener.RULESET_TAG);
    assertNotNull(rulesetName);
    assertEquals("Properties", rulesetName);
    final List<Import> importList = RuleSheetParserUtil.getImportList(listener.getProperties().getProperty(DefaultRuleSheetListener.IMPORT_TAG));
    assertNotNull(importList);
    assertEquals(1, importList.size());
    assertEquals("java.util.List", importList.get(0).getClassName());
    final List<Global> variableList = RuleSheetParserUtil.getVariableList(listener.getProperties().getProperty(DefaultRuleSheetListener.VARIABLES_TAG));
    assertNotNull(variableList);
    assertEquals(1, variableList.size());
    assertEquals("java.util.List", variableList.get(0).getClassName());
    assertEquals("list", variableList.get(0).getIdentifier());
    final List<String> functions = listener.getProperties().getProperty(DefaultRuleSheetListener.FUNCTIONS_TAG);
    assertNotNull(functions);
    assertEquals(1, functions.size());
    assertEquals("A function", functions.get(0));
    final List<String> queries = listener.getProperties().getProperty(DefaultRuleSheetListener.QUERIES_TAG);
    assertNotNull(queries);
    assertEquals(1, queries.size());
    assertEquals("A query", queries.get(0));
    final List<String> declarations = listener.getProperties().getProperty(DefaultRuleSheetListener.DECLARES_TAG);
    assertNotNull(declarations);
    assertEquals(1, declarations.size());
    assertEquals("A declared type", declarations.get(0));
    final String sequentialFlag = listener.getProperties().getSingleProperty(DefaultRuleSheetListener.SEQUENTIAL_FLAG);
    assertNotNull(sequentialFlag);
    assertEquals("false", sequentialFlag);
    final String escapeQuotesFlag = listener.getProperties().getSingleProperty(DefaultRuleSheetListener.ESCAPE_QUOTES_FLAG);
    assertNotNull(escapeQuotesFlag);
    assertEquals("false", escapeQuotesFlag);
}
Also used : DefaultRuleSheetListener(org.drools.decisiontable.parser.DefaultRuleSheetListener) Import(org.drools.template.model.Import) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ExcelParser(org.drools.decisiontable.parser.xls.ExcelParser) DataListener(org.drools.template.parser.DataListener) Global(org.drools.template.model.Global) Test(org.junit.Test)

Example 2 with DefaultRuleSheetListener

use of org.drools.decisiontable.parser.DefaultRuleSheetListener in project drools by kiegroup.

the class SpreadsheetCompiler method getRuleSheetListener.

private RuleSheetListener getRuleSheetListener(final Resource resource, final String worksheetName) {
    final DefaultRuleSheetListener listener = new DefaultRuleSheetListener();
    listener.setWorksheetName(worksheetName);
    final Map<String, List<DataListener>> sheetListeners = new HashMap<String, List<DataListener>>();
    final List<DataListener> listeners = new ArrayList<DataListener>();
    listeners.add(listener);
    sheetListeners.put(worksheetName, listeners);
    parseResource(new ExcelParser(sheetListeners), resource);
    return listener;
}
Also used : DefaultRuleSheetListener(org.drools.decisiontable.parser.DefaultRuleSheetListener) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ExcelParser(org.drools.decisiontable.parser.xls.ExcelParser) ArrayList(java.util.ArrayList) List(java.util.List) DataListener(org.drools.template.parser.DataListener)

Example 3 with DefaultRuleSheetListener

use of org.drools.decisiontable.parser.DefaultRuleSheetListener in project drools by kiegroup.

the class SpreadsheetCompilerUnitTest method testPropertiesWithWhiteSpaceXLS.

@Test
public void testPropertiesWithWhiteSpaceXLS() {
    final List<DataListener> listeners = new ArrayList<DataListener>();
    final DefaultRuleSheetListener listener = new DefaultRuleSheetListener();
    listeners.add(listener);
    final ExcelParser parser = new ExcelParser(listeners);
    final InputStream is = this.getClass().getResourceAsStream("PropertiesWithWhiteSpace.xls");
    parser.parseFile(is);
    listener.getProperties();
    final String rulesetName = listener.getProperties().getSingleProperty(DefaultRuleSheetListener.RULESET_TAG);
    assertNotNull(rulesetName);
    assertEquals("Properties", rulesetName);
    final List<Import> importList = RuleSheetParserUtil.getImportList(listener.getProperties().getProperty(DefaultRuleSheetListener.IMPORT_TAG));
    assertNotNull(importList);
    assertEquals(1, importList.size());
    assertEquals("java.util.List", importList.get(0).getClassName());
    final List<Global> variableList = RuleSheetParserUtil.getVariableList(listener.getProperties().getProperty(DefaultRuleSheetListener.VARIABLES_TAG));
    assertNotNull(variableList);
    assertEquals(1, variableList.size());
    assertEquals("java.util.List", variableList.get(0).getClassName());
    assertEquals("list", variableList.get(0).getIdentifier());
    final List<String> functions = listener.getProperties().getProperty(DefaultRuleSheetListener.FUNCTIONS_TAG);
    assertNotNull(functions);
    assertEquals(1, functions.size());
    assertEquals("A function", functions.get(0));
    final List<String> queries = listener.getProperties().getProperty(DefaultRuleSheetListener.QUERIES_TAG);
    assertNotNull(queries);
    assertEquals(1, queries.size());
    assertEquals("A query", queries.get(0));
    final List<String> declarations = listener.getProperties().getProperty(DefaultRuleSheetListener.DECLARES_TAG);
    assertNotNull(declarations);
    assertEquals(1, declarations.size());
    assertEquals("A declared type", declarations.get(0));
    final String sequentialFlag = listener.getProperties().getSingleProperty(DefaultRuleSheetListener.SEQUENTIAL_FLAG);
    assertNotNull(sequentialFlag);
    assertEquals("false", sequentialFlag);
    final String escapeQuotesFlag = listener.getProperties().getSingleProperty(DefaultRuleSheetListener.ESCAPE_QUOTES_FLAG);
    assertNotNull(escapeQuotesFlag);
    assertEquals("false", escapeQuotesFlag);
}
Also used : DefaultRuleSheetListener(org.drools.decisiontable.parser.DefaultRuleSheetListener) Import(org.drools.template.model.Import) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ExcelParser(org.drools.decisiontable.parser.xls.ExcelParser) DataListener(org.drools.template.parser.DataListener) Global(org.drools.template.model.Global) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)3 DefaultRuleSheetListener (org.drools.decisiontable.parser.DefaultRuleSheetListener)3 ExcelParser (org.drools.decisiontable.parser.xls.ExcelParser)3 DataListener (org.drools.template.parser.DataListener)3 InputStream (java.io.InputStream)2 Global (org.drools.template.model.Global)2 Import (org.drools.template.model.Import)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 List (java.util.List)1