Search in sources :

Example 66 with HasExpression

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

the class DMNDocumentationDRDsFactoryTest method testGetNodeImage.

@Test
public void testGetNodeImage() {
    final String uuid = "0000-1111-2222-3333";
    final Node<View, Edge> node = new NodeImpl<>(uuid);
    final HasExpression hasExpression = mock(HasExpression.class);
    final String expectedImage = "<image>";
    final double wide = 800;
    final double high = 600;
    doNothing().when(factory).setExpressionContainerGrid(any(), any());
    when(expressionHelper.getOptionalHasExpression(node)).thenReturn(Optional.of(hasExpression));
    when(expressionContainerGrid.getWidth()).thenReturn(wide);
    when(expressionContainerGrid.getHeight()).thenReturn(high);
    when(viewport.toDataURL(DataURLType.PNG)).thenReturn(expectedImage);
    final String actualImage = factory.getNodeImage(diagram, node);
    verify(viewport).setPixelSize(810, 610);
    verify(factory).setExpressionContainerGrid(diagram, uuid);
    assertEquals(expectedImage, actualImage);
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) ExpressionEditorView(org.kie.workbench.common.dmn.client.editors.expressions.ExpressionEditorView) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 67 with HasExpression

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

the class DMNDocumentationDRDsFactoryTest method testCreate.

@Test
public void testCreate() {
    final String nodeUUID1 = "1111-1111-1111-1111";
    final String nodeUUID2 = "2222-2222-2222-2222";
    final Node<View, Edge> node1 = new NodeImpl<>(nodeUUID1);
    final Node<View, Edge> node2 = new NodeImpl<>(nodeUUID2);
    final View view1 = mock(View.class);
    final View view2 = mock(View.class);
    final HasExpression hasExpression1 = mock(HasExpression.class);
    final List<Node<View, Edge>> nodes = asList(node1, node2);
    final Decision drgElement1 = new Decision();
    final InputData drgElement2 = new InputData();
    final String name1 = "Decision-1";
    final String name2 = "Input-data-2";
    final String description1 = "Description...";
    final InformationItemPrimary variable1 = new InformationItemPrimary();
    final QName typeRef1 = BOOLEAN.asQName();
    final String image1 = "<image1>";
    final DMNExternalLink externalLink = new DMNExternalLink();
    final DocumentationLinksHolder linksHolder = new DocumentationLinksHolder();
    linksHolder.getValue().addLink(externalLink);
    drgElement2.setLinksHolder(linksHolder);
    node1.setContent(view1);
    node2.setContent(view2);
    when(view1.getDefinition()).thenReturn(drgElement1);
    when(view2.getDefinition()).thenReturn(drgElement2);
    when(expressionHelper.getOptionalHasExpression(node1)).thenReturn(Optional.ofNullable(hasExpression1));
    when(expressionHelper.getOptionalHasExpression(node2)).thenReturn(Optional.empty());
    when(expressionContainerGrid.getNodeUUID()).thenReturn(Optional.of(nodeUUID2));
    when(graph.nodes()).thenReturn(nodes);
    doReturn(image1).when(factory).getNodeImage(diagram, node1);
    doNothing().when(factory).setExpressionContainerGrid(any(), any());
    variable1.setTypeRef(typeRef1);
    drgElement1.setVariable(variable1);
    drgElement1.setDescription(new Description(description1));
    drgElement1.setName(new Name(name1));
    drgElement2.setName(new Name(name2));
    final List<DMNDocumentationDRD> drds = factory.create(diagram);
    final DMNDocumentationDRD documentationDRD1 = drds.get(0);
    final DMNDocumentationDRD documentationDRD2 = drds.get(1);
    assertEquals(2, drds.size());
    assertEquals(name1, documentationDRD1.getDrdName());
    assertEquals(BOOLEAN.getName(), documentationDRD1.getDrdType());
    assertEquals(description1, documentationDRD1.getDrdDescription());
    assertEquals(image1, documentationDRD1.getDrdBoxedExpressionImage());
    assertEquals(NONE, documentationDRD2.getDrdDescription());
    assertEquals(UNDEFINED.getName(), documentationDRD2.getDrdType());
    assertEquals(name2, documentationDRD2.getDrdName());
    assertEquals(NONE, documentationDRD2.getDrdBoxedExpressionImage());
    assertFalse(documentationDRD1.getHasExternalLinks());
    assertTrue(documentationDRD2.getHasExternalLinks());
    verify(factory).setExpressionContainerGrid(diagram, nodeUUID2);
}
Also used : InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Node(org.kie.workbench.common.stunner.core.graph.Node) DocumentationLinksHolder(org.kie.workbench.common.dmn.api.property.dmn.DocumentationLinksHolder) ExpressionEditorView(org.kie.workbench.common.dmn.client.editors.expressions.ExpressionEditorView) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) Edge(org.kie.workbench.common.stunner.core.graph.Edge) DMNExternalLink(org.kie.workbench.common.dmn.api.property.dmn.DMNExternalLink) Test(org.junit.Test)

