Search in sources :

Example 6 with ConfigurationCacheFileInfo

use of org.apache.nifi.minifi.c2.api.cache.ConfigurationCacheFileInfo in project nifi-minifi by apache.

the class FileSystemConfigurationCacheTest method getConfigurationTest.

@Test
public void getConfigurationTest() throws IOException, ConfigurationProviderException {
    final String pathRoot = "files";
    final String pathPattern = "config";
    FileSystemConfigurationCache cache = new FileSystemConfigurationCache(pathRoot, pathPattern);
    Map<String, List<String>> parameters = new HashMap<>();
    ConfigurationCacheFileInfo info = cache.getCacheFileInfo("text/yaml", parameters);
    WriteableConfiguration configuration = info.getConfiguration(1);
    assertEquals("config.text.yaml.v1", configuration.getName());
    assertEquals("1", configuration.getVersion());
    assertTrue(configuration.exists());
}
Also used : HashMap(java.util.HashMap) WriteableConfiguration(org.apache.nifi.minifi.c2.api.cache.WriteableConfiguration) FileSystemConfigurationCache(org.apache.nifi.minifi.c2.cache.filesystem.FileSystemConfigurationCache) List(java.util.List) ConfigurationCacheFileInfo(org.apache.nifi.minifi.c2.api.cache.ConfigurationCacheFileInfo) Test(org.junit.Test)

Example 7 with ConfigurationCacheFileInfo

use of org.apache.nifi.minifi.c2.api.cache.ConfigurationCacheFileInfo in project nifi-minifi by apache.

the class FileSystemConfigurationCacheTest method getCachedConfigurationsTest.

@Test
public void getCachedConfigurationsTest() throws IOException, ConfigurationProviderException {
    final String pathRoot = "files";
    final String pathPattern = "config";
    FileSystemConfigurationCache cache = new FileSystemConfigurationCache(pathRoot, pathPattern);
    Map<String, List<String>> parameters = new HashMap<>();
    ConfigurationCacheFileInfo info = cache.getCacheFileInfo("text/yaml", parameters);
    Stream<WriteableConfiguration> configs = info.getCachedConfigurations();
    assertEquals(1, configs.count());
}
Also used : HashMap(java.util.HashMap) WriteableConfiguration(org.apache.nifi.minifi.c2.api.cache.WriteableConfiguration) FileSystemConfigurationCache(org.apache.nifi.minifi.c2.cache.filesystem.FileSystemConfigurationCache) List(java.util.List) ConfigurationCacheFileInfo(org.apache.nifi.minifi.c2.api.cache.ConfigurationCacheFileInfo) Test(org.junit.Test)

Example 8 with ConfigurationCacheFileInfo

use of org.apache.nifi.minifi.c2.api.cache.ConfigurationCacheFileInfo in project nifi-minifi by apache.

the class FileSystemConfigurationCacheTest method getNonexistantConfigurationTest.

@Test
public void getNonexistantConfigurationTest() throws IOException, ConfigurationProviderException {
    final String pathRoot = "files";
    final String pathPattern = "config";
    FileSystemConfigurationCache cache = new FileSystemConfigurationCache(pathRoot, pathPattern);
    Map<String, List<String>> parameters = new HashMap<>();
    ConfigurationCacheFileInfo info = cache.getCacheFileInfo("test/contenttype", parameters);
    WriteableConfiguration configuration = info.getConfiguration(1);
    assertEquals("config.test.contenttype.v1", configuration.getName());
    assertEquals("1", configuration.getVersion());
    assertFalse(configuration.exists());
}
Also used : HashMap(java.util.HashMap) WriteableConfiguration(org.apache.nifi.minifi.c2.api.cache.WriteableConfiguration) FileSystemConfigurationCache(org.apache.nifi.minifi.c2.cache.filesystem.FileSystemConfigurationCache) List(java.util.List) ConfigurationCacheFileInfo(org.apache.nifi.minifi.c2.api.cache.ConfigurationCacheFileInfo) Test(org.junit.Test)

