You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by jo...@apache.org on 2020/01/19 02:03:42 UTC

[nifi] branch master updated: NIFI-6882 from plain patch file in JIRA contributed by 'Josh' Removed tests which created dirs outside target location and which do not appear unit testable.

This is an automated email from the ASF dual-hosted git repository.

joewitt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/master by this push:
     new 0789ec3  NIFI-6882 from plain patch file in JIRA contributed by 'Josh' Removed tests which created dirs outside target location and which do not appear unit testable.
0789ec3 is described below

commit 0789ec3a6b8a3a56afdb2f844937b0b39729aa3d
Author: Joe Witt <jo...@apache.org>
AuthorDate: Sat Jan 18 14:57:09 2020 -0500

    NIFI-6882 from plain patch file in JIRA contributed by 'Josh'
    Removed tests which created dirs outside target location and which do not appear unit testable.
---
 .../apache/nifi/processors/standard/PutFile.java   |  2 +-
 .../nifi/processors/standard/TestPutFile.java      | 34 ++++++++++++++++++++++
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutFile.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutFile.java
index 73caa69..cdb7cba 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutFile.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutFile.java
@@ -229,7 +229,7 @@ public class PutFile extends AbstractProcessor {
 
         Path tempDotCopyFile = null;
         try {
-            final Path rootDirPath = configuredRootDirPath;
+            final Path rootDirPath = configuredRootDirPath.toAbsolutePath();
             String filename = flowFile.getAttribute(CoreAttributes.FILENAME.key());
             final Path tempCopyFile = rootDirPath.resolve("." + filename);
             final Path copyFile = rootDirPath.resolve(filename);
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutFile.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutFile.java
index 3440c44..0c202c1 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutFile.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutFile.java
@@ -85,6 +85,40 @@ public class TestPutFile {
     }
 
     @Test
+    public void testCreateRelativeDirectory() throws IOException {
+        final TestRunner runner = TestRunners.newTestRunner(new PutFile());
+        String newDir = TARGET_DIRECTORY + "/new-folder";
+        runner.setProperty(PutFile.DIRECTORY, newDir);
+        runner.setProperty(PutFile.CONFLICT_RESOLUTION, PutFile.REPLACE_RESOLUTION);
+
+        Map<String, String> attributes = new HashMap<>();
+        attributes.put(CoreAttributes.FILENAME.key(), "targetFile.txt");
+        runner.enqueue("Hello world!!".getBytes(), attributes);
+        runner.run();
+        runner.assertAllFlowFilesTransferred(FetchFile.REL_SUCCESS, 1);
+        Path targetPath = Paths.get(newDir + "/targetFile.txt");
+        byte[] content = Files.readAllBytes(targetPath);
+        assertEquals("Hello world!!", new String(content));
+    }
+
+    @Test(expected = AssertionError.class)
+    public void testCreateEmptyStringDirectory() throws IOException {
+        final TestRunner runner = TestRunners.newTestRunner(new PutFile());
+        String newDir = "";
+        runner.setProperty(PutFile.DIRECTORY, newDir);
+        runner.setProperty(PutFile.CONFLICT_RESOLUTION, PutFile.REPLACE_RESOLUTION);
+
+        Map<String, String> attributes = new HashMap<>();
+        attributes.put(CoreAttributes.FILENAME.key(), "targetFile.txt");
+        runner.enqueue("Hello world!!".getBytes(), attributes);
+        runner.run();
+        runner.assertAllFlowFilesTransferred(FetchFile.REL_SUCCESS, 1);
+        Path targetPath = Paths.get(newDir + "/targetFile.txt");
+        byte[] content = Files.readAllBytes(targetPath);
+        assertEquals("Hello world!!", new String(content));
+    }
+
+    @Test
     public void testReplaceConflictResolution() throws IOException {
         final TestRunner runner = TestRunners.newTestRunner(new PutFile());
         runner.setProperty(PutFile.DIRECTORY, targetDir.getAbsolutePath());