summaryrefslogtreecommitdiffstats
path: root/utils/src/test/java/org/onap
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2020-01-22 17:51:26 +0000
committerliamfallon <liam.fallon@est.tech>2020-01-22 17:51:30 +0000
commitb4f69e428f1677339ff432c27e2cb8bfa756114e (patch)
tree2730e2d03dd4817c16e7a7212ac899f666699809 /utils/src/test/java/org/onap
parentc22d70d8f2429747ac7eb991c8d83aa3be633d1b (diff)
Create path to text file being created
If you try and write to a file where part of the pat does not exist, that path should be created. Issue-ID: POLICY-1581 Change-Id: Ifb7a4ff4e1804814b6679956f0c58d5ac026c4a4 Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'utils/src/test/java/org/onap')
-rw-r--r--utils/src/test/java/org/onap/policy/common/utils/resources/TextFileUtilsTest.java22
1 files changed, 21 insertions, 1 deletions
diff --git a/utils/src/test/java/org/onap/policy/common/utils/resources/TextFileUtilsTest.java b/utils/src/test/java/org/onap/policy/common/utils/resources/TextFileUtilsTest.java
index 7f246ab2..0952b168 100644
--- a/utils/src/test/java/org/onap/policy/common/utils/resources/TextFileUtilsTest.java
+++ b/utils/src/test/java/org/onap/policy/common/utils/resources/TextFileUtilsTest.java
@@ -30,6 +30,7 @@ import org.junit.Test;
/**
* Test text file utilities.
+ *
* @author Liam Fallon (liam.fallon@est.tech)
*/
public class TextFileUtilsTest {
@@ -37,7 +38,7 @@ public class TextFileUtilsTest {
private static final String FILE_CONTENT = "This is the contents of a text file";
@Test
- public void test() throws IOException {
+ public void testPutToFile() throws IOException {
final File tempTextFile = File.createTempFile("Test", "txt");
TextFileUtils.putStringAsTextFile(FILE_CONTENT, tempTextFile.getAbsolutePath());
@@ -48,6 +49,25 @@ public class TextFileUtilsTest {
final FileInputStream fis = new FileInputStream(tempTextFile);
final String textFileString1 = TextFileUtils.getStreamAsString(fis);
assertEquals(textFileString0, textFileString1);
+ }
+
+ @Test
+ public void testPutToFileWithNewPath() throws IOException {
+ String tempDirAndFileName = System.getProperty("java.io.tmpdir") + "/non/existant/path/Test.txt";
+
+ TextFileUtils.putStringAsTextFile(FILE_CONTENT, tempDirAndFileName);
+
+ final String textFileString0 = TextFileUtils.getTextFileAsString(tempDirAndFileName);
+ assertEquals(FILE_CONTENT, textFileString0);
+
+ final FileInputStream fis = new FileInputStream(tempDirAndFileName);
+ final String textFileString1 = TextFileUtils.getStreamAsString(fis);
+ assertEquals(textFileString0, textFileString1);
+ File tempDirAndFile = new File(tempDirAndFileName);
+ tempDirAndFile.delete();
+ tempDirAndFile.getParentFile().delete();
+ tempDirAndFile.getParentFile().getParentFile().delete();
+ tempDirAndFile.getParentFile().getParentFile().getParentFile().delete();
}
}