use of org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations in project kie-wb-common by kiegroup.
the class DeleteNodeCommandTest method testNotAllowed.
@Test
@SuppressWarnings("unchecked")
public void testNotAllowed() {
final RuleViolations FAILED_VIOLATIONS = new DefaultRuleViolations().addViolation(new CardinalityMaxRuleViolation("candidate", 1, 2, Violation.Type.ERROR));
when(ruleManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(FAILED_VIOLATIONS);
CommandResult<RuleViolation> result = tested.allow(graphCommandExecutionContext);
assertEquals(CommandResult.Type.ERROR, result.getType());
}
use of org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations in project kie-wb-common by kiegroup.
the class DeleteNodeCommandTest method testExecuteCheckFailed.
@Test
@SuppressWarnings("unchecked")
public void testExecuteCheckFailed() {
final RuleViolations FAILED_VIOLATIONS = new DefaultRuleViolations().addViolation(new CardinalityMaxRuleViolation("candidate", 1, 2, Violation.Type.ERROR));
when(ruleManager.evaluate(any(RuleSet.class), any(RuleEvaluationContext.class))).thenReturn(FAILED_VIOLATIONS);
CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext);
assertEquals(CommandResult.Type.ERROR, result.getType());
verify(graphIndex, times(0)).removeNode(any(Node.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));
}
use of org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations in project kie-wb-common by kiegroup.
the class DockNodeCommandTest method testExecuteCheckFailed.
@Test
@SuppressWarnings("unchecked")
public void testExecuteCheckFailed() {
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.execute(graphCommandExecutionContext);
assertEquals(CommandResult.Type.ERROR, result.getType());
assertTrue(parent.getOutEdges().isEmpty());
assertTrue(candidate.getInEdges().isEmpty());
}
use of org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations in project kie-wb-common by kiegroup.
the class SetParentNodeCommandTest method testExecuteCheckFailed.
@Test
@SuppressWarnings("unchecked")
public void testExecuteCheckFailed() {
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.execute(graphCommandExecutionContext);
assertEquals(CommandResult.Type.ERROR, result.getType());
assertTrue(parent.getOutEdges().isEmpty());
assertTrue(candidate.getInEdges().isEmpty());
}
use of org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations in project kie-wb-common by kiegroup.
the class RuleManagerImplTest method setup.
@Before
public void setup() throws Exception {
rule1 = new CanContain("r1", "r1-cId", new HashSet<String>(2) {
{
add("role1");
add("role2");
}
});
rule2 = new CanContain("r2", "r2-cId", new HashSet<String>(2) {
{
add("role1");
add("role2");
}
});
ruleEvaluationContext = RuleContextBuilder.DomainContexts.containment(Collections.singleton("r1-cId"), new HashSet<String>(1) {
{
add("r2-cId");
}
});
ruleViolation1 = new RuleViolationImpl("error - v1");
ruleViolation2 = new RuleViolationImpl("error - v2");
ruleViolation3 = new RuleViolationImpl("error - v3");
ruleViolations1 = new DefaultRuleViolations().addViolation(ruleViolation1);
ruleViolations2 = new DefaultRuleViolations().addViolation(ruleViolation2);
ruleViolations3 = new DefaultRuleViolations().addViolation(ruleViolation3);
ruleExtension = new RuleExtension("re1", "cId").setHandlerType(RuleExtensionHandler.class);
ruleSet = new RuleSetImpl("rs1", new ArrayList<Rule>(2) {
{
add(rule1);
add(rule2);
add(ruleExtension);
}
});
handlers.add(handler1);
handlers.add(handler2);
when(registryFactory.newRuleHandlerRegistry()).thenReturn(registry);
when(registry.getHandlersByContext(any(Class.class))).thenReturn(handlers);
when(registry.getExtensionHandler(eq(RuleExtensionHandler.class))).thenReturn(extensionHandler);
when(handler1.getRuleType()).thenReturn(CanContain.class);
when(handler1.getContextType()).thenReturn(ContainmentContext.class);
when(handler2.getRuleType()).thenReturn(CanContain.class);
when(handler2.getContextType()).thenReturn(ContainmentContext.class);
when(extensionHandler.getRuleType()).thenReturn(RuleExtension.class);
when(extensionHandler.getContextType()).thenReturn(ContainmentContext.class);
tested = new RuleManagerImpl(registryFactory);
}
Aggregations