Search in sources :

Example 26 with Entity

use of com.hp.octane.integrations.dto.entities.Entity in project octane-ci-java-sdk by MicroFocus.

the class TestExecutionServiceImpl method prepareTestExecutionForSuites.

@Override
public List<TestExecutionContext> prepareTestExecutionForSuites(Long workspaceId, List<Long> suiteIds, final SupportsConsoleLog supportsConsoleLog) {
    SupportsConsoleLog mySupportsConsoleLog = getSupportConsoleLogOrCreateEmpty(supportsConsoleLog);
    List<TestExecutionContext> output = new ArrayList<>();
    mySupportsConsoleLog.println("Fetching test data for suite ids " + suiteIds + " from " + configurer.octaneConfiguration.getLocationForLog() + ":" + workspaceId);
    suiteIds.forEach(suiteId -> {
        List<Entity> suiteLinks = getSuiteLinks(workspaceId, suiteId, mySupportsConsoleLog);
        List<Entity> suiteLinksWithTestRunner = suiteLinks.stream().filter(e -> e.containsFieldAndValue(EntityConstants.TestSuiteLinkToTest.TEST_RUNNER_FIELD)).collect(Collectors.toList());
        int noRunnerCount = (suiteLinks.size() - suiteLinksWithTestRunner.size());
        if (noRunnerCount > 0) {
            String noRunnerMsg = String.format("Suite %s: found %s test(s) without test runner, such tests will be skipped", suiteId, noRunnerCount);
            mySupportsConsoleLog.println(noRunnerMsg);
        }
        mySupportsConsoleLog.println(String.format("suite %s: found %s test(s) eligible for execution", suiteId, suiteLinks.size()));
        Map<String, List<Entity>> testRunnerId2links = suiteLinksWithTestRunner.stream().collect(Collectors.groupingBy(e -> ((Entity) e.getField(EntityConstants.TestSuiteLinkToTest.TEST_RUNNER_FIELD)).getId()));
        // test runners
        Map<String, Entity> id2testRunners = getTestRunners(workspaceId, testRunnerId2links.keySet()).stream().collect(Collectors.toMap(Entity::getId, Function.identity()));
        List<Entity> testRunnersFromAnotherCiServer = id2testRunners.values().stream().filter(e -> !this.configurer.octaneConfiguration.getInstanceId().equals(e.getEntityValue("ci_server").getStringValue(EntityConstants.CIServer.INSTANCE_ID_FIELD))).collect(Collectors.toList());
        if (!testRunnersFromAnotherCiServer.isEmpty()) {
            // if there are test runners from another ci server, need to remove such tests from execution
            String runnerNames = testRunnersFromAnotherCiServer.stream().map(Entity::getName).collect(Collectors.joining(","));
            mySupportsConsoleLog.println(String.format("Suite %s: found tests with test runner(s) belong to another ci server, such tests will be skipped. Test runners are : %s", suiteId, runnerNames));
            // remove not relevant test runners
            testRunnersFromAnotherCiServer.forEach(e -> testRunnerId2links.remove(e.getId()));
        }
        testRunnerId2links.keySet().forEach(testRunnerId -> {
            try {
                List<Entity> links = testRunnerId2links.get(testRunnerId);
                String testsToRunJson = convertLinksToJson(links);
                output.add(new TestExecutionContext(id2testRunners.get(testRunnerId), testsToRunJson, links, TestExecutionIdentifierType.SUITE, Long.toString(suiteId)));
            } catch (Exception e) {
                throw new RuntimeException("Failed to build testsToRun for test runner " + testRunnerId + " : " + e.getMessage());
            }
        });
    });
    return output;
}
Also used : EntitiesService(com.hp.octane.integrations.services.entities.EntitiesService) java.util(java.util) Entity(com.hp.octane.integrations.dto.entities.Entity) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpMethod(com.hp.octane.integrations.dto.connectivity.HttpMethod) OctaneRequest(com.hp.octane.integrations.dto.connectivity.OctaneRequest) TestToRunDataCollection(com.hp.octane.integrations.executor.TestToRunDataCollection) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) RestService(com.hp.octane.integrations.services.rest.RestService) IOException(java.io.IOException) QueryHelper(com.hp.octane.integrations.services.entities.QueryHelper) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) CucumberJVMConverter(com.hp.octane.integrations.executor.converters.CucumberJVMConverter) EntityConstants(com.hp.octane.integrations.dto.entities.EntityConstants) OctaneSDK(com.hp.octane.integrations.OctaneSDK) Logger(org.apache.logging.log4j.Logger) DTOFactory(com.hp.octane.integrations.dto.DTOFactory) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) TestToRunData(com.hp.octane.integrations.executor.TestToRunData) SdkStringUtils(com.hp.octane.integrations.utils.SdkStringUtils) OctaneResponse(com.hp.octane.integrations.dto.connectivity.OctaneResponse) SupportsConsoleLog(com.hp.octane.integrations.services.SupportsConsoleLog) LogManager(org.apache.logging.log4j.LogManager) Entity(com.hp.octane.integrations.dto.entities.Entity) SupportsConsoleLog(com.hp.octane.integrations.services.SupportsConsoleLog) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException)

