@Test
public void testNtStatement() throws Exception {

    TestUtil.withInMemoryRepo(session -> {
        TestUtil.installCndFromURL(session, getClass().getResource("/sling_nodetypes.cnd"));
        final int sample = 5;
        List<String> orderedPaths = IntStream.range(0, sample).mapToObj(val -> "/test/ordered" + val).collect(Collectors.toList());
        List<String> unorderedPaths = IntStream.range(0, sample).mapToObj(val -> "/test/unordered" + val).collect(Collectors.toList());
        assertEquals("should generate n paths: ", sample, orderedPaths.size());
        orderedPaths.forEach(Fun.tryOrVoid1(path ->
                JcrUtils.getOrCreateByPath(path, "nt:folder",
                        "sling:OrderedFolder", session, true)));
        unorderedPaths.forEach(Fun.tryOrVoid1(path ->
                JcrUtils.getOrCreateByPath(path, "nt:folder",
                        "sling:Folder", session, true)));
        final ChecklistExporter exporter = new ChecklistExporter.Builder().build();
        final String statement = exporter.ntStatement(session, Arrays.asList("nt:folder", "+sling:Folder"));
        assertTrue("statement should contain 'FROM [sling:Folder]'", statement.contains("FROM [sling:Folder]"));
        assertTrue("statement should contain ' UNION '", statement.contains(" UNION "));
        assertTrue("statement should contain 'FROM [nt:base]'", statement.contains("FROM [nt:base]"));
        assertTrue("statement should contain '[jcr:primaryType] = 'nt:folder'", statement.contains("[jcr:primaryType] = 'nt:folder'"));
        List<ForcedRoot> bySQL2 = exporter.query(session, statement);
        for (String path : unorderedPaths) {
            ForcedRoot root0 = bySQL2.stream().filter(root -> path.equals(root.getPath())).findFirst().orElse(null);
            assertNotNull(String.format("root for path %s should not be null", path), root0);
            assertEquals(String.format("root primaryType for path %s should be sling:Folder", path),
                    "sling:Folder", root0.getPrimaryType());
        }
        for (String path : orderedPaths) {
            ForcedRoot root0 = bySQL2.stream().filter(root -> path.equals(root.getPath())).findFirst().orElse(null);
            assertNotNull(String.format("root for path %s should not be null", path), root0);
            assertEquals(String.format("root primaryType for path %s should be sling:OrderedFolder", path),
                    "sling:OrderedFolder", root0.getPrimaryType());
        }
        for (String path : Collections.singletonList("/test")) {
            ForcedRoot root0 = bySQL2.stream().filter(root -> path.equals(root.getPath())).findFirst().orElse(null);
            assertNotNull(String.format("root for path %s should not be null", path), root0);
            assertEquals(String.format("root primaryType for path %s should be nt:folder", path),
                    "nt:folder", root0.getPrimaryType());
        }
        final String simpler = exporter.ntStatement(session, Collections.singletonList("sling:OrderedFolder"));
        List<ForcedRoot> orderedRoots = exporter.query(session, simpler);
        for (String path : orderedPaths) {
            ForcedRoot root0 = orderedRoots.stream().filter(root -> path.equals(root.getPath())).findFirst().orElse(null);
            assertNotNull(String.format("root for path %s should not be null", path), root0);
            assertEquals(String.format("root primaryType for path %s should be sling:OrderedFolder", path),
                    "sling:OrderedFolder", root0.getPrimaryType());
        }
    });
}