exceptionfactory commented on code in PR #11495:
URL: https://github.com/apache/nifi/pull/11495#discussion_r3887802221


##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/pom.xml:
##########
@@ -38,6 +38,21 @@
             <artifactId>nifi-standard-record-utils</artifactId>
             <version>2.11.0-SNAPSHOT</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.nifi</groupId>
+            <artifactId>nifi-resource-transfer</artifactId>
+            <version>2.11.0-SNAPSHOT</version>

Review Comment:
   The versions should be updated to `2.12.0-SNAPSHOT`.



##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutFile.java:
##########
@@ -244,6 +249,42 @@ public void testReplaceAndMaxFileLimitReach() throws 
IOException {
         assertEquals("Another file", new String(content));
     }
 
+    @Test
+    public void testPutFileFromLocalFile() throws Exception {
+        final TestRunner runner = TestRunners.newTestRunner(new PutFile());
+        runner.setProperty(PutFile.DIRECTORY, targetDir.getAbsolutePath());
+        runner.setProperty(PutFile.CONFLICT_RESOLUTION, 
PutFile.REPLACE_RESOLUTION);
+
+        final String attributeName = "file.path";
+        final String serviceId = FileResourceService.class.getSimpleName();
+        final FileResourceService service = new StandardFileResourceService();
+        runner.addControllerService(serviceId, service);
+        runner.setProperty(service, StandardFileResourceService.FILE_PATH, 
String.format("${%s}", attributeName));
+        runner.enableControllerService(service);
+
+        
runner.setProperty(ResourceTransferProperties.RESOURCE_TRANSFER_SOURCE, 
ResourceTransferSource.FILE_RESOURCE_SERVICE.getValue());
+        runner.setProperty(ResourceTransferProperties.FILE_RESOURCE_SERVICE, 
serviceId);
+
+        final byte[] fileData = "0123456789".getBytes(StandardCharsets.UTF_8);
+        final Path tempFilePath = 
Files.createTempFile("PutFile_testPutFileFromLocalFile_", "");

Review Comment:
   This approach can leave files in the temporary directory. The JUnit TempDir 
annotation should be used to wire in a directory to the test method instead.



##########
nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutFile.java:
##########
@@ -304,7 +315,16 @@ public void onTrigger(final ProcessContext context, final 
ProcessSession session
                 }
             }
 
-            session.exportTo(flowFile, dotCopyFile, false);
+            final ResourceTransferSource resourceTransferSource = 
ResourceTransferSource.valueOf(
+                    context.getProperty(RESOURCE_TRANSFER_SOURCE).getValue());
+            final Optional<FileResource> fileResource = 
getFileResource(resourceTransferSource, context, flowFile.getAttributes());

Review Comment:
   This should use `asAllowableValue()` instead of 
`ResourceTransferSource.valueOf()`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to