@Test
@FixFor( "MODE-2401" )
public void shouldNotReturnNonQueryableNodeTypes() throws Exception {

    Node folder1 = session.getRootNode().addNode("folder1", "test:noQueryFolder");
    Node folder2 = session.getRootNode().addNode("folder2", "nt:folder");
    Node folder3 = session.getRootNode().addNode("folder3", "test:noQueryFolder");
    Node folder31 = folder3.addNode("folder3_1", "nt:folder");
    Node folder311 = folder31.addNode("folder3_1", "test:noQueryFolder");
    folder311.addNode("folder3_1_1", "nt:folder");
    session.save();
    try {
        String sql = "SELECT folder.[jcr:name] FROM [nt:folder] AS folder";
        Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2);
        NodeIterator nodes = query.execute().getNodes();
        assertEquals(3, nodes.getSize());
        Set<String> names = new TreeSet<>();
        while (nodes.hasNext()) {
            names.add(nodes.nextNode().getName());
        }
        assertArrayEquals(new String[] { "folder2", "folder3_1", "folder3_1_1" }, names.toArray(new String[0]));
    } finally {
        folder1.remove();
        folder2.remove();
        folder3.remove();
        session.save();
    }
}