View Javadoc
1   /*
2    * This file is part of dependency-check-ant.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   * Copyright (c) 2013 Jeremy Long. All Rights Reserved.
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   * @author Jeremy Long <jeremy.long@owasp.org>
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          //no cleanup...
47          //executeTarget("cleanup");
48          Settings.cleanup();
49      }
50  
51      /**
52       * Test of addFileSet method, of class DependencyCheckTask.
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       * Test of addFileList method, of class DependencyCheckTask.
70       *
71       * @throws Exception
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       * Test of addDirSet method, of class DependencyCheckTask.
88       *
89       * @throws Exception
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      * Test of getFailBuildOnCVSS method, of class DependencyCheckTask.
105      */
106     @Test
107     public void testGetFailBuildOnCVSS() {
108         expectBuildException("failCVSS", "asdfasdfscore");
109         System.out.println(this.getOutput());
110     }
111 }