use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpression in project kie-wb-common by kiegroup.
the class AddOutputClauseCommandTest method testGraphCommandExecuteInsertMiddle.
@Test
public void testGraphCommandExecuteInsertMiddle() throws Exception {
makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT + 1);
final String ruleOutputOne = "rule out 1";
final String ruleOutputTwo = "rule out 2";
dtable.getOutput().add(new OutputClause());
dtable.getOutput().add(new OutputClause());
addRuleWithOutputClauseValues(ruleOutputOne, ruleOutputTwo);
assertEquals(2, dtable.getOutput().size());
// Graph command will insert new OutputClause at index 1 of the OutputEntries
final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
assertEquals(3, dtable.getOutput().size());
assertNull(dtable.getOutput().get(0).getName());
assertEquals(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_PREFIX + "1", dtable.getOutput().get(1).getName());
assertNull(dtable.getOutput().get(2).getName());
final List<LiteralExpression> ruleOutputs = dtable.getRule().get(0).getOutputEntry();
// first rule
assertEquals(3, ruleOutputs.size());
assertEquals(ruleOutputOne, ruleOutputs.get(0).getText().getValue());
assertEquals(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_EXPRESSION_TEXT, ruleOutputs.get(1).getText().getValue());
assertEquals(dtable.getRule().get(0), ruleOutputs.get(1).getParent());
assertEquals(ruleOutputTwo, ruleOutputs.get(2).getText().getValue());
assertEquals(dtable, outputClause.getParent());
}
use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpression in project kie-wb-common by kiegroup.
the class ExpressionEditorViewImplTest method testSetExpressionDoesUpdateExpressionTypeTextWhenHasExpressionIsNotEmpty.
@Test
public void testSetExpressionDoesUpdateExpressionTypeTextWhenHasExpressionIsNotEmpty() {
final Expression expression = new LiteralExpression();
final Optional<HasName> hasName = Optional.empty();
when(hasExpression.getExpression()).thenReturn(expression);
view.setExpression(NODE_UUID, hasExpression, hasName, false);
verify(expressionType).setTextContent(eq(LITERAL_EXPRESSION_DEFINITION_NAME));
}
use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpression in project kie-wb-common by kiegroup.
the class ExpressionEditorViewImplTest method setup.
@Before
@SuppressWarnings("unchecked")
public void setup() {
this.expressionGridCache = new ExpressionGridCacheImpl();
this.gridPanelContainer = spy(new DMNGridPanelContainer());
when(sessionManager.getCurrentSession()).thenReturn(session);
when(session.getExpressionGridCache()).thenReturn(expressionGridCache);
when(session.getGridPanel()).thenReturn(gridPanel);
when(session.getGridLayer()).thenReturn(gridLayer);
when(session.getCellEditorControls()).thenReturn(cellEditorControls);
when(session.getMousePanMediator()).thenReturn(mousePanMediator);
doReturn(viewport).when(gridPanel).getViewport();
doReturn(viewportMediators).when(viewport).getMediators();
doReturn(gridPanelElement).when(gridPanel).getElement();
doReturn(Optional.of(editor)).when(editorDefinition).getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt());
doReturn(new BaseGridData()).when(editor).getModel();
this.view = spy(new ExpressionEditorViewImpl(returnToLink, expressionName, expressionType, gridPanelContainer, translationService, listSelector, sessionManager, sessionCommandManager, canvasCommandFactory, expressionEditorDefinitionsSupplier, refreshFormPropertiesEvent, domainObjectSelectionEvent));
view.init(presenter);
view.bind(session);
final ExpressionEditorDefinitions expressionEditorDefinitions = new ExpressionEditorDefinitions();
expressionEditorDefinitions.add(undefinedExpressionEditorDefinition);
expressionEditorDefinitions.add(literalExpressionEditorDefinition);
when(expressionEditorDefinitionsSupplier.get()).thenReturn(expressionEditorDefinitions);
when(undefinedExpressionEditorDefinition.getModelClass()).thenReturn(Optional.empty());
when(undefinedExpressionEditorDefinition.getName()).thenReturn(UNDEFINED_EXPRESSION_DEFINITION_NAME);
when(undefinedExpressionEditor.getModel()).thenReturn(new BaseGridData());
when(undefinedExpressionEditorDefinition.getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt())).thenReturn(Optional.of(undefinedExpressionEditor));
when(literalExpressionEditorDefinition.getModelClass()).thenReturn(Optional.of(new LiteralExpression()));
when(literalExpressionEditorDefinition.getName()).thenReturn(LITERAL_EXPRESSION_DEFINITION_NAME);
when(literalExpressionEditor.getModel()).thenReturn(new BaseGridData());
when(literalExpressionEditorDefinition.getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt())).thenReturn(Optional.of(literalExpressionEditor));
doAnswer((i) -> i.getArguments()[1]).when(translationService).format(Mockito.<String>any(), anyObject());
doAnswer((i) -> i.getArguments()[0]).when(translationService).getTranslation(Mockito.<String>any());
}
use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpression 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 BaseGridRow());
this.uiModel.appendRow(new BaseGridRow());
this.uiModel.appendColumn(uiRowNumberColumn);
this.uiModel.appendColumn(uiInputClauseColumn);
this.uiModel.appendColumn(uiOutputClauseColumn);
this.uiModel.appendColumn(uiAnnotationClauseColumn);
doReturn(0).when(uiRowNumberColumn).getIndex();
doReturn(1).when(uiInputClauseColumn).getIndex();
doReturn(2).when(uiOutputClauseColumn).getIndex();
doReturn(3).when(uiAnnotationClauseColumn).getIndex();
this.dtable = new DecisionTable();
this.dtable.getInput().add(new InputClause());
this.dtable.getOutput().add(new OutputClause());
this.dtable.getAnnotations().add(new RuleAnnotationClause());
this.dtable.getRule().add(new DecisionRule() {
{
getInputEntry().add(new UnaryTests() {
{
getText().setValue("i1");
}
});
getOutputEntry().add(new LiteralExpression() {
{
getText().setValue("o1");
}
});
getAnnotationEntry().add(new RuleAnnotationClauseText() {
{
getText().setValue("a1");
}
});
}
});
this.dtable.getRule().add(new DecisionRule() {
{
getInputEntry().add(new UnaryTests() {
{
getText().setValue("i2");
}
});
getOutputEntry().add(new LiteralExpression() {
{
getText().setValue("o2");
}
});
getAnnotationEntry().add(new RuleAnnotationClauseText() {
{
getText().setValue("a2");
}
});
}
});
this.mapper = new DecisionTableUIModelMapper(() -> uiModel, () -> Optional.of(dtable), listSelector, DEFAULT_HEIGHT);
}
use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpression in project kie-wb-common by kiegroup.
the class DecisionRuleFactoryTest method testMakeDecisionRule.
@Test
public void testMakeDecisionRule() {
final DecisionRule rule = DecisionRuleFactory.makeDecisionRule(dtable);
final List<UnaryTests> inputEntries = rule.getInputEntry();
assertThat(inputEntries.size()).isEqualTo(2);
assertThat(inputEntries).allSatisfy(unaryTests -> assertUnaryTestsText(unaryTests, DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT)).allSatisfy(unaryTests -> assertThat(unaryTests.getConstraintType()).isEqualTo(NONE)).allSatisfy(unaryTests -> assertThat(unaryTests.getParent()).isEqualTo(rule));
final List<LiteralExpression> outputEntries = rule.getOutputEntry();
assertThat(outputEntries.size()).isEqualTo(2);
assertThat(outputEntries).allSatisfy(literalExpression -> assertLiteralExpressionText(literalExpression, DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_EXPRESSION_TEXT)).allSatisfy(literalExpression -> assertThat(literalExpression.getParent()).isEqualTo(rule));
final List<RuleAnnotationClauseText> annotationEntries = rule.getAnnotationEntry();
assertThat(annotationEntries.size()).isEqualTo(2);
assertThat(annotationEntries).allSatisfy(clauseText -> assertAnnotationClauseText(clauseText, DecisionTableDefaultValueUtilities.RULE_ANNOTATION_CLAUSE_EXPRESSION_TEXT)).allSatisfy(clauseText -> assertThat(clauseText.getParent()).isEqualTo(rule));
assertThat(rule.getParent()).isEqualTo(dtable);
}
Aggregations