Search in sources :

Example 1 with DockingContext

use of org.kie.workbench.common.stunner.core.rule.context.DockingContext 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)

Aggregations

Test (org.junit.Test)1 ParentAssignment (org.kie.workbench.common.stunner.core.client.canvas.controls.builder.impl.AbstractElementBuilderControl.ParentAssignment)1 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