Search in sources :

Example 1 with BasePropertyReader

use of org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.properties.BasePropertyReader in project kie-wb-common by kiegroup.

the class ProcessPostConverterTest method testPostConvert.

@Test
public void testPostConvert() {
    DefinitionResolver definitionResolver = mock(DefinitionResolver.class);
    double laneX = 80;
    double laneY = 100;
    double laneWidth = 500;
    double laneHeight = 200;
    RectangleDimensionsSet laneRectangleDimensionsSet = new RectangleDimensionsSet(laneWidth, laneHeight);
    Lane laneDefinition = mock(Lane.class);
    when(laneDefinition.getDimensionsSet()).thenReturn(laneRectangleDimensionsSet);
    Node<? extends View<? extends BPMNViewDefinition>, ?> lane = mockNode(laneDefinition, laneX, laneY, laneWidth, laneHeight);
    BpmnNode laneNode = mockBpmnNode(lane);
    double startEventX = 180;
    double startEventY = 130;
    double eventWidth = 56;
    double eventHeight = 56;
    Node<? extends View<? extends BPMNViewDefinition>, ?> startEvent = mockNode(mock(StartNoneEvent.class), startEventX + laneX, startEventY + laneY, eventWidth, eventHeight);
    BpmnNode startEventNode = mockBpmnNode(startEvent);
    // subprocess is collapsed and has a boundaryEvent, and contains task1 and task2 (task2 has a boundaryEvent)
    double subprocessX = 270;
    double subprocessY = 180;
    double subprocessWidth = 100;
    double subprocessHeight = 60;
    RectangleDimensionsSet subprocessRectangleDimensionsSet = new RectangleDimensionsSet(subprocessWidth, subprocessHeight);
    EmbeddedSubprocess subprocessDefinition = mock(EmbeddedSubprocess.class);
    when(subprocessDefinition.getDimensionsSet()).thenReturn(subprocessRectangleDimensionsSet);
    Node<? extends View<? extends BPMNViewDefinition>, ?> subprocess = mockNode(subprocessDefinition, subprocessX + laneX, subprocessY + laneY, subprocessWidth, subprocessHeight);
    BpmnNode subprocessNode = mockBpmnNode(subprocess);
    BasePropertyReader subprocessPropertyReader = subprocessNode.getPropertyReader();
    when(subprocessPropertyReader.isExpanded()).thenReturn(false);
    double subprocessBoundaryEventX = subprocessWidth - 28;
    double subprocessBoundaryEventY = (subprocessHeight / 2) - 28;
    Node<? extends View<? extends BPMNViewDefinition>, ?> subprocessBoundaryEvent = mockNode(mock(IntermediateTimerEvent.class), subprocessBoundaryEventX, subprocessBoundaryEventY, eventWidth, eventHeight);
    BpmnNode subprocessBoundaryEventNode = mockBpmnNode(subprocessBoundaryEvent).docked();
    double task1X = 10;
    double task1Y = 10;
    double taskWidth = 200;
    double taskHeight = 100;
    Node<? extends View<? extends BPMNViewDefinition>, ?> task1 = mockNode(mock(UserTask.class), task1X, task1Y, taskWidth, taskHeight);
    BpmnNode task1Node = mockBpmnNode(task1);
    double task2X = 300;
    double task2Y = 200;
    Node<? extends View<? extends BPMNViewDefinition>, ?> task2 = mockNode(mock(UserTask.class), task2X, task2Y, taskWidth, taskHeight);
    BpmnNode task2Node = mockBpmnNode(task2);
    double task2BoundaryEventX = taskWidth - 28;
    double task2BoundaryEventY = taskHeight - 28;
    Node<? extends View<? extends BPMNViewDefinition>, ?> task2BoundaryEvent = mockNode(mock(IntermediateTimerEvent.class), task2BoundaryEventX, task2BoundaryEventY, eventWidth, eventHeight);
    BpmnNode task2BoundaryEventNode = mockBpmnNode(task2BoundaryEvent).docked();
    double endEventX = 450;
    double endEventY = 230;
    Node<? extends View<? extends BPMNViewDefinition>, ?> endEvent = mockNode(mock(EndNoneEvent.class), endEventX + laneX, endEventY + laneY, eventWidth, eventHeight);
    BpmnNode endEventNode = mockBpmnNode(endEvent);
    double task3X = 500;
    double task3Y = 600;
    Node<? extends View<? extends BPMNViewDefinition>, ?> task3 = mockNode(mock(UserTask.class), task3X + laneX, task3Y + laneY, taskWidth, taskHeight);
    BpmnNode task3Node = mockBpmnNode(task3);
    double task3BoundaryEventX = taskWidth - 28;
    double task3BoundaryEventY = taskHeight - 28;
    Node<? extends View<? extends BPMNViewDefinition>, ?> task3BoundaryEvent = mockNode(mock(IntermediateTimerEvent.class), task3BoundaryEventX, task3BoundaryEventY, eventWidth, eventHeight);
    BpmnNode task3BoundaryEventNode = mockBpmnNode(task3BoundaryEvent).docked();
    double task4X = 900;
    double task4Y = 1000;
    Node<? extends View<? extends BPMNViewDefinition>, ?> task4 = mockNode(mock(UserTask.class), task4X + laneX, task4Y + laneY, taskWidth, taskHeight);
    BpmnNode task4Node = mockBpmnNode(task4);
    List<Point2D> controlPoints = new ArrayList<>();
    controlPoints.add(Point2D.create(900 + 100 + laneX, 700 + laneY));
    Connection sourceConnection = MagnetConnection.Builder.at(56, 28).setAuto(false);
    Connection targetConnection = MagnetConnection.Builder.at(100, 0).setAuto(false);
    BPMNEdge bpmnEdge = mock(BPMNEdge.class);
    BaseElement baseElement = mock(BaseElement.class);
    SequenceFlowPropertyReader edgePropertyReader = mock(SequenceFlowPropertyReader.class);
    when(edgePropertyReader.getDefinitionResolver()).thenReturn(definitionResolver);
    when(edgePropertyReader.getElement()).thenReturn(baseElement);
    when(baseElement.getId()).thenReturn("elementId");
    when(definitionResolver.getEdge("elementId")).thenReturn(bpmnEdge);
    List<Point> wayPoints = new ArrayList<>();
    wayPoints.add(mockPoint((float) (700 + 28 + laneX), (float) (700 + laneY)));
    wayPoints.add(mockPoint((float) (1000 + laneX), (float) (700 + laneY)));
    wayPoints.add(mockPoint((float) (900 + 100 + laneX), (float) (1000 + laneY)));
    when(bpmnEdge.getWaypoint()).thenReturn(wayPoints);
    org.eclipse.dd.dc.Bounds sourceShapeBounds = mockBounds((float) (task3X + taskWidth - 28 + laneX), (float) (task3Y + taskHeight - 28 + laneY), (float) eventWidth, (float) eventHeight);
    BPMNShape sourceShape = mockShape(sourceShapeBounds);
    when(task3BoundaryEventNode.getPropertyReader().getShape()).thenReturn(sourceShape);
    org.eclipse.dd.dc.Bounds targetShapeBounds = mockBounds(task4.getContent().getBounds());
    BPMNShape targetShape = mockShape(targetShapeBounds);
    when(task4Node.getPropertyReader().getShape()).thenReturn(targetShape);
    BpmnEdge.Simple edgeTask3BoundaryEventToTask4 = BpmnEdge.of(null, task3BoundaryEventNode, sourceConnection, controlPoints, task4Node, targetConnection, edgePropertyReader);
    Node<? extends View<? extends BPMNViewDefinition>, ?> diagram = mockNode(mock(BPMNDiagramImpl.class), 0, 0, 10000, 10000);
    BpmnNode rootNode = mockBpmnNode(diagram);
    rootNode.addChild(laneNode);
    laneNode.addChild(startEventNode);
    laneNode.addChild(subprocessNode);
    laneNode.addChild(subprocessBoundaryEventNode);
    rootNode.addEdge(BpmnEdge.docked(subprocessNode, subprocessBoundaryEventNode));
    subprocessNode.addChild(task1Node);
    subprocessNode.addChild(task2Node);
    subprocessNode.addChild(task2BoundaryEventNode);
    subprocessNode.addEdge(BpmnEdge.docked(task2Node, task2BoundaryEventNode));
    laneNode.addChild(task3Node);
    laneNode.addChild(task3BoundaryEventNode);
    laneNode.addChild(task4Node);
    rootNode.addEdge(BpmnEdge.docked(task3Node, task3BoundaryEventNode));
    rootNode.addEdge(edgeTask3BoundaryEventToTask4);
    laneNode.addChild(endEventNode);
    ProcessPostConverter postConverter = new ProcessPostConverter();
    when(definitionResolver.getResolutionFactor()).thenReturn(2d);
    Result<BpmnNode> result = postConverter.postConvert(rootNode, definitionResolver);
    Bounds startEventBounds = startEventNode.value().getContent().getBounds();
    // preserves original position
    assertEquals(laneX + startEventX, startEventBounds.getUpperLeft().getX(), 0);
    assertEquals(laneY + startEventY, startEventBounds.getUpperLeft().getY(), 0);
    assertEquals(eventWidth, startEventBounds.getWidth(), 0);
    assertEquals(eventHeight, startEventBounds.getHeight(), 0);
    Bounds subProcessBounds = subprocessNode.value().getContent().getBounds();
    // was properly resized and preserves original position
    assertEquals(laneX + subprocessX, subProcessBounds.getUpperLeft().getX(), 0);
    assertEquals(laneY + subprocessY, subProcessBounds.getUpperLeft().getY(), 0);
    assertEquals(300 + 200 + 10, subProcessBounds.getWidth(), 0);
    assertEquals(200 + 100 + 10, subProcessBounds.getHeight(), 0);
    Bounds subProcessBoundaryEventBounds = subprocessBoundaryEventNode.value().getContent().getBounds();
    // boundary event was properly located
    assertEquals(subProcessBounds.getWidth() - 28, subProcessBoundaryEventBounds.getUpperLeft().getX(), 0);
    assertEquals(subProcessBounds.getHeight() / subprocessHeight * subprocessBoundaryEventY, subProcessBoundaryEventBounds.getUpperLeft().getY(), 0);
    Bounds task1Bounds = task1Node.value().getContent().getBounds();
    // was properly positioned and preserves size
    assertEquals(laneX + subprocessX + task1X, task1Bounds.getUpperLeft().getX(), 0);
    assertEquals(laneY + subprocessY + task1Y, task1Bounds.getUpperLeft().getY(), 0);
    assertEquals(taskWidth, task1Bounds.getWidth(), 0);
    assertEquals(taskHeight, task1Bounds.getHeight(), 0);
    Bounds task2Bounds = task2Node.value().getContent().getBounds();
    // was properly positioned and preserves size
    assertEquals(laneX + subprocessX + task2X, task2Bounds.getUpperLeft().getX(), 0);
    assertEquals(laneY + subprocessY + task2Y, task2Bounds.getUpperLeft().getY(), 0);
    assertEquals(taskWidth, task1Bounds.getWidth(), 0);
    assertEquals(taskHeight, task1Bounds.getHeight(), 0);
    Bounds task2BoundaryEventBounds = task2BoundaryEventNode.value().getContent().getBounds();
    // is relative to the task2 in the converted model and preserves size
    assertEquals(task2BoundaryEventX, task2BoundaryEventBounds.getUpperLeft().getX(), 0);
    assertEquals(task2BoundaryEventY, task2BoundaryEventBounds.getUpperLeft().getY(), 0);
    assertEquals(eventWidth, task2BoundaryEventBounds.getWidth(), 0);
    assertEquals(eventHeight, task2BoundaryEventBounds.getHeight(), 0);
    Bounds endEventBounds = endEventNode.value().getContent().getBounds();
    double subprocessDeltaX = subProcessBounds.getWidth() - subprocessWidth;
    double subprocessDeltaY = subProcessBounds.getHeight() - subprocessHeight;
    // was properly moved after the subprocess resize
    assertEquals(laneX + endEventX + subprocessDeltaX, endEventBounds.getUpperLeft().getX(), 0);
    assertEquals(laneY + endEventY + subprocessDeltaY, endEventBounds.getUpperLeft().getY(), 0);
    Bounds task3Bounds = task3Node.value().getContent().getBounds();
    // was properly moved after the subprocess resize
    assertEquals(laneX + task3X + subprocessDeltaX, task3Bounds.getUpperLeft().getX(), 0);
    assertEquals(laneY + task3Y + subprocessDeltaY, task3Bounds.getUpperLeft().getY(), 0);
    Bounds task3BoundaryEventBounds = task3BoundaryEventNode.value().getContent().getBounds();
    // is relative to the task3 in the converted model and preserves size
    assertEquals(task3BoundaryEventX, task3BoundaryEventBounds.getUpperLeft().getX(), 0);
    assertEquals(task3BoundaryEventY, task3BoundaryEventBounds.getUpperLeft().getY(), 0);
    assertEquals(eventWidth, task3BoundaryEventBounds.getWidth(), 0);
    assertEquals(eventHeight, task3BoundaryEventBounds.getHeight(), 0);
    Bounds task4Bounds = task4Node.value().getContent().getBounds();
    // was properly moved after the subprocess resize
    assertEquals(laneX + task4X + subprocessDeltaX, task4Bounds.getUpperLeft().getX(), 0);
    assertEquals(laneY + task4Y + subprocessDeltaY, task4Bounds.getUpperLeft().getY(), 0);
    // edgeTask3BoundaryEventToTask4 was properly translated and magnets are ok
    assertEquals(56, edgeTask3BoundaryEventToTask4.getSourceConnection().getLocation().getX(), 0);
    assertEquals(28, edgeTask3BoundaryEventToTask4.getSourceConnection().getLocation().getY(), 0);
    assertEquals(task4Node.value().getContent().getBounds().getUpperLeft().getX() + taskWidth / 2, controlPoints.get(0).getX(), 0);
    assertEquals(task3Node.value().getContent().getBounds().getLowerRight().getY(), controlPoints.get(0).getY(), 0);
    // assert the message result
    List<MarshallingMessage> messages = result.messages();
    assertEquals(1, messages.size());
    MarshallingMessage message = messages.get(0);
    assertEquals(Violation.Type.WARNING, message.getViolationType());
    assertEquals(MarshallingMessageKeys.collapsedElementExpanded, message.getMessageKey());
}
Also used : MarshallingMessage(org.kie.workbench.common.stunner.core.marshaller.MarshallingMessage) ArrayList(java.util.ArrayList) GraphBuilderTest.mockBpmnNode(org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.GraphBuilderTest.mockBpmnNode) BasePropertyReader(org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.properties.BasePropertyReader) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) EmbeddedSubprocess(org.kie.workbench.common.stunner.bpmn.definition.EmbeddedSubprocess) EndNoneEvent(org.kie.workbench.common.stunner.bpmn.definition.EndNoneEvent) BPMNDiagramImpl(org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagramImpl) StartNoneEvent(org.kie.workbench.common.stunner.bpmn.definition.StartNoneEvent) BPMNEdge(org.eclipse.bpmn2.di.BPMNEdge) Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) Lane(org.kie.workbench.common.stunner.bpmn.definition.Lane) UserTask(org.kie.workbench.common.stunner.bpmn.definition.UserTask) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) RectangleDimensionsSet(org.kie.workbench.common.stunner.bpmn.definition.property.dimensions.RectangleDimensionsSet) Point(org.eclipse.dd.dc.Point) BPMNShape(org.eclipse.bpmn2.di.BPMNShape) SequenceFlowPropertyReader(org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.properties.SequenceFlowPropertyReader) BaseElement(org.eclipse.bpmn2.BaseElement) IntermediateTimerEvent(org.kie.workbench.common.stunner.bpmn.definition.IntermediateTimerEvent) Factories.dc(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.Factories.dc) Test(org.junit.Test)

