Search in sources :

Example 1 with Entity

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

the class MbtDiscoveryResultDispatcherImpl method postUnits.

private boolean postUnits(EntitiesService entitiesService, List<UftTestAction> actions, Map<String, Entity> foldersMap, long workspaceId) {
    if (!actions.isEmpty()) {
        logger.info("dispatching {} new units", actions.size());
        // add external parameter entities list to be filled by each action creation
        List<Entity> parameterToAdd = new ArrayList<>();
        // add units
        List<Entity> unitsToAdd = actions.stream().map(action -> createUnitEntity(action, foldersMap, parameterToAdd)).collect(Collectors.toList());
        Map<String, Entity> unitEntities = entitiesService.postEntities(workspaceId, EntityConstants.MbtUnit.COLLECTION_NAME, unitsToAdd, Collections.singletonList(EntityConstants.MbtUnit.REPOSITORY_PATH_FIELD)).stream().collect(Collectors.toMap(entity -> entity.getField(EntityConstants.MbtUnit.REPOSITORY_PATH_FIELD).toString(), Function.identity()));
        logger.info("actual new units {} added", unitEntities.size());
        // replace parent unit entities for parameters in order to save their relations
        logger.info("dispatching {} new unit parameters", parameterToAdd.size());
        parameterToAdd.forEach(parameter -> {
            Entity parentUnit = (Entity) parameter.getField(EntityConstants.MbtUnitParameter.MODEL_ITEM);
            Entity newParentUnit = unitEntities.get(parentUnit.getField(EntityConstants.MbtUnit.REPOSITORY_PATH_FIELD).toString());
            parameter.setField(EntityConstants.MbtUnitParameter.MODEL_ITEM, createModelItemEntity(newParentUnit));
        });
        // add parameters
        List<Entity> unitParameterEntities = entitiesService.postEntities(workspaceId, EntityConstants.MbtUnitParameter.COLLECTION_NAME, parameterToAdd);
        logger.info("actual new unit parameters {} added", unitParameterEntities.size());
    }
    return true;
}
Also used : EntitiesService(com.hp.octane.integrations.services.entities.EntitiesService) EntityConstants(com.hp.octane.integrations.dto.entities.EntityConstants) java.util(java.util) Logger(org.apache.logging.log4j.Logger) Entity(com.hp.octane.integrations.dto.entities.Entity) com.hp.octane.integrations.uft.items(com.hp.octane.integrations.uft.items) SdkStringUtils(com.hp.octane.integrations.utils.SdkStringUtils) QueryHelper(com.hp.octane.integrations.services.entities.QueryHelper) LogManager(org.apache.logging.log4j.LogManager) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Entity(com.hp.octane.integrations.dto.entities.Entity)

Example 2 with Entity

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

the class MbtDiscoveryResultDispatcherImpl method createUnitEntity.

private Entity createUnitEntity(UftTestAction action, Map<String, Entity> foldersMap, List<Entity> parameterEntities) {
    String unitName = SdkStringUtils.isEmpty(action.getLogicalName()) || action.getLogicalName().startsWith("Action") ? action.getTestName() + ":" + action.getName() : action.getLogicalName();
    Entity parentFolder = foldersMap.get(action.getTestName());
    Entity unitEntity = dtoFactory.newDTO(Entity.class).setType(EntityConstants.MbtUnit.ENTITY_NAME).setField(EntityConstants.MbtUnit.SUBTYPE_FIELD, EntityConstants.MbtUnit.ENTITY_SUBTYPE).setField(EntityConstants.MbtUnit.NAME_FIELD, unitName).setField(EntityConstants.MbtUnit.DESCRIPTION_FIELD, action.getDescription()).setField(EntityConstants.MbtUnit.PARENT, parentFolder).setField(EntityConstants.MbtUnit.AUTOMATION_STATUS_FIELD, AUTOMATED_AUTOMATION_STATUS).setField(EntityConstants.MbtUnit.REPOSITORY_PATH_FIELD, action.getRepositoryPath()).setField(EntityConstants.MbtUnit.TESTING_TOOL_TYPE_FIELD, TESTING_TOOL_TYPE);
    if (CollectionUtils.isNotEmpty(action.getParameters())) {
        List<Entity> parameters = action.getParameters().stream().map(parameter -> createUnitParameterEntity(parameter, unitEntity)).collect(Collectors.toList());
        parameterEntities.addAll(parameters);
    }
    return unitEntity;
}
Also used : EntitiesService(com.hp.octane.integrations.services.entities.EntitiesService) EntityConstants(com.hp.octane.integrations.dto.entities.EntityConstants) java.util(java.util) Logger(org.apache.logging.log4j.Logger) Entity(com.hp.octane.integrations.dto.entities.Entity) com.hp.octane.integrations.uft.items(com.hp.octane.integrations.uft.items) SdkStringUtils(com.hp.octane.integrations.utils.SdkStringUtils) QueryHelper(com.hp.octane.integrations.services.entities.QueryHelper) LogManager(org.apache.logging.log4j.LogManager) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Entity(com.hp.octane.integrations.dto.entities.Entity)

