use of com.synopsys.integration.detect.workflow.event.EventSystem 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.detect.workflow.event.EventSystem in project synopsys-detect by blackducksoftware.
the class OperationSystemTest method initTest.
@BeforeEach
public void initTest() {
eventSystem = new EventSystem();
statusEventPublisher = new StatusEventPublisher(eventSystem);
detectIssues = new ArrayList<>();
detectOperations = new ArrayList<>();
eventSystem.registerListener(Event.DetectOperationsComplete, detectOperations::addAll);
eventSystem.registerListener(Event.Issue, detectIssues::add);
}
use of com.synopsys.integration.detect.workflow.event.EventSystem in project synopsys-detect by blackducksoftware.
the class DetectorToolTest method executeToolTest.
private DetectorToolResult executeToolTest(Extraction extraction, DetectableResult extractionResult, String projectBomTool) throws DetectableException, ExecutableFailedException {
ExtractionEnvironmentProvider extractionEnvironmentProvider = Mockito.mock(ExtractionEnvironmentProvider.class);
DetectorFinder detectorFinder = Mockito.mock(DetectorFinder.class);
EventSystem eventSystem = Mockito.mock(EventSystem.class);
CodeLocationConverter codeLocationConverter = Mockito.mock(CodeLocationConverter.class);
DetectorIssuePublisher detectorIssuePublisher = Mockito.mock(DetectorIssuePublisher.class);
StatusEventPublisher statusEventPublisher = Mockito.mock(StatusEventPublisher.class);
ExitCodePublisher exitCodePublisher = Mockito.mock(ExitCodePublisher.class);
DetectorEventPublisher detectorEventPublisher = Mockito.mock(DetectorEventPublisher.class);
DetectorTool tool = new DetectorTool(detectorFinder, extractionEnvironmentProvider, eventSystem, codeLocationConverter, detectorIssuePublisher, statusEventPublisher, exitCodePublisher, detectorEventPublisher);
File directory = new File(".");
GoModCliDetectable detectable = createDetectable(extraction, extractionResult);
DetectorRule<GoModCliDetectable> rule = createRule(detectable);
DetectorRuleSet detectorRuleSet = createRuleSet(rule);
DetectorFinderOptions detectorFinderOptions = createFinderOptions();
DetectorEvaluationOptions evaluationOptions = createEvaluationOptions();
DetectorEvaluationTree evaluationTree = createEvaluationTree(extraction, extractionResult, directory, rule, detectorRuleSet);
Mockito.when(detectorFinder.findDetectors(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(Optional.of(evaluationTree));
return tool.performDetectors(directory, detectorRuleSet, detectorFinderOptions, evaluationOptions, projectBomTool, new ArrayList<>(), new SimpleFileFinder());
}
use of com.synopsys.integration.detect.workflow.event.EventSystem in project synopsys-detect by blackducksoftware.
the class ExitManagerTest method testForceExit.
@Test
public void testForceExit() {
long startTime = System.currentTimeMillis();
EventSystem eventSystem = new EventSystem();
DetectStatusManager statusManager = new DetectStatusManager(eventSystem);
ExceptionUtility exitCodeUtility = new ExceptionUtility();
ExitCodeManager exitCodeManager = new ExitCodeManager(eventSystem, exitCodeUtility);
exitCodeManager.addExitCodeRequest(new ExitCodeRequest(ExitCodeType.FAILURE_CONFIGURATION, "JUnit failure code."));
ExitManager exitManager = new ExitManager(eventSystem, exitCodeManager, statusManager);
ExitOptions exitOptions = new ExitOptions(startTime, true, true);
ExitResult exitResult = exitManager.exit(exitOptions);
assertEquals(startTime, exitOptions.getStartTime());
assertTrue(exitResult.shouldForceSuccess());
assertTrue(exitResult.shouldPerformExit());
assertEquals(ExitCodeType.FAILURE_CONFIGURATION, exitResult.getExitCodeType());
}
use of com.synopsys.integration.detect.workflow.event.EventSystem in project synopsys-detect by blackducksoftware.
the class ExitManagerTest method testSkipExit.
@Test
public void testSkipExit() {
long startTime = System.currentTimeMillis();
EventSystem eventSystem = new EventSystem();
DetectStatusManager statusManager = new DetectStatusManager(eventSystem);
ExceptionUtility exitCodeUtility = new ExceptionUtility();
ExitCodeManager exitCodeManager = new ExitCodeManager(eventSystem, exitCodeUtility);
exitCodeManager.addExitCodeRequest(new ExitCodeRequest(ExitCodeType.FAILURE_CONFIGURATION, "JUnit failure code."));
ExitManager exitManager = new ExitManager(eventSystem, exitCodeManager, statusManager);
ExitOptions exitOptions = new ExitOptions(startTime, false, false);
ExitResult exitResult = exitManager.exit(exitOptions);
assertEquals(startTime, exitOptions.getStartTime());
assertFalse(exitResult.shouldForceSuccess());
assertFalse(exitResult.shouldPerformExit());
assertEquals(ExitCodeType.FAILURE_CONFIGURATION, exitResult.getExitCodeType());
}
Aggregations