Search in sources :

Example 11 with Binding

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

the class AddParameterBindingCommandTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() {
    this.invocation = new Invocation();
    this.binding = new Binding();
    final InformationItem parameter = new InformationItem();
    parameter.setName(new Name("p" + invocation.getBinding().size()));
    this.binding.setParameter(parameter);
    this.uiModel = new BaseGridData(false);
    this.uiModelRow = new BaseGridRow();
    this.uiModel.appendColumn(uiRowNumberColumn);
    this.uiModel.appendColumn(uiNameColumn);
    this.uiModel.appendColumn(uiExpressionEditorColumn);
    this.uiModelMapper = new InvocationUIModelMapper(gridWidget, () -> uiModel, () -> Optional.of(invocation), () -> false, () -> expressionEditorDefinitions, listSelector, 0);
    doReturn(ruleManager).when(handler).getRuleManager();
    doReturn(0).when(uiRowNumberColumn).getIndex();
    doReturn(1).when(uiNameColumn).getIndex();
    doReturn(2).when(uiExpressionEditorColumn).getIndex();
    doReturn(uiModel).when(gridWidget).getModel();
    doReturn(Optional.empty()).when(expressionEditorDefinitions).getExpressionEditorDefinition(any(Optional.class));
}
Also used : Binding(org.kie.workbench.common.dmn.api.definition.model.Binding) Invocation(org.kie.workbench.common.dmn.api.definition.model.Invocation) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) Optional(java.util.Optional) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) InvocationUIModelMapper(org.kie.workbench.common.dmn.client.editors.expressions.types.invocation.InvocationUIModelMapper) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Before(org.junit.Before)

Example 12 with Binding

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

the class DeleteParameterBindingCommandTest method testCanvasCommandExecuteDeleteOneOfThree.

@Test
public void testCanvasCommandExecuteDeleteOneOfThree() {
    final Binding secondBinding = new Binding();
    final Binding thirdBinding = new Binding();
    invocation.getBinding().add(secondBinding);
    invocation.getBinding().add(thirdBinding);
    final BaseGridRow secondRow = new BaseGridRow();
    final BaseGridRow thirdRow = new BaseGridRow();
    uiModel.appendRow(secondRow);
    uiModel.appendRow(thirdRow);
    makeCommand(1);
    final Command<AbstractCanvasHandler, CanvasViolation> cc = command.newCanvasCommand(handler);
    assertEquals(CanvasCommandResultBuilder.SUCCESS, cc.execute(handler));
    assertEquals(2, uiModel.getRowCount());
    assertEquals(uiGridRow, uiModel.getRow(0));
    assertEquals(thirdRow, uiModel.getRow(1));
    assertEquals(3, uiModel.getColumnCount());
    assertEquals(uiRowNumberColumn, uiModel.getColumns().get(0));
    assertEquals(uiNameColumn, uiModel.getColumns().get(1));
    assertEquals(uiExpressionEditorColumn, uiModel.getColumns().get(2));
    verify(command).updateRowNumbers();
    verify(command).updateParentInformation();
    verify(canvasOperation).execute();
}
Also used : Binding(org.kie.workbench.common.dmn.api.definition.model.Binding) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Test(org.junit.Test)

Example 13 with Binding

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

the class BindingPropertyConverterTest method testWBFromDMN.

@Test
public void testWBFromDMN() {
    final org.kie.dmn.model.api.Binding dmn = new TBinding();
    final org.kie.dmn.model.api.InformationItem informationItem = new TInformationItem();
    dmn.setParameter(informationItem);
    final org.kie.dmn.model.api.LiteralExpression literalExpression = new TLiteralExpression();
    literalExpression.setId(EXPRESSION_UUID);
    dmn.setExpression(literalExpression);
    final Binding wb = BindingPropertyConverter.wbFromDMN(dmn, hasComponentWidthsConsumer);
    assertThat(wb).isNotNull();
    assertThat(wb.getParameter()).isNotNull();
    assertThat(wb.getExpression()).isNotNull();
    assertThat(wb.getExpression().getId().getValue()).isEqualTo(EXPRESSION_UUID);
    verify(hasComponentWidthsConsumer).accept(eq(EXPRESSION_UUID), hasComponentWidthsCaptor.capture());
    final HasComponentWidths hasComponentWidths = hasComponentWidthsCaptor.getValue();
    assertThat(hasComponentWidths).isNotNull();
    assertThat(hasComponentWidths).isEqualTo(wb.getExpression());
}
Also used : Binding(org.kie.workbench.common.dmn.api.definition.model.Binding) TBinding(org.kie.dmn.model.v1_2.TBinding) TBinding(org.kie.dmn.model.v1_2.TBinding) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) HasComponentWidths(org.kie.workbench.common.dmn.api.definition.HasComponentWidths) Test(org.junit.Test)

