1 package org.onap.pnfsimulator.netconfmonitor.netconf;
3 import static org.junit.jupiter.api.Assertions.assertEquals;
4 import static org.junit.jupiter.api.Assertions.assertFalse;
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;
16 @EnableRuleMigrationSupport
17 class NetconfConfigurationWriterTest {
19 private static final String TEST_CONFIGURATION = "test-configuration";
22 public TemporaryFolder temporaryFolder = new TemporaryFolder();
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());
29 configurationWriter.writeToFile(TEST_CONFIGURATION);
31 File[] files = file.listFiles();
32 assertEquals(1, files.length);
34 String content = FileUtils.readFileToString(files[0], "UTF-8");
35 assertEquals(TEST_CONFIGURATION, content);
39 void writeToFile_should_not_write_config_when_directory_doesnt_exist() {
40 String logFolderPath = "/not/existing/logs";
41 NetconfConfigurationWriter configurationWriter = new NetconfConfigurationWriter(logFolderPath);
43 configurationWriter.writeToFile(TEST_CONFIGURATION);
45 assertFalse(Files.exists(Paths.get(logFolderPath)));