Search in sources :

Example 1 with RuleExtension

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

the class ConnectorParentsMatchHandlerTest method testAccept.

@Test(expected = IllegalArgumentException.class)
public void testAccept() {
    final RuleExtension ruleExtension = mock(RuleExtension.class);
    when(ruleExtension.getArguments()).thenReturn(new String[] { "parentType" });
    final RuleEvaluationContext context = mock(RuleEvaluationContext.class);
    assertTrue(tested.accepts(ruleExtension, context));
    verify(multiHandler, times(1)).accepts(eq(ruleExtension), eq(context));
}
Also used : RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) RuleExtension(org.kie.workbench.common.stunner.core.rule.ext.RuleExtension) Test(org.junit.Test)

Example 2 with RuleExtension

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

the class ConnectorParentsMatchHandlerTest method testEvaluateNoParentType.

@Test(expected = IllegalArgumentException.class)
public void testEvaluateNoParentType() {
    final RuleExtension ruleExtension = mock(RuleExtension.class);
    when(ruleExtension.getArguments()).thenReturn(new String[] {});
    final RuleEvaluationContext context = mock(RuleEvaluationContext.class);
    tested.evaluate(ruleExtension, context);
}
Also used : RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) RuleExtension(org.kie.workbench.common.stunner.core.rule.ext.RuleExtension) Test(org.junit.Test)

Example 3 with RuleExtension

use of org.kie.workbench.common.stunner.core.rule.ext.RuleExtension 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);
}
Also used : CanContain(org.kie.workbench.common.stunner.core.rule.impl.CanContain) RuleViolationImpl(org.kie.workbench.common.stunner.core.rule.violations.RuleViolationImpl) RuleExtensionHandler(org.kie.workbench.common.stunner.core.rule.ext.RuleExtensionHandler) ArrayList(java.util.ArrayList) DefaultRuleViolations(org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations) HashSet(java.util.HashSet) RuleExtension(org.kie.workbench.common.stunner.core.rule.ext.RuleExtension) Before(org.junit.Before)

Example 4 with RuleExtension

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

the class ConnectorParentsMatchHandlerTest method testAcceptNoParentType.

@Test(expected = IllegalArgumentException.class)
public void testAcceptNoParentType() {
    final RuleExtension ruleExtension = mock(RuleExtension.class);
    when(ruleExtension.getArguments()).thenReturn(new String[] {});
    final RuleEvaluationContext context = mock(RuleEvaluationContext.class);
    tested.accepts(ruleExtension, context);
}
Also used : RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) RuleExtension(org.kie.workbench.common.stunner.core.rule.ext.RuleExtension) Test(org.junit.Test)

Example 5 with RuleExtension

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

the class ConnectorParentsMatchHandlerTest method testEvaluate.

@Test(expected = IllegalArgumentException.class)
public void testEvaluate() {
    final RuleExtension ruleExtension = mock(RuleExtension.class);
    when(ruleExtension.getArguments()).thenReturn(new String[] { "parentType" });
    final RuleEvaluationContext context = mock(RuleEvaluationContext.class);
    assertEquals(ruleViolations, tested.evaluate(ruleExtension, context));
    verify(multiHandler, times(1)).evaluate(eq(ruleExtension), eq(context));
}
Also used : RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) RuleExtension(org.kie.workbench.common.stunner.core.rule.ext.RuleExtension) Test(org.junit.Test)

Aggregations

RuleExtension (org.kie.workbench.common.stunner.core.rule.ext.RuleExtension)5 Test (org.junit.Test)4 RuleEvaluationContext (org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext)4 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Before (org.junit.Before)1 RuleExtensionHandler (org.kie.workbench.common.stunner.core.rule.ext.RuleExtensionHandler)1 CanContain (org.kie.workbench.common.stunner.core.rule.impl.CanContain)1 DefaultRuleViolations (org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations)1 RuleViolationImpl (org.kie.workbench.common.stunner.core.rule.violations.RuleViolationImpl)1