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