diff --git a/src/main/java/org/springframework/data/keyvalue/repository/support/KeyValueQueryDslUtils.java b/src/main/java/org/springframework/data/keyvalue/repository/support/KeyValueQuerydslUtils.java similarity index 95% rename from src/main/java/org/springframework/data/keyvalue/repository/support/KeyValueQueryDslUtils.java rename to src/main/java/org/springframework/data/keyvalue/repository/support/KeyValueQuerydslUtils.java index 9619a7c..fcc8ce3 100644 --- a/src/main/java/org/springframework/data/keyvalue/repository/support/KeyValueQueryDslUtils.java +++ b/src/main/java/org/springframework/data/keyvalue/repository/support/KeyValueQuerydslUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,12 +32,15 @@ import com.mysema.query.types.Path; import com.mysema.query.types.path.PathBuilder; /** + * Utilities for Querydsl usage. + * * @author Christoph Strobl * @author Thomas Darimont + * @author Oliver Gierke */ -abstract class KeyValueQueryDslUtils { +abstract class KeyValueQuerydslUtils { - private KeyValueQueryDslUtils() { + private KeyValueQuerydslUtils() { // prevent instantiation } diff --git a/src/main/java/org/springframework/data/keyvalue/repository/support/KeyValueRepositoryFactory.java b/src/main/java/org/springframework/data/keyvalue/repository/support/KeyValueRepositoryFactory.java index 8e6a7b8..2575bbf 100644 --- a/src/main/java/org/springframework/data/keyvalue/repository/support/KeyValueRepositoryFactory.java +++ b/src/main/java/org/springframework/data/keyvalue/repository/support/KeyValueRepositoryFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,6 +45,7 @@ import org.springframework.util.ClassUtils; * {@link org.springframework.data.keyvalue.repository.KeyValueRepository}. * * @author Christoph Strobl + * @author Oliver Gierke */ public class KeyValueRepositoryFactory extends RepositoryFactorySupport { @@ -106,7 +107,7 @@ public class KeyValueRepositoryFactory extends RepositoryFactorySupport { EntityInformation entityInformation = getEntityInformation(metadata.getDomainType()); if (ClassUtils.isAssignable(QueryDslPredicateExecutor.class, metadata.getRepositoryInterface())) { - return new QueryDslKeyValueRepository(entityInformation, keyValueOperations); + return new QuerydslKeyValueRepository(entityInformation, keyValueOperations); } return new SimpleKeyValueRepository(entityInformation, keyValueOperations); @@ -118,7 +119,7 @@ public class KeyValueRepositoryFactory extends RepositoryFactorySupport { */ @Override protected Class getRepositoryBaseClass(RepositoryMetadata metadata) { - return isQueryDslRepository(metadata.getRepositoryInterface()) ? QueryDslKeyValueRepository.class + return isQueryDslRepository(metadata.getRepositoryInterface()) ? QuerydslKeyValueRepository.class : SimpleKeyValueRepository.class; } diff --git a/src/main/java/org/springframework/data/keyvalue/repository/support/QueryDslKeyValueRepository.java b/src/main/java/org/springframework/data/keyvalue/repository/support/QuerydslKeyValueRepository.java similarity index 87% rename from src/main/java/org/springframework/data/keyvalue/repository/support/QueryDslKeyValueRepository.java rename to src/main/java/org/springframework/data/keyvalue/repository/support/QuerydslKeyValueRepository.java index 15523ea..e59eac7 100644 --- a/src/main/java/org/springframework/data/keyvalue/repository/support/QueryDslKeyValueRepository.java +++ b/src/main/java/org/springframework/data/keyvalue/repository/support/QuerydslKeyValueRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ */ package org.springframework.data.keyvalue.repository.support; -import static org.springframework.data.keyvalue.repository.support.KeyValueQueryDslUtils.*; +import static org.springframework.data.keyvalue.repository.support.KeyValueQuerydslUtils.*; import java.io.Serializable; @@ -42,10 +42,11 @@ import com.mysema.query.types.path.PathBuilder; * {@link KeyValueRepository} implementation capable of executing {@link Predicate}s using {@link CollQuery}. * * @author Christoph Strobl - * @param - * @param + * @author Oliver Gierke + * @param the domain type to manage + * @param the identififer type of the domain type */ -public class QueryDslKeyValueRepository extends SimpleKeyValueRepository implements +public class QuerydslKeyValueRepository extends SimpleKeyValueRepository implements QueryDslPredicateExecutor { private static final EntityPathResolver DEFAULT_ENTITY_PATH_RESOLVER = SimpleEntityPathResolver.INSTANCE; @@ -54,25 +55,25 @@ public class QueryDslKeyValueRepository extends Simp private final PathBuilder builder; /** - * Creates a new {@link QueryDslKeyValueRepository} for the given {@link EntityInformation} and + * Creates a new {@link QuerydslKeyValueRepository} for the given {@link EntityInformation} and * {@link KeyValueOperations}. * * @param entityInformation must not be {@literal null}. * @param operations must not be {@literal null}. */ - public QueryDslKeyValueRepository(EntityInformation entityInformation, KeyValueOperations operations) { + public QuerydslKeyValueRepository(EntityInformation entityInformation, KeyValueOperations operations) { this(entityInformation, operations, DEFAULT_ENTITY_PATH_RESOLVER); } /** - * Creates a new {@link QueryDslKeyValueRepository} for the given {@link EntityInformation}, + * Creates a new {@link QuerydslKeyValueRepository} for the given {@link EntityInformation}, * {@link KeyValueOperations} and {@link EntityPathResolver}. * * @param entityInformation must not be {@literal null}. * @param operations must not be {@literal null}. * @param resolver must not be {@literal null}. */ - public QueryDslKeyValueRepository(EntityInformation entityInformation, KeyValueOperations operations, + public QuerydslKeyValueRepository(EntityInformation entityInformation, KeyValueOperations operations, EntityPathResolver resolver) { super(entityInformation, operations); @@ -162,6 +163,15 @@ public class QueryDslKeyValueRepository extends Simp return prepareQuery(predicate).count(); } + /* + * (non-Javadoc) + * @see org.springframework.data.querydsl.QueryDslPredicateExecutor#exists(com.mysema.query.types.Predicate) + */ + @Override + public boolean exists(Predicate predicate) { + return prepareQuery(predicate).exists(); + } + /** * Creates executable query for given {@link Predicate}. * diff --git a/src/test/java/org/springframework/data/keyvalue/repository/support/QueryDslUtilsUnitTests.java b/src/test/java/org/springframework/data/keyvalue/repository/support/KeyValueQuerydslUtilsUnitTests.java similarity index 94% rename from src/test/java/org/springframework/data/keyvalue/repository/support/QueryDslUtilsUnitTests.java rename to src/test/java/org/springframework/data/keyvalue/repository/support/KeyValueQuerydslUtilsUnitTests.java index 478e453..605becf 100644 --- a/src/test/java/org/springframework/data/keyvalue/repository/support/QueryDslUtilsUnitTests.java +++ b/src/test/java/org/springframework/data/keyvalue/repository/support/KeyValueQuerydslUtilsUnitTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ package org.springframework.data.keyvalue.repository.support; import static org.hamcrest.collection.IsArrayWithSize.*; import static org.junit.Assert.*; -import static org.springframework.data.keyvalue.repository.support.KeyValueQueryDslUtils.*; +import static org.springframework.data.keyvalue.repository.support.KeyValueQuerydslUtils.*; import org.hamcrest.collection.IsArrayContainingInOrder; import org.junit.Before; @@ -34,10 +34,13 @@ import com.mysema.query.types.OrderSpecifier; import com.mysema.query.types.path.PathBuilder; /** + * Unit tests for {@link KeyValueQuerydslUtils}. + * * @author Christoph Strobl * @author Thomas Darimont + * @author Oliver Gierke */ -public class QueryDslUtilsUnitTests { +public class KeyValueQuerydslUtilsUnitTests { private EntityPath path; private PathBuilder builder; diff --git a/src/test/java/org/springframework/data/map/AbstractRepositoryUnitTests.java b/src/test/java/org/springframework/data/map/AbstractRepositoryUnitTests.java new file mode 100644 index 0000000..f9bc531 --- /dev/null +++ b/src/test/java/org/springframework/data/map/AbstractRepositoryUnitTests.java @@ -0,0 +1,174 @@ +/* + * Copyright 2014-2015 the original author or authors. + * + * Licensed 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.springframework.data.map; + +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; + +import java.util.Arrays; +import java.util.List; + +import org.hamcrest.collection.IsCollectionWithSize; +import org.junit.Before; +import org.junit.Test; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.data.domain.Sort.Direction; +import org.springframework.data.keyvalue.Person; +import org.springframework.data.keyvalue.core.KeyValueOperations; +import org.springframework.data.keyvalue.core.KeyValueTemplate; +import org.springframework.data.keyvalue.repository.KeyValueRepository; +import org.springframework.data.keyvalue.repository.support.KeyValueRepositoryFactory; +import org.springframework.data.repository.CrudRepository; + +/** + * Base class for test cases for repository implementations. + * + * @author Christoph Strobl + * @author Oliver Gierke + */ +public abstract class AbstractRepositoryUnitTests { + + protected static final Person CERSEI = new Person("cersei", 19); + protected static final Person JAIME = new Person("jaime", 19); + protected static final Person TYRION = new Person("tyrion", 17); + + protected static List LENNISTERS = Arrays.asList(CERSEI, JAIME, TYRION); + + protected T repository; + protected KeyValueRepositoryFactory factory; + + @Before + public void setup() { + + KeyValueOperations operations = new KeyValueTemplate(new MapKeyValueAdapter()); + KeyValueRepositoryFactory keyValueRepositoryFactory = new KeyValueRepositoryFactory(operations); + + this.repository = getRepository(keyValueRepositoryFactory); + } + + /** + * @see DATACMNS-525 + */ + @Test + public void findBy() { + + repository.save(LENNISTERS); + + assertThat(repository.findByAge(19), hasItems(CERSEI, JAIME)); + } + + /** + * @see DATACMNS-525 + */ + @Test + public void combindedFindUsingAnd() { + + repository.save(LENNISTERS); + + assertThat(repository.findByFirstnameAndAge(JAIME.getFirstname(), 19), hasItem(JAIME)); + } + + /** + * @see DATACMNS-525 + */ + @Test + public void findPage() { + + repository.save(LENNISTERS); + + Page page = repository.findByAge(19, new PageRequest(0, 1)); + assertThat(page.hasNext(), is(true)); + assertThat(page.getTotalElements(), is(2L)); + assertThat(page.getContent(), IsCollectionWithSize.hasSize(1)); + + Page next = repository.findByAge(19, page.nextPageable()); + assertThat(next.hasNext(), is(false)); + assertThat(next.getTotalElements(), is(2L)); + assertThat(next.getContent(), IsCollectionWithSize.hasSize(1)); + } + + /** + * @see DATACMNS-525 + */ + @Test + public void findByConnectingOr() { + + repository.save(LENNISTERS); + + assertThat(repository.findByAgeOrFirstname(19, TYRION.getFirstname()), hasItems(CERSEI, JAIME, TYRION)); + } + + /** + * @see DATACMNS-525 + */ + @Test + public void singleEntityExecution() { + + repository.save(LENNISTERS); + + assertThat(repository.findByAgeAndFirstname(TYRION.getAge(), TYRION.getFirstname()), is(TYRION)); + } + + /** + * @see DATACMNS-525 + */ + @Test + public void findAllShouldRespectSort() { + + repository.save(LENNISTERS); + + assertThat( + repository.findAll(new Sort(new Sort.Order(Direction.ASC, "age"), new Sort.Order(Direction.DESC, "firstname"))), + contains(TYRION, JAIME, CERSEI)); + } + + /** + * @see DATACMNS-525 + */ + @Test + public void derivedFinderShouldRespectSort() { + + repository.save(LENNISTERS); + + List result = repository.findByAgeGreaterThanOrderByAgeAscFirstnameDesc(2); + + assertThat(result, contains(TYRION, JAIME, CERSEI)); + } + + protected abstract T getRepository(KeyValueRepositoryFactory factory); + + public static interface PersonRepository extends CrudRepository, KeyValueRepository { + + List findByAge(int age); + + List findByFirstname(String firstname); + + List findByFirstnameAndAge(String firstname, int age); + + Page findByAge(int age, Pageable page); + + List findByAgeOrFirstname(int age, String firstname); + + Person findByAgeAndFirstname(int age, String firstname); + + List findByAgeGreaterThanOrderByAgeAscFirstnameDesc(int age); + + } + +} diff --git a/src/test/java/org/springframework/data/map/QueryDslMapRepositoryUnitTests.java b/src/test/java/org/springframework/data/map/QuerydslKeyValueRepositoryUnitTests.java similarity index 60% rename from src/test/java/org/springframework/data/map/QueryDslMapRepositoryUnitTests.java rename to src/test/java/org/springframework/data/map/QuerydslKeyValueRepositoryUnitTests.java index fe84026..cbf50b0 100644 --- a/src/test/java/org/springframework/data/map/QueryDslMapRepositoryUnitTests.java +++ b/src/test/java/org/springframework/data/map/QuerydslKeyValueRepositoryUnitTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,13 +27,19 @@ import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort.Direction; import org.springframework.data.keyvalue.Person; import org.springframework.data.keyvalue.QPerson; +import org.springframework.data.keyvalue.repository.support.KeyValueRepositoryFactory; +import org.springframework.data.keyvalue.repository.support.QuerydslKeyValueRepository; +import org.springframework.data.map.QuerydslKeyValueRepositoryUnitTests.QPersonRepository; import org.springframework.data.querydsl.QSort; import org.springframework.data.querydsl.QueryDslPredicateExecutor; /** + * Unit tests for {@link QuerydslKeyValueRepository}. + * * @author Christoph Strobl + * @author Oliver Gierke */ -public class QueryDslMapRepositoryUnitTests extends SimpleKeyValueRepositoryUnitTests { +public class QuerydslKeyValueRepositoryUnitTests extends AbstractRepositoryUnitTests { /** * @see DATACMNS-525 @@ -43,7 +49,7 @@ public class QueryDslMapRepositoryUnitTests extends SimpleKeyValueRepositoryUnit repository.save(LENNISTERS); - Person result = getQPersonRepo().findOne(QPerson.person.firstname.eq(CERSEI.getFirstname())); + Person result = repository.findOne(QPerson.person.firstname.eq(CERSEI.getFirstname())); assertThat(result, is(CERSEI)); } @@ -55,7 +61,7 @@ public class QueryDslMapRepositoryUnitTests extends SimpleKeyValueRepositoryUnit repository.save(LENNISTERS); - Iterable result = getQPersonRepo().findAll(QPerson.person.age.eq(CERSEI.getAge())); + Iterable result = repository.findAll(QPerson.person.age.eq(CERSEI.getAge())); assertThat(result, containsInAnyOrder(CERSEI, JAIME)); } @@ -66,7 +72,7 @@ public class QueryDslMapRepositoryUnitTests extends SimpleKeyValueRepositoryUnit public void findWithPaginationWorksCorrectly() { repository.save(LENNISTERS); - Page page1 = getQPersonRepo().findAll(QPerson.person.age.eq(CERSEI.getAge()), new PageRequest(0, 1)); + Page page1 = repository.findAll(QPerson.person.age.eq(CERSEI.getAge()), new PageRequest(0, 1)); assertThat(page1.getTotalElements(), is(2L)); assertThat(page1.getContent(), hasSize(1)); @@ -88,7 +94,7 @@ public class QueryDslMapRepositoryUnitTests extends SimpleKeyValueRepositoryUnit repository.save(LENNISTERS); - Iterable result = getQPersonRepo().findAll(QPerson.person.age.eq(CERSEI.getAge()), + Iterable result = repository.findAll(QPerson.person.age.eq(CERSEI.getAge()), QPerson.person.firstname.desc()); assertThat(result, contains(JAIME, CERSEI)); @@ -102,8 +108,8 @@ public class QueryDslMapRepositoryUnitTests extends SimpleKeyValueRepositoryUnit repository.save(LENNISTERS); - Iterable result = getQPersonRepo().findAll(QPerson.person.age.eq(CERSEI.getAge()), - new PageRequest(0, 10, Direction.DESC, "firstname")); + Iterable result = repository.findAll(QPerson.person.age.eq(CERSEI.getAge()), new PageRequest(0, 10, + Direction.DESC, "firstname")); assertThat(result, contains(JAIME, CERSEI)); } @@ -116,8 +122,8 @@ public class QueryDslMapRepositoryUnitTests extends SimpleKeyValueRepositoryUnit repository.save(LENNISTERS); - Iterable result = getQPersonRepo().findAll(QPerson.person.age.eq(CERSEI.getAge()), - new PageRequest(0, 10, new QSort(QPerson.person.firstname.desc()))); + Iterable result = repository.findAll(QPerson.person.age.eq(CERSEI.getAge()), new PageRequest(0, 10, + new QSort(QPerson.person.firstname.desc()))); assertThat(result, contains(JAIME, CERSEI)); } @@ -130,7 +136,7 @@ public class QueryDslMapRepositoryUnitTests extends SimpleKeyValueRepositoryUnit repository.save(LENNISTERS); - Iterable result = getQPersonRepo().findAll(new QSort(QPerson.person.firstname.desc())); + Iterable result = repository.findAll(new QSort(QPerson.person.firstname.desc())); assertThat(result, contains(TYRION, JAIME, CERSEI)); } @@ -143,22 +149,31 @@ public class QueryDslMapRepositoryUnitTests extends SimpleKeyValueRepositoryUnit repository.save(LENNISTERS); - Iterable result = getQPersonRepo().findAll((QSort) null); + Iterable result = repository.findAll((QSort) null); assertThat(result, containsInAnyOrder(TYRION, JAIME, CERSEI)); } + /** + * @see DATAKV-95 + */ + @Test + public void executesExistsCorrectly() { + + repository.save(LENNISTERS); + + assertThat(repository.exists(QPerson.person.age.eq(CERSEI.getAge())), is(true)); + } + + /* + * (non-Javadoc) + * @see org.springframework.data.map.SimpleKeyValueRepositoryUnitTests#getRepository(org.springframework.data.keyvalue.repository.support.KeyValueRepositoryFactory) + */ @Override - protected Class getRepositoryClass() { - return QPersonRepository.class; - } - - QPersonRepository getQPersonRepo() { - return ((QPersonRepository) repository); - } - - static interface QPersonRepository extends PersonRepository, QueryDslPredicateExecutor { - + protected QPersonRepository getRepository(KeyValueRepositoryFactory factory) { + return factory.getRepository(QPersonRepository.class); } + static interface QPersonRepository extends org.springframework.data.map.AbstractRepositoryUnitTests.PersonRepository, + QueryDslPredicateExecutor {} } diff --git a/src/test/java/org/springframework/data/map/SimpleKeyValueRepositoryUnitTests.java b/src/test/java/org/springframework/data/map/SimpleKeyValueRepositoryUnitTests.java index 2313feb..17ca4fd 100644 --- a/src/test/java/org/springframework/data/map/SimpleKeyValueRepositoryUnitTests.java +++ b/src/test/java/org/springframework/data/map/SimpleKeyValueRepositoryUnitTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,156 +15,19 @@ */ package org.springframework.data.map; -import static org.hamcrest.collection.IsIterableContainingInAnyOrder.*; -import static org.hamcrest.collection.IsIterableContainingInOrder.*; -import static org.hamcrest.core.Is.*; -import static org.junit.Assert.*; - -import java.util.Arrays; -import java.util.List; - -import org.hamcrest.collection.IsCollectionWithSize; -import org.hamcrest.collection.IsIterableContainingInOrder; -import org.junit.Before; -import org.junit.Test; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; -import org.springframework.data.domain.Sort.Direction; -import org.springframework.data.keyvalue.Person; -import org.springframework.data.keyvalue.core.KeyValueTemplate; -import org.springframework.data.keyvalue.repository.KeyValueRepository; import org.springframework.data.keyvalue.repository.support.KeyValueRepositoryFactory; -import org.springframework.data.repository.CrudRepository; +import org.springframework.data.keyvalue.repository.support.SimpleKeyValueRepository; +import org.springframework.data.map.AbstractRepositoryUnitTests.PersonRepository; /** + * Unit tests for {@link SimpleKeyValueRepository}. + * * @author Christoph Strobl + * @author Oliver Gierke */ -public class SimpleKeyValueRepositoryUnitTests { +public class SimpleKeyValueRepositoryUnitTests extends AbstractRepositoryUnitTests { - protected static final Person CERSEI = new Person("cersei", 19); - protected static final Person JAIME = new Person("jaime", 19); - protected static final Person TYRION = new Person("tyrion", 17); - - protected static List LENNISTERS = Arrays.asList(CERSEI, JAIME, TYRION); - - protected PersonRepository repository; - protected KeyValueTemplate template = new KeyValueTemplate(new MapKeyValueAdapter()); - - @Before - public void setup() { - this.repository = new KeyValueRepositoryFactory(template).getRepository(getRepositoryClass()); + protected PersonRepository getRepository(KeyValueRepositoryFactory factory) { + return factory.getRepository(PersonRepository.class); } - - /** - * @see DATACMNS-525 - */ - @Test - public void findBy() { - - this.repository.save(LENNISTERS); - assertThat(this.repository.findByAge(19), containsInAnyOrder(CERSEI, JAIME)); - } - - /** - * @see DATACMNS-525 - */ - @Test - public void combindedFindUsingAnd() { - - this.repository.save(LENNISTERS); - - assertThat(this.repository.findByFirstnameAndAge(JAIME.getFirstname(), 19), containsInAnyOrder(JAIME)); - } - - /** - * @see DATACMNS-525 - */ - @Test - public void findPage() { - - this.repository.save(LENNISTERS); - - Page page = this.repository.findByAge(19, new PageRequest(0, 1)); - assertThat(page.hasNext(), is(true)); - assertThat(page.getTotalElements(), is(2L)); - assertThat(page.getContent(), IsCollectionWithSize.hasSize(1)); - - Page next = this.repository.findByAge(19, page.nextPageable()); - assertThat(next.hasNext(), is(false)); - assertThat(next.getTotalElements(), is(2L)); - assertThat(next.getContent(), IsCollectionWithSize.hasSize(1)); - } - - /** - * @see DATACMNS-525 - */ - @Test - public void findByConnectingOr() { - - this.repository.save(LENNISTERS); - - assertThat(this.repository.findByAgeOrFirstname(19, TYRION.getFirstname()), - containsInAnyOrder(CERSEI, JAIME, TYRION)); - } - - /** - * @see DATACMNS-525 - */ - @Test - public void singleEntityExecution() { - - this.repository.save(LENNISTERS); - - assertThat(this.repository.findByAgeAndFirstname(TYRION.getAge(), TYRION.getFirstname()), is(TYRION)); - } - - /** - * @see DATACMNS-525 - */ - @Test - public void findAllShouldRespectSort() { - - this.repository.save(LENNISTERS); - - assertThat(this.repository.findAll(new Sort(new Sort.Order(Direction.ASC, "age"), new Sort.Order(Direction.DESC, - "firstname"))), IsIterableContainingInOrder.contains(TYRION, JAIME, CERSEI)); - } - - /** - * @see DATACMNS-525 - */ - @Test - public void derivedFinderShouldRespectSort() { - - repository.save(LENNISTERS); - - List result = repository.findByAgeGreaterThanOrderByAgeAscFirstnameDesc(2); - - assertThat(result, contains(TYRION, JAIME, CERSEI)); - } - - protected Class getRepositoryClass() { - return PersonRepository.class; - } - - public static interface PersonRepository extends CrudRepository, KeyValueRepository { - - List findByAge(int age); - - List findByFirstname(String firstname); - - List findByFirstnameAndAge(String firstname, int age); - - Page findByAge(int age, Pageable page); - - List findByAgeOrFirstname(int age, String firstname); - - Person findByAgeAndFirstname(int age, String firstname); - - List findByAgeGreaterThanOrderByAgeAscFirstnameDesc(int age); - - } - }