@Override public boolean accepts(final CanContain rule, final NodeContainmentContext context) { final Set<String> parenteLabels = evalUtils.getLabels(context.getParent()); // As for acceptance checking, the delegated handler only needs the parent node id, no need // to calculate roles for the candidate node. return containmentHandler.accepts(rule, RuleContextBuilder.DomainContexts.containment(parenteLabels, Collections.emptySet())); }
@Test public void testAccepts() { Set<String> candidateRoles = Collections.singleton("role2"); Set<String> parentRoles = Collections.singleton(PARENT_ID); when(context.getParentRoles()).thenReturn(parentRoles); when(context.getCandidateRoles()).thenReturn(candidateRoles); assertTrue(tested.accepts(RULE, context)); parentRoles = Collections.singleton("otherParent"); when(context.getParentRoles()).thenReturn(parentRoles); assertFalse(tested.accepts(RULE, context)); }
@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(); }