Search in sources :

Example 6 with MBeanExporter

use of org.springframework.jmx.export.MBeanExporter in project spring-boot by spring-projects.

the class EndpointMBeanExporterTests method testSkipRegistrationOfDisabledEndpoint.

@Test
public void testSkipRegistrationOfDisabledEndpoint() throws Exception {
    this.context = new GenericApplicationContext();
    this.context.registerBeanDefinition("endpointMbeanExporter", new RootBeanDefinition(EndpointMBeanExporter.class));
    MutablePropertyValues mpv = new MutablePropertyValues();
    mpv.add("enabled", Boolean.FALSE);
    this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(TestEndpoint.class, null, mpv));
    this.context.refresh();
    MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
    assertThat(mbeanExporter.getServer().isRegistered(getObjectName("endpoint1", this.context))).isFalse();
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) MBeanExporter(org.springframework.jmx.export.MBeanExporter) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Example 7 with MBeanExporter

use of org.springframework.jmx.export.MBeanExporter in project spring-boot by spring-projects.

the class EndpointMBeanExporterTests method testRegistrationTwoEndpoints.

@Test
public void testRegistrationTwoEndpoints() throws Exception {
    this.context = new GenericApplicationContext();
    this.context.registerBeanDefinition("endpointMbeanExporter", new RootBeanDefinition(EndpointMBeanExporter.class));
    this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(TestEndpoint.class));
    this.context.registerBeanDefinition("endpoint2", new RootBeanDefinition(TestEndpoint2.class));
    this.context.refresh();
    MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
    assertThat(mbeanExporter.getServer().getMBeanInfo(getObjectName("endpoint1", this.context))).isNotNull();
    assertThat(mbeanExporter.getServer().getMBeanInfo(getObjectName("endpoint2", this.context))).isNotNull();
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) MBeanExporter(org.springframework.jmx.export.MBeanExporter) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Example 8 with MBeanExporter

use of org.springframework.jmx.export.MBeanExporter in project spring-boot by spring-projects.

the class EndpointMBeanExporterTests method testRegistrationWithDifferentDomainAndIdentity.

@Test
public void testRegistrationWithDifferentDomainAndIdentity() throws Exception {
    Map<String, Object> properties = new HashMap<>();
    properties.put("domain", "test-domain");
    properties.put("ensureUniqueRuntimeObjectNames", true);
    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(getObjectName("test-domain", "endpoint1", true, this.context))).isNotNull();
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) MBeanExporter(org.springframework.jmx.export.MBeanExporter) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 9 with MBeanExporter

use of org.springframework.jmx.export.MBeanExporter in project spring-boot by spring-projects.

the class JndiDataSourceAutoConfigurationTests method standardDataSourceIsNotExcludedFromExport.

@SuppressWarnings("unchecked")
@Test
public void standardDataSourceIsNotExcludedFromExport() throws IllegalStateException, NamingException {
    DataSource dataSource = mock(DataSource.class);
    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).isEmpty();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Set(java.util.Set) MBeanExporter(org.springframework.jmx.export.MBeanExporter) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) BasicDataSource(org.apache.commons.dbcp2.BasicDataSource) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 10 with MBeanExporter

use of org.springframework.jmx.export.MBeanExporter in project av-service by dvoraka.

the class CoreConfig method mbeanExporter.

/**
     * Special MBeanExporter bean for integration tests.
     *
     * @return MBeanExporter with a different registration strategy
     */
@Bean
@Profile("itest")
public MBeanExporter mbeanExporter() {
    MBeanExporter exporter = new MBeanExporter();
    exporter.setRegistrationPolicy(RegistrationPolicy.REPLACE_EXISTING);
    return exporter;
}
Also used : MBeanExporter(org.springframework.jmx.export.MBeanExporter) Profile(org.springframework.context.annotation.Profile) Bean(org.springframework.context.annotation.Bean)

Aggregations

MBeanExporter (org.springframework.jmx.export.MBeanExporter)23 Test (org.junit.Test)21 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)11 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)11 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)7 HashMap (java.util.HashMap)6 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)5 LinkedHashMap (java.util.LinkedHashMap)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 EndpointMBeanExporter (org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter)4 Map (java.util.Map)2 Set (java.util.Set)2 MBeanInfo (javax.management.MBeanInfo)2 DataSource (javax.sql.DataSource)2 BasicDataSource (org.apache.commons.dbcp2.BasicDataSource)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2 IJmxTestBean (org.springframework.jmx.IJmxTestBean)2 MockEnvironment (org.springframework.mock.env.MockEnvironment)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SimpleDateFormat (java.text.SimpleDateFormat)1