From 6ef518e6a08c9fbd71d205d052d4b8f78227eb7d Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Thu, 25 Sep 2014 15:25:51 +0200 Subject: [PATCH] DATAMONGO-1053 - Type check is now only performed on explicit language properties. We now only perform a type check on via @Language explicitly defined language properties. Prior to this change non-String properties named language caused errors on entity validation. Original pull request: #228. --- .../mapping/BasicMongoPersistentEntity.java | 2 +- .../BasicMongoPersistentEntityUnitTests.java | 61 +++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/BasicMongoPersistentEntity.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/BasicMongoPersistentEntity.java index c99c0eef8..b4f4f1a2b 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/BasicMongoPersistentEntity.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/BasicMongoPersistentEntity.java @@ -284,7 +284,7 @@ public class BasicMongoPersistentEntity extends BasicPersistentEntity entity = new BasicMongoPersistentEntity( + ClassTypeInformation.from(AnyDocument.class)); + + when(propertyMock.isExplicitLanguageProperty()).thenReturn(true); + when(propertyMock.getActualType()).thenReturn((Class) Number.class); + + entity.addPersistentProperty(propertyMock); + entity.verify(); + } + + /** + * @see DATAMONGO-1053 + */ + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Test + public void verifyShouldPassForStringAsExplicitLanguageProperty() { + + BasicMongoPersistentEntity entity = new BasicMongoPersistentEntity( + ClassTypeInformation.from(AnyDocument.class)); + when(propertyMock.isExplicitLanguageProperty()).thenReturn(true); + when(propertyMock.getActualType()).thenReturn((Class) String.class); + entity.addPersistentProperty(propertyMock); + + entity.verify(); + + verify(propertyMock, times(1)).isExplicitLanguageProperty(); + verify(propertyMock, times(1)).getActualType(); + } + + /** + * @see DATAMONGO-1053 + */ + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Test + public void verifyShouldIgnoreNonExplicitLanguageProperty() { + + BasicMongoPersistentEntity entity = new BasicMongoPersistentEntity( + ClassTypeInformation.from(AnyDocument.class)); + when(propertyMock.isExplicitLanguageProperty()).thenReturn(false); + when(propertyMock.getActualType()).thenReturn((Class) Number.class); + entity.addPersistentProperty(propertyMock); + + entity.verify(); + + verify(propertyMock, times(1)).isExplicitLanguageProperty(); + verify(propertyMock, never()).getActualType(); + } + @Document(collection = "contacts") class Contact { @@ -111,4 +168,8 @@ public class BasicMongoPersistentEntityUnitTests { static class DocumentWithLanguage { } + + static class AnyDocument { + + } }