2828
2929import org .junit .jupiter .api .Test ;
3030import org .junit .jupiter .api .extension .ExtendWith ;
31+ import org .junitpioneer .jupiter .SetSystemProperty ;
3132import org .mockito .Mock ;
3233import org .mockito .junit .jupiter .MockitoExtension ;
3334
3435import org .springframework .context .ApplicationContext ;
3536import org .springframework .core .annotation .AliasFor ;
37+ import org .springframework .core .env .StandardEnvironment ;
3638import org .springframework .data .mapping .MappingException ;
3739import org .springframework .data .mongodb .core .query .Collation ;
3840import org .springframework .data .spel .ExtensionAwareEvaluationContextProvider ;
3941import org .springframework .data .spel .spi .EvaluationContextExtension ;
40- import org .springframework .data .util .ClassTypeInformation ;
42+ import org .springframework .data .util .TypeInformation ;
4143
4244/**
4345 * Unit tests for {@link BasicMongoPersistentEntity}.
@@ -56,14 +58,14 @@ public class BasicMongoPersistentEntityUnitTests {
5658 void subclassInheritsAtDocumentAnnotation () {
5759
5860 BasicMongoPersistentEntity <Person > entity = new BasicMongoPersistentEntity <>(
59- ClassTypeInformation . from (Person .class ));
61+ TypeInformation . of (Person .class ));
6062 assertThat (entity .getCollection ()).isEqualTo ("contacts" );
6163 }
6264
6365 @ Test
6466 void evaluatesSpELExpression () {
6567
66- MongoPersistentEntity <Company > entity = new BasicMongoPersistentEntity <>(ClassTypeInformation . from (Company .class ));
68+ MongoPersistentEntity <Company > entity = new BasicMongoPersistentEntity <>(TypeInformation . of (Company .class ));
6769 assertThat (entity .getCollection ()).isEqualTo ("35" );
6870 }
6971
@@ -76,7 +78,7 @@ void collectionAllowsReferencingSpringBean() {
7678 when (context .getBean ("myBean" )).thenReturn (provider );
7779
7880 BasicMongoPersistentEntity <DynamicallyMapped > entity = new BasicMongoPersistentEntity <>(
79- ClassTypeInformation . from (DynamicallyMapped .class ));
81+ TypeInformation . of (DynamicallyMapped .class ));
8082 entity .setEvaluationContextProvider (new ExtensionAwareEvaluationContextProvider (context ));
8183
8284 assertThat (entity .getCollection ()).isEqualTo ("reference" );
@@ -89,7 +91,7 @@ void collectionAllowsReferencingSpringBean() {
8991 void shouldDetectLanguageCorrectly () {
9092
9193 BasicMongoPersistentEntity <DocumentWithLanguage > entity = new BasicMongoPersistentEntity <>(
92- ClassTypeInformation . from (DocumentWithLanguage .class ));
94+ TypeInformation . of (DocumentWithLanguage .class ));
9395
9496 assertThat (entity .getLanguage ()).isEqualTo ("spanish" );
9597 }
@@ -101,7 +103,7 @@ void verifyShouldThrowExceptionForInvalidTypeOfExplicitLanguageProperty() {
101103 doReturn (Number .class ).when (propertyMock ).getActualType ();
102104
103105 BasicMongoPersistentEntity <AnyDocument > entity = new BasicMongoPersistentEntity <>(
104- ClassTypeInformation . from (AnyDocument .class ));
106+ TypeInformation . of (AnyDocument .class ));
105107 entity .addPersistentProperty (propertyMock );
106108
107109 assertThatExceptionOfType (MappingException .class ).isThrownBy (entity ::verify );
@@ -114,7 +116,7 @@ void verifyShouldPassForStringAsExplicitLanguageProperty() {
114116 doReturn (String .class ).when (propertyMock ).getActualType ();
115117
116118 BasicMongoPersistentEntity <AnyDocument > entity = new BasicMongoPersistentEntity <>(
117- ClassTypeInformation . from (AnyDocument .class ));
119+ TypeInformation . of (AnyDocument .class ));
118120 entity .addPersistentProperty (propertyMock );
119121
120122 entity .verify ();
@@ -127,7 +129,7 @@ void verifyShouldPassForStringAsExplicitLanguageProperty() {
127129 void verifyShouldIgnoreNonExplicitLanguageProperty () {
128130
129131 BasicMongoPersistentEntity <AnyDocument > entity = new BasicMongoPersistentEntity <>(
130- ClassTypeInformation . from (AnyDocument .class ));
132+ TypeInformation . of (AnyDocument .class ));
131133 when (propertyMock .isExplicitLanguageProperty ()).thenReturn (false );
132134 entity .addPersistentProperty (propertyMock );
133135
@@ -149,7 +151,7 @@ void verifyShouldThrowErrorForLazyDBRefOnFinalClass() {
149151 doReturn (true ).when (dbRefMock ).lazy ();
150152
151153 BasicMongoPersistentEntity <AnyDocument > entity = new BasicMongoPersistentEntity <>(
152- ClassTypeInformation . from (AnyDocument .class ));
154+ TypeInformation . of (AnyDocument .class ));
153155 entity .addPersistentProperty (propertyMock );
154156
155157 assertThatExceptionOfType (MappingException .class ).isThrownBy (entity ::verify );
@@ -167,7 +169,7 @@ void verifyShouldThrowErrorForLazyDBRefArray() {
167169 doReturn (true ).when (dbRefMock ).lazy ();
168170
169171 BasicMongoPersistentEntity <AnyDocument > entity = new BasicMongoPersistentEntity <>(
170- ClassTypeInformation . from (AnyDocument .class ));
172+ TypeInformation . of (AnyDocument .class ));
171173 entity .addPersistentProperty (propertyMock );
172174
173175 assertThatExceptionOfType (MappingException .class ).isThrownBy (entity ::verify );
@@ -185,7 +187,7 @@ void verifyShouldPassForLazyDBRefOnNonArrayNonFinalClass() {
185187 doReturn (true ).when (dbRefMock ).lazy ();
186188
187189 BasicMongoPersistentEntity <AnyDocument > entity = new BasicMongoPersistentEntity <>(
188- ClassTypeInformation . from (AnyDocument .class ));
190+ TypeInformation . of (AnyDocument .class ));
189191 entity .addPersistentProperty (propertyMock );
190192 entity .verify ();
191193
@@ -203,7 +205,7 @@ void verifyShouldPassForNonLazyDBRefOnFinalClass() {
203205 doReturn (false ).when (dbRefMock ).lazy ();
204206
205207 BasicMongoPersistentEntity <AnyDocument > entity = new BasicMongoPersistentEntity <>(
206- ClassTypeInformation . from (AnyDocument .class ));
208+ TypeInformation . of (AnyDocument .class ));
207209 entity .addPersistentProperty (propertyMock );
208210 entity .verify ();
209211
@@ -214,7 +216,7 @@ void verifyShouldPassForNonLazyDBRefOnFinalClass() {
214216 void metaInformationShouldBeReadCorrectlyFromInheritedDocumentAnnotation () {
215217
216218 BasicMongoPersistentEntity <DocumentWithCustomAnnotation > entity = new BasicMongoPersistentEntity <>(
217- ClassTypeInformation . from (DocumentWithCustomAnnotation .class ));
219+ TypeInformation . of (DocumentWithCustomAnnotation .class ));
218220
219221 assertThat (entity .getCollection ()).isEqualTo ("collection-1" );
220222 }
@@ -223,7 +225,7 @@ void metaInformationShouldBeReadCorrectlyFromInheritedDocumentAnnotation() {
223225 void metaInformationShouldBeReadCorrectlyFromComposedDocumentAnnotation () {
224226
225227 BasicMongoPersistentEntity <DocumentWithComposedAnnotation > entity = new BasicMongoPersistentEntity <>(
226- ClassTypeInformation . from (DocumentWithComposedAnnotation .class ));
228+ TypeInformation . of (DocumentWithComposedAnnotation .class ));
227229
228230 assertThat (entity .getCollection ()).isEqualTo ("custom-collection" );
229231 }
@@ -232,18 +234,29 @@ void metaInformationShouldBeReadCorrectlyFromComposedDocumentAnnotation() {
232234 void usesEvaluationContextExtensionInDynamicDocumentName () {
233235
234236 BasicMongoPersistentEntity <MappedWithExtension > entity = new BasicMongoPersistentEntity <>(
235- ClassTypeInformation . from (MappedWithExtension .class ));
237+ TypeInformation . of (MappedWithExtension .class ));
236238 entity .setEvaluationContextProvider (
237239 new ExtensionAwareEvaluationContextProvider (Collections .singletonList (new SampleExtension ())));
238240
239241 assertThat (entity .getCollection ()).isEqualTo ("collectionName" );
240242 }
241243
244+ @ Test // GH-4634
245+ @ SetSystemProperty (key = "mongo.entity.collection" , value = "collectionName" )
246+ void readsCollectionNameFromSystemProperty () {
247+
248+ BasicMongoPersistentEntity <MappedWithExtensionPropertyPlaceholderStyle > entity = new BasicMongoPersistentEntity <>(
249+ TypeInformation .of (MappedWithExtensionPropertyPlaceholderStyle .class ));
250+ entity .setEnvironment (new StandardEnvironment ());
251+
252+ assertThat (entity .getCollection ()).isEqualTo ("collectionName" );
253+ }
254+
242255 @ Test // DATAMONGO-1854
243256 void readsSimpleCollation () {
244257
245258 BasicMongoPersistentEntity <WithSimpleCollation > entity = new BasicMongoPersistentEntity <>(
246- ClassTypeInformation . from (WithSimpleCollation .class ));
259+ TypeInformation . of (WithSimpleCollation .class ));
247260
248261 assertThat (entity .getCollation ()).isEqualTo (org .springframework .data .mongodb .core .query .Collation .of ("en_US" ));
249262 }
@@ -252,7 +265,7 @@ void readsSimpleCollation() {
252265 void readsDocumentCollation () {
253266
254267 BasicMongoPersistentEntity <WithDocumentCollation > entity = new BasicMongoPersistentEntity <>(
255- ClassTypeInformation . from (WithDocumentCollation .class ));
268+ TypeInformation . of (WithDocumentCollation .class ));
256269
257270 assertThat (entity .getCollation ()).isEqualTo (org .springframework .data .mongodb .core .query .Collation .of ("en_US" ));
258271 }
@@ -261,7 +274,7 @@ void readsDocumentCollation() {
261274 void usesCorrectExpressionsForCollectionAndCollation () {
262275
263276 BasicMongoPersistentEntity <WithCollectionAndCollationFromSpEL > entity = new BasicMongoPersistentEntity <>(
264- ClassTypeInformation . from (WithCollectionAndCollationFromSpEL .class ));
277+ TypeInformation . of (WithCollectionAndCollationFromSpEL .class ));
265278 entity .setEvaluationContextProvider (
266279 new ExtensionAwareEvaluationContextProvider (Collections .singletonList (new SampleExtension ())));
267280
@@ -298,7 +311,7 @@ void readsMultiShardKey() {
298311 }
299312
300313 static <T > BasicMongoPersistentEntity <T > entityOf (Class <T > type ) {
301- return new BasicMongoPersistentEntity <>(ClassTypeInformation . from (type ));
314+ return new BasicMongoPersistentEntity <>(TypeInformation . of (type ));
302315 }
303316
304317 @ Document ("contacts" )
@@ -350,6 +363,9 @@ private static class DocumentWithComposedAnnotation {}
350363 @ Document ("#{myProperty}" )
351364 class MappedWithExtension {}
352365
366+ @ Document ("${mongo.entity.collection}" )
367+ class MappedWithExtensionPropertyPlaceholderStyle {}
368+
353369 @ Document ("${value.from.file}" )
354370 class MappedWithValue {}
355371
0 commit comments