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