1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.owasp.dependencycheck.dependency;
19
20 import java.io.File;
21 import java.util.List;
22 import java.util.Set;
23 import org.junit.After;
24 import org.junit.AfterClass;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertFalse;
27 import static org.junit.Assert.assertTrue;
28 import org.junit.Before;
29 import org.junit.BeforeClass;
30 import org.junit.Test;
31 import org.owasp.dependencycheck.BaseTest;
32 import org.owasp.dependencycheck.data.nexus.MavenArtifact;
33
34
35
36
37
38 public class DependencyTest {
39
40 public DependencyTest() {
41 }
42
43 @BeforeClass
44 public static void setUpClass() throws Exception {
45 }
46
47 @AfterClass
48 public static void tearDownClass() throws Exception {
49 }
50
51 @Before
52 public void setUp() {
53 }
54
55 @After
56 public void tearDown() {
57 }
58
59
60
61
62 @Test
63 public void testGetFileName() {
64 Dependency instance = new Dependency();
65 String expResult = "filename";
66 instance.setFileName(expResult);
67 String result = instance.getFileName();
68 assertEquals(expResult, result);
69 }
70
71
72
73
74 @Test
75 public void testSetFileName() {
76 String fileName = "file.tar";
77 Dependency instance = new Dependency();
78 instance.setFileName(fileName);
79 assertEquals(fileName, instance.getFileName());
80 }
81
82
83
84
85 @Test
86 public void testSetActualFilePath() {
87 String actualFilePath = "file.tar";
88 Dependency instance = new Dependency();
89 instance.setSha1sum("non-null value");
90 instance.setActualFilePath(actualFilePath);
91 assertEquals(actualFilePath, instance.getActualFilePath());
92 }
93
94
95
96
97 @Test
98 public void testGetActualFilePath() {
99 Dependency instance = new Dependency();
100 String expResult = "file.tar";
101 instance.setSha1sum("non-null value");
102 instance.setActualFilePath(expResult);
103 String result = instance.getActualFilePath();
104 assertEquals(expResult, result);
105 }
106
107
108
109
110 @Test
111 public void testSetFilePath() {
112 String filePath = "file.tar";
113 Dependency instance = new Dependency();
114 instance.setFilePath(filePath);
115 assertEquals(filePath, instance.getFilePath());
116 }
117
118
119
120
121 @Test
122 public void testGetFilePath() {
123 Dependency instance = new Dependency();
124 String expResult = "file.tar";
125 instance.setFilePath(expResult);
126 String result = instance.getFilePath();
127 assertEquals(expResult, result);
128 }
129
130
131
132
133 @Test
134 public void testGetMd5sum() {
135
136 File file = BaseTest.getResourceAsFile(this, "struts2-core-2.1.2.jar");
137
138 Dependency instance = new Dependency(file);
139
140
141 String expResult = "c30b57142e1ccbc1efd5cd15f307358f";
142 String result = instance.getMd5sum();
143 assertEquals(expResult, result);
144 }
145
146
147
148
149 @Test
150 public void testSetMd5sum() {
151 String md5sum = "test";
152 Dependency instance = new Dependency();
153 instance.setMd5sum(md5sum);
154 assertEquals(md5sum, instance.getMd5sum());
155 }
156
157
158
159
160 @Test
161 public void testGetSha1sum() {
162
163 File file = BaseTest.getResourceAsFile(this, "struts2-core-2.1.2.jar");
164 Dependency instance = new Dependency(file);
165
166 String expResult = "89ce9e36aa9a9e03f1450936d2f4f8dd0f961f8b";
167 String result = instance.getSha1sum();
168 assertEquals(expResult, result);
169 }
170
171
172
173
174 @Test
175 public void testSetSha1sum() {
176 String sha1sum = "test";
177 Dependency instance = new Dependency();
178 instance.setSha1sum(sha1sum);
179 assertEquals(sha1sum, instance.getSha1sum());
180 }
181
182
183
184
185 @Test
186 public void testGetIdentifiers() {
187 Dependency instance = new Dependency();
188 List expResult = null;
189 Set<Identifier> result = instance.getIdentifiers();
190
191 assertTrue(true);
192 }
193
194
195
196
197 @Test
198 public void testSetIdentifiers() {
199 Set<Identifier> identifiers = null;
200 Dependency instance = new Dependency();
201 instance.setIdentifiers(identifiers);
202 assertTrue(true);
203 }
204
205
206
207
208 @Test
209 public void testAddIdentifier() {
210 String type = "cpe";
211 String value = "cpe:/a:apache:struts:2.1.2";
212 String url = "http://somewhere";
213 Identifier expResult = new Identifier(type, value, url);
214
215 Dependency instance = new Dependency();
216 instance.addIdentifier(type, value, url);
217 assertEquals(1, instance.getIdentifiers().size());
218 assertTrue("Identifier doesn't contain expected result.", instance.getIdentifiers().contains(expResult));
219 }
220
221
222
223
224 @Test
225 public void testGetEvidence() {
226 Dependency instance = new Dependency();
227 EvidenceCollection expResult = null;
228 EvidenceCollection result = instance.getEvidence();
229 assertTrue(true);
230 }
231
232
233
234
235 @Test
236 public void testGetEvidenceUsed() {
237 Dependency instance = new Dependency();
238 String expResult = "used";
239
240 instance.getProductEvidence().addEvidence("used", "used", "used", Confidence.HIGH);
241 instance.getProductEvidence().addEvidence("not", "not", "not", Confidence.MEDIUM);
242 for (Evidence e : instance.getProductEvidence().iterator(Confidence.HIGH)) {
243 String use = e.getValue();
244 }
245
246 EvidenceCollection result = instance.getEvidenceUsed();
247
248 assertEquals(1, result.size());
249 assertTrue(result.containsUsedString(expResult));
250 }
251
252
253
254
255 @Test
256 public void testGetVendorEvidence() {
257 Dependency instance = new Dependency();
258 EvidenceCollection expResult = null;
259 EvidenceCollection result = instance.getVendorEvidence();
260 assertTrue(true);
261 }
262
263
264
265
266 @Test
267 public void testGetProductEvidence() {
268 Dependency instance = new Dependency();
269 EvidenceCollection expResult = null;
270 EvidenceCollection result = instance.getProductEvidence();
271 assertTrue(true);
272 }
273
274
275
276
277 @Test
278 public void testGetVersionEvidence() {
279 Dependency instance = new Dependency();
280 EvidenceCollection expResult = null;
281 EvidenceCollection result = instance.getVersionEvidence();
282 assertTrue(true);
283 }
284
285
286
287
288 @Test
289 public void testAddAsEvidence() {
290 Dependency instance = new Dependency();
291 MavenArtifact mavenArtifact = new MavenArtifact("group", "artifact", "version", "url");
292 instance.addAsEvidence("pom", mavenArtifact, Confidence.HIGH);
293 assertTrue(instance.getEvidence().contains(Confidence.HIGH));
294 assertFalse(instance.getEvidence().getEvidence("pom", "groupid").isEmpty());
295 assertFalse(instance.getEvidence().getEvidence("pom", "artifactid").isEmpty());
296 assertFalse(instance.getEvidence().getEvidence("pom", "version").isEmpty());
297 assertFalse(instance.getIdentifiers().isEmpty());
298 }
299
300
301
302
303 @Test
304 public void testAddAsEvidenceWithEmptyArtefact() {
305 Dependency instance = new Dependency();
306 MavenArtifact mavenArtifact = new MavenArtifact(null, null, null, null);
307 instance.addAsEvidence("pom", mavenArtifact, Confidence.HIGH);
308 assertFalse(instance.getEvidence().contains(Confidence.HIGH));
309 assertTrue(instance.getEvidence().getEvidence("pom", "groupid").isEmpty());
310 assertTrue(instance.getEvidence().getEvidence("pom", "artifactid").isEmpty());
311 assertTrue(instance.getEvidence().getEvidence("pom", "version").isEmpty());
312 assertTrue(instance.getIdentifiers().isEmpty());
313 }
314 }