1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.owasp.dependencycheck.data.nvdcve;
19
20 import java.util.Properties;
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertTrue;
23 import org.junit.Test;
24 import org.owasp.dependencycheck.data.update.nvd.NvdCveInfo;
25
26
27
28
29
30 public class DatabasePropertiesIntegrationTest extends BaseDBTestCase {
31
32
33
34
35 @Test
36 public void testIsEmpty() throws Exception {
37 CveDB cveDB = null;
38 try {
39 cveDB = new CveDB();
40 cveDB.open();
41 DatabaseProperties instance = cveDB.getDatabaseProperties();
42 boolean expResult = false;
43 boolean result = instance.isEmpty();
44
45
46 } finally {
47 if (cveDB != null) {
48 cveDB.close();
49 }
50 }
51 }
52
53
54
55
56 @Test
57 public void testSave() throws Exception {
58 NvdCveInfo updatedValue = new NvdCveInfo();
59 String key = "test";
60 long expected = 1337;
61 updatedValue.setId(key);
62 updatedValue.setTimestamp(expected);
63 CveDB cveDB = null;
64 try {
65 cveDB = new CveDB();
66 cveDB.open();
67 DatabaseProperties instance = cveDB.getDatabaseProperties();
68 instance.save(updatedValue);
69
70 cveDB.close();
71 cveDB = new CveDB();
72 cveDB.open();
73 instance = cveDB.getDatabaseProperties();
74 long results = Long.parseLong(instance.getProperty("NVD CVE " + key));
75 assertEquals(expected, results);
76 } finally {
77 if (cveDB != null) {
78 cveDB.close();
79 }
80 }
81 }
82
83
84
85
86 @Test
87 public void testGetProperty_String_String() throws Exception {
88 String key = "doesn't exist";
89 String defaultValue = "default";
90 CveDB cveDB = null;
91 try {
92 cveDB = new CveDB();
93 cveDB.open();
94 DatabaseProperties instance = cveDB.getDatabaseProperties();
95 String expResult = "default";
96 String result = instance.getProperty(key, defaultValue);
97 assertEquals(expResult, result);
98 } finally {
99 if (cveDB != null) {
100 cveDB.close();
101 }
102 }
103 }
104
105
106
107
108 @Test
109 public void testGetProperty_String() throws DatabaseException {
110 String key = "version";
111 CveDB cveDB = null;
112 try {
113 cveDB = new CveDB();
114 cveDB.open();
115 DatabaseProperties instance = cveDB.getDatabaseProperties();
116 String result = instance.getProperty(key);
117 double version = Double.parseDouble(result);
118 assertTrue(version >= 2.8);
119 assertTrue(version <= 10);
120 } finally {
121 if (cveDB != null) {
122 cveDB.close();
123 }
124 }
125 }
126
127
128
129
130 @Test
131 public void testGetProperties() throws DatabaseException {
132 CveDB cveDB = null;
133 try {
134 cveDB = new CveDB();
135 cveDB.open();
136 DatabaseProperties instance = cveDB.getDatabaseProperties();
137 Properties result = instance.getProperties();
138 assertTrue(result.size() > 0);
139 } finally {
140 if (cveDB != null) {
141 cveDB.close();
142 }
143 }
144 }
145 }