1717
1818import static org .assertj .core .api .Assertions .*;
1919import static org .mockito .Mockito .*;
20+ import static org .springframework .data .relational .core .query .Criteria .*;
2021
2122import io .r2dbc .spi .R2dbcType ;
2223import io .r2dbc .spi .test .MockColumnMetadata ;
@@ -87,8 +88,6 @@ void before() {
8788 @ Test // gh-220
8889 void shouldCountBy () {
8990
90- MockRowMetadata metadata = MockRowMetadata .builder ()
91- .columnMetadata (MockColumnMetadata .builder ().name ("name" ).type (R2dbcType .VARCHAR ).build ()).build ();
9291 MockResult result = MockResult .builder ().row (MockRow .builder ().identified (0 , Long .class , 1L ).build ()).build ();
9392
9493 recorder .addStubbing (s -> s .startsWith ("SELECT" ), result );
@@ -104,11 +103,29 @@ void shouldCountBy() {
104103 assertThat (statement .getBindings ()).hasSize (1 ).containsEntry (0 , Parameter .from ("Walter" ));
105104 }
106105
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+
107126 @ Test // gh-469
108127 void shouldProjectExistsResult () {
109128
110- MockRowMetadata metadata = MockRowMetadata .builder ()
111- .columnMetadata (MockColumnMetadata .builder ().name ("name" ).type (R2dbcType .VARCHAR ).build ()).build ();
112129 MockResult result = MockResult .builder ().row (MockRow .builder ().identified (0 , Object .class , null ).build ()).build ();
113130
114131 recorder .addStubbing (s -> s .startsWith ("SELECT" ), result );
@@ -271,7 +288,7 @@ void shouldDeleteByQuery() {
271288
272289 recorder .addStubbing (s -> s .startsWith ("DELETE" ), result );
273290
274- entityTemplate .delete (Query .query (Criteria . where ("name" ).is ("Walter" )), Person .class ) //
291+ entityTemplate .delete (Query .query (where ("name" ).is ("Walter" )), Person .class ) //
275292 .as (StepVerifier ::create ) //
276293 .expectNext (1L ) //
277294 .verifyComplete ();
@@ -564,6 +581,11 @@ public Person withDescription(String description) {
564581 }
565582 }
566583
584+ interface PersonProjection {
585+
586+ String getName ();
587+ }
588+
567589 record VersionedPerson (@ Id String id , @ Version long version , String name ) {
568590
569591 public VersionedPerson withId (String id ) {
0 commit comments