Search in sources :

Example 1 with ConfigurationStatus

use of org.codice.ddf.admin.core.api.ConfigurationStatus in project ddf by codice.

the class ConfigurationAdminImplTest method testEnableConfigurations.

/**
 * Tests the {@link AdminConsoleService#enableConfiguration(String)} method
 *
 * @throws Exception
 */
@Test
public void testEnableConfigurations() throws Exception {
    setUpListServices();
    when(testAttDef.getID()).thenReturn(TEST_KEY_IN_METATYPE);
    org.osgi.service.cm.ConfigurationAdmin testConfigAdmin = mock(org.osgi.service.cm.ConfigurationAdmin.class);
    ConfigurationAdminImpl configurationAdminImpl = getConfigurationAdminImpl(testConfigAdmin, new ArrayList<>());
    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_FACT_PID_DISABLED);
    testProperties.put(TEST_KEY_IN_METATYPE, TEST_VALUE);
    testProperties.put(INVALID_TEST_KEY, TEST_VALUE);
    when(testConfigAdmin.listConfigurations('(' + Constants.SERVICE_PID + '=' + TEST_PID + ')')).thenReturn(new Configuration[] { testConfig });
    when(testConfig.getProperties()).thenReturn(testProperties);
    when(testFactoryConfig.getPid()).thenReturn(TEST_FACTORY_PID);
    when(testConfigAdmin.createFactoryConfiguration(TEST_FACTORY_PID, null)).thenReturn(testFactoryConfig);
    ConfigurationStatus result = configurationAdminImpl.enableManagedServiceFactoryConfiguration(TEST_PID, testConfig);
    assertThat("Should show the pid in an enabled state.", (String) result.get("newFactoryPid"), is(TEST_FACTORY_PID));
    assertThat("Should show the original disabled pid.", (String) result.get("originalFactoryPid"), is(TEST_FACT_PID_DISABLED));
    Dictionary<String, Object> enabledProperties = new Hashtable<>();
    enabledProperties.put(org.osgi.service.cm.ConfigurationAdmin.SERVICE_FACTORYPID, TEST_FACTORY_PID);
    enabledProperties.put(TEST_KEY_IN_METATYPE, TEST_VALUE);
    verify(testConfig).delete();
    verify(testFactoryConfig).update(enabledProperties);
}
Also used : Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) ConfigurationStatus(org.codice.ddf.admin.core.api.ConfigurationStatus) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.Test)

Example 2 with ConfigurationStatus

use of org.codice.ddf.admin.core.api.ConfigurationStatus in project ddf by codice.

the class ConfigurationAdminImplTest method testDisableConfiguration.

/**
 * Tests the {@link AdminConsoleService#disableConfiguration(String)} method
 *
 * @throws Exception
 */
@Test
public void testDisableConfiguration() throws Exception {
    setUpListServices();
    when(testAttDef.getID()).thenReturn(TEST_KEY_IN_METATYPE);
    org.osgi.service.cm.ConfigurationAdmin testConfigAdmin = mock(org.osgi.service.cm.ConfigurationAdmin.class);
    ConfigurationAdminImpl configurationAdminImpl = getConfigurationAdminImpl(testConfigAdmin, new ArrayList<>());
    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);
    testProperties.put(TEST_KEY_IN_METATYPE, TEST_VALUE);
    testProperties.put(INVALID_TEST_KEY, TEST_VALUE);
    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);
    ConfigurationStatus result = configurationAdminImpl.disableManagedServiceFactoryConfiguration(TEST_PID, testConfig);
    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));
    Dictionary<String, Object> disabledProperties = new Hashtable<>();
    disabledProperties.put(org.osgi.service.cm.ConfigurationAdmin.SERVICE_FACTORYPID, TEST_FACT_PID_DISABLED);
    disabledProperties.put(TEST_KEY_IN_METATYPE, TEST_VALUE);
    verify(testConfig).delete();
    verify(testFactoryConfig).update(disabledProperties);
}
Also used : Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) ConfigurationStatus(org.codice.ddf.admin.core.api.ConfigurationStatus) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.Test)

Aggregations

Hashtable (java.util.Hashtable)2 ConfigurationStatus (org.codice.ddf.admin.core.api.ConfigurationStatus)2 Test (org.junit.Test)2 Mockito.anyString (org.mockito.Mockito.anyString)2 Configuration (org.osgi.service.cm.Configuration)2 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)2