22
22
import java .util .Collections ;
23
23
24
24
import org .junit .Test ;
25
-
26
25
import org .springframework .data .domain .Sort ;
27
26
import org .springframework .data .r2dbc .convert .MappingR2dbcConverter ;
28
27
import org .springframework .data .r2dbc .convert .R2dbcConverter ;
43
42
*/
44
43
public class QueryMapperUnitTests {
45
44
46
- R2dbcConverter converter = new MappingR2dbcConverter (new R2dbcMappingContext ());
45
+ R2dbcMappingContext context = new R2dbcMappingContext ();
46
+ R2dbcConverter converter = new MappingR2dbcConverter (context );
47
+
47
48
QueryMapper mapper = new QueryMapper (PostgresDialect .INSTANCE , converter );
48
49
BindTarget bindTarget = mock (BindTarget .class );
49
50
@@ -90,8 +91,13 @@ public void shouldMapNestedGroup() {
90
91
91
92
Criteria initial = Criteria .empty ();
92
93
93
- Criteria criteria = initial .and (Criteria .where ("name" ).is ("Foo" )).and (Criteria .where ("name" ).is ("Bar" ).or ("age" )
94
- .lessThan (49 ).or (Criteria .where ("name" ).not ("Bar" ).and ("age" ).greaterThan (49 )));
94
+ Criteria criteria = initial .and (Criteria .where ("name" ).is ("Foo" )) //
95
+ .and (Criteria .where ("name" ).is ("Bar" ) //
96
+ .or ("age" ).lessThan (49 ) //
97
+ .or (Criteria .where ("name" ).not ("Bar" ) //
98
+ .and ("age" ).greaterThan (49 ) //
99
+ ) //
100
+ );
95
101
96
102
assertThat (criteria .isEmpty ()).isFalse ();
97
103
@@ -104,8 +110,10 @@ public void shouldMapNestedGroup() {
104
110
@ Test // gh-289
105
111
public void shouldMapFrom () {
106
112
107
- Criteria criteria = Criteria .from (Criteria .where ("name" ).is ("Foo" ))
108
- .and (Criteria .where ("name" ).is ("Bar" ).or ("age" ).lessThan (49 ));
113
+ Criteria criteria = Criteria .from (Criteria .where ("name" ).is ("Foo" )) //
114
+ .and (Criteria .where ("name" ).is ("Bar" ) //
115
+ .or ("age" ).lessThan (49 ) //
116
+ );
109
117
110
118
assertThat (criteria .isEmpty ()).isFalse ();
111
119
@@ -149,7 +157,7 @@ public void shouldMapExpression() {
149
157
Table table = Table .create ("my_table" ).as ("my_aliased_table" );
150
158
151
159
Expression mappedObject = mapper .getMappedObject (table .column ("alternative" ).as ("my_aliased_col" ),
152
- converter . getMappingContext () .getRequiredPersistentEntity (Person .class ));
160
+ context .getRequiredPersistentEntity (Person .class ));
153
161
154
162
assertThat (mappedObject ).hasToString ("my_aliased_table.another_name AS my_aliased_col" );
155
163
}
@@ -160,7 +168,7 @@ public void shouldMapCountFunction() {
160
168
Table table = Table .create ("my_table" ).as ("my_aliased_table" );
161
169
162
170
Expression mappedObject = mapper .getMappedObject (Functions .count (table .column ("alternative" )),
163
- converter . getMappingContext () .getRequiredPersistentEntity (Person .class ));
171
+ context .getRequiredPersistentEntity (Person .class ));
164
172
165
173
assertThat (mappedObject ).hasToString ("COUNT(my_aliased_table.another_name)" );
166
174
}
@@ -171,7 +179,7 @@ public void shouldMapExpressionToUnknownColumn() {
171
179
Table table = Table .create ("my_table" ).as ("my_aliased_table" );
172
180
173
181
Expression mappedObject = mapper .getMappedObject (table .column ("unknown" ).as ("my_aliased_col" ),
174
- converter . getMappingContext () .getRequiredPersistentEntity (Person .class ));
182
+ context .getRequiredPersistentEntity (Person .class ));
175
183
176
184
assertThat (mappedObject ).hasToString ("my_aliased_table.unknown AS my_aliased_col" );
177
185
}
@@ -352,7 +360,7 @@ public void shouldMapSort() {
352
360
353
361
Sort sort = Sort .by (desc ("alternative" ));
354
362
355
- Sort mapped = mapper .getMappedObject (sort , converter . getMappingContext () .getRequiredPersistentEntity (Person .class ));
363
+ Sort mapped = mapper .getMappedObject (sort , context .getRequiredPersistentEntity (Person .class ));
356
364
357
365
assertThat (mapped .getOrderFor ("another_name" )).isEqualTo (desc ("another_name" ));
358
366
assertThat (mapped .getOrderFor ("alternative" )).isNull ();
@@ -363,7 +371,7 @@ private BoundCondition map(Criteria criteria) {
363
371
BindMarkersFactory markers = BindMarkersFactory .indexed ("$" , 1 );
364
372
365
373
return mapper .getMappedObject (markers .create (), criteria , Table .create ("person" ),
366
- converter . getMappingContext () .getRequiredPersistentEntity (Person .class ));
374
+ context .getRequiredPersistentEntity (Person .class ));
367
375
}
368
376
369
377
static class Person {
0 commit comments