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.util.List;
21  import static org.junit.Assert.assertFalse;
22  import static org.junit.Assert.assertTrue;
23  import org.junit.Test;
24  import org.owasp.dependencycheck.BaseDBTestCase;
25  import org.owasp.dependencycheck.utils.Settings;
26  
27  /**
28   *
29   * @author Jeremy Long
30   */
31  public class AnalyzerServiceTest extends BaseDBTestCase {
32  
33      /**
34       * Test of getAnalyzers method, of class AnalyzerService.
35       */
36      @Test
37      public void testGetAnalyzers() {
38          AnalyzerService instance = new AnalyzerService(Thread.currentThread().getContextClassLoader());
39          List<Analyzer> result = instance.getAnalyzers();
40  
41          boolean found = false;
42          for (Analyzer a : result) {
43              if ("Jar Analyzer".equals(a.getName())) {
44                  found = true;
45              }
46          }
47          assertTrue("JarAnalyzer loaded", found);
48      }
49      
50      /**
51       * Test of getAnalyzers method, of class AnalyzerService.
52       */
53      @Test
54      public void testGetExperimentalAnalyzers() {
55          Settings.setBoolean(Settings.KEYS.ANALYZER_EXPERIMENTAL_ENABLED, false);
56          AnalyzerService instance = new AnalyzerService(Thread.currentThread().getContextClassLoader());
57          List<Analyzer> result = instance.getAnalyzers();
58          String experimental = "CMake Analyzer";
59          boolean found = false;
60          for (Analyzer a : result) {
61              if (experimental.equals(a.getName())) {
62                  found = true;
63              }
64          }
65          assertFalse("Experimental analyzer loaded when set to false", found);
66          
67          Settings.setBoolean(Settings.KEYS.ANALYZER_EXPERIMENTAL_ENABLED, true);
68          result = instance.getAnalyzers();
69          found = false;
70          for (Analyzer a : result) {
71              if (experimental.equals(a.getName())) {
72                  found = true;
73              }
74          }
75          assertTrue("Experimental analyzer not loaded when set to true", found);
76      }
77  }