|
34 | 34 |
|
35 | 35 | import org.springframework.context.ApplicationContext;
|
36 | 36 | import org.springframework.core.annotation.AliasFor;
|
| 37 | +import org.springframework.core.env.Environment; |
37 | 38 | import org.springframework.core.env.StandardEnvironment;
|
38 | 39 | import org.springframework.data.mapping.MappingException;
|
39 | 40 | import org.springframework.data.mongodb.core.query.Collation;
|
40 | 41 | import org.springframework.data.spel.ExtensionAwareEvaluationContextProvider;
|
41 | 42 | import org.springframework.data.spel.spi.EvaluationContextExtension;
|
42 | 43 | import org.springframework.data.util.TypeInformation;
|
| 44 | +import org.springframework.mock.env.MockEnvironment; |
43 | 45 |
|
44 | 46 | /**
|
45 | 47 | * Unit tests for {@link BasicMongoPersistentEntity}.
|
@@ -87,6 +89,19 @@ void collectionAllowsReferencingSpringBean() {
|
87 | 89 | assertThat(entity.getCollection()).isEqualTo("otherReference");
|
88 | 90 | }
|
89 | 91 |
|
| 92 | + @Test // GH-2764 |
| 93 | + void collectionAllowsReferencingProperties() { |
| 94 | + |
| 95 | + MockEnvironment environment = new MockEnvironment(); |
| 96 | + environment.setProperty("collectionName", "reference"); |
| 97 | + |
| 98 | + BasicMongoPersistentEntity<DynamicallyMappedUsingPropertyPlaceholder> entity = new BasicMongoPersistentEntity<>( |
| 99 | + TypeInformation.of(DynamicallyMappedUsingPropertyPlaceholder.class)); |
| 100 | + entity.setEnvironment(environment); |
| 101 | + |
| 102 | + assertThat(entity.getCollection()).isEqualTo("reference_cat"); |
| 103 | + } |
| 104 | + |
90 | 105 | @Test // DATAMONGO-937
|
91 | 106 | void shouldDetectLanguageCorrectly() {
|
92 | 107 |
|
@@ -325,6 +340,9 @@ class Company {}
|
325 | 340 | @Document("#{@myBean.collectionName}")
|
326 | 341 | class DynamicallyMapped {}
|
327 | 342 |
|
| 343 | + @Document("${collectionName}_cat") |
| 344 | + class DynamicallyMappedUsingPropertyPlaceholder {} |
| 345 | + |
328 | 346 | class CollectionProvider {
|
329 | 347 | String collectionName;
|
330 | 348 |
|
|
0 commit comments