Committed by
Gerrit Code Review
ONOS-1679 Removed use of /tmp directory from various unit tests.
Change-Id: I1725f3807f51bc44756d90b5e41ae7fa3c56c55f
Showing
4 changed files
with
19 additions
and
23 deletions
... | @@ -17,6 +17,7 @@ package org.onosproject.common.app; | ... | @@ -17,6 +17,7 @@ package org.onosproject.common.app; |
17 | 17 | ||
18 | import com.google.common.collect.ImmutableSet; | 18 | import com.google.common.collect.ImmutableSet; |
19 | import com.google.common.io.ByteStreams; | 19 | import com.google.common.io.ByteStreams; |
20 | +import com.google.common.io.Files; | ||
20 | import org.junit.After; | 21 | import org.junit.After; |
21 | import org.junit.Before; | 22 | import org.junit.Before; |
22 | import org.junit.Test; | 23 | import org.junit.Test; |
... | @@ -27,7 +28,6 @@ import org.onosproject.app.ApplicationException; | ... | @@ -27,7 +28,6 @@ import org.onosproject.app.ApplicationException; |
27 | import java.io.File; | 28 | import java.io.File; |
28 | import java.io.IOException; | 29 | import java.io.IOException; |
29 | import java.io.InputStream; | 30 | import java.io.InputStream; |
30 | -import java.util.Random; | ||
31 | import java.util.Set; | 31 | import java.util.Set; |
32 | 32 | ||
33 | import static org.junit.Assert.*; | 33 | import static org.junit.Assert.*; |
... | @@ -38,20 +38,19 @@ import static org.onosproject.app.DefaultApplicationDescriptionTest.*; | ... | @@ -38,20 +38,19 @@ import static org.onosproject.app.DefaultApplicationDescriptionTest.*; |
38 | */ | 38 | */ |
39 | public class ApplicationArchiveTest { | 39 | public class ApplicationArchiveTest { |
40 | 40 | ||
41 | - static final String ROOT = "/tmp/app-junit/"; | 41 | + static final File STORE = Files.createTempDir(); |
42 | - static final String STORE = ROOT + new Random().nextInt(1000) + "/foo"; | ||
43 | 42 | ||
44 | private ApplicationArchive aar = new ApplicationArchive(); | 43 | private ApplicationArchive aar = new ApplicationArchive(); |
45 | 44 | ||
46 | @Before | 45 | @Before |
47 | public void setUp() { | 46 | public void setUp() { |
48 | - aar.setRootPath(STORE); | 47 | + aar.setRootPath(STORE.getAbsolutePath()); |
49 | } | 48 | } |
50 | 49 | ||
51 | @After | 50 | @After |
52 | public void tearDown() throws IOException { | 51 | public void tearDown() throws IOException { |
53 | - if (new File(ROOT).exists()) { | 52 | + if (STORE.exists()) { |
54 | - Tools.removeDirectory(ROOT); | 53 | + Tools.removeDirectory(STORE); |
55 | } | 54 | } |
56 | } | 55 | } |
57 | 56 | ... | ... |
... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
16 | package org.onosproject.store.trivial; | 16 | package org.onosproject.store.trivial; |
17 | 17 | ||
18 | import com.google.common.collect.ImmutableSet; | 18 | import com.google.common.collect.ImmutableSet; |
19 | +import com.google.common.io.Files; | ||
19 | import org.junit.After; | 20 | import org.junit.After; |
20 | import org.junit.Before; | 21 | import org.junit.Before; |
21 | import org.junit.Test; | 22 | import org.junit.Test; |
... | @@ -25,20 +26,15 @@ import org.onosproject.app.ApplicationStoreDelegate; | ... | @@ -25,20 +26,15 @@ import org.onosproject.app.ApplicationStoreDelegate; |
25 | import org.onosproject.common.app.ApplicationArchive; | 26 | import org.onosproject.common.app.ApplicationArchive; |
26 | import org.onosproject.core.Application; | 27 | import org.onosproject.core.Application; |
27 | import org.onosproject.core.ApplicationId; | 28 | import org.onosproject.core.ApplicationId; |
28 | -import org.onosproject.core.Permission; | ||
29 | import org.onosproject.core.ApplicationIdStoreAdapter; | 29 | import org.onosproject.core.ApplicationIdStoreAdapter; |
30 | import org.onosproject.core.DefaultApplicationId; | 30 | import org.onosproject.core.DefaultApplicationId; |
31 | +import org.onosproject.core.Permission; | ||
31 | 32 | ||
32 | import java.io.File; | 33 | import java.io.File; |
33 | import java.io.IOException; | 34 | import java.io.IOException; |
34 | -import java.util.Random; | ||
35 | 35 | ||
36 | import static org.junit.Assert.assertEquals; | 36 | import static org.junit.Assert.assertEquals; |
37 | -import static org.onosproject.app.ApplicationEvent.Type.APP_INSTALLED; | 37 | +import static org.onosproject.app.ApplicationEvent.Type.*; |
38 | -import static org.onosproject.app.ApplicationEvent.Type.APP_DEACTIVATED; | ||
39 | -import static org.onosproject.app.ApplicationEvent.Type.APP_ACTIVATED; | ||
40 | -import static org.onosproject.app.ApplicationEvent.Type.APP_UNINSTALLED; | ||
41 | -import static org.onosproject.app.ApplicationEvent.Type.APP_PERMISSIONS_CHANGED; | ||
42 | import static org.onosproject.app.ApplicationState.ACTIVE; | 38 | import static org.onosproject.app.ApplicationState.ACTIVE; |
43 | import static org.onosproject.app.ApplicationState.INSTALLED; | 39 | import static org.onosproject.app.ApplicationState.INSTALLED; |
44 | 40 | ||
... | @@ -47,8 +43,7 @@ import static org.onosproject.app.ApplicationState.INSTALLED; | ... | @@ -47,8 +43,7 @@ import static org.onosproject.app.ApplicationState.INSTALLED; |
47 | */ | 43 | */ |
48 | public class SimpleApplicationStoreTest { | 44 | public class SimpleApplicationStoreTest { |
49 | 45 | ||
50 | - static final String ROOT = "/tmp/app-junit/"; | 46 | + static final File STORE = Files.createTempDir(); |
51 | - static final String STORE = ROOT + new Random().nextInt(1000) + "/foo"; | ||
52 | 47 | ||
53 | private TestApplicationStore store = new TestApplicationStore(); | 48 | private TestApplicationStore store = new TestApplicationStore(); |
54 | private TestDelegate delegate = new TestDelegate(); | 49 | private TestDelegate delegate = new TestDelegate(); |
... | @@ -57,15 +52,15 @@ public class SimpleApplicationStoreTest { | ... | @@ -57,15 +52,15 @@ public class SimpleApplicationStoreTest { |
57 | @Before | 52 | @Before |
58 | public void setUp() { | 53 | public void setUp() { |
59 | store.idStore = new TestIdStore(); | 54 | store.idStore = new TestIdStore(); |
60 | - store.setRootPath(STORE); | 55 | + store.setRootPath(STORE.getAbsolutePath()); |
61 | store.setDelegate(delegate); | 56 | store.setDelegate(delegate); |
62 | store.activate(); | 57 | store.activate(); |
63 | } | 58 | } |
64 | 59 | ||
65 | @After | 60 | @After |
66 | public void tearDown() throws IOException { | 61 | public void tearDown() throws IOException { |
67 | - if (new File(ROOT).exists()) { | 62 | + if (STORE.exists()) { |
68 | - Tools.removeDirectory(ROOT); | 63 | + Tools.removeDirectory(STORE); |
69 | } | 64 | } |
70 | store.deactivate(); | 65 | store.deactivate(); |
71 | } | 66 | } | ... | ... |
... | @@ -74,6 +74,7 @@ class StepProcessor implements Runnable { | ... | @@ -74,6 +74,7 @@ class StepProcessor implements Runnable { |
74 | */ | 74 | */ |
75 | private int execute() { | 75 | private int execute() { |
76 | try (PrintWriter pw = new PrintWriter(logFile())) { | 76 | try (PrintWriter pw = new PrintWriter(logFile())) { |
77 | + System.out.println("cmd: [" + command() + "]"); | ||
77 | process = Runtime.getRuntime().exec(command()); | 78 | process = Runtime.getRuntime().exec(command()); |
78 | processOutput(pw); | 79 | processOutput(pw); |
79 | 80 | ... | ... |
... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
15 | */ | 15 | */ |
16 | package org.onlab.stc; | 16 | package org.onlab.stc; |
17 | 17 | ||
18 | +import com.google.common.io.Files; | ||
18 | import org.junit.AfterClass; | 19 | import org.junit.AfterClass; |
19 | import org.junit.BeforeClass; | 20 | import org.junit.BeforeClass; |
20 | import org.junit.Test; | 21 | import org.junit.Test; |
... | @@ -23,6 +24,7 @@ import org.onlab.util.Tools; | ... | @@ -23,6 +24,7 @@ import org.onlab.util.Tools; |
23 | import java.io.File; | 24 | import java.io.File; |
24 | import java.io.IOException; | 25 | import java.io.IOException; |
25 | 26 | ||
27 | +import static com.google.common.base.Preconditions.checkState; | ||
26 | import static org.junit.Assert.assertEquals; | 28 | import static org.junit.Assert.assertEquals; |
27 | import static org.junit.Assert.assertTrue; | 29 | import static org.junit.Assert.assertTrue; |
28 | import static org.onlab.stc.Coordinator.Status.SUCCEEDED; | 30 | import static org.onlab.stc.Coordinator.Status.SUCCEEDED; |
... | @@ -32,14 +34,13 @@ import static org.onlab.stc.Coordinator.Status.SUCCEEDED; | ... | @@ -32,14 +34,13 @@ import static org.onlab.stc.Coordinator.Status.SUCCEEDED; |
32 | */ | 34 | */ |
33 | public class StepProcessorTest { | 35 | public class StepProcessorTest { |
34 | 36 | ||
35 | - static final File DIR = new File("/tmp/stc/foo"); | 37 | + static final File DIR = Files.createTempDir(); |
36 | - | ||
37 | private final Listener delegate = new Listener(); | 38 | private final Listener delegate = new Listener(); |
38 | 39 | ||
39 | @BeforeClass | 40 | @BeforeClass |
40 | public static void setUpClass() { | 41 | public static void setUpClass() { |
41 | StepProcessor.launcher = "echo"; | 42 | StepProcessor.launcher = "echo"; |
42 | - DIR.mkdirs(); | 43 | + checkState(DIR.mkdirs(), "Unable to create directory"); |
43 | } | 44 | } |
44 | 45 | ||
45 | @AfterClass | 46 | @AfterClass |
... | @@ -49,13 +50,13 @@ public class StepProcessorTest { | ... | @@ -49,13 +50,13 @@ public class StepProcessorTest { |
49 | 50 | ||
50 | @Test | 51 | @Test |
51 | public void basics() { | 52 | public void basics() { |
52 | - Step step = new Step("foo", "ls /tmp", null, null, null); | 53 | + Step step = new Step("foo", "ls " + DIR.getAbsolutePath(), null, null, null); |
53 | StepProcessor processor = new StepProcessor(step, DIR, delegate); | 54 | StepProcessor processor = new StepProcessor(step, DIR, delegate); |
54 | processor.run(); | 55 | processor.run(); |
55 | assertTrue("should be started", delegate.started); | 56 | assertTrue("should be started", delegate.started); |
56 | - assertTrue("should have output", delegate.output); | ||
57 | assertTrue("should be stopped", delegate.stopped); | 57 | assertTrue("should be stopped", delegate.stopped); |
58 | assertEquals("incorrect status", SUCCEEDED, delegate.status); | 58 | assertEquals("incorrect status", SUCCEEDED, delegate.status); |
59 | + assertTrue("should have output", delegate.output); | ||
59 | } | 60 | } |
60 | 61 | ||
61 | private class Listener implements StepProcessListener { | 62 | private class Listener implements StepProcessListener { | ... | ... |
-
Please register or login to post a comment