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 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   * @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() 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          //no cleanup...
59          //executeTarget("cleanup");
60      }
61  
62      /**
63       * Test of addFileSet method, of class DependencyCheckTask.
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       * Test of addFileList method, of class DependencyCheckTask.
81       *
82       * @throws Exception
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       * Test of addDirSet method, of class DependencyCheckTask.
99       *
100      * @throws Exception
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      * Test of getFailBuildOnCVSS method, of class DependencyCheckTask.
116      */
117     @Test
118     public void testGetFailBuildOnCVSS() {
119         expectBuildException("failCVSS", "asdfasdfscore");
120         System.out.println(this.getOutput());
121     }
122 }