@Test
public void testNodeToRootNodeTypeScoped() throws Exception {

    TestUtil.withInMemoryRepo(session -> {
        TestUtil.installCndFromURL(session, getClass().getResource("/sling_nodetypes.cnd"));
        final NamespaceMapping mapping = new NamespaceMapping(new SessionNamespaceResolver(session));
        Node node1 = JcrUtils.getOrCreateByPath("/test/node1", "nt:folder", session);
        node1.addMixin("mix:title");
        node1.addMixin("sling:Resource");
        node1.addMixin("sling:ResourceSuperType");
        ChecklistExporter mixExporter = new ChecklistExporter.Builder().withNodeTypeFilters(
                Rules.fromJsonArray(arr(key("type", "include").key("pattern", "mix:.*"))
                        .get())).build();
        ChecklistExporter slingExporter = new ChecklistExporter.Builder().withNodeTypeFilters(
                Rules.fromJsonArray(arr(key("type", "include").key("pattern", "sling:.*"))
                        .get())).build();
        ChecklistExporter rtExporter = new ChecklistExporter.Builder().withNodeTypeFilters(
                Rules.fromJsonArray(arr(key("type", "include").key("pattern", "sling:Resource"))
                        .get())).build();
        ForcedRoot mixRoot = mixExporter.nodeToRoot(node1, mapping).orElse(null);
        assertNotNull("mixRoot should not be null", mixRoot);
        assertTrue("mixRoot should contain mix:title mixin", mixRoot.getMixinTypes().contains("mix:title"));
        assertFalse("mixRoot should not contain sling:Resource mixin", mixRoot.getMixinTypes().contains("sling:Resource"));
        assertFalse("mixRoot should not contain sling:ResourceSuperType mixin", mixRoot.getMixinTypes().contains("sling:ResourceSuperType"));
        ForcedRoot slingRoot = slingExporter.nodeToRoot(node1, mapping).orElse(null);
        assertNotNull("slingRoot should not be null", slingRoot);
        assertFalse("slingRoot should not contain mix:title mixin", slingRoot.getMixinTypes().contains("mix:title"));
        assertTrue("slingRoot should contain sling:Resource mixin", slingRoot.getMixinTypes().contains("sling:Resource"));
        assertTrue("slingRoot should contain sling:ResourceSuperType mixin", slingRoot.getMixinTypes().contains("sling:ResourceSuperType"));
        ForcedRoot rtRoot = rtExporter.nodeToRoot(node1, mapping).orElse(null);
        assertNotNull("rtRoot should not be null", rtRoot);
        assertNull("rtRoot primaryType should be null", rtRoot.getPrimaryType());
        assertFalse("rtRoot should not contain mix:title mixin", rtRoot.getMixinTypes().contains("mix:title"));
        assertTrue("rtRoot should contain sling:Resource mixin", rtRoot.getMixinTypes().contains("sling:Resource"));
        assertFalse("rtRoot should not contain sling:ResourceSuperType mixin", rtRoot.getMixinTypes().contains("sling:ResourceSuperType"));
    });
}