SpringBootJoranConfiguratorTests Class — spring-boot Architecture
Architecture documentation for the SpringBootJoranConfiguratorTests class in SpringBootJoranConfiguratorTests.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
core/spring-boot/src/test/java/org/springframework/boot/logging/logback/SpringBootJoranConfiguratorTests.java lines 55–429
@ExtendWith(OutputCaptureExtension.class)
class SpringBootJoranConfiguratorTests {
private MockEnvironment environment;
private LoggingInitializationContext initializationContext;
private JoranConfigurator configurator;
private LoggerContext context;
private Logger logger;
private CapturedOutput output;
@BeforeEach
void setup(CapturedOutput output) {
this.output = output;
this.environment = new MockEnvironment();
this.initializationContext = new LoggingInitializationContext(this.environment);
this.configurator = new SpringBootJoranConfigurator(this.initializationContext);
this.context = (LoggerContext) LoggerFactory.getILoggerFactory();
this.logger = this.context.getLogger(getClass());
}
@AfterEach
void reset() {
this.context.stop();
new BasicConfigurator().configure((LoggerContext) LoggerFactory.getILoggerFactory());
this.context.start();
}
@Test
@WithProductionProfileXmlResource
void profileActive() throws Exception {
this.environment.setActiveProfiles("production");
initialize("production-profile.xml");
this.logger.trace("Hello");
assertThat(this.output).contains("Hello");
}
@Test
@WithResource(name = "profile-in-include.xml", content = """
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<include file="${resourceRoot}/include-with-profile.xml"/>
</configuration>
""")
@WithResource(name = "include-with-profile.xml", content = """
<included>
<springProfile name="production">
<logger name="org.springframework.boot.logging.logback" level="TRACE"/>
</springProfile>
</included>
""")
void profileInIncludeActive() throws Exception {
this.environment.setActiveProfiles("production");
initialize("profile-in-include.xml");
this.logger.trace("Hello");
assertThat(this.output).contains("Hello");
}
@Test
@WithMultiProfileNamesXmlResource
void multipleNamesFirstProfileActive() throws Exception {
this.environment.setActiveProfiles("production");
initialize("multi-profile-names.xml");
this.logger.trace("Hello");
assertThat(this.output).contains("Hello");
}
@Test
@WithMultiProfileNamesXmlResource
void multipleNamesSecondProfileActive() throws Exception {
this.environment.setActiveProfiles("test");
initialize("multi-profile-names.xml");
this.logger.trace("Hello");
assertThat(this.output).contains("Hello");
}
@Test
@WithProductionProfileXmlResource
void profileNotActive() throws Exception {
initialize("production-profile.xml");
this.logger.trace("Hello");
assertThat(this.output).doesNotContain("Hello");
}
@Test
@WithProfileExpressionXmlResource
void profileExpressionMatchFirst() throws Exception {
this.environment.setActiveProfiles("production");
initialize("profile-expression.xml");
this.logger.trace("Hello");
assertThat(this.output).contains("Hello");
}
@Test
@WithProfileExpressionXmlResource
void profileExpressionMatchSecond() throws Exception {
this.environment.setActiveProfiles("test");
initialize("profile-expression.xml");
this.logger.trace("Hello");
assertThat(this.output).contains("Hello");
}
@Test
@WithProfileExpressionXmlResource
void profileExpressionNoMatch() throws Exception {
this.environment.setActiveProfiles("development");
initialize("profile-expression.xml");
this.logger.trace("Hello");
assertThat(this.output).doesNotContain("Hello");
}
@Test
@WithNestedXmlResource
void profileNestedActiveActive() throws Exception {
doTestNestedProfile(true, "outer", "inner");
}
@Test
@WithNestedXmlResource
void profileNestedActiveNotActive() throws Exception {
doTestNestedProfile(false, "outer");
}
@Test
@WithNestedXmlResource
void profileNestedNotActiveActive() throws Exception {
doTestNestedProfile(false, "inner");
}
@Test
@WithNestedXmlResource
void profileNestedNotActiveNotActive() throws Exception {
doTestNestedProfile(false);
}
@Test
@WithPropertyXmlResource
void springProperty() throws Exception {
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment, "my.example-property=test");
initialize("property.xml");
assertThat(this.context.getProperty("MINE")).isEqualTo("test");
}
@Test
@WithPropertyXmlResource
void relaxedSpringProperty() throws Exception {
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment, "my.EXAMPLE_PROPERTY=test");
ConfigurationPropertySources.attach(this.environment);
initialize("property.xml");
assertThat(this.context.getProperty("MINE")).isEqualTo("test");
}
@Test
@WithPropertyXmlResource
void springPropertyNoValue() throws Exception {
initialize("property.xml");
assertThat(this.context.getProperty("SIMPLE")).isNull();
}
@Test
@WithPropertyXmlResource
void relaxedSpringPropertyNoValue() throws Exception {
initialize("property.xml");
assertThat(this.context.getProperty("MINE")).isNull();
}
@Test
@WithPropertyDefaultValueXmlResource
void springPropertyWithDefaultValue() throws Exception {
initialize("property-default-value.xml");
assertThat(this.context.getProperty("SIMPLE")).isEqualTo("foo");
}
@Test
@WithPropertyDefaultValueXmlResource
void relaxedSpringPropertyWithDefaultValue() throws Exception {
initialize("property-default-value.xml");
assertThat(this.context.getProperty("MINE")).isEqualTo("bar");
}
@Test
@WithPropertyInIfXmlResource
void springPropertyInIfWhenTrue() throws Exception {
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment, "my.example-property=true");
initialize("property-in-if.xml");
assertThat(this.context.getProperty("MYCHECK")).isEqualTo("i-was-included");
}
@Test
@WithPropertyInIfXmlResource
void springPropertyInIfWhenFalse() throws Exception {
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment, "my.example-property=false");
initialize("property-in-if.xml");
assertThat(this.context.getProperty("MYCHECK")).isNull();
}
@Test
@WithResource(name = "property-in-include.xml", content = """
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<include file="${resourceRoot}/include-with-property.xml"/>
</configuration>
""")
@WithResource(name = "include-with-property.xml", content = """
<included>
<springProperty scope="context" name="MINE" source="my.example-property" defaultValue="default-test"/>
</included>
""")
@ClassPathExclusions
void springPropertyInInclude() throws Exception {
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment, "my.example-property=test");
initialize("property-in-include.xml");
assertThat(this.context.getProperty("MINE")).isEqualTo("test");
}
@Test
@WithPropertyXmlResource
void addsAotContributionToContextDuringAotProcessing() throws Exception {
withSystemProperty(AbstractAotProcessor.AOT_PROCESSING, "true", () -> {
initialize("property.xml");
Object contribution = this.context.getObject(BeanFactoryInitializationAotContribution.class.getName());
assertThat(contribution).isNotNull();
});
}
private void withSystemProperty(String name, String value, Action action) throws Exception {
System.setProperty(name, value);
try {
action.perform();
}
finally {
System.clearProperty(name);
}
}
private void doTestNestedProfile(boolean expected, String... profiles) throws JoranException {
this.environment.setActiveProfiles(profiles);
initialize("nested.xml");
this.logger.trace("Hello");
if (expected) {
assertThat(this.output).contains("Hello");
}
else {
assertThat(this.output).doesNotContain("Hello");
}
}
private void initialize(String config) throws JoranException {
this.configurator.setContext(this.context);
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
this.configurator.doConfigure(contextClassLoader.getResource(config));
}
private interface Action {
void perform() throws Exception;
}
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@WithResource(name = "property-default-value.xml", content = """
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<springProperty scope="context" name="SIMPLE" source="testpropertyfoobar" defaultValue="foo"/>
<springProperty scope="context" name="MINE" source="my.example-property" defaultValue="bar"/>
</configuration>
""")
private @interface WithPropertyDefaultValueXmlResource {
}
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@WithResource(name = "property-in-if.xml", content = """
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<springProperty scope="context" name="MINE" source="my.example-property"/>
<if condition='property("MINE").contains("true")'>
<then>
<variable scope="context" name="MYCHECK" value="i-was-included"/>
</then>
</if>
</configuration>
""")
private @interface WithPropertyInIfXmlResource {
}
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@WithResource(name = "property.xml", content = """
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<springProperty scope="context" name="SIMPLE" source="testpropertyfoobar"/>
<springProperty scope="context" name="MINE" source="my.example-property"/>
</configuration>
""")
private @interface WithPropertyXmlResource {
}
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@WithResource(name = "profile-expression.xml", content = """
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<springProfile name="production | test">
<logger name="org.springframework.boot.logging.logback" level="TRACE"/>
</springProfile>
</configuration>
""")
private @interface WithProfileExpressionXmlResource {
}
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@WithResource(name = "production-profile.xml", content = """
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<springProfile name="production">
<logger name="org.springframework.boot.logging.logback" level="TRACE"/>
</springProfile>
</configuration>
""")
private @interface WithProductionProfileXmlResource {
}
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@WithResource(name = "nested.xml", content = """
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<springProfile name="outer">
<springProfile name="inner">
<logger name="org.springframework.boot.logging.logback" level="TRACE"/>
</springProfile>
</springProfile>
</configuration>
""")
private @interface WithNestedXmlResource {
}
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@WithResource(name = "multi-profile-names.xml", content = """
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<springProfile name="production, test">
<logger name="org.springframework.boot.logging.logback" level="TRACE"/>
</springProfile>
</configuration>
""")
private @interface WithMultiProfileNamesXmlResource {
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free