Search in sources :

Example 11 with Entity

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

the class UftDiscoveryResultPreparerImpl method matchDiscoveryTestResultsWithOctaneForFullSync.

/**
 * This method check whether discovered test are already exist on server, and instead of creation - those tests will be updated
 * Go over discovered and octane tests
 * 1.if test doesn't exist on octane - this is new test
 * 2.if test exist
 * 2.1 if test different from discovered - this is test for update
 * 2.2 if tests are equal - skip test
 * 3. all tests that are found in Octane but not discovered - those deleted tests and they will be turned to not executable
 *
 * @return true if there were changes comparing to discovered results
 */
private void matchDiscoveryTestResultsWithOctaneForFullSync(EntitiesService entitiesService, UftTestDiscoveryResult discoveryResult) {
    Collection<String> additionalFields = SdkStringUtils.isNotEmpty(discoveryResult.getTestRunnerId()) ? Arrays.asList(EntityConstants.AutomatedTest.TEST_RUNNER_FIELD) : null;
    Map<String, Entity> octaneTestsMap = getTestsFromServer(entitiesService, Long.parseLong(discoveryResult.getWorkspaceId()), Long.parseLong(discoveryResult.getScmRepositoryId()), true, null, additionalFields);
    Map<String, Entity> octaneTestsMapWithoutScmRepository = getTestsFromServer(entitiesService, Long.parseLong(discoveryResult.getWorkspaceId()), Long.parseLong(discoveryResult.getScmRepositoryId()), false, null, additionalFields);
    for (AutomatedTest discoveredTest : discoveryResult.getAllTests()) {
        String key = createKey(discoveredTest.getPackage(), discoveredTest.getName());
        Entity octaneTest = octaneTestsMap.remove(key);
        Entity octaneTestWithoutScmRepository = octaneTestsMapWithoutScmRepository.remove(key);
        if (octaneTest != null) {
            // the only fields that might be different is description and executable
            boolean testsEqual = checkTestEquals(discoveredTest, octaneTest, discoveryResult.getTestRunnerId());
            if (!testsEqual) {
                // if equal - skip
                discoveredTest.setId(octaneTest.getId());
                discoveredTest.setOctaneStatus(OctaneStatus.MODIFIED);
                if (octaneTest.containsField(EntityConstants.AutomatedTest.TEST_RUNNER_FIELD) && octaneTest.getField(EntityConstants.AutomatedTest.TEST_RUNNER_FIELD) == null) {
                    discoveredTest.setMissingTestRunner(true);
                }
            } else {
                discoveredTest.setOctaneStatus(OctaneStatus.NONE);
            }
        } else if (octaneTestWithoutScmRepository != null) {
            // special handling - test were injected from pipeline,or created from other fork. need to update scm repository
            discoveredTest.setId(octaneTestWithoutScmRepository.getId());
            discoveredTest.setOctaneStatus(OctaneStatus.MODIFIED);
            if (octaneTestWithoutScmRepository.containsField(EntityConstants.AutomatedTest.TEST_RUNNER_FIELD) && octaneTestWithoutScmRepository.getField(EntityConstants.AutomatedTest.TEST_RUNNER_FIELD) == null) {
                discoveredTest.setMissingTestRunner(true);
            }
            discoveredTest.setMissingScmRepository(true);
        }
    // else do nothing, status of test should remain NEW
    }
    // go over executable tests that exist in Octane but not discovered and disable them
    for (Entity octaneTest : octaneTestsMap.values()) {
        boolean octaneExecutable = octaneTest.getBooleanValue(EntityConstants.AutomatedTest.EXECUTABLE_FIELD);
        if (octaneExecutable) {
            AutomatedTest test = new AutomatedTest();
            discoveryResult.getAllTests().add(test);
            test.setId(octaneTest.getId());
            test.setExecutable(false);
            test.setName(octaneTest.getName());
            test.setPackage(octaneTest.getStringValue(EntityConstants.AutomatedTest.PACKAGE_FIELD));
            test.setOctaneStatus(OctaneStatus.DELETED);
        }
    }
}
Also used : Entity(com.hp.octane.integrations.dto.entities.Entity) AutomatedTest(com.hp.octane.integrations.uft.items.AutomatedTest)

Example 12 with Entity

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

the class TestExecutionServiceImpl method planSuiteRuns.