Example 14 with Binding

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

the class BindingPropertyConverterTest method testDMNFromWB.

@Test
public void testDMNFromWB() {
    final Binding wb = new Binding();
    final InformationItem informationItem = new InformationItem();
    wb.setParameter(informationItem);
    final LiteralExpression literalExpression = new LiteralExpression();
    literalExpression.getComponentWidths().set(0, 200.0);
    literalExpression.getId().setValue(EXPRESSION_UUID);
    wb.setExpression(literalExpression);
    final org.kie.dmn.model.api.Binding dmn = BindingPropertyConverter.dmnFromWB(wb, componentWidthsConsumer);
    assertThat(dmn).isNotNull();
    assertThat(dmn.getParameter()).isNotNull();
    assertThat(dmn.getExpression()).isNotNull();
    assertThat(dmn.getExpression().getId()).isEqualTo(EXPRESSION_UUID);
    verify(componentWidthsConsumer).accept(componentWidthsCaptor.capture());
    final ComponentWidths componentWidths = componentWidthsCaptor.getValue();
    assertThat(componentWidths).isNotNull();
    assertThat(componentWidths.getDmnElementRef().getLocalPart()).isEqualTo(EXPRESSION_UUID);
    assertThat(componentWidths.getWidths().size()).isEqualTo(literalExpression.getRequiredComponentWidthCount());
    assertThat(componentWidths.getWidths().get(0)).isEqualTo(200.0);
}
Also used : Binding(org.kie.workbench.common.dmn.api.definition.model.Binding) TBinding(org.kie.dmn.model.v1_2.TBinding) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) HasComponentWidths(org.kie.workbench.common.dmn.api.definition.HasComponentWidths) ComponentWidths(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ComponentWidths) Test(org.junit.Test)

Example 15 with Binding

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

the class InvocationEditorDefinition method enrich.

@Override
public void enrich(final Optional<String> nodeUUID, final HasExpression hasExpression, final Optional<Invocation> expression) {
    expression.ifPresent(invocation -> {
        final LiteralExpression literalExpression = new LiteralExpression();
        invocation.setExpression(literalExpression);
        final InformationItem parameter = new InformationItem();
        parameter.getName().setValue(InvocationDefaultValueUtilities.getNewParameterName(invocation));
        final Binding binding = new Binding();
        binding.setParameter(parameter);
        invocation.getBinding().add(binding);
        // Setup parent relationships
        literalExpression.setParent(invocation);
        binding.setParent(invocation);
        parameter.setParent(binding);
    });
}
Also used : Binding(org.kie.workbench.common.dmn.api.definition.model.Binding) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem)

Aggregations

Binding (org.kie.workbench.common.dmn.api.definition.model.Binding)26 Test (org.junit.Test)13 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)13 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)7 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)7 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)5 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)5 Invocation (org.kie.workbench.common.dmn.api.definition.model.Invocation)4 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)4 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)3 JSITBinding (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITBinding)3 JSITExpression (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression)3 Optional (java.util.Optional)2 TBinding (org.kie.dmn.model.v1_2.TBinding)2 TInformationItem (org.kie.dmn.model.v1_2.TInformationItem)2 TLiteralExpression (org.kie.dmn.model.v1_2.TLiteralExpression)2 HasComponentWidths (org.kie.workbench.common.dmn.api.definition.HasComponentWidths)2 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)2 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)2 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)2