Search in sources :

Example 1 with DetectorRule

use of com.synopsys.integration.detector.rule.DetectorRule in project synopsys-detect by blackducksoftware.

the class FormattedOutputManagerTest method detectorOutputStatusDataTest.

@Test
public <T extends Detectable> void detectorOutputStatusDataTest() throws IllegalAccessException {
    EventSystem eventSystem = new EventSystem();
    FormattedOutputManager formattedOutputManager = new FormattedOutputManager(eventSystem);
    DetectorRule rule = Mockito.mock(DetectorRule.class);
    Mockito.when(rule.getDescriptiveName()).thenReturn("");
    Mockito.when(rule.getName()).thenReturn("");
    Mockito.when(rule.getDetectorType()).thenReturn(DetectorType.GO_MOD);
    DetectorEvaluation detectorEvaluation = new DetectorEvaluation(rule);
    ExecutableNotFoundDetectableResult result = new ExecutableNotFoundDetectableResult("go");
    DetectorResult extractableResult = new DetectorResult(result.getPassed(), result.toDescription(), result.getClass(), Collections.emptyList(), Collections.emptyList());
    detectorEvaluation.setExtractable(extractableResult);
    detectorEvaluation.setApplicable(new DetectorResult(true, "", Collections.emptyList(), Collections.emptyList()));
    detectorEvaluation.setSearchable(new DetectorResult(true, "", Collections.emptyList(), Collections.emptyList()));
    detectorEvaluation.setDetectableEnvironment(new DetectableEnvironment(new File("")));
    DetectorToolResult detectorToolResult = new DetectorToolResult(null, null, null, new HashSet<>(), new DetectorEvaluationTree(null, 0, null, Collections.singletonList(detectorEvaluation), new HashSet<>()), null);
    eventSystem.publishEvent(Event.DetectorsComplete, detectorToolResult);
    DetectInfo detectInfo = new DetectInfo("", null, "");
    FormattedOutput formattedOutput = formattedOutputManager.createFormattedOutput(detectInfo);
    FormattedDetectorOutput detectorOutput = formattedOutput.detectors.get(0);
    Assertions.assertEquals("FAILURE", detectorOutput.status);
    Assertions.assertEquals(DetectorStatusCode.EXECUTABLE_NOT_FOUND, detectorOutput.statusCode);
    Assertions.assertEquals("No go executable was found.", detectorOutput.statusReason);
}
Also used : ExecutableNotFoundDetectableResult(com.synopsys.integration.detectable.detectable.result.ExecutableNotFoundDetectableResult) DetectInfo(com.synopsys.integration.detect.configuration.DetectInfo) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) FormattedOutputManager(com.synopsys.integration.detect.workflow.report.output.FormattedOutputManager) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) FormattedOutput(com.synopsys.integration.detect.workflow.report.output.FormattedOutput) DetectorToolResult(com.synopsys.integration.detect.tool.detector.DetectorToolResult) DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) FormattedDetectorOutput(com.synopsys.integration.detect.workflow.report.output.FormattedDetectorOutput) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) EventSystem(com.synopsys.integration.detect.workflow.event.EventSystem) DetectorResult(com.synopsys.integration.detector.result.DetectorResult) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 2 with DetectorRule

use of com.synopsys.integration.detector.rule.DetectorRule in project synopsys-detect by blackducksoftware.

the class DetectorRuleSetBuilderTest method testReorderedWithYield.

