Merge branch '5.3.x'
# Conflicts: # spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java
This commit is contained in:
@@ -207,6 +207,70 @@ class MergedAnnotationsTests {
|
||||
|
||||
}
|
||||
|
||||
@Nested
|
||||
class ConventionBasedAnnotationAttributeOverrideTests {
|
||||
|
||||
@Test
|
||||
void getWithInheritedAnnotationsAttributesWithConventionBasedComposedAnnotation() {
|
||||
MergedAnnotation<?> annotation =
|
||||
MergedAnnotations.from(ConventionBasedComposedContextConfigurationClass.class,
|
||||
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class);
|
||||
assertThat(annotation.isPresent()).isTrue();
|
||||
assertThat(annotation.getStringArray("locations")).containsExactly("explicitDeclaration");
|
||||
assertThat(annotation.getStringArray("value")).containsExactly("explicitDeclaration");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getWithInheritedAnnotationsFromHalfConventionBasedAndHalfAliasedComposedAnnotation1() {
|
||||
// SPR-13554: convention mapping mixed with AliasFor annotations
|
||||
// xmlConfigFiles can be used because it has an AliasFor annotation
|
||||
MergedAnnotation<?> annotation =
|
||||
MergedAnnotations.from(HalfConventionBasedAndHalfAliasedComposedContextConfigurationClass1.class,
|
||||
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class);
|
||||
assertThat(annotation.getStringArray("locations")).containsExactly("explicitDeclaration");
|
||||
assertThat(annotation.getStringArray("value")).containsExactly("explicitDeclaration");
|
||||
}
|
||||
|
||||
@Test
|
||||
void withInheritedAnnotationsFromHalfConventionBasedAndHalfAliasedComposedAnnotation2() {
|
||||
// SPR-13554: convention mapping mixed with AliasFor annotations
|
||||
// locations doesn't apply because it has no AliasFor annotation
|
||||
MergedAnnotation<?> annotation =
|
||||
MergedAnnotations.from(HalfConventionBasedAndHalfAliasedComposedContextConfigurationClass2.class,
|
||||
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class);
|
||||
assertThat(annotation.getStringArray("locations")).isEmpty();
|
||||
assertThat(annotation.getStringArray("value")).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void getWithInheritedAnnotationsFromInvalidConventionBasedComposedAnnotation() {
|
||||
assertThatExceptionOfType(AnnotationConfigurationException.class)
|
||||
.isThrownBy(() -> MergedAnnotations.from(InvalidConventionBasedComposedContextConfigurationClass.class,
|
||||
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getWithTypeHierarchyWithSingleElementOverridingAnArrayViaConvention() {
|
||||
testGetWithTypeHierarchy(ConventionBasedSinglePackageComponentScanClass.class, "com.example.app.test");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getWithTypeHierarchyWithLocalAliasesThatConflictWithAttributesInMetaAnnotationByConvention() {
|
||||
MergedAnnotation<?> annotation =
|
||||
MergedAnnotations.from(SpringApplicationConfigurationClass.class, SearchStrategy.TYPE_HIERARCHY)
|
||||
.get(ContextConfiguration.class);
|
||||
assertThat(annotation.getStringArray("locations")).isEmpty();
|
||||
assertThat(annotation.getStringArray("value")).isEmpty();
|
||||
assertThat(annotation.getClassArray("classes")).containsExactly(Number.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getWithTypeHierarchyOnMethodWithSingleElementOverridingAnArrayViaConvention() throws Exception {
|
||||
testGetWithTypeHierarchyWebMapping(WebController.class.getMethod("postMappedWithPathAttribute"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void fromPreconditions() {
|
||||
SearchStrategy strategy = SearchStrategy.DIRECT;
|
||||
@@ -479,41 +543,7 @@ class MergedAnnotationsTests {
|
||||
assertThat(annotation.isPresent()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void getWithInheritedAnnotationsAttributesWithConventionBasedComposedAnnotation() {
|
||||
MergedAnnotation<?> annotation = MergedAnnotations.from(
|
||||
ConventionBasedComposedContextConfigurationClass.class,
|
||||
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class);
|
||||
assertThat(annotation.isPresent()).isTrue();
|
||||
assertThat(annotation.getStringArray("locations")).containsExactly(
|
||||
"explicitDeclaration");
|
||||
assertThat(annotation.getStringArray("value")).containsExactly(
|
||||
"explicitDeclaration");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getWithInheritedAnnotationsFromHalfConventionBasedAndHalfAliasedComposedAnnotation1() {
|
||||
// SPR-13554: convention mapping mixed with AliasFor annotations
|
||||
// xmlConfigFiles can be used because it has an AliasFor annotation
|
||||
MergedAnnotation<?> annotation = MergedAnnotations.from(
|
||||
HalfConventionBasedAndHalfAliasedComposedContextConfigurationClass1.class,
|
||||
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class);
|
||||
assertThat(annotation.getStringArray("locations")).containsExactly(
|
||||
"explicitDeclaration");
|
||||
assertThat(annotation.getStringArray("value")).containsExactly(
|
||||
"explicitDeclaration");
|
||||
}
|
||||
|
||||
@Test
|
||||
void withInheritedAnnotationsFromHalfConventionBasedAndHalfAliasedComposedAnnotation2() {
|
||||
// SPR-13554: convention mapping mixed with AliasFor annotations
|
||||
// locations doesn't apply because it has no AliasFor annotation
|
||||
MergedAnnotation<?> annotation = MergedAnnotations.from(
|
||||
HalfConventionBasedAndHalfAliasedComposedContextConfigurationClass2.class,
|
||||
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class);
|
||||
assertThat(annotation.getStringArray("locations")).isEmpty();
|
||||
assertThat(annotation.getStringArray("value")).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void withInheritedAnnotationsFromAliasedComposedAnnotation() {
|
||||
@@ -591,13 +621,6 @@ class MergedAnnotationsTests {
|
||||
assertThat(annotation.getClassArray("classes")).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void getWithInheritedAnnotationsFromInvalidConventionBasedComposedAnnotation() {
|
||||
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() ->
|
||||
MergedAnnotations.from(InvalidConventionBasedComposedContextConfigurationClass.class,
|
||||
SearchStrategy.INHERITED_ANNOTATIONS).get(ContextConfiguration.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getWithInheritedAnnotationsFromShadowedAliasComposedAnnotation() {
|
||||
MergedAnnotation<?> annotation = MergedAnnotations.from(
|
||||
@@ -760,11 +783,6 @@ class MergedAnnotationsTests {
|
||||
testGetWithTypeHierarchy(ComponentScanWithBasePackagesAndValueAliasClass.class, "com.example.app.test");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getWithTypeHierarchyWithSingleElementOverridingAnArrayViaConvention() {
|
||||
testGetWithTypeHierarchy(ConventionBasedSinglePackageComponentScanClass.class, "com.example.app.test");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getWithTypeHierarchyWithSingleElementOverridingAnArrayViaAliasFor() {
|
||||
testGetWithTypeHierarchy(AliasForBasedSinglePackageComponentScanClass.class, "com.example.app.test");
|
||||
@@ -793,22 +811,6 @@ class MergedAnnotationsTests {
|
||||
"test.properties");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getWithTypeHierarchyWithLocalAliasesThatConflictWithAttributesInMetaAnnotationByConvention() {
|
||||
MergedAnnotation<?> annotation = MergedAnnotations.from(
|
||||
SpringApplicationConfigurationClass.class, SearchStrategy.TYPE_HIERARCHY).get(
|
||||
ContextConfiguration.class);
|
||||
assertThat(annotation.getStringArray("locations")).isEmpty();
|
||||
assertThat(annotation.getStringArray("value")).isEmpty();
|
||||
assertThat(annotation.getClassArray("classes")).containsExactly(Number.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getWithTypeHierarchyOnMethodWithSingleElementOverridingAnArrayViaConvention() throws Exception {
|
||||
testGetWithTypeHierarchyWebMapping(
|
||||
WebController.class.getMethod("postMappedWithPathAttribute"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getWithTypeHierarchyOnMethodWithSingleElementOverridingAnArrayViaAliasFor() throws Exception {
|
||||
testGetWithTypeHierarchyWebMapping(
|
||||
|
||||
Reference in New Issue
Block a user