DATACMNS-556 - Make annotation validation in AnnotationBasedPersistentProperty more lenient.
Annotations used on both fields and accessors are now only rejected if they're Spring Data annotations (i.e. from the org.springframework.data namespace) and the configurations of these annotations differ.
This commit is contained in:
@@ -25,6 +25,8 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.annotation.AccessType;
|
||||
@@ -156,8 +158,8 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
|
||||
/**
|
||||
* @see DATACMNS-243
|
||||
*/
|
||||
@Test(expected = MappingException.class)
|
||||
public void detectsAmbiguityCausedByFieldAnAccessorAnnotation() {
|
||||
@Test
|
||||
public void doesNotRejectSameAnnotationIfItsEqualOnBothFieldAndAccessor() {
|
||||
context.getPersistentEntity(AnotherInvalidSample.class);
|
||||
}
|
||||
|
||||
@@ -193,6 +195,14 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
|
||||
assertThat(getProperty(ClassWithReadOnlyProperties.class, "customReadOnlyProperty").isWritable(), is(false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-556
|
||||
*/
|
||||
@Test
|
||||
public void doesNotRejectNonSpringDataAnnotationsUsedOnBothFieldAndAccessor() {
|
||||
getProperty(TypeWithCustomAnnotationsOnBothFieldAndAccessor.class, "field");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<Class<? extends Annotation>, Annotation> getAnnotationCache(SamplePersistentProperty property) {
|
||||
return (Map<Class<? extends Annotation>, Annotation>) ReflectionTestUtils.getField(property, "annotationCache");
|
||||
@@ -317,6 +327,16 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
|
||||
@CustomReadOnly String customReadOnlyProperty;
|
||||
}
|
||||
|
||||
static class TypeWithCustomAnnotationsOnBothFieldAndAccessor {
|
||||
|
||||
@Nullable String field;
|
||||
|
||||
@Nullable
|
||||
public String getField() {
|
||||
return field;
|
||||
}
|
||||
}
|
||||
|
||||
@ReadOnlyProperty
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(FIELD)
|
||||
|
||||
Reference in New Issue
Block a user