|
42 | 42 | import org.springframework.dao.InvalidDataAccessApiUsageException;
|
43 | 43 | import org.springframework.data.annotation.Id;
|
44 | 44 | import org.springframework.data.annotation.Version;
|
| 45 | +import org.springframework.data.domain.Sort; |
45 | 46 | import org.springframework.data.mongodb.MongoDbFactory;
|
46 | 47 | import org.springframework.data.mongodb.core.convert.CustomConversions;
|
47 | 48 | import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver;
|
|
50 | 51 | import org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexCreator;
|
51 | 52 | import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
52 | 53 | import org.springframework.data.mongodb.core.query.BasicQuery;
|
| 54 | +import org.springframework.data.mongodb.core.query.Criteria; |
53 | 55 | import org.springframework.data.mongodb.core.query.Query;
|
54 | 56 | import org.springframework.data.mongodb.core.query.Update;
|
55 | 57 | import org.springframework.test.util.ReflectionTestUtils;
|
56 | 58 |
|
57 | 59 | import com.mongodb.BasicDBObject;
|
| 60 | +import com.mongodb.BasicDBObjectBuilder; |
58 | 61 | import com.mongodb.DB;
|
59 | 62 | import com.mongodb.DBCollection;
|
60 | 63 | import com.mongodb.DBCursor;
|
@@ -329,6 +332,26 @@ public void findAllAndRemoveShouldNotTriggerRemoveIfFindResultIsEmpty() {
|
329 | 332 | verify(collection, never()).remove(Mockito.any(DBObject.class));
|
330 | 333 | }
|
331 | 334 |
|
| 335 | + /** |
| 336 | + * @see DATAMONGO-948 |
| 337 | + */ |
| 338 | + @Test |
| 339 | + public void sortShouldBeTakenAsIsWhenExecutingQueryWithoutSpecificTypeInformation() { |
| 340 | + |
| 341 | + Query query = Query.query(Criteria.where("foo").is("bar")).with(new Sort("foo")); |
| 342 | + template.executeQuery(query, "collection1", new DocumentCallbackHandler() { |
| 343 | + |
| 344 | + @Override |
| 345 | + public void processDocument(DBObject dbObject) throws MongoException, DataAccessException { |
| 346 | + // nothing to do - just a test |
| 347 | + } |
| 348 | + }); |
| 349 | + |
| 350 | + ArgumentCaptor<DBObject> captor = ArgumentCaptor.forClass(DBObject.class); |
| 351 | + verify(cursor, times(1)).sort(captor.capture()); |
| 352 | + assertThat(captor.getValue(), equalTo(new BasicDBObjectBuilder().add("foo", 1).get())); |
| 353 | + } |
| 354 | + |
332 | 355 | class AutogenerateableId {
|
333 | 356 |
|
334 | 357 | @Id BigInteger id;
|
|
0 commit comments