StructuredLoggingJsonPropertiesBeanFactoryInitializationAotProcessorTests Class — spring-boot Architecture
Architecture documentation for the StructuredLoggingJsonPropertiesBeanFactoryInitializationAotProcessorTests class in StructuredLoggingJsonPropertiesBeanFactoryInitializationAotProcessorTests.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
core/spring-boot/src/test/java/org/springframework/boot/logging/structured/StructuredLoggingJsonPropertiesBeanFactoryInitializationAotProcessorTests.java lines 48–145
class StructuredLoggingJsonPropertiesBeanFactoryInitializationAotProcessorTests {
@Test
void structuredLoggingJsonPropertiesBeanFactoryInitializationAotProcessorIsRegistered() {
assertThat(AotServices.factories().load(BeanFactoryInitializationAotProcessor.class))
.anyMatch(StructuredLoggingJsonPropertiesBeanFactoryInitializationAotProcessor.class::isInstance);
}
@Test
void shouldRegisterRuntimeHintsWhenCustomizerIsPresent() {
MockEnvironment environment = new MockEnvironment();
environment.setProperty("logging.structured.json.customizer", TestCustomizer.class.getName());
BeanFactoryInitializationAotContribution contribution = getContribution(environment);
assertThat(contribution).isNotNull();
RuntimeHints hints = getRuntimeHints(contribution);
assertThat(RuntimeHintsPredicates.reflection()
.onType(TestCustomizer.class)
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS))
.accepts(hints);
}
@Test
void shouldRegisterRuntimeHintsWhenCustomStackTracePrinterIsPresent() {
MockEnvironment environment = new MockEnvironment();
environment.setProperty("logging.structured.json.stacktrace.printer", TestStackTracePrinter.class.getName());
BeanFactoryInitializationAotContribution contribution = getContribution(environment);
assertThat(contribution).isNotNull();
RuntimeHints hints = getRuntimeHints(contribution);
assertThat(RuntimeHintsPredicates.reflection()
.onType(TestStackTracePrinter.class)
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS))
.accepts(hints);
}
@ParameterizedTest
@ValueSource(strings = { "logging-system", "standard" })
void shouldNotRegisterRuntimeHintsWhenStackTracePrinterIsNotCustomImplementation(String printer) {
MockEnvironment environment = new MockEnvironment();
environment.setProperty("logging.structured.json.stacktrace.printer", printer);
BeanFactoryInitializationAotContribution contribution = getContribution(environment);
assertThat(contribution).isNull();
}
@Test
void shouldNotRegisterRuntimeHintsWhenPropertiesAreNotSet() {
MockEnvironment environment = new MockEnvironment();
BeanFactoryInitializationAotContribution contribution = getContribution(environment);
assertThat(contribution).isNull();
}
@Test
void shouldNotRegisterRuntimeHintsWhenCustomizerAndPrinterAreNotSet() {
MockEnvironment environment = new MockEnvironment();
environment.setProperty("logging.structured.json.exclude", "something");
BeanFactoryInitializationAotContribution contribution = getContribution(environment);
assertThat(contribution).isNull();
}
private @Nullable BeanFactoryInitializationAotContribution getContribution(ConfigurableEnvironment environment) {
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
context.setEnvironment(environment);
context.refresh();
return new StructuredLoggingJsonPropertiesBeanFactoryInitializationAotProcessor()
.processAheadOfTime(context.getBeanFactory());
}
}
private RuntimeHints getRuntimeHints(BeanFactoryInitializationAotContribution contribution) {
TestGenerationContext generationContext = new TestGenerationContext();
contribution.applyTo(generationContext, mock(BeanFactoryInitializationCode.class));
return generationContext.getRuntimeHints();
}
static class TestCustomizer implements StructuredLoggingJsonMembersCustomizer<String> {
@Override
public void customize(Members<String> members) {
}
}
static class TestStackTracePrinter implements StackTracePrinter {
@Override
public void printStackTrace(Throwable throwable, Appendable out) throws IOException {
}
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free