javadocs + tests

This commit is contained in:
Mark Rekveld
2017-07-10 16:23:17 +02:00
parent cb3cf79beb
commit f2aa3f12be
3 changed files with 126 additions and 6 deletions

View File

@@ -0,0 +1,81 @@
package org.owasp.dependencycheck;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestName;
import org.owasp.dependencycheck.analyzer.AnalysisPhase;
import org.owasp.dependencycheck.utils.Settings;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
/**
* @author Mark Rekveld
*/
public class EngineModeTest extends BaseTest {
@Rule
public TemporaryFolder tempDir = new TemporaryFolder();
@Rule
public TestName testName = new TestName();
private Engine engine;
@Before
public void setUp() throws Exception {
Settings.setString(Settings.KEYS.DATA_DIRECTORY, tempDir.newFolder().getAbsolutePath());
}
@After
public void tearDown() throws Exception {
engine.cleanup();
}
@Test
public void testEvidenceCollectionMode() throws Exception {
engine = new Engine(Engine.Mode.EVIDENCE_COLLECTION);
assertDatabase(false);
for (AnalysisPhase phase : Engine.Mode.EVIDENCE_COLLECTION.phases) {
assertThat(engine.getAnalyzers(phase), is(notNullValue()));
}
for (AnalysisPhase phase : Engine.Mode.EVIDENCE_PROCESSING.phases) {
assertThat(engine.getAnalyzers(phase), is(nullValue()));
}
}
@Test
public void testEvidenceProcessingMode() throws Exception {
engine = new Engine(Engine.Mode.EVIDENCE_PROCESSING);
assertDatabase(true);
for (AnalysisPhase phase : Engine.Mode.EVIDENCE_PROCESSING.phases) {
assertThat(engine.getAnalyzers(phase), is(notNullValue()));
}
for (AnalysisPhase phase : Engine.Mode.EVIDENCE_COLLECTION.phases) {
assertThat(engine.getAnalyzers(phase), is(nullValue()));
}
}
@Test
public void testStandaloneMode() throws Exception {
engine = new Engine(Engine.Mode.STANDALONE);
assertDatabase(true);
for (AnalysisPhase phase : Engine.Mode.STANDALONE.phases) {
assertThat(engine.getAnalyzers(phase), is(notNullValue()));
}
}
private void assertDatabase(boolean exists) throws Exception {
Path directory = Settings.getDataDirectory().toPath();
assertThat(Files.exists(directory), is(true));
assertThat(Files.isDirectory(directory), is(true));
Path database = directory.resolve(Settings.getString(Settings.KEYS.DB_FILE_NAME));
assertThat(Files.exists(database), is(exists));
}
}

View File

@@ -17,13 +17,18 @@
*/
package org.owasp.dependencycheck.analyzer;
import java.util.List;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.owasp.dependencycheck.BaseDBTestCase;
import org.owasp.dependencycheck.utils.Settings;
import java.util.List;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.owasp.dependencycheck.analyzer.AnalysisPhase.FINAL;
import static org.owasp.dependencycheck.analyzer.AnalysisPhase.INITIAL;
/**
*
* @author Jeremy Long
@@ -46,7 +51,22 @@ public class AnalyzerServiceTest extends BaseDBTestCase {
}
assertTrue("JarAnalyzer loaded", found);
}
/**
* Test of getAnalyzers method, of class AnalyzerService.
*/
@Test
public void testGetAnalyzers_SpecificPhases() throws Exception {
AnalyzerService instance = new AnalyzerService(Thread.currentThread().getContextClassLoader());
List<Analyzer> result = instance.getAnalyzers(INITIAL, FINAL);
for (Analyzer a : result) {
if (a.getAnalysisPhase() != INITIAL && a.getAnalysisPhase() != FINAL) {
fail("Only expecting analyzers for phases " + INITIAL + " and " + FINAL);
}
}
}
/**
* Test of getAnalyzers method, of class AnalyzerService.
*/