AclFactory { public Map<PatternHolder, Set<String>> parseAcl(Buffer buffer) throws ValidationException { ValidationResult validationResult = Validator.validateStatic(buffer, aclSchema, log); if (!validationResult.isSuccess()) { throw new ValidationException(validationResult); } Map<PatternHolder, Set<String>> result = new HashMap<>(); JsonObject aclItems = new JsonObject(buffer.toString("UTF-8")); for (String id : aclItems.fieldNames()) { Object aclItemToTest = aclItems.getValue(id); if (!(aclItemToTest instanceof JsonObject)) { throw new ValidationException("acl item must be a map: " + id); } JsonObject aclItem = aclItems.getJsonObject(id); aclItems.getValue("debug.read"); String path = aclItem.getString("path"); JsonArray methods = aclItem.getJsonArray("methods"); checkPropertiesValid(path, methods, id); if (path != null) { PatternHolder holder = new PatternHolder(Pattern.compile(path)); Set<String> methodSet = result.get(holder); if (methodSet == null) { methodSet = new HashSet<>(); result.put(holder, methodSet); } if (methods != null) { for (Object methodObj : methods) { String method = (String) methodObj; methodSet.add(method); } } } } return result; } AclFactory(); Map<PatternHolder, Set<String>> parseAcl(Buffer buffer);  }
@Test public void testInvalidACLJson() throws ValidationException { thrown.expect(ValidationException.class); thrown.expectMessage("Unable to parse json"); aclFactory.parseAcl(Buffer.buffer(INVALID_ACL_JSON)); }
@Test public void testValidAclConfig(TestContext context) throws ValidationException { Map<PatternHolder, Set<String>> result = aclFactory.parseAcl(Buffer.buffer(VALID_ACL_RESOURCE)); context.assertNotNull(result); context.assertEquals(1, result.size()); Collection<Set<String>> values = result.values(); for (Set<String> value : values) { context.assertTrue(value.containsAll(Arrays.asList("POST", "GET", "DELETE"))); context.assertFalse(value.contains("PUT")); } }