Search in sources :

Example 16 with Definition

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

the class DRDContextMenuServiceTest method mockNodes.

private Collection<Node<? extends Definition<?>, Edge>> mockNodes() {
    final Node node = mock(Node.class);
    final Node clonedNode = mock(Node.class);
    final View content = mock(View.class);
    final View clonedContent = mock(View.class);
    final Bounds bounds = mock(Bounds.class);
    final Bound upperLeft = mock(Bound.class);
    final Bound lowerRight = mock(Bound.class);
    final InputData inputData = spy(new InputData());
    final InputData clonedInputData = spy(new InputData());
    final Collection<Node<? extends Definition<?>, Edge>> nodes = new ArrayList<>();
    when(node.getContent()).thenReturn(content);
    when(content.getDefinition()).thenReturn(inputData);
    when(content.getBounds()).thenReturn(bounds);
    when(bounds.getUpperLeft()).thenReturn(upperLeft);
    when(bounds.getLowerRight()).thenReturn(lowerRight);
    when(factoryManager.newElement(Mockito.<String>any(), Mockito.<String>any())).thenReturn(clonedNode);
    when(clonedNode.asNode()).thenReturn(clonedNode);
    when(clonedNode.getContent()).thenReturn(clonedContent);
    when(clonedContent.getDefinition()).thenReturn(clonedInputData);
    when(dmnDeepCloneProcess.clone(eq(inputData))).thenReturn(clonedInputData);
    nodes.add(node);
    return nodes;
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Bound(org.kie.workbench.common.stunner.core.graph.content.Bound) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) ArrayList(java.util.ArrayList) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Example 17 with Definition

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

the class DRDContextMenuServiceTest method testAddToNewDRD.

@Test
public void testAddToNewDRD() {
    final Collection<Node<? extends Definition<?>, Edge>> nodes = mock(Collection.class);
    final Definitions definitions = mock(Definitions.class);
    final Diagram drgDiagram = mock(Diagram.class);
    final List<DMNDiagramElement> diagramElements = mock(List.class);
    when(dmnDiagramsSession.getDRGDiagram()).thenReturn(drgDiagram);
    when(dmnDiagramUtils.getDefinitions(drgDiagram)).thenReturn(definitions);
    when(definitions.getDiagramElements()).thenReturn(diagramElements);
    drdContextMenuService.addToNewDRD(nodes);
    verify(diagramElements, times(1)).add(Mockito.<DMNDiagramElement>any());
    verify(dmnDiagramsSession, times(1)).add(Mockito.<DMNDiagramElement>any(), Mockito.<Diagram>any());
    verify(selectedEvent, times(1)).fire(Mockito.<DMNDiagramSelected>any());
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Test(org.junit.Test)

Example 18 with Definition

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

the class ContextGridTest 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 ContextEditorDefinition(definitionUtils, sessionManager, sessionCommandManager, canvasCommandFactory, editorSelectedEvent, refreshFormPropertiesEvent, domainObjectSelectionEvent, listSelector, translationService, expressionEditorDefinitionsSupplier, headerEditor, readOnlyProvider);
    final Decision decision = new Decision();
    decision.setName(new Name(NAME));
    hasName = Optional.of(decision);
    expression = definition.getModelClass();
    definition.enrich(Optional.empty(), hasExpression, expression);
    final ExpressionEditorDefinitions expressionEditorDefinitions = new ExpressionEditorDefinitions();
    expressionEditorDefinitions.add((ExpressionEditorDefinition) definition);
    expressionEditorDefinitions.add(literalExpressionEditorDefinition);
    expressionEditorDefinitions.add(undefinedExpressionEditorDefinition);
    when(expressionEditorDefinitionsSupplier.get()).thenReturn(expressionEditorDefinitions);
    when(literalExpressionEditor.getParentInformation()).thenReturn(parent);
    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(session.getCanvasHandler()).thenReturn(canvasHandler);
    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) 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 19 with Definition

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

the class ExpressionContainerGridTest method testSelectCellWithDomainObjectInStunnerGraph.

@Test
public void testSelectCellWithDomainObjectInStunnerGraph() {
    final int uiRowIndex = 0;
    final int uiColumnIndex = 1;
    final LiteralExpression domainObject = mock(LiteralExpression.class);
    when(hasExpression.asDMNModelInstrumentedBase()).thenReturn(domainObject);
    when(graph.nodes()).thenReturn(Collections.singletonList(node));
    final Definition definition = mock(Definition.class);
    when(node.getUUID()).thenReturn(NODE_UUID);
    when(node.getContent()).thenReturn(definition);
    when(definition.getDefinition()).thenReturn(domainObject);
    grid.setExpression(NODE_UUID, hasExpression, Optional.of(hasName), false);
    grid.selectCell(uiRowIndex, uiColumnIndex, false, true);
    verify(gridLayer).select(eq(grid));
    verify(refreshFormPropertiesEvent).fire(refreshFormPropertiesEventCaptor.capture());
    final RefreshFormPropertiesEvent refreshFormPropertiesEvent = refreshFormPropertiesEventCaptor.getValue();
    assertThat(refreshFormPropertiesEvent.getUuid()).isEqualTo(NODE_UUID);
    assertThat(refreshFormPropertiesEvent.getSession()).isEqualTo(session);
    verify(cellSelectionManager).selectCell(eq(uiRowIndex), eq(uiColumnIndex), eq(false), eq(true));
}
Also used : LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) 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) RefreshFormPropertiesEvent(org.kie.workbench.common.stunner.forms.client.event.RefreshFormPropertiesEvent) Test(org.junit.Test)

Example 20 with Definition

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

the class MonacoFEELSuggestionsTest method makeDecisionNode.

private NodeImpl<Definition<Decision>> makeDecisionNode(final String name, final BuiltInType builtInType) {
    final NodeImpl<Definition<Decision>> node = makeNodeImpl();
    final Definition<Decision> definition = makeDefinition();
    final Decision decision = spy(new Decision());
    final InformationItemPrimary informationItemPrimary = mock(InformationItemPrimary.class);
    final QName qName = builtInType == null ? null : new QName(builtInType);
    when(informationItemPrimary.getTypeRef()).thenReturn(qName);
    when(node.getContent()).thenReturn(definition);
    when(definition.getDefinition()).thenReturn(decision);
    decision.setName(new Name(name));
    decision.setVariable(informationItemPrimary);
    return node;
}
Also used : InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) QName(org.kie.workbench.common.dmn.api.property.dmn.QName)

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