@ -52,6 +52,7 @@ import org.springframework.data.geo.Polygon;
import org.springframework.data.mongodb.core.MongoOperations ;
import org.springframework.data.mongodb.core.MongoOperations ;
import org.springframework.data.mongodb.core.query.BasicQuery ;
import org.springframework.data.mongodb.core.query.BasicQuery ;
import org.springframework.data.mongodb.repository.Person.Sex ;
import org.springframework.data.mongodb.repository.Person.Sex ;
import org.springframework.data.mongodb.repository.SampleEvaluationContextExtension.SampleSecurityContextHolder ;
import org.springframework.data.querydsl.QSort ;
import org.springframework.data.querydsl.QSort ;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner ;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner ;
@ -174,8 +175,8 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
@Test
@Test
public void executesPagedFinderCorrectly ( ) throws Exception {
public void executesPagedFinderCorrectly ( ) throws Exception {
Page < Person > page = repository . findByLastnameLike ( "*a*" , new PageRequest ( 0 , 2 , Direction . ASC , "lastname" ,
Page < Person > page = repository . findByLastnameLike ( "*a*" ,
"firstname" ) ) ;
new PageRequest ( 0 , 2 , Direction . ASC , "lastname" , "firstname" ) ) ;
assertThat ( page . isFirst ( ) , is ( true ) ) ;
assertThat ( page . isFirst ( ) , is ( true ) ) ;
assertThat ( page . isLast ( ) , is ( false ) ) ;
assertThat ( page . isLast ( ) , is ( false ) ) ;
assertThat ( page . getNumberOfElements ( ) , is ( 2 ) ) ;
assertThat ( page . getNumberOfElements ( ) , is ( 2 ) ) ;
@ -185,8 +186,8 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
@Test
@Test
public void executesPagedFinderWithAnnotatedQueryCorrectly ( ) throws Exception {
public void executesPagedFinderWithAnnotatedQueryCorrectly ( ) throws Exception {
Page < Person > page = repository . findByLastnameLikeWithPageable ( ".*a.*" , new PageRequest ( 0 , 2 , Direction . ASC ,
Page < Person > page = repository . findByLastnameLikeWithPageable ( ".*a.*" ,
"lastname" , "firstname" ) ) ;
new PageRequest ( 0 , 2 , Direction . ASC , "lastname" , "firstname" ) ) ;
assertThat ( page . isFirst ( ) , is ( true ) ) ;
assertThat ( page . isFirst ( ) , is ( true ) ) ;
assertThat ( page . isLast ( ) , is ( false ) ) ;
assertThat ( page . isLast ( ) , is ( false ) ) ;
assertThat ( page . getNumberOfElements ( ) , is ( 2 ) ) ;
assertThat ( page . getNumberOfElements ( ) , is ( 2 ) ) ;
@ -310,8 +311,8 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
@Test
@Test
public void findsPagedPeopleByPredicate ( ) throws Exception {
public void findsPagedPeopleByPredicate ( ) throws Exception {
Page < Person > page = repository . findAll ( person . lastname . contains ( "a" ) , new PageRequest ( 0 , 2 , Direction . ASC ,
Page < Person > page = repository . findAll ( person . lastname . contains ( "a" ) ,
"lastname" ) ) ;
new PageRequest ( 0 , 2 , Direction . ASC , "lastname" ) ) ;
assertThat ( page . isFirst ( ) , is ( true ) ) ;
assertThat ( page . isFirst ( ) , is ( true ) ) ;
assertThat ( page . isLast ( ) , is ( false ) ) ;
assertThat ( page . isLast ( ) , is ( false ) ) ;
assertThat ( page . getNumberOfElements ( ) , is ( 2 ) ) ;
assertThat ( page . getNumberOfElements ( ) , is ( 2 ) ) ;
@ -397,8 +398,8 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
dave . setLocation ( point ) ;
dave . setLocation ( point ) ;
repository . save ( dave ) ;
repository . save ( dave ) ;
GeoResults < Person > results = repository . findByLocationNear ( new Point ( - 73 . 99 , 40 . 73 ) , new Distance ( 2000 ,
GeoResults < Person > results = repository . findByLocationNear ( new Point ( - 73 . 99 , 40 . 73 ) ,
Metrics . KILOMETERS ) ) ;
new Distance ( 2000 , Metrics . KILOMETERS ) ) ;
assertThat ( results . getContent ( ) . isEmpty ( ) , is ( false ) ) ;
assertThat ( results . getContent ( ) . isEmpty ( ) , is ( false ) ) ;
}
}
@ -409,8 +410,8 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
dave . setLocation ( point ) ;
dave . setLocation ( point ) ;
repository . save ( dave ) ;
repository . save ( dave ) ;
GeoPage < Person > results = repository . findByLocationNear ( new Point ( - 73 . 99 , 40 . 73 ) , new Distance ( 2000 ,
GeoPage < Person > results = repository . findByLocationNear ( new Point ( - 73 . 99 , 40 . 73 ) ,
Metrics . KILOMETERS ) , new PageRequest ( 0 , 20 ) ) ;
new Distance ( 2000 , Metrics . KILOMETERS ) , new PageRequest ( 0 , 20 ) ) ;
assertThat ( results . getContent ( ) . isEmpty ( ) , is ( false ) ) ;
assertThat ( results . getContent ( ) . isEmpty ( ) , is ( false ) ) ;
// DATAMONGO-607
// DATAMONGO-607
@ -620,8 +621,8 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
repository . save ( Arrays . asList ( dave , oliver , carter , boyd , leroi ) ) ;
repository . save ( Arrays . asList ( dave , oliver , carter , boyd , leroi ) ) ;
GeoPage < Person > results = repository . findByLocationNear ( new Point ( - 73 . 99 , 40 . 73 ) , new Distance ( 2000 ,
GeoPage < Person > results = repository . findByLocationNear ( new Point ( - 73 . 99 , 40 . 73 ) ,
Metrics . KILOMETERS ) , new PageRequest ( 1 , 2 ) ) ;
new Distance ( 2000 , Metrics . KILOMETERS ) , new PageRequest ( 1 , 2 ) ) ;
assertThat ( results . getContent ( ) . isEmpty ( ) , is ( false ) ) ;
assertThat ( results . getContent ( ) . isEmpty ( ) , is ( false ) ) ;
assertThat ( results . getNumberOfElements ( ) , is ( 2 ) ) ;
assertThat ( results . getNumberOfElements ( ) , is ( 2 ) ) ;
@ -645,8 +646,8 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
repository . save ( Arrays . asList ( dave , oliver , carter ) ) ;
repository . save ( Arrays . asList ( dave , oliver , carter ) ) ;
GeoPage < Person > results = repository . findByLocationNear ( new Point ( - 73 . 99 , 40 . 73 ) , new Distance ( 2000 ,
GeoPage < Person > results = repository . findByLocationNear ( new Point ( - 73 . 99 , 40 . 73 ) ,
Metrics . KILOMETERS ) , new PageRequest ( 1 , 2 ) ) ;
new Distance ( 2000 , Metrics . KILOMETERS ) , new PageRequest ( 1 , 2 ) ) ;
assertThat ( results . getContent ( ) . isEmpty ( ) , is ( false ) ) ;
assertThat ( results . getContent ( ) . isEmpty ( ) , is ( false ) ) ;
assertThat ( results . getNumberOfElements ( ) , is ( 1 ) ) ;
assertThat ( results . getNumberOfElements ( ) , is ( 1 ) ) ;
assertThat ( results . isFirst ( ) , is ( false ) ) ;
assertThat ( results . isFirst ( ) , is ( false ) ) ;
@ -664,8 +665,8 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
dave . setLocation ( point ) ;
dave . setLocation ( point ) ;
repository . save ( dave ) ;
repository . save ( dave ) ;
GeoPage < Person > results = repository . findByLocationNear ( new Point ( - 73 . 99 , 40 . 73 ) , new Distance ( 2000 ,
GeoPage < Person > results = repository . findByLocationNear ( new Point ( - 73 . 99 , 40 . 73 ) ,
Metrics . KILOMETERS ) , new PageRequest ( 0 , 2 ) ) ;
new Distance ( 2000 , Metrics . KILOMETERS ) , new PageRequest ( 0 , 2 ) ) ;
assertThat ( results . getContent ( ) . isEmpty ( ) , is ( false ) ) ;
assertThat ( results . getContent ( ) . isEmpty ( ) , is ( false ) ) ;
assertThat ( results . getNumberOfElements ( ) , is ( 1 ) ) ;
assertThat ( results . getNumberOfElements ( ) , is ( 1 ) ) ;
@ -683,8 +684,8 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
dave . setLocation ( new Point ( - 73 . 99171 , 40 . 738868 ) ) ;
dave . setLocation ( new Point ( - 73 . 99171 , 40 . 738868 ) ) ;
repository . save ( dave ) ;
repository . save ( dave ) ;
GeoPage < Person > results = repository . findByLocationNear ( new Point ( - 73 . 99 , 40 . 73 ) , new Distance ( 2000 ,
GeoPage < Person > results = repository . findByLocationNear ( new Point ( - 73 . 99 , 40 . 73 ) ,
Metrics . KILOMETERS ) , new PageRequest ( 1 , 2 ) ) ;
new Distance ( 2000 , Metrics . KILOMETERS ) , new PageRequest ( 1 , 2 ) ) ;
assertThat ( results . getContent ( ) . isEmpty ( ) , is ( true ) ) ;
assertThat ( results . getContent ( ) . isEmpty ( ) , is ( true ) ) ;
assertThat ( results . getNumberOfElements ( ) , is ( 0 ) ) ;
assertThat ( results . getNumberOfElements ( ) , is ( 0 ) ) ;
@ -934,8 +935,8 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
@Test
@Test
public void shouldLimitCollectionQueryToMaxResultsWhenPresent ( ) {
public void shouldLimitCollectionQueryToMaxResultsWhenPresent ( ) {
repository . save ( Arrays . asList ( new Person ( "Bob-1" , "Dylan" ) , new Person ( "Bob-2" , "Dylan" ) , new Person ( "Bob-3" ,
repository . save ( Arrays . asList ( new Person ( "Bob-1" , "Dylan" ) , new Person ( "Bob-2" , "Dylan" ) ,
"Dylan" ) , new Person ( "Bob-4" , "Dylan" ) , new Person ( "Bob-5" , "Dylan" ) ) ) ;
new Person ( "Bob-3" , "Dylan" ) , new Person ( "Bob-4" , "Dylan" ) , new Person ( "Bob-5" , "Dylan" ) ) ) ;
List < Person > result = repository . findTop3ByLastnameStartingWith ( "Dylan" ) ;
List < Person > result = repository . findTop3ByLastnameStartingWith ( "Dylan" ) ;
assertThat ( result . size ( ) , is ( 3 ) ) ;
assertThat ( result . size ( ) , is ( 3 ) ) ;
}
}
@ -946,8 +947,8 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
@Test
@Test
public void shouldNotLimitPagedQueryWhenPageRequestWithinBounds ( ) {
public void shouldNotLimitPagedQueryWhenPageRequestWithinBounds ( ) {
repository . save ( Arrays . asList ( new Person ( "Bob-1" , "Dylan" ) , new Person ( "Bob-2" , "Dylan" ) , new Person ( "Bob-3" ,
repository . save ( Arrays . asList ( new Person ( "Bob-1" , "Dylan" ) , new Person ( "Bob-2" , "Dylan" ) ,
"Dylan" ) , new Person ( "Bob-4" , "Dylan" ) , new Person ( "Bob-5" , "Dylan" ) ) ) ;
new Person ( "Bob-3" , "Dylan" ) , new Person ( "Bob-4" , "Dylan" ) , new Person ( "Bob-5" , "Dylan" ) ) ) ;
Page < Person > result = repository . findTop3ByLastnameStartingWith ( "Dylan" , new PageRequest ( 0 , 2 ) ) ;
Page < Person > result = repository . findTop3ByLastnameStartingWith ( "Dylan" , new PageRequest ( 0 , 2 ) ) ;
assertThat ( result . getContent ( ) . size ( ) , is ( 2 ) ) ;
assertThat ( result . getContent ( ) . size ( ) , is ( 2 ) ) ;
}
}
@ -958,8 +959,8 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
@Test
@Test
public void shouldLimitPagedQueryWhenPageRequestExceedsUpperBoundary ( ) {
public void shouldLimitPagedQueryWhenPageRequestExceedsUpperBoundary ( ) {
repository . save ( Arrays . asList ( new Person ( "Bob-1" , "Dylan" ) , new Person ( "Bob-2" , "Dylan" ) , new Person ( "Bob-3" ,
repository . save ( Arrays . asList ( new Person ( "Bob-1" , "Dylan" ) , new Person ( "Bob-2" , "Dylan" ) ,
"Dylan" ) , new Person ( "Bob-4" , "Dylan" ) , new Person ( "Bob-5" , "Dylan" ) ) ) ;
new Person ( "Bob-3" , "Dylan" ) , new Person ( "Bob-4" , "Dylan" ) , new Person ( "Bob-5" , "Dylan" ) ) ) ;
Page < Person > result = repository . findTop3ByLastnameStartingWith ( "Dylan" , new PageRequest ( 1 , 2 ) ) ;
Page < Person > result = repository . findTop3ByLastnameStartingWith ( "Dylan" , new PageRequest ( 1 , 2 ) ) ;
assertThat ( result . getContent ( ) . size ( ) , is ( 1 ) ) ;
assertThat ( result . getContent ( ) . size ( ) , is ( 1 ) ) ;
}
}
@ -970,8 +971,8 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
@Test
@Test
public void shouldReturnEmptyWhenPageRequestedPageIsTotallyOutOfScopeForLimit ( ) {
public void shouldReturnEmptyWhenPageRequestedPageIsTotallyOutOfScopeForLimit ( ) {
repository . save ( Arrays . asList ( new Person ( "Bob-1" , "Dylan" ) , new Person ( "Bob-2" , "Dylan" ) , new Person ( "Bob-3" ,
repository . save ( Arrays . asList ( new Person ( "Bob-1" , "Dylan" ) , new Person ( "Bob-2" , "Dylan" ) ,
"Dylan" ) , new Person ( "Bob-4" , "Dylan" ) , new Person ( "Bob-5" , "Dylan" ) ) ) ;
new Person ( "Bob-3" , "Dylan" ) , new Person ( "Bob-4" , "Dylan" ) , new Person ( "Bob-5" , "Dylan" ) ) ) ;
Page < Person > result = repository . findTop3ByLastnameStartingWith ( "Dylan" , new PageRequest ( 2 , 2 ) ) ;
Page < Person > result = repository . findTop3ByLastnameStartingWith ( "Dylan" , new PageRequest ( 2 , 2 ) ) ;
assertThat ( result . getContent ( ) . size ( ) , is ( 0 ) ) ;
assertThat ( result . getContent ( ) . size ( ) , is ( 0 ) ) ;
}
}
@ -1183,4 +1184,41 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
GeoResults < Person > results = repository . findPersonByLocationNear ( new Point ( - 73 . 99 , 40 . 73 ) , range ) ;
GeoResults < Person > results = repository . findPersonByLocationNear ( new Point ( - 73 . 99 , 40 . 73 ) , range ) ;
assertThat ( results . getContent ( ) . isEmpty ( ) , is ( false ) ) ;
assertThat ( results . getContent ( ) . isEmpty ( ) , is ( false ) ) ;
}
}
/ * *
* @see DATAMONGO - 990
* /
@Test
public void shouldFindByFirstnameForSpELExpressionWithParameterIndexOnly ( ) {
List < Person > users = repository . findWithSpelByFirstnameForSpELExpressionWithParameterIndexOnly ( "Dave" ) ;
assertThat ( users , hasSize ( 1 ) ) ;
assertThat ( users . get ( 0 ) , is ( dave ) ) ;
}
/ * *
* @see DATAMONGO - 990
* /
@Test
public void shouldFindByFirstnameAndCurrentUserWithCustomQuery ( ) {
SampleSecurityContextHolder . getCurrent ( ) . setPrincipal ( dave ) ;
List < Person > users = repository . findWithSpelByFirstnameAndCurrentUserWithCustomQuery ( "Dave" ) ;
assertThat ( users , hasSize ( 1 ) ) ;
assertThat ( users . get ( 0 ) , is ( dave ) ) ;
}
/ * *
* @see DATAMONGO - 990
* /
@Test
public void shouldFindByFirstnameForSpELExpressionWithParameterVariableOnly ( ) {
List < Person > users = repository . findWithSpelByFirstnameForSpELExpressionWithParameterVariableOnly ( "Dave" ) ;
assertThat ( users , hasSize ( 1 ) ) ;
assertThat ( users . get ( 0 ) , is ( dave ) ) ;
}
}
}