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