use of com.synopsys.integration.detectable.detectable.exception.DetectableException in project synopsys-detect by blackducksoftware.
the class ProjectInspectorAirGapCreator method install.
private void install(File container, String targetDirectory, String propertyName) throws DetectUserFriendlyException {
try {
File destination = new File(container, targetDirectory);
// actually downloads it to 'destination/zipName'
File downloaded = projectInspectorInstaller.downloadZip(propertyName, destination);
// move 'destination/zipName' to 'destination'
FileUtils.copyDirectory(downloaded, destination);
// delete 'destination/zipName'
FileUtils.deleteDirectory(downloaded);
} catch (DetectableException | IOException e) {
throw new DetectUserFriendlyException("An error occurred installing project-inspector to the " + targetDirectory + " folder.", e, ExitCodeType.FAILURE_GENERAL_ERROR);
}
}
use of com.synopsys.integration.detectable.detectable.exception.DetectableException in project synopsys-detect by blackducksoftware.
the class ExtractableEvaluatorTest method testEvaluationExtractableException.
@Test
public void testEvaluationExtractableException() throws DetectableException {
DetectorEvaluationOptions evaluationOptions = Mockito.mock(DetectorEvaluationOptions.class);
ExtractionEnvironment extractionEnvironment = Mockito.mock(ExtractionEnvironment.class);
Function<DetectorEvaluation, ExtractionEnvironment> extractionEnvironmentProvider = (detectorEvaluation) -> extractionEnvironment;
ExtractableEvaluator evaluator = new ExtractableEvaluator(evaluationOptions, extractionEnvironmentProvider);
DetectorEvaluationTree detectorEvaluationTree = Mockito.mock(DetectorEvaluationTree.class);
Mockito.when(detectorEvaluationTree.getDirectory()).thenReturn(new File("."));
DetectorEvaluatorListener detectorEvaluatorListener = Mockito.mock(DetectorEvaluatorListener.class);
evaluator.setDetectorEvaluatorListener(detectorEvaluatorListener);
DetectorEvaluation detectorEvaluation = createEvaluationMocks(evaluationOptions, detectorEvaluationTree, false, true);
DetectorAggregateEvaluationResult result = evaluator.evaluate(detectorEvaluationTree);
assertEquals(detectorEvaluationTree, result.getEvaluationTree());
Mockito.verify(detectorEvaluatorListener).extractableStarted(detectorEvaluation);
Mockito.verify(detectorEvaluation).setExtractable(Mockito.any(DetectorResult.class));
Mockito.verify(detectorEvaluatorListener).extractableEnded(detectorEvaluation);
}
use of com.synopsys.integration.detectable.detectable.exception.DetectableException in project synopsys-detect by blackducksoftware.
the class ExtractableEvaluatorTest method createEvaluationMocks.
private DetectorEvaluation createEvaluationMocks(DetectorEvaluationOptions evaluationOptions, DetectorEvaluationTree detectorEvaluationTree, boolean extractable, boolean throwException) throws DetectableException {
DetectorEvaluation detectorEvaluation = Mockito.mock(DetectorEvaluation.class);
Detectable detectable = Mockito.mock(Detectable.class);
DetectableResult detectableExtractableResult = Mockito.mock(DetectableResult.class);
Mockito.when(detectableExtractableResult.getPassed()).thenReturn(true);
Mockito.when(detectableExtractableResult.toDescription()).thenReturn("test detectable");
Mockito.when(detectable.extractable()).thenReturn(detectableExtractableResult);
Mockito.when(detectorEvaluation.getDetectable()).thenReturn(detectable);
List<DetectorEvaluation> detectorEvaluations = Collections.singletonList(detectorEvaluation);
Mockito.when(detectorEvaluationTree.getOrderedEvaluations()).thenReturn(detectorEvaluations);
DetectorRuleSet detectorRuleSet = Mockito.mock(DetectorRuleSet.class);
Mockito.when(detectorEvaluationTree.getDetectorRuleSet()).thenReturn(detectorRuleSet);
DetectorRule detectorRule = Mockito.mock(DetectorRule.class);
Mockito.when(detectorRule.getDescriptiveName()).thenReturn("test rule");
Mockito.when(detectorEvaluation.getDetectorRule()).thenReturn(detectorRule);
Mockito.when(detectorEvaluationTree.getDepthFromRoot()).thenReturn(0);
Mockito.when(evaluationOptions.isForceNested()).thenReturn(true);
Predicate<DetectorRule> rulePredicate = it -> true;
Mockito.when(evaluationOptions.getDetectorFilter()).thenReturn(rulePredicate);
Mockito.when(detectorEvaluation.isSearchable()).thenReturn(true);
Mockito.when(detectorEvaluation.isApplicable()).thenReturn(true);
Mockito.when(detectorEvaluation.isExtractable()).thenReturn(extractable);
Mockito.when(detectorRule.createDetectable(Mockito.any(DetectableEnvironment.class))).thenReturn(detectable);
Mockito.when(detectable.applicable()).thenReturn(new PassedDetectableResult());
if (throwException) {
Mockito.when(detectable.extractable()).thenThrow(new DetectableException("JUnit Expected Exception."));
} else {
Mockito.when(detectable.extractable()).thenReturn(detectableExtractableResult);
}
return detectorEvaluation;
}
use of com.synopsys.integration.detectable.detectable.exception.DetectableException in project synopsys-detect by blackducksoftware.
the class ExtractableEvaluatorTest method testEvaluationSuccess.
@Test
public void testEvaluationSuccess() throws DetectableException {
DetectorEvaluationOptions evaluationOptions = Mockito.mock(DetectorEvaluationOptions.class);
ExtractionEnvironment extractionEnvironment = Mockito.mock(ExtractionEnvironment.class);
Function<DetectorEvaluation, ExtractionEnvironment> extractionEnvironmentProvider = (detectorEvaluation) -> extractionEnvironment;
ExtractableEvaluator evaluator = new ExtractableEvaluator(evaluationOptions, extractionEnvironmentProvider);
DetectorEvaluationTree detectorEvaluationTree = Mockito.mock(DetectorEvaluationTree.class);
Mockito.when(detectorEvaluationTree.getDirectory()).thenReturn(new File("."));
DetectorEvaluatorListener detectorEvaluatorListener = Mockito.mock(DetectorEvaluatorListener.class);
evaluator.setDetectorEvaluatorListener(detectorEvaluatorListener);
DetectorEvaluation detectorEvaluation = createEvaluationMocks(evaluationOptions, detectorEvaluationTree, false, false);
DetectorAggregateEvaluationResult result = evaluator.evaluate(detectorEvaluationTree);
assertEquals(detectorEvaluationTree, result.getEvaluationTree());
Mockito.verify(detectorEvaluatorListener).extractableStarted(detectorEvaluation);
Mockito.verify(detectorEvaluation).setExtractable(Mockito.any(DetectorResult.class));
Mockito.verify(detectorEvaluatorListener).extractableEnded(detectorEvaluation);
}
use of com.synopsys.integration.detectable.detectable.exception.DetectableException in project synopsys-detect by blackducksoftware.
the class ExtractionEvaluatorTest method createEvaluationMocks.
private DetectorEvaluation createEvaluationMocks(DetectorEvaluationOptions evaluationOptions, DetectorEvaluationTree detectorEvaluationTree, boolean extractionExists, boolean throwException) throws DetectableException, ExecutableFailedException, IOException, CycleDetectedException, MissingExternalIdException, ExecutableRunnerException, ParserConfigurationException, SAXException {
ExtractionEnvironment extractionEnvironment = Mockito.mock(ExtractionEnvironment.class);
DetectorEvaluation detectorEvaluation = Mockito.mock(DetectorEvaluation.class);
Detectable detectable = Mockito.mock(Detectable.class);
DetectableResult detectableExtractableResult = Mockito.mock(DetectableResult.class);
Mockito.when(detectableExtractableResult.getPassed()).thenReturn(true);
Mockito.when(detectableExtractableResult.toDescription()).thenReturn("test detectable");
Mockito.when(detectable.extractable()).thenReturn(detectableExtractableResult);
Mockito.when(detectorEvaluation.getDetectable()).thenReturn(detectable);
Mockito.when(detectorEvaluation.getExtractionEnvironment()).thenReturn(extractionEnvironment);
Mockito.when(detectorEvaluation.isSearchable()).thenReturn(true);
Mockito.when(detectorEvaluation.isApplicable()).thenReturn(true);
Mockito.when(detectorEvaluation.isExtractable()).thenReturn(true);
List<DetectorEvaluation> detectorEvaluations = Collections.singletonList(detectorEvaluation);
Mockito.when(detectorEvaluationTree.getOrderedEvaluations()).thenReturn(detectorEvaluations);
DetectorRuleSet detectorRuleSet = Mockito.mock(DetectorRuleSet.class);
Mockito.when(detectorEvaluationTree.getDetectorRuleSet()).thenReturn(detectorRuleSet);
DetectorRule detectorRule = Mockito.mock(DetectorRule.class);
Mockito.when(detectorRule.getDescriptiveName()).thenReturn("test rule");
Mockito.when(detectorEvaluation.getDetectorRule()).thenReturn(detectorRule);
Mockito.when(detectorEvaluationTree.getDepthFromRoot()).thenReturn(0);
Mockito.when(evaluationOptions.isForceNested()).thenReturn(true);
Predicate<DetectorRule> rulePredicate = it -> true;
Mockito.when(evaluationOptions.getDetectorFilter()).thenReturn(rulePredicate);
Mockito.when(detectorRule.createDetectable(Mockito.any(DetectableEnvironment.class))).thenReturn(detectable);
Mockito.when(detectable.applicable()).thenReturn(new PassedDetectableResult());
if (throwException) {
Mockito.when(detectable.extract(Mockito.eq(extractionEnvironment))).thenThrow(new RuntimeException("JUnit expected exception"));
} else {
Mockito.when(detectable.extract(Mockito.eq(extractionEnvironment))).thenReturn(new Extraction.Builder().success().build());
}
return detectorEvaluation;
}
Aggregations