From e3aadd63ab5d70fdf68a31b333e2b894eb92f28d Mon Sep 17 00:00:00 2001 From: Ryan Tenney Date: Tue, 13 May 2014 23:23:26 -0400 Subject: [PATCH] DATAMONGO-928 - Removed explicit default value for abbreviate-field-names from namespace XSD. The default for boolean attributes leaks into the evaluation of XML namespace attributes which causes us being unable to detect whether two attributes have been set in a conflicting way. Fix the documentation on the field-naming-strategy-ref attribute. Original pull request: #183. Related pull request: #177. Related ticket: DATAMONGO-925. --- .../data/mongodb/config/spring-mongo-1.5.xsd | 8 +++---- ...gMongoConverterParserIntegrationTests.java | 21 +++++++++++++++++++ .../converter-custom-fieldnamingstrategy.xml | 13 ++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 spring-data-mongodb/src/test/resources/namespace/converter-custom-fieldnamingstrategy.xml diff --git a/spring-data-mongodb/src/main/resources/org/springframework/data/mongodb/config/spring-mongo-1.5.xsd b/spring-data-mongodb/src/main/resources/org/springframework/data/mongodb/config/spring-mongo-1.5.xsd index 9b225e6a4..68524f8f8 100644 --- a/spring-data-mongodb/src/main/resources/org/springframework/data/mongodb/config/spring-mongo-1.5.xsd +++ b/spring-data-mongodb/src/main/resources/org/springframework/data/mongodb/config/spring-mongo-1.5.xsd @@ -212,11 +212,11 @@ The base package in which to scan for entities annotated with @Document - + Enables abbreviating the field names for domain class properties to the - first character of their camel case names, e.g. fooBar -> fb. + first character of their camel case names, e.g. fooBar -> fb. Defaults to false. @@ -226,7 +226,7 @@ The base package in which to scan for entities annotated with @Document - The reference to a MappingContext. Will default to 'mappingContext'. + The reference to a FieldNamingStrategy. @@ -654,4 +654,4 @@ The GridFs bucket string.]]> - \ No newline at end of file + diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/config/MappingMongoConverterParserIntegrationTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/config/MappingMongoConverterParserIntegrationTests.java index bdf7c54f6..f001a0026 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/config/MappingMongoConverterParserIntegrationTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/config/MappingMongoConverterParserIntegrationTests.java @@ -25,6 +25,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.config.BeanReference; import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.DefaultListableBeanFactory; @@ -49,6 +50,7 @@ import com.mongodb.DBObject; * @author Oliver Gierke * @author Thomas Darimont * @author Christoph Strobl + * @author Ryan Tenney */ public class MappingMongoConverterParserIntegrationTests { @@ -134,6 +136,25 @@ public class MappingMongoConverterParserIntegrationTests { loadNestedBeanConfiguration(); } + /** + * @see DATAMONGO-925, DATAMONGO-928 + */ + @Test + public void shouldSupportCustomFieldNamingStrategy() { + + BeanDefinitionRegistry factory = new DefaultListableBeanFactory(); + XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory); + reader.loadBeanDefinitions(new ClassPathResource("namespace/converter-custom-fieldnamingstrategy.xml")); + + BeanDefinition definition = reader.getRegistry().getBeanDefinition( + "mappingConverterWithCustomFieldNamingStrategy.mongoMappingContext"); + + BeanReference value = (BeanReference) definition.getPropertyValues().getPropertyValue("fieldNamingStrategy") + .getValue(); + + assertThat(value.getBeanName(), is("customFieldNamingStrategy")); + } + private void loadValidConfiguration() { this.loadConfiguration("namespace/converter.xml"); } diff --git a/spring-data-mongodb/src/test/resources/namespace/converter-custom-fieldnamingstrategy.xml b/spring-data-mongodb/src/test/resources/namespace/converter-custom-fieldnamingstrategy.xml new file mode 100644 index 000000000..35e04bce8 --- /dev/null +++ b/spring-data-mongodb/src/test/resources/namespace/converter-custom-fieldnamingstrategy.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file