use of com.hp.octane.integrations.uft.items.AutomatedTest 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.uft.items.AutomatedTest in project octane-ci-java-sdk by MicroFocus.
the class UftDiscoveryResultPreparerImpl method handleMovedTests.
private void handleMovedTests(UftTestDiscoveryResult result) {
List<AutomatedTest> newTests = result.getNewTests();
List<AutomatedTest> deletedTests = result.getDeletedTests();
if (!newTests.isEmpty() && !deletedTests.isEmpty()) {
Map<String, AutomatedTest> dst2Test = new HashMap<>();
Map<AutomatedTest, AutomatedTest> deleted2newMovedTests = new HashMap<>();
for (AutomatedTest newTest : newTests) {
if (SdkStringUtils.isNotEmpty(newTest.getChangeSetDst())) {
dst2Test.put(newTest.getChangeSetDst(), newTest);
}
}
for (AutomatedTest deletedTest : deletedTests) {
if (SdkStringUtils.isNotEmpty(deletedTest.getChangeSetDst()) && dst2Test.containsKey(deletedTest.getChangeSetDst())) {
AutomatedTest newTest = dst2Test.get(deletedTest.getChangeSetDst());
deleted2newMovedTests.put(deletedTest, newTest);
}
}
for (Map.Entry<AutomatedTest, AutomatedTest> entry : deleted2newMovedTests.entrySet()) {
AutomatedTest deletedTest = entry.getKey();
AutomatedTest newTest = entry.getValue();
newTest.setIsMoved(true);
newTest.setOldName(deletedTest.getName());
newTest.setOldPackage(deletedTest.getPackage());
newTest.setOctaneStatus(OctaneStatus.MODIFIED);
result.getAllTests().remove(deletedTest);
}
}
}
use of com.hp.octane.integrations.uft.items.AutomatedTest in project octane-ci-java-sdk by MicroFocus.
the class UftDiscoveryResultPreparerImpl method validateTestDiscoveryAndCompleteTestIdsForScmChangeDetection.
/**
* This method try to find ids of updated and deleted tests for scm change detection
* if test is found on server - update id of discovered test
* if test is not found and test is marked for update - move it to new tests (possibly test was deleted on server)
*
* @return true if there were changes comparing to discoverede results
*/
private boolean validateTestDiscoveryAndCompleteTestIdsForScmChangeDetection(EntitiesService entitiesService, UftTestDiscoveryResult result) {
boolean hasDiff = false;
Set<String> allTestNames = new HashSet<>();
for (AutomatedTest test : result.getAllTests()) {
if (test.getIsMoved()) {
allTestNames.add(test.getOldName());
} else {
allTestNames.add(test.getName());
}
}
// GET TESTS FROM OCTANE
Collection<String> additionalFields = SdkStringUtils.isNotEmpty(result.getTestRunnerId()) ? Collections.singletonList(EntityConstants.AutomatedTest.TEST_RUNNER_FIELD) : null;
Map<String, Entity> octaneTestsMapByKey = getTestsFromServer(entitiesService, Long.parseLong(result.getWorkspaceId()), Long.parseLong(result.getScmRepositoryId()), true, allTestNames, additionalFields);
// MATCHING
for (AutomatedTest discoveredTest : result.getAllTests()) {
String key = discoveredTest.getIsMoved() ? createKey(discoveredTest.getOldPackage(), discoveredTest.getOldName()) : createKey(discoveredTest.getPackage(), discoveredTest.getName());
Entity octaneTest = octaneTestsMapByKey.get(key);
boolean octaneTestFound = (octaneTest != null);
if (octaneTestFound) {
discoveredTest.setId(octaneTest.getId());
}
switch(discoveredTest.getOctaneStatus()) {
case DELETED:
if (!octaneTestFound) {
// discoveredTest that is marked to be deleted - doesn't exist in Octane - do nothing
hasDiff = true;
discoveredTest.setOctaneStatus(OctaneStatus.NONE);
}
break;
case MODIFIED:
if (!octaneTestFound) {
// updated discoveredTest that has no matching in Octane, possibly was remove from Octane. So we move it to new tests
hasDiff = true;
discoveredTest.setOctaneStatus(OctaneStatus.NEW);
} else {
boolean testsEqual = checkTestEquals(discoveredTest, octaneTest, result.getTestRunnerId());
if (testsEqual) {
// if equal - skip
discoveredTest.setOctaneStatus(OctaneStatus.NONE);
}
}
break;
case NEW:
if (octaneTestFound) {
// new discoveredTest was found in Octane - move it to update
hasDiff = true;
discoveredTest.setOctaneStatus(OctaneStatus.MODIFIED);
}
break;
default:
}
}
return hasDiff;
}
use of com.hp.octane.integrations.uft.items.AutomatedTest 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);
}
}
}
Aggregations