You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by ta...@apache.org on 2019/01/08 17:06:24 UTC

[2/2] deltaspike git commit: DELTASPIKE-1365: Support extra JPQL comparators in method expressions

DELTASPIKE-1365: Support extra JPQL comparators in method expressions

Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/bb780635
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/bb780635
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/bb780635

Branch: refs/heads/master
Commit: bb7806352f50465f197061672e1e727bc81b33c3
Parents: 757be9b
Author: Thomas Andraschko <ta...@apache.org>
Authored: Tue Jan 8 18:06:16 2019 +0100
Committer: Thomas Andraschko <ta...@apache.org>
Committed: Tue Jan 8 18:06:16 2019 +0100

----------------------------------------------------------------------
 .../data/impl/builder/QueryOperator.java        |  188 +-
 .../data/impl/builder/part/QueryRootTest.java   |  734 +++--
 documentation/src/main/asciidoc/data.adoc       | 3086 +++++++++---------
 3 files changed, 2191 insertions(+), 1817 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/bb780635/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/QueryOperator.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/QueryOperator.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/QueryOperator.java
index 2c84eb9..c032ace 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/QueryOperator.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/builder/QueryOperator.java
@@ -1,90 +1,98 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.deltaspike.data.impl.builder;
-
-/**
- * Comparison options for queries.
- */
-public enum QueryOperator
-{
-
-    LessThan("LessThan", "{0} < {1}"),
-    LessThanEquals("LessThanEquals", "{0} <= {1}"),
-    GreaterThan("GreaterThan", "{0} > {1}"),
-    GreaterThanEquals("GreaterThanEquals", "{0} >= {1}"),
-    Like("Like", "{0} like {1}"),
-    LikeIgnoreCase("LikeIgnoreCase", "upper({0}) like {1}", true),
-    NotEqual("NotEqual", "{0} <> {1}"),
-    NotEqualIgnoreCase("NotEqualIgnoreCase", "upper({0}) <> upper({1})"),
-    Equal("Equal", "{0} = {1}"),
-    EqualIgnoreCase("EqualIgnoreCase", "upper({0}) = upper({1})"),
-    IgnoreCase("IgnoreCase", "upper({0}) = upper({1})"),
-    Between("Between", "{0} between {1} and {2}", 2),
-    IsNotNull("IsNotNull", "{0} IS NOT NULL", 0),
-    IsNull("IsNull", "{0} IS NULL", 0);
-
-    private final String expression;
-    private final String jpql;
-    private final int paramNum;
-    private final boolean caseInsensitive;
-
-    private QueryOperator(String expression, String jpql)
-    {
-        this(expression, jpql, 1);
-    }
-
-    private QueryOperator(String expression, String jpql, boolean caseInsensitive)
-    {
-        this(expression, jpql, 1, caseInsensitive);
-    }
-
-    private QueryOperator(String expression, String jpql, int paramNum)
-    {
-        this(expression, jpql, paramNum, false);
-    }
-
-    private QueryOperator(String expression, String jpql, int paramNum, boolean caseInsensitive)
-    {
-        this.expression = expression;
-        this.jpql = jpql;
-        this.paramNum = paramNum;
-        this.caseInsensitive = caseInsensitive;
-    }
-
-    public String getExpression()
-    {
-        return expression;
-    }
-
-    public String getJpql()
-    {
-        return jpql;
-    }
-
-    public int getParamNum()
-    {
-        return paramNum;
-    }
-
-    public boolean isCaseInsensitive()
-    {
-        return caseInsensitive;
-    }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.builder;
+
+/**
+ * Comparison options for queries.
+ */
+public enum QueryOperator
+{
+
+    LessThan("LessThan", "{0} < {1}"),
+    LessThanEquals("LessThanEquals", "{0} <= {1}"),
+    GreaterThan("GreaterThan", "{0} > {1}"),
+    GreaterThanEquals("GreaterThanEquals", "{0} >= {1}"),
+    NotLike("NotLike", "{0} not like {1}"),
+    Like("Like", "{0} like {1}"),
+    LikeIgnoreCase("LikeIgnoreCase", "upper({0}) like {1}", true),
+    NotEqual("NotEqual", "{0} <> {1}"),
+    NotEqualIgnoreCase("NotEqualIgnoreCase", "upper({0}) <> upper({1})"),
+    Equal("Equal", "{0} = {1}"),
+    EqualIgnoreCase("EqualIgnoreCase", "upper({0}) = upper({1})"),
+    IgnoreCase("IgnoreCase", "upper({0}) = upper({1})"),
+    Between("Between", "{0} between {1} and {2}", 2),
+    IsNotNull("IsNotNull", "{0} IS NOT NULL", 0),
+    IsNull("IsNull", "{0} IS NULL", 0),
+    NotIn("NotIn", "{0} NOT IN {1}"),
+    In("In", "{0} IN {1}"),
+    True("True", "{0} IS TRUE", 0),
+    False("False", "{0} IS FALSE", 0),
+    Containing("Containing", "{0} like CONCAT(''%'', CONCAT({1}, ''%''))"),
+    StartingWith("StartingWith", "{0} like CONCAT({1}, ''%'')"),
+    EndingWith("EndingWith", "{0} like CONCAT(''%'', {1})");
+
+    private final String expression;
+    private final String jpql;
+    private final int paramNum;
+    private final boolean caseInsensitive;
+
+    private QueryOperator(String expression, String jpql)
+    {
+        this(expression, jpql, 1);
+    }
+
+    private QueryOperator(String expression, String jpql, boolean caseInsensitive)
+    {
+        this(expression, jpql, 1, caseInsensitive);
+    }
+
+    private QueryOperator(String expression, String jpql, int paramNum)
+    {
+        this(expression, jpql, paramNum, false);
+    }
+
+    private QueryOperator(String expression, String jpql, int paramNum, boolean caseInsensitive)
+    {
+        this.expression = expression;
+        this.jpql = jpql;
+        this.paramNum = paramNum;
+        this.caseInsensitive = caseInsensitive;
+    }
+
+    public String getExpression()
+    {
+        return expression;
+    }
+
+    public String getJpql()
+    {
+        return jpql;
+    }
+
+    public int getParamNum()
+    {
+        return paramNum;
+    }
+
+    public boolean isCaseInsensitive()
+    {
+        return caseInsensitive;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/bb780635/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/builder/part/QueryRootTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/builder/part/QueryRootTest.java b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/builder/part/QueryRootTest.java
index 9312203..c65aa0a 100644
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/builder/part/QueryRootTest.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/builder/part/QueryRootTest.java
@@ -1,191 +1,543 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.deltaspike.data.impl.builder.part;
-
-import static org.junit.Assert.assertEquals;
-
-import org.apache.deltaspike.data.impl.builder.MethodExpressionException;
-import org.apache.deltaspike.data.impl.meta.RepositoryMethodPrefix;
-import org.apache.deltaspike.data.impl.meta.EntityMetadata;
-import org.apache.deltaspike.data.impl.meta.RepositoryMetadata;
-import org.apache.deltaspike.data.test.domain.Simple;
-import org.apache.deltaspike.data.test.service.SimpleFetchRepository;
-import org.apache.deltaspike.data.test.service.SimpleRepository;
-import org.junit.Test;
-
-public class QueryRootTest
-{
-    private final RepositoryMetadata repo = new RepositoryMetadata(SimpleRepository.class, new EntityMetadata(Simple.class, "Simple", Long.class));
-    private final RepositoryMetadata repoFetchBy = new RepositoryMetadata(SimpleFetchRepository.class, new EntityMetadata(Simple.class, "Simple", Long.class));
-
-    @Test
-    public void should_create_simple_query()
-    {
-        // given
-        final String name = "findByName";
-        final String expected =
-                "select e from Simple e " +
-                        "where e.name = ?1";
-
-        // when
-        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
-
-        // then
-        assertEquals(expected, result);
-    }
-
-    @Test
-    public void should_create_complex_query()
-    {
-        // given
-        final String name = "findByNameAndTemporalBetweenOrEnabledIsNull" +
-                "AndCamelCaseLikeIgnoreCaseAndEmbedded_embeddNotEqualIgnoreCase" +
-                "OrderByEmbedded_embeddDesc";
-        final String expected =
-                "select e from Simple e " +
-                        "where e.name = ?1 " +
-                        "and e.temporal between ?2 and ?3 " +
-                        "or e.enabled IS NULL " +
-                        "and upper(e.camelCase) like ?4 " +
-                        "and upper(e.embedded.embedd) <> upper(?5) " +
-                        "order by e.embedded.embedd desc";
-
-        // when
-        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
-
-        // then
-        assertEquals(expected, result);
-    }
-
-    @Test
-    public void should_create_query_with_order_by_only()
-    {
-        // given
-        final String name = "findByOrderByIdAsc";
-        final String expected =
-                "select e from Simple e " +
-                        "order by e.id asc";
-
-        // when
-        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
-
-        // then
-        assertEquals(expected, result);
-    }
-
-    @Test(expected = MethodExpressionException.class)
-    public void should_fail_in_where()
-    {
-        // given
-        final String name = "findByInvalid";
-
-        // when
-        QueryRoot.create(name, repo, prefix(name));
-    }
-
-    @Test(expected = MethodExpressionException.class)
-    public void should_fail_with_prefix_only()
-    {
-        // given
-        final String name = "findBy";
-
-        // when
-        QueryRoot.create(name, repo, prefix(name));
-    }
-
-    @Test(expected = MethodExpressionException.class)
-    public void should_fail_in_order_by()
-    {
-        // given
-        final String name = "findByNameOrderByInvalidDesc";
-
-        // when
-        QueryRoot.create(name, repo, prefix(name));
-    }
-
-    @Test
-    public void should_use_alternative_prefix()
-    {
-        // given
-        final String name = "fetchByName";
-        final String expected =
-                "select e from Simple e " +
-                        "where e.name = ?1";
-
-        // when
-        String result = QueryRoot.create(name, repoFetchBy, new RepositoryMethodPrefix("fetchBy", name)).getJpqlQuery().trim();
-
-        // then
-        assertEquals(expected, result);
-    }
-
-    @Test
-    public void should_create_delete_query_by_name()
-    {
-        // given
-        final String name = "deleteByName";
-        final String expected =
-                "delete from Simple e " +
-                        "where e.name = ?1";
-
-        // when
-        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
-
-        // then
-        assertEquals(expected, result);
-    }
-
-    @Test
-    public void should_create_delete_query_by_name_and_enabled()
-    {
-        // given
-        final String name = "deleteByNameAndEnabled";
-        final String expected =
-                "delete from Simple e " +
-                        "where e.name = ?1 and e.enabled = ?2";
-
-        // when
-        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
-
-        // then
-        assertEquals(expected, result);
-    }
-
-    @Test
-    public void should_apply_order_by_in_order()
-    {
-        // given
-        final String name = "findAllOrderByNameDescIdAsc";
-        final String expected =
-                "select e from Simple e " +
-                        "order by e.name desc, e.id asc";
-
-        // when
-        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
-
-        // then
-        assertEquals(expected, result);
-    }
-
-    private RepositoryMethodPrefix prefix(final String name)
-    {
-        return new RepositoryMethodPrefix("", name);
-    }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.deltaspike.data.impl.builder.part;
+
+import org.apache.deltaspike.data.impl.builder.MethodExpressionException;
+import org.apache.deltaspike.data.impl.meta.EntityMetadata;
+import org.apache.deltaspike.data.impl.meta.RepositoryMetadata;
+import org.apache.deltaspike.data.impl.meta.RepositoryMethodPrefix;
+import org.apache.deltaspike.data.test.domain.Simple;
+import org.apache.deltaspike.data.test.service.SimpleFetchRepository;
+import org.apache.deltaspike.data.test.service.SimpleRepository;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class QueryRootTest
+{
+    private final RepositoryMetadata repo = new RepositoryMetadata(SimpleRepository.class, new EntityMetadata(Simple.class, "Simple", Long.class));
+    private final RepositoryMetadata repoFetchBy = new RepositoryMetadata(SimpleFetchRepository.class, new EntityMetadata(Simple.class, "Simple", Long.class));
+
+    @Test
+    public void should_create_simple_query()
+    {
+        // given
+        final String name = "findByName";
+        final String expected =
+                "select e from Simple e " +
+                        "where e.name = ?1";
+
+        // when
+        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
+
+        // then
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void should_create_complex_query()
+    {
+        // given
+        final String name = "findByNameAndTemporalBetweenOrEnabledIsNull" +
+                "AndCamelCaseLikeIgnoreCaseAndEmbedded_embeddNotEqualIgnoreCase" +
+                "OrderByEmbedded_embeddDesc";
+        final String expected =
+                "select e from Simple e " +
+                        "where e.name = ?1 " +
+                        "and e.temporal between ?2 and ?3 " +
+                        "or e.enabled IS NULL " +
+                        "and upper(e.camelCase) like ?4 " +
+                        "and upper(e.embedded.embedd) <> upper(?5) " +
+                        "order by e.embedded.embedd desc";
+
+        // when
+        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
+
+        // then
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void should_create_query_with_order_by_only()
+    {
+        // given
+        final String name = "findByOrderByIdAsc";
+        final String expected =
+                "select e from Simple e " +
+                        "order by e.id asc";
+
+        // when
+        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
+
+        // then
+        assertEquals(expected, result);
+    }
+
+    @Test(expected = MethodExpressionException.class)
+    public void should_fail_in_where()
+    {
+        // given
+        final String name = "findByInvalid";
+
+        // when
+        QueryRoot.create(name, repo, prefix(name));
+    }
+
+    @Test(expected = MethodExpressionException.class)
+    public void should_fail_with_prefix_only()
+    {
+        // given
+        final String name = "findBy";
+
+        // when
+        QueryRoot.create(name, repo, prefix(name));
+    }
+
+    @Test(expected = MethodExpressionException.class)
+    public void should_fail_in_order_by()
+    {
+        // given
+        final String name = "findByNameOrderByInvalidDesc";
+
+        // when
+        QueryRoot.create(name, repo, prefix(name));
+    }
+
+    @Test
+    public void should_use_alternative_prefix()
+    {
+        // given
+        final String name = "fetchByName";
+        final String expected =
+                "select e from Simple e " +
+                        "where e.name = ?1";
+
+        // when
+        String result = QueryRoot.create(name, repoFetchBy, new RepositoryMethodPrefix("fetchBy", name)).getJpqlQuery().trim();
+
+        // then
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void should_create_delete_query_by_name()
+    {
+        // given
+        final String name = "deleteByName";
+        final String expected =
+                "delete from Simple e " +
+                        "where e.name = ?1";
+
+        // when
+        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
+
+        // then
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void should_create_delete_query_by_name_and_enabled()
+    {
+        // given
+        final String name = "deleteByNameAndEnabled";
+        final String expected =
+                "delete from Simple e " +
+                        "where e.name = ?1 and e.enabled = ?2";
+
+        // when
+        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
+
+        // then
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void should_apply_order_by_in_order()
+    {
+        // given
+        final String name = "findAllOrderByNameDescIdAsc";
+        final String expected =
+                "select e from Simple e " +
+                        "order by e.name desc, e.id asc";
+
+        // when
+        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
+
+        // then
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void should_apply_comparator_LessThan()
+    {
+        // given
+        final String name = "findByNameLessThan";
+        final String expected =
+                "select e from Simple e " +
+                        "where e.name < ?1";
+
+        // when
+        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
+
+        // then
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void should_apply_comparator_LessThanEquals()
+    {
+        // given
+        final String name = "findByNameLessThanEquals";
+        final String expected =
+                "select e from Simple e " +
+                        "where e.name <= ?1";
+
+        // when
+        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
+
+        // then
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void should_apply_comparator_GreaterThan()
+    {
+        // given
+        final String name = "findByNameGreaterThan";
+        final String expected =
+                "select e from Simple e " +
+                        "where e.name > ?1";
+
+        // when
+        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
+
+        // then
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void should_apply_comparator_GreaterThanEquals()
+    {
+        // given
+        final String name = "findByNameGreaterThanEquals";
+        final String expected =
+                "select e from Simple e " +
+                        "where e.name >= ?1";
+
+        // when
+        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
+
+        // then
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void should_apply_comparator_Like()
+    {
+        // given
+        final String name = "findByNameLike";
+        final String expected =
+                "select e from Simple e " +
+                        "where e.name like ?1";
+
+        // when
+        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
+
+        // then
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void should_apply_comparator_NotLike()
+    {
+        // given
+        final String name = "findByNameNotLike";
+        final String expected =
+                "select e from Simple e " +
+                        "where e.name not like ?1";
+
+        // when
+        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
+
+        // then
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void should_apply_comparator_LikeIgnoreCase()
+    {
+        // given
+        final String name = "findByNameLikeIgnoreCase";
+        final String expected =
+                "select e from Simple e " +
+                        "where upper(e.name) like ?1";
+
+        // when
+        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
+
+        // then
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void should_apply_comparator_NotEqual()
+    {
+        // given
+        final String name = "findByNameNotEqual";
+        final String expected =
+                "select e from Simple e " +
+                        "where e.name <> ?1";
+
+        // when
+        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
+
+        // then
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void should_apply_comparator_NotEqualIgnoreCase()
+    {
+        // given
+        final String name = "findByNameNotEqualIgnoreCase";
+        final String expected =
+                "select e from Simple e " +
+                        "where upper(e.name) <> upper(?1)";
+
+        // when
+        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
+
+        // then
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void should_apply_comparator_Equal()
+    {
+        // given
+        final String name = "findByNameEqual";
+        final String expected =
+                "select e from Simple e " +
+                        "where e.name = ?1";
+
+        // when
+        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
+
+        // then
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void should_apply_comparator_EqualIgnoreCase()
+    {
+        // given
+        final String name = "findByNameEqualIgnoreCase";
+        final String expected =
+                "select e from Simple e " +
+                        "where upper(e.name) = upper(?1)";
+
+        // when
+        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
+
+        // then
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void should_apply_comparator_IgnoreCase()
+    {
+        // given
+        final String name = "findByNameIgnoreCase";
+        final String expected =
+                "select e from Simple e " +
+                        "where upper(e.name) = upper(?1)";
+
+        // when
+        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
+
+        // then
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void should_apply_comparator_In()
+    {
+        // given
+        final String name = "findByNameIn";
+        final String expected =
+                "select e from Simple e " +
+                        "where e.name IN ?1";
+
+        // when
+        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
+
+        // then
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void should_apply_comparator_Between()
+    {
+        // given
+        final String name = "findByNameBetween";
+        final String expected =
+                "select e from Simple e " +
+                        "where e.name between ?1 and ?2";
+
+        // when
+        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
+
+        // then
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void should_apply_comparator_IsNotNull()
+    {
+        // given
+        final String name = "findByNameIsNotNull";
+        final String expected =
+                "select e from Simple e " +
+                        "where e.name IS NOT NULL";
+
+        // when
+        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
+
+        // then
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void should_apply_comparator_IsNull()
+    {
+        // given
+        final String name = "findByNameIsNull";
+        final String expected =
+                "select e from Simple e " +
+                        "where e.name IS NULL";
+
+        // when
+        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
+
+        // then
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void should_apply_comparator_NotIn()
+    {
+        // given
+        final String name = "findByNameNotIn";
+        final String expected =
+                "select e from Simple e " +
+                        "where e.name NOT IN ?1";
+
+        // when
+        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
+
+        // then
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void should_apply_comparator_True()
+    {
+        // given
+        final String name = "findByNameTrue";
+        final String expected =
+                "select e from Simple e " +
+                        "where e.name IS TRUE";
+
+        // when
+        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
+
+        // then
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void should_apply_comparator_False()
+    {
+        // given
+        final String name = "findByNameFalse";
+        final String expected =
+                "select e from Simple e " +
+                        "where e.name IS FALSE";
+
+        // when
+        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
+
+        // then
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void should_apply_comparator_Containing()
+    {
+        // given
+        final String name = "findByNameContaining";
+        final String expected =
+                "select e from Simple e " +
+                        "where e.name like CONCAT('%', CONCAT(?1, '%'))";
+
+        // when
+        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
+
+        // then
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void should_apply_comparator_StartingWith()
+    {
+        // given
+        final String name = "findByNameStartingWith";
+        final String expected =
+                "select e from Simple e " +
+                        "where e.name like CONCAT(?1, '%')";
+
+        // when
+        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
+
+        // then
+        assertEquals(expected, result);
+    }
+
+    @Test
+    public void should_apply_comparator_EndingWith()
+    {
+        // given
+        final String name = "findByNameEndingWith";
+        final String expected =
+                "select e from Simple e " +
+                        "where e.name like CONCAT('%', ?1)";
+
+        // when
+        String result = QueryRoot.create(name, repo, prefix(name)).getJpqlQuery().trim();
+
+        // then
+        assertEquals(expected, result);
+    }
+
+    private RepositoryMethodPrefix prefix(final String name)
+    {
+        return new RepositoryMethodPrefix("", name);
+    }
+
+}