Search in sources :

Example 26 with RuleViolation

use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.

the class SetConnectionTargetNodeCommandTest method testExecute.

@Test
@SuppressWarnings("unchecked")
public void testExecute() {
    final List lastTargetInEdges = mock(List.class);
    final List sourceOutEdges = mock(List.class);
    final List targetInEdges = mock(List.class);
    when(source.getOutEdges()).thenReturn(sourceOutEdges);
    when(lastTargetNode.getInEdges()).thenReturn(lastTargetInEdges);
    when(node.getInEdges()).thenReturn(targetInEdges);
    CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext);
    final ArgumentCaptor<RuleEvaluationContext> contextCaptor = ArgumentCaptor.forClass(RuleEvaluationContext.class);
    verify(ruleManager, times(3)).evaluate(eq(ruleSet), contextCaptor.capture());
    final List<RuleEvaluationContext> contexts = contextCaptor.getAllValues();
    assertEquals(3, contexts.size());
    verifyConnection((GraphConnectionContext) contexts.get(0), edge, source, node);
    verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(1), graph, lastTargetNode, edge, EdgeCardinalityContext.Direction.INCOMING, Optional.of(CardinalityContext.Operation.DELETE));
    verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(2), graph, node, edge, EdgeCardinalityContext.Direction.INCOMING, Optional.of(CardinalityContext.Operation.ADD));
    assertEquals(CommandResult.Type.INFO, result.getType());
    verify(lastTargetInEdges, times(1)).remove(eq(edge));
    verify(targetInEdges, times(1)).add(eq(edge));
    verify(edgeContent, times(1)).setTargetConnection(any(Connection.class));
    verify(edge, times(1)).setTargetNode(eq(node));
    verify(targetInEdges, times(0)).remove(any(Edge.class));
    verify(sourceOutEdges, times(0)).add(any(Edge.class));
    verify(graphIndex, times(0)).removeEdge(any(Edge.class));
    verify(graphIndex, times(0)).addEdge(any(Edge.class));
    verify(graphIndex, times(0)).addNode(any(Node.class));
    verify(graphIndex, times(0)).removeNode(any(Node.class));
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) TestingGraphUtils.verifyConnection(org.kie.workbench.common.stunner.core.TestingGraphUtils.verifyConnection) MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) List(java.util.List) RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 27 with RuleViolation

use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.

the class SetParentNodeCommandTest method testNotAllowed.

@Test
@SuppressWarnings("unchecked")
public void testNotAllowed() {
    final RuleViolations FAILED_VIOLATIONS = new DefaultRuleViolations().addViolation(new ContainmentRuleViolation(graph.getUUID(), PARENT_UUID));
    when(ruleManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(FAILED_VIOLATIONS);
    CommandResult<RuleViolation> result = tested.allow(graphCommandExecutionContext);
    assertEquals(CommandResult.Type.ERROR, result.getType());
}
Also used : RuleSet(org.kie.workbench.common.stunner.core.rule.RuleSet) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) ContainmentRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) ContainmentRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation) Test(org.junit.Test)

Example 28 with RuleViolation

use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.

the class SetParentNodeCommandTest method testExecute.

@Test
@SuppressWarnings("unchecked")
public void testExecute() {
    CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext);
    assertEquals(CommandResult.Type.INFO, result.getType());
    assertFalse(parent.getOutEdges().isEmpty());
    assertFalse(candidate.getInEdges().isEmpty());
    Edge edge = (Edge) parent.getOutEdges().get(0);
    assertTrue(edge.getContent() instanceof Parent);
    assertEquals(parent, edge.getSourceNode());
    assertEquals(candidate, edge.getTargetNode());
    verify(graphIndex, times(1)).addEdge(eq(edge));
    verify(graphIndex, times(0)).addNode(any(Node.class));
}
Also used : Parent(org.kie.workbench.common.stunner.core.graph.content.relationship.Parent) Node(org.kie.workbench.common.stunner.core.graph.Node) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) ContainmentRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 29 with RuleViolation

use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.

the class UpdateElementPositionCommandTest method testExecute.

@Test
public void testExecute() {
    CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext);
    ArgumentCaptor<Bounds> bounds = ArgumentCaptor.forClass(Bounds.class);
    verify(content, times(1)).setBounds(bounds.capture());
    assertEquals(CommandResult.Type.INFO, result.getType());
    Bounds b = bounds.getValue();
    assertEquals(UUID, tested.getUuid());
    assertEquals(LOCATION, tested.getLocation());
    assertEquals(PREVIOUS_LOCATION, tested.getPreviousLocation());
    assertEquals(PREVIOUS_LOCATION.getY(), tested.getPreviousLocation().getY(), 0d);
    assertEquals(Double.valueOf(LOCATION.getX() + W), b.getLowerRight().getX());
    assertEquals(Double.valueOf(LOCATION.getY() + H), b.getLowerRight().getY());
}
Also used : Bounds(org.kie.workbench.common.stunner.core.graph.content.Bounds) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Test(org.junit.Test)

Example 30 with RuleViolation

use of org.kie.workbench.common.stunner.core.rule.RuleViolation in project kie-wb-common by kiegroup.

the class RuleExtensionMultiHandlerTest method testEvaluateAll.

@Test
@SuppressWarnings("unchecked")
public void testEvaluateAll() {
    when(handler1.accepts(eq(rule1), eq(context))).thenReturn(true);
    when(handler2.accepts(eq(rule1), eq(context))).thenReturn(true);
    when(handler1.evaluate(eq(rule1), eq(context))).thenReturn(violations1);
    when(handler2.evaluate(eq(rule1), eq(context))).thenReturn(violations1);
    final RuleViolations result = tested.evaluate(rule1, context);
    assertNotNull(result);
    final Collection<RuleViolation> violations = (Collection<RuleViolation>) result.violations();
    assertTrue(violations.size() == 2);
    assertTrue(violations.contains(violation1));
    assertTrue(violations.contains(violation1));
}
Also used : DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) RuleViolations(org.kie.workbench.common.stunner.core.rule.RuleViolations) Collection(java.util.Collection) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Test(org.junit.Test)

Aggregations

RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)122 Test (org.junit.Test)81 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)59 Node (org.kie.workbench.common.stunner.core.graph.Node)27 Edge (org.kie.workbench.common.stunner.core.graph.Edge)26 RuleViolations (org.kie.workbench.common.stunner.core.rule.RuleViolations)21 LiteralExpression (org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression)18 RuleEvaluationContext (org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext)18 InformationItem (org.kie.workbench.common.dmn.api.definition.v1_1.InformationItem)16 DefaultRuleViolations (org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations)16 RuleSet (org.kie.workbench.common.stunner.core.rule.RuleSet)15 ContainmentRuleViolation (org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation)15 GraphCommandResultBuilder (org.kie.workbench.common.stunner.core.graph.command.GraphCommandResultBuilder)13 DecisionRule (org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule)12 AbstractGraphCommand (org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand)11 List (org.kie.workbench.common.dmn.api.definition.v1_1.List)10 Collection (java.util.Collection)8 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)8 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)8 Binding (org.kie.workbench.common.dmn.api.definition.v1_1.Binding)7