Search in sources :

Example 1 with EventSystem

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);
}
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 EventSystem

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);
}
Also used : EventSystem(com.synopsys.integration.detect.workflow.event.EventSystem) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with EventSystem

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());
}
Also used : DetectorEvaluationOptions(com.synopsys.integration.detector.evaluation.DetectorEvaluationOptions) GoModCliDetectable(com.synopsys.integration.detectable.detectables.go.gomod.GoModCliDetectable) DetectorFinderOptions(com.synopsys.integration.detector.finder.DetectorFinderOptions) ExtractionEnvironmentProvider(com.synopsys.integration.detect.tool.detector.extraction.ExtractionEnvironmentProvider) ExitCodePublisher(com.synopsys.integration.detect.lifecycle.shutdown.ExitCodePublisher) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) SimpleFileFinder(com.synopsys.integration.common.util.finder.SimpleFileFinder) DetectorFinder(com.synopsys.integration.detector.finder.DetectorFinder) StatusEventPublisher(com.synopsys.integration.detect.workflow.status.StatusEventPublisher) EventSystem(com.synopsys.integration.detect.workflow.event.EventSystem) File(java.io.File)

Example 4 with EventSystem

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());
}
Also used : ExitCodeRequest(com.synopsys.integration.detect.lifecycle.shutdown.ExitCodeRequest) ExceptionUtility(com.synopsys.integration.detect.lifecycle.shutdown.ExceptionUtility) EventSystem(com.synopsys.integration.detect.workflow.event.EventSystem) DetectStatusManager(com.synopsys.integration.detect.workflow.status.DetectStatusManager) ExitCodeManager(com.synopsys.integration.detect.lifecycle.shutdown.ExitCodeManager) Test(org.junit.jupiter.api.Test)

Example 5 with EventSystem

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());
}
Also used : ExitCodeRequest(com.synopsys.integration.detect.lifecycle.shutdown.ExitCodeRequest) ExceptionUtility(com.synopsys.integration.detect.lifecycle.shutdown.ExceptionUtility) EventSystem(com.synopsys.integration.detect.workflow.event.EventSystem) DetectStatusManager(com.synopsys.integration.detect.workflow.status.DetectStatusManager) ExitCodeManager(com.synopsys.integration.detect.lifecycle.shutdown.ExitCodeManager) Test(org.junit.jupiter.api.Test)

Aggregations

EventSystem (com.synopsys.integration.detect.workflow.event.EventSystem)9 Test (org.junit.jupiter.api.Test)6 ExceptionUtility (com.synopsys.integration.detect.lifecycle.shutdown.ExceptionUtility)4 ExitCodeManager (com.synopsys.integration.detect.lifecycle.shutdown.ExitCodeManager)4 DetectStatusManager (com.synopsys.integration.detect.workflow.status.DetectStatusManager)4 File (java.io.File)4 SimpleFileFinder (com.synopsys.integration.common.util.finder.SimpleFileFinder)3 DetectInfo (com.synopsys.integration.detect.configuration.DetectInfo)2 ExitCodePublisher (com.synopsys.integration.detect.lifecycle.shutdown.ExitCodePublisher)2 ExitCodeRequest (com.synopsys.integration.detect.lifecycle.shutdown.ExitCodeRequest)2 ExtractionEnvironmentProvider (com.synopsys.integration.detect.tool.detector.extraction.ExtractionEnvironmentProvider)2 FormattedOutputManager (com.synopsys.integration.detect.workflow.report.output.FormattedOutputManager)2 StatusEventPublisher (com.synopsys.integration.detect.workflow.status.StatusEventPublisher)2 DetectorEvaluationTree (com.synopsys.integration.detector.base.DetectorEvaluationTree)2 DetectorEvaluationOptions (com.synopsys.integration.detector.evaluation.DetectorEvaluationOptions)2 DetectorFinder (com.synopsys.integration.detector.finder.DetectorFinder)2 DetectorFinderOptions (com.synopsys.integration.detector.finder.DetectorFinderOptions)2 DetectorRuleSet (com.synopsys.integration.detector.rule.DetectorRuleSet)2 HashSet (java.util.HashSet)2 Gson (com.google.gson.Gson)1