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) 2015 The OWASP Foundatio. All Rights Reserved.
17   */
18  package org.owasp.dependencycheck.analyzer;
19  
20  import org.junit.After;
21  import org.junit.Before;
22  import org.junit.Test;
23  import org.owasp.dependencycheck.BaseTest;
24  import org.owasp.dependencycheck.Engine;
25  import org.owasp.dependencycheck.analyzer.exception.AnalysisException;
26  import org.owasp.dependencycheck.dependency.Confidence;
27  import org.owasp.dependencycheck.dependency.Dependency;
28  import org.owasp.dependencycheck.dependency.Evidence;
29  
30  import java.io.File;
31  
32  import static org.hamcrest.CoreMatchers.containsString;
33  import static org.hamcrest.CoreMatchers.is;
34  import static org.junit.Assert.assertEquals;
35  import static org.junit.Assert.assertThat;
36  import static org.junit.Assert.assertTrue;
37  import org.owasp.dependencycheck.BaseDBTestCase;
38  
39  /**
40   * Unit tests for NodePackageAnalyzer.
41   *
42   * @author Dale Visser
43   */
44  public class ComposerLockAnalyzerTest extends BaseDBTestCase {
45  
46      /**
47       * The analyzer to test.
48       */
49      ComposerLockAnalyzer analyzer;
50  
51      /**
52       * Correctly setup the analyzer for testing.
53       *
54       * @throws Exception thrown if there is a problem
55       */
56      @Before
57      public void setUp() throws Exception {
58          analyzer = new ComposerLockAnalyzer();
59          analyzer.setFilesMatched(true);
60          analyzer.initialize();
61      }
62  
63      /**
64       * Cleanup the analyzer's temp files, etc.
65       *
66       * @throws Exception thrown if there is a problem
67       */
68      @After
69      public void tearDown() throws Exception {
70          analyzer.close();
71          analyzer = null;
72      }
73  
74      /**
75       * Test of getName method, of class ComposerLockAnalyzer.
76       */
77      @Test
78      public void testGetName() {
79          assertEquals("Composer.lock analyzer", analyzer.getName());
80      }
81  
82      /**
83       * Test of supportsExtension method, of class ComposerLockAnalyzer.
84       */
85      @Test
86      public void testSupportsFiles() {
87          assertTrue(analyzer.accept(new File("composer.lock")));
88      }
89  
90      /**
91       * Test of inspect method, of class PythonDistributionAnalyzer.
92       *
93       * @throws AnalysisException is thrown when an exception occurs.
94       */
95      @Test
96      public void testAnalyzePackageJson() throws Exception {
97          final Engine engine = new Engine();
98          final Dependency result = new Dependency(BaseTest.getResourceAsFile(this,
99                  "composer.lock"));
100         analyzer.analyze(result, engine);
101     }
102 }