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;
}
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;
}
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());
}
});
}
}
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;
}
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;
}
Aggregations