Preserve registration order in @ActiveProfiles
With this commit, bean definition profiles declared via @ActiveProfiles are once again stored in registration order, in order to support use cases in Spring Boot and other frameworks that depend on the registration order. This effectively reverts the changes made in conjunction with gh-25973. Closes gh-26004
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -143,7 +143,7 @@ class MergedContextConfigurationTests {
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles1, loader);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(),
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles2, loader);
|
||||
assertThat(mergedConfig2).hasSameHashCodeAs(mergedConfig1);
|
||||
assertThat(mergedConfig2.hashCode()).isNotEqualTo(mergedConfig1.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -339,13 +339,13 @@ class MergedContextConfigurationTests {
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles1, loader);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(),
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles2, loader);
|
||||
assertThat(mergedConfig2).isEqualTo(mergedConfig1);
|
||||
assertThat(mergedConfig2).isNotEqualTo(mergedConfig1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void equalsWithSameDuplicateProfiles() {
|
||||
String[] activeProfiles1 = new String[] { "catbert", "dogbert" };
|
||||
String[] activeProfiles2 = new String[] { "dogbert", "catbert", "dogbert", "catbert" };
|
||||
String[] activeProfiles2 = new String[] { "catbert", "dogbert", "catbert", "dogbert", "catbert" };
|
||||
MergedContextConfiguration mergedConfig1 = new MergedContextConfiguration(getClass(),
|
||||
EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, activeProfiles1, loader);
|
||||
MergedContextConfiguration mergedConfig2 = new MergedContextConfiguration(getClass(),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -90,8 +90,8 @@ class ContextCacheTests {
|
||||
int size = 0, hit = 0, miss = 0;
|
||||
loadCtxAndAssertStats(FooBarProfilesTestCase.class, ++size, hit, ++miss);
|
||||
loadCtxAndAssertStats(FooBarProfilesTestCase.class, size, ++hit, miss);
|
||||
// Profiles {foo, bar} MUST hash to the same as {bar, foo}
|
||||
loadCtxAndAssertStats(BarFooProfilesTestCase.class, size, ++hit, miss);
|
||||
// Profiles {foo, bar} should not hash to the same as {bar,foo}
|
||||
loadCtxAndAssertStats(BarFooProfilesTestCase.class, ++size, hit, ++miss);
|
||||
loadCtxAndAssertStats(FooBarProfilesTestCase.class, size, ++hit, miss);
|
||||
loadCtxAndAssertStats(FooBarProfilesTestCase.class, size, ++hit, miss);
|
||||
loadCtxAndAssertStats(BarFooProfilesTestCase.class, size, ++hit, miss);
|
||||
|
||||
@@ -67,12 +67,12 @@ class ActiveProfilesUtilsTests extends AbstractContextConfigurationUtilsTests {
|
||||
|
||||
@Test
|
||||
void resolveActiveProfilesWithDuplicatedProfiles() {
|
||||
assertResolvedProfiles(DuplicatedProfiles.class, "bar", "baz", "foo");
|
||||
assertResolvedProfiles(DuplicatedProfiles.class, "foo", "bar", "baz");
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveActiveProfilesWithLocalAndInheritedDuplicatedProfiles() {
|
||||
assertResolvedProfiles(ExtendedDuplicatedProfiles.class, "bar", "baz", "cat", "dog", "foo");
|
||||
assertResolvedProfiles(ExtendedDuplicatedProfiles.class, "foo", "bar", "baz", "cat", "dog");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -92,12 +92,12 @@ class ActiveProfilesUtilsTests extends AbstractContextConfigurationUtilsTests {
|
||||
|
||||
@Test
|
||||
void resolveActiveProfilesWithLocalAndInheritedAnnotations() {
|
||||
assertResolvedProfiles(LocationsBar.class, "bar", "foo");
|
||||
assertResolvedProfiles(LocationsBar.class, "foo", "bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveActiveProfilesWithOverriddenAnnotation() {
|
||||
assertResolvedProfiles(Animals.class, "cat", "dog");
|
||||
assertResolvedProfiles(Animals.class, "dog", "cat");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,7 +129,7 @@ class ActiveProfilesUtilsTests extends AbstractContextConfigurationUtilsTests {
|
||||
*/
|
||||
@Test
|
||||
void resolveActiveProfilesWithLocalAndInheritedMetaAnnotations() {
|
||||
assertResolvedProfiles(MetaLocationsBar.class, "bar", "foo");
|
||||
assertResolvedProfiles(MetaLocationsBar.class, "foo", "bar");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,7 +137,7 @@ class ActiveProfilesUtilsTests extends AbstractContextConfigurationUtilsTests {
|
||||
*/
|
||||
@Test
|
||||
void resolveActiveProfilesWithOverriddenMetaAnnotation() {
|
||||
assertResolvedProfiles(MetaAnimals.class, "cat", "dog");
|
||||
assertResolvedProfiles(MetaAnimals.class, "dog", "cat");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,7 +161,7 @@ class ActiveProfilesUtilsTests extends AbstractContextConfigurationUtilsTests {
|
||||
*/
|
||||
@Test
|
||||
void resolveActiveProfilesWithMergedInheritedResolver() {
|
||||
assertResolvedProfiles(MergedInheritedFooActiveProfilesResolverTestCase.class, "bar", "foo");
|
||||
assertResolvedProfiles(MergedInheritedFooActiveProfilesResolverTestCase.class, "foo", "bar");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -373,6 +373,8 @@ class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigurationUt
|
||||
void buildMergedConfigWithDuplicateConfigurationOnEnclosingClassAndNestedClass() {
|
||||
compareApplesToApples(AppleConfigTestCase.class, AppleConfigTestCase.Nested.class);
|
||||
compareApplesToApples(AppleConfigTestCase.Nested.class, AppleConfigTestCase.Nested.DoubleNested.class);
|
||||
compareApplesToOranges(ApplesAndOrangesConfigTestCase.class, ApplesAndOrangesConfigTestCase.Nested.class);
|
||||
compareApplesToOranges(ApplesAndOrangesConfigTestCase.Nested.class, ApplesAndOrangesConfigTestCase.Nested.DoubleNested.class);
|
||||
}
|
||||
|
||||
private void compareApplesToApples(Class<?> parent, Class<?> child) {
|
||||
@@ -400,7 +402,7 @@ class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigurationUt
|
||||
DelegatingSmartContextLoader.class);
|
||||
|
||||
assertThat(parentMergedConfig.getActiveProfiles()).as("active profiles")
|
||||
.containsExactly("apples", "oranges")
|
||||
.containsExactly("oranges", "apples")
|
||||
.isEqualTo(childMergedConfig.getActiveProfiles());
|
||||
assertThat(parentMergedConfig).isEqualTo(childMergedConfig);
|
||||
}
|
||||
@@ -531,7 +533,7 @@ class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigurationUt
|
||||
}
|
||||
|
||||
@ContextConfiguration(classes = AppleConfig.class)
|
||||
@ActiveProfiles({"apples", "oranges"})
|
||||
@ActiveProfiles({"oranges", "apples"})
|
||||
static class ApplesAndOrangesConfigTestCase {
|
||||
|
||||
@ContextConfiguration(classes = AppleConfig.class)
|
||||
@@ -539,19 +541,19 @@ class BootstrapTestUtilsMergedConfigTests extends AbstractContextConfigurationUt
|
||||
class Nested {
|
||||
|
||||
@ContextConfiguration(classes = AppleConfig.class)
|
||||
@ActiveProfiles(profiles = {"apples", "oranges", "apples"}, inheritProfiles = false)
|
||||
@ActiveProfiles(profiles = {"oranges", "apples", "oranges"}, inheritProfiles = false)
|
||||
class DoubleNested {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ContextConfiguration(classes = AppleConfig.class)
|
||||
@ActiveProfiles(profiles = {"oranges", "apples"}, inheritProfiles = false)
|
||||
@ActiveProfiles(profiles = {"oranges", "apples", "oranges"}, inheritProfiles = false)
|
||||
static class DuplicateConfigApplesAndOrangesConfigTestCase extends ApplesAndOrangesConfigTestCase {
|
||||
}
|
||||
|
||||
@ContextConfiguration(classes = AppleConfig.class)
|
||||
@ActiveProfiles(profiles = {"apples", "oranges", "apples"}, inheritProfiles = false)
|
||||
@ActiveProfiles(profiles = {"oranges", "apples", "oranges"}, inheritProfiles = false)
|
||||
static class SubDuplicateConfigApplesAndOrangesConfigTestCase extends DuplicateConfigApplesAndOrangesConfigTestCase {
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user