Search in sources :

Example 1 with MBeanExporter

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

the class EndpointMBeanExportAutoConfigurationTests method testEndpointMBeanExporterIsNotInstalledIfNestedInManagedResource.

@Test
public void testEndpointMBeanExporterIsNotInstalledIfNestedInManagedResource() throws Exception {
    this.context = new AnnotationConfigApplicationContext();
    this.context.register(TestConfiguration.class, JmxAutoConfiguration.class, NestedInManagedEndpoint.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();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) EndpointMBeanExporter(org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter) MBeanExporter(org.springframework.jmx.export.MBeanExporter) Test(org.junit.Test)

Example 2 with MBeanExporter

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

the class EndpointMBeanExportAutoConfigurationTests method testEndpointMBeanExporterWithProperties.

@Test
public void testEndpointMBeanExporterWithProperties() throws IntrospectionException, InstanceNotFoundException, MalformedObjectNameException, ReflectionException {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("endpoints.jmx.domain", "test-domain");
    environment.setProperty("endpoints.jmx.unique_names", "true");
    environment.setProperty("endpoints.jmx.static_names", "key1=value1, key2=value2");
    this.context = new AnnotationConfigApplicationContext();
    this.context.setEnvironment(environment);
    this.context.register(JmxAutoConfiguration.class, EndpointAutoConfiguration.class, EndpointMBeanExportAutoConfiguration.class);
    this.context.refresh();
    this.context.getBean(EndpointMBeanExporter.class);
    MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
    assertThat(mbeanExporter.getServer().getMBeanInfo(ObjectNameManager.getInstance(getObjectName("test-domain", "healthEndpoint", this.context).toString() + ",key1=value1,key2=value2"))).isNotNull();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MockEnvironment(org.springframework.mock.env.MockEnvironment) EndpointMBeanExporter(org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter) MBeanExporter(org.springframework.jmx.export.MBeanExporter) Test(org.junit.Test)

Example 3 with MBeanExporter

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

the class EndpointMBeanExportAutoConfigurationTests method testEndpointMBeanExporterIsInstalled.

@Test
public void testEndpointMBeanExporterIsInstalled() throws Exception {
    this.context = new AnnotationConfigApplicationContext();
    this.context.register(TestConfiguration.class, JmxAutoConfiguration.class, EndpointAutoConfiguration.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)).isNotEmpty();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) EndpointMBeanExporter(org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter) MBeanExporter(org.springframework.jmx.export.MBeanExporter) Test(org.junit.Test)

Example 4 with MBeanExporter

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

the class EndpointMBeanExporterTests method testRegistrationWithDifferentDomain.

@Test
public void testRegistrationWithDifferentDomain() throws Exception {
    this.context = new GenericApplicationContext();
    this.context.registerBeanDefinition("endpointMbeanExporter", new RootBeanDefinition(EndpointMBeanExporter.class, null, new MutablePropertyValues(Collections.singletonMap("domain", "test-domain"))));
    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", false, this.context))).isNotNull();
}
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 5 with MBeanExporter

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

the class EndpointMBeanExporterTests method loggerEndpointLowerCaseLogLevel.

@Test
public void loggerEndpointLowerCaseLogLevel() throws Exception {
    MBeanExporter mbeanExporter = registerLoggersEndpoint();
    Object response = mbeanExporter.getServer().invoke(getObjectName("loggersEndpoint", this.context), "setLogLevel", new Object[] { "com.example", "trace" }, new String[] { String.class.getName(), String.class.getName() });
    assertThat(response).isNull();
}
Also used : MBeanExporter(org.springframework.jmx.export.MBeanExporter) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

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