Search in sources :

Example 1 with ConfigurationFileException

use of org.codice.ddf.configuration.status.ConfigurationFileException in project ddf by codice.

the class ConfigurationAdminMigrationTest method testInitMovesFilesThatCannotBeReadToFailedDirectory.

@Test
public void testInitMovesFilesThatCannotBeReadToFailedDirectory() throws Exception {
    setUpTwoConfigFileIterator(configurationDirectoryStream);
    setUpConfigurationFileFactoryForTwoFiles();
    doThrow(new ConfigurationFileException("")).when(configFile1).createConfig();
    doThrow(new ConfigurationFileException("")).when(configFile2).createConfig();
    when(Files.move(CONFIG_PATH1, PROCESSED_DIRECTORY_PATH, REPLACE_EXISTING)).thenReturn(FAILED_DIRECTORY_PATH);
    when(Files.move(CONFIG_PATH2, PROCESSED_DIRECTORY_PATH, REPLACE_EXISTING)).thenReturn(FAILED_DIRECTORY_PATH);
    ConfigurationAdminMigration configurationAdminMigrator = new ConfigurationAdminMigration(configurationDirectoryStream, PROCESSED_DIRECTORY_PATH, FAILED_DIRECTORY_PATH, configurationFileFactory, configurationFilePoller, configurationAdmin, CONFIGURATION_FILE_EXTENSION);
    configurationAdminMigrator.init();
    verifyStatic();
    Files.move(CONFIG_PATH1, CONFIG_FILE_IN_FAILED_DIRECTORY.resolve(CONFIG_FILE_PATH1), REPLACE_EXISTING);
    Files.move(CONFIG_PATH2, CONFIG_FILE_IN_FAILED_DIRECTORY.resolve(CONFIG_FILE_PATH2), REPLACE_EXISTING);
    verify(configurationDirectoryStream).close();
}
Also used : ConfigurationFileException(org.codice.ddf.configuration.status.ConfigurationFileException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with ConfigurationFileException

use of org.codice.ddf.configuration.status.ConfigurationFileException in project ddf by codice.

the class ConfigurationAdminMigrationTest method testExportConfigurationFileException.

@Test(expected = MigrationException.class)
public void testExportConfigurationFileException() throws IOException, InvalidSyntaxException, ConfigurationFileException {
    when(configurationAdmin.listConfigurations(anyString())).thenReturn(new Configuration[] { configuration });
    ConfigurationAdminMigration configurationAdminMigration = createConfigurationAdminMigratorWithNoFiles();
    when(configurationFileFactory.createConfigurationFile((Dictionary<String, Object>) anyObject())).thenThrow(new ConfigurationFileException(""));
    configurationAdminMigration.export(EXPORTED_DIRECTORY_PATH);
}
Also used : ConfigurationFileException(org.codice.ddf.configuration.status.ConfigurationFileException) Matchers.anyObject(org.mockito.Matchers.anyObject) Matchers.anyString(org.mockito.Matchers.anyString) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with ConfigurationFileException

use of org.codice.ddf.configuration.status.ConfigurationFileException in project ddf by codice.

the class ConfigurationAdminMigrationTest method testNotifyFailsToMoveFileToFailedDirectory.

@Test
public void testNotifyFailsToMoveFileToFailedDirectory() throws Exception {
    doThrow(new ConfigurationFileException("")).when(configFile1).createConfig();
    ConfigurationAdminMigration configurationAdminMigration = createConfigurationAdminMigratorForNotify();
    configurationAdminMigration.notify(CONFIG_PATH1);
    verify(configurationFileFactory).createConfigurationFile(CONFIG_PATH1);
}
Also used : ConfigurationFileException(org.codice.ddf.configuration.status.ConfigurationFileException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with ConfigurationFileException

use of org.codice.ddf.configuration.status.ConfigurationFileException in project ddf by codice.

the class ConfigurationFileFactoryTest method testCreateConfigurationFileWhenConfigFileReadThrowsConfigurationFileException.

@Test(expected = ConfigurationFileException.class)
public void testCreateConfigurationFileWhenConfigFileReadThrowsConfigurationFileException() throws Exception {
    // Setup
    PersistenceStrategy mockPersistenceStrategy = mock(PersistenceStrategy.class);
    when(mockPersistenceStrategy.read(mockInputStream)).thenThrow(new ConfigurationFileException(""));
    ConfigurationFileFactory factory = new ConfigurationFileFactoryUnderTest(mockPersistenceStrategy, configAdmin);
    // Perform Test
    factory.createConfigurationFile(mockPath);
}
Also used : PersistenceStrategy(org.codice.ddf.configuration.persistence.PersistenceStrategy) ConfigurationFileException(org.codice.ddf.configuration.status.ConfigurationFileException) Test(org.junit.Test)

Example 5 with ConfigurationFileException

use of org.codice.ddf.configuration.status.ConfigurationFileException in project ddf by codice.

the class ManagedServiceFactoryConfigurationFile method createConfig.

@Override
public void createConfig() throws ConfigurationFileException {
    String factoryPid = getFactoryPid();
    try {
        Configuration configuration = configAdmin.createFactoryConfiguration(factoryPid, null);
        configuration.update(properties);
    } catch (IOException e) {
        String message = String.format("Unable to get or update Configuration for factory pid [%s].", factoryPid);
        LOGGER.info(message, e);
        throw new ConfigurationFileException(message, e);
    }
}
Also used : Configuration(org.osgi.service.cm.Configuration) ConfigurationFileException(org.codice.ddf.configuration.status.ConfigurationFileException) IOException(java.io.IOException)

Aggregations

ConfigurationFileException (org.codice.ddf.configuration.status.ConfigurationFileException)16 Test (org.junit.Test)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 IOException (java.io.IOException)4 Path (java.nio.file.Path)4 Configuration (org.osgi.service.cm.Configuration)3 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStreamReader (java.io.InputStreamReader)1 StandardCopyOption (java.nio.file.StandardCopyOption)1 ArrayList (java.util.ArrayList)1 Dictionary (java.util.Dictionary)1 PersistenceStrategy (org.codice.ddf.configuration.persistence.PersistenceStrategy)1 ExportMigrationException (org.codice.ddf.migration.ExportMigrationException)1 UnexpectedMigrationException (org.codice.ddf.migration.UnexpectedMigrationException)1 Matchers.anyObject (org.mockito.Matchers.anyObject)1 Matchers.anyString (org.mockito.Matchers.anyString)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1