DATAMONGO-1690 - Polishing.

Rename QueryDslMongoRepository -> QuerydslMongoRepository. Migrate assertions to AssertJ.

Original pull request #461.
Related ticket: DATACMNS-1059.
This commit is contained in:
Christoph Strobl
2017-05-11 12:10:35 +02:00
committed by Oliver Gierke
parent 898489fecf
commit f2ee7d90c4
3 changed files with 23 additions and 28 deletions

View File

@@ -106,7 +106,7 @@ public class MongoRepositoryFactory extends RepositoryFactorySupport {
return SimpleReactiveMongoRepository.class; return SimpleReactiveMongoRepository.class;
} }
return isQueryDslRepository ? QueryDslMongoRepository.class : SimpleMongoRepository.class; return isQueryDslRepository ? QuerydslMongoRepository.class : SimpleMongoRepository.class;
} }
/* /*

View File

@@ -45,14 +45,14 @@ import com.querydsl.core.types.dsl.PathBuilder;
import com.querydsl.mongodb.AbstractMongodbQuery; import com.querydsl.mongodb.AbstractMongodbQuery;
/** /**
* Special QueryDsl based repository implementation that allows execution {@link Predicate}s in various forms. * Special Querydsl based repository implementation that allows execution {@link Predicate}s in various forms.
* *
* @author Oliver Gierke * @author Oliver Gierke
* @author Thomas Darimont * @author Thomas Darimont
* @author Mark Paluch * @author Mark Paluch
* @author Christoph Strobl * @author Christoph Strobl
*/ */
public class QueryDslMongoRepository<T, ID extends Serializable> extends SimpleMongoRepository<T, ID> public class QuerydslMongoRepository<T, ID extends Serializable> extends SimpleMongoRepository<T, ID>
implements QuerydslPredicateExecutor<T> { implements QuerydslPredicateExecutor<T> {
private final PathBuilder<T> builder; private final PathBuilder<T> builder;
@@ -60,25 +60,25 @@ public class QueryDslMongoRepository<T, ID extends Serializable> extends SimpleM
private final MongoOperations mongoOperations; private final MongoOperations mongoOperations;
/** /**
* Creates a new {@link QueryDslMongoRepository} for the given {@link EntityMetadata} and {@link MongoTemplate}. Uses * Creates a new {@link QuerydslMongoRepository} for the given {@link EntityMetadata} and {@link MongoTemplate}. Uses
* the {@link SimpleEntityPathResolver} to create an {@link EntityPath} for the given domain class. * the {@link SimpleEntityPathResolver} to create an {@link EntityPath} for the given domain class.
* *
* @param entityInformation must not be {@literal null}. * @param entityInformation must not be {@literal null}.
* @param mongoOperations must not be {@literal null}. * @param mongoOperations must not be {@literal null}.
*/ */
public QueryDslMongoRepository(MongoEntityInformation<T, ID> entityInformation, MongoOperations mongoOperations) { public QuerydslMongoRepository(MongoEntityInformation<T, ID> entityInformation, MongoOperations mongoOperations) {
this(entityInformation, mongoOperations, SimpleEntityPathResolver.INSTANCE); this(entityInformation, mongoOperations, SimpleEntityPathResolver.INSTANCE);
} }
/** /**
* Creates a new {@link QueryDslMongoRepository} for the given {@link MongoEntityInformation}, {@link MongoTemplate} * Creates a new {@link QuerydslMongoRepository} for the given {@link MongoEntityInformation}, {@link MongoTemplate}
* and {@link EntityPathResolver}. * and {@link EntityPathResolver}.
* *
* @param entityInformation must not be {@literal null}. * @param entityInformation must not be {@literal null}.
* @param mongoOperations must not be {@literal null}. * @param mongoOperations must not be {@literal null}.
* @param resolver must not be {@literal null}. * @param resolver must not be {@literal null}.
*/ */
public QueryDslMongoRepository(MongoEntityInformation<T, ID> entityInformation, MongoOperations mongoOperations, public QuerydslMongoRepository(MongoEntityInformation<T, ID> entityInformation, MongoOperations mongoOperations,
EntityPathResolver resolver) { EntityPathResolver resolver) {
super(entityInformation, mongoOperations); super(entityInformation, mongoOperations);
@@ -227,7 +227,7 @@ public class QueryDslMongoRepository<T, ID extends Serializable> extends SimpleM
/** /**
* Creates a {@link MongodbQuery} for the given {@link Predicate}. * Creates a {@link MongodbQuery} for the given {@link Predicate}.
* *
* @param predicate * @param predicate
* @return * @return
*/ */
@@ -246,7 +246,7 @@ public class QueryDslMongoRepository<T, ID extends Serializable> extends SimpleM
/** /**
* Applies the given {@link Pageable} to the given {@link MongodbQuery}. * Applies the given {@link Pageable} to the given {@link MongodbQuery}.
* *
* @param query * @param query
* @param pageable * @param pageable
* @return * @return
@@ -260,7 +260,7 @@ public class QueryDslMongoRepository<T, ID extends Serializable> extends SimpleM
/** /**
* Applies the given {@link Sort} to the given {@link MongodbQuery}. * Applies the given {@link Sort} to the given {@link MongodbQuery}.
* *
* @param query * @param query
* @param sort * @param sort
* @return * @return
@@ -284,7 +284,7 @@ public class QueryDslMongoRepository<T, ID extends Serializable> extends SimpleM
/** /**
* Transforms a plain {@link Order} into a QueryDsl specific {@link OrderSpecifier}. * Transforms a plain {@link Order} into a QueryDsl specific {@link OrderSpecifier}.
* *
* @param order * @param order
* @return * @return
*/ */

View File

@@ -15,13 +15,11 @@
*/ */
package org.springframework.data.mongodb.repository.support; package org.springframework.data.mongodb.repository.support;
import static org.hamcrest.Matchers.*; import static org.assertj.core.api.Assertions.*;
import static org.junit.Assert.*;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.assertj.core.api.Assertions;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@@ -37,7 +35,7 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/** /**
* Integration test for {@link QueryDslMongoRepository}. * Integration test for {@link QuerydslMongoRepository}.
* *
* @author Thomas Darimont * @author Thomas Darimont
* @author Mark Paluch * @author Mark Paluch
@@ -49,7 +47,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
public class QueryDslMongoRepositoryIntegrationTests { public class QueryDslMongoRepositoryIntegrationTests {
@Autowired MongoOperations operations; @Autowired MongoOperations operations;
QueryDslMongoRepository<Person, String> repository; QuerydslMongoRepository<Person, String> repository;
Person dave, oliver, carter; Person dave, oliver, carter;
QPerson person; QPerson person;
@@ -59,7 +57,7 @@ public class QueryDslMongoRepositoryIntegrationTests {
MongoRepositoryFactory factory = new MongoRepositoryFactory(operations); MongoRepositoryFactory factory = new MongoRepositoryFactory(operations);
MongoEntityInformation<Person, String> entityInformation = factory.getEntityInformation(Person.class); MongoEntityInformation<Person, String> entityInformation = factory.getEntityInformation(Person.class);
repository = new QueryDslMongoRepository<Person, String>(entityInformation, operations); repository = new QuerydslMongoRepository<>(entityInformation, operations);
operations.dropCollection(Person.class); operations.dropCollection(Person.class);
@@ -75,8 +73,8 @@ public class QueryDslMongoRepositoryIntegrationTests {
@Test // DATAMONGO-1146 @Test // DATAMONGO-1146
public void shouldSupportExistsWithPredicate() throws Exception { public void shouldSupportExistsWithPredicate() throws Exception {
assertThat(repository.exists(person.firstname.eq("Dave")), is(true)); assertThat(repository.exists(person.firstname.eq("Dave"))).isTrue();
assertThat(repository.exists(person.firstname.eq("Unknown")), is(false)); assertThat(repository.exists(person.firstname.eq("Unknown"))).isFalse();
} }
@Test // DATAMONGO-1167 @Test // DATAMONGO-1167
@@ -84,20 +82,17 @@ public class QueryDslMongoRepositoryIntegrationTests {
List<Person> users = repository.findAll(person.lastname.isNotNull(), Sort.by(Direction.ASC, "firstname")); List<Person> users = repository.findAll(person.lastname.isNotNull(), Sort.by(Direction.ASC, "firstname"));
assertThat(users, hasSize(3)); assertThat(users).containsExactly(carter, dave, oliver);
assertThat(users.get(0).getFirstname(), is(carter.getFirstname()));
assertThat(users.get(2).getFirstname(), is(oliver.getFirstname()));
assertThat(users, hasItems(carter, dave, oliver));
} }
@Test // DATAMONGO-1690 @Test // DATAMONGO-1690
public void findOneWithPredicateReturnsResultCorrectly() { public void findOneWithPredicateReturnsResultCorrectly() {
Assertions.assertThat(repository.findOne(person.firstname.eq(dave.getFirstname()))).contains(dave); assertThat(repository.findOne(person.firstname.eq(dave.getFirstname()))).contains(dave);
} }
@Test // DATAMONGO-1690 @Test // DATAMONGO-1690
public void findOneWithPredicateReturnsOptionalEmptyWhenNoDataFound() { public void findOneWithPredicateReturnsOptionalEmptyWhenNoDataFound() {
Assertions.assertThat(repository.findOne(person.firstname.eq("batman"))).isNotPresent(); assertThat(repository.findOne(person.firstname.eq("batman"))).isNotPresent();
} }
@Test(expected = IncorrectResultSizeDataAccessException.class) // DATAMONGO-1690 @Test(expected = IncorrectResultSizeDataAccessException.class) // DATAMONGO-1690