|
1 | 1 | /*
|
2 |
| - * Copyright 2014-2015 the original author or authors. |
| 2 | + * Copyright 2014-2016 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
21 | 21 | import static org.springframework.data.mongodb.core.query.IsTextQuery.*;
|
22 | 22 |
|
23 | 23 | import java.lang.reflect.Method;
|
| 24 | +import java.util.List; |
24 | 25 |
|
25 | 26 | import org.junit.Before;
|
26 | 27 | import org.junit.Rule;
|
|
40 | 41 | import org.springframework.data.mongodb.core.query.TextCriteria;
|
41 | 42 | import org.springframework.data.mongodb.repository.MongoRepository;
|
42 | 43 | import org.springframework.data.mongodb.repository.Person;
|
| 44 | +import org.springframework.data.mongodb.repository.Person.Sex; |
43 | 45 | import org.springframework.data.mongodb.repository.Query;
|
44 | 46 | import org.springframework.data.projection.ProjectionFactory;
|
45 | 47 | import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
|
@@ -192,6 +194,18 @@ public void usesDynamicProjection() {
|
192 | 194 | assertThat(fields.get("age"), is((Object) 1));
|
193 | 195 | }
|
194 | 196 |
|
| 197 | + /** |
| 198 | + * @see DATAMONGO-1500 |
| 199 | + */ |
| 200 | + @Test |
| 201 | + public void shouldLeaveParameterConversionToQueryMapper() { |
| 202 | + |
| 203 | + org.springframework.data.mongodb.core.query.Query query = deriveQueryFromMethod("findBySex", Sex.FEMALE); |
| 204 | + |
| 205 | + assertThat(query.getQueryObject().get("sex"), is((Object) Sex.FEMALE)); |
| 206 | + assertThat(query.getFieldsObject().get("firstname"), is((Object) 1)); |
| 207 | + } |
| 208 | + |
195 | 209 | private org.springframework.data.mongodb.core.query.Query deriveQueryFromMethod(String method, Object... args) {
|
196 | 210 |
|
197 | 211 | Class<?>[] types = new Class<?>[args.length];
|
@@ -249,6 +263,9 @@ interface Repo extends MongoRepository<Person, Long> {
|
249 | 263 | PersonDto findPersonDtoByAge(Integer age);
|
250 | 264 |
|
251 | 265 | <T> T findDynamicallyProjectedBy(Class<T> type);
|
| 266 | + |
| 267 | + @Query(fields = "{ 'firstname' : 1 }") |
| 268 | + List<Person> findBySex(Sex sex); |
252 | 269 | }
|
253 | 270 |
|
254 | 271 | interface PersonProjection {
|
|
0 commit comments