Thomas Vachuska
Committed by Gerrit Code Review

ONOS-1679 Removed use of /tmp directory from various unit tests.

Change-Id: I1725f3807f51bc44756d90b5e41ae7fa3c56c55f
......@@ -17,6 +17,7 @@ package org.onosproject.common.app;
import com.google.common.collect.ImmutableSet;
import com.google.common.io.ByteStreams;
import com.google.common.io.Files;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
......@@ -27,7 +28,6 @@ import org.onosproject.app.ApplicationException;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Random;
import java.util.Set;
import static org.junit.Assert.*;
......@@ -38,20 +38,19 @@ import static org.onosproject.app.DefaultApplicationDescriptionTest.*;
*/
public class ApplicationArchiveTest {
static final String ROOT = "/tmp/app-junit/";
static final String STORE = ROOT + new Random().nextInt(1000) + "/foo";
static final File STORE = Files.createTempDir();
private ApplicationArchive aar = new ApplicationArchive();
@Before
public void setUp() {
aar.setRootPath(STORE);
aar.setRootPath(STORE.getAbsolutePath());
}
@After
public void tearDown() throws IOException {
if (new File(ROOT).exists()) {
Tools.removeDirectory(ROOT);
if (STORE.exists()) {
Tools.removeDirectory(STORE);
}
}
......
......@@ -16,6 +16,7 @@
package org.onosproject.store.trivial;
import com.google.common.collect.ImmutableSet;
import com.google.common.io.Files;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
......@@ -25,20 +26,15 @@ import org.onosproject.app.ApplicationStoreDelegate;
import org.onosproject.common.app.ApplicationArchive;
import org.onosproject.core.Application;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.Permission;
import org.onosproject.core.ApplicationIdStoreAdapter;
import org.onosproject.core.DefaultApplicationId;
import org.onosproject.core.Permission;
import java.io.File;
import java.io.IOException;
import java.util.Random;
import static org.junit.Assert.assertEquals;
import static org.onosproject.app.ApplicationEvent.Type.APP_INSTALLED;
import static org.onosproject.app.ApplicationEvent.Type.APP_DEACTIVATED;
import static org.onosproject.app.ApplicationEvent.Type.APP_ACTIVATED;
import static org.onosproject.app.ApplicationEvent.Type.APP_UNINSTALLED;
import static org.onosproject.app.ApplicationEvent.Type.APP_PERMISSIONS_CHANGED;
import static org.onosproject.app.ApplicationEvent.Type.*;
import static org.onosproject.app.ApplicationState.ACTIVE;
import static org.onosproject.app.ApplicationState.INSTALLED;
......@@ -47,8 +43,7 @@ import static org.onosproject.app.ApplicationState.INSTALLED;
*/
public class SimpleApplicationStoreTest {
static final String ROOT = "/tmp/app-junit/";
static final String STORE = ROOT + new Random().nextInt(1000) + "/foo";
static final File STORE = Files.createTempDir();
private TestApplicationStore store = new TestApplicationStore();
private TestDelegate delegate = new TestDelegate();
......@@ -57,15 +52,15 @@ public class SimpleApplicationStoreTest {
@Before
public void setUp() {
store.idStore = new TestIdStore();
store.setRootPath(STORE);
store.setRootPath(STORE.getAbsolutePath());
store.setDelegate(delegate);
store.activate();
}
@After
public void tearDown() throws IOException {
if (new File(ROOT).exists()) {
Tools.removeDirectory(ROOT);
if (STORE.exists()) {
Tools.removeDirectory(STORE);
}
store.deactivate();
}
......
......@@ -74,6 +74,7 @@ class StepProcessor implements Runnable {
*/
private int execute() {
try (PrintWriter pw = new PrintWriter(logFile())) {
System.out.println("cmd: [" + command() + "]");
process = Runtime.getRuntime().exec(command());
processOutput(pw);
......
......@@ -15,6 +15,7 @@
*/
package org.onlab.stc;
import com.google.common.io.Files;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
......@@ -23,6 +24,7 @@ import org.onlab.util.Tools;
import java.io.File;
import java.io.IOException;
import static com.google.common.base.Preconditions.checkState;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.onlab.stc.Coordinator.Status.SUCCEEDED;
......@@ -32,14 +34,13 @@ import static org.onlab.stc.Coordinator.Status.SUCCEEDED;
*/
public class StepProcessorTest {
static final File DIR = new File("/tmp/stc/foo");
static final File DIR = Files.createTempDir();
private final Listener delegate = new Listener();
@BeforeClass
public static void setUpClass() {
StepProcessor.launcher = "echo";
DIR.mkdirs();
checkState(DIR.mkdirs(), "Unable to create directory");
}
@AfterClass
......@@ -49,13 +50,13 @@ public class StepProcessorTest {
@Test
public void basics() {
Step step = new Step("foo", "ls /tmp", null, null, null);
Step step = new Step("foo", "ls " + DIR.getAbsolutePath(), null, null, null);
StepProcessor processor = new StepProcessor(step, DIR, delegate);
processor.run();
assertTrue("should be started", delegate.started);
assertTrue("should have output", delegate.output);
assertTrue("should be stopped", delegate.stopped);
assertEquals("incorrect status", SUCCEEDED, delegate.status);
assertTrue("should have output", delegate.output);
}
private class Listener implements StepProcessListener {
......