Example 2 with BasePropertyReader

use of org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.properties.BasePropertyReader in project kie-wb-common by kiegroup.

the class GraphBuilderTest method mockBpmnNode.

public static BpmnNode mockBpmnNode(Node<? extends View<? extends BPMNViewDefinition>, ?> node) {
    Bounds nodeBounds = node.getContent().getBounds();
    BasePropertyReader propertyReader = mock(BasePropertyReader.class);
    BPMNShape shape = mock(BPMNShape.class);
    org.eclipse.dd.dc.Bounds bounds = dc.createBounds();
    bounds.setX(nodeBounds.getUpperLeft().getX().floatValue());
    bounds.setY(nodeBounds.getUpperLeft().getY().floatValue());
    bounds.setWidth(Double.valueOf(nodeBounds.getWidth()).floatValue());
    bounds.setHeight(Double.valueOf(nodeBounds.getHeight()).floatValue());
    Bounds readerBounds = Bounds.create(nodeBounds.getUpperLeft().getX(), nodeBounds.getUpperLeft().getY(), nodeBounds.getLowerRight().getX(), nodeBounds.getLowerRight().getY());
    when(propertyReader.getBounds()).thenReturn(readerBounds);
    when(shape.getBounds()).thenReturn(bounds);
    when(propertyReader.getShape()).thenReturn(shape);
    return BpmnNode.of(node, propertyReader);
}
Also used : Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) BasePropertyReader(org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.properties.BasePropertyReader) BPMNShape(org.eclipse.bpmn2.di.BPMNShape) Factories.dc(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.Factories.dc)

