17
17
18
18
import static org .assertj .core .api .Assertions .*;
19
19
import static org .mockito .Mockito .*;
20
+ import static org .springframework .data .relational .core .query .Criteria .*;
20
21
21
22
import io .r2dbc .spi .R2dbcType ;
22
23
import io .r2dbc .spi .test .MockColumnMetadata ;
@@ -87,8 +88,6 @@ void before() {
87
88
@ Test // gh-220
88
89
void shouldCountBy () {
89
90
90
- MockRowMetadata metadata = MockRowMetadata .builder ()
91
- .columnMetadata (MockColumnMetadata .builder ().name ("name" ).type (R2dbcType .VARCHAR ).build ()).build ();
92
91
MockResult result = MockResult .builder ().row (MockRow .builder ().identified (0 , Long .class , 1L ).build ()).build ();
93
92
94
93
recorder .addStubbing (s -> s .startsWith ("SELECT" ), result );
@@ -104,11 +103,28 @@ void shouldCountBy() {
104
103
assertThat (statement .getBindings ()).hasSize (1 ).containsEntry (0 , Parameter .from ("Walter" ));
105
104
}
106
105
106
+ @ Test // GH-1690
107
+ void shouldApplyInterfaceProjection () {
108
+
109
+ MockRowMetadata metadata = MockRowMetadata .builder ()
110
+ .columnMetadata (MockColumnMetadata .builder ().name ("THE_NAME" ).type (R2dbcType .VARCHAR ).build ()).build ();
111
+ MockResult result = MockResult .builder ()
112
+ .row (MockRow .builder ().identified ("THE_NAME" , Object .class , "Walter" ).metadata (metadata ).build ()).build ();
113
+
114
+ recorder .addStubbing (s -> s .startsWith ("SELECT" ), result );
115
+
116
+ entityTemplate .select (Person .class ) //
117
+ .from ("foo" ) //
118
+ .as (PersonProjection .class ) //
119
+ .matching (Query .query (Criteria .where ("name" ).is ("Walter" ))) //
120
+ .all () //
121
+ .as (StepVerifier ::create ) //
122
+ .assertNext (actual -> assertThat (actual .getName ()).isEqualTo ("Walter" )).verifyComplete ();
123
+ }
124
+
107
125
@ Test // gh-469
108
126
void shouldProjectExistsResult () {
109
127
110
- MockRowMetadata metadata = MockRowMetadata .builder ()
111
- .columnMetadata (MockColumnMetadata .builder ().name ("name" ).type (R2dbcType .VARCHAR ).build ()).build ();
112
128
MockResult result = MockResult .builder ().row (MockRow .builder ().identified (0 , Object .class , null ).build ()).build ();
113
129
114
130
recorder .addStubbing (s -> s .startsWith ("SELECT" ), result );
@@ -271,7 +287,7 @@ void shouldDeleteByQuery() {
271
287
272
288
recorder .addStubbing (s -> s .startsWith ("DELETE" ), result );
273
289
274
- entityTemplate .delete (Query .query (Criteria . where ("name" ).is ("Walter" )), Person .class ) //
290
+ entityTemplate .delete (Query .query (where ("name" ).is ("Walter" )), Person .class ) //
275
291
.as (StepVerifier ::create ) //
276
292
.expectNext (1L ) //
277
293
.verifyComplete ();
@@ -564,6 +580,11 @@ public Person withDescription(String description) {
564
580
}
565
581
}
566
582
583
+ interface PersonProjection {
584
+
585
+ String getName ();
586
+ }
587
+
567
588
record VersionedPerson (@ Id String id , @ Version long version , String name ) {
568
589
569
590
public VersionedPerson withId (String id ) {
0 commit comments