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 @Before
35 @Override
36 public void setUp() throws Exception {
37 Settings.initialize();
38 BaseDBTestCase.ensureDBExists();
39 final String buildFile = this.getClass().getClassLoader().getResource("build.xml").getPath();
40 configureProject(buildFile);
41 }
42
43 @After
44 @Override
45 public void tearDown() {
46
47
48 Settings.cleanup();
49 }
50
51
52
53
54 @Test
55 public void testAddFileSet() throws Exception {
56 File report = new File("target/dependency-check-report.html");
57 if (report.exists()) {
58 if (!report.delete()) {
59 throw new Exception("Unable to delete 'target/DependencyCheck-Report.html' prior to test.");
60 }
61 }
62 executeTarget("test.fileset");
63
64 assertTrue("DependencyCheck report was not generated", report.exists());
65
66 }
67
68
69
70
71
72
73 @Test
74 public void testAddFileList() throws Exception {
75 File report = new File("target/dependency-check-report.xml");
76 if (report.exists()) {
77 if (!report.delete()) {
78 throw new Exception("Unable to delete 'target/DependencyCheck-Report.xml' prior to test.");
79 }
80 }
81 executeTarget("test.filelist");
82
83 assertTrue("DependencyCheck report was not generated", report.exists());
84 }
85
86
87
88
89
90
91 @Test
92 public void testAddDirSet() throws Exception {
93 File report = new File("target/dependency-check-vulnerability.html");
94 if (report.exists()) {
95 if (!report.delete()) {
96 throw new Exception("Unable to delete 'target/DependencyCheck-Vulnerability.html' prior to test.");
97 }
98 }
99 executeTarget("test.dirset");
100 assertTrue("DependencyCheck report was not generated", report.exists());
101 }
102
103
104
105
106 @Test
107 public void testGetFailBuildOnCVSS() {
108 expectBuildException("failCVSS", "asdfasdfscore");
109 System.out.println(this.getOutput());
110 }
111 }