1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.owasp.dependencycheck.taskdefs;
19
20 import java.io.File;
21 import org.apache.tools.ant.BuildFileTest;
22 import org.junit.After;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.owasp.dependencycheck.data.nvdcve.BaseDBTestCase;
26 import org.owasp.dependencycheck.utils.Settings;
27
28
29
30
31
32 public class DependencyCheckTaskTest extends BuildFileTest {
33
34
35
36
37
38 @Before
39 @Override
40 public void setUp() throws Exception {
41 Settings.initialize();
42 BaseDBTestCase.ensureDBExists();
43 final String buildFile = this.getClass().getClassLoader().getResource("build.xml").getPath();
44 configureProject(buildFile);
45 }
46
47 @After
48 @Override
49 public void tearDown() {
50
51
52 Settings.cleanup(true);
53 }
54
55
56
57
58 @Test
59 public void testAddFileSet() throws Exception {
60 File report = new File("target/dependency-check-report.html");
61 if (report.exists()) {
62 if (!report.delete()) {
63 throw new Exception("Unable to delete 'target/DependencyCheck-Report.html' prior to test.");
64 }
65 }
66 executeTarget("test.fileset");
67
68 assertTrue("DependencyCheck report was not generated", report.exists());
69
70 }
71
72
73
74
75
76
77 @Test
78 public void testAddFileList() throws Exception {
79 File report = new File("target/dependency-check-report.xml");
80 if (report.exists()) {
81 if (!report.delete()) {
82 throw new Exception("Unable to delete 'target/DependencyCheck-Report.xml' prior to test.");
83 }
84 }
85 executeTarget("test.filelist");
86
87 assertTrue("DependencyCheck report was not generated", report.exists());
88 }
89
90
91
92
93
94
95 @Test
96 public void testAddDirSet() throws Exception {
97 File report = new File("target/dependency-check-vulnerability.html");
98 if (report.exists()) {
99 if (!report.delete()) {
100 throw new Exception("Unable to delete 'target/DependencyCheck-Vulnerability.html' prior to test.");
101 }
102 }
103 executeTarget("test.dirset");
104 assertTrue("DependencyCheck report was not generated", report.exists());
105 }
106
107
108
109
110 @Test
111 public void testGetFailBuildOnCVSS() {
112 expectBuildException("failCVSS", "asdfasdfscore");
113 System.out.println(this.getOutput());
114 }
115 }