Search in sources :

Example 1 with PersistenceStrategy

use of org.codice.ddf.configuration.persistence.PersistenceStrategy in project ddf by codice.

the class ConfigurationFileFactoryTest method testCreateConfigurationFileFromProperties.

@Test
public void testCreateConfigurationFileFromProperties() throws Exception {
    // Setup
    Dictionary<String, Object> properties = new Hashtable<>(1);
    properties.put(Constants.SERVICE_PID, PID);
    PersistenceStrategy mockPersistenceStrategy = getMockPersistenceStrategy(mockInputStream, properties);
    ConfigurationFileFactory factory = new ConfigurationFileFactoryUnderTest(mockPersistenceStrategy, configAdmin);
    // Perform Test
    ConfigurationFile configFile = factory.createConfigurationFile(properties);
    // Verify
    assertThat(configFile, instanceOf(ManagedServiceConfigurationFile.class));
}
Also used : PersistenceStrategy(org.codice.ddf.configuration.persistence.PersistenceStrategy) Hashtable(java.util.Hashtable) Test(org.junit.Test)

Example 2 with PersistenceStrategy

use of org.codice.ddf.configuration.persistence.PersistenceStrategy 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 3 with PersistenceStrategy

use of org.codice.ddf.configuration.persistence.PersistenceStrategy in project ddf by codice.

the class ConfigurationFileFactoryTest method testCreateConfigurationFileWhenConfigFileReadThrowsIOException.

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

Example 4 with PersistenceStrategy

use of org.codice.ddf.configuration.persistence.PersistenceStrategy in project ddf by codice.

the class ConfigurationFileFactoryTest method testCreateConfigurationFileNoServicePidOrFactoryPid.

@Test(expected = ConfigurationFileException.class)
public void testCreateConfigurationFileNoServicePidOrFactoryPid() throws Exception {
    // Setup
    Dictionary<String, Object> properties = new Hashtable<>(1);
    properties.put("prop1", "value1");
    PersistenceStrategy mockPersistenceStrategy = getMockPersistenceStrategy(mockInputStream, properties);
    ConfigurationFileFactory factory = new ConfigurationFileFactoryUnderTest(mockPersistenceStrategy, configAdmin);
    // Perform Test
    factory.createConfigurationFile(mockPath);
}
Also used : PersistenceStrategy(org.codice.ddf.configuration.persistence.PersistenceStrategy) Hashtable(java.util.Hashtable) Test(org.junit.Test)

Example 5 with PersistenceStrategy

use of org.codice.ddf.configuration.persistence.PersistenceStrategy in project ddf by codice.

the class ConfigurationFileFactoryTest method testCreateConfigurationFileFileNotFoundExceptionOnGetInputStream.

@Test(expected = ConfigurationFileException.class)
public void testCreateConfigurationFileFileNotFoundExceptionOnGetInputStream() throws Exception {
    // Setup
    Dictionary<String, Object> properties = new Hashtable<>(1);
    properties.put(Constants.SERVICE_PID, PID);
    PersistenceStrategy mockPersistenceStrategy = getMockPersistenceStrategy(mockInputStream, properties);
    ConfigurationFileFactory factory = new ConfigurationFileFactory(mockPersistenceStrategy, configAdmin) {

        @Override
        InputStream getInputStream(Path path) throws FileNotFoundException {
            throw new FileNotFoundException();
        }
    };
    // Perform Test
    factory.createConfigurationFile(mockPath);
}
Also used : Path(java.nio.file.Path) PersistenceStrategy(org.codice.ddf.configuration.persistence.PersistenceStrategy) Hashtable(java.util.Hashtable) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.Test)

Aggregations

PersistenceStrategy (org.codice.ddf.configuration.persistence.PersistenceStrategy)9 Test (org.junit.Test)8 Hashtable (java.util.Hashtable)5 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ConfigurationFileException (org.codice.ddf.configuration.status.ConfigurationFileException)1