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
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() {
50 final String buildFile = this.getClass().getClassLoader().getResource("build.xml").getPath();
51 configureProject(buildFile);
52 }
53
54 @After
55 @Override
56 public void tearDown() {
57
58
59 }
60
61
62
63
64 @Test
65 public void testAddFileSet() throws Exception {
66 File report = new File("target/DependencyCheck-Report.html");
67 if (report.exists()) {
68 if (!report.delete()) {
69 throw new Exception("Unable to delete 'target/DependencyCheck-Report.html' prior to test.");
70 }
71 }
72 executeTarget("test.fileset");
73
74 assertTrue("DependencyCheck report was not generated", report.exists());
75
76 }
77
78
79
80
81
82
83 @Test
84 public void testAddFileList() throws Exception {
85 File report = new File("target/DependencyCheck-Report.xml");
86 if (report.exists()) {
87 if (!report.delete()) {
88 throw new Exception("Unable to delete 'target/DependencyCheck-Report.xml' prior to test.");
89 }
90 }
91 executeTarget("test.filelist");
92
93 assertTrue("DependencyCheck report was not generated", report.exists());
94 }
95
96
97
98
99
100
101 @Test
102 public void testAddDirSet() throws Exception {
103 File report = new File("target/DependencyCheck-Vulnerability.html");
104 if (report.exists()) {
105 if (!report.delete()) {
106 throw new Exception("Unable to delete 'target/DependencyCheck-Vulnerability.html' prior to test.");
107 }
108 }
109 executeTarget("test.dirset");
110 assertTrue("DependencyCheck report was not generated", report.exists());
111 }
112
113
114
115
116 @Test
117 public void testGetFailBuildOnCVSS() {
118 expectBuildException("failCVSS", "asdfasdfscore");
119 System.out.println(this.getOutput());
120 }
121 }