@Test
public void testReorderedWithYield() {
    DetectorRuleSetBuilder ruleSetBuilder = new DetectorRuleSetBuilder();
    DetectorRule gradle = ruleSetBuilder.addDetector(DetectorType.GRADLE, "Gradle", GradleDetectable.class, (e) -> null).build();
    DetectorRule npm = ruleSetBuilder.addDetector(DetectorType.NPM, "Npm", NpmCliDetectable.class, (e) -> null).build();
    ruleSetBuilder.yield(gradle).to(npm);
    DetectorRuleSet ruleSet = ruleSetBuilder.build();
    Assertions.assertEquals(2, ruleSet.getOrderedDetectorRules().size());
    Assertions.assertEquals("Npm", ruleSet.getOrderedDetectorRules().get(0).getName());
    Assertions.assertEquals("Gradle", ruleSet.getOrderedDetectorRules().get(1).getName());
}
Also used : Test(org.junit.jupiter.api.Test) NpmCliDetectable(com.synopsys.integration.detectable.detectables.npm.cli.NpmCliDetectable) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) Assertions(org.junit.jupiter.api.Assertions) DetectorType(com.synopsys.integration.detector.base.DetectorType) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) DetectorRuleSetBuilder(com.synopsys.integration.detector.rule.DetectorRuleSetBuilder) GradleDetectable(com.synopsys.integration.detectable.detectables.gradle.inspection.GradleDetectable) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) GradleDetectable(com.synopsys.integration.detectable.detectables.gradle.inspection.GradleDetectable) NpmCliDetectable(com.synopsys.integration.detectable.detectables.npm.cli.NpmCliDetectable) DetectorRuleSetBuilder(com.synopsys.integration.detector.rule.DetectorRuleSetBuilder) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) Test(org.junit.jupiter.api.Test)

Example 3 with DetectorRule

use of com.synopsys.integration.detector.rule.DetectorRule in project synopsys-detect by blackducksoftware.

the class DetectorRuleSetBuilderTest method testCircularYieldThrows.

@Test
public void testCircularYieldThrows() {
    DetectorRuleSetBuilder ruleSetBuilder = new DetectorRuleSetBuilder();
    DetectorRule gradle = ruleSetBuilder.addDetector(DetectorType.GRADLE, "Gradle", GradleDetectable.class, (e) -> null).build();
    DetectorRule npm = ruleSetBuilder.addDetector(DetectorType.NPM, "Npm", NpmCliDetectable.class, (e) -> null).build();
    ruleSetBuilder.yield(gradle).to(npm);
    ruleSetBuilder.yield(npm).to(gradle);
    Assertions.assertThrows(RuntimeException.class, ruleSetBuilder::build);
}
Also used : Test(org.junit.jupiter.api.Test) NpmCliDetectable(com.synopsys.integration.detectable.detectables.npm.cli.NpmCliDetectable) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) Assertions(org.junit.jupiter.api.Assertions) DetectorType(com.synopsys.integration.detector.base.DetectorType) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) DetectorRuleSetBuilder(com.synopsys.integration.detector.rule.DetectorRuleSetBuilder) GradleDetectable(com.synopsys.integration.detectable.detectables.gradle.inspection.GradleDetectable) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) GradleDetectable(com.synopsys.integration.detectable.detectables.gradle.inspection.GradleDetectable) NpmCliDetectable(com.synopsys.integration.detectable.detectables.npm.cli.NpmCliDetectable) DetectorRuleSetBuilder(com.synopsys.integration.detector.rule.DetectorRuleSetBuilder) Test(org.junit.jupiter.api.Test)

Example 4 with DetectorRule

use of com.synopsys.integration.detector.rule.DetectorRule in project synopsys-detect by blackducksoftware.

the class DetectorAggregateEvaluationResultTest method generateDetectorEvaluationTreeMock.

@NotNull
private DetectorEvaluationTree generateDetectorEvaluationTreeMock(DetectorType detectorType) {
    DetectorEvaluationTree evaluationTree = Mockito.mock(DetectorEvaluationTree.class);
    List<DetectorEvaluation> evaluations = new ArrayList<>();
    DetectorEvaluation topLevelEvaluation = Mockito.mock(DetectorEvaluation.class);
    Mockito.when(topLevelEvaluation.isApplicable()).thenReturn(true);
    DetectorRule rule = Mockito.mock(DetectorRule.class);
    Mockito.when(rule.getDetectorType()).thenReturn(detectorType);
    Mockito.when(topLevelEvaluation.getDetectorRule()).thenReturn(rule);
    evaluations.add(topLevelEvaluation);
    Mockito.when(evaluationTree.getOrderedEvaluations()).thenReturn(evaluations);
    return evaluationTree;
}
Also used : DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) ArrayList(java.util.ArrayList) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with DetectorRule

use of com.synopsys.integration.detector.rule.DetectorRule in project synopsys-detect by blackducksoftware.

the class DetectorRuleSetEvaluatorTest method test.

