@Test
@FixFor( "MODE-2275" )
public void shouldAllowQueryingForRuntimeRegisteredNodeTypes() throws Exception {

    NamespaceRegistry namespaceRegistry = session.getWorkspace().getNamespaceRegistry();
    namespaceRegistry.registerNamespace("foo", "http://www.modeshape.org/foo/1.0");
    Node node1 = null;
    Node node2 = null;
    try {
        registerNodeType("foo:nodeType1");
        node1 = session.getRootNode().addNode("foo1", "foo:nodeType1");
        session.save();
        String sql = "SELECT node.[jcr:name] FROM [foo:nodeType1] AS node";
        Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2);
        NodeIterator nodes = query.execute().getNodes();
        assertEquals(1, nodes.getSize());
        assertEquals("foo1", nodes.nextNode().getName());
        registerNodeType("foo:nodeType2");
        node2 = session.getRootNode().addNode("foo2", "foo:nodeType2");
        session.save();
        sql = "SELECT node.[jcr:name] FROM [foo:nodeType2] AS node";
        query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2);
        nodes = query.execute().getNodes();
        assertEquals(1, nodes.getSize());
        assertEquals("foo2", nodes.nextNode().getName());
    } finally {
        // remove the nodes to avoid influencing the other tests
        if (node1 != null) {
            node1.remove();
        }
        if (node2 != null) {
            node2.remove();
        }
        session.save();
        // remove the custom types and namespaces to avoid influencing the other tests
        JcrNodeTypeManager nodeTypeManager = session.getWorkspace().getNodeTypeManager();
        nodeTypeManager.unregisterNodeType("foo:nodeType1");
        nodeTypeManager.unregisterNodeType("foo:nodeType2");
        namespaceRegistry.unregisterNamespace("foo");
    }
}