Search in sources :

Example 1 with ParentAssignment

use of org.kie.workbench.common.stunner.core.client.canvas.controls.builder.impl.AbstractElementBuilderControl.ParentAssignment in project kie-wb-common by kiegroup.

the class ElementBuilderControlImplTest method getParentAssignmentDocking.

@Test
public void getParentAssignmentDocking() {
    // test docking
    ArgumentCaptor<DockingContext> dockingContextCaptor = forClass(DockingContext.class);
    when(ruleManager.evaluate(eq(ruleSet), dockingContextCaptor.capture())).thenReturn(new DefaultRuleViolations());
    ParentAssignment parentAssignment = elementBuilderControl.getParentAssignment(parent, def);
    assertEquals(dockingContextCaptor.getValue().getCandidateRoles(), DEFINITION_LABELS);
    assertEquals(dockingContextCaptor.getValue().getParentRoles(), PARENT_LABELS);
    assertEquals(parentAssignment, ParentAssignment.DOCKING);
    // test containment
    ArgumentCaptor<ContainmentContext> containmentContextArgumentCaptor = forClass(ContainmentContext.class);
    DefaultRuleViolations dockingRuleViolations = new DefaultRuleViolations();
    dockingRuleViolations.addViolation(new DockingRuleViolation("", ""));
    when(ruleManager.evaluate(eq(ruleSet), containmentContextArgumentCaptor.capture())).thenAnswer(arg -> {
        if (arg.getArguments()[1] instanceof ContainmentContext) {
            return new DefaultRuleViolations();
        } else {
            return dockingRuleViolations;
        }
    });
    parentAssignment = elementBuilderControl.getParentAssignment(parent, def);
    assertEquals(parentAssignment, ParentAssignment.CONTAINMENT);
    // testing none
    DefaultRuleViolations allViolations = new DefaultRuleViolations();
    allViolations.addViolation(new DockingRuleViolation("", ""));
    allViolations.addViolation(new ContainmentRuleViolation("", ""));
    when(ruleManager.evaluate(eq(ruleSet), any())).thenReturn(allViolations);
    parentAssignment = elementBuilderControl.getParentAssignment(parent, def);
    assertEquals(parentAssignment, ParentAssignment.NONE);
}
Also used : DockingContext(org.kie.workbench.common.stunner.core.rule.context.DockingContext) ParentAssignment(org.kie.workbench.common.stunner.core.client.canvas.controls.builder.impl.AbstractElementBuilderControl.ParentAssignment) DockingRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.DockingRuleViolation) ContainmentContext(org.kie.workbench.common.stunner.core.rule.context.ContainmentContext) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) ContainmentRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation) Test(org.junit.Test)

Example 2 with ParentAssignment

use of org.kie.workbench.common.stunner.core.client.canvas.controls.builder.impl.AbstractElementBuilderControl.ParentAssignment in project kie-wb-common by kiegroup.

the class ElementBuilderControlImplTest method getElementCommandsNoParent.

@Test
public void getElementCommandsNoParent() {
    ParentAssignment parentAssignment = ParentAssignment.NONE;
    elementBuilderControl.getElementCommands(node, parent, parentAssignment, X, Y, callback);
    verify(callback).onComplete(any(), commandsCapture.capture());
    List<Command<AbstractCanvasHandler, CanvasViolation>> commands = commandsCapture.getValue();
    assertTrue(commands.get(0) instanceof AddNodeCommand);
    assertTrue(commands.get(1) instanceof UpdateElementPositionCommand);
    verify(canvasCommandFactory).addNode(node, SHAPE_SET_ID);
    ArgumentCaptor<Point2D> positionCaptor = ArgumentCaptor.forClass(Point2D.class);
    verify(canvasCommandFactory).updatePosition(eq(node), positionCaptor.capture());
    assertEquals(positionCaptor.getValue(), new Point2D(X, Y));
}
Also used : AddNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddNodeCommand) AddNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddNodeCommand) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) UpdateDockNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateDockNodeCommand) AddChildNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddChildNodeCommand) Command(org.kie.workbench.common.stunner.core.command.Command) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) ParentAssignment(org.kie.workbench.common.stunner.core.client.canvas.controls.builder.impl.AbstractElementBuilderControl.ParentAssignment) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) Test(org.junit.Test)

Example 3 with ParentAssignment

use of org.kie.workbench.common.stunner.core.client.canvas.controls.builder.impl.AbstractElementBuilderControl.ParentAssignment in project kie-wb-common by kiegroup.

