Search in sources :

Example 71 with Configuration

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);
}
Also used : Configuration(org.osgi.service.cm.Configuration) Test(org.junit.Test)

Example 72 with Configuration

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();
}
Also used : Configuration(org.osgi.service.cm.Configuration) Test(org.junit.Test)

Example 73 with Configuration

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);
}
Also used : Configuration(org.osgi.service.cm.Configuration) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.Test)

Example 74 with Configuration

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);
}
Also used : Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.Test)

Example 75 with Configuration

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;
}
Also used : Configuration(org.osgi.service.cm.Configuration) IOException(java.io.IOException)

Aggregations

Configuration (org.osgi.service.cm.Configuration)226 Test (org.junit.Test)85 Hashtable (java.util.Hashtable)75 IOException (java.io.IOException)55 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)49 Dictionary (java.util.Dictionary)36 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)19 ServiceReference (org.osgi.framework.ServiceReference)19 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)18 Matchers.anyString (org.mockito.Matchers.anyString)16 BundleContext (org.osgi.framework.BundleContext)15 RegistrySourceConfiguration (org.codice.ddf.registry.federationadmin.service.internal.RegistrySourceConfiguration)11 Map (java.util.Map)10 Bundle (org.osgi.framework.Bundle)10 File (java.io.File)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)9 Mockito.anyString (org.mockito.Mockito.anyString)9 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)8 SkipUnstableTest (org.codice.ddf.itests.common.annotations.SkipUnstableTest)7