@Override public boolean accepts(final CanConnect rule, final GraphConnectionContext context) { final Edge<? extends View<?>, ? extends Node> connector = context.getConnector(); final Set<String> labels = evalUtils.getLabels(connector); return labels.stream() .filter(cr -> rule.getRole().equals(cr) && // As for acceptance the delegated handler only needs the connector id, no need // to calculate roles for current source/target nodes. connectionEvaluationHandler.accepts(rule, RuleContextBuilder.DomainContexts.connection(cr, Optional.empty(), Optional.empty()))) .findAny() .isPresent(); }
@Before public void setup() throws Exception { RegistryFactory registryFactory = mock(RegistryFactory.class); when(registryFactory.newRuleHandlerRegistry()).thenReturn(ruleHandlerRegistry); when(ruleHandlerRegistry.getHandlersByContext(eq(ContainmentContext.class))).thenReturn(Arrays.asList(containmentHandler)); when(ruleHandlerRegistry.getHandlersByContext(eq(ConnectionContext.class))).thenReturn(Arrays.asList(connectionHandler)); when(connectionHandler.getRuleType()).thenReturn(CanConnect.class); when(connectionHandler.getContextType()).thenReturn(ConnectionContext.class); when(connectionHandler.accepts(any(CanConnect.class), any(ConnectionContext.class))).thenReturn(true); when(containmentHandler.accepts(any(CanContain.class), any(ContainmentContext.class))).thenReturn(true); when(containmentHandler.getRuleType()).thenReturn(CanContain.class); when(containmentHandler.getContextType()).thenReturn(ContainmentContext.class); RuleManagerImpl delegate = new RuleManagerImpl(registryFactory); when(ruleSet.getName()).thenReturn("testRuleSet"); when(ruleSet.getRules()).thenReturn(Arrays.asList(containmentRule, connectionRule)); tested = new CachedRuleManager(delegate); tested.init(); }