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