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 static junit.framework.TestCase.assertTrue;
22 import org.apache.tools.ant.BuildFileTest;
23 import org.junit.After;
24 import org.junit.AfterClass;
25 import org.junit.Before;
26 import org.junit.BeforeClass;
27 import org.junit.Test;
28 import org.owasp.dependencycheck.data.nvdcve.BaseDBTestCase;
29
30
31
32
33
34 public class DependencyCheckTaskTest extends BuildFileTest {
35
36 public DependencyCheckTaskTest() {
37 }
38
39 @BeforeClass
40 public static void setUpClass() {
41 }
42
43 @AfterClass
44 public static void tearDownClass() {
45 }
46
47 @Before
48 @Override
49 public void setUp() throws Exception {
50 BaseDBTestCase.ensureDBExists();
51 final String buildFile = this.getClass().getClassLoader().getResource("build.xml").getPath();
52 configureProject(buildFile);
53 }
54
55 @After
56 @Override
57 public void tearDown() {
58
59
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 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 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 executeTarget("test.dirset");
111 assertTrue("DependencyCheck report was not generated", report.exists());
112 }
113
114
115
116
117 @Test
118 public void testGetFailBuildOnCVSS() {
119 expectBuildException("failCVSS", "asdfasdfscore");
120 System.out.println(this.getOutput());
121 }
122 }