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.data.cwe;
    20
    21  import org.owasp.dependencycheck.data.cwe.CweDB;
    22  import org.junit.After;
    23  import org.junit.AfterClass;
    24  import org.junit.Before;
    25  import org.junit.BeforeClass;
    26  import org.junit.Test;
    27  import static org.junit.Assert.*;
    28
    29  /**
    30   *
    31   * @author Jeremy Long (jeremy.long@owasp.org)
    32   */
    33  public class CweDBTest {
    34
    35      public CweDBTest() {
    36      }
    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       * Method to serialize the CWE HashMap. This is not used in production; this
    56       * is only used once during dev to create the serialized HashMap.
    57       */
    58  //    @Test
    59  //    public void testUpdate() throws Exception {
    60  //        SAXParserFactory factory = SAXParserFactory.newInstance();
    61  //        SAXParser saxParser = factory.newSAXParser();
    62  //
    63  //        CweHandler handler = new CweHandler();
    64  //        File file = new File(this.getClass().getClassLoader().getResource("cwe.2000.xml").getPath());
    65  //
    66  //        saxParser.parse(file, handler);
    67  //        System.out.println("Found " + handler.getCwe().size() + " cwe entries.");
    68  //        Map<String,String> cwe = handler.getCwe();
    69  //        FileOutputStream fout = new FileOutputStream("src/main/resources/data/cwe.hashmap.serialized");
    70  //        ObjectOutputStream objOut = new ObjectOutputStream(fout);
    71  //        objOut.writeObject(cwe);
    72  //        objOut.close();
    73  //    }
    74      /**
    75       * Test of getCweName method, of class CweDB.
    76       */
    77      @Test
    78      public void testGetCweName() {
    79          String cweId = "CWE-16";
    80          String expResult = "Configuration";
    81          String result = CweDB.getCweName(cweId);
    82          assertEquals(expResult, result);
    83      }
    84  }