Search in sources :

Example 71 with HasExpression

use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.

the class DMNEditBusinessKnowledgeModelToolboxActionTest method testActionSetExpression.

@Test
public void testActionSetExpression() {
    tested.onMouseClick(canvasHandler, E_UUID, mouseClickEvent);
    final ArgumentCaptor<EditExpressionEvent> eventCaptor = ArgumentCaptor.forClass(EditExpressionEvent.class);
    verify(editExpressionEvent, times(1)).fire(eventCaptor.capture());
    final EditExpressionEvent editExprEvent = eventCaptor.getValue();
    final HasExpression hasExpression = editExprEvent.getHasExpression();
    Assertions.assertThatThrownBy(() -> hasExpression.setExpression(new DecisionTable())).isInstanceOf(UnsupportedOperationException.class).hasMessage("It is not possible to set the EncapsulatedLogic of a BusinessKnowledgeModel.");
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) EditExpressionEvent(org.kie.workbench.common.dmn.client.events.EditExpressionEvent) Test(org.junit.Test)

Example 72 with HasExpression

use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.

the class DMNEditBusinessKnowledgeModelToolboxActionTest method testActionWhenIsReadOnlyDiagram.

@Test
public void testActionWhenIsReadOnlyDiagram() {
    when(readOnlyProvider.isReadOnlyDiagram()).thenReturn(true);
    final ToolboxAction<AbstractCanvasHandler> cascade = tested.onMouseClick(canvasHandler, E_UUID, mouseClickEvent);
    assertEquals(tested, cascade);
    final ArgumentCaptor<EditExpressionEvent> eventCaptor = ArgumentCaptor.forClass(EditExpressionEvent.class);
    verify(editExpressionEvent, times(1)).fire(eventCaptor.capture());
    final EditExpressionEvent editExprEvent = eventCaptor.getValue();
    assertEquals(E_UUID, editExprEvent.getNodeUUID());
    final HasExpression hasExpression = editExprEvent.getHasExpression();
    assertEquals(bkm.getEncapsulatedLogic(), hasExpression.getExpression());
    assertEquals(bkm, hasExpression.asDMNModelInstrumentedBase());
    assertFalse(hasExpression.isClearSupported());
    assertEquals(bkm, editExprEvent.getHasName().get());
    assertEquals(session, editExprEvent.getSession());
    assertTrue(editExprEvent.isOnlyVisualChangeAllowed());
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) EditExpressionEvent(org.kie.workbench.common.dmn.client.events.EditExpressionEvent) Test(org.junit.Test)

Example 73 with HasExpression

use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.

the class DeleteListRowCommandTest method testGraphCommandExecuteRemoveMiddle.

@Test
public void testGraphCommandExecuteRemoveMiddle() {
    uiModel.appendRow(new BaseGridRow());
    uiModel.appendRow(new BaseGridRow());
    final HasExpression firstRow = HasExpression.wrap(list, new LiteralExpression());
    final HasExpression lastRow = HasExpression.wrap(list, new LiteralExpression());
    list.getExpression().add(0, firstRow);
    list.getExpression().add(lastRow);
    makeCommand(1);
    final Command<GraphCommandExecutionContext, RuleViolation> c = command.newGraphCommand(handler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, c.execute(gce));
    assertEquals(2, list.getExpression().size());
    assertEquals(firstRow, list.getExpression().get(0));
    assertEquals(lastRow, list.getExpression().get(1));
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Test(org.junit.Test)

Example 74 with HasExpression

use of org.kie.workbench.common.dmn.api.definition.HasExpression 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));
}
Also used : LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) HasName(org.kie.workbench.common.dmn.api.definition.HasName) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) Test(org.junit.Test)

Example 75 with HasExpression

use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.

the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenDecisionTypeRefIsStructureAndOneSubfieldIsStructure.

@Test
public void testModelEnrichmentWhenDecisionTypeRefIsStructureAndOneSubfieldIsStructure() {
    final DMNGraphUtils dmnGraphUtils = mock(DMNGraphUtils.class);
    final Definitions definitions = mock(Definitions.class);
    final HasExpression hasExpression = mock(HasExpression.class);
    final Decision decision = mock(Decision.class);
    final InformationItemPrimary informationItemPrimary = mock(InformationItemPrimary.class);
    final ItemDefinition tCompany = mockTCompanyStructure();
    when(dmnGraphUtils.getModelDefinitions()).thenReturn(definitions);
    when(definitions.getItemDefinition()).thenReturn(Collections.singletonList(tCompany));
    when(hasExpression.asDMNModelInstrumentedBase()).thenReturn(decision);
    when(decision.getVariable()).thenReturn(informationItemPrimary);
    when(informationItemPrimary.getTypeRef()).thenReturn(new QName("", TYPE_COMPANY));
    final DecisionTableEditorDefinitionEnricher enricher = new DecisionTableEditorDefinitionEnricher(null, dmnGraphUtils, itemDefinitionUtils);
    final Optional<DecisionTable> oModel = definition.getModelClass();
    final DecisionTable model = oModel.get();
    enricher.buildOutputClausesByDataType(hasExpression, model, new DecisionRule());
    final List<OutputClause> outputClauses = model.getOutput();
    assertThat(outputClauses.size()).isEqualTo(2);
    final OutputClause outputClause1 = outputClauses.get(0);
    final OutputClause outputClause2 = outputClauses.get(1);
    assertEquals("address", outputClause1.getName());
    assertEquals(ANY.asQName(), outputClause1.getTypeRef());
    assertEquals("name", outputClause2.getName());
    assertEquals(STRING.asQName(), outputClause2.getTypeRef());
}
Also used : InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) DMNGraphUtils(org.kie.workbench.common.dmn.client.graph.DMNGraphUtils) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) Test(org.junit.Test)

Aggregations

HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)78 Test (org.junit.Test)41 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)30 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)24 HasName (org.kie.workbench.common.dmn.api.definition.HasName)18 BaseExpressionGrid (org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid)15 BaseUIModelMapper (org.kie.workbench.common.dmn.client.widgets.grid.model.BaseUIModelMapper)15 GridCellTuple (org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple)15 GridData (org.uberfire.ext.wires.core.grids.client.model.GridData)15 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)13 Optional (java.util.Optional)12 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)12 View (org.kie.workbench.common.stunner.core.graph.content.view.View)12 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)10 GridWidget (org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget)10 ExpressionEditorDefinition (org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinition)8 ExpressionEditorDefinitions (org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinitions)8 ArrayList (java.util.ArrayList)7 EditExpressionEvent (org.kie.workbench.common.dmn.client.events.EditExpressionEvent)6 Before (org.junit.Before)5