View Javadoc

1   /*
2    * This file is part of dependency-check-ant.
3    *
4    * Dependency-check-ant is free software: you can redistribute it and/or modify it
5    * under the terms of the GNU General Public License as published by the Free
6    * Software Foundation, either version 3 of the License, or (at your option) any
7    * later version.
8    *
9    * Dependency-check-ant is distributed in the hope that it will be useful, but
10   * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11   * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12   * details.
13   *
14   * You should have received a copy of the GNU General Public License along with
15   * dependency-check-ant. If not, see http://www.gnu.org/licenses/.
16   *
17   * Copyright (c) 2013 Jeremy Long. All Rights Reserved.
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   * @author Jeremy Long (jeremy.long@owasp.org)
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          //no cleanup...
58          //executeTarget("cleanup");
59      }
60  
61      /**
62       * Test of addFileSet method, of class DependencyCheckTask.
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       * Test of addFileList method, of class DependencyCheckTask.
80       *
81       * @throws Exception
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       * Test of addDirSet method, of class DependencyCheckTask.
98       *
99       * @throws Exception
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      * Test of getFailBuildOnCVSS method, of class DependencyCheckTask.
115      */
116     @Test
117     public void testGetFailBuildOnCVSS() {
118         expectBuildException("failCVSS", "asdfasdfscore");
119         System.out.println(this.getOutput());
120     }
121 }