MappingRuleMatchers { public static MappingRuleMatcher createUserGroupMatcher(String groupName) { return new UserGroupMatcher(groupName); } private  MappingRuleMatchers(); static MappingRuleMatcher createUserMatcher(String userName); static MappingRuleMatcher createUserGroupMatcher(String groupName); static MappingRuleMatcher createUserGroupMatcher(
      String userName, String groupName); static MappingRuleMatcher createApplicationNameMatcher(String name); static MappingRuleMatcher createAllMatcher();  }
@Test public void testBoolOperatorMatchers() { VariableContext developerBob = new VariableContext(); developerBob.put("%user", "bob"); developerBob.put("%primary_group", "developers"); developerBob.putExtraDataset("groups", Sets.newHashSet("developers")); VariableContext testerBob = new VariableContext(); testerBob.put("%user", "bob"); testerBob.put("%primary_group", "testers"); testerBob.putExtraDataset("groups", Sets.newHashSet("testers")); VariableContext testerDave = new VariableContext(); testerDave.put("%user", "dave"); testerDave.put("%primary_group", "testers"); testerDave.putExtraDataset("groups", Sets.newHashSet("testers")); VariableContext accountantDave = new VariableContext(); accountantDave.put("%user", "dave"); accountantDave.put("%primary_group", "accountants"); MappingRuleMatcher userBob = new MappingRuleMatchers.VariableMatcher("%user", "bob"); MappingRuleMatcher groupDevelopers = new MappingRuleMatchers.VariableMatcher( "%primary_group", "developers"); MappingRuleMatcher groupAccountants = new MappingRuleMatchers.VariableMatcher( "%primary_group", "accountants"); MappingRuleMatcher developerBobMatcher = new MappingRuleMatchers.AndMatcher( userBob, groupDevelopers); MappingRuleMatcher testerDaveMatcher = MappingRuleMatchers.createUserGroupMatcher("dave", "testers"); MappingRuleMatcher accountantOrBobMatcher = new MappingRuleMatchers.OrMatcher(groupAccountants, userBob); assertTrue(developerBobMatcher.match(developerBob)); assertFalse(developerBobMatcher.match(testerBob)); assertFalse(developerBobMatcher.match(testerDave)); assertFalse(developerBobMatcher.match(accountantDave)); assertFalse(testerDaveMatcher.match(developerBob)); assertFalse(testerDaveMatcher.match(testerBob)); assertTrue(testerDaveMatcher.match(testerDave)); assertFalse(testerDaveMatcher.match(accountantDave)); assertTrue(accountantOrBobMatcher.match(developerBob)); assertTrue(accountantOrBobMatcher.match(testerBob)); assertFalse(accountantOrBobMatcher.match(testerDave)); assertTrue(accountantOrBobMatcher.match(accountantDave)); }
@Test public void testGroupMatching() { VariableContext letterGroups = new VariableContext(); letterGroups.putExtraDataset("groups", Sets.newHashSet("a", "b", "c")); VariableContext numberGroups = new VariableContext(); numberGroups.putExtraDataset("groups", Sets.newHashSet("1", "2", "3")); VariableContext noGroups = new VariableContext(); MappingRuleMatcher matchA = MappingRuleMatchers.createUserGroupMatcher("a"); MappingRuleMatcher matchB = MappingRuleMatchers.createUserGroupMatcher("b"); MappingRuleMatcher matchC = MappingRuleMatchers.createUserGroupMatcher("c"); MappingRuleMatcher match1 = MappingRuleMatchers.createUserGroupMatcher("1"); MappingRuleMatcher match2 = MappingRuleMatchers.createUserGroupMatcher("2"); MappingRuleMatcher match3 = MappingRuleMatchers.createUserGroupMatcher("3"); MappingRuleMatcher matchNull = MappingRuleMatchers.createUserGroupMatcher(null); assertTrue(matchA.match(letterGroups)); assertTrue(matchB.match(letterGroups)); assertTrue(matchC.match(letterGroups)); assertFalse(match1.match(letterGroups)); assertFalse(match2.match(letterGroups)); assertFalse(match3.match(letterGroups)); assertFalse(matchNull.match(letterGroups)); assertFalse(matchA.match(numberGroups)); assertFalse(matchB.match(numberGroups)); assertFalse(matchC.match(numberGroups)); assertTrue(match1.match(numberGroups)); assertTrue(match2.match(numberGroups)); assertTrue(match3.match(numberGroups)); assertFalse(matchNull.match(numberGroups)); assertFalse(matchA.match(noGroups)); assertFalse(matchB.match(noGroups)); assertFalse(matchC.match(noGroups)); assertFalse(match1.match(noGroups)); assertFalse(match2.match(noGroups)); assertFalse(match3.match(noGroups)); assertFalse(matchNull.match(noGroups)); }