@Test
public void testGetPrivilegesFromJson() {

    List<PrivilegeDefinition> oneDef = JsonCnd.getPrivilegesFromJson(key("nt:canDo", obj()
                    .key(JsonCnd.PRIVILEGE_KEY_ABSTRACT, true)
                    .key(JsonCnd.PRIVILEGE_KEY_CONTAINS, arr("jcr:read", "jcr:write"))).get(),
            JsonCnd.BUILTIN_MAPPINGS);
    assertEquals("size is ", 1, oneDef.size());
    assertEquals("name is", "canDo", oneDef.get(0).getName().getLocalName());
    assertEquals("uri is", Name.NS_NT_URI, oneDef.get(0).getName().getNamespaceURI());
    List<PrivilegeDefinition> oneName = JsonCnd.getPrivilegesFromJson(arr("nt:canDo").get(),
            JsonCnd.BUILTIN_MAPPINGS);
    assertEquals("size is ", 1, oneName.size());
    assertEquals("name is", "canDo", oneName.get(0).getName().getLocalName());
    assertEquals("uri is", Name.NS_NT_URI, oneName.get(0).getName().getNamespaceURI());
    List<PrivilegeDefinition> jsonNull = JsonCnd.getPrivilegesFromJson(wrap(null), JsonCnd.BUILTIN_MAPPINGS);
    assertEquals("size is ", 0, jsonNull.size());
    List<PrivilegeDefinition> defs = JsonCnd.getPrivilegesFromJson(obj()
            .key("jcr:canDo", obj())
            .key("jcr:willDo", obj()
                    .key(JsonCnd.PRIVILEGE_KEY_ABSTRACT, false))
            .key("jcr:wouldDoBut", obj()
                    .key(JsonCnd.PRIVILEGE_KEY_ABSTRACT, true))
            .key("jcr:wontDo", null)
            .key("jcr:none", obj()
                    .key(JsonCnd.PRIVILEGE_KEY_CONTAINS, arr()))
            .key("jcr:rw", obj()
                    .key(JsonCnd.PRIVILEGE_KEY_ABSTRACT, false)
                    .key(JsonCnd.PRIVILEGE_KEY_CONTAINS,
                            arr("jcr:read", "jcr:write", "jcr:addChildNodes")))
            .key("jcr:mightRw", obj()
                    .key(JsonCnd.PRIVILEGE_KEY_ABSTRACT, true)
                    .key(JsonCnd.PRIVILEGE_KEY_CONTAINS,
                            arr("jcr:read", "jcr:write", "jcr:removeNode")))
            .get(), getMapping());
    final Map<String, PrivilegeDefinition> defMap = defs.stream()
            .collect(Collectors.toMap(compose1(PrivilegeDefinition::getName, uncheck1(resolver::getJCRName)),
                    def -> def));
    final PrivilegeDefinition canDo = defMap.get("jcr:canDo");
    assertNotNull("canDo not null", canDo);
    assertFalse("canDo not abstract", canDo.isAbstract());
    assertEquals("canDo contains nothing", Collections.emptySet(), canDo.getDeclaredAggregateNames());
    final PrivilegeDefinition willDo = defMap.get("jcr:willDo");
    assertNotNull("willDo not null", willDo);
    assertFalse("willDo not abstract", willDo.isAbstract());
    assertEquals("willDo contains nothing", Collections.emptySet(), willDo.getDeclaredAggregateNames());
    final PrivilegeDefinition wouldDoBut = defMap.get("jcr:wouldDoBut");
    assertNotNull("wouldDoBut not null", wouldDoBut);
    assertTrue("wouldDoBut is abstract", wouldDoBut.isAbstract());
    assertEquals("wouldDoBut contains nothing", Collections.emptySet(), wouldDoBut.getDeclaredAggregateNames());
    final PrivilegeDefinition wontDo = defMap.get("jcr:wontDo");
    assertNull("wontDo is null", wontDo);
    final PrivilegeDefinition none = defMap.get("jcr:none");
    assertNotNull("none not null", none);
    assertFalse("none not abstract", none.isAbstract());
    assertEquals("none contains nothing", Collections.emptySet(), none.getDeclaredAggregateNames());
    final PrivilegeDefinition rw = defMap.get("jcr:rw");
    assertNotNull("rw not null", rw);
    assertFalse("rw not abstract", rw.isAbstract());
    assertEquals("rw contains nothing", Stream.of("jcr:read", "jcr:write", "jcr:addChildNodes")
                    .map(uncheck1(resolver::getQName)).collect(Collectors.toSet()),
            rw.getDeclaredAggregateNames());
    final PrivilegeDefinition mightRw = defMap.get("jcr:mightRw");
    assertNotNull("mightRw not null", mightRw);
    assertTrue("mightRw is abstract", mightRw.isAbstract());
    assertEquals("mightRw contains nothing", Stream.of("jcr:read", "jcr:write", "jcr:removeNode")
            .map(uncheck1(resolver::getQName)).collect(Collectors.toSet()), mightRw.getDeclaredAggregateNames());
}