Search in sources :

Example 1 with FormattedOutput

use of com.synopsys.integration.detect.workflow.report.output.FormattedOutput 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 FormattedOutput

use of com.synopsys.integration.detect.workflow.report.output.FormattedOutput in project synopsys-detect by blackducksoftware.

the class DockerAssertions method projectVersion.

public void projectVersion(String project, String version) {
    FormattedOutput statusJson = locateStatusJson();
    Assertions.assertEquals(project, statusJson.projectName);
    Assertions.assertEquals(version, statusJson.projectVersion);
    // Should we rely solely on the status json?
    logContains("Project name: " + project);
    logContains("Project version: " + version);
}
Also used : FormattedOutput(com.synopsys.integration.detect.workflow.report.output.FormattedOutput)

Example 3 with FormattedOutput

use of com.synopsys.integration.detect.workflow.report.output.FormattedOutput in project synopsys-detect by blackducksoftware.

the class DockerAssertions method successfulDetectorTypeStatusJson.

public void successfulDetectorTypeStatusJson(String detectorType) {
    FormattedOutput statusJson = locateStatusJson();
    Optional<FormattedDetectorOutput> detector = statusJson.detectors.stream().filter(it -> it.detectorType.equals(detectorType)).findFirst();
    Assertions.assertTrue(detector.isPresent(), "Could not find required detector in status json detector list.");
    Assertions.assertEquals("SUCCESS", detector.get().status);
}
Also used : Arrays(java.util.Arrays) FormattedDetectorOutput(com.synopsys.integration.detect.workflow.report.output.FormattedDetectorOutput) FormattedOutput(com.synopsys.integration.detect.workflow.report.output.FormattedOutput) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) FormattedStatusOutput(com.synopsys.integration.detect.workflow.report.output.FormattedStatusOutput) Objects(java.util.Objects) NameVersion(com.synopsys.integration.util.NameVersion) FormattedOperationOutput(com.synopsys.integration.detect.workflow.report.output.FormattedOperationOutput) Gson(com.google.gson.Gson) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) FileReader(java.io.FileReader) Pattern(java.util.regex.Pattern) FormattedDetectorOutput(com.synopsys.integration.detect.workflow.report.output.FormattedDetectorOutput) FormattedOutput(com.synopsys.integration.detect.workflow.report.output.FormattedOutput)

Example 4 with FormattedOutput

use of com.synopsys.integration.detect.workflow.report.output.FormattedOutput in project synopsys-detect by blackducksoftware.

the class DockerAssertions method successfulOperationStatusJson.

public void successfulOperationStatusJson(String operationKey) {
    FormattedOutput statusJson = locateStatusJson();
    Optional<FormattedOperationOutput> detector = statusJson.operations.stream().filter(it -> it.descriptionKey.equals(operationKey)).findFirst();
    Assertions.assertTrue(detector.isPresent(), "Could not find required operation '" + operationKey + "' in status json detector list.");
    Assertions.assertEquals("SUCCESS", detector.get().status);
}
Also used : Arrays(java.util.Arrays) FormattedDetectorOutput(com.synopsys.integration.detect.workflow.report.output.FormattedDetectorOutput) FormattedOutput(com.synopsys.integration.detect.workflow.report.output.FormattedOutput) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) FormattedStatusOutput(com.synopsys.integration.detect.workflow.report.output.FormattedStatusOutput) Objects(java.util.Objects) NameVersion(com.synopsys.integration.util.NameVersion) FormattedOperationOutput(com.synopsys.integration.detect.workflow.report.output.FormattedOperationOutput) Gson(com.google.gson.Gson) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) FileReader(java.io.FileReader) Pattern(java.util.regex.Pattern) FormattedOperationOutput(com.synopsys.integration.detect.workflow.report.output.FormattedOperationOutput) FormattedOutput(com.synopsys.integration.detect.workflow.report.output.FormattedOutput)

Example 5 with FormattedOutput

use of com.synopsys.integration.detect.workflow.report.output.FormattedOutput in project synopsys-detect by blackducksoftware.

the class DockerAssertions method locateStatusJson.

private FormattedOutput locateStatusJson() {
    if (statusJson != null)
        return statusJson;
    File runs = new File(outputDirectory, "runs");
    File[] runDirectories = runs.listFiles();
    Assertions.assertNotNull(runDirectories, "Could not find any run directories, looked in: " + runs);
    Assertions.assertEquals(1, runDirectories.length, "There should be exactly one run directory (from this latest run).");
    File run = runDirectories[0];
    File status = new File(run, "status");
    Assertions.assertTrue(status.exists(), "Could not find status directory in the run directory!");
    File statusJsonFile = new File(status, "status.json");
    Assertions.assertTrue(statusJsonFile.exists(), "Could not find status json in the status directory!");
    try {
        statusJson = new Gson().fromJson(new FileReader(statusJsonFile), FormattedOutput.class);
    } catch (FileNotFoundException e) {
        Assertions.fail("Unable to parse status json with gson.", e);
    }
    return statusJson;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) FileReader(java.io.FileReader) File(java.io.File) FormattedOutput(com.synopsys.integration.detect.workflow.report.output.FormattedOutput)

Aggregations

FormattedOutput (com.synopsys.integration.detect.workflow.report.output.FormattedOutput)6 File (java.io.File)5 Gson (com.google.gson.Gson)4 FormattedDetectorOutput (com.synopsys.integration.detect.workflow.report.output.FormattedDetectorOutput)4 FileNotFoundException (java.io.FileNotFoundException)4 FileReader (java.io.FileReader)4 FormattedOperationOutput (com.synopsys.integration.detect.workflow.report.output.FormattedOperationOutput)3 FormattedStatusOutput (com.synopsys.integration.detect.workflow.report.output.FormattedStatusOutput)3 NameVersion (com.synopsys.integration.util.NameVersion)3 Arrays (java.util.Arrays)3 Objects (java.util.Objects)3 Optional (java.util.Optional)3 Pattern (java.util.regex.Pattern)3 Assertions (org.junit.jupiter.api.Assertions)3 DetectInfo (com.synopsys.integration.detect.configuration.DetectInfo)1 DetectorToolResult (com.synopsys.integration.detect.tool.detector.DetectorToolResult)1 EventSystem (com.synopsys.integration.detect.workflow.event.EventSystem)1 FormattedOutputManager (com.synopsys.integration.detect.workflow.report.output.FormattedOutputManager)1 DetectableEnvironment (com.synopsys.integration.detectable.DetectableEnvironment)1 ExecutableNotFoundDetectableResult (com.synopsys.integration.detectable.detectable.result.ExecutableNotFoundDetectableResult)1