use of org.osgi.service.cm.Configuration in project ddf by codice.
the class ConfigurationAdminTest method testSetBundleLocation.
/**
* Tests the {@link ConfigurationAdmin#setBundleLocation(String, String)} method
*
* @throws Exception
*/
@Test
public void testSetBundleLocation() throws Exception {
org.osgi.service.cm.ConfigurationAdmin testConfigAdmin = mock(org.osgi.service.cm.ConfigurationAdmin.class);
ConfigurationAdmin configAdmin = new ConfigurationAdmin(testConfigAdmin);
Configuration testConfig = mock(Configuration.class);
when(testConfigAdmin.getConfiguration(TEST_PID, null)).thenReturn(testConfig);
configAdmin.setBundleLocation(TEST_PID, TEST_LOCATION);
verify(testConfig).setBundleLocation(TEST_LOCATION);
}
use of org.osgi.service.cm.Configuration in project ddf by codice.
the class ConfigurationAdminTest method testDeleteConfigurations.
/**
* Tests the {@link ConfigurationAdmin#deleteConfigurations(String)} method
*
* @throws Exception
*/
@Test
public void testDeleteConfigurations() throws Exception {
org.osgi.service.cm.ConfigurationAdmin testConfigAdmin = mock(org.osgi.service.cm.ConfigurationAdmin.class);
ConfigurationAdmin configAdmin = new ConfigurationAdmin(testConfigAdmin);
Configuration testConfig = mock(Configuration.class);
when(testConfigAdmin.listConfigurations(anyString())).thenReturn(new Configuration[] { testConfig });
configAdmin.deleteConfigurations(TEST_FILTER_1);
verify(testConfigAdmin).listConfigurations(TEST_FILTER_1);
verify(testConfig).delete();
}
use of org.osgi.service.cm.Configuration in project ddf by codice.
the class ConfigurationAdminTest method testCreateFactoryConfiguration.
/**
* Tests the {@link ConfigurationAdmin#createFactoryConfiguration(String)} and
* {@link ConfigurationAdmin#createFactoryConfigurationForLocation(String, String)} methods
*
* @throws Exception
*/
@Test
public void testCreateFactoryConfiguration() throws Exception {
org.osgi.service.cm.ConfigurationAdmin testConfigAdmin = mock(org.osgi.service.cm.ConfigurationAdmin.class);
ConfigurationAdmin configAdmin = new ConfigurationAdmin(testConfigAdmin, configurationAdminExt);
Configuration testConfig = mock(Configuration.class);
when(testConfig.getPid()).thenReturn(TEST_PID);
when(testConfigAdmin.createFactoryConfiguration(TEST_PID)).thenReturn(testConfig);
String config = configAdmin.createFactoryConfiguration(TEST_PID);
assertNotNull(config);
assertEquals(TEST_PID, config);
}
use of org.osgi.service.cm.Configuration in project ddf by codice.
the class ConfigurationAdminTest method testDisableConfiguration.
/**
* Tests the {@link ConfigurationAdmin#disableConfiguration(String)} method
*
* @throws Exception
*/
@Test
public void testDisableConfiguration() throws Exception {
org.osgi.service.cm.ConfigurationAdmin testConfigAdmin = mock(org.osgi.service.cm.ConfigurationAdmin.class);
ConfigurationAdminExt configAdminExt = new ConfigurationAdminExt(testConfigAdmin) {
@Override
public boolean isPermittedToViewService(String servicePid) {
return true;
}
};
ConfigurationAdmin configAdmin = new ConfigurationAdmin(testConfigAdmin, configAdminExt);
Configuration testConfig = mock(Configuration.class);
Configuration testFactoryConfig = mock(Configuration.class);
Dictionary<String, Object> testProperties = new Hashtable<>();
testProperties.put(org.osgi.service.cm.ConfigurationAdmin.SERVICE_FACTORYPID, TEST_FACTORY_PID);
when(testConfigAdmin.listConfigurations('(' + Constants.SERVICE_PID + '=' + TEST_PID + ')')).thenReturn(new Configuration[] { testConfig });
when(testConfigAdmin.createFactoryConfiguration(TEST_FACT_PID_DISABLED, null)).thenReturn(testFactoryConfig);
when(testConfig.getProperties()).thenReturn(testProperties);
when(testFactoryConfig.getPid()).thenReturn(TEST_FACT_PID_DISABLED);
Map<String, Object> result = configAdmin.disableConfiguration(TEST_PID);
assertThat("Should show the pid in a disabled state.", (String) result.get("newFactoryPid"), is(TEST_FACT_PID_DISABLED));
assertThat("Should return the given original pid.", (String) result.get("originalFactoryPid"), is(TEST_FACTORY_PID));
verify(testConfig).delete();
verify(testFactoryConfig).update(testProperties);
}
use of org.osgi.service.cm.Configuration in project ddf by codice.
the class ConfigurationAdmin method getBundleLocation.
/**
* @see ConfigurationAdminMBean#getBundleLocation(java.lang.String)
*/
public String getBundleLocation(String pid) throws IOException {
if (StringUtils.isBlank(pid)) {
throw new IOException("Argument pid cannot be null or empty");
}
Configuration config = configurationAdmin.getConfiguration(pid, null);
String bundleLocation = (config.getBundleLocation() == null) ? "Configuration is not yet bound to a bundle location" : config.getBundleLocation();
return bundleLocation;
}
Aggregations