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.analyzer;
19  
20  import java.io.File;
21  import static org.junit.Assert.assertEquals;
22  import static org.junit.Assert.assertTrue;
23  import org.junit.Test;
24  import org.owasp.dependencycheck.BaseTest;
25  import org.owasp.dependencycheck.dependency.Dependency;
26  
27  /**
28   *
29   * @author Jeremy Long
30   */
31  public class FileNameAnalyzerTest extends BaseTest  {
32  
33      /**
34       * Test of getName method, of class FileNameAnalyzer.
35       */
36      @Test
37      public void testGetName() {
38          FileNameAnalyzer instance = new FileNameAnalyzer();
39          String expResult = "File Name Analyzer";
40          String result = instance.getName();
41          assertEquals(expResult, result);
42      }
43  
44      /**
45       * Test of getAnalysisPhase method, of class FileNameAnalyzer.
46       */
47      @Test
48      public void testGetAnalysisPhase() {
49          FileNameAnalyzer instance = new FileNameAnalyzer();
50          AnalysisPhase expResult = AnalysisPhase.INFORMATION_COLLECTION;
51          AnalysisPhase result = instance.getAnalysisPhase();
52          assertEquals(expResult, result);
53      }
54  
55      /**
56       * Test of analyze method, of class FileNameAnalyzer.
57       */
58      @Test
59      public void testAnalyze() throws Exception {
60          //File struts = new File(this.getClass().getClassLoader().getResource("struts2-core-2.1.2.jar").getPath());
61          File struts = BaseTest.getResourceAsFile(this, "struts2-core-2.1.2.jar");
62          Dependency resultStruts = new Dependency(struts);
63          //File axis = new File(this.getClass().getClassLoader().getResource("axis2-adb-1.4.1.jar").getPath());
64          File axis = BaseTest.getResourceAsFile(this, "axis2-adb-1.4.1.jar");
65          Dependency resultAxis = new Dependency(axis);
66          FileNameAnalyzer instance = new FileNameAnalyzer();
67          instance.analyze(resultStruts, null);
68          assertTrue(resultStruts.getVendorEvidence().toString().toLowerCase().contains("struts"));
69  
70          instance.analyze(resultAxis, null);
71          assertTrue(resultStruts.getVersionEvidence().toString().toLowerCase().contains("2.1.2"));
72  
73      }
74  
75      /**
76       * Test of initialize method, of class FileNameAnalyzer.
77       */
78      @Test
79      public void testInitialize() throws Exception {
80          FileNameAnalyzer instance = new FileNameAnalyzer();
81          instance.initialize();
82          assertTrue(true); //initialize does nothing.
83      }
84  
85      /**
86       * Test of close method, of class FileNameAnalyzer.
87       */
88      @Test
89      public void testClose() throws Exception {
90          FileNameAnalyzer instance = new FileNameAnalyzer();
91          instance.close();
92          assertTrue(true); //close does nothing.
93      }
94  }