mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Polish "Add profile expression support"
Issue: SPR-12458
This commit is contained in:
+41
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -305,6 +305,37 @@ public class EnvironmentSystemIntegrationTests {
|
||||
assertThat("should not have transitive bean", ctx.containsBean(TRANSITIVE_BEAN_NAME), is(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void annotationConfigApplicationContext_withProfileExpressionMatchOr() {
|
||||
testProfileExpression(true, "p3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void annotationConfigApplicationContext_withProfileExpressionMatchAnd() {
|
||||
testProfileExpression(true, "p1", "p2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void annotationConfigApplicationContext_withProfileExpressionNoMatchAnd() {
|
||||
testProfileExpression(false, "p1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void annotationConfigApplicationContext_withProfileExpressionNoMatchNone() {
|
||||
testProfileExpression(false, "p4");
|
||||
}
|
||||
|
||||
private void testProfileExpression(boolean expected, String... activeProfiles) {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
|
||||
StandardEnvironment environment = new StandardEnvironment();
|
||||
environment.setActiveProfiles(activeProfiles);
|
||||
ctx.setEnvironment(environment);
|
||||
ctx.register(ProfileExpressionConfig.class);
|
||||
ctx.refresh();
|
||||
assertThat("wrong presence of expression bean",
|
||||
ctx.containsBean("expressionBean"), is(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void webApplicationContext() {
|
||||
GenericWebApplicationContext ctx = new GenericWebApplicationContext(newBeanFactoryWithEnvironmentAwareBean());
|
||||
@@ -644,6 +675,15 @@ public class EnvironmentSystemIntegrationTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Profile("(p1 & p2) | p3")
|
||||
@Configuration
|
||||
static class ProfileExpressionConfig {
|
||||
@Bean
|
||||
public Object expressionBean() {
|
||||
return new Object();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constants used both locally and in scan* sub-packages
|
||||
|
||||
Reference in New Issue
Block a user