@Test public void testReadRestrictions() throws Exception { NodeUtil aceNode = new NodeUtil(root.getTree("/")).addChild("test", NT_REP_GRANT_ACE); aceNode.setBoolean("boolean", true); aceNode.setValues("longs", new Value[] {vf.createValue(10), vf.createValue(290)}); aceNode.setString(REP_GLOB, "*"); aceNode.setNames(REP_NT_NAMES); // empty array aceNode.setString("invalid", "val"); aceNode.setStrings("invalid2", "val1", "val2", "val3"); Set<Restriction> restrictions = provider.readRestrictions("/test", aceNode.getTree()); assertEquals(4, restrictions.size()); for (Restriction r : restrictions) { String name = r.getDefinition().getName(); if (!supported.contains(name)) { fail("read unsupported restriction"); } } }
@Test public void testValidateRestrictionsAtEntryNode() throws Exception { NodeUtil aceNode = new NodeUtil(root.getTree("/")).addChild("test", NT_REP_GRANT_ACE); aceNode.setBoolean("boolean", true); aceNode.setValues("longs", new Value[] {vf.createValue(10), vf.createValue(290)}); aceNode.setString(REP_GLOB, "*"); aceNode.setNames(REP_NT_NAMES); // empty array provider.validateRestrictions("/test", aceNode.getTree()); }
@Test public void testValidateInvalidRestrictionDef() throws Exception { RestrictionProvider rp = CompositeRestrictionProvider.newInstance(rp1, rp3); NodeUtil aceNode = new NodeUtil(root.getTree("/")).addChild("test", NT_REP_GRANT_ACE); NodeUtil rNode = aceNode.addChild(REP_RESTRICTIONS, NT_REP_RESTRICTIONS); rNode.setValues(REP_GLOB, new Value[]{vf.createValue(10), vf.createValue(290)}); try { rp.validateRestrictions("/test", aceNode.getTree()); fail("Validation must detect invalid restriction definition"); } catch (AccessControlException e) { // success } }
@Test public void testGetRestrictionPattern() throws Exception { NodeUtil aceNode = new NodeUtil(root.getTree("/")).addChild("test", NT_REP_GRANT_ACE); NodeUtil rNode = aceNode.addChild(REP_RESTRICTIONS, NT_REP_RESTRICTIONS); rNode.setString(REP_GLOB, "*"); assertFalse(provider.getPattern("/test", aceNode.getTree()) instanceof CompositePattern); rNode.setBoolean("boolean", true); rNode.setValues("longs", new Value[]{vf.createValue(10), vf.createValue(290)}); assertTrue(provider.getPattern("/test", rNode.getTree()) instanceof CompositePattern); } }
NodeUtil rNode = aceNode.addChild(REP_RESTRICTIONS, NT_REP_RESTRICTIONS); rNode.setBoolean("boolean", true); rNode.setValues("longs", new Value[] {vf.createValue(10), vf.createValue(290)}); rNode.setString(REP_GLOB, "*");