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());
}
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());
}
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());
}
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());
}
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));
}
Aggregations