use of org.drools.decisiontable.parser.xls.ExcelParser in project drools-wb by kiegroup.
the class GuidedDecisionTableGeneratorListenerTest method testAttributes.
@Test
public void testAttributes() {
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("Attributes.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("AttributesTest", dtable.getTableName());
assertEquals(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY, dtable.getTableFormat());
// Check expanded columns
List<BaseColumn> columns = dtable.getExpandedColumns();
assertNotNull(columns);
assertEquals(12, columns.size());
assertTrue(columns.get(0) instanceof RowNumberCol52);
assertTrue(columns.get(1) instanceof DescriptionCol52);
assertTrue(columns.get(2) instanceof AttributeCol52);
assertTrue(columns.get(3) instanceof AttributeCol52);
assertTrue(columns.get(4) instanceof AttributeCol52);
assertTrue(columns.get(5) instanceof AttributeCol52);
assertTrue(columns.get(6) instanceof AttributeCol52);
assertTrue(columns.get(7) instanceof AttributeCol52);
assertTrue(columns.get(8) instanceof AttributeCol52);
assertTrue(columns.get(9) instanceof AttributeCol52);
assertTrue(columns.get(10) instanceof AttributeCol52);
assertTrue(columns.get(11) instanceof AttributeCol52);
// Check individual attributes
AttributeCol52 attrCol2 = ((AttributeCol52) columns.get(2));
assertEquals(GuidedDecisionTable52.SALIENCE_ATTR, attrCol2.getAttribute());
assertFalse(attrCol2.isUseRowNumber());
assertFalse(attrCol2.isReverseOrder());
AttributeCol52 attrCol3 = ((AttributeCol52) columns.get(3));
assertEquals(GuidedDecisionTable52.ACTIVATION_GROUP_ATTR, attrCol3.getAttribute());
AttributeCol52 attrCol4 = ((AttributeCol52) columns.get(4));
assertEquals(GuidedDecisionTable52.DURATION_ATTR, attrCol4.getAttribute());
AttributeCol52 attrCol5 = ((AttributeCol52) columns.get(5));
assertEquals(GuidedDecisionTable52.TIMER_ATTR, attrCol5.getAttribute());
AttributeCol52 attrCol6 = ((AttributeCol52) columns.get(6));
assertEquals(GuidedDecisionTable52.CALENDARS_ATTR, attrCol6.getAttribute());
AttributeCol52 attrCol7 = ((AttributeCol52) columns.get(7));
assertEquals(GuidedDecisionTable52.NO_LOOP_ATTR, attrCol7.getAttribute());
AttributeCol52 attrCol8 = ((AttributeCol52) columns.get(8));
assertEquals(GuidedDecisionTable52.LOCK_ON_ACTIVE_ATTR, attrCol8.getAttribute());
AttributeCol52 attrCol9 = ((AttributeCol52) columns.get(9));
assertEquals(GuidedDecisionTable52.AUTO_FOCUS_ATTR, attrCol9.getAttribute());
AttributeCol52 attrCol10 = ((AttributeCol52) columns.get(10));
assertEquals(GuidedDecisionTable52.AGENDA_GROUP_ATTR, attrCol10.getAttribute());
AttributeCol52 attrCol11 = ((AttributeCol52) columns.get(11));
assertEquals(GuidedDecisionTable52.RULEFLOW_GROUP_ATTR, attrCol11.getAttribute());
// Check data
assertEquals(2, dtable.getData().size());
assertTrue(isRowEquivalent(new Object[] { 1, "Specific rule 1", 1, "g1", 100l, "T1", "CAL1", true, true, true, "AG1", "RFG1" }, dtable.getData().get(0)));
assertTrue(isRowEquivalent(new Object[] { 2, "Specific rule 2", 2, "g2", 200l, "T2", "CAL2", false, false, false, "AG2", "RFG2" }, dtable.getData().get(1)));
}
use of org.drools.decisiontable.parser.xls.ExcelParser in project drools-wb by kiegroup.
the class GuidedDecisionTableGeneratorListenerTest method testSalienceWarnings.
@Test
public void testSalienceWarnings() {
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("SalienceWarnings.xls");
try {
parser.parseFile(is);
} finally {
try {
is.close();
} catch (IOException ioe) {
fail(ioe.getMessage());
}
}
// Check conversion results
assertEquals(2, result.getMessages().size());
assertEquals(ConversionMessageType.WARNING, result.getMessages().get(0).getMessageType());
assertFalse(result.getMessages().get(0).getMessage().indexOf("Priority is not an integer literal, in cell C7") == -1);
assertEquals(ConversionMessageType.WARNING, result.getMessages().get(1).getMessageType());
assertFalse(result.getMessages().get(1).getMessage().indexOf("Priority is not an integer literal, in cell C8") == -1);
// Check basics
List<GuidedDecisionTable52> dtables = listener.getGuidedDecisionTables();
assertNotNull(dtables);
assertEquals(1, dtables.size());
GuidedDecisionTable52 dtable = dtables.get(0);
assertEquals("SalienceWarningsTest", 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());
assertFalse(attrCol2.isUseRowNumber());
assertFalse(attrCol2.isReverseOrder());
// Check data
assertEquals(2, dtable.getData().size());
assertTrue(isRowEquivalent(new Object[] { 1, "Rule 1", 0 }, dtable.getData().get(0)));
assertTrue(isRowEquivalent(new Object[] { 2, "Rule 2", 0 }, dtable.getData().get(1)));
}
use of org.drools.decisiontable.parser.xls.ExcelParser in project drools-wb by kiegroup.
the class GuidedDecisionTableGeneratorListenerTest method testMultipleSingleParameters.
@Test
public void testMultipleSingleParameters() {
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("MultipleSingleParameters.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("MultipleSingleParameters", 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 BRLConditionVariableColumn);
// Check individual condition columns
assertEquals(1, dtable.getConditions().size());
assertTrue(dtable.getConditions().get(0) instanceof BRLConditionColumn);
// Column 1
BRLConditionColumn conditionCol0 = ((BRLConditionColumn) dtable.getConditions().get(0));
assertEquals("Converted from ['Re-using single parameter']", conditionCol0.getHeader());
assertEquals(1, conditionCol0.getChildColumns().size());
List<IPattern> conditionCol0definition = conditionCol0.getDefinition();
assertEquals(1, conditionCol0definition.size());
assertTrue(conditionCol0definition.get(0) instanceof FreeFormLine);
FreeFormLine conditionCol0ffl = (FreeFormLine) conditionCol0definition.get(0);
assertEquals("Driver(@{param1} != null, @{param1} == true)", conditionCol0ffl.getText());
// Column 1 - Variable 1
BRLConditionVariableColumn conditionCol0param0 = conditionCol0.getChildColumns().get(0);
assertEquals("param1", conditionCol0param0.getVarName());
assertEquals("Re-using single parameter", conditionCol0param0.getHeader());
assertEquals(DataType.TYPE_OBJECT, conditionCol0param0.getFieldType());
assertNull(conditionCol0param0.getFactType());
assertNull(conditionCol0param0.getFactField());
// Check data
assertEquals(2, dtable.getData().size());
assertTrue(isRowEquivalent(new Object[] { 1, "Row 1", "isQualified" }, dtable.getData().get(0)));
assertTrue(isRowEquivalent(new Object[] { 2, "Row 2", "isLicensed" }, dtable.getData().get(1)));
}
use of org.drools.decisiontable.parser.xls.ExcelParser in project drools-wb by kiegroup.
the class GuidedDecisionTableGeneratorListenerTest method testMissingTemplateKeyValues_RHSInsertThenUpdate.
@Test
public // https://issues.jboss.org/browse/GUVNOR-2030
void testMissingTemplateKeyValues_RHSInsertThenUpdate() {
final ConversionResult result = new ConversionResult();
final List<DataListener> listeners = new ArrayList<DataListener>();
addModelField("org.test.Transaction", "this", "org.test.Transaction", DataType.TYPE_THIS);
addModelField("org.test.Transaction", "enabled", Boolean.class.getName(), DataType.TYPE_BOOLEAN);
final GuidedDecisionTableGeneratorListener listener = new GuidedDecisionTableGeneratorListener(result, dmo);
listeners.add(listener);
// Convert
final ExcelParser parser = new ExcelParser(listeners);
final InputStream is = this.getClass().getResourceAsStream("GUVNOR-2030 (RHS insert then update).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
final List<GuidedDecisionTable52> dtables = listener.getGuidedDecisionTables();
assertNotNull(dtables);
assertEquals(1, dtables.size());
GuidedDecisionTable52 dtable = dtables.get(0);
assertEquals("asd", dtable.getTableName());
assertEquals(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY, dtable.getTableFormat());
// Check expanded columns
List<BaseColumn> columns = dtable.getExpandedColumns();
assertNotNull(columns);
assertEquals(6, columns.size());
assertTrue(columns.get(0) instanceof RowNumberCol52);
assertTrue(columns.get(1) instanceof DescriptionCol52);
assertTrue(columns.get(2) instanceof BRLConditionVariableColumn);
assertTrue(columns.get(3) instanceof BRLActionVariableColumn);
assertTrue(columns.get(4) instanceof BRLActionVariableColumn);
assertTrue(columns.get(5) instanceof BRLActionVariableColumn);
// Check individual condition columns
assertEquals(1, dtable.getConditions().size());
assertTrue(dtable.getConditions().get(0) instanceof BRLConditionColumn);
// Column 1
BRLConditionColumn conditionCol0 = ((BRLConditionColumn) dtable.getConditions().get(0));
assertEquals("Converted from ['Disabled']", conditionCol0.getHeader());
assertEquals(1, conditionCol0.getChildColumns().size());
List<IPattern> conditionCol0definition = conditionCol0.getDefinition();
assertEquals(1, conditionCol0definition.size());
assertTrue(conditionCol0definition.get(0) instanceof FactPattern);
FactPattern conditionCol0fp = (FactPattern) conditionCol0definition.get(0);
assertEquals("Transaction", conditionCol0fp.getFactType());
assertEquals(1, conditionCol0fp.getNumberOfConstraints());
assertTrue(conditionCol0fp.getConstraint(0) instanceof SingleFieldConstraint);
final SingleFieldConstraint conditionCol0fpsfc0 = (SingleFieldConstraint) conditionCol0fp.getConstraint(0);
assertEquals("enabled", conditionCol0fpsfc0.getFieldName());
assertEquals("==", conditionCol0fpsfc0.getOperator());
assertEquals("param1", conditionCol0fpsfc0.getValue());
assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0fpsfc0.getConstraintValueType());
assertEquals(DataType.TYPE_BOOLEAN, conditionCol0fpsfc0.getFieldType());
// Column 1 - Variable 1
BRLConditionVariableColumn conditionCol0param0 = conditionCol0.getChildColumns().get(0);
assertEquals("param1", conditionCol0param0.getVarName());
assertEquals("Disabled", conditionCol0param0.getHeader());
assertEquals(DataType.TYPE_BOOLEAN, conditionCol0param0.getFieldType());
assertEquals("Transaction", conditionCol0param0.getFactType());
assertEquals("enabled", conditionCol0param0.getFactField());
// Check individual action columns
assertEquals(3, dtable.getActionCols().size());
assertTrue(dtable.getActionCols().get(0) instanceof BRLActionColumn);
// Column 2
BRLActionColumn actionCol0 = ((BRLActionColumn) dtable.getActionCols().get(0));
assertEquals("Converted from ['Enable']", actionCol0.getHeader());
assertEquals(1, actionCol0.getChildColumns().size());
List<IAction> actionCol0definition = actionCol0.getDefinition();
assertEquals(1, actionCol0definition.size());
assertTrue(actionCol0definition.get(0) instanceof ActionSetField);
ActionSetField actionCol0asf0 = (ActionSetField) actionCol0definition.get(0);
assertEquals("$t", actionCol0asf0.getVariable());
ActionFieldValue[] actionCol0asf0afvs = actionCol0asf0.getFieldValues();
assertEquals(1, actionCol0asf0afvs.length);
ActionFieldValue actionCol0asf0afv0 = actionCol0asf0afvs[0];
assertEquals("enabled", actionCol0asf0afv0.getField());
assertEquals("param2", actionCol0asf0afv0.getValue());
assertEquals(FieldNatureType.TYPE_TEMPLATE, actionCol0asf0afv0.getNature());
assertEquals(DataType.TYPE_BOOLEAN, actionCol0asf0afv0.getType());
// Column 3
BRLActionColumn actionCol1 = ((BRLActionColumn) dtable.getActionCols().get(1));
assertEquals("Converted from ['New']", actionCol1.getHeader());
assertEquals(1, actionCol1.getChildColumns().size());
List<IAction> actionCol1definition = actionCol1.getDefinition();
assertEquals(1, actionCol1definition.size());
assertTrue(actionCol1definition.get(0) instanceof ActionInsertFact);
ActionInsertFact actionCol1aif0 = (ActionInsertFact) actionCol1definition.get(0);
assertEquals("$t2", actionCol1aif0.getBoundName());
assertEquals("Transaction", actionCol1aif0.getFactType());
ActionFieldValue[] actionCol1aif0afvs = actionCol1aif0.getFieldValues();
assertEquals(0, actionCol1aif0afvs.length);
// Column 4
BRLActionColumn actionCol2 = ((BRLActionColumn) dtable.getActionCols().get(2));
assertEquals("Converted from ['Disable']", actionCol2.getHeader());
assertEquals(1, actionCol2.getChildColumns().size());
List<IAction> actionCol2definition = actionCol2.getDefinition();
assertEquals(1, actionCol2definition.size());
assertTrue(actionCol2definition.get(0) instanceof ActionSetField);
ActionSetField actionCol2asf0 = (ActionSetField) actionCol2definition.get(0);
assertEquals("$t2", actionCol2asf0.getVariable());
ActionFieldValue[] actionCol2asf0afvs = actionCol2asf0.getFieldValues();
assertEquals(1, actionCol2asf0afvs.length);
ActionFieldValue actionCol2asf0afv0 = actionCol2asf0afvs[0];
assertEquals("enabled", actionCol2asf0afv0.getField());
assertEquals("param3", actionCol2asf0afv0.getValue());
assertEquals(FieldNatureType.TYPE_TEMPLATE, actionCol2asf0afv0.getNature());
assertEquals(DataType.TYPE_BOOLEAN, actionCol2asf0afv0.getType());
// Check data
assertEquals(1, dtable.getData().size());
assertTrue(isRowEquivalent(new Object[] { 1, "asd", false, true, false, false }, dtable.getData().get(0)));
}
use of org.drools.decisiontable.parser.xls.ExcelParser in project drools-wb by kiegroup.
the class GuidedDecisionTableGeneratorListenerTest method conversionWithBigIntegers.
@Test
public // https://issues.jboss.org/browse/RHBPMS-4737
void conversionWithBigIntegers() {
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_BIGINTEGER);
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 (BigInteger).xlsx");
try {
parser.parseFile(is);
} finally {
try {
is.close();
} catch (IOException ioe) {
fail(ioe.getMessage());
}
}
checkConversionWithBigMaths(result, listener, () -> DataType.TYPE_NUMERIC_BIGINTEGER, () -> new BigInteger("10"), () -> new BigInteger("20"));
}
Aggregations