Commit 38c6cd75 authored by Oscar Scholten's avatar Oscar Scholten

CMS-9669: adding unit test to capture the expected behavior of...

CMS-9669: adding unit test to capture the expected behavior of org.onehippo.cms7.services.search.jcr.query.Filter#addContains to optimize an empty "contains" clause. See also ENT dash 868.
parent ab4528ad
......@@ -30,6 +30,7 @@ public class TestJcrQueryBuilder extends RepositoryTestCase {
public final static String COMMON_SCOPE = "(@hippo:paths='cafebabe-cafe-babe-cafe-babecafebabe')";
public final static String COMMON_ORDERBY = " order by @jcr:score descending";
@Test
public void testEmptyQuery() throws Exception {
InitialQueryImpl query = new InitialQueryImpl();
......@@ -187,4 +188,15 @@ public class TestJcrQueryBuilder extends RepositoryTestCase {
assertEquals("//*[" + COMMON_SCOPE + "]/.." + COMMON_ORDERBY, queryAsString);
}
@Test
public void test_contains_empty_string_is_optimized_away() {
InitialQueryImpl initialQuery = new InitialQueryImpl();
QueryImpl query = initialQuery.from("/").where(QueryUtils.text().contains(""))
.and(QueryUtils.text().contains("this"))
.and(QueryUtils.text().contains(""));
String queryAsString = TestUtils.getQueryAsString(query, session);
assertEquals("//*[" + COMMON_SCOPE + " and (((jcr:contains(.,'this') or jcr:contains(.,'this*'))))]" + COMMON_ORDERBY, queryAsString);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment