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  
38  /**
39   * Unit tests for NodePackageAnalyzer.
40   *
41   * @author Dale Visser <dvisser@ida.org>
42   */
43  public class ComposerLockAnalyzerTest extends BaseTest {
44  
45      /**
46       * The analyzer to test.
47       */
48      ComposerLockAnalyzer analyzer;
49  
50      /**
51       * Correctly setup the analyzer for testing.
52       *
53       * @throws Exception thrown if there is a problem
54       */
55      @Before
56      public void setUp() throws Exception {
57          analyzer = new ComposerLockAnalyzer();
58          analyzer.setFilesMatched(true);
59          analyzer.initialize();
60      }
61  
62      /**
63       * Cleanup the analyzer's temp files, etc.
64       *
65       * @throws Exception thrown if there is a problem
66       */
67      @After
68      public void tearDown() throws Exception {
69          analyzer.close();
70          analyzer = null;
71      }
72  
73      /**
74       * Test of getName method, of class ComposerLockAnalyzer.
75       */
76      @Test
77      public void testGetName() {
78          assertEquals("Composer.lock analyzer", analyzer.getName());
79      }
80  
81      /**
82       * Test of supportsExtension method, of class ComposerLockAnalyzer.
83       */
84      @Test
85      public void testSupportsFiles() {
86          assertTrue(analyzer.accept(new File("composer.lock")));
87      }
88  
89      /**
90       * Test of inspect method, of class PythonDistributionAnalyzer.
91       *
92       * @throws AnalysisException is thrown when an exception occurs.
93       */
94      @Test
95      public void testAnalyzePackageJson() throws Exception {
96          final Engine engine = new Engine();
97          final Dependency result = new Dependency(BaseTest.getResourceAsFile(this,
98                  "composer.lock"));
99          analyzer.analyze(result, engine);
100     }
101 }