1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.owasp.dependencycheck;
17
18 import io.github.jeremylong.jcs3.slf4j.Slf4jAdapter;
19 import java.io.File;
20 import java.io.InputStream;
21 import java.net.URISyntaxException;
22 import org.junit.After;
23
24 import org.junit.AfterClass;
25 import org.junit.Assume;
26 import org.junit.Before;
27 import org.owasp.dependencycheck.utils.Settings;
28
29
30
31
32
33 public abstract class BaseTest {
34
35
36
37
38 private Settings settings;
39
40
41
42
43 @Before
44 public void setUp() throws Exception {
45 System.setProperty("jcs.logSystem", "slf4j");
46 Slf4jAdapter.muteLogging(true);
47 settings = new Settings();
48 }
49
50
51
52
53 @After
54 public void tearDown() throws Exception {
55 settings.cleanup(true);
56 }
57
58 @AfterClass
59 public static void tearDownClass() throws Exception {
60 File f = new File("./target/data/odc.mv.db");
61 if (f.exists() && f.isFile() && f.length() < 71680) {
62 System.err.println("------------------------------------------------");
63 System.err.println("------------------------------------------------");
64 System.err.println("Test referenced CveDB() and does not extend BaseDbTestCases?");
65 System.err.println("------------------------------------------------");
66 System.err.println("------------------------------------------------");
67 }
68 }
69
70
71
72
73
74
75
76
77
78
79 public static InputStream getResourceAsStream(Object o, String resource) {
80 getResourceAsFile(o, resource);
81 return o.getClass().getClassLoader().getResourceAsStream(resource);
82 }
83
84
85
86
87
88
89
90
91
92
93 public static File getResourceAsFile(Object o, String resource) {
94 try {
95 File f = new File(o.getClass().getClassLoader().getResource(resource).toURI().getPath());
96 Assume.assumeTrue(String.format("%n%n[SEVERE] Unable to load resource for test case: %s%n%n", resource), f.exists());
97 return f;
98 } catch (URISyntaxException e) {
99 throw new UnsupportedOperationException(e);
100 }
101 }
102
103
104
105
106
107
108 protected Settings getSettings() {
109 return settings;
110 }
111 }