Search in sources :

Example 76 with Definition

use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.

the class BaseLiteralExpressionGridTest method setup.

@Before
public void setup() {
    when(sessionManager.getCurrentSession()).thenReturn(session);
    when(session.getGridPanel()).thenReturn(gridPanel);
    when(session.getGridLayer()).thenReturn(gridLayer);
    when(session.getCellEditorControls()).thenReturn(cellEditorControls);
    tupleWithoutValue = new GridCellTuple(0, 0, gridWidget);
    tupleWithValue = new GridCellValueTuple<>(0, 0, gridWidget, new BaseGridCellValue<>("value"));
    definition = getDefinition();
    final Decision decision = new Decision();
    decision.setName(new Name(NAME));
    hasName = Optional.of(decision);
    expression = definition.getModelClass();
    expression.ifPresent(e -> e.getText().setValue(EXPRESSION_TEXT));
    when(session.getCanvasHandler()).thenReturn(canvasHandler);
    when(gridLayer.getVisibleBounds()).thenReturn(mock(Bounds.class));
    when(gridWidget.getModel()).thenReturn(new BaseGridData(false));
    when(canvasHandler.getDiagram()).thenReturn(diagram);
    when(diagram.getGraph()).thenReturn(graph);
    when(graph.nodes()).thenReturn(Collections.singletonList(node));
    when(canvasHandler.getGraphIndex()).thenReturn(index);
    when(index.get(Mockito.<String>any())).thenReturn(element);
    when(element.getContent()).thenReturn(mock(Definition.class));
    when(definitionUtils.getNameIdentifier(any())).thenReturn("name");
    when(canvasCommandFactory.updatePropertyValue(any(Element.class), Mockito.<String>any(), any())).thenReturn(mock(UpdateElementPropertyCommand.class));
    parentGridWidget = getParentGridWidget();
    parentGridUiModel = getParentGridWidgetUiModel();
    when(parentGridWidget.getModel()).thenReturn(parentGridUiModel);
    when(parent.getGridWidget()).thenReturn(parentGridWidget);
    when(parent.getRowIndex()).thenReturn(PARENT_ROW_INDEX);
    when(parent.getColumnIndex()).thenReturn(PARENT_COLUMN_INDEX);
    doAnswer((i) -> i.getArguments()[0].toString()).when(translationService).getTranslation(Mockito.<String>any());
}
Also used : GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) Bounds(org.uberfire.ext.wires.core.grids.client.model.Bounds) Element(org.kie.workbench.common.stunner.core.graph.Element) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) BaseEditorDefinition(org.kie.workbench.common.dmn.client.editors.expressions.types.BaseEditorDefinition) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) UpdateElementPropertyCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPropertyCommand) BaseGridCellValue(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue) HasName(org.kie.workbench.common.dmn.api.definition.HasName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Before(org.junit.Before)

Example 77 with Definition

use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.

the class InvocationGridTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() {
    when(parent.getGridWidget()).thenReturn(parentGridWidget);
    when(parentGridWidget.getModel()).thenReturn(parentGridData);
    when(parentGridData.getColumns()).thenReturn(Collections.singletonList(parentGridColumn));
    when(sessionManager.getCurrentSession()).thenReturn(session);
    when(session.getGridPanel()).thenReturn(gridPanel);
    when(session.getGridLayer()).thenReturn(gridLayer);
    when(session.getCellEditorControls()).thenReturn(cellEditorControls);
    tupleWithoutValue = new GridCellTuple(0, 1, gridWidget);
    tupleWithValue = new GridCellValueTuple<>(0, 1, gridWidget, new BaseGridCellValue<>("value"));
    definition = new InvocationEditorDefinition(definitionUtils, sessionManager, sessionCommandManager, canvasCommandFactory, editorSelectedEvent, refreshFormPropertiesEvent, domainObjectSelectionEvent, listSelector, translationService, expressionEditorDefinitionsSupplier, headerEditor, readOnlyProvider);
    expression = definition.getModelClass();
    definition.enrich(Optional.empty(), hasExpression, expression);
    expression.ifPresent(invocation -> ((LiteralExpression) invocation.getExpression()).getText().setValue("invocation-expression"));
    final ExpressionEditorDefinitions expressionEditorDefinitions = new ExpressionEditorDefinitions();
    expressionEditorDefinitions.add((ExpressionEditorDefinition) definition);
    expressionEditorDefinitions.add(literalExpressionEditorDefinition);
    expressionEditorDefinitions.add(undefinedExpressionEditorDefinition);
    when(expressionEditorDefinitionsSupplier.get()).thenReturn(expressionEditorDefinitions);
    when(literalExpressionEditorDefinition.getModelClass()).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(undefinedExpressionEditor.getParentInformation()).thenReturn(parent);
    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));
    when(sessionManager.getCurrentSession()).thenReturn(session);
    when(session.getCanvasHandler()).thenReturn(canvasHandler);
    when(canvasHandler.getGraphExecutionContext()).thenReturn(graphContext);
    final Decision decision = new Decision();
    decision.setName(new Name("name"));
    hasName = Optional.of(decision);
    when(gridWidget.getModel()).thenReturn(new BaseGridData(false));
    when(gridLayer.getDomElementContainer()).thenReturn(gridLayerDomElementContainer);
    when(gridLayerDomElementContainer.iterator()).thenReturn(mock(Iterator.class));
    when(gridLayer.getVisibleBounds()).thenReturn(new BaseBounds(0, 0, 100, 200));
    when(gridLayer.getViewport()).thenReturn(viewport);
    when(viewport.getTransform()).thenReturn(transform);
    when(canvasHandler.getDiagram()).thenReturn(diagram);
    when(diagram.getGraph()).thenReturn(graph);
    when(graph.nodes()).thenReturn(Collections.singletonList(node));
    when(canvasHandler.getGraphIndex()).thenReturn(index);
    when(index.get(Mockito.<String>any())).thenReturn(element);
    when(element.getContent()).thenReturn(mock(Definition.class));
    when(definitionUtils.getNameIdentifier(any())).thenReturn("name");
    when(canvasCommandFactory.updatePropertyValue(any(Element.class), Mockito.<String>any(), any())).thenReturn(mock(UpdateElementPropertyCommand.class));
    doAnswer((i) -> i.getArguments()[0].toString()).when(translationService).format(Mockito.<String>any());
    doAnswer((i) -> i.getArguments()[0].toString()).when(translationService).getTranslation(Mockito.<String>any());
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Optional(java.util.Optional) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) Element(org.kie.workbench.common.stunner.core.graph.Element) ExpressionEditorDefinition(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinition) UndefinedExpressionEditorDefinition(org.kie.workbench.common.dmn.client.editors.expressions.types.undefined.UndefinedExpressionEditorDefinition) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) BaseBounds(org.uberfire.ext.wires.core.grids.client.model.impl.BaseBounds) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) UpdateElementPropertyCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPropertyCommand) HasName(org.kie.workbench.common.dmn.api.definition.HasName) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) ExpressionEditorDefinitions(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinitions) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) Iterator(java.util.Iterator) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) BaseGridCellValue(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue) Before(org.junit.Before)