@Test
public void test() {
    DetectorRuleSet detectorRuleSet = Mockito.mock(DetectorRuleSet.class);
    DetectorRule detectorRule = Mockito.mock(DetectorRule.class);
    SearchEnvironment environment = Mockito.mock(SearchEnvironment.class);
    Predicate<DetectorRule> rulePredicate = it -> true;
    Mockito.when(environment.getDetectorFilter()).thenReturn(rulePredicate);
    Mockito.when(detectorRule.getMaxDepth()).thenReturn(1);
    Mockito.when(environment.getDepth()).thenReturn(0);
    Set<DetectorRule> appliedSoFar = new HashSet<>();
    Mockito.when(environment.getAppliedSoFar()).thenReturn(appliedSoFar);
    Set<DetectorRule> appliedToParent = new HashSet<>();
    Mockito.when(environment.getAppliedToParent()).thenReturn(appliedToParent);
    Mockito.when(detectorRule.isNestable()).thenReturn(true);
    Mockito.when(environment.isForceNestedSearch()).thenReturn(false);
    Mockito.when(detectorRule.isSelfTypeNestable()).thenReturn(false);
    Mockito.when(detectorRule.getDetectorType()).thenReturn(DetectorType.GRADLE);
    DetectorRuleSetEvaluator evaluator = new DetectorRuleSetEvaluator();
    DetectorResult result = evaluator.evaluateSearchable(detectorRuleSet, detectorRule, environment);
    assertTrue(result.getPassed());
}
Also used : NotSelfTypeNestableDetectorResult(com.synopsys.integration.detector.result.NotSelfTypeNestableDetectorResult) Predicate(java.util.function.Predicate) Set(java.util.Set) SwiftCliDetectable(com.synopsys.integration.detectable.detectables.swift.cli.SwiftCliDetectable) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) XcodeWorkspaceDetectable(com.synopsys.integration.detectable.detectables.xcode.XcodeWorkspaceDetectable) NotNestableBeneathDetectorResult(com.synopsys.integration.detector.result.NotNestableBeneathDetectorResult) Sets(com.github.jsonldjava.shaded.com.google.common.collect.Sets) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions(org.junit.jupiter.api.Assertions) XcodeProjectDetectable(com.synopsys.integration.detectable.detectables.xcode.XcodeProjectDetectable) DetectorType(com.synopsys.integration.detector.base.DetectorType) DetectorResult(com.synopsys.integration.detector.result.DetectorResult) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) DetectorRuleSetBuilder(com.synopsys.integration.detector.rule.DetectorRuleSetBuilder) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) NotSelfTypeNestableDetectorResult(com.synopsys.integration.detector.result.NotSelfTypeNestableDetectorResult) NotNestableBeneathDetectorResult(com.synopsys.integration.detector.result.NotNestableBeneathDetectorResult) DetectorResult(com.synopsys.integration.detector.result.DetectorResult) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

DetectorRule (com.synopsys.integration.detector.rule.DetectorRule)14 DetectorRuleSet (com.synopsys.integration.detector.rule.DetectorRuleSet)10 Test (org.junit.jupiter.api.Test)9 DetectorResult (com.synopsys.integration.detector.result.DetectorResult)7 Detectable (com.synopsys.integration.detectable.Detectable)6 DetectorEvaluation (com.synopsys.integration.detector.base.DetectorEvaluation)6 DetectorEvaluationTree (com.synopsys.integration.detector.base.DetectorEvaluationTree)6 DetectorType (com.synopsys.integration.detector.base.DetectorType)6 DetectableEnvironment (com.synopsys.integration.detectable.DetectableEnvironment)5 DetectorRuleSetBuilder (com.synopsys.integration.detector.rule.DetectorRuleSetBuilder)5 HashSet (java.util.HashSet)5 Predicate (java.util.function.Predicate)5 Assertions (org.junit.jupiter.api.Assertions)5 Mockito (org.mockito.Mockito)5 NotNestableBeneathDetectorResult (com.synopsys.integration.detector.result.NotNestableBeneathDetectorResult)4 NotSelfTypeNestableDetectorResult (com.synopsys.integration.detector.result.NotSelfTypeNestableDetectorResult)4 List (java.util.List)4 Set (java.util.Set)4 Sets (com.github.jsonldjava.shaded.com.google.common.collect.Sets)3 DetectableResult (com.synopsys.integration.detectable.detectable.result.DetectableResult)3