use of org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinition method getModelClass.
@Override
public Optional<DecisionTable> getModelClass() {
final DecisionTable dtable = new DecisionTable();
dtable.setHitPolicy(HitPolicy.ANY);
dtable.setPreferredOrientation(DecisionTableOrientation.RULE_AS_ROW);
final InputClause ic = new InputClause();
final LiteralExpression le = new LiteralExpression();
le.setText(INPUT_CLAUSE_EXPRESSION_TEXT);
ic.setInputExpression(le);
dtable.getInput().add(ic);
final OutputClause oc = new OutputClause();
oc.setName(OUTPUT_CLAUSE_NAME);
dtable.getOutput().add(oc);
final DecisionRule dr = new DecisionRule();
final UnaryTests drut = new UnaryTests();
drut.setText(INPUT_CLAUSE_UNARY_TEST_TEXT);
dr.getInputEntry().add(drut);
final LiteralExpression drle = new LiteralExpression();
drle.setText(OUTPUT_CLAUSE_EXPRESSION_TEXT);
dr.getOutputEntry().add(drle);
final Description d = new Description();
d.setValue(RULE_DESCRIPTION);
dr.setDescription(d);
dtable.getRule().add(dr);
return Optional.of(dtable);
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionTest method testModelDefinition.
@Test
public void testModelDefinition() {
final Optional<DecisionTable> oModel = definition.getModelClass();
assertThat(oModel).isPresent();
final DecisionTable model = oModel.get();
assertThat(model.getHitPolicy()).isEqualTo(HitPolicy.ANY);
assertThat(model.getPreferredOrientation()).isEqualTo(DecisionTableOrientation.RULE_AS_ROW);
final List<InputClause> input = model.getInput();
assertThat(input.size()).isEqualTo(1);
assertThat(input.get(0).getInputExpression()).isInstanceOf(LiteralExpression.class);
final List<OutputClause> output = model.getOutput();
assertThat(output.size()).isEqualTo(1);
final List<DecisionRule> rules = model.getRule();
assertThat(rules.size()).isEqualTo(1);
final DecisionRule rule = rules.get(0);
assertThat(rule.getInputEntry().size()).isEqualTo(1);
assertThat(rule.getInputEntry().get(0)).isInstanceOf(UnaryTests.class);
assertThat(rule.getOutputEntry().size()).isEqualTo(1);
assertThat(rule.getOutputEntry().get(0)).isInstanceOf(LiteralExpression.class);
assertThat(rule.getDescription()).isNotNull();
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule in project kie-wb-common by kiegroup.
the class DecisionTableUIModelMapperTest method setup.
@Before
@SuppressWarnings("unchecked")
public void setup() {
this.uiModel = new BaseGridData();
this.uiModel.appendRow(new DMNGridRow());
this.uiModel.appendRow(new DMNGridRow());
this.uiModel.appendColumn(uiRowNumberColumn);
this.uiModel.appendColumn(uiInputClauseColumn);
this.uiModel.appendColumn(uiOutputClauseColumn);
this.uiModel.appendColumn(uiDescriptionColumn);
doReturn(0).when(uiRowNumberColumn).getIndex();
doReturn(1).when(uiInputClauseColumn).getIndex();
doReturn(2).when(uiOutputClauseColumn).getIndex();
doReturn(3).when(uiDescriptionColumn).getIndex();
this.dtable = new DecisionTable();
this.dtable.getInput().add(new InputClause());
this.dtable.getOutput().add(new OutputClause());
this.dtable.getRule().add(new DecisionRule() {
{
getInputEntry().add(new UnaryTests() {
{
setText("i1");
}
});
getOutputEntry().add(new LiteralExpression() {
{
setText("o1");
}
});
setDescription(new Description("desc1"));
}
});
this.dtable.getRule().add(new DecisionRule() {
{
getInputEntry().add(new UnaryTests() {
{
setText("i2");
}
});
getOutputEntry().add(new LiteralExpression() {
{
setText("o2");
}
});
setDescription(new Description("desc2"));
}
});
this.mapper = new DecisionTableUIModelMapper(() -> uiModel, () -> Optional.of(dtable), listSelector);
this.cellValueSupplier = Optional::empty;
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule in project kie-wb-common by kiegroup.
the class AddDecisionRuleCommandTest method testCanvasCommandExecuteInsertBelowThenUndo.
@Test
public void testCanvasCommandExecuteInsertBelowThenUndo() {
// The default behaviour of tests in this class is to "insert above"
final DecisionRule existingRule = new DecisionRule();
final DMNGridRow existingUiRow = new DMNGridRow();
dtable.getRule().add(existingRule);
uiModel.appendRow(existingUiRow);
makeCommand(1);
uiModel.appendColumn(uiInputClauseColumn);
uiModel.appendColumn(uiOutputClauseColumn);
uiModel.appendColumn(uiDescriptionColumn);
final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
final Command<AbstractCanvasHandler, CanvasViolation> canvasCommand = command.newCanvasCommand(canvasHandler);
graphCommand.execute(graphCommandExecutionContext);
canvasCommand.execute(canvasHandler);
canvasCommand.undo(canvasHandler);
assertEquals(1, uiModel.getRowCount());
assertEquals(existingUiRow, uiModel.getRow(0));
// one time in execute(), one time in undo()
verify(canvasOperation, times(2)).execute();
verify(command, times(2)).updateRowNumbers();
verify(command, times(2)).updateParentInformation();
}
use of org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule in project kie-wb-common by kiegroup.
the class AddDecisionRuleCommandTest method testGraphCommandExecuteInsertBelow.
@Test
public void testGraphCommandExecuteInsertBelow() {
// The default behaviour of tests in this class is to "insert above"
final DecisionRule existingRule = new DecisionRule();
dtable.getRule().add(existingRule);
makeCommand(1);
final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
graphCommand.execute(graphCommandExecutionContext);
assertEquals(2, dtable.getRule().size());
assertEquals(existingRule, dtable.getRule().get(0));
assertEquals(rule, dtable.getRule().get(1));
}
Aggregations