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