use of com.synopsys.integration.detector.result.DetectorResult 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.result.DetectorResult 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());
}
use of com.synopsys.integration.detector.result.DetectorResult in project synopsys-detect by blackducksoftware.
the class DetectorRuleSetEvaluator method evaluateSearchable.
public DetectorResult evaluateSearchable(DetectorRuleSet detectorRuleSet, DetectorRule detectorRule, SearchEnvironment environment) {
if (!environment.getDetectorFilter().test(detectorRule)) {
return new ExcludedDetectorResult();
}
int maxDepth = detectorRule.getMaxDepth();
if (environment.getDepth() > maxDepth) {
return new MaxDepthExceededDetectorResult(environment.getDepth(), maxDepth);
}
Set<DetectorRule> yieldTo = environment.getAppliedSoFar().stream().filter(it -> detectorRuleSet.getYieldsTo(detectorRule).contains(it)).collect(Collectors.toSet());
if (yieldTo.size() > 0) {
return new YieldedDetectorResult(yieldTo.stream().map(DetectorRule::getName).collect(Collectors.toSet()));
}
boolean nestable = detectorRule.isNestable();
boolean selfNestable = detectorRule.isSelfNestable();
boolean selfTypeNestable = detectorRule.isSelfTypeNestable();
DetectorType detectorType = detectorRule.getDetectorType();
Set<DetectorType> notNestableBeneath = detectorRule.getNotNestableBeneath();
if (environment.isForceNestedSearch()) {
return new ForcedNestedPassedDetectorResult();
} else if (nestable) {
if (!selfNestable && environment.getAppliedToParent().stream().anyMatch(detectorRule::equals)) {
return new NotSelfNestableDetectorResult();
}
if (!selfTypeNestable && environment.getAppliedToParent().stream().map(DetectorRule::getDetectorType).anyMatch(detectorType::equals)) {
return new NotSelfTypeNestableDetectorResult(detectorType);
}
if (notNestableBeneath.size() > 0) {
Optional<DetectorType> notNestableBeneathType = environment.getAppliedToParent().stream().map(DetectorRule::getDetectorType).filter(notNestableBeneath::contains).findAny();
if (notNestableBeneathType.isPresent()) {
return new NotNestableBeneathDetectorResult(notNestableBeneathType.get());
}
}
} else if (environment.getAppliedToParent().stream().anyMatch(it -> !it.isNestInvisible())) {
return new NotNestableDetectorResult();
}
return new PassedDetectorResult();
}
use of com.synopsys.integration.detector.result.DetectorResult in project synopsys-detect by blackducksoftware.
the class DetectorRuleSetEvaluatorTest method nestableExcept.
@Test
public void nestableExcept() {
DetectorRuleSetBuilder ruleSet = new DetectorRuleSetBuilder();
DetectorRule xcode = ruleSet.addDetector(DetectorType.XCODE, "Xcode", XcodeProjectDetectable.class, (e) -> null).defaults().build();
DetectorRule swift = ruleSet.addDetector(DetectorType.SWIFT, "Swift", SwiftCliDetectable.class, (e) -> null).defaults().nestableExceptTo(DetectorType.XCODE).build();
// XCODE applied at depth 0, we are now scanning a folder at depth 2.
Set<DetectorRule> appliedToParent = Sets.newHashSet(xcode);
Set<DetectorRule> appliedSoFar = Sets.newHashSet();
SearchEnvironment searchEnvironment = new SearchEnvironment(2, (d) -> true, false, false, appliedToParent, appliedSoFar);
DetectorResult result = new DetectorRuleSetEvaluator().evaluateSearchable(ruleSet.build(), swift, searchEnvironment);
Assertions.assertEquals(NotNestableBeneathDetectorResult.class, result.getClass());
}
use of com.synopsys.integration.detector.result.DetectorResult in project synopsys-detect by blackducksoftware.
the class DetectorRuleSetEvaluatorTest method nestableExceptByDetectorType.
@Test
public void nestableExceptByDetectorType() {
DetectorRuleSetBuilder ruleSet = new DetectorRuleSetBuilder();
DetectorRule workspaceRule = ruleSet.addDetector(DetectorType.XCODE, "Xcode Workspace", XcodeWorkspaceDetectable.class, (e) -> null).defaults().notSelfTypeNestable().build();
DetectorRule projectRule = ruleSet.addDetector(DetectorType.XCODE, "Xcode Project", XcodeProjectDetectable.class, (e) -> null).defaults().notSelfTypeNestable().build();
// XCODE applied at depth 0, we are now scanning a folder at depth 2.
Set<DetectorRule> appliedToParent = Sets.newHashSet(workspaceRule);
Set<DetectorRule> appliedSoFar = Sets.newHashSet();
SearchEnvironment searchEnvironment = new SearchEnvironment(2, (d) -> true, false, false, appliedToParent, appliedSoFar);
DetectorResult result = new DetectorRuleSetEvaluator().evaluateSearchable(ruleSet.build(), projectRule, searchEnvironment);
Assertions.assertEquals(NotSelfTypeNestableDetectorResult.class, result.getClass());
}
Aggregations