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;
19  
20  import org.junit.After;
21  import static org.junit.Assert.assertTrue;
22  import org.junit.Before;
23  import org.junit.Test;
24  import org.owasp.dependencycheck.data.nvdcve.CveDB;
25  import org.owasp.dependencycheck.data.nvdcve.DatabaseProperties;
26  import org.owasp.dependencycheck.reporting.ReportGenerator;
27  import org.owasp.dependencycheck.utils.Settings;
28  
29  /**
30   *
31   * @author Jeremy Long
32   */
33  public class EngineIntegrationTest extends BaseTest {
34  
35      @Before
36      public void setUp() throws Exception {
37          org.owasp.dependencycheck.BaseDBTestCase.ensureDBExists();
38      }
39  
40      @After
41      public void tearDown() {
42      }
43  
44      /**
45       * Test running the entire engine.
46       *
47       * @throws Exception is thrown when an exception occurs.
48       */
49      @Test
50      public void testEngine() throws Exception {
51          String testClasses = "target/test-classes";
52          boolean autoUpdate = Settings.getBoolean(Settings.KEYS.AUTO_UPDATE);
53          Settings.setBoolean(Settings.KEYS.AUTO_UPDATE, false);
54          Engine instance = new Engine();
55          Settings.setBoolean(Settings.KEYS.AUTO_UPDATE, autoUpdate);
56          instance.scan(testClasses);
57          assertTrue(instance.getDependencies().size() > 0);
58          instance.analyzeDependencies();
59          CveDB cveDB = new CveDB();
60          cveDB.open();
61          DatabaseProperties dbProp = cveDB.getDatabaseProperties();
62          cveDB.close();
63          ReportGenerator rg = new ReportGenerator("DependencyCheck", instance.getDependencies(), instance.getAnalyzers(), dbProp);
64          rg.generateReports("./target/", "ALL");
65          instance.cleanup();
66      }
67  }