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,29 @@ void shouldCountBy() {
104
103
assertThat (statement .getBindings ()).hasSize (1 ).containsEntry (0 , Parameter .from ("Walter" ));
105
104
}
106
105
106
+ @ Test
107
+ // GH-1690
108
+ void shouldApplyInterfaceProjection () {
109
+
110
+ MockRowMetadata metadata = MockRowMetadata .builder ()
111
+ .columnMetadata (MockColumnMetadata .builder ().name ("THE_NAME" ).type (R2dbcType .VARCHAR ).build ()).build ();
112
+ MockResult result = MockResult .builder ()
113
+ .row (MockRow .builder ().identified ("THE_NAME" , Object .class , "Walter" ).metadata (metadata ).build ()).build ();
114
+
115
+ recorder .addStubbing (s -> s .startsWith ("SELECT" ), result );
116
+
117
+ entityTemplate .select (Person .class ) //
118
+ .from ("foo" ) //
119
+ .as (PersonProjection .class ) //
120
+ .matching (Query .query (Criteria .where ("name" ).is ("Walter" ))) //
121
+ .all () //
122
+ .as (StepVerifier ::create ) //
123
+ .assertNext (actual -> assertThat (actual .getName ()).isEqualTo ("Walter" )).verifyComplete ();
124
+ }
125
+
107
126
@ Test // gh-469
108
127
void shouldProjectExistsResult () {
109
128
110
- MockRowMetadata metadata = MockRowMetadata .builder ()
111
- .columnMetadata (MockColumnMetadata .builder ().name ("name" ).type (R2dbcType .VARCHAR ).build ()).build ();
112
129
MockResult result = MockResult .builder ().row (MockRow .builder ().identified (0 , Object .class , null ).build ()).build ();
113
130
114
131
recorder .addStubbing (s -> s .startsWith ("SELECT" ), result );
@@ -271,7 +288,7 @@ void shouldDeleteByQuery() {
271
288
272
289
recorder .addStubbing (s -> s .startsWith ("DELETE" ), result );
273
290
274
- entityTemplate .delete (Query .query (Criteria . where ("name" ).is ("Walter" )), Person .class ) //
291
+ entityTemplate .delete (Query .query (where ("name" ).is ("Walter" )), Person .class ) //
275
292
.as (StepVerifier ::create ) //
276
293
.expectNext (1L ) //
277
294
.verifyComplete ();
@@ -564,6 +581,11 @@ public Person withDescription(String description) {
564
581
}
565
582
}
566
583
584
+ interface PersonProjection {
585
+
586
+ String getName ();
587
+ }
588
+
567
589
record VersionedPerson (@ Id String id , @ Version long version , String name ) {
568
590
569
591
public VersionedPerson withId (String id ) {
0 commit comments