Search in sources :

Example 16 with MBeanExporter

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

the class EndpointMBeanExporterTests method jsonListConversion.

@Test
public void jsonListConversion() throws Exception {
    this.context = new GenericApplicationContext();
    this.context.registerBeanDefinition("endpointMbeanExporter", new RootBeanDefinition(EndpointMBeanExporter.class));
    this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(JsonListConversionEndpoint.class));
    this.context.refresh();
    MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
    Object response = mbeanExporter.getServer().invoke(getObjectName("endpoint1", this.context), "getData", new Object[0], new String[0]);
    assertThat(response).isInstanceOf(List.class);
    assertThat(((List<?>) response).get(0)).isInstanceOf(Long.class);
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) MBeanExporter(org.springframework.jmx.export.MBeanExporter) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) List(java.util.List) Test(org.junit.Test)

Example 17 with MBeanExporter

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

the class EndpointMBeanExporterTests method loggerEndpointUnknownLogLevel.

@Test
public void loggerEndpointUnknownLogLevel() throws Exception {
    MBeanExporter mbeanExporter = registerLoggersEndpoint();
    this.thrown.expect(MBeanException.class);
    this.thrown.expectCause(hasMessage(containsString("No enum constant")));
    this.thrown.expectCause(hasMessage(containsString("LogLevel.INVALID")));
    mbeanExporter.getServer().invoke(getObjectName("loggersEndpoint", this.context), "setLogLevel", new Object[] { "com.example", "invalid" }, new String[] { String.class.getName(), String.class.getName() });
}
Also used : MBeanExporter(org.springframework.jmx.export.MBeanExporter) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 18 with MBeanExporter

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

the class EndpointMBeanExporterTests method testRegistrationWithParentContext.

@Test
public void testRegistrationWithParentContext() throws Exception {
    this.context = new GenericApplicationContext();
    this.context.registerBeanDefinition("endpointMbeanExporter", new RootBeanDefinition(EndpointMBeanExporter.class));
    this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(TestEndpoint.class));
    GenericApplicationContext parent = new GenericApplicationContext();
    this.context.setParent(parent);
    parent.refresh();
    this.context.refresh();
    MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
    assertThat(mbeanExporter.getServer().getMBeanInfo(getObjectName("endpoint1", this.context))).isNotNull();
    parent.close();
}
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 19 with MBeanExporter

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

the class EndpointMBeanExporterTests method jsonMapConversionWithDefaultObjectMapper.

@Test
public void jsonMapConversionWithDefaultObjectMapper() throws Exception {
    this.context = new GenericApplicationContext();
    this.context.registerBeanDefinition("endpointMbeanExporter", new RootBeanDefinition(EndpointMBeanExporter.class));
    this.context.registerBeanDefinition("endpoint1", new RootBeanDefinition(JsonMapConversionEndpoint.class));
    this.context.refresh();
    MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
    Object response = mbeanExporter.getServer().invoke(getObjectName("endpoint1", this.context), "getData", new Object[0], new String[0]);
    assertThat(response).isInstanceOf(Map.class);
    assertThat(((Map<?, ?>) response).get("date")).isInstanceOf(Long.class);
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) MBeanExporter(org.springframework.jmx.export.MBeanExporter) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.junit.Test)

Example 20 with MBeanExporter

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

the class EndpointMBeanExporterTests method testRegistrationOfEnabledEndpoint.

@Test
public void testRegistrationOfEnabledEndpoint() throws Exception {
    this.context = new GenericApplicationContext();
    this.context.registerBeanDefinition("endpointMbeanExporter", new RootBeanDefinition(EndpointMBeanExporter.class));
    MutablePropertyValues mpv = new MutablePropertyValues();
    mpv.add("enabled", Boolean.TRUE);
    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))).isTrue();
}
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)

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