Support not (!) operator for profile selection
The following syntax is now supported
<beans profile="p1,!p2">
@Profile("p1", "!p2")
indicating that the <beans> element or annotated component should
be processed only if profile 'p1' is active or profile 'p2' is not
active.
Issue: SPR-8728
This commit is contained in:
@@ -17,8 +17,10 @@
|
||||
package org.springframework.core.env;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import java.security.AccessControlException;
|
||||
import java.security.Permission;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
@@ -147,6 +149,11 @@ public class StandardEnvironmentTests {
|
||||
environment.setActiveProfiles("");
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void setActiveProfiles_withNotOperator() {
|
||||
environment.setActiveProfiles("p1", "!p2");
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void setDefaultProfiles_withNullProfileArray() {
|
||||
environment.setDefaultProfiles((String[])null);
|
||||
@@ -162,6 +169,11 @@ public class StandardEnvironmentTests {
|
||||
environment.setDefaultProfiles("");
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void setDefaultProfiles_withNotOperator() {
|
||||
environment.setDefaultProfiles("d1", "!d2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addActiveProfile() {
|
||||
assertThat(environment.getActiveProfiles().length, is(0));
|
||||
@@ -284,6 +296,20 @@ public class StandardEnvironmentTests {
|
||||
assertThat(environment.acceptsProfiles("p1"), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void acceptsProfiles_withNotOperator() {
|
||||
assertThat(environment.acceptsProfiles("p1"), is(false));
|
||||
assertThat(environment.acceptsProfiles("!p1"), is(true));
|
||||
environment.addActiveProfile("p1");
|
||||
assertThat(environment.acceptsProfiles("p1"), is(true));
|
||||
assertThat(environment.acceptsProfiles("!p1"), is(false));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void acceptsProfiles_withInvalidNotOperator() {
|
||||
environment.acceptsProfiles("p1", "!");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void environmentSubclass_withCustomProfileValidation() {
|
||||
ConfigurableEnvironment env = new AbstractEnvironment() {
|
||||
|
||||
Reference in New Issue
Block a user