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