use of org.springframework.jmx.export.MBeanExporter in project spring-boot by spring-projects.
the class EndpointMBeanExportAutoConfigurationTests method testEndpointMBeanExporterIsNotInstalledIfManagedResource.
@Test
public void testEndpointMBeanExporterIsNotInstalledIfManagedResource() throws Exception {
this.context = new AnnotationConfigApplicationContext();
this.context.register(TestConfiguration.class, JmxAutoConfiguration.class, ManagedEndpoint.class, EndpointMBeanExportAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
assertThat(this.context.getBean(EndpointMBeanExporter.class)).isNotNull();
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
assertThat(mbeanExporter.getServer().queryNames(getObjectName("*", "*,*", this.context), null)).isEmpty();
}
use of org.springframework.jmx.export.MBeanExporter in project spring-boot by spring-projects.
the class JndiDataSourceAutoConfigurationTests method mbeanDataSourceIsExcludedFromExport.
@SuppressWarnings("unchecked")
@Test
public void mbeanDataSourceIsExcludedFromExport() throws IllegalStateException, NamingException {
DataSource dataSource = new BasicDataSource();
configureJndi("foo", dataSource);
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.jndi-name:foo");
this.context.register(JndiDataSourceAutoConfiguration.class, MBeanExporterConfiguration.class);
this.context.refresh();
assertThat(this.context.getBean(DataSource.class)).isEqualTo(dataSource);
MBeanExporter exporter = this.context.getBean(MBeanExporter.class);
Set<String> excludedBeans = (Set<String>) new DirectFieldAccessor(exporter).getPropertyValue("excludedBeans");
assertThat(excludedBeans).containsExactly("dataSource");
}
use of org.springframework.jmx.export.MBeanExporter in project spring-boot by spring-projects.
the class JmxAutoConfigurationTests method testDefaultDomainConfiguredOnMBeanExport.
@Test
public void testDefaultDomainConfiguredOnMBeanExport() {
MockEnvironment env = new MockEnvironment();
env.setProperty("spring.jmx.enabled", "true");
env.setProperty("spring.jmx.default-domain", "my-test-domain");
this.context = new AnnotationConfigApplicationContext();
this.context.setEnvironment(env);
this.context.register(TestConfiguration.class, JmxAutoConfiguration.class);
this.context.refresh();
MBeanExporter mBeanExporter = this.context.getBean(MBeanExporter.class);
assertThat(mBeanExporter).isNotNull();
MetadataNamingStrategy naming = (MetadataNamingStrategy) ReflectionTestUtils.getField(mBeanExporter, "namingStrategy");
assertThat(ReflectionTestUtils.getField(naming, "defaultDomain")).isEqualTo("my-test-domain");
}
use of org.springframework.jmx.export.MBeanExporter in project spring-boot by spring-projects.
the class EndpointMBeanExporterTests method testRegistrationOfOneEndpoint.
@Test
public void testRegistrationOfOneEndpoint() throws Exception {
this.context = new GenericApplicationContext();
this.context.registerBeanDefinition("endpointMbeanExporter", new RootBeanDefinition(EndpointMBeanExporter.class));
this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(TestEndpoint.class));
this.context.refresh();
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
MBeanInfo mbeanInfo = mbeanExporter.getServer().getMBeanInfo(getObjectName("endpoint1", this.context));
assertThat(mbeanInfo).isNotNull();
assertThat(mbeanInfo.getOperations().length).isEqualTo(3);
assertThat(mbeanInfo.getAttributes().length).isEqualTo(3);
}
use of org.springframework.jmx.export.MBeanExporter in project spring-boot by spring-projects.
the class EndpointMBeanExporterTests method testRegistrationWithDifferentDomainAndIdentityAndStaticNames.
@Test
public void testRegistrationWithDifferentDomainAndIdentityAndStaticNames() throws Exception {
Map<String, Object> properties = new HashMap<>();
properties.put("domain", "test-domain");
properties.put("ensureUniqueRuntimeObjectNames", true);
Properties staticNames = new Properties();
staticNames.put("key1", "value1");
staticNames.put("key2", "value2");
properties.put("objectNameStaticProperties", staticNames);
this.context = new GenericApplicationContext();
this.context.registerBeanDefinition("endpointMbeanExporter", new RootBeanDefinition(EndpointMBeanExporter.class, null, new MutablePropertyValues(properties)));
this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(TestEndpoint.class));
this.context.refresh();
MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
assertThat(mbeanExporter.getServer().getMBeanInfo(ObjectNameManager.getInstance(getObjectName("test-domain", "endpoint1", true, this.context).toString() + ",key1=value1,key2=value2"))).isNotNull();
}
Aggregations