Search in sources :

Example 1 with TestClass

use of org.apache.aries.jmx.whiteboard.integration.helper.TestClass in project aries by apache.

the class MBeanServerTest method test_MServerBean.

@Test
public void test_MServerBean() throws Exception {
    final String instanceName = "simple.test.instance";
    final String objectNameString = "domain:instance=" + instanceName;
    final ObjectName objectName = new ObjectName(objectNameString);
    final TestClass testInstance = new TestClass(instanceName);
    // get or create the dynamic MBean Server
    final MBeanServer server = getOrCreateMBeanServer();
    // MBean server not registered as service, unknown object
    assertNotRegistered(server, objectName);
    // expect the MBean to be registered with the static server
    final ServiceRegistration mBeanReg = registerService(TestClassMBean.class.getName(), testInstance, objectNameString);
    // MBean server not registered, expect object to not be known
    assertNotRegistered(server, objectName);
    // register MBean server, expect MBean registered
    ServiceRegistration mBeanServerReg = registerMBeanServer(server);
    assertRegistered(server, objectName);
    // expect MBean to return expected value
    TestCase.assertEquals(instanceName, server.getAttribute(objectName, "InstanceName"));
    // unregister MBean server, expect MBean to be unregistered
    mBeanServerReg.unregister();
    assertNotRegistered(server, objectName);
    // unregister MBean, expect to not be registered any more
    mBeanReg.unregister();
    assertNotRegistered(server, objectName);
}
Also used : TestClassMBean(org.apache.aries.jmx.whiteboard.integration.helper.TestClassMBean) TestClass(org.apache.aries.jmx.whiteboard.integration.helper.TestClass) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer) ServiceRegistration(org.osgi.framework.ServiceRegistration) Test(org.junit.Test)

Example 2 with TestClass

use of org.apache.aries.jmx.whiteboard.integration.helper.TestClass in project aries by apache.

the class MBeanTest method test_simple_MBean_different_package.

@Test
public void test_simple_MBean_different_package() throws Exception {
    final String instanceName = "simple.test.instance.2";
    final String objectNameString = "domain:instance=" + instanceName;
    final ObjectName objectName = new ObjectName(objectNameString);
    final TestClass testInstance = new TestClass2(instanceName);
    final MBeanServer server = getStaticMBeanServer();
    // expect MBean to not be registered yet
    assertNotRegistered(server, objectName);
    // expect the MBean to be registered with the static server
    final ServiceRegistration reg = registerService(TestClassMBean.class.getName(), testInstance, objectNameString);
    assertRegistered(server, objectName);
    // expect MBean to return expected value
    TestCase.assertEquals(instanceName, server.getAttribute(objectName, "InstanceName"));
    // unregister MBean, expect to not be registered any more
    reg.unregister();
    assertNotRegistered(server, objectName);
}
Also used : TestClassMBean(org.apache.aries.jmx.whiteboard.integration.helper.TestClassMBean) TestClass(org.apache.aries.jmx.whiteboard.integration.helper.TestClass) TestClass2(org.apache.aries.jmx.whiteboard.integration.helper2.TestClass2) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer) ServiceRegistration(org.osgi.framework.ServiceRegistration) Test(org.junit.Test)

Example 3 with TestClass

use of org.apache.aries.jmx.whiteboard.integration.helper.TestClass in project aries by apache.

the class MBeanTest method test_simple_MBean.

@Test
public void test_simple_MBean() throws Exception {
    final String instanceName = "simple.test.instance";
    final String objectNameString = "domain:instance=" + instanceName;
    final ObjectName objectName = new ObjectName(objectNameString);
    final TestClass testInstance = new TestClass(instanceName);
    final MBeanServer server = getStaticMBeanServer();
    // expect MBean to not be registered yet
    assertNotRegistered(server, objectName);
    // expect the MBean to be registered with the static server
    final ServiceRegistration reg = registerService(TestClassMBean.class.getName(), testInstance, objectNameString);
    assertRegistered(server, objectName);
    // expect MBean to return expected value
    TestCase.assertEquals(instanceName, server.getAttribute(objectName, "InstanceName"));
    // unregister MBean, expect to not be registered any more
    reg.unregister();
    assertNotRegistered(server, objectName);
}
Also used : TestClassMBean(org.apache.aries.jmx.whiteboard.integration.helper.TestClassMBean) TestClass(org.apache.aries.jmx.whiteboard.integration.helper.TestClass) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer) ServiceRegistration(org.osgi.framework.ServiceRegistration) Test(org.junit.Test)

Aggregations

MBeanServer (javax.management.MBeanServer)3 ObjectName (javax.management.ObjectName)3 TestClass (org.apache.aries.jmx.whiteboard.integration.helper.TestClass)3 TestClassMBean (org.apache.aries.jmx.whiteboard.integration.helper.TestClassMBean)3 Test (org.junit.Test)3 ServiceRegistration (org.osgi.framework.ServiceRegistration)3 TestClass2 (org.apache.aries.jmx.whiteboard.integration.helper2.TestClass2)1