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.
This commit is contained in:
Ryan Tenney
2014-05-13 23:23:26 -04:00
committed by Oliver Gierke
parent aa06d520df
commit e3aadd63ab
3 changed files with 38 additions and 4 deletions

View File

@@ -212,11 +212,11 @@ The base package in which to scan for entities annotated with @Document
<xsd:union memberTypes="xsd:boolean xsd:string"/>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="abbreviate-field-names" use="optional" default="false">
<xsd:attribute name="abbreviate-field-names" use="optional">
<xsd:annotation>
<xsd:documentation source="org.springframework.data.mongodb.core.mapping.CamelCaseAbbreviatingFieldNamingStrategy">
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.
</xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
@@ -226,7 +226,7 @@ The base package in which to scan for entities annotated with @Document
<xsd:attribute name="field-naming-strategy-ref" type="fieldNamingStrategyRef" use="optional">
<xsd:annotation>
<xsd:documentation source="org.springframework.data.mongodb.core.mapping.FieldNamingStrategy">
The reference to a MappingContext. Will default to 'mappingContext'.
The reference to a FieldNamingStrategy.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
@@ -654,4 +654,4 @@ The GridFs bucket string.]]></xsd:documentation>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</xsd:schema>

View File

@@ -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");
}

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<mongo:mapping-converter id="mappingConverterWithCustomFieldNamingStrategy" field-naming-strategy-ref="customFieldNamingStrategy" />
<bean id="customFieldNamingStrategy" class="org.mockito.Mockito" factory-method="mock">
<property name="type" value="org.springframework.data.mongodb.core.mapping.FieldNamingStrategy" />
</bean>
</beans>