SpringApplicationAdminJmxAutoConfigurationTests Class — spring-boot Architecture
Architecture documentation for the SpringApplicationAdminJmxAutoConfigurationTests class in SpringApplicationAdminJmxAutoConfigurationTests.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
core/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfigurationTests.java lines 52–151
class SpringApplicationAdminJmxAutoConfigurationTests {
private static final String ENABLE_ADMIN_PROP = "spring.application.admin.enabled=true";
private static final String DEFAULT_JMX_NAME = "org.springframework.boot:type=Admin,name=SpringApplication";
private final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(SpringApplicationAdminJmxAutoConfiguration.class));
@Test
void notRegisteredWhenThereAreNoMBeanExporter() {
this.contextRunner.withPropertyValues(ENABLE_ADMIN_PROP).run((context) -> {
ObjectName objectName = createDefaultObjectName();
ObjectInstance objectInstance = this.server.getObjectInstance(objectName);
assertThat(objectInstance).as("Lifecycle bean should have been registered").isNotNull();
});
}
@Test
void notRegisteredByDefaultWhenThereAreMultipleMBeanExporters() {
this.contextRunner.withUserConfiguration(MultipleMBeanExportersConfiguration.class)
.run((context) -> assertThatExceptionOfType(InstanceNotFoundException.class)
.isThrownBy(() -> this.server.getObjectInstance(createDefaultObjectName())));
}
@Test
void registeredWithPropertyWhenThereAreMultipleMBeanExporters() {
this.contextRunner.withUserConfiguration(MultipleMBeanExportersConfiguration.class)
.withPropertyValues(ENABLE_ADMIN_PROP)
.run((context) -> {
ObjectName objectName = createDefaultObjectName();
ObjectInstance objectInstance = this.server.getObjectInstance(objectName);
assertThat(objectInstance).as("Lifecycle bean should have been registered").isNotNull();
});
}
@Test
void registerWithCustomJmxNameWhenThereAreMultipleMBeanExporters() {
String customJmxName = "org.acme:name=FooBar";
this.contextRunner.withUserConfiguration(MultipleMBeanExportersConfiguration.class)
.withSystemProperties("spring.application.admin.jmx-name=" + customJmxName)
.withPropertyValues(ENABLE_ADMIN_PROP)
.run((context) -> {
try {
this.server.getObjectInstance(createObjectName(customJmxName));
}
catch (InstanceNotFoundException ex) {
fail("Admin MBean should have been exposed with custom name");
}
assertThatExceptionOfType(InstanceNotFoundException.class)
.isThrownBy(() -> this.server.getObjectInstance(createDefaultObjectName()));
});
}
@Test
void onlyRegisteredOnceWhenThereIsAChildContext() {
SpringApplicationBuilder parentBuilder = new SpringApplicationBuilder().web(WebApplicationType.NONE)
.sources(MultipleMBeanExportersConfiguration.class, SpringApplicationAdminJmxAutoConfiguration.class);
SpringApplicationBuilder childBuilder = parentBuilder
.child(MultipleMBeanExportersConfiguration.class, SpringApplicationAdminJmxAutoConfiguration.class)
.web(WebApplicationType.NONE);
try (ConfigurableApplicationContext parent = parentBuilder.run("--" + ENABLE_ADMIN_PROP);
ConfigurableApplicationContext child = childBuilder.run("--" + ENABLE_ADMIN_PROP)) {
BeanFactoryUtils.beanOfType(parent.getBeanFactory(), SpringApplicationAdminMXBeanRegistrar.class);
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() -> BeanFactoryUtils
.beanOfType(child.getBeanFactory(), SpringApplicationAdminMXBeanRegistrar.class));
}
}
private ObjectName createDefaultObjectName() {
return createObjectName(DEFAULT_JMX_NAME);
}
private ObjectName createObjectName(String jmxName) {
try {
return new ObjectName(jmxName);
}
catch (MalformedObjectNameException ex) {
throw new IllegalStateException("Invalid jmx name " + jmxName, ex);
}
}
@Configuration(proxyBeanMethods = false)
static class MultipleMBeanExportersConfiguration {
@Bean
MBeanExporter firstMBeanExporter() {
return new MBeanExporter();
}
@Bean
MBeanExporter secondMBeanExporter() {
return new MBeanExporter();
}
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free