Search in sources :

Example 1 with SupportsConsoleLog

use of com.hp.octane.integrations.services.SupportsConsoleLog 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 2 with SupportsConsoleLog

use of com.hp.octane.integrations.services.SupportsConsoleLog 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)

Aggregations

Entity (com.hp.octane.integrations.dto.entities.Entity)2 SupportsConsoleLog (com.hp.octane.integrations.services.SupportsConsoleLog)2 JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 OctaneSDK (com.hp.octane.integrations.OctaneSDK)1 DTOFactory (com.hp.octane.integrations.dto.DTOFactory)1 HttpMethod (com.hp.octane.integrations.dto.connectivity.HttpMethod)1 OctaneRequest (com.hp.octane.integrations.dto.connectivity.OctaneRequest)1 OctaneResponse (com.hp.octane.integrations.dto.connectivity.OctaneResponse)1 EntityConstants (com.hp.octane.integrations.dto.entities.EntityConstants)1 TestToRunData (com.hp.octane.integrations.executor.TestToRunData)1 TestToRunDataCollection (com.hp.octane.integrations.executor.TestToRunDataCollection)1 CucumberJVMConverter (com.hp.octane.integrations.executor.converters.CucumberJVMConverter)1 EntitiesService (com.hp.octane.integrations.services.entities.EntitiesService)1 QueryHelper (com.hp.octane.integrations.services.entities.QueryHelper)1 RestService (com.hp.octane.integrations.services.rest.RestService)1 SdkStringUtils (com.hp.octane.integrations.utils.SdkStringUtils)1 IOException (java.io.IOException)1 java.util (java.util)1