Example 3 with Entity

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

the class MbtDiscoveryResultPreparerImpl method handleUpdatedTestDeletedActionCase.

// handle case 2 for deleted actions
private void handleUpdatedTestDeletedActionCase(Map<String, UftTestAction> scmPathToActionMap, Map<String, Entity> scmPathToEntityMap, List<AutomatedTest> updatedTests) {
    Collection<String> deletedActions = CollectionUtils.removeAll(scmPathToEntityMap.keySet(), scmPathToActionMap.keySet());
    if (CollectionUtils.isNotEmpty(deletedActions)) {
        Set<AutomatedTest> updatedTestsCounter = new HashSet<>();
        deletedActions.forEach(s -> {
            String scmTestPath = extractScmTestPath(s);
            if (Objects.isNull(scmTestPath)) {
                logger.warn("repository path {} of unit id {} name {} is not valid and will be discarded", s, scmPathToEntityMap.get(s).getId(), scmPathToEntityMap.get(s).getName());
                scmPathToEntityMap.remove(s);
            } else {
                // try to match between the automated test and the units to be deleted. since the action was already deleted
                // from the scm, we need to update octane. the handling is the same as handling a deleted test. we need
                // to mark the deleted actions and provide only the unit id
                updatedTests.forEach(automatedTest -> {
                    String calculatedTestPath = UftTestDiscoveryUtils.getTestPathPrefix(automatedTest, false).toLowerCase();
                    // match found. add a marker action to the automated test
                    if (calculatedTestPath.equals(scmTestPath)) {
                        Entity entity = scmPathToEntityMap.get(s);
                        UftTestAction action = convertToAction(entity);
                        action.setOctaneStatus(OctaneStatus.DELETED);
                        automatedTest.getActions().add(action);
                        updatedTestsCounter.add(automatedTest);
                    }
                });
                scmPathToEntityMap.remove(s);
                logger.info("found {} updated tests for deleted action", updatedTestsCounter.size());
            }
        });
    }
}
Also used : Entity(com.hp.octane.integrations.dto.entities.Entity) AutomatedTest(com.hp.octane.integrations.uft.items.AutomatedTest) UftTestAction(com.hp.octane.integrations.uft.items.UftTestAction)

Example 4 with Entity

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

the class UftDiscoveryResultDispatcherImpl method postScmResources.

