@FixFor( "MODE-1145" ) @Test public void shouldParseQueryWithResidualPropertyInSelectAndCriteria() throws Exception { String sql = "SELECT [jcr:path], something FROM [nt:unstructured] AS u WHERE something LIKE 'value%'"; Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); assertThat(query, is(notNullValue())); QueryResult result = query.execute(); validateQuery().rowCount(2).hasColumns("jcr:path", "something").onEachRow(new Predicate() { @Override public void validate( int rowNumber, Row row ) throws RepositoryException { assertThat(row.getNode().hasProperty("something"), is(true)); } }).validate(query, result); }
@FixFor( "MODE-1679" ) @Test public void shouldBeAbleToCreateAndExecuteJcrSql2QueryWithMultipleReferenceConstraintUsingJoin() throws RepositoryException { String sql = "SELECT typed.* FROM [notion:typed] AS typed JOIN [mix:referenceable] AS target ON typed.[notion:multipleReferences] = target.[jcr:uuid] WHERE PATH(target) = '/Other/NodeA[2]'"; Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); assertThat(query, is(notNullValue())); QueryResult result = query.execute(); validateQuery().rowCount(1).hasColumns(typedColumnNames("typed")).onEachRow(new Predicate() { @Override public void validate( int rowNumber, Row row ) throws RepositoryException { assertValueIsNonNullReference(row, "typed.notion:singleReference"); assertValueIsNonNullReference(row, "typed.notion:multipleReferences"); } }).validate(query, result); }
@FixFor( "MODE-1309" ) @Test public void shouldBeAbleToCreateAndExecuteJcrSql2QuerySelectingResidualPropertyWithAliasUsingAliasInConstraint() throws RepositoryException { String sql = "SELECT a.propB AS foo FROM [nt:unstructured] AS a WHERE a.foo = 'value1'"; Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); QueryResult result = query.execute(); validateQuery().rowCount(2).hasColumns("foo").onEachRow(new Predicate() { @Override public void validate( int rowNumber, Row row ) throws RepositoryException { // All the rows are identical ... assertThat(row.getValue("foo").getString(), is("value1")); } }).validate(query, result); }
@FixFor( "MODE-934" ) @Test public void shouldParseQueryWithUnqualifiedPathInSelectAndUnqualifiedNameInCriteriaOfJcrSql2Query() throws RepositoryException { String sql = "select [jcr:primaryType], [jcr:path] FROM [nt:base] WHERE [jcr:name] LIKE '%3%'"; Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); QueryResult result = query.execute(); validateQuery().rowCount(4).hasColumns("jcr:primaryType", "jcr:path").onEachRow(new Predicate() { @Override public void validate( int rowNumber, Row row ) throws RepositoryException { assertNotNull(row.getValue("jcr:primaryType")); } }).validate(query, result); }
@FixFor( "MODE-1309" ) @Test public void shouldBeAbleToCreateAndExecuteJcrSql2QuerySelectingResidualProperty() throws RepositoryException { String sql = "SELECT a.propB FROM [nt:unstructured] AS a WHERE a.propB = 'value1'"; Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); QueryResult result = query.execute(); validateQuery().rowCount(2).hasColumns("propB").onEachRow(new Predicate() { @Override public void validate( int rowNumber, Row row ) throws RepositoryException { // All the rows are identical ... assertThat(row.getValue("propB").getString(), is("value1")); } }).validate(query, result); }
@FixFor( "MODE-1679" ) @Test public void shouldBeAbleToCreateAndExecuteJcrSql2QueryWithMultipleReferenceConstraintUsingSubquery() throws RepositoryException { String sql = "SELECT [notion:multipleReferences] FROM [notion:typed] WHERE [notion:multipleReferences] IN ( SELECT [jcr:uuid] FROM [mix:referenceable] AS node WHERE PATH(node) = '/Other/NodeA[2]')"; Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); QueryResult result = query.execute(); validateQuery().rowCount(1).hasColumns("notion:multipleReferences").onEachRow(new Predicate() { @Override public void validate( int rowNumber, Row row ) throws RepositoryException { assertValueIsNonNullReference(row, "notion:multipleReferences"); } }).validate(query, result); }
@FixFor( "MODE-1679" ) @Test public void shouldBeAbleToCreateAndExecuteJcrSql2QueryToFindNodesOfParticularPrimaryType() throws RepositoryException { String sql = "SELECT [notion:singleReference], [notion:multipleReferences] FROM [notion:typed]"; Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); QueryResult result = query.execute(); validateQuery().rowCount(1).hasColumns("notion:singleReference", "notion:multipleReferences").onEachRow(new Predicate() { @Override public void validate( int rowNumber, Row row ) throws RepositoryException { assertValueIsNonNullReference(row, "notion:singleReference"); assertValueIsNonNullReference(row, "notion:multipleReferences"); } }).validate(query, result); }
@FixFor( "MODE-1309" ) @Test public void shouldBeAbleToCreateAndExecuteJcrSql2QuerySelectingResidualPropertyWithAlias() throws RepositoryException { String sql = "SELECT a.propB AS foo FROM [nt:unstructured] AS a WHERE a.propB = 'value1'"; Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); QueryResult result = query.execute(); validateQuery().rowCount(2).hasColumns("foo").onEachRow(new Predicate() { @Override public void validate( int rowNumber, Row row ) throws RepositoryException { // All the rows are identical ... assertThat(row.getValue("foo").getString(), is("value1")); } }).validate(query, result); }
@FixFor( "MODE-934" ) @Test public void shouldParseQueryWithUnqualifiedPathInSelectAndUnqualifiedLocalNameInCriteriaOfJcrSql2Query() throws RepositoryException { String sql = "select [jcr:primaryType], [jcr:path] FROM [nt:base] WHERE [mode:localName] LIKE '%3%'"; Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); QueryResult result = query.execute(); validateQuery().rowCount(4).hasColumns("jcr:primaryType", "jcr:path").onEachRow(new Predicate() { @Override public void validate( int rowNumber, Row row ) throws RepositoryException { assertNotNull(row.getValue("jcr:primaryType")); } }).validate(query, result); }
@FixFor( "MODE-1679" ) @Test public void shouldBeAbleToCreateAndExecuteJcrSql2QueryWithSingleReferenceConstraintUsingJoin() throws RepositoryException { String sql = "SELECT typed.* FROM [notion:typed] AS typed JOIN [mix:referenceable] AS target ON typed.[notion:singleReference] = target.[jcr:uuid] WHERE PATH(target) = '/Other/NodeA'"; Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); QueryResult result = query.execute(); validateQuery().rowCount(1).hasColumns(typedColumnNames("typed")).onEachRow(new Predicate() { @Override public void validate( int rowNumber, Row row ) throws RepositoryException { assertValueIsNonNullReference(row, "typed.notion:singleReference"); assertValueIsNonNullReference(row, "typed.notion:multipleReferences"); } }).validate(query, result); }
@SuppressWarnings( "deprecation" ) @Test public void shouldNotReturnNodesWithNoPropertyForLikeCriterion() throws Exception { String xpath = "/jcr:root/Cars//*[jcr:like(@car:wheelbaseInInches, '%')]"; Query query = session.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH); QueryResult result = query.execute(); validateQuery().rowCount(1).hasColumns("jcr:primaryType", "jcr:path", "jcr:score").onEachRow(new Predicate() { @Override public void validate( int rowNumber, Row row ) throws RepositoryException { assertThat(row.getNode().hasProperty("car:wheelbaseInInches"), is(true)); } }).validate(query, result); }
@FixFor( "MODE-934" ) @Test public void shouldParseQueryWithUnqualifiedPathInSelectAndCriteriaOfJcrSql2Query() throws RepositoryException { String sql = "select [jcr:primaryType], [jcr:path] FROM [nt:base] WHERE [jcr:path] LIKE '/Cars/%'"; Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); QueryResult result = query.execute(); validateQuery().rowCount(17).hasColumns("jcr:primaryType", "jcr:path").onEachRow(new Predicate() { @Override public void validate( int rowNumber, Row row ) throws RepositoryException { assertNotNull(row.getValue("jcr:primaryType")); } }).validate(query, result); }
@FixFor( "MODE-934" ) @Test public void shouldParseQueryWithUnqualifiedPathInSelectOfJcrSql2Query() throws RepositoryException { String sql = "select [jcr:primaryType], [jcr:path] FROM [nt:base]"; Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); QueryResult result = query.execute(); validateQuery().rowCount(totalNodeCount).hasColumns("jcr:primaryType", "jcr:path").onEachRow(new Predicate() { @Override public void validate( int rowNumber, Row row ) throws RepositoryException { assertNotNull(row.getValue("jcr:primaryType")); } }).validate(query, result); }
@FixFor( "MODE-1679" ) @Test public void shouldBeAbleToCreateAndExecuteJcrSql2QueryWithSingleReferenceConstraintUsingSubquery() throws RepositoryException { String sql = "SELECT [notion:singleReference] FROM [notion:typed] WHERE [notion:singleReference] IN ( SELECT [jcr:uuid] FROM [mix:referenceable] AS node WHERE PATH(node) = '/Other/NodeA')"; Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); QueryResult result = query.execute(); validateQuery().rowCount(1).hasColumns("notion:singleReference").onEachRow(new Predicate() { @Override public void validate( int rowNumber, Row row ) throws RepositoryException { assertValueIsNonNullReference(row, "notion:singleReference"); } }).validate(query, result); }
@SuppressWarnings( "deprecation" ) @Test public void shouldNotReturnNodesWithNoPropertyForPropertyCriterion() throws Exception { String xpath = "/jcr:root/Cars//*[@car:wheelbaseInInches]"; Query query = session.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH); QueryResult result = query.execute(); validateQuery().rowCount(1).hasColumns("jcr:primaryType", "jcr:path", "jcr:score").onEachRow(new Predicate() { @Override public void validate( int rowNumber, Row row ) throws RepositoryException { assertThat(row.getNode().hasProperty("car:wheelbaseInInches"), is(true)); } }).validate(query, result); }
@Test public void shouldBeAbleToCreateAndExecuteJcrSql2QueryForNodeLocalNamedHybrid() throws RepositoryException { String sql = "SELECT [jcr:path] FROM [nt:unstructured] AS hybrid WHERE LOCALNAME(hybrid) = 'Hybrid'"; Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); QueryResult result = query.execute(); validateQuery().rowCount(1).hasColumns("jcr:path").onEachRow(new Predicate() { @Override public void validate( int rowNumber, Row row ) throws RepositoryException { assertThat(row.getNode().getName(), is("Hybrid")); } }).validate(query, result); }
@Test public void shouldBeAbleToCreateAndExecuteJcrSql2QueryForNodeNamedHybrid() throws RepositoryException { String sql = "SELECT [jcr:path] FROM [nt:unstructured] AS hybrid WHERE NAME(hybrid) = 'Hybrid'"; Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); QueryResult result = query.execute(); validateQuery().rowCount(1).hasColumns("jcr:path").onEachRow(new Predicate() { @Override public void validate( int rowNumber, Row row ) throws RepositoryException { assertThat(row.getNode().getName(), is("Hybrid")); } }).validate(query, result); }
@Test public void shouldBeAbleToCreateAndExecuteJcrSql2QueryWithPathCriteria() throws RepositoryException { String sql = "SELECT [jcr:path] FROM [nt:unstructured] WHERE PATH() = '/Cars/Hybrid/Toyota Highlander'"; Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); QueryResult result = query.execute(); validateQuery().rowCount(1).hasColumns("jcr:path").onEachRow(new Predicate() { @Override public void validate( int rowNumber, Row row ) throws RepositoryException { assertThat(row.getNode().getPath(), is("/Cars/Hybrid/Toyota Highlander")); } }).validate(query, result); }
@FixFor( "MODE-2138" ) @Test public void shouldBeAbleToCreateAndExecuteJcrSql2QueryWithOrderByPathPseudoColumn() throws RepositoryException { String sql = "SELECT [jcr:path] from [nt:base] ORDER BY [jcr:path]"; Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); QueryResult result = query.execute(); validateQuery().rowCount(totalNodeCount).hasColumns("jcr:path").onEachRow(pathOrder()).validate(query, result); }
@FixFor( "MODE-2138" ) @Test public void shouldBeAbleToCreateAndExecuteJcrSql2QueryWithOrderByPath() throws RepositoryException { String sql = "SELECT [jcr:path] from [nt:base] ORDER BY [jcr:path]"; Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); QueryResult result = query.execute(); validateQuery().rowCount(totalNodeCount).hasColumns("jcr:path").onEachRow(pathOrder()).validate(query, result); }