mirror of
https://github.com/apache/nifi.git
synced 2025-03-07 01:49:19 +00:00
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 commit is contained in:
parent
71226ce077
commit
0789ec3a6b
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src
main/java/org/apache/nifi/processors/standard
test/java/org/apache/nifi/processors/standard
@ -229,7 +229,7 @@ public class PutFile extends AbstractProcessor {
|
|||||||
|
|
||||||
Path tempDotCopyFile = null;
|
Path tempDotCopyFile = null;
|
||||||
try {
|
try {
|
||||||
final Path rootDirPath = configuredRootDirPath;
|
final Path rootDirPath = configuredRootDirPath.toAbsolutePath();
|
||||||
String filename = flowFile.getAttribute(CoreAttributes.FILENAME.key());
|
String filename = flowFile.getAttribute(CoreAttributes.FILENAME.key());
|
||||||
final Path tempCopyFile = rootDirPath.resolve("." + filename);
|
final Path tempCopyFile = rootDirPath.resolve("." + filename);
|
||||||
final Path copyFile = rootDirPath.resolve(filename);
|
final Path copyFile = rootDirPath.resolve(filename);
|
||||||
|
@ -84,6 +84,40 @@ public class TestPutFile {
|
|||||||
assertEquals("Hello world!!", new String(content));
|
assertEquals("Hello world!!", new String(content));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
@Test
|
||||||
public void testReplaceConflictResolution() throws IOException {
|
public void testReplaceConflictResolution() throws IOException {
|
||||||
final TestRunner runner = TestRunners.newTestRunner(new PutFile());
|
final TestRunner runner = TestRunners.newTestRunner(new PutFile());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user