|
39 | 39 | import java.util.stream.Collectors;
|
40 | 40 | import java.util.stream.IntStream;
|
41 | 41 |
|
42 |
| -import org.bson.Document; |
43 | 42 | import org.bson.types.ObjectId;
|
44 | 43 | import org.joda.time.DateTime;
|
45 | 44 | import org.junit.jupiter.api.AfterEach;
|
46 | 45 | import org.junit.jupiter.api.Test;
|
47 | 46 | import org.junit.jupiter.api.extension.ExtendWith;
|
48 |
| - |
49 | 47 | import org.springframework.context.ConfigurableApplicationContext;
|
50 | 48 | import org.springframework.context.support.GenericApplicationContext;
|
51 | 49 | import org.springframework.core.convert.converter.Converter;
|
|
67 | 65 | import org.springframework.data.mongodb.MongoDatabaseFactory;
|
68 | 66 | import org.springframework.data.mongodb.core.BulkOperations.BulkMode;
|
69 | 67 | import org.springframework.data.mongodb.core.convert.LazyLoadingProxy;
|
| 68 | +import org.springframework.data.mongodb.core.convert.MongoCustomConversions; |
| 69 | +import org.springframework.data.mongodb.core.convert.MongoCustomConversions.MongoConverterConfigurationAdapter; |
70 | 70 | import org.springframework.data.mongodb.core.geo.GeoJsonPoint;
|
71 | 71 | import org.springframework.data.mongodb.core.index.Index;
|
72 | 72 | import org.springframework.data.mongodb.core.index.IndexField;
|
@@ -1787,6 +1787,30 @@ public void findsEntityByDateReference() {
|
1787 | 1787 | assertThat(result.get(0).date).isNotNull();
|
1788 | 1788 | }
|
1789 | 1789 |
|
| 1790 | + @Test // GH-4390 |
| 1791 | + void nativeDriverDateTimeCodecShouldBeApplied/*when configured*/() { |
| 1792 | + |
| 1793 | + MongoTestTemplate ops = new MongoTestTemplate(cfg -> { |
| 1794 | + cfg.configureConversion(conversion -> { |
| 1795 | + conversion.customConversions( |
| 1796 | + MongoCustomConversions.create(MongoConverterConfigurationAdapter::useNativeDriverJavaTimeCodecs)); |
| 1797 | + }); |
| 1798 | + }); |
| 1799 | + |
| 1800 | + TypeWithDate source = new TypeWithDate(); |
| 1801 | + source.id = "id-1"; |
| 1802 | + source.date = Date.from(Instant.now()); |
| 1803 | + |
| 1804 | + ops.save(source); |
| 1805 | + |
| 1806 | + Object dbDate = ops.execute(TypeWithDate.class, |
| 1807 | + collection -> collection.find(new org.bson.Document("_id", source.id)).first().get("date")); |
| 1808 | + |
| 1809 | + TypeWithDate target = ops.findOne(query(where("date").is(source.date)), TypeWithDate.class); |
| 1810 | + |
| 1811 | + assertThat(target.date).isEqualTo(source.date).isEqualTo(dbDate); |
| 1812 | + } |
| 1813 | + |
1790 | 1814 | @Test // DATAMONGO-540
|
1791 | 1815 | public void findOneAfterUpsertForNonExistingObjectReturnsTheInsertedObject() {
|
1792 | 1816 |
|
|
0 commit comments