NIFI-561: FileBasedClusterNodeFirewallTest should rely on JUnit / Maven norms for test files.

Signed-off-by: Mark Payne <markap14@hotmail.com>
This commit is contained in:
Sean Busbey 2015-04-29 22:42:44 -05:00 committed by Mark Payne
parent 5bf610a11e
commit 73a368f861
1 changed files with 8 additions and 18 deletions

View File

@ -17,18 +17,17 @@
package org.apache.nifi.cluster.firewall.impl; package org.apache.nifi.cluster.firewall.impl;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; 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.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue; import static org.junit.Assume.assumeTrue;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder;
public class FileBasedClusterNodeFirewallTest { public class FileBasedClusterNodeFirewallTest {
@ -42,6 +41,9 @@ public class FileBasedClusterNodeFirewallTest {
private File restoreDirectory; private File restoreDirectory;
@Rule
public final TemporaryFolder temp = new TemporaryFolder();
private static boolean badHostsDoNotResolve = false; private static boolean badHostsDoNotResolve = false;
/** /**
@ -62,20 +64,15 @@ public class FileBasedClusterNodeFirewallTest {
@Before @Before
public void setup() throws Exception { public void setup() throws Exception {
ipsConfig = new File("src/test/resources/org/apache/nifi/cluster/firewall/impl/ips.txt"); ipsConfig = new File(getClass().getResource("/org/apache/nifi/cluster/firewall/impl/ips.txt").toURI());
emptyConfig = new File("src/test/resources/org/apache/nifi/cluster/firewall/impl/empty.txt"); 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); ipsFirewall = new FileBasedClusterNodeFirewall(ipsConfig, restoreDirectory);
acceptAllFirewall = new FileBasedClusterNodeFirewall(emptyConfig); 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. * 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")); 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);
}
} }