DATAGRAPH-389 : Derived Queries for Labels - part 3
This commit is contained in:
committed by
Michael Hunger
parent
a605e2c415
commit
1710ec5a15
@@ -137,7 +137,7 @@ public abstract class AbstractDerivedFinderMethodTestBase {
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByFirstNameAndLastName",
|
||||
new Object[]{"foo", "bar"},
|
||||
getExpectedQuery("START `thing`=node:`Thing`({0})"),
|
||||
getExpectedQuery("subclass-to-supply-trs-specific-query"),
|
||||
getExpectedParams("firstName:foo AND lastName:bar"));
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ public abstract class AbstractDerivedFinderMethodTestBase {
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByFirstName",
|
||||
new Object[]{"foo"},
|
||||
getExpectedQuery("START `thing`=node:`Thing`(`firstName`={0})"),
|
||||
getExpectedQuery("subclass-to-supply-trs-specific-query"),
|
||||
getExpectedParams("foo"));
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ public abstract class AbstractDerivedFinderMethodTestBase {
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByDescription",
|
||||
new Object[]{"foo"},
|
||||
getExpectedQuery("START `thing`=node:`search`({0})"),
|
||||
getExpectedQuery("subclass-to-supply-trs-specific-query"),
|
||||
getExpectedParams("description:foo"));
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ public abstract class AbstractDerivedFinderMethodTestBase {
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByDescriptionAndFirstName",
|
||||
new Object[]{"foo","bar"},
|
||||
getExpectedQuery("START `thing`=node:`search`({0}) WHERE `thing`.`firstName` = {1}"),
|
||||
getExpectedQuery("subclass-to-supply-trs-specific-query"),
|
||||
getExpectedParams("description:foo","bar"));
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ public abstract class AbstractDerivedFinderMethodTestBase {
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByFirstNameAndDescription",
|
||||
new Object[]{"foo","bar"},
|
||||
getExpectedQuery("START `thing`=node:`Thing`(`firstName`={0}) WHERE `thing`.`description` = {1}"),
|
||||
getExpectedQuery("subclass-to-supply-trs-specific-query"),
|
||||
getExpectedParams("foo","bar"));
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ public abstract class AbstractDerivedFinderMethodTestBase {
|
||||
public void testIndexQueryWithOneNonIndexedParam() throws Exception {
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByAge", new Object[]{100},
|
||||
getExpectedQuery("WHERE `thing`.`age` = {0}"),
|
||||
getExpectedQuery("subclass-to-supply-trs-specific-query"),
|
||||
getExpectedParams(100));
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ public abstract class AbstractDerivedFinderMethodTestBase {
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByAgeAndFirstName",
|
||||
new Object[]{100, "foo"},
|
||||
getExpectedQuery("START `thing`=node:`Thing`(`firstName`={1}) WHERE `thing`.`age` = {0}"),
|
||||
getExpectedQuery("subclass-to-supply-trs-specific-query"),
|
||||
getExpectedParams(100, "foo"));
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ public abstract class AbstractDerivedFinderMethodTestBase {
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByFirstNameLike",
|
||||
new Object[]{"foo"},
|
||||
getExpectedQuery("START `thing`=node:`Thing`({0})"),
|
||||
getExpectedQuery("subclass-to-supply-trs-specific-query"),
|
||||
getExpectedParams("firstName:foo"));
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ public abstract class AbstractDerivedFinderMethodTestBase {
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByFirstNameLike",
|
||||
new Object[]{"foo bar"},
|
||||
getExpectedQuery("START `thing`=node:`Thing`({0})"),
|
||||
getExpectedQuery("subclass-to-supply-trs-specific-query"),
|
||||
getExpectedParams("firstName:\"foo bar\""));
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ public abstract class AbstractDerivedFinderMethodTestBase {
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByFirstNameContains",
|
||||
new Object[]{"foo"},
|
||||
getExpectedQuery("START `thing`=node:`Thing`({0})"),
|
||||
getExpectedQuery("subclass-to-supply-trs-specific-query"),
|
||||
getExpectedParams("firstName:*foo*"));
|
||||
}
|
||||
@Test
|
||||
@@ -225,7 +225,7 @@ public abstract class AbstractDerivedFinderMethodTestBase {
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByFirstNameStartsWith",
|
||||
new Object[]{"foo"},
|
||||
getExpectedQuery("START `thing`=node:`Thing`({0})"),
|
||||
getExpectedQuery("subclass-to-supply-trs-specific-query"),
|
||||
getExpectedParams("firstName:foo*"));
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ public abstract class AbstractDerivedFinderMethodTestBase {
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByFirstNameEndsWith",
|
||||
new Object[]{"foo"},
|
||||
getExpectedQuery("START `thing`=node:`Thing`({0})"),
|
||||
getExpectedQuery("subclass-to-supply-trs-specific-query"),
|
||||
getExpectedParams("firstName:*foo"));
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ public abstract class AbstractDerivedFinderMethodTestBase {
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByFirstNameStartsWith",
|
||||
new Object[]{"foo bar"},
|
||||
getExpectedQuery("START `thing`=node:`Thing`({0})"));
|
||||
getExpectedQuery("subclass-to-supply-trs-specific-query"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -251,7 +251,7 @@ public abstract class AbstractDerivedFinderMethodTestBase {
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByName",
|
||||
new Object[]{"foo"},
|
||||
getExpectedQuery("WHERE `thing`.`name` = {0}"),
|
||||
getExpectedQuery("subclass-to-supply-trs-specific-query"),
|
||||
getExpectedParams("foo"));
|
||||
}
|
||||
|
||||
@@ -260,7 +260,7 @@ public abstract class AbstractDerivedFinderMethodTestBase {
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByNameStartsWith",
|
||||
new Object[]{"foo"},
|
||||
getExpectedQuery("WHERE `thing`.`name` =~ {0}"),
|
||||
getExpectedQuery("subclass-to-supply-trs-specific-query"),
|
||||
getExpectedParams("^foo.*"));
|
||||
}
|
||||
@Test
|
||||
@@ -268,7 +268,7 @@ public abstract class AbstractDerivedFinderMethodTestBase {
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByNameEndsWith",
|
||||
new Object[]{"foo"},
|
||||
getExpectedQuery("WHERE `thing`.`name` =~ {0}"),
|
||||
getExpectedQuery("subclass-to-supply-trs-specific-query"),
|
||||
getExpectedParams(".*foo$"));
|
||||
}
|
||||
|
||||
@@ -277,7 +277,7 @@ public abstract class AbstractDerivedFinderMethodTestBase {
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByNameContains",
|
||||
new Object[]{"foo"},
|
||||
getExpectedQuery("WHERE `thing`.`name` =~ {0}"),
|
||||
getExpectedQuery("subclass-to-supply-trs-specific-query"),
|
||||
getExpectedParams(".*foo.*"));
|
||||
}
|
||||
@Test
|
||||
@@ -285,7 +285,7 @@ public abstract class AbstractDerivedFinderMethodTestBase {
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByNameLike",
|
||||
new Object[]{"foo"},
|
||||
getExpectedQuery("WHERE `thing`.`name` =~ {0}"),
|
||||
getExpectedQuery("subclass-to-supply-trs-specific-query"),
|
||||
getExpectedParams("foo"));
|
||||
}
|
||||
@Test
|
||||
@@ -293,7 +293,7 @@ public abstract class AbstractDerivedFinderMethodTestBase {
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByNameNotLike",
|
||||
new Object[]{"foo"},
|
||||
getExpectedQuery("WHERE not( `thing`.`name` =~ {0} )"),
|
||||
getExpectedQuery("subclass-to-supply-trs-specific-query"),
|
||||
getExpectedParams("foo"));
|
||||
}
|
||||
|
||||
@@ -302,26 +302,26 @@ public abstract class AbstractDerivedFinderMethodTestBase {
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByNameMatches",
|
||||
new Object[]{"foo"},
|
||||
getExpectedQuery("WHERE `thing`.`name` =~ {0}"),
|
||||
getExpectedQuery("subclass-to-supply-trs-specific-query"),
|
||||
getExpectedParams("foo"));
|
||||
}
|
||||
@Test
|
||||
public void testFindBySimpleBooleanIsTrue() throws Exception {
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByTaggedIsTrue", new Object[]{},
|
||||
getExpectedQuery("WHERE `thing`.`tagged` = true"));
|
||||
getExpectedQuery("subclass-to-supply-trs-specific-query"));
|
||||
}
|
||||
@Test
|
||||
public void testFindBySimpleBooleanIsFalse() throws Exception {
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByTaggedIsFalse", new Object[]{},
|
||||
getExpectedQuery("WHERE `thing`.`tagged` = false"));
|
||||
getExpectedQuery("subclass-to-supply-trs-specific-query"));
|
||||
}
|
||||
@Test
|
||||
public void testFindBySimpleStringExists() throws Exception {
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByNameExists", new Object[]{},
|
||||
getExpectedQuery("WHERE has(`thing`.`name` )"));
|
||||
getExpectedQuery("subclass-to-supply-trs-specific-query"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -329,15 +329,16 @@ public abstract class AbstractDerivedFinderMethodTestBase {
|
||||
List<String> param = asList("foo");
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByNameIn", new Object[]{param},
|
||||
getExpectedQuery("WHERE `thing`.`name` in {0}"),
|
||||
getExpectedQuery("subclass-to-supply-trs-specific-query"),
|
||||
getExpectedParams(param));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindBySimpleStringInCollectionOfEnums() throws Exception {
|
||||
List<TimeUnit> param = asList(TimeUnit.MINUTES);
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByNameIn", new Object[]{param},
|
||||
getExpectedQuery("WHERE `thing`.`name` in {0}"),
|
||||
getExpectedQuery("subclass-to-supply-trs-specific-query"),
|
||||
getExpectedParams(param));
|
||||
}
|
||||
|
||||
@@ -346,15 +347,16 @@ public abstract class AbstractDerivedFinderMethodTestBase {
|
||||
List<String> param = asList("foo");
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByNameNotIn", new Object[]{param},
|
||||
getExpectedQuery("WHERE not( `thing`.`name` in {0} )"),
|
||||
getExpectedQuery("subclass-to-supply-trs-specific-query"),
|
||||
getExpectedParams(param));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindBySimpleDateBefore() throws Exception {
|
||||
Date param = new Date(1337);
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByBornBefore", new Object[]{param},
|
||||
getExpectedQuery("WHERE `thing`.`born` < {0}"),
|
||||
getExpectedQuery("subclass-to-supply-trs-specific-query"),
|
||||
getExpectedParams(param.getTime()));
|
||||
}
|
||||
|
||||
@@ -363,7 +365,7 @@ public abstract class AbstractDerivedFinderMethodTestBase {
|
||||
Date param = new Date(1337);
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByBornAfter", new Object[]{param},
|
||||
getExpectedQuery("WHERE `thing`.`born` > {0}"),
|
||||
getExpectedQuery("subclass-to-supply-trs-specific-query"),
|
||||
getExpectedParams(param.getTime()));
|
||||
}
|
||||
|
||||
@@ -371,7 +373,7 @@ public abstract class AbstractDerivedFinderMethodTestBase {
|
||||
public void testFindByNumericIndexedField() throws Exception {
|
||||
assertRepositoryQueryMethod(ThingRepository.class,
|
||||
"findByNumber", new Object[]{10},
|
||||
getExpectedQuery("START `thing`=node:`Thing`(`number`={0})"),
|
||||
getExpectedQuery("subclass-to-supply-trs-specific-query"),
|
||||
getExpectedParams(ValueContext.numeric(10)));
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.data.neo4j.repository.query;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.neo4j.index.lucene.ValueContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.neo4j.core.NodeTypeRepresentationStrategy;
|
||||
import org.springframework.data.neo4j.support.typerepresentation.IndexBasedNodeTypeRepresentationStrategy;
|
||||
@@ -28,6 +29,10 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
|
||||
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
|
||||
@@ -42,6 +47,8 @@ import static org.hamcrest.Matchers.instanceOf;
|
||||
@TestExecutionListeners({CleanContextCacheTestExecutionListener.class, DependencyInjectionTestExecutionListener.class, TransactionalTestExecutionListener.class})
|
||||
public class DerivedFinderMethodForIndexedBasedTRSTests extends AbstractDerivedFinderMethodTestBase {
|
||||
|
||||
private static final String DEFAULT_START_CLAUSE = "START `thing`=node:__types__(className=\"org.springframework.data.neo4j.repository.query.AbstractDerivedFinderMethodTestBase$Thing\")";
|
||||
|
||||
@Autowired
|
||||
NodeTypeRepresentationStrategy strategy;
|
||||
|
||||
@@ -56,9 +63,303 @@ public class DerivedFinderMethodForIndexedBasedTRSTests extends AbstractDerivedF
|
||||
@Test
|
||||
@Override
|
||||
public void testQueryWithEntityGraphId() throws Exception {
|
||||
this.trsSpecificExpectedQuery = "START `thing_owner`=node({0}) MATCH `thing`-[:`owner`]->`thing_owner` WHERE `thing`.__type__ IN ['org.springframework.data.neo4j.repository.query.AbstractDerivedFinderMethodTestBase$Thing'] ";
|
||||
this.trsSpecificExpectedParams = new Object[] { 123 };
|
||||
// findByOwnerId
|
||||
this.trsSpecificExpectedQuery =
|
||||
"START `thing_owner`=node({0}) " +
|
||||
"MATCH `thing`-[:`owner`]->`thing_owner` " +
|
||||
"WHERE `thing`.__type__ IN ['org.springframework.data.neo4j.repository.query.AbstractDerivedFinderMethodTestBase$Thing'] ";
|
||||
super.testQueryWithEntityGraphId();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testIndexQueryWithTwoParams() throws Exception {
|
||||
// "findByFirstNameAndLastName",
|
||||
this.trsSpecificExpectedQuery =
|
||||
"START `thing`=node:`Thing`({0}) RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { "firstName:foo AND lastName:bar" };
|
||||
super.testIndexQueryWithTwoParams();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testIndexQueryWithOneParam() throws Exception {
|
||||
// "findByFirstName",
|
||||
this.trsSpecificExpectedQuery =
|
||||
"START `thing`=node:`Thing`(`firstName`={0}) RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { "foo" };
|
||||
super.testIndexQueryWithOneParam();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testIndexQueryWithOneParamFullText() throws Exception {
|
||||
// "findByDescription",
|
||||
this.trsSpecificExpectedQuery =
|
||||
"START `thing`=node:`search`({0}) RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { "description:foo" };
|
||||
super.testIndexQueryWithOneParamFullText();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testIndexQueryWithOneParamFullTextAndOneParam() throws Exception {
|
||||
// "findByDescriptionAndFirstName",
|
||||
this.trsSpecificExpectedQuery =
|
||||
"START `thing`=node:`search`({0}) WHERE `thing`.`firstName` = {1} RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { "description:foo","bar" };
|
||||
super.testIndexQueryWithOneParamFullTextAndOneParam();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testIndexQueryWithOneParamAndOneParamFullText() throws Exception {
|
||||
// "findByFirstNameAndDescription",
|
||||
this.trsSpecificExpectedQuery =
|
||||
"START `thing`=node:`Thing`(`firstName`={0}) WHERE `thing`.`description` = {1} RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { "foo","bar" };
|
||||
super.testIndexQueryWithOneParamAndOneParamFullText();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testIndexQueryWithOneNonIndexedParam() throws Exception {
|
||||
// "findByAge",
|
||||
this.trsSpecificExpectedQuery = DEFAULT_START_CLAUSE +
|
||||
" WHERE `thing`.`age` = {0} RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { 100 };
|
||||
super.testIndexQueryWithOneNonIndexedParam();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testIndexQueryWithOneNonIndexedParamAndOneIndexedParam() throws Exception {
|
||||
// "findByAgeAndFirstName",
|
||||
this.trsSpecificExpectedQuery =
|
||||
"START `thing`=node:`Thing`(`firstName`={1}) WHERE `thing`.`age` = {0} RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { 100, "foo" };
|
||||
super.testIndexQueryWithOneNonIndexedParamAndOneIndexedParam();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testIndexQueryWithLikeIndexedParam() throws Exception {
|
||||
// "findByFirstNameLike",
|
||||
this.trsSpecificExpectedQuery =
|
||||
"START `thing`=node:`Thing`({0}) RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { "firstName:foo" };
|
||||
super.testIndexQueryWithLikeIndexedParam();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testIndexQueryWithLikeIndexedParamWithSpaces() throws Exception {
|
||||
// "findByFirstNameLike",
|
||||
this.trsSpecificExpectedQuery =
|
||||
"START `thing`=node:`Thing`({0}) RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { "firstName:\"foo bar\"" };
|
||||
super.testIndexQueryWithLikeIndexedParamWithSpaces();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testIndexQueryWithContainsIndexedParam() throws Exception {
|
||||
// "findByFirstNameContains",
|
||||
this.trsSpecificExpectedQuery =
|
||||
"START `thing`=node:`Thing`({0}) RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { "firstName:*foo*" };
|
||||
super.testIndexQueryWithContainsIndexedParam();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testIndexQueryWithStartsWithIndexedParam() throws Exception {
|
||||
// "findByFirstNameStartsWith",
|
||||
this.trsSpecificExpectedQuery =
|
||||
"START `thing`=node:`Thing`({0}) RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { "firstName:foo*" };
|
||||
super.testIndexQueryWithStartsWithIndexedParam();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testIndexQueryWithEndsWithIndexedParam() throws Exception {
|
||||
// "findByFirstNameEndsWith",
|
||||
this.trsSpecificExpectedQuery =
|
||||
"START `thing`=node:`Thing`({0}) RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { "firstName:*foo" };
|
||||
super.testIndexQueryWithEndsWithIndexedParam();
|
||||
}
|
||||
|
||||
@Test(expected = RepositoryQueryException.class)
|
||||
@Override
|
||||
public void testFailIndexQueryWithStartsWithIndexedParamWithSpaces() throws Exception {
|
||||
// findByFirstNameStartsWith
|
||||
this.trsSpecificExpectedQuery =
|
||||
"START `thing`=node:`Thing`({0})" +
|
||||
" RETURN `thing`";
|
||||
super.testFailIndexQueryWithStartsWithIndexedParamWithSpaces();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleStringParam() throws Exception {
|
||||
// findByName
|
||||
this.trsSpecificExpectedQuery = DEFAULT_START_CLAUSE +
|
||||
" WHERE `thing`.`name` = {0}" +
|
||||
" RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { "foo" };
|
||||
super.testFindBySimpleStringParam();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleStringParamStartsWith() throws Exception {
|
||||
// findByNameStartsWith
|
||||
this.trsSpecificExpectedQuery = DEFAULT_START_CLAUSE +
|
||||
" WHERE `thing`.`name` =~ {0}" +
|
||||
" RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { "^foo.*" };
|
||||
super.testFindBySimpleStringParamStartsWith();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleStringParamEndsWith() throws Exception {
|
||||
// findByNameEndsWith
|
||||
this.trsSpecificExpectedQuery = DEFAULT_START_CLAUSE +
|
||||
" WHERE `thing`.`name` =~ {0}" +
|
||||
" RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { ".*foo$" };
|
||||
super.testFindBySimpleStringParamEndsWith();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleStringParamContains() throws Exception {
|
||||
// findByNameContains
|
||||
this.trsSpecificExpectedQuery = DEFAULT_START_CLAUSE +
|
||||
" WHERE `thing`.`name` =~ {0}" +
|
||||
" RETURN `thing`";
|
||||
super.testFindBySimpleStringParamContains();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleStringParamLike() throws Exception {
|
||||
// findByNameLike
|
||||
this.trsSpecificExpectedQuery = DEFAULT_START_CLAUSE +
|
||||
" WHERE `thing`.`name` =~ {0}" +
|
||||
" RETURN `thing`";
|
||||
super.testFindBySimpleStringParamLike();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleStringParamNotLike() throws Exception {
|
||||
// findByNameNotLike
|
||||
this.trsSpecificExpectedQuery = DEFAULT_START_CLAUSE +
|
||||
" WHERE not( `thing`.`name` =~ {0} )" +
|
||||
" RETURN `thing`";
|
||||
super.testFindBySimpleStringParamNotLike();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleStringParamRegexp() throws Exception {
|
||||
// findByNameMatches
|
||||
this.trsSpecificExpectedQuery = DEFAULT_START_CLAUSE +
|
||||
" WHERE `thing`.`name` =~ {0}" +
|
||||
" RETURN `thing`";
|
||||
super.testFindBySimpleStringParamRegexp();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleBooleanIsTrue() throws Exception {
|
||||
// findByTaggedIsTrue
|
||||
this.trsSpecificExpectedQuery = DEFAULT_START_CLAUSE +
|
||||
" WHERE `thing`.`tagged` = true" +
|
||||
" RETURN `thing`";
|
||||
super.testFindBySimpleBooleanIsTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleBooleanIsFalse() throws Exception {
|
||||
// findByTaggedIsFalse
|
||||
this.trsSpecificExpectedQuery = DEFAULT_START_CLAUSE +
|
||||
" WHERE `thing`.`tagged` = false" +
|
||||
" RETURN `thing`";
|
||||
super.testFindBySimpleBooleanIsFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleStringExists() throws Exception {
|
||||
// findByNameExists
|
||||
this.trsSpecificExpectedQuery = DEFAULT_START_CLAUSE +
|
||||
" WHERE has(`thing`.`name` )" +
|
||||
" RETURN `thing`";
|
||||
super.testFindBySimpleStringExists();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleStringInCollection() throws Exception {
|
||||
// findByNameIn
|
||||
this.trsSpecificExpectedQuery = DEFAULT_START_CLAUSE +
|
||||
" WHERE `thing`.`name` in {0}" +
|
||||
" RETURN `thing`";
|
||||
super.testFindBySimpleStringInCollection();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleStringInCollectionOfEnums() throws Exception {
|
||||
// findByNameIn
|
||||
this.trsSpecificExpectedQuery = DEFAULT_START_CLAUSE +
|
||||
" WHERE `thing`.`name` in {0}" +
|
||||
" RETURN `thing`";
|
||||
super.testFindBySimpleStringInCollectionOfEnums();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleStringNotInCollection() throws Exception {
|
||||
// findByNameNotIn
|
||||
this.trsSpecificExpectedQuery = DEFAULT_START_CLAUSE +
|
||||
" WHERE not( `thing`.`name` in {0} )" +
|
||||
" RETURN `thing`";
|
||||
super.testFindBySimpleStringNotInCollection();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleDateBefore() throws Exception {
|
||||
// findByBornBefore
|
||||
this.trsSpecificExpectedQuery = DEFAULT_START_CLAUSE +
|
||||
" WHERE `thing`.`born` < {0} RETURN `thing`";
|
||||
super.testFindBySimpleDateBefore();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleDateAfter() throws Exception {
|
||||
// findByBornAfter
|
||||
this.trsSpecificExpectedQuery = DEFAULT_START_CLAUSE +
|
||||
" WHERE `thing`.`born` > {0} RETURN `thing`";
|
||||
super.testFindBySimpleDateAfter();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindByNumericIndexedField() throws Exception {
|
||||
// findByNumber
|
||||
this.trsSpecificExpectedQuery =
|
||||
"START `thing`=node:`Thing`(`number`={0}) RETURN `thing`";
|
||||
super.testFindByNumericIndexedField();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
|
||||
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
|
||||
@@ -42,6 +44,8 @@ import static org.hamcrest.Matchers.instanceOf;
|
||||
@TestExecutionListeners({CleanContextCacheTestExecutionListener.class, DependencyInjectionTestExecutionListener.class, TransactionalTestExecutionListener.class})
|
||||
public class DerivedFinderMethodForLabelBasedTRSTests extends AbstractDerivedFinderMethodTestBase {
|
||||
|
||||
private static final String DEFAULT_MATCH_CLAUSE = "MATCH `thing`:`org.springframework.data.neo4j.repository.query.AbstractDerivedFinderMethodTestBase$Thing`";
|
||||
|
||||
@Autowired
|
||||
NodeTypeRepresentationStrategy strategy;
|
||||
|
||||
@@ -56,8 +60,301 @@ public class DerivedFinderMethodForLabelBasedTRSTests extends AbstractDerivedFin
|
||||
@Test
|
||||
@Override
|
||||
public void testQueryWithEntityGraphId() throws Exception {
|
||||
// findByOwnerId
|
||||
this.trsSpecificExpectedQuery = "START `thing_owner`=node({0}) MATCH `thing`-[:`owner`]->`thing_owner` WHERE `thing`:`org.springframework.data.neo4j.repository.query.AbstractDerivedFinderMethodTestBase$Thing` ";
|
||||
this.trsSpecificExpectedParams = new Object[] { 123 };
|
||||
super.testQueryWithEntityGraphId();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testIndexQueryWithTwoParams() throws Exception {
|
||||
// "findByFirstNameAndLastName",
|
||||
this.trsSpecificExpectedQuery =
|
||||
"START `thing`=node:`Thing`({0}) RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { "firstName:foo AND lastName:bar" };
|
||||
super.testIndexQueryWithTwoParams();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testIndexQueryWithOneParam() throws Exception {
|
||||
// "findByFirstName",
|
||||
this.trsSpecificExpectedQuery =
|
||||
"START `thing`=node:`Thing`(`firstName`={0}) RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { "foo" };
|
||||
super.testIndexQueryWithOneParam();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testIndexQueryWithOneParamFullText() throws Exception {
|
||||
// "findByDescription",
|
||||
this.trsSpecificExpectedQuery =
|
||||
"START `thing`=node:`search`({0}) RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { "description:foo" };
|
||||
super.testIndexQueryWithOneParamFullText();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testIndexQueryWithOneParamFullTextAndOneParam() throws Exception {
|
||||
// "findByDescriptionAndFirstName",
|
||||
this.trsSpecificExpectedQuery =
|
||||
"START `thing`=node:`search`({0}) WHERE `thing`.`firstName` = {1} RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { "description:foo","bar" };
|
||||
super.testIndexQueryWithOneParamFullTextAndOneParam();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testIndexQueryWithOneParamAndOneParamFullText() throws Exception {
|
||||
// "findByFirstNameAndDescription",
|
||||
this.trsSpecificExpectedQuery =
|
||||
"START `thing`=node:`Thing`(`firstName`={0}) WHERE `thing`.`description` = {1} RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { "foo","bar" };
|
||||
super.testIndexQueryWithOneParamAndOneParamFullText();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testIndexQueryWithOneNonIndexedParam() throws Exception {
|
||||
// "findByAge",
|
||||
this.trsSpecificExpectedQuery = DEFAULT_MATCH_CLAUSE +
|
||||
" WHERE `thing`.`age` = {0} RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { 100 };
|
||||
super.testIndexQueryWithOneNonIndexedParam();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testIndexQueryWithOneNonIndexedParamAndOneIndexedParam() throws Exception {
|
||||
// "findByAgeAndFirstName",
|
||||
this.trsSpecificExpectedQuery =
|
||||
"START `thing`=node:`Thing`(`firstName`={1}) WHERE `thing`.`age` = {0} RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { 100, "foo" };
|
||||
super.testIndexQueryWithOneNonIndexedParamAndOneIndexedParam();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testIndexQueryWithLikeIndexedParam() throws Exception {
|
||||
// "findByFirstNameLike",
|
||||
this.trsSpecificExpectedQuery =
|
||||
"START `thing`=node:`Thing`({0}) RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { "firstName:foo" };
|
||||
super.testIndexQueryWithLikeIndexedParam();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testIndexQueryWithLikeIndexedParamWithSpaces() throws Exception {
|
||||
// "findByFirstNameLike",
|
||||
this.trsSpecificExpectedQuery =
|
||||
"START `thing`=node:`Thing`({0}) RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { "firstName:\"foo bar\"" };
|
||||
super.testIndexQueryWithLikeIndexedParamWithSpaces();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testIndexQueryWithContainsIndexedParam() throws Exception {
|
||||
// "findByFirstNameContains",
|
||||
this.trsSpecificExpectedQuery =
|
||||
"START `thing`=node:`Thing`({0}) RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { "firstName:*foo*" };
|
||||
super.testIndexQueryWithContainsIndexedParam();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testIndexQueryWithStartsWithIndexedParam() throws Exception {
|
||||
// "findByFirstNameStartsWith",
|
||||
this.trsSpecificExpectedQuery =
|
||||
"START `thing`=node:`Thing`({0}) RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { "firstName:foo*" };
|
||||
super.testIndexQueryWithStartsWithIndexedParam();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testIndexQueryWithEndsWithIndexedParam() throws Exception {
|
||||
// "findByFirstNameEndsWith",
|
||||
this.trsSpecificExpectedQuery =
|
||||
"START `thing`=node:`Thing`({0}) RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { "firstName:*foo" };
|
||||
super.testIndexQueryWithEndsWithIndexedParam();
|
||||
}
|
||||
|
||||
@Test(expected = RepositoryQueryException.class)
|
||||
@Override
|
||||
public void testFailIndexQueryWithStartsWithIndexedParamWithSpaces() throws Exception {
|
||||
// findByFirstNameStartsWith
|
||||
this.trsSpecificExpectedQuery =
|
||||
"START `thing`=node:`Thing`({0})" +
|
||||
" RETURN `thing`";
|
||||
super.testFailIndexQueryWithStartsWithIndexedParamWithSpaces();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleStringParam() throws Exception {
|
||||
// findByName
|
||||
this.trsSpecificExpectedQuery = DEFAULT_MATCH_CLAUSE +
|
||||
" WHERE `thing`.`name` = {0}" +
|
||||
" RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { "foo" };
|
||||
super.testFindBySimpleStringParam();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleStringParamStartsWith() throws Exception {
|
||||
// findByNameStartsWith
|
||||
this.trsSpecificExpectedQuery = DEFAULT_MATCH_CLAUSE +
|
||||
" WHERE `thing`.`name` =~ {0}" +
|
||||
" RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { "^foo.*" };
|
||||
super.testFindBySimpleStringParamStartsWith();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleStringParamEndsWith() throws Exception {
|
||||
// findByNameEndsWith
|
||||
this.trsSpecificExpectedQuery = DEFAULT_MATCH_CLAUSE +
|
||||
" WHERE `thing`.`name` =~ {0}" +
|
||||
" RETURN `thing`";
|
||||
this.trsSpecificExpectedParams = new Object[] { ".*foo$" };
|
||||
super.testFindBySimpleStringParamEndsWith();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleStringParamContains() throws Exception {
|
||||
// findByNameContains
|
||||
this.trsSpecificExpectedQuery = DEFAULT_MATCH_CLAUSE +
|
||||
" WHERE `thing`.`name` =~ {0}" +
|
||||
" RETURN `thing`";
|
||||
super.testFindBySimpleStringParamContains();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleStringParamLike() throws Exception {
|
||||
// findByNameLike
|
||||
this.trsSpecificExpectedQuery = DEFAULT_MATCH_CLAUSE +
|
||||
" WHERE `thing`.`name` =~ {0}" +
|
||||
" RETURN `thing`";
|
||||
super.testFindBySimpleStringParamLike();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleStringParamNotLike() throws Exception {
|
||||
// findByNameNotLike
|
||||
this.trsSpecificExpectedQuery = DEFAULT_MATCH_CLAUSE +
|
||||
" WHERE not( `thing`.`name` =~ {0} )" +
|
||||
" RETURN `thing`";
|
||||
super.testFindBySimpleStringParamNotLike();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleStringParamRegexp() throws Exception {
|
||||
// findByNameMatches
|
||||
this.trsSpecificExpectedQuery = DEFAULT_MATCH_CLAUSE +
|
||||
" WHERE `thing`.`name` =~ {0}" +
|
||||
" RETURN `thing`";
|
||||
super.testFindBySimpleStringParamRegexp();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleBooleanIsTrue() throws Exception {
|
||||
// findByTaggedIsTrue
|
||||
this.trsSpecificExpectedQuery = DEFAULT_MATCH_CLAUSE +
|
||||
" WHERE `thing`.`tagged` = true" +
|
||||
" RETURN `thing`";
|
||||
super.testFindBySimpleBooleanIsTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleBooleanIsFalse() throws Exception {
|
||||
// findByTaggedIsFalse
|
||||
this.trsSpecificExpectedQuery = DEFAULT_MATCH_CLAUSE +
|
||||
" WHERE `thing`.`tagged` = false" +
|
||||
" RETURN `thing`";
|
||||
super.testFindBySimpleBooleanIsFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleStringExists() throws Exception {
|
||||
// findByNameExists
|
||||
this.trsSpecificExpectedQuery = DEFAULT_MATCH_CLAUSE +
|
||||
" WHERE has(`thing`.`name` )" +
|
||||
" RETURN `thing`";
|
||||
super.testFindBySimpleStringExists();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleStringInCollection() throws Exception {
|
||||
// findByNameIn
|
||||
this.trsSpecificExpectedQuery = DEFAULT_MATCH_CLAUSE +
|
||||
" WHERE `thing`.`name` in {0}" +
|
||||
" RETURN `thing`";
|
||||
super.testFindBySimpleStringInCollection();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleStringInCollectionOfEnums() throws Exception {
|
||||
// findByNameIn
|
||||
this.trsSpecificExpectedQuery = DEFAULT_MATCH_CLAUSE +
|
||||
" WHERE `thing`.`name` in {0}" +
|
||||
" RETURN `thing`";
|
||||
super.testFindBySimpleStringInCollectionOfEnums();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleStringNotInCollection() throws Exception {
|
||||
// findByNameNotIn
|
||||
this.trsSpecificExpectedQuery = DEFAULT_MATCH_CLAUSE +
|
||||
" WHERE not( `thing`.`name` in {0} )" +
|
||||
" RETURN `thing`";
|
||||
super.testFindBySimpleStringNotInCollection();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleDateBefore() throws Exception {
|
||||
// findByBornBefore
|
||||
this.trsSpecificExpectedQuery = DEFAULT_MATCH_CLAUSE +
|
||||
" WHERE `thing`.`born` < {0} RETURN `thing`";
|
||||
super.testFindBySimpleDateBefore();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindBySimpleDateAfter() throws Exception {
|
||||
// findByBornAfter
|
||||
this.trsSpecificExpectedQuery = DEFAULT_MATCH_CLAUSE +
|
||||
" WHERE `thing`.`born` > {0} RETURN `thing`";
|
||||
super.testFindBySimpleDateAfter();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testFindByNumericIndexedField() throws Exception {
|
||||
// findByNumber
|
||||
this.trsSpecificExpectedQuery = "START `thing`=node:`Thing`(`number`={0}) RETURN `thing`";
|
||||
super.testFindByNumericIndexedField();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user