use of org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult in project drools-wb by kiegroup.
the class GuidedDecisionTableGeneratorListenerTest method testProperties.
@Test
public void testProperties() {
final ConversionResult result = new ConversionResult();
final List<DataListener> listeners = new ArrayList<DataListener>();
final GuidedDecisionTableGeneratorListener listener = new GuidedDecisionTableGeneratorListener(result, dmo);
listeners.add(listener);
// Convert
final ExcelParser parser = new ExcelParser(listeners);
final InputStream is = this.getClass().getResourceAsStream("Properties.xls");
try {
parser.parseFile(is);
} finally {
try {
is.close();
} catch (IOException ioe) {
fail(ioe.getMessage());
}
}
// Check conversion results
assertEquals(0, result.getMessages().size());
// Check properties
List<String> functions = listener.getFunctions();
assertNotNull(functions);
assertEquals(1, functions.size());
assertEquals("function a() { }", functions.get(0));
List<Global> globals = listener.getGlobals();
assertNotNull(globals);
assertEquals(1, globals.size());
assertEquals("java.util.List", globals.get(0).getClassName());
assertEquals("list", globals.get(0).getIdentifier());
List<Import> imports = listener.getImports();
assertNotNull(imports);
assertEquals(2, imports.size());
assertEquals("org.yourco.model.*", imports.get(0).getClassName());
assertEquals("java.util.Date", imports.get(1).getClassName());
List<String> queries = listener.getQueries();
assertNotNull(queries);
assertEquals(1, queries.size());
assertEquals("A query", queries.get(0));
List<String> types = listener.getTypeDeclarations();
assertNotNull(types);
assertEquals(1, types.size());
assertEquals("declare Smurf name : String end", types.get(0));
}
use of org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult in project drools-wb by kiegroup.
the class GuidedDecisionTableGeneratorListenerTest method testMultipleRuleTables.
@Test
public void testMultipleRuleTables() {
final ConversionResult result = new ConversionResult();
final List<DataListener> listeners = new ArrayList<DataListener>();
final GuidedDecisionTableGeneratorListener listener = new GuidedDecisionTableGeneratorListener(result, dmo);
listeners.add(listener);
// Convert
final ExcelParser parser = new ExcelParser(listeners);
final InputStream is = this.getClass().getResourceAsStream("MultipleRuleTables.xls");
try {
parser.parseFile(is);
} finally {
try {
is.close();
} catch (IOException ioe) {
fail(ioe.getMessage());
}
}
// Check conversion results
assertEquals(0, result.getMessages().size());
// Check basics
List<GuidedDecisionTable52> dtables = listener.getGuidedDecisionTables();
assertNotNull(dtables);
assertEquals(2, dtables.size());
GuidedDecisionTable52 dtable0 = dtables.get(0);
assertEquals("Table1", dtable0.getTableName());
assertEquals(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY, dtable0.getTableFormat());
GuidedDecisionTable52 dtable1 = dtables.get(1);
assertEquals("Table2", dtable1.getTableName());
assertEquals(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY, dtable1.getTableFormat());
// Check expanded columns
List<BaseColumn> columns0 = dtable0.getExpandedColumns();
assertNotNull(columns0);
assertEquals(5, columns0.size());
assertTrue(columns0.get(0) instanceof RowNumberCol52);
assertTrue(columns0.get(1) instanceof DescriptionCol52);
assertTrue(columns0.get(2) instanceof AttributeCol52);
assertTrue(columns0.get(3) instanceof BRLConditionVariableColumn);
assertTrue(columns0.get(4) instanceof BRLActionVariableColumn);
AttributeCol52 attrCol0_2 = ((AttributeCol52) columns0.get(2));
assertEquals(GuidedDecisionTable52.AGENDA_GROUP_ATTR, attrCol0_2.getAttribute());
// Check individual condition columns
assertEquals(1, dtable0.getConditions().size());
assertTrue(dtable0.getConditions().get(0) instanceof BRLConditionColumn);
// Column 1
BRLConditionColumn conditionCol0_0 = ((BRLConditionColumn) dtable0.getConditions().get(0));
assertEquals("Converted from ['Person's name']", conditionCol0_0.getHeader());
assertEquals(1, conditionCol0_0.getChildColumns().size());
List<IPattern> conditionCol0_0definition = conditionCol0_0.getDefinition();
assertEquals(1, conditionCol0_0definition.size());
assertTrue(conditionCol0_0definition.get(0) instanceof FactPattern);
FactPattern conditionCol0_0fp = (FactPattern) conditionCol0_0definition.get(0);
assertEquals("Person", conditionCol0_0fp.getFactType());
assertEquals(1, conditionCol0_0fp.getNumberOfConstraints());
assertTrue(conditionCol0_0fp.getConstraint(0) instanceof SingleFieldConstraint);
final SingleFieldConstraint conditionCol0_0fpsfc0 = (SingleFieldConstraint) conditionCol0_0fp.getConstraint(0);
assertEquals("name", conditionCol0_0fpsfc0.getFieldName());
assertEquals("==", conditionCol0_0fpsfc0.getOperator());
assertEquals("param1", conditionCol0_0fpsfc0.getValue());
assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0_0fpsfc0.getConstraintValueType());
// Column 1 - Variable 1
BRLConditionVariableColumn conditionCol0_0param0 = conditionCol0_0.getChildColumns().get(0);
assertEquals("param1", conditionCol0_0param0.getVarName());
assertEquals("Person's name", conditionCol0_0param0.getHeader());
assertEquals(DataType.TYPE_STRING, conditionCol0_0param0.getFieldType());
assertEquals("Person", conditionCol0_0param0.getFactType());
assertEquals("name", conditionCol0_0param0.getFactField());
// Column 2
BRLActionColumn actionCol0_0 = ((BRLActionColumn) dtable0.getActionCols().get(0));
assertEquals("Converted from ['Salutation']", actionCol0_0.getHeader());
assertEquals(1, actionCol0_0.getChildColumns().size());
List<IAction> actionCol0_0definition = actionCol0_0.getDefinition();
assertEquals(1, actionCol0_0definition.size());
assertTrue(actionCol0_0definition.get(0) instanceof FreeFormLine);
FreeFormLine actionCol0_0ffl = (FreeFormLine) actionCol0_0definition.get(0);
assertEquals("System.out.println(\"@{param2}\");", actionCol0_0ffl.getText());
// Column 1 - Variable 1
BRLActionVariableColumn actionCol0_0param0 = actionCol0_0.getChildColumns().get(0);
assertEquals("param2", actionCol0_0param0.getVarName());
assertEquals("Salutation", actionCol0_0param0.getHeader());
assertEquals(DataType.TYPE_OBJECT, actionCol0_0param0.getFieldType());
assertNull(actionCol0_0param0.getFactType());
assertNull(actionCol0_0param0.getFactField());
// Check data
assertEquals(2, dtable0.getData().size());
assertTrue(isRowEquivalent(new Object[] { 1, "Created from row 7", "AG1", "John", "Hello Sir" }, dtable0.getData().get(0)));
assertTrue(isRowEquivalent(new Object[] { 2, "Row 2", "AG2", "Jane", "Hello Madam" }, dtable0.getData().get(1)));
// Check expanded columns
List<BaseColumn> columns1 = dtable1.getExpandedColumns();
assertNotNull(columns1);
assertEquals(4, columns1.size());
assertTrue(columns1.get(0) instanceof RowNumberCol52);
assertTrue(columns1.get(1) instanceof DescriptionCol52);
assertTrue(columns1.get(2) instanceof BRLConditionVariableColumn);
assertTrue(columns1.get(3) instanceof BRLConditionVariableColumn);
// Check individual condition columns
assertEquals(1, dtable0.getConditions().size());
assertTrue(dtable0.getConditions().get(0) instanceof BRLConditionColumn);
// Column 1
BRLConditionColumn conditionCol1_0 = ((BRLConditionColumn) dtable1.getConditions().get(0));
assertEquals("Converted from ['Person’s name', 'Person’s age']", conditionCol1_0.getHeader());
assertEquals(2, conditionCol1_0.getChildColumns().size());
List<IPattern> conditionCol1_0definition = conditionCol1_0.getDefinition();
assertEquals(1, conditionCol1_0definition.size());
assertTrue(conditionCol1_0definition.get(0) instanceof FactPattern);
FactPattern conditionCol1_0fp = (FactPattern) conditionCol1_0definition.get(0);
assertEquals("Person", conditionCol1_0fp.getFactType());
assertEquals(2, conditionCol1_0fp.getNumberOfConstraints());
assertTrue(conditionCol1_0fp.getConstraint(0) instanceof SingleFieldConstraint);
final SingleFieldConstraint conditionCol1_0fpsfc0 = (SingleFieldConstraint) conditionCol1_0fp.getConstraint(0);
assertEquals("name", conditionCol1_0fpsfc0.getFieldName());
assertEquals("==", conditionCol1_0fpsfc0.getOperator());
assertEquals("param1", conditionCol1_0fpsfc0.getValue());
assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol1_0fpsfc0.getConstraintValueType());
assertTrue(conditionCol1_0fp.getConstraint(1) instanceof SingleFieldConstraint);
final SingleFieldConstraint conditionCol1_0fpsfc1 = (SingleFieldConstraint) conditionCol1_0fp.getConstraint(1);
assertEquals("age", conditionCol1_0fpsfc1.getFieldName());
assertEquals("==", conditionCol1_0fpsfc1.getOperator());
assertEquals("param2", conditionCol1_0fpsfc1.getValue());
assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol1_0fpsfc1.getConstraintValueType());
// Column 1 - Variable 1
BRLConditionVariableColumn conditionCol1_0param0 = conditionCol1_0.getChildColumns().get(0);
assertEquals("param1", conditionCol1_0param0.getVarName());
assertEquals("Person’s name", conditionCol1_0param0.getHeader());
assertEquals(DataType.TYPE_STRING, conditionCol1_0param0.getFieldType());
assertEquals("Person", conditionCol1_0param0.getFactType());
assertEquals("name", conditionCol1_0param0.getFactField());
// Column 1 - Variable 2
BRLConditionVariableColumn conditionCol1_0param1 = conditionCol1_0.getChildColumns().get(1);
assertEquals("param2", conditionCol1_0param1.getVarName());
assertEquals("Person’s age", conditionCol1_0param1.getHeader());
assertEquals(DataType.TYPE_STRING, conditionCol1_0param1.getFieldType());
assertEquals("Person", conditionCol1_0param1.getFactType());
assertEquals("age", conditionCol1_0param1.getFactField());
// Check data
assertEquals(2, dtable1.getData().size());
assertTrue(isRowEquivalent(new Object[] { 1, "Row 1", "John", "25" }, dtable1.getData().get(0)));
assertTrue(isRowEquivalent(new Object[] { 2, "Created from row 16", "Jane", "29" }, dtable1.getData().get(1)));
}
use of org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult in project drools-wb by kiegroup.
the class GuidedDecisionTableGeneratorListenerTest method testSequentialSalience.
@Test
public void testSequentialSalience() {
final ConversionResult result = new ConversionResult();
final List<DataListener> listeners = new ArrayList<DataListener>();
final GuidedDecisionTableGeneratorListener listener = new GuidedDecisionTableGeneratorListener(result, dmo);
listeners.add(listener);
// Convert
final ExcelParser parser = new ExcelParser(listeners);
final InputStream is = this.getClass().getResourceAsStream("SequentialSalience.xls");
try {
parser.parseFile(is);
} finally {
try {
is.close();
} catch (IOException ioe) {
fail(ioe.getMessage());
}
}
// Check conversion results
assertEquals(0, result.getMessages().size());
// Check basics
List<GuidedDecisionTable52> dtables = listener.getGuidedDecisionTables();
assertNotNull(dtables);
assertEquals(1, dtables.size());
GuidedDecisionTable52 dtable = dtables.get(0);
assertEquals("SequentialSalienceTest", dtable.getTableName());
assertEquals(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY, dtable.getTableFormat());
// Check expanded columns
List<BaseColumn> columns = dtable.getExpandedColumns();
assertNotNull(columns);
assertEquals(3, columns.size());
assertTrue(columns.get(0) instanceof RowNumberCol52);
assertTrue(columns.get(1) instanceof DescriptionCol52);
assertTrue(columns.get(2) instanceof AttributeCol52);
// Check attribute column
AttributeCol52 attrCol2 = ((AttributeCol52) columns.get(2));
assertEquals(GuidedDecisionTable52.SALIENCE_ATTR, attrCol2.getAttribute());
assertTrue(attrCol2.isUseRowNumber());
assertTrue(attrCol2.isReverseOrder());
// Check data
assertEquals(2, dtable.getData().size());
assertTrue(isRowEquivalent(new Object[] { 1, "Rule 1", 2 }, dtable.getData().get(0)));
assertTrue(isRowEquivalent(new Object[] { 2, "Rule 2", 1 }, dtable.getData().get(1)));
}
use of org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult in project drools-wb by kiegroup.
the class GuidedDecisionTableGeneratorListenerTest method testMetadata.
@Test
public void testMetadata() {
final ConversionResult result = new ConversionResult();
final List<DataListener> listeners = new ArrayList<DataListener>();
final GuidedDecisionTableGeneratorListener listener = new GuidedDecisionTableGeneratorListener(result, dmo);
listeners.add(listener);
// Convert
final ExcelParser parser = new ExcelParser(listeners);
final InputStream is = this.getClass().getResourceAsStream("Metadata.xls");
try {
parser.parseFile(is);
} finally {
try {
is.close();
} catch (IOException ioe) {
fail(ioe.getMessage());
}
}
// Check conversion results
assertEquals(0, result.getMessages().size());
// Check basics
List<GuidedDecisionTable52> dtables = listener.getGuidedDecisionTables();
assertNotNull(dtables);
assertEquals(1, dtables.size());
GuidedDecisionTable52 dtable = dtables.get(0);
assertEquals("MetadataTest", dtable.getTableName());
assertEquals(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY, dtable.getTableFormat());
// Check expanded columns
List<BaseColumn> columns = dtable.getExpandedColumns();
assertNotNull(columns);
assertEquals(3, columns.size());
assertTrue(columns.get(0) instanceof RowNumberCol52);
assertTrue(columns.get(1) instanceof DescriptionCol52);
assertTrue(columns.get(2) instanceof MetadataCol52);
// Check metadata column
MetadataCol52 mdCol2 = ((MetadataCol52) columns.get(2));
assertEquals("cheese", mdCol2.getMetadata());
// Check data
assertEquals(2, dtable.getData().size());
assertTrue(isRowEquivalent(new Object[] { 1, "Rule 1", "cheddar" }, dtable.getData().get(0)));
assertTrue(isRowEquivalent(new Object[] { 2, "Rule 2", "edam" }, dtable.getData().get(1)));
}
use of org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult in project drools-wb by kiegroup.
the class GuidedDecisionTableGeneratorListenerTest method conversionWithBigDecimals.
@Test
public // https://issues.jboss.org/browse/RHBPMS-4737
void conversionWithBigDecimals() {
final ConversionResult result = new ConversionResult();
final List<DataListener> listeners = new ArrayList<>();
addModelField("org.test.Message", "this", "org.test.Message", DataType.TYPE_THIS);
addModelField("org.test.Message", "status", String.class.getName(), DataType.TYPE_STRING);
addModelField("org.test.Message", "message", String.class.getName(), DataType.TYPE_STRING);
addModelField("org.test.Message", "rate", BigDecimal.class.getName(), DataType.TYPE_NUMERIC_BIGDECIMAL);
addModelField("org.test.Reply", "this", "org.test.Reply", DataType.TYPE_THIS);
addModelField("org.test.Reply", "message", String.class.getName(), DataType.TYPE_STRING);
final GuidedDecisionTableGeneratorListener listener = new GuidedDecisionTableGeneratorListener(result, dmo);
listeners.add(listener);
// Convert
final ExcelParser parser = new ExcelParser(listeners);
final InputStream is = this.getClass().getResourceAsStream("RHBPMS-4737 (BigDecimal).xlsx");
try {
parser.parseFile(is);
} finally {
try {
is.close();
} catch (IOException ioe) {
fail(ioe.getMessage());
}
}
checkConversionWithBigMaths(result, listener, () -> DataType.TYPE_NUMERIC_BIGDECIMAL, () -> new BigDecimal("10.00"), () -> new BigDecimal("20.00"));
}
Aggregations