Example 9 with ConfigurationCacheFileInfo

use of org.apache.nifi.minifi.c2.api.cache.ConfigurationCacheFileInfo in project nifi-minifi by apache.

the class DelegatingConfigurationProviderTest method testGetConfigurationDoesntExistWithNoVersion.

@Test
public void testGetConfigurationDoesntExistWithNoVersion() throws ConfigurationProviderException, IOException {
    parameters.remove("version");
    endpointPath = "/c2/config?class=raspi3&net=edge";
    initMocks();
    ConfigurationCacheFileInfo configurationCacheFileInfo = mock(ConfigurationCacheFileInfo.class);
    WriteableConfiguration configuration = mock(WriteableConfiguration.class);
    byte[] payload = "payload".getBytes(StandardCharsets.UTF_8);
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    when(httpURLConnection.getInputStream()).thenReturn(new ByteArrayInputStream(payload));
    when(configuration.getOutputStream()).thenReturn(output);
    when(httpURLConnection.getHeaderField("X-Content-Version")).thenReturn("2");
    when(configurationCache.getCacheFileInfo(contentType, parameters)).thenReturn(configurationCacheFileInfo);
    when(configurationCacheFileInfo.getConfiguration(version)).thenReturn(configuration);
    when(configuration.exists()).thenReturn(false);
    assertEquals(configuration, delegatingConfigurationProvider.getConfiguration(contentType, null, parameters));
    assertArrayEquals(payload, output.toByteArray());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) WriteableConfiguration(org.apache.nifi.minifi.c2.api.cache.WriteableConfiguration) ConfigurationCacheFileInfo(org.apache.nifi.minifi.c2.api.cache.ConfigurationCacheFileInfo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 10 with ConfigurationCacheFileInfo

use of org.apache.nifi.minifi.c2.api.cache.ConfigurationCacheFileInfo in project nifi-minifi by apache.

the class DelegatingConfigurationProviderTest method testGetConfigurationExistsWithNoVersion.

@Test
public void testGetConfigurationExistsWithNoVersion() throws ConfigurationProviderException {
    parameters.remove("version");
    endpointPath = "/c2/config?class=raspi3&net=edge";
    initMocks();
    ConfigurationCacheFileInfo configurationCacheFileInfo = mock(ConfigurationCacheFileInfo.class);
    WriteableConfiguration configuration = mock(WriteableConfiguration.class);
    when(httpURLConnection.getHeaderField("X-Content-Version")).thenReturn("2");
    when(configurationCache.getCacheFileInfo(contentType, parameters)).thenReturn(configurationCacheFileInfo);
    when(configurationCacheFileInfo.getConfiguration(version)).thenReturn(configuration);
    when(configuration.exists()).thenReturn(true);
    assertEquals(configuration, delegatingConfigurationProvider.getConfiguration(contentType, null, parameters));
}
Also used : WriteableConfiguration(org.apache.nifi.minifi.c2.api.cache.WriteableConfiguration) ConfigurationCacheFileInfo(org.apache.nifi.minifi.c2.api.cache.ConfigurationCacheFileInfo) Test(org.junit.Test)

Aggregations

ConfigurationCacheFileInfo (org.apache.nifi.minifi.c2.api.cache.ConfigurationCacheFileInfo)9 WriteableConfiguration (org.apache.nifi.minifi.c2.api.cache.WriteableConfiguration)9 Test (org.junit.Test)8 List (java.util.List)5 HashMap (java.util.HashMap)3 FileSystemConfigurationCache (org.apache.nifi.minifi.c2.cache.filesystem.FileSystemConfigurationCache)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 HttpURLConnection (java.net.HttpURLConnection)1 Path (java.nio.file.Path)1 Map (java.util.Map)1 ConfigurationProviderException (org.apache.nifi.minifi.c2.api.ConfigurationProviderException)1 InvalidParameterException (org.apache.nifi.minifi.c2.api.InvalidParameterException)1 Pair (org.apache.nifi.minifi.c2.api.util.Pair)1