Example 68 with HasExpression

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

the class ExpressionContainerUIModelMapperTest method setup.

@SuppressWarnings("unchecked")
public void setup(final boolean isOnlyVisualChangeAllowed) {
    uiModel = new BaseGridData();
    uiModel.appendRow(new BaseGridRow());
    uiModel.appendColumn(uiExpressionColumn);
    when(uiExpressionColumn.getIndex()).thenReturn(0);
    when(uiExpressionColumn.getMinimumWidth()).thenReturn(MINIMUM_COLUMN_WIDTH);
    parent = new GridCellTuple(0, 0, expressionContainerGrid);
    final ExpressionEditorDefinitions expressionEditorDefinitions = new ExpressionEditorDefinitions();
    expressionEditorDefinitions.add(literalExpressionEditorDefinition);
    expressionEditorDefinitions.add(undefinedExpressionEditorDefinition);
    when(expressionEditorDefinitionsSupplier.get()).thenReturn(expressionEditorDefinitions);
    when(literalExpressionEditorDefinition.getModelClass()).thenReturn(Optional.of(literalExpression));
    when(literalExpressionEditor.isCacheable()).thenReturn(true);
    when(literalExpressionEditor.getExpression()).thenReturn(() -> Optional.of(literalExpression));
    when(literalExpressionEditorDefinition.getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt())).thenReturn(Optional.of(literalExpressionEditor));
    when(undefinedExpressionEditorDefinition.getModelClass()).thenReturn(Optional.empty());
    when(undefinedExpressionEditorDefinition.getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt())).thenReturn(Optional.of(undefinedExpressionEditor));
    expressionGridCache = spy(new ExpressionGridCacheImpl());
    mapper = new ExpressionContainerUIModelMapper(parent, () -> uiModel, () -> Optional.ofNullable(expression), () -> NODE_UUID, () -> hasExpression, () -> Optional.of(hasName), () -> isOnlyVisualChangeAllowed, expressionEditorDefinitionsSupplier, () -> expressionGridCache, listSelector);
}
Also used : ExpressionEditorDefinitions(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinitions) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) Optional(java.util.Optional) ExpressionGridCacheImpl(org.kie.workbench.common.dmn.client.widgets.grid.ExpressionGridCacheImpl) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData)

Example 69 with HasExpression

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

the class BoxedExpressionHelperTest method testGetHasExpression.

@Test
public void testGetHasExpression() {
    final View content = mock(View.class);
    final Decision expected = mock(Decision.class);
    when(node.getContent()).thenReturn(content);
    when(content.getDefinition()).thenReturn(expected);
    final HasExpression actual = helper.getHasExpression(node);
    assertEquals(expected, actual);
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) Test(org.junit.Test)

Example 70 with HasExpression

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

the class BoxedExpressionHelperTest method testGetOptionalHasExpressionWhenNodeIsDecision.

@Test
public void testGetOptionalHasExpressionWhenNodeIsDecision() {
    final View content = mock(View.class);
    final Decision expectedHasExpression = mock(Decision.class);
    when(node.getContent()).thenReturn(content);
    when(content.getDefinition()).thenReturn(expectedHasExpression);
    final Optional<HasExpression> actualHasExpression = helper.getOptionalHasExpression(node);
    assertTrue(actualHasExpression.isPresent());
    assertEquals(expectedHasExpression, actualHasExpression.get());
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) 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