Example 27 with Entity

use of com.hp.octane.integrations.dto.entities.Entity in project octane-ci-java-sdk by MicroFocus.

the class TestExecutionServiceImpl method executeSuiteRuns.

@Override
public void executeSuiteRuns(Long workspaceId, List<Long> suiteIds, Long optionalReleaseId, String optionalSuiteRunName, SupportsConsoleLog supportsConsoleLog) throws IOException {
    SupportsConsoleLog mySupportsConsoleLog = getSupportConsoleLogOrCreateEmpty(supportsConsoleLog);
    mySupportsConsoleLog.println("Executing suite ids " + suiteIds + " in " + configurer.octaneConfiguration.getLocationForLog() + ", workspace " + workspaceId);
    for (Long suiteId : suiteIds) {
        this.validateSuiteRun(workspaceId, suiteId);
    }
    Entity release = getReleaseOrThrow(workspaceId, optionalReleaseId);
    mySupportsConsoleLog.println("Using release  - " + release.getId());
    List<Entity> suiteRuns = this.planSuiteRuns(workspaceId, suiteIds, release, optionalSuiteRunName);
    for (Entity suiteRun : suiteRuns) {
        String suiteId = suiteRun.getEntityValue(EntityConstants.Run.TEST_FIELD).getId();
        String url = this.configurer.octaneConfiguration.getUrl() + String.format("/ui/?p=%s/%s#/entity-navigation?entityType=run&id=%s", this.configurer.octaneConfiguration.getSharedSpace(), workspaceId, suiteRun.getId());
        mySupportsConsoleLog.println(String.format("Suite %s - suite run id is %s , %s", suiteId, suiteRun.getId(), url));
        this.runSuiteRun(workspaceId, Long.parseLong(suiteRun.getId()));
    }
    mySupportsConsoleLog.println("Suite runs are started ");
}
Also used : Entity(com.hp.octane.integrations.dto.entities.Entity) SupportsConsoleLog(com.hp.octane.integrations.services.SupportsConsoleLog)

Example 28 with Entity

use of com.hp.octane.integrations.dto.entities.Entity in project octane-ci-java-sdk by MicroFocus.

the class FODValuesConverter method setSeverity.

