@@ -93,6 +93,27 @@ void shouldApplyPageableParameterToCollectionQuery() throws SecurityException, N
93
93
assertThat (query .getRows ()).isEqualTo (3 );
94
94
}
95
95
96
+ @ Test // GH-563
97
+ @ SuppressWarnings ({ "unchecked" , "rawtypes" })
98
+ void shouldAllowProjectionQueries () throws SecurityException , NoSuchMethodException {
99
+
100
+ when (metadataMock .getDomainType ()).thenReturn ((Class ) Person .class );
101
+ when (metadataMock .getDomainTypeInformation ()).thenReturn ((TypeInformation ) TypeInformation .of (Person .class ));
102
+ when (metadataMock .getReturnType (any (Method .class ))).thenReturn ((TypeInformation ) TypeInformation .of (List .class ));
103
+ when (metadataMock .getReturnedDomainClass (any (Method .class ))).thenReturn ((Class ) Person .class );
104
+
105
+ QueryMethod qm = new QueryMethod (Repo .class .getMethod ("findProjectionByFirstname" ,String .class ), metadataMock ,
106
+ projectionFactoryMock );
107
+
108
+ KeyValuePartTreeQuery partTreeQuery = new KeyValuePartTreeQuery (qm , QueryMethodEvaluationContextProvider .DEFAULT ,
109
+ kvOpsMock , SpelQueryCreator .class );
110
+
111
+ KeyValueQuery <?> query = partTreeQuery .prepareQuery (new Object [] { "firstname" });
112
+ partTreeQuery .doExecute (new Object [] { "firstname" }, query );
113
+
114
+ verify (kvOpsMock ).find (eq (query ), eq (Person .class ));
115
+ }
116
+
96
117
@ Test // DATAKV-142
97
118
@ SuppressWarnings ({ "unchecked" , "rawtypes" })
98
119
void shouldApplyDerivedMaxResultsToQuery () throws SecurityException , NoSuchMethodException {
@@ -166,5 +187,11 @@ interface Repo {
166
187
List <Person > findTop3By ();
167
188
168
189
List <Person > findTop3ByFirstname (String firstname );
190
+
191
+ PersonProjection findProjectionByFirstname (String firstname );
192
+ }
193
+
194
+ interface PersonProjection {
195
+ String getFirstname ();
169
196
}
170
197
}
0 commit comments