Search in sources :

Example 6 with CanConnect

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

the class CommonLookupsTest method checkAllowedTargetDefinitionsWithNotPermittedStartConnectionRules.

@Test
@SuppressWarnings("unchecked")
public void checkAllowedTargetDefinitionsWithNotPermittedStartConnectionRules() {
    this.ruleSet = new RuleSetImpl("connection-rules", new ArrayList<Rule>() {

        {
            add(new CanConnect(MockConnector.class.getName(), MockConnector.class.getName(), new ArrayList<CanConnect.PermittedConnection>() {

                {
                    add(new CanConnect.PermittedConnection("not-permitted", "definition-role"));
                }
            }));
        }
    });
    when(definitionAdapter.getLabels(any(MockDefinition.class))).thenReturn(Collections.singleton("definition-role"));
    when(definitionSetRuleAdapter.getRuleSet(any(MockDefinitionSet.class))).thenReturn(ruleSet);
    final Set<Object> targetDefinitions = lookups.getAllowedTargetDefinitions(MockDefinitionSet.class.getName(), graph, node, MockConnector.class.getName(), 0, 10);
    assertTrue(targetDefinitions.isEmpty());
}
Also used : ArrayList(java.util.ArrayList) RuleSetImpl(org.kie.workbench.common.stunner.core.rule.RuleSetImpl) CanConnect(org.kie.workbench.common.stunner.core.rule.impl.CanConnect) Test(org.junit.Test)

Example 7 with CanConnect

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

the class CommonLookupsTest method checkAllowedTargetDefinitionsWithPermittedConnectionRules.

@Test
@SuppressWarnings("unchecked")
public void checkAllowedTargetDefinitionsWithPermittedConnectionRules() {
    this.ruleSet = new RuleSetImpl("connection-rules", new ArrayList<Rule>() {

        {
            add(new CanConnect(MockConnector.class.getName(), MockConnector.class.getName(), new ArrayList<CanConnect.PermittedConnection>() {

                {
                    add(new CanConnect.PermittedConnection("definition-role", "definition-role"));
                }
            }));
        }
    });
    when(definitionAdapter.getLabels(any(MockDefinition.class))).thenReturn(Collections.singleton("definition-role"));
    when(definitionSetRuleAdapter.getRuleSet(any(MockDefinitionSet.class))).thenReturn(ruleSet);
    final Set<Object> targetDefinitions = lookups.getAllowedTargetDefinitions(MockDefinitionSet.class.getName(), graph, node, MockConnector.class.getName(), 0, 10);
    assertEquals(1, targetDefinitions.size());
    assertTrue(targetDefinitions.iterator().next() instanceof MockDefinition);
}
Also used : ArrayList(java.util.ArrayList) RuleSetImpl(org.kie.workbench.common.stunner.core.rule.RuleSetImpl) CanConnect(org.kie.workbench.common.stunner.core.rule.impl.CanConnect) Test(org.junit.Test)

Example 8 with CanConnect

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

the class CommonLookupsTest method checkAllowedTargetDefinitionsWithNotPermittedEndConnectionRules.

@Test
@SuppressWarnings("unchecked")
public void checkAllowedTargetDefinitionsWithNotPermittedEndConnectionRules() {
    this.ruleSet = new RuleSetImpl("connection-rules", new ArrayList<Rule>() {

        {
            add(new CanConnect(MockConnector.class.getName(), MockConnector.class.getName(), new ArrayList<CanConnect.PermittedConnection>() {

                {
                    add(new CanConnect.PermittedConnection("definition-role", "not-permitted"));
                }
            }));
        }
    });
    when(definitionAdapter.getLabels(any(MockDefinition.class))).thenReturn(Collections.singleton("definition-role"));
    when(definitionSetRuleAdapter.getRuleSet(any(MockDefinitionSet.class))).thenReturn(ruleSet);
    final Set<Object> targetDefinitions = lookups.getAllowedTargetDefinitions(MockDefinitionSet.class.getName(), graph, node, MockConnector.class.getName(), 0, 10);
    assertTrue(targetDefinitions.isEmpty());
}
Also used : ArrayList(java.util.ArrayList) RuleSetImpl(org.kie.workbench.common.stunner.core.rule.RuleSetImpl) CanConnect(org.kie.workbench.common.stunner.core.rule.impl.CanConnect) Test(org.junit.Test)

Aggregations

CanConnect (org.kie.workbench.common.stunner.core.rule.impl.CanConnect)8 ArrayList (java.util.ArrayList)3 LinkedHashSet (java.util.LinkedHashSet)3 Test (org.junit.Test)3 RuleSetImpl (org.kie.workbench.common.stunner.core.rule.RuleSetImpl)3 Rule (org.kie.workbench.common.stunner.core.rule.Rule)2 DefaultRuleViolations (org.kie.workbench.common.stunner.core.rule.violations.DefaultRuleViolations)2 Optional (java.util.Optional)1 Set (java.util.Set)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Inject (javax.inject.Inject)1 DefinitionManager (org.kie.workbench.common.stunner.core.api.DefinitionManager)1 Edge (org.kie.workbench.common.stunner.core.graph.Edge)1 Node (org.kie.workbench.common.stunner.core.graph.Node)1 View (org.kie.workbench.common.stunner.core.graph.content.view.View)1 RuleEvaluationHandler (org.kie.workbench.common.stunner.core.rule.RuleEvaluationHandler)1 RuleViolations (org.kie.workbench.common.stunner.core.rule.RuleViolations)1 GraphConnectionContext (org.kie.workbench.common.stunner.core.rule.context.GraphConnectionContext)1 RuleContextBuilder (org.kie.workbench.common.stunner.core.rule.context.impl.RuleContextBuilder)1 CanContain (org.kie.workbench.common.stunner.core.rule.impl.CanContain)1