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 org.junit.After;
21 import org.junit.AfterClass;
22 import static org.junit.Assert.assertEquals;
23 import org.junit.Before;
24 import org.junit.BeforeClass;
25 import org.junit.Test;
26
27 /**
28 *
29 * @author Jeremy Long
30 */
31 public class CweDBTest {
32
33 public CweDBTest() {
34 }
35
36 @BeforeClass
37 public static void setUpClass() throws Exception {
38 }
39
40 @AfterClass
41 public static void tearDownClass() throws Exception {
42 }
43
44 @Before
45 public void setUp() {
46 }
47
48 @After
49 public void tearDown() {
50 }
51
52 /**
53 * Method to serialize the CWE HashMap. This is not used in production; this is only used once during dev to create
54 * the serialized HashMap.
55 */
56 // @Test
57 // public void testUpdate() throws Exception {
58 // SAXParserFactory factory = SAXParserFactory.newInstance();
59 // SAXParser saxParser = factory.newSAXParser();
60 //
61 // CweHandler handler = new CweHandler();
62 // //File file = new File(this.getClass().getClassLoader().getResource("cwe.2000.xml").getPath());
63 // File file = new File(this.getClass().getClassLoader().getResource("cwec_v2.5.xml").getPath());
64 //
65 // saxParser.parse(file, handler);
66 // System.out.println("Found " + handler.getCwe().size() + " cwe entries.");
67 // Map<String, String> cwe = handler.getCwe();
68 //// FileOutputStream fout = new FileOutputStream("target/current.csv");
69 //// //FileOutputStream fout = new FileOutputStream("target/new.csv");
70 //// PrintWriter writer = new PrintWriter(fout);
71 //// for (Map.Entry<String, String> entry : cwe.entrySet()) {
72 //// writer.print('"');
73 //// writer.print(entry.getKey());
74 //// writer.print('"');
75 //// writer.print(',');
76 //// writer.print('"');
77 //// writer.print(entry.getValue());
78 //// writer.println('"');
79 //// }
80 //// writer.close();
81 //
82 // FileOutputStream fout = new FileOutputStream("src/main/resources/data/cwe.hashmap.serialized");
83 // ObjectOutputStream objOut = new ObjectOutputStream(fout);
84 // objOut.writeObject(cwe);
85 // objOut.close();
86 // }
87 /**
88 * Test of getCweName method, of class CweDB.
89 */
90 @Test
91 public void testGetCweName() {
92 String cweId = "CWE-16";
93 String expResult = "Configuration";
94 String result = CweDB.getCweName(cweId);
95 assertEquals(expResult, result);
96 }
97 }