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
22 import org.apache.tools.ant.BuildException;
23 import org.apache.tools.ant.BuildFileRule;
24 import org.junit.After;
25 import org.junit.Before;
26 import org.junit.Rule;
27 import org.junit.Test;
28 import org.junit.rules.ExpectedException;
29 import org.owasp.dependencycheck.BaseDBTestCase;
30 import org.owasp.dependencycheck.utils.Settings;
31
32 import static org.junit.Assert.assertTrue;
33
34
35
36
37
38
39 public class DependencyCheckTaskTest {
40
41 @Rule
42 public BuildFileRule buildFileRule = new BuildFileRule();
43
44 @Rule
45 public ExpectedException expectedException = ExpectedException.none();
46
47 @Before
48 public void setUp() throws Exception {
49 Settings.initialize();
50 BaseDBTestCase.ensureDBExists();
51 final String buildFile = this.getClass().getClassLoader().getResource("build.xml").getPath();
52 buildFileRule.configureProject(buildFile);
53 }
54
55 @After
56 public void tearDown() {
57
58
59 Settings.cleanup(true);
60 }
61
62
63
64
65 @Test
66 public void testAddFileSet() throws Exception {
67 File report = new File("target/dependency-check-report.html");
68 if (report.exists()) {
69 if (!report.delete()) {
70 throw new Exception("Unable to delete 'target/DependencyCheck-Report.html' prior to test.");
71 }
72 }
73 buildFileRule.executeTarget("test.fileset");
74
75 assertTrue("DependencyCheck report was not generated", report.exists());
76
77 }
78
79
80
81
82
83
84 @Test
85 public void testAddFileList() throws Exception {
86 File report = new File("target/dependency-check-report.xml");
87 if (report.exists()) {
88 if (!report.delete()) {
89 throw new Exception("Unable to delete 'target/DependencyCheck-Report.xml' prior to test.");
90 }
91 }
92 buildFileRule.executeTarget("test.filelist");
93
94 assertTrue("DependencyCheck report was not generated", report.exists());
95 }
96
97
98
99
100
101
102 @Test
103 public void testAddDirSet() throws Exception {
104 File report = new File("target/dependency-check-vulnerability.html");
105 if (report.exists()) {
106 if (!report.delete()) {
107 throw new Exception("Unable to delete 'target/DependencyCheck-Vulnerability.html' prior to test.");
108 }
109 }
110 buildFileRule.executeTarget("test.dirset");
111 assertTrue("DependencyCheck report was not generated", report.exists());
112 }
113
114
115
116
117 @Test
118 public void testGetFailBuildOnCVSS() {
119 expectedException.expect(BuildException.class);
120 buildFileRule.executeTarget("failCVSS");
121 }
122 }