private List<Entity> planSuiteRuns(Long workspaceId, List<Long> suiteIds, Entity release, String suiteRunName) {
    Map<Long, String> suiteNames = SdkStringUtils.isNotEmpty(suiteRunName) ? Collections.emptyMap() : this.validateAllSuiteIdsExistAndReturnSuiteNames(workspaceId, suiteIds);
    Entity status = dtoFactory.newDTO(Entity.class).setType(EntityConstants.Lists.ENTITY_NAME).setId("list_node.run_native_status.planned");
    List<Entity> suiteRuns = suiteIds.stream().map(suiteId -> {
        Entity test = dtoFactory.newDTO(Entity.class).setType(EntityConstants.Test.ENTITY_NAME).setId(Long.toString(suiteId));
        Entity suiteRun = dtoFactory.newDTO(Entity.class).setField(EntityConstants.Run.NAME_FIELD, SdkStringUtils.isNotEmpty(suiteRunName) ? suiteRunName : suiteNames.get(suiteId)).setField(EntityConstants.Run.SUBTYPE_FIELD, "run_suite").setField(EntityConstants.Run.RELEASE_FIELD, release).setField(EntityConstants.Run.TEST_FIELD, test).setField(EntityConstants.Run.NATIVE_STATUS_FIELD, status);
        return suiteRun;
    }).collect(Collectors.toList());
    List<Entity> entities = entitiesService.postEntities(workspaceId, EntityConstants.Run.COLLECTION_NAME, suiteRuns, Arrays.asList(EntityConstants.Run.TEST_FIELD), Collections.singletonMap("is_atomic_creation", "true"));
    return entities;
}
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)

Example 13 with Entity

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

the class TestExecutionServiceImpl method convertLinksToJson.

private String convertLinksToJson(List<Entity> links) throws JsonProcessingException {
    TestToRunDataCollection collection = new TestToRunDataCollection();
    for (Entity link : links) {
        TestToRunData data = new TestToRunData();
        Entity test = (Entity) link.getField("test");
        data.setPackageName(test.getStringValue(EntityConstants.AutomatedTest.PACKAGE_FIELD));
        data.setClassName(test.getStringValue(EntityConstants.AutomatedTest.CLASS_NAME_FIELD));
        data.setTestName(test.getStringValue(EntityConstants.AutomatedTest.NAME_FIELD));
        if (test.containsFieldAndValue("automation_identifier")) {
            data.addParameters(CucumberJVMConverter.FEATURE_FILE_PATH, test.getStringValue("automation_identifier"));
        }
        if (test.containsFieldAndValue("external_test_id")) {
            data.addParameters("external_test_id", test.getStringValue("external_test_id"));
        }
        if (test.containsFieldAndValue("data_table")) {
            data.addParameters(CucumberJVMConverter.FEATURE_FILE_PATH, link.getEntityValue("data_table").getStringValue("relative_path"));
        }
        if (test.containsFieldAndValue(EntityConstants.TestSuiteLinkToTest.EXECUTION_PARAMETERS_FIELD)) {
            String[] parts = link.getStringValue(EntityConstants.TestSuiteLinkToTest.EXECUTION_PARAMETERS_FIELD).split("[\n;]");
            for (String part : parts) {
                String myPart = part.trim();
                int splitterIndex = myPart.indexOf('=');
                if (myPart.isEmpty() || myPart.startsWith("#") || splitterIndex == -1) {
                    continue;
                }
                String name = myPart.substring(0, splitterIndex).trim();
                String value = myPart.substring(splitterIndex + 1).trim();
                data.addParameters(name, value);
            }
        }
        collection.getTestsToRun().add(data);
    }
    final ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    return objectMapper.writeValueAsString(collection);
}
Also used : Entity(com.hp.octane.integrations.dto.entities.Entity) TestToRunDataCollection(com.hp.octane.integrations.executor.TestToRunDataCollection) TestToRunData(com.hp.octane.integrations.executor.TestToRunData) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 14 with Entity

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

the class SonarVulnerabilitiesServiceImpl method createClosedOctaneIssue.

private OctaneIssue createClosedOctaneIssue(String remoteId) {
    Entity closedListNodeEntity = SSCToOctaneIssueUtil.createListNodeEntity(ISSUE_STATE_CLOSED);
    OctaneIssueImpl octaneIssue = new OctaneIssueImpl();
    octaneIssue.setRemoteId(remoteId);
    octaneIssue.setState(closedListNodeEntity);
    return octaneIssue;
}
Also used : Entity(com.hp.octane.integrations.dto.entities.Entity) OctaneIssueImpl(com.hp.octane.integrations.dto.securityscans.impl.OctaneIssueImpl)

Example 15 with Entity

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

the class VulnerabilitiesGeneralUtils method createClosedOctaneIssue.

public static OctaneIssue createClosedOctaneIssue(String remoteId) {
    Entity closedListNodeEntity = createListNodeEntity(OctaneIssueConsts.ISSUE_STATE_CLOSED);
    OctaneIssueImpl octaneIssue = new OctaneIssueImpl();
    octaneIssue.setRemoteId(remoteId);
    octaneIssue.setState(closedListNodeEntity);
    return octaneIssue;
}
Also used : SSCToOctaneIssueUtil.createListNodeEntity(com.hp.octane.integrations.services.vulnerabilities.ssc.SSCToOctaneIssueUtil.createListNodeEntity) Entity(com.hp.octane.integrations.dto.entities.Entity) OctaneIssueImpl(com.hp.octane.integrations.dto.securityscans.impl.OctaneIssueImpl)

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