DATAMONGO-1737 - BasicMongoPersistentEntity now correctly initializes comparator.

In BasicMongoPersistentEntity.verify() we now properly call the super method to make sure the comparators that honor the @Field's order value are initialized properly.
This commit is contained in:
Oliver Gierke
2017-11-17 14:54:36 +01:00
parent cf70f5e5eb
commit 9e0b5caeac
2 changed files with 26 additions and 1 deletions

View File

@@ -149,6 +149,8 @@ public class BasicMongoPersistentEntity<T> extends BasicPersistentEntity<T, Mong
@Override
public void verify() {
super.verify();
verifyFieldUniqueness();
verifyFieldTypes();
}

View File

@@ -15,14 +15,17 @@
*/
package org.springframework.data.mongodb.core.mapping;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.junit.Assert.assertThat;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import org.junit.Before;
@@ -186,6 +189,19 @@ public class BasicMongoPersistentPropertyUnitTests {
assertThat(property.getFieldName(), is("myField"));
}
@Test // DATAMONGO-1737
public void honorsFieldOrderWhenIteratingOverProperties() {
MongoMappingContext context = new MongoMappingContext();
BasicMongoPersistentEntity<?> entity = context.getPersistentEntity(Sample.class);
List<String> properties = new ArrayList<>();
entity.doWithProperties((MongoPersistentProperty property) -> properties.add(property.getName()));
assertThat(properties).containsExactly("first", "second", "third");
}
private MongoPersistentProperty getPropertyFor(Field field) {
return getPropertyFor(entity, field);
}
@@ -213,6 +229,13 @@ public class BasicMongoPersistentPropertyUnitTests {
@org.springframework.data.mongodb.core.mapping.Field(order = -20) String ssn;
}
class Sample {
@org.springframework.data.mongodb.core.mapping.Field(order = 2) String second;
@org.springframework.data.mongodb.core.mapping.Field(order = 3) String third;
@org.springframework.data.mongodb.core.mapping.Field(order = 1) String first;
}
enum UppercaseFieldNamingStrategy implements FieldNamingStrategy {
INSTANCE;