From 17abd6d977329f37d847f08cea43ecad1bb4da0c Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Fri, 9 Feb 2018 21:25:36 +1300 Subject: [PATCH] #1255 - Regression on raw LIKE expression with slashes on Postgres Tests --- .../query/other/TestWhereLikeWithSlash.java | 66 ++++++++++++++++--- 1 file changed, 58 insertions(+), 8 deletions(-) diff --git a/src/test/java/org/tests/query/other/TestWhereLikeWithSlash.java b/src/test/java/org/tests/query/other/TestWhereLikeWithSlash.java index a3b3eac29..f08e57eec 100644 --- a/src/test/java/org/tests/query/other/TestWhereLikeWithSlash.java +++ b/src/test/java/org/tests/query/other/TestWhereLikeWithSlash.java @@ -3,25 +3,75 @@ package org.tests.query.other; import io.ebean.BaseTestCase; import io.ebean.Ebean; import io.ebean.Query; -import org.tests.model.basic.EBasic; import org.junit.Test; +import org.tests.model.basic.EBasic; + +import java.util.List; + +import static org.junit.Assert.assertEquals; public class TestWhereLikeWithSlash extends BaseTestCase { @Test - public void test() { - - EBasic basic = new EBasic(); - basic.setName("slash\\monkey"); + public void testWithSlash() { + EBasic basic = new EBasic("slash\\monkey"); Ebean.save(basic); - Query query = Ebean.find(EBasic.class).where().like("name", "slash\\mon%").query(); - query.findList(); + Query query = Ebean.find(EBasic.class).where().startsWith("name", "slash\\mon").query(); + List list = query.findList(); + + assertEquals(1, list.size()); + + Query query1 = Ebean.find(EBasic.class).where().like("name", "slash\\mon%").query(); + List list1 = query1.findList(); // This doesn't work in the latest version of H2 so disable for now. // Still good on Postgres which was the original issue - //Assert.assertEquals(1, list.size()); + assertEquals(1, list1.size()); + } + @Test + public void testWithPipe() { + + EBasic basic = new EBasic("bash|monkey"); + Ebean.save(basic); + + Query query = Ebean.find(EBasic.class).where().startsWith("name", "bash|mo").query(); + List list = query.findList(); + + assertEquals(1, list.size()); + + Query query1 = Ebean.find(EBasic.class).where().like("name", "bash|mon%").query(); + List list1 = query1.findList(); + + // This doesn't work in the latest version of H2 so disable for now. + // Still good on Postgres which was the original issue + assertEquals(1, list1.size()); + } + + @Test + public void testWithOpenSquare() { + + EBasic basic = new EBasic("mash[monkey"); + Ebean.save(basic); + + Query query = Ebean.find(EBasic.class).where().startsWith("name", "mash[mo").query(); + List list = query.findList(); + + assertEquals(1, list.size()); + + List list1; + if (isSqlServer()) { + list1 = Ebean.find(EBasic.class).where().like("name", "mash[[]mon%").query().findList(); + + } else { + list1 = Ebean.find(EBasic.class).where().like("name", "mash[mon%").query().findList(); + } + + // This doesn't work in the latest version of H2 so disable for now. + // Still good on Postgres which was the original issue + assertEquals(1, list1.size()); + } }