462be4bd5f2e28707fe4035c75e5e4882ee962d2
[integration.git] /
1 package org.onap.pnfsimulator.netconfmonitor.netconf;
2
3 import static org.junit.jupiter.api.Assertions.assertEquals;
4 import static org.junit.jupiter.api.Assertions.assertFalse;
5
6 import java.io.File;
7 import java.io.IOException;
8 import java.nio.file.Files;
9 import java.nio.file.Paths;
10 import org.apache.commons.io.FileUtils;
11 import org.junit.Rule;
12 import org.junit.jupiter.api.Test;
13 import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport;
14 import org.junit.rules.TemporaryFolder;
15
16 @EnableRuleMigrationSupport
17 class NetconfConfigurationWriterTest {
18
19     private static final String TEST_CONFIGURATION = "test-configuration";
20
21     @Rule
22     public TemporaryFolder temporaryFolder = new TemporaryFolder();
23
24     @Test
25     void writeToFile_should_write_sample_config_when_directory_exists() throws IOException {
26         File file = temporaryFolder.newFolder("temp");
27         NetconfConfigurationWriter configurationWriter = new NetconfConfigurationWriter(file.getPath());
28
29         configurationWriter.writeToFile(TEST_CONFIGURATION);
30
31         File[] files = file.listFiles();
32         assertEquals(1, files.length);
33
34         String content = FileUtils.readFileToString(files[0], "UTF-8");
35         assertEquals(TEST_CONFIGURATION, content);
36     }
37
38     @Test
39     void writeToFile_should_not_write_config_when_directory_doesnt_exist() {
40         String logFolderPath = "/not/existing/logs";
41         NetconfConfigurationWriter configurationWriter = new NetconfConfigurationWriter(logFolderPath);
42
43         configurationWriter.writeToFile(TEST_CONFIGURATION);
44
45         assertFalse(Files.exists(Paths.get(logFolderPath)));
46     }
47 }