2525import java .util .Collection ;
2626import java .util .Collections ;
2727import java .util .Date ;
28- import java .util .HashMap ;
2928import java .util .List ;
30- import java .util .Map ;
3129
3230import org .junit .Before ;
3331import org .junit .Test ;
3432import org .junit .runner .RunWith ;
3533import org .mockito .runners .MockitoJUnitRunner ;
34+ import org .springframework .core .convert .ConversionFailedException ;
3635import org .springframework .core .convert .ConversionService ;
3736import org .springframework .core .convert .support .GenericConversionService ;
3837import org .springframework .data .domain .Page ;
4443import org .springframework .data .repository .Repository ;
4544import org .springframework .data .repository .core .RepositoryMetadata ;
4645import org .springframework .data .repository .core .support .DefaultRepositoryMetadata ;
46+ import org .springframework .data .repository .query .Param ;
4747import org .springframework .data .repository .support .CrudRepositoryInvokerUnitTests .Person ;
4848import org .springframework .data .repository .support .CrudRepositoryInvokerUnitTests .PersonRepository ;
4949import org .springframework .data .repository .support .RepositoryInvocationTestUtils .VerifyingMethodInterceptor ;
5050import org .springframework .format .support .DefaultFormattingConversionService ;
51+ import org .springframework .util .LinkedMultiValueMap ;
52+ import org .springframework .util .MultiValueMap ;
5153
5254/**
5355 * Integration tests for {@link ReflectionRepositoryInvoker}.
@@ -155,8 +157,8 @@ public void invokesFindAllWithPageableCorrectly() throws Exception {
155157 @ Test
156158 public void invokesQueryMethod () throws Exception {
157159
158- HashMap <String , String [] > parameters = new HashMap <String , String [] >();
159- parameters .put ("firstName" , new String [] { "John" } );
160+ MultiValueMap <String , String > parameters = new LinkedMultiValueMap <String , String >();
161+ parameters .add ("firstName" , "John" );
160162
161163 Method method = PersonRepository .class .getMethod ("findByFirstName" , String .class , Pageable .class );
162164 PersonRepository repository = mock (PersonRepository .class );
@@ -170,8 +172,8 @@ public void invokesQueryMethod() throws Exception {
170172 @ Test
171173 public void considersFormattingAnnotationsOnQueryMethodParameters () throws Exception {
172174
173- Map <String , String [] > parameters = Collections . singletonMap ( "date" ,
174- new String [] { "2013-07-18T10:49:00.000+02:00" } );
175+ MultiValueMap <String , String > parameters = new LinkedMultiValueMap < String , String >();
176+ parameters . add ( "date" , "2013-07-18T10:49:00.000+02:00" );
175177
176178 Method method = PersonRepository .class .getMethod ("findByCreatedUsingISO8601Date" , Date .class , Pageable .class );
177179 PersonRepository repository = mock (PersonRepository .class );
@@ -247,7 +249,8 @@ public void translatesCollectionRequestParametersCorrectly() throws Exception {
247249
248250 for (String [] ids : Arrays .asList (new String [] { "1,2" }, new String [] { "1" , "2" })) {
249251
250- Map <String , String []> parameters = Collections .singletonMap ("ids" , ids );
252+ MultiValueMap <String , String > parameters = new LinkedMultiValueMap <String , String >();
253+ parameters .put ("ids" , Arrays .asList (ids ));
251254
252255 Method method = PersonRepository .class .getMethod ("findByIdIn" , Collection .class );
253256 PersonRepository repository = mock (PersonRepository .class );
@@ -256,6 +259,29 @@ public void translatesCollectionRequestParametersCorrectly() throws Exception {
256259 }
257260 }
258261
262+ /**
263+ * @see DATACMNS-700
264+ */
265+ @ Test
266+ public void failedParameterConversionCapturesContext () throws Exception {
267+
268+ RepositoryInvoker invoker = getInvokerFor (mock (SimpleRepository .class ));
269+
270+ MultiValueMap <String , Object > parameters = new LinkedMultiValueMap <String , Object >();
271+ parameters .add ("value" , "value" );
272+
273+ Method method = SimpleRepository .class .getMethod ("findByClass" , int .class );
274+
275+ try {
276+ invoker .invokeQueryMethod (method , parameters , null , null );
277+ } catch (QueryMethodParameterConversionException o_O ) {
278+
279+ assertThat (o_O .getParameter (), is (new MethodParameters (method ).getParameters ().get (0 )));
280+ assertThat (o_O .getSource (), is ((Object ) "value" ));
281+ assertThat (o_O .getCause (), is (instanceOf (ConversionFailedException .class )));
282+ }
283+ }
284+
259285 private static RepositoryInvoker getInvokerFor (Object repository ) {
260286
261287 RepositoryMetadata metadata = new DefaultRepositoryMetadata (repository .getClass ().getInterfaces ()[0 ]);
@@ -310,4 +336,9 @@ interface RepoWithDomainDeleteAndFindOne extends Repository<Domain, Long> {
310336
311337 void delete (Domain entity );
312338 }
339+
340+ interface SimpleRepository extends Repository <Domain , Long > {
341+
342+ Domain findByClass (@ Param ("value" ) int value );
343+ }
313344}
0 commit comments