Search in sources :

Example 1 with AnnotationTestInstrumentation

use of org.apache.cxf.management.jmx.export.AnnotationTestInstrumentation in project cxf by apache.

the class JMXManagedComponentManagerTest method testRegisterInstrumentation.

@Test
public void testRegisterInstrumentation() throws Exception {
    AnnotationTestInstrumentation im = new AnnotationTestInstrumentation();
    ObjectName name = new ObjectName("org.apache.cxf:type=foo,name=bar");
    im.setName("John Smith");
    manager.register(im, name);
    Object val = manager.getMBeanServer().getAttribute(name, NAME_ATTRIBUTE);
    assertEquals("Incorrect result", "John Smith", val);
    try {
        manager.register(im, name);
        fail("Registering with existing name should fail.");
    } catch (JMException jmex) {
    // Expected
    }
    manager.register(im, name, true);
    val = manager.getMBeanServer().getAttribute(name, NAME_ATTRIBUTE);
    assertEquals("Incorrect result", "John Smith", val);
    manager.unregister(name);
    im.setName("Foo Bar");
    name = manager.register(im);
    val = manager.getMBeanServer().getAttribute(name, NAME_ATTRIBUTE);
    assertEquals("Incorrect result", "Foo Bar", val);
    try {
        manager.register(im);
        fail("Registering with existing name should fail.");
    } catch (JMException jmex) {
    // Expected
    }
    name = manager.register(im, true);
    val = manager.getMBeanServer().getAttribute(name, NAME_ATTRIBUTE);
    assertEquals("Incorrect result", "Foo Bar", val);
    manager.unregister(im);
}
Also used : AnnotationTestInstrumentation(org.apache.cxf.management.jmx.export.AnnotationTestInstrumentation) JMException(javax.management.JMException) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

JMException (javax.management.JMException)1 ObjectName (javax.management.ObjectName)1 AnnotationTestInstrumentation (org.apache.cxf.management.jmx.export.AnnotationTestInstrumentation)1 Test (org.junit.Test)1