the class ElementBuilderControlImplTest method getElementCommandsContainment.

@Test
public void getElementCommandsContainment() {
    ParentAssignment parentAssignment = ParentAssignment.CONTAINMENT;
    elementBuilderControl.getElementCommands(node, parent, parentAssignment, X, Y, callback);
    verify(callback).onComplete(any(), commandsCapture.capture());
    List<Command<AbstractCanvasHandler, CanvasViolation>> commands = commandsCapture.getValue();
    assertTrue(commands.get(0) instanceof AddChildNodeCommand);
    assertTrue(commands.get(1) instanceof UpdateElementPositionCommand);
    verify(canvasCommandFactory).addChildNode(parent, node, SHAPE_SET_ID);
    ArgumentCaptor<Point2D> positionCaptor = ArgumentCaptor.forClass(Point2D.class);
    verify(canvasCommandFactory).updatePosition(eq(node), positionCaptor.capture());
    assertEquals(positionCaptor.getValue(), new Point2D(X, Y));
}
Also used : AddNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddNodeCommand) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) UpdateDockNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateDockNodeCommand) AddChildNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddChildNodeCommand) Command(org.kie.workbench.common.stunner.core.command.Command) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) ParentAssignment(org.kie.workbench.common.stunner.core.client.canvas.controls.builder.impl.AbstractElementBuilderControl.ParentAssignment) AddChildNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddChildNodeCommand) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) Test(org.junit.Test)

Example 4 with ParentAssignment

use of org.kie.workbench.common.stunner.core.client.canvas.controls.builder.impl.AbstractElementBuilderControl.ParentAssignment in project kie-wb-common by kiegroup.

the class ElementBuilderControlImplTest method getElementCommandsDocked.

@Test
public void getElementCommandsDocked() {
    ParentAssignment parentAssignment = ParentAssignment.DOCKING;
    elementBuilderControl.getElementCommands(node, parent, parentAssignment, X, Y, callback);
    verify(callback).onComplete(any(), commandsCapture.capture());
    List<Command<AbstractCanvasHandler, CanvasViolation>> commands = commandsCapture.getValue();
    assertTrue(commands.get(0) instanceof AddChildNodeCommand);
    assertTrue(commands.get(1) instanceof UpdateElementPositionCommand);
    assertTrue(commands.get(2) instanceof UpdateDockNodeCommand);
    verify(canvasCommandFactory).addChildNode(grandParent, node, SHAPE_SET_ID);
    ArgumentCaptor<Point2D> positionCaptor = ArgumentCaptor.forClass(Point2D.class);
    verify(canvasCommandFactory).updatePosition(eq(node), positionCaptor.capture());
    assertEquals(positionCaptor.getValue(), new Point2D(X, Y));
    verify(canvasCommandFactory).addChildNode(grandParent, node, SHAPE_SET_ID);
}
Also used : AddNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddNodeCommand) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) UpdateDockNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateDockNodeCommand) AddChildNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddChildNodeCommand) Command(org.kie.workbench.common.stunner.core.command.Command) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) ParentAssignment(org.kie.workbench.common.stunner.core.client.canvas.controls.builder.impl.AbstractElementBuilderControl.ParentAssignment) AddChildNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddChildNodeCommand) UpdateDockNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateDockNodeCommand) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 ParentAssignment (org.kie.workbench.common.stunner.core.client.canvas.controls.builder.impl.AbstractElementBuilderControl.ParentAssignment)4 AddChildNodeCommand (org.kie.workbench.common.stunner.core.client.canvas.command.AddChildNodeCommand)3 AddNodeCommand (org.kie.workbench.common.stunner.core.client.canvas.command.AddNodeCommand)3 UpdateDockNodeCommand (org.kie.workbench.common.stunner.core.client.canvas.command.UpdateDockNodeCommand)3 UpdateElementPositionCommand (org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand)3 Command (org.kie.workbench.common.stunner.core.command.Command)3 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)3 ContainmentContext (org.kie.workbench.common.stunner.core.rule.context.ContainmentContext)1 DockingContext (org.kie.workbench.common.stunner.core.rule.context.DockingContext)1 ContainmentRuleViolation (org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation)1 DefaultRuleViolations (org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations)1 DockingRuleViolation (org.kie.workbench.common.stunner.core.rule.violations.DockingRuleViolation)1