private boolean postScmResources(EntitiesService entitiesService, List<ScmResourceFile> resources, String workspaceId, String scmRepositoryId) {
    if (!resources.isEmpty()) {
        // CONVERT TO DTO
        List<Entity> entitiesForPost = new ArrayList<>(resources.size());
        Entity scmRepository = dtoFactory.newDTO(Entity.class).setType(EntityConstants.ScmRepository.ENTITY_NAME).setId(scmRepositoryId);
        for (ScmResourceFile resource : resources) {
            Entity entity = dtoFactory.newDTO(Entity.class).setType(EntityConstants.ScmResourceFile.ENTITY_NAME).setName(resource.getName()).setField(EntityConstants.ScmResourceFile.SCM_REPOSITORY_FIELD, scmRepository).setField(EntityConstants.ScmResourceFile.RELATIVE_PATH_FIELD, resource.getRelativePath());
            entitiesForPost.add(entity);
        }
        // POST
        for (int i = 0; i < resources.size(); i += POST_BULK_SIZE) try {
            List<Entity> subList = entitiesForPost.subList(i, Math.min(i + POST_BULK_SIZE, entitiesForPost.size()));
            entitiesService.postEntities(Long.parseLong(workspaceId), EntityConstants.ScmResourceFile.COLLECTION_NAME, subList);
        } catch (OctaneBulkException e) {
            return checkIfExceptionCanBeIgnoredInPOST(e, "Failed to post scm resource files");
        }
    }
    return true;
}
Also used : Entity(com.hp.octane.integrations.dto.entities.Entity) OctaneBulkException(com.hp.octane.integrations.exceptions.OctaneBulkException) EntityList(com.hp.octane.integrations.dto.entities.EntityList)

Example 5 with Entity

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

the class UftDiscoveryResultDispatcherImpl method postTests.

private boolean postTests(EntitiesService entitiesService, List<AutomatedTest> tests, String workspaceId, String scmRepositoryId, String testRunnerId) {
    if (!tests.isEmpty()) {
        // convert to DTO
        List<Entity> testsForPost = new ArrayList<>(tests.size());
        Entity uftTestingTool = createListNodeEntity("list_node.testing_tool_type.uft");
        Entity uftFramework = createListNodeEntity("list_node.je.framework.uft");
        Entity guiTestType = createListNodeEntity("list_node.test_type.gui");
        Entity apiTestType = createListNodeEntity("list_node.test_type.api");
        Entity scmRepository = dtoFactory.newDTO(Entity.class).setType(EntityConstants.ScmRepository.ENTITY_NAME).setId(scmRepositoryId);
        Entity testRunner = SdkStringUtils.isNotEmpty(testRunnerId) ? dtoFactory.newDTO(Entity.class).setType(EntityConstants.Executors.ENTITY_NAME).setId(testRunnerId) : null;
        for (AutomatedTest test : tests) {
            Entity testType = UftTestType.API.equals(test.getUftTestType()) ? apiTestType : guiTestType;
            EntityList testTypeList = dtoFactory.newDTO(EntityList.class).addEntity(testType);
            Entity octaneTest = dtoFactory.newDTO(Entity.class).setType(EntityConstants.AutomatedTest.ENTITY_NAME).setField(EntityConstants.AutomatedTest.TESTING_TOOL_TYPE_FIELD, uftTestingTool).setField(EntityConstants.AutomatedTest.FRAMEWORK_FIELD, uftFramework).setField(EntityConstants.AutomatedTest.TEST_TYPE_FIELD, testTypeList).setField(EntityConstants.AutomatedTest.SCM_REPOSITORY_FIELD, scmRepository).setField(EntityConstants.AutomatedTest.NAME_FIELD, test.getName()).setField(EntityConstants.AutomatedTest.PACKAGE_FIELD, test.getPackage()).setField(EntityConstants.AutomatedTest.DESCRIPTION_FIELD, test.getDescription()).setField(EntityConstants.AutomatedTest.EXECUTABLE_FIELD, test.getExecutable());
            testsForPost.add(octaneTest);
            if (testRunner != null) {
                octaneTest.setField(EntityConstants.AutomatedTest.TEST_RUNNER_FIELD, testRunner);
            }
        }
        // POST
        for (int i = 0; i < testsForPost.size(); i += POST_BULK_SIZE) {
            try {
                List<Entity> subList = testsForPost.subList(i, Math.min(i + POST_BULK_SIZE, testsForPost.size()));
                entitiesService.postEntities(Long.parseLong(workspaceId), EntityConstants.AutomatedTest.COLLECTION_NAME, subList);
            } catch (OctaneBulkException e) {
                return checkIfExceptionCanBeIgnoredInPOST(e, "Failed to post tests");
            }
        }
    }
    return true;
}
Also used : Entity(com.hp.octane.integrations.dto.entities.Entity) EntityList(com.hp.octane.integrations.dto.entities.EntityList) OctaneBulkException(com.hp.octane.integrations.exceptions.OctaneBulkException)

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