2424import org .springframework .beans .factory .annotation .Autowired ;
2525import org .springframework .context .annotation .Bean ;
2626import org .springframework .context .annotation .Configuration ;
27+ import org .springframework .data .domain .Page ;
2728import org .springframework .data .domain .PageRequest ;
2829import org .springframework .data .domain .Sort ;
2930import org .springframework .data .neo4j .config .AbstractNeo4jConfig ;
3031import org .springframework .data .neo4j .integration .shared .common .Person ;
31- // tag::sdn-mixins.dynamic-conditions.add-mixin[]
3232import org .springframework .data .neo4j .repository .Neo4jRepository ;
33- // end::sdn-mixins.dynamic-conditions.add-mixin[]
3433import org .springframework .data .neo4j .repository .config .EnableNeo4jRepositories ;
3534import org .springframework .data .neo4j .test .Neo4jExtension ;
3635import org .springframework .data .neo4j .test .Neo4jIntegrationTest ;
37- // tag::sdn-mixins.dynamic-conditions.add-mixin[]
3836import org .springframework .data .querydsl .QuerydslPredicateExecutor ;
39-
40- // end::sdn-mixins.dynamic-conditions.add-mixin[]
4137import org .springframework .transaction .annotation .EnableTransactionManagement ;
4238
4339import com .querydsl .core .types .Ops ;
@@ -70,7 +66,8 @@ protected static void setupData() {
7066 transaction .run ("MATCH (n) detach delete n" );
7167 transaction .run ("CREATE (p:Person{firstName: 'A', lastName: 'LA'})" );
7268 transaction .run ("CREATE (p:Person{firstName: 'B', lastName: 'LB'})" );
73- transaction .run ("CREATE (p:Person{firstName: 'Helge', lastName: 'Schneider'}) -[:LIVES_AT]-> (a:Address {city: 'Mülheim an der Ruhr'})" );
69+ transaction
70+ .run ("CREATE (p:Person{firstName: 'Helge', lastName: 'Schneider'}) -[:LIVES_AT]-> (a:Address {city: 'Mülheim an der Ruhr'})" );
7471 transaction .run ("CREATE (p:Person{firstName: 'Bela', lastName: 'B.'})" );
7572 transaction .commit ();
7673 }
@@ -127,13 +124,33 @@ void orderedFindAllWithoutPredicateShouldWork(@Autowired QueryDSLPersonRepositor
127124 @ Test
128125 void pagedFindAllShouldWork (@ Autowired QueryDSLPersonRepository repository ) {
129126
130- assertThat (
131- repository .findAll (Expressions .predicate (Ops .EQ , firstName , Expressions .asString ("Helge" ))
132- .or (Expressions .predicate (Ops .EQ , lastName , Expressions .asString ("B." ))),
133- PageRequest .of (1 , 1 , Sort .by ("lastName" ).descending ())
134- ))
127+ Page <Person > people = repository .findAll (Expressions .predicate (Ops .EQ , firstName , Expressions .asString ("Helge" ))
128+ .or (Expressions .predicate (Ops .EQ , lastName , Expressions .asString ("B." ))),
129+ PageRequest .of (1 , 1 , Sort .by ("lastName" ).descending ())
130+ );
131+
132+ assertThat (people .hasPrevious ()).isTrue ();
133+ assertThat (people .hasNext ()).isFalse ();
134+ assertThat (people .getTotalElements ()).isEqualTo (2 );
135+ assertThat (people )
135136 .extracting (Person ::getFirstName )
136- .containsExactly ("B" );
137+ .containsExactly ("Bela" );
138+ }
139+
140+ @ Test // GH-2194
141+ void pagedFindAllShouldWork2 (@ Autowired QueryDSLPersonRepository repository ) {
142+
143+ Page <Person > people = repository .findAll (Expressions .predicate (Ops .EQ , firstName , Expressions .asString ("Helge" ))
144+ .or (Expressions .predicate (Ops .EQ , lastName , Expressions .asString ("B." ))),
145+ PageRequest .of (0 , 20 , Sort .by ("lastName" ).descending ())
146+ );
147+
148+ assertThat (people .hasPrevious ()).isFalse ();
149+ assertThat (people .hasNext ()).isFalse ();
150+ assertThat (people .getTotalElements ()).isEqualTo (2 );
151+ assertThat (people )
152+ .extracting (Person ::getFirstName )
153+ .containsExactly ("Helge" , "Bela" );
137154 }
138155
139156 @ Test
@@ -160,7 +177,6 @@ interface QueryDSLPersonRepository extends
160177 }
161178 // end::sdn-mixins.dynamic-conditions.add-mixin[]
162179
163-
164180 @ Configuration
165181 @ EnableTransactionManagement
166182 @ EnableNeo4jRepositories (considerNestedRepositories = true )
0 commit comments