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  import org.owasp.dependencycheck.data.nvdcve.BaseDBTestCase;
    30
    31  /**
    32   *
    33   * @author Jeremy Long (jeremy.long@owasp.org)
    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          //no cleanup...
    60          //executeTarget("cleanup");
    61      }
    62
    63      /**
    64       * Test of addFileSet method, of class DependencyCheckTask.
    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       * Test of addFileList method, of class DependencyCheckTask.
    82       *
    83       * @throws Exception
    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       * Test of addDirSet method, of class DependencyCheckTask.
    100      *
    101      * @throws Exception
    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      * Test of getFailBuildOnCVSS method, of class DependencyCheckTask.
    117      */
    118     @Test
    119     public void testGetFailBuildOnCVSS() {
    120         expectBuildException("failCVSS", "asdfasdfscore");
    121         System.out.println(this.getOutput());
    122     }
    123 }