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);
}
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());
}
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);
}
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;
}
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());
}
Aggregations