1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.owasp.dependencycheck;
17
18 import org.junit.jupiter.api.AfterAll;
19 import org.junit.jupiter.api.AfterEach;
20 import org.junit.jupiter.api.BeforeEach;
21 import org.owasp.dependencycheck.utils.Settings;
22
23 import java.io.File;
24 import java.io.InputStream;
25 import java.net.URISyntaxException;
26 import java.util.Objects;
27
28
29
30
31
32 public abstract class BaseTest {
33
34
35
36
37 private Settings settings;
38
39
40
41
42 @BeforeEach
43 public void setUp() throws Exception {
44 settings = new Settings();
45 }
46
47
48
49
50 @AfterEach
51 public void tearDown() throws Exception {
52 settings.cleanup(true);
53 }
54
55 @AfterAll
56 public static void tearDownClass() {
57 File f = new File("./target/data/odc.mv.db");
58 if (f.exists() && f.isFile() && f.length() < 71680) {
59 System.err.println("------------------------------------------------");
60 System.err.println("------------------------------------------------");
61 System.err.println("Test referenced CveDB() and does not extend BaseDbTestCases?");
62 System.err.println("------------------------------------------------");
63 System.err.println("------------------------------------------------");
64 }
65 }
66
67
68
69
70
71
72
73
74 public static InputStream getResourceAsStream(Object o, String resource) {
75 return Objects.requireNonNull(o.getClass().getClassLoader().getResourceAsStream(resource), resource + " not found on classpath");
76 }
77
78
79
80
81
82
83
84
85 public static File getResourceAsFile(Object o, String resource) {
86 try {
87 return new File(Objects.requireNonNull(o.getClass().getClassLoader().getResource(resource), resource + " not found on classpath").toURI().getPath());
88 } catch (URISyntaxException e) {
89 throw new UnsupportedOperationException(e);
90 }
91 }
92
93
94
95
96 protected Settings getSettings() {
97 return settings;
98 }
99 }