View Javadoc

    1   /*
    2    * This file is part of dependency-check-core.
    3    *
    4    * Dependency-check-core 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-core 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-core. If not, see http://www.gnu.org/licenses/.
    16   *
    17   * Copyright (c) 2012 Jeremy Long. All Rights Reserved.
    18   */
    19  package org.owasp.dependencycheck.utils;
    20
    21  import java.io.File;
    22  import org.owasp.dependencycheck.utils.Settings;
    23  import org.owasp.dependencycheck.utils.Downloader;
    24  import java.net.URL;
    25  import org.junit.After;
    26  import org.junit.AfterClass;
    27  import org.junit.Before;
    28  import org.junit.BeforeClass;
    29  import org.junit.Test;
    30  import static org.junit.Assert.*;
    31
    32  /**
    33   *
    34   * @author Jeremy Long (jeremy.long@owasp.org)
    35   */
    36  public class DownloaderIntegrationTest {
    37
    38      @BeforeClass
    39      public static void setUpClass() throws Exception {
    40      }
    41
    42      @AfterClass
    43      public static void tearDownClass() throws Exception {
    44      }
    45
    46      @Before
    47      public void setUp() {
    48      }
    49
    50      @After
    51      public void tearDown() {
    52      }
    53
    54      /**
    55       * Test of fetchFile method, of class Downloader.
    56       *
    57       * @throws Exception thrown when an exception occurs.
    58       */
    59      @Test
    60      public void testFetchFile() throws Exception {
    61
    62  //        Settings.setString(Settings.KEYS.CONNECTION_TIMEOUT, "1000");
    63  //        Settings.setString(Settings.KEYS.PROXY_PORT, "8080");
    64  //        Settings.setString(Settings.KEYS.PROXY_URL, "127.0.0.1");
    65
    66          URL url = new URL(Settings.getString(Settings.KEYS.CVE_MODIFIED_20_URL));
    67          File outputPath = new File("target/downloaded_cve.xml");
    68          Downloader.fetchFile(url, outputPath);
    69
    70      }
    71
    72      @Test
    73      public void testGetLastModified() throws Exception {
    74          URL url = new URL("http://nvd.nist.gov/download/nvdcve-2012.xml");
    75          long timestamp = Downloader.getLastModified(url);
    76          assertTrue("timestamp equal to zero?", timestamp > 0);
    77      }
    78  }