use of org.osgi.service.cm.Configuration in project aries by apache.
the class ConfigurationAdmin method updateForLocation.
/**
* @see org.osgi.jmx.service.cm.ConfigurationAdminMBean#updateForLocation(java.lang.String, java.lang.String, javax.management.openmbean.TabularData)
*/
@SuppressWarnings("unchecked")
public void updateForLocation(String pid, String location, TabularData configurationTable) throws IOException {
if (pid == null || pid.length() < 1) {
throw new IOException("Argument pid cannot be null or empty");
}
if (configurationTable == null) {
throw new IOException("Argument configurationTable cannot be null");
}
if (!PROPERTIES_TYPE.equals(configurationTable.getTabularType())) {
throw new IOException("Invalid TabularType [" + configurationTable.getTabularType() + "]");
}
Dictionary<String, Object> configurationProperties = new Hashtable<String, Object>();
Collection<CompositeData> compositeData = (Collection<CompositeData>) configurationTable.values();
for (CompositeData row : compositeData) {
PropertyData<? extends Class<?>> propertyData = PropertyData.from(row);
configurationProperties.put(propertyData.getKey(), propertyData.getValue());
}
Configuration config = configurationAdmin.getConfiguration(pid, location);
config.update(configurationProperties);
}
use of org.osgi.service.cm.Configuration in project aries by apache.
the class ConnectionLifecycleTest method testDeleteOfConfig.
@Test
public void testDeleteOfConfig() throws Exception {
Assume.assumeTrue("Not a configuration test", isConfigured());
txControl.required(() -> connection.createStatement().execute("Insert into TEST_TABLE values ( 'Hello World!' )"));
assertEquals("Hello World!", txControl.notSupported(() -> {
ResultSet rs = connection.createStatement().executeQuery("Select * from TEST_TABLE");
rs.next();
return rs.getString(1);
}));
ConfigurationAdmin cm = getService(ConfigurationAdmin.class, 5000);
Configuration[] configurations = cm.listConfigurations("(service.factoryPid=org.apache.aries.tx.control.jdbc.*)");
assertNotNull(configurations);
assertEquals(1, configurations.length);
configurations[0].delete();
Thread.sleep(2000);
try {
assertEquals("Hello World!", txControl.notSupported(() -> {
ResultSet rs = connection.createStatement().executeQuery("Select * from TEST_TABLE");
rs.next();
return rs.getString(1);
}));
fail("Should not be accessible");
} catch (ScopedWorkException swe) {
assertTrue(swe.getCause().toString(), swe.getCause() instanceof TransactionException);
assertEquals("There was a problem getting hold of a database connection", swe.getCause().getMessage());
}
}
use of org.osgi.service.cm.Configuration in project aries by apache.
the class ConfigurationAdminTest method testGetFactoryPid.
@Test
public void testGetFactoryPid() throws Exception {
org.osgi.service.cm.ConfigurationAdmin admin = mock(org.osgi.service.cm.ConfigurationAdmin.class);
String factoryPid = "org.apache.aries.jmx.factory.mock";
Configuration config = mock(Configuration.class);
when(admin.getConfiguration(eq(factoryPid + "-1260133982371-0"), anyString())).thenReturn(config);
when(config.getFactoryPid()).thenReturn(factoryPid);
ConfigurationAdmin mbean = new ConfigurationAdmin(admin);
assertEquals(factoryPid, mbean.getFactoryPid(factoryPid + "-1260133982371-0"));
assertEquals(factoryPid, mbean.getFactoryPidForLocation(factoryPid + "-1260133982371-0", "location"));
}
use of org.osgi.service.cm.Configuration in project aries by apache.
the class ConfigurationAdminTest method testDeleteConfigurations.
@Test
public void testDeleteConfigurations() throws Exception {
org.osgi.service.cm.ConfigurationAdmin admin = mock(org.osgi.service.cm.ConfigurationAdmin.class);
String filter = "(" + Constants.SERVICE_PID + "=org.apache.aries.jmx.mock)";
Configuration a = mock(Configuration.class);
Configuration b = mock(Configuration.class);
when(admin.listConfigurations(filter)).thenReturn(new Configuration[] { a, b });
ConfigurationAdmin mbean = new ConfigurationAdmin(admin);
mbean.deleteConfigurations(filter);
verify(a).delete();
verify(b).delete();
}
use of org.osgi.service.cm.Configuration in project aries by apache.
the class ConfigurationAdminTest method testCreateFactoryConfiguration.
@Test
public void testCreateFactoryConfiguration() throws Exception {
org.osgi.service.cm.ConfigurationAdmin admin = mock(org.osgi.service.cm.ConfigurationAdmin.class);
String fpid = "org.apache.aries.jmx.mock.factory";
Configuration config = mock(Configuration.class);
when(admin.createFactoryConfiguration(eq(fpid))).thenReturn(config);
when(admin.createFactoryConfiguration(eq(fpid), anyString())).thenReturn(config);
when(config.getPid()).thenReturn(fpid + "-1260133982371-0");
ConfigurationAdmin mbean = new ConfigurationAdmin(admin);
assertEquals(fpid + "-1260133982371-0", mbean.createFactoryConfiguration(fpid));
assertEquals(fpid + "-1260133982371-0", mbean.createFactoryConfigurationForLocation(fpid, "/bundlex"));
}
Aggregations