Aggregations

BPMNShape (org.eclipse.bpmn2.di.BPMNShape)2 Factories.dc (org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.Factories.dc)2 BasePropertyReader (org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.properties.BasePropertyReader)2 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)2 ArrayList (java.util.ArrayList)1 BaseElement (org.eclipse.bpmn2.BaseElement)1 BPMNEdge (org.eclipse.bpmn2.di.BPMNEdge)1 Point (org.eclipse.dd.dc.Point)1 Test (org.junit.Test)1 GraphBuilderTest.mockBpmnNode (org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.GraphBuilderTest.mockBpmnNode)1 SequenceFlowPropertyReader (org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.properties.SequenceFlowPropertyReader)1 BPMNDiagramImpl (org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagramImpl)1 EmbeddedSubprocess (org.kie.workbench.common.stunner.bpmn.definition.EmbeddedSubprocess)1 EndNoneEvent (org.kie.workbench.common.stunner.bpmn.definition.EndNoneEvent)1 IntermediateTimerEvent (org.kie.workbench.common.stunner.bpmn.definition.IntermediateTimerEvent)1 Lane (org.kie.workbench.common.stunner.bpmn.definition.Lane)1 StartNoneEvent (org.kie.workbench.common.stunner.bpmn.definition.StartNoneEvent)1 UserTask (org.kie.workbench.common.stunner.bpmn.definition.UserTask)1 RectangleDimensionsSet (org.kie.workbench.common.stunner.bpmn.definition.property.dimensions.RectangleDimensionsSet)1 Connection (org.kie.workbench.common.stunner.core.graph.content.view.Connection)1