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