Search in sources :

Example 1 with InterfaceB

use of org.apache.aries.jmx.test.bundleb.api.InterfaceB in project aries by apache.

the class ConfigurationAdminMBeanTest method testMBeanInterface.

@Ignore("ManagedServiceFactory tests failing.. " + "Some issues surrounding creating a factory configuration and then retrieving by pid to update.. Needs investigation")
@Test
@SuppressWarnings("unchecked")
public void testMBeanInterface() throws Exception {
    // get bundles
    Bundle a = getBundleByName("org.apache.aries.jmx.test.bundlea");
    // ManagedService operations
    assertNull(managedServiceA.getConfig());
    // create a configuration for A
    TabularData data = mbean.getProperties("org.apache.aries.jmx.test.ServiceA");
    assertEquals(0, data.size());
    PropertyData<String> p1 = PropertyData.newInstance("A1", "first");
    data.put(p1.toCompositeData());
    PropertyData<Integer> p2 = PropertyData.newInstance("A2", 2);
    data.put(p2.toCompositeData());
    mbean.update("org.apache.aries.jmx.test.ServiceA", data);
    Thread.sleep(1000);
    Dictionary<String, Object> config = managedServiceA.getConfig();
    assertNotNull(config);
    assertEquals(3, config.size());
    assertEquals("org.apache.aries.jmx.test.ServiceA", config.get(Constants.SERVICE_PID));
    assertEquals("first", config.get("A1"));
    assertEquals(2, config.get("A2"));
    //delete
    mbean.deleteForLocation("org.apache.aries.jmx.test.ServiceA", a.getLocation());
    Thread.sleep(1000);
    assertNull(managedServiceA.getConfig());
    // ManagedServiceFactory operations
    String cpid = mbean.createFactoryConfiguration("jmx.test.B.factory");
    assertNotNull(cpid);
    assertTrue(cpid.contains("jmx.test.B.factory"));
    TabularData fConfig = mbean.getProperties(cpid);
    assertNotNull(fConfig);
    assertEquals(0, fConfig.values().size());
    PropertyData<String> prop1 = PropertyData.newInstance("B1", "value1");
    fConfig.put(prop1.toCompositeData());
    PropertyData<Boolean> prop2 = PropertyData.newInstance("B2", true);
    fConfig.put(prop2.toCompositeData());
    mbean.update(cpid, fConfig);
    Thread.sleep(1000);
    InterfaceB configured = managedFactory.getConfigured(cpid);
    assertNotNull(configured);
    config = configured.getConfig();
    assertNotNull(config);
    assertTrue(config.size() >= 4);
    assertEquals("jmx.test.B.factory", config.get(ConfigurationAdmin.SERVICE_FACTORYPID));
    assertEquals(cpid, config.get(Constants.SERVICE_PID));
    assertEquals("value1", config.get("B1"));
    assertEquals("true", config.get("B2"));
    assertEquals("jmx.test.B.factory", mbean.getFactoryPid(cpid));
    mbean.delete(cpid);
    Thread.sleep(1000);
    assertNull(managedFactory.getConfigured(cpid));
    // list operations
    data = mbean.getProperties("org.apache.aries.jmx.test.ServiceA");
    assertEquals(0, data.size());
    p1 = PropertyData.newInstance("A1", "a1Value");
    data.put(p1.toCompositeData());
    mbean.update("org.apache.aries.jmx.test.ServiceA", data);
    Thread.sleep(1000);
    config = managedServiceA.getConfig();
    assertNotNull(config);
    assertEquals(2, config.size());
    assertEquals("org.apache.aries.jmx.test.ServiceA", config.get(Constants.SERVICE_PID));
    assertEquals("a1Value", config.get("A1"));
    String[][] configurations = mbean.getConfigurations("(A1=a1Value)");
    assertNotNull(configurations);
    assertEquals(1, configurations.length);
    assertEquals("org.apache.aries.jmx.test.ServiceA", configurations[0][0]);
    assertEquals(a.getLocation(), configurations[0][1]);
    // delete with filter
    mbean.deleteConfigurations("(A1=a1Value)");
    Thread.sleep(1000);
    assertNull(managedServiceA.getConfig());
}
Also used : InterfaceB(org.apache.aries.jmx.test.bundleb.api.InterfaceB) Bundle(org.osgi.framework.Bundle) TabularData(javax.management.openmbean.TabularData) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.jmx.AbstractIntegrationTest)

Aggregations

TabularData (javax.management.openmbean.TabularData)1 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)1 InterfaceB (org.apache.aries.jmx.test.bundleb.api.InterfaceB)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 Bundle (org.osgi.framework.Bundle)1