ParentAwareNamingStrategyTests Class — spring-boot Architecture
Architecture documentation for the ParentAwareNamingStrategyTests class in ParentAwareNamingStrategyTests.java from the spring-boot codebase.
Entity Profile
Source Code
core/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jmx/ParentAwareNamingStrategyTests.java lines 35–103
class ParentAwareNamingStrategyTests {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner();
@Test
void objectNameMatchesManagedResourceByDefault() {
this.contextRunner.withBean("testManagedResource", TestManagedResource.class).run((context) -> {
ParentAwareNamingStrategy strategy = new ParentAwareNamingStrategy(new AnnotationJmxAttributeSource());
strategy.setApplicationContext(context);
assertThat(strategy.getObjectName(context.getBean("testManagedResource"), "testManagedResource")
.getKeyPropertyListString()).isEqualTo("type=something,name1=def,name2=ghi");
});
}
@Test
void uniqueObjectNameAddsIdentityProperty() {
this.contextRunner.withBean("testManagedResource", TestManagedResource.class).run((context) -> {
ParentAwareNamingStrategy strategy = new ParentAwareNamingStrategy(new AnnotationJmxAttributeSource());
strategy.setApplicationContext(context);
strategy.setEnsureUniqueRuntimeObjectNames(true);
Object resource = context.getBean("testManagedResource");
ObjectName objectName = strategy.getObjectName(resource, "testManagedResource");
assertThat(objectName.getDomain()).isEqualTo("ABC");
assertThat(objectName.getCanonicalKeyPropertyListString()).isEqualTo(
"identity=" + ObjectUtils.getIdentityHexString(resource) + ",name1=def,name2=ghi,type=something");
});
}
@Test
void sameBeanInParentContextAddsContextProperty() {
this.contextRunner.withBean("testManagedResource", TestManagedResource.class)
.run((parent) -> this.contextRunner.withBean("testManagedResource", TestManagedResource.class)
.withParent(parent)
.run((context) -> {
ParentAwareNamingStrategy strategy = new ParentAwareNamingStrategy(
new AnnotationJmxAttributeSource());
strategy.setApplicationContext(context);
Object resource = context.getBean("testManagedResource");
ObjectName objectName = strategy.getObjectName(resource, "testManagedResource");
assertThat(objectName.getDomain()).isEqualTo("ABC");
assertThat(objectName.getCanonicalKeyPropertyListString()).isEqualTo("context="
+ ObjectUtils.getIdentityHexString(context) + ",name1=def,name2=ghi,type=something");
}));
}
@Test
void uniqueObjectNameAndSameBeanInParentContextOnlyAddsIdentityProperty() {
this.contextRunner.withBean("testManagedResource", TestManagedResource.class)
.run((parent) -> this.contextRunner.withBean("testManagedResource", TestManagedResource.class)
.withParent(parent)
.run((context) -> {
ParentAwareNamingStrategy strategy = new ParentAwareNamingStrategy(
new AnnotationJmxAttributeSource());
strategy.setApplicationContext(context);
strategy.setEnsureUniqueRuntimeObjectNames(true);
Object resource = context.getBean("testManagedResource");
ObjectName objectName = strategy.getObjectName(resource, "testManagedResource");
assertThat(objectName.getDomain()).isEqualTo("ABC");
assertThat(objectName.getCanonicalKeyPropertyListString()).isEqualTo("identity="
+ ObjectUtils.getIdentityHexString(resource) + ",name1=def,name2=ghi,type=something");
}));
}
@ManagedResource(objectName = "ABC:type=something,name1=def,name2=ghi")
public static class TestManagedResource {
}
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free