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 Set<Identifier> result = instance.getIdentifiers();
189
190 assertTrue(true);
191 }
192
193
194
195
196 @Test
197 public void testSetIdentifiers() {
198 Set<Identifier> identifiers = null;
199 Dependency instance = new Dependency();
200 instance.setIdentifiers(identifiers);
201 assertTrue(true);
202 }
203
204
205
206
207 @Test
208 public void testAddIdentifier() {
209 String type = "cpe";
210 String value = "cpe:/a:apache:struts:2.1.2";
211 String url = "http://somewhere";
212 Identifier expResult = new Identifier(type, value, url);
213
214 Dependency instance = new Dependency();
215 instance.addIdentifier(type, value, url);
216 assertEquals(1, instance.getIdentifiers().size());
217 assertTrue("Identifier doesn't contain expected result.", instance.getIdentifiers().contains(expResult));
218 }
219
220
221
222
223 @Test
224 public void testGetEvidence() {
225 Dependency instance = new Dependency();
226 EvidenceCollection expResult = null;
227 EvidenceCollection result = instance.getEvidence();
228 assertTrue(true);
229 }
230
231
232
233
234 @Test
235 public void testGetEvidenceUsed() {
236 Dependency instance = new Dependency();
237 String expResult = "used";
238
239 instance.getProductEvidence().addEvidence("used", "used", "used", Confidence.HIGH);
240 instance.getProductEvidence().addEvidence("not", "not", "not", Confidence.MEDIUM);
241 for (Evidence e : instance.getProductEvidence().iterator(Confidence.HIGH)) {
242 String use = e.getValue();
243 }
244
245 EvidenceCollection result = instance.getEvidenceUsed();
246
247 assertEquals(1, result.size());
248 assertTrue(result.containsUsedString(expResult));
249 }
250
251
252
253
254 @Test
255 public void testGetVendorEvidence() {
256 Dependency instance = new Dependency();
257 EvidenceCollection expResult = null;
258 EvidenceCollection result = instance.getVendorEvidence();
259 assertTrue(true);
260 }
261
262
263
264
265 @Test
266 public void testGetProductEvidence() {
267 Dependency instance = new Dependency();
268 EvidenceCollection expResult = null;
269 EvidenceCollection result = instance.getProductEvidence();
270 assertTrue(true);
271 }
272
273
274
275
276 @Test
277 public void testGetVersionEvidence() {
278 Dependency instance = new Dependency();
279 EvidenceCollection expResult = null;
280 EvidenceCollection result = instance.getVersionEvidence();
281 assertTrue(true);
282 }
283
284
285
286
287 @Test
288 public void testAddAsEvidence() {
289 Dependency instance = new Dependency();
290 MavenArtifact mavenArtifact = new MavenArtifact("group", "artifact", "version", "url");
291 instance.addAsEvidence("pom", mavenArtifact, Confidence.HIGH);
292 assertTrue(instance.getEvidence().contains(Confidence.HIGH));
293 assertFalse(instance.getEvidence().getEvidence("pom", "groupid").isEmpty());
294 assertFalse(instance.getEvidence().getEvidence("pom", "artifactid").isEmpty());
295 assertFalse(instance.getEvidence().getEvidence("pom", "version").isEmpty());
296 assertFalse(instance.getIdentifiers().isEmpty());
297 }
298
299
300
301
302 @Test
303 public void testAddAsEvidenceWithEmptyArtefact() {
304 Dependency instance = new Dependency();
305 MavenArtifact mavenArtifact = new MavenArtifact(null, null, null, null);
306 instance.addAsEvidence("pom", mavenArtifact, Confidence.HIGH);
307 assertFalse(instance.getEvidence().contains(Confidence.HIGH));
308 assertTrue(instance.getEvidence().getEvidence("pom", "groupid").isEmpty());
309 assertTrue(instance.getEvidence().getEvidence("pom", "artifactid").isEmpty());
310 assertTrue(instance.getEvidence().getEvidence("pom", "version").isEmpty());
311 assertTrue(instance.getIdentifiers().isEmpty());
312 }
313 }