private void setSeverity(OctaneIssue entity, Integer severity) {
    if (severity == null) {
        return;
    }
    String logicalNameForSeverity = null;
    if (severity.equals(4)) {
        logicalNameForSeverity = SEVERITY_LG_NAME_CRITICAL;
    } else if (severity.equals(3)) {
        logicalNameForSeverity = SEVERITY_LG_NAME_HIGH;
    } else if (severity.equals(2)) {
        logicalNameForSeverity = SEVERITY_LG_NAME_MEDIUM;
    } else if (severity.equals(1)) {
        logicalNameForSeverity = SEVERITY_LG_NAME_LOW;
    }
    Entity listNodeEntity = createListNodeEntity(logicalNameForSeverity);
    if (listNodeEntity != null) {
        entity.setSeverity(listNodeEntity);
    }
}
Also used : Entity(com.hp.octane.integrations.dto.entities.Entity) SSCToOctaneIssueUtil.createListNodeEntity(com.hp.octane.integrations.services.vulnerabilities.ssc.SSCToOctaneIssueUtil.createListNodeEntity)

Example 29 with Entity

use of com.hp.octane.integrations.dto.entities.Entity in project octane-ci-java-sdk by MicroFocus.

the class FODValuesConverter method setAnalysis.

private void setAnalysis(OctaneIssue entity, Vulnerability vulnerability) {
    if (isReviewed(vulnerability)) {
        Entity analysisListNode = createListNodeEntity("list_node.issue_analysis_node.reviewed");
        entity.setAnalysis(analysisListNode);
    } else {
        String listNodeId = mapFODAnalysisToLogicalName(vulnerability.status);
        if (listNodeId == null) {
            listNodeId = mapAuditorStatusToAnalysis(vulnerability.auditorStatus);
        }
        if (listNodeId != null) {
            Entity analysisListNode = createListNodeEntity(listNodeId);
            entity.setAnalysis(analysisListNode);
        }
    }
}
Also used : Entity(com.hp.octane.integrations.dto.entities.Entity) SSCToOctaneIssueUtil.createListNodeEntity(com.hp.octane.integrations.services.vulnerabilities.ssc.SSCToOctaneIssueUtil.createListNodeEntity)

Example 30 with Entity

use of com.hp.octane.integrations.dto.entities.Entity in project octane-ci-java-sdk by MicroFocus.

the class FODValuesConverter method setStatus.

private void setStatus(OctaneIssue entity, String status) {
    String logicalName = mapFODStatusToLogicalName(status);
    if (logicalName != null) {
        Entity stateListNode = createListNodeEntity(logicalName);
        entity.setState(stateListNode);
    }
}
Also used : Entity(com.hp.octane.integrations.dto.entities.Entity) SSCToOctaneIssueUtil.createListNodeEntity(com.hp.octane.integrations.services.vulnerabilities.ssc.SSCToOctaneIssueUtil.createListNodeEntity)

Aggregations

Entity (com.hp.octane.integrations.dto.entities.Entity)34 EntitiesService (com.hp.octane.integrations.services.entities.EntitiesService)6 EntityConstants (com.hp.octane.integrations.dto.entities.EntityConstants)5 OctaneBulkException (com.hp.octane.integrations.exceptions.OctaneBulkException)5 QueryHelper (com.hp.octane.integrations.services.entities.QueryHelper)5 SdkStringUtils (com.hp.octane.integrations.utils.SdkStringUtils)5 java.util (java.util)5 Function (java.util.function.Function)5 Collectors (java.util.stream.Collectors)5 LogManager (org.apache.logging.log4j.LogManager)5 Logger (org.apache.logging.log4j.Logger)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 RestService (com.hp.octane.integrations.services.rest.RestService)4 IOException (java.io.IOException)4 OctaneSDK (com.hp.octane.integrations.OctaneSDK)3 DTOFactory (com.hp.octane.integrations.dto.DTOFactory)3 HttpMethod (com.hp.octane.integrations.dto.connectivity.HttpMethod)3 OctaneRequest (com.hp.octane.integrations.dto.connectivity.OctaneRequest)3 OctaneResponse (com.hp.octane.integrations.dto.connectivity.OctaneResponse)3 TestToRunData (com.hp.octane.integrations.executor.TestToRunData)3