From 73a368f861de76638daac6787eea310cd1010ba6 Mon Sep 17 00:00:00 2001 From: Sean Busbey Date: Wed, 29 Apr 2015 22:42:44 -0500 Subject: [PATCH] NIFI-561: FileBasedClusterNodeFirewallTest should rely on JUnit / Maven norms for test files. Signed-off-by: Mark Payne --- .../FileBasedClusterNodeFirewallTest.java | 26 ++++++------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/firewall/impl/FileBasedClusterNodeFirewallTest.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/firewall/impl/FileBasedClusterNodeFirewallTest.java index 8e92de85d9..5259f4f974 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/firewall/impl/FileBasedClusterNodeFirewallTest.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/firewall/impl/FileBasedClusterNodeFirewallTest.java @@ -17,18 +17,17 @@ package org.apache.nifi.cluster.firewall.impl; import java.io.File; -import java.io.IOException; import java.net.InetAddress; import java.net.UnknownHostException; -import org.apache.nifi.util.file.FileUtils; -import org.junit.After; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; public class FileBasedClusterNodeFirewallTest { @@ -42,6 +41,9 @@ public class FileBasedClusterNodeFirewallTest { private File restoreDirectory; + @Rule + public final TemporaryFolder temp = new TemporaryFolder(); + private static boolean badHostsDoNotResolve = false; /** @@ -62,20 +64,15 @@ public class FileBasedClusterNodeFirewallTest { @Before public void setup() throws Exception { - ipsConfig = new File("src/test/resources/org/apache/nifi/cluster/firewall/impl/ips.txt"); - emptyConfig = new File("src/test/resources/org/apache/nifi/cluster/firewall/impl/empty.txt"); + ipsConfig = new File(getClass().getResource("/org/apache/nifi/cluster/firewall/impl/ips.txt").toURI()); + emptyConfig = new File(getClass().getResource("/org/apache/nifi/cluster/firewall/impl/empty.txt").toURI()); - restoreDirectory = new File(System.getProperty("java.io.tmpdir") + "/firewall_restore"); + restoreDirectory = temp.newFolder("firewall_restore"); ipsFirewall = new FileBasedClusterNodeFirewall(ipsConfig, restoreDirectory); acceptAllFirewall = new FileBasedClusterNodeFirewall(emptyConfig); } - @After - public void teardown() throws IOException { - deleteFile(restoreDirectory); - } - /** * We have two garbage lines in our test config file, ensure they didn't get turned into hosts. */ @@ -133,11 +130,4 @@ public class FileBasedClusterNodeFirewallTest { acceptAllFirewall.isPermissible("abc")); } - private boolean deleteFile(final File file) { - if (file.isDirectory()) { - FileUtils.deleteFilesInDir(file, null, null, true, true); - } - return FileUtils.deleteFile(file, null, 10); - } - }