Example 78 with Definition

use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.

the class DecisionServiceParametersListWidgetTest method testAddDecisionNodeToGroup.

@Test
public void testAddDecisionNodeToGroup() {
    final ParameterGroup group = mock(ParameterGroup.class);
    final Node node = mock(Node.class);
    final Definition definition = mock(Definition.class);
    final Decision decision = mock(Decision.class);
    final InformationItemPrimary variable = mock(InformationItemPrimary.class);
    final String decisionName = "decision name";
    final String type = "type";
    final QName typeRef = mock(QName.class);
    when(definition.getDefinition()).thenReturn(decision);
    when(node.getContent()).thenReturn(definition);
    when(decision.getVariable()).thenReturn(variable);
    when(decision.getName()).thenReturn(new Name(decisionName));
    when(typeRef.getLocalPart()).thenReturn(type);
    when(variable.getTypeRef()).thenReturn(typeRef);
    widget.addDecisionNodeToGroup(group, node);
    verify(group).addParameter(decisionName, type);
}
Also used : InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) ParameterGroup(org.kie.workbench.common.dmn.client.widgets.decisionservice.parameters.parametergroup.ParameterGroup) Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) 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) Test(org.junit.Test)

Example 79 with Definition

use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.

the class DMNMarshallerTest method testWithIncludedModelsWhenNodeParentIsDMNDiagram.

@Test
public void testWithIncludedModelsWhenNodeParentIsDMNDiagram() {
    final DMNMarshaller dmnMarshaller = spy(new DMNMarshaller());
    final Node node = mock(Node.class);
    final Definition nodeDefinition = mock(Definition.class);
    final DRGElement drgElement = mock(DRGElement.class);
    final Definitions definitionsStunnerPojo = mock(Definitions.class);
    final Import import1 = mock(Import.class);
    final Import import2 = mock(Import.class);
    final List<Import> diagramImports = new ArrayList<>(asList(import1, import2));
    final DMNDiagram nodeDiagram = mock(DMNDiagram.class);
    final Definitions nodeDiagramDefinitions = mock(Definitions.class);
    final List<Import> nodeDiagramImports = new ArrayList<>();
    when(node.getContent()).thenReturn(nodeDefinition);
    when(nodeDefinition.getDefinition()).thenReturn(drgElement);
    when(definitionsStunnerPojo.getImport()).thenReturn(diagramImports);
    when(drgElement.getParent()).thenReturn(nodeDiagram);
    when(nodeDiagram.getDefinitions()).thenReturn(nodeDiagramDefinitions);
    when(nodeDiagramDefinitions.getImport()).thenReturn(nodeDiagramImports);
    dmnMarshaller.withIncludedModels(node, definitionsStunnerPojo);
    assertEquals(2, nodeDiagramImports.size());
    assertTrue(nodeDiagramImports.contains(import1));
    assertTrue(nodeDiagramImports.contains(import2));
}
Also used : JSIDMNDiagram(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Import(org.kie.workbench.common.dmn.api.definition.model.Import) Node(org.kie.workbench.common.stunner.core.graph.Node) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) ArrayList(java.util.ArrayList) JSITDRGElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDRGElement) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Test(org.junit.Test)

Example 80 with Definition

use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.

the class NodeConnectorTest method testConnectEdgeToNodesWhenDMNDIIsPresent.

@Test
public void testConnectEdgeToNodesWhenDMNDIIsPresent() {
    final JSIDMNEdge existingEdge = mock(JSIDMNEdge.class);
    final Definition definition = mock(Definition.class);
    final DRGElement drgElement = mock(DRGElement.class);
    final String id = "789";
    final String contentDefinitionId = "123";
    final List<NodeEntry> list = singletonList(nodeEntry);
    when(jsiDMNElementReference.getHref()).thenReturn("#123");
    when(jsiDMNElement.getId()).thenReturn(id);
    when(existingEdge.getDmnElementRef()).thenReturn(new QName("", id));
    when(definition.getDefinition()).thenReturn(drgElement);
    when(currentNode.getContent()).thenReturn(definition);
    when(drgElement.getContentDefinitionId()).thenReturn(contentDefinitionId);
    doReturn(true).when(nodeConnector).isEdgeConnectedWithNode(eq(existingEdge), eq(currentNode), eq(list));
    doReturn(Optional.of(requiredNode)).when(nodeConnector).getSourceNode(eq(existingEdge), any());
    doNothing().when(nodeConnector).connectWbEdge(any(), any(), any(), any(), any(), any());
    entriesById.put(contentDefinitionId, list);
    edges.add(existingEdge);
    isDMNDIPresent = true;
    nodeConnector.connectEdgeToNodes(connectorTypeId, jsiDMNElement, jsiDMNElementReference, entriesById, diagramId, edges, isDMNDIPresent, currentNode);
    verify(nodeConnector).connectWbEdge(eq(connectorTypeId), eq(diagramId), eq(currentNode), eq(requiredNode), eq(existingEdge), eq("789"));
    verify(nodeConnector).isEdgeConnectedWithNode(eq(existingEdge), eq(currentNode), eq(list));
}
Also used : QName(javax.xml.namespace.QName) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Test(org.junit.Test)

Aggregations

Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)111 Node (org.kie.workbench.common.stunner.core.graph.Node)61 Test (org.junit.Test)46 Element (org.kie.workbench.common.stunner.core.graph.Element)31 Edge (org.kie.workbench.common.stunner.core.graph.Edge)25 Graph (org.kie.workbench.common.stunner.core.graph.Graph)20 ArrayList (java.util.ArrayList)16 Optional (java.util.Optional)14 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)14 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)14 Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)14 View (org.kie.workbench.common.stunner.core.graph.content.view.View)12 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)11 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)10 List (java.util.List)9 Before (org.junit.Before)9 DMNDiagram (org.kie.workbench.common.dmn.api.definition.model.DMNDiagram)9 HasContentDefinitionId (org.kie.workbench.common.stunner.core.graph.content.HasContentDefinitionId)9 NodeImpl (org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)9 Stream (java.util.stream.Stream)8