View Javadoc
1   /*
2    * This file is part of dependency-check-core.
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) 2012 Jeremy Long. All Rights Reserved.
17   */
18  package org.owasp.dependencycheck.data.cwe;
19  
20  import static org.junit.Assert.assertEquals;
21  
22  import org.junit.Test;
23  import org.owasp.dependencycheck.BaseTest;
24  
25  /**
26   *
27   * @author Jeremy Long
28   */
29  public class CweDBTest  extends BaseTest {
30  
31      /**
32       * Method to serialize the CWE HashMap. This is not used in production; this is only used once during dev to create
33       * the serialized HashMap.
34       */
35  //    @Test
36  //    public void testUpdate() throws Exception {
37  //        SAXParserFactory factory = SAXParserFactory.newInstance();
38  //        SAXParser saxParser = factory.newSAXParser();
39  //
40  //        CweHandler handler = new CweHandler();
41  //        //File file = new File(this.getClass().getClassLoader().getResource("cwe.2000.xml").getPath());
42  //        File file = new File(this.getClass().getClassLoader().getResource("cwec_v2.5.xml").getPath());
43  //
44  //        saxParser.parse(file, handler);
45  //        System.out.println("Found " + handler.getCwe().size() + " cwe entries.");
46  //        Map<String, String> cwe = handler.getCwe();
47  ////        FileOutputStream fout = new FileOutputStream("target/current.csv");
48  ////        //FileOutputStream fout = new FileOutputStream("target/new.csv");
49  ////        PrintWriter writer = new PrintWriter(fout);
50  ////        for (Map.Entry<String, String> entry : cwe.entrySet()) {
51  ////            writer.print('"');
52  ////            writer.print(entry.getKey());
53  ////            writer.print('"');
54  ////            writer.print(',');
55  ////            writer.print('"');
56  ////            writer.print(entry.getValue());
57  ////            writer.println('"');
58  ////        }
59  ////        writer.close();
60  //
61  //        FileOutputStream fout = new FileOutputStream("src/main/resources/data/cwe.hashmap.serialized");
62  //        ObjectOutputStream objOut = new ObjectOutputStream(fout);
63  //        objOut.writeObject(cwe);
64  //        objOut.close();
65  //    }
66      /**
67       * Test of getCweName method, of class CweDB.
68       */
69      @Test
70      public void testGetCweName() {
71          String cweId = "CWE-16";
72          String expResult = "Configuration";
73          String result = CweDB.getCweName(cweId);
74          assertEquals(expResult, result);
75      }
76  }