@Test
public void testFromJson_scopePaths() throws Exception {

    final File targetFile = new File(testOutDir, "testFromJson_scopePaths.json");
    if (targetFile.exists()) {
        targetFile.delete();
    }
    OakMachine.Builder emptyOak = TestUtil.fromPlan(obj().get());
    WebsterChecklistTarget target = WebsterChecklistTarget.fromJson(targetFile, obj().get());
    emptyOak.build().initAndInspect(target::perform);
    final List<JcrNs> nsList = Arrays.asList(JcrNs.create(OakMachine.NS_PREFIX_OAKPAL, OakMachine.NS_URI_OAKPAL));
    OakMachine.Builder twoRootsOak = TestUtil.fromPlan(obj()
            .key("forcedRoots", arr()
                    .val(new ForcedRoot().withPath("/foo1"))
                    .val(new ForcedRoot().withPath("/foo2"))
            )
            .get());
    WebsterChecklistTarget twoRootsTarget = WebsterChecklistTarget.fromJson(targetFile, obj()
            //.key("jcrNamespaces", nsList)
            .key("selectors", arr()
                    .val(key("type", "path").key("args", arr("/foo1", "/foo2"))))
            .key("scopePaths", arr(new Rule(RuleType.INCLUDE, Pattern.compile("/foo2"))))
            .key("nodeTypeFilters", arr(new Rule(RuleType.EXCLUDE, Pattern.compile(OakMachine.NS_PREFIX_OAKPAL + ":.*"))))
            .get());
    twoRootsOak.build().adminInitAndInspect(twoRootsTarget::perform);
    assertJsonFile(targetFile, json -> {
        final Checklist checklist = Checklist.fromJson("testFromJson", null, json);
        assertEquals("expect 1 roots", 1, checklist.getForcedRoots().size());
        assertEquals("expect root path", "/foo2", checklist.getForcedRoots().get(0).getPath());
        assertNull("expect root null primaryType", checklist.getForcedRoots().get(0).getPrimaryType());
    });
    OakMachine.Builder twoTypedRootsOak = TestUtil.fromPlan(obj()
            .key("forcedRoots", arr()
                    .val(new ForcedRoot().withPath("/foo1").withPrimaryType("nt:folder"))
                    .val(new ForcedRoot().withPath("/foo2").withPrimaryType("nt:folder"))
            )
            .get());
    WebsterChecklistTarget twoTypedRootsTarget = WebsterChecklistTarget.fromJson(targetFile, obj()
            .key("jcrNamespaces", nsList)
            .key("selectors", arr()
                    .val(key("type", "path").key("args", arr("/foo1", "/foo2"))))
            .key("scopePaths", arr(new Rule(RuleType.INCLUDE, Pattern.compile("/foo1"))))
            .key("nodeTypeFilters", arr(new Rule(RuleType.EXCLUDE, Pattern.compile("oakpaltmp:.*"))))
            .key("updatePolicy", "replace")
            .get());
    twoTypedRootsOak.build().adminInitAndInspect(twoTypedRootsTarget::perform);
    assertJsonFile(targetFile, json -> {
        final Checklist checklist = Checklist.fromJson("testFromJson", null, json);
        assertEquals("expect 1 roots", 2, checklist.getForcedRoots().size());
        assertEquals("expect root path", "/foo1", checklist.getForcedRoots().get(0).getPath());
        assertEquals("expect root primaryType of nt:folder", "nt:folder",
                checklist.getForcedRoots().get(0).getPrimaryType());
    });
}