use of com.epam.ta.reportportal.ws.converter.builders.TestItemBuilder in project service-api by reportportal.
the class RerunHandlerImpl method handleChildItem.
@Override
public Optional<ItemCreatedRS> handleChildItem(StartTestItemRQ request, Launch launch, String parentUuid) {
if (!request.isHasStats()) {
return Optional.empty();
}
final Pair<Long, String> pathName = testItemRepository.selectPath(parentUuid).orElseThrow(() -> new ReportPortalException(ErrorType.TEST_ITEM_NOT_FOUND, parentUuid));
TestItem newItem = new TestItemBuilder().addLaunchId(launch.getId()).addStartItemRequest(request).addAttributes(request.getAttributes()).addParentId(pathName.getFirst()).get();
if (Objects.isNull(newItem.getTestCaseId())) {
newItem.setTestCaseHash(testCaseHashGenerator.generate(newItem, IdentityUtil.getItemTreeIds(pathName.getSecond()), launch.getProjectId()));
}
final Filter childItemFilter = getChildItemFilter(launch, newItem.getTestCaseHash(), pathName.getFirst());
return rerunSearcher.findItem(childItemFilter).flatMap(testItemRepository::findById).flatMap(foundItem -> {
if (!foundItem.isHasChildren()) {
final TestItem parent = testItemRepository.findIdByUuidForUpdate(parentUuid).map(testItemRepository::getOne).orElseThrow(() -> new ReportPortalException(ErrorType.TEST_ITEM_NOT_FOUND, parentUuid));
parentItemValidators.forEach(v -> v.validate(request, parent));
return Optional.of(handleRetry(launch, newItem, foundItem, parent));
}
if (foundItem.getName().equals(newItem.getName())) {
return Optional.of(updateRootItem(request, foundItem));
}
childItemFilter.withCondition(new FilterCondition(Condition.EQUALS, false, newItem.getName(), CRITERIA_NAME));
return rerunSearcher.findItem(childItemFilter).flatMap(testItemRepository::findById).map(it -> updateRootItem(request, it));
});
}
use of com.epam.ta.reportportal.ws.converter.builders.TestItemBuilder in project service-api by reportportal.
the class StartTestItemHandlerImpl method startRootItem.
@Override
public ItemCreatedRS startRootItem(ReportPortalUser user, ReportPortalUser.ProjectDetails projectDetails, StartTestItemRQ rq) {
Launch launch = launchRepository.findByUuid(rq.getLaunchUuid()).orElseThrow(() -> new ReportPortalException(LAUNCH_NOT_FOUND, rq.getLaunchUuid()));
validate(user, projectDetails, rq, launch);
if (launch.isRerun()) {
Optional<ItemCreatedRS> rerunCreatedRs = rerunHandler.handleRootItem(rq, launch);
if (rerunCreatedRs.isPresent()) {
return rerunCreatedRs.get();
}
}
TestItem item = new TestItemBuilder().addStartItemRequest(rq).addAttributes(rq.getAttributes()).addLaunchId(launch.getId()).get();
testItemRepository.save(item);
generateUniqueId(launch, item, String.valueOf(item.getItemId()));
LOGGER.debug("Created new root TestItem {}", item.getUuid());
return new ItemCreatedRS(item.getUuid(), item.getUniqueId());
}
use of com.epam.ta.reportportal.ws.converter.builders.TestItemBuilder in project service-api by reportportal.
the class StartTestItemHandlerImpl method startChildItem.
@Override
public ItemCreatedRS startChildItem(ReportPortalUser user, ReportPortalUser.ProjectDetails projectDetails, StartTestItemRQ rq, String parentId) {
boolean isRetry = BooleanUtils.toBoolean(rq.isRetry()) || StringUtils.isNotBlank(rq.getRetryOf());
Launch launch = launchRepository.findByUuid(rq.getLaunchUuid()).orElseThrow(() -> new ReportPortalException(LAUNCH_NOT_FOUND, rq.getLaunchUuid()));
if (launch.isRerun()) {
Optional<ItemCreatedRS> rerunCreatedRs = rerunHandler.handleChildItem(rq, launch, parentId);
if (rerunCreatedRs.isPresent()) {
return rerunCreatedRs.get();
}
}
final TestItem parentItem;
if (isRetry) {
// Lock for test
Long lockedParentId = testItemRepository.findIdByUuidForUpdate(parentId).orElseThrow(() -> new ReportPortalException(TEST_ITEM_NOT_FOUND, parentId));
parentItem = testItemRepository.getOne(lockedParentId);
} else {
parentItem = testItemRepository.findByUuid(parentId).orElseThrow(() -> new ReportPortalException(TEST_ITEM_NOT_FOUND, parentId));
}
parentItemValidators.forEach(v -> v.validate(rq, parentItem));
TestItem item = new TestItemBuilder().addStartItemRequest(rq).addAttributes(rq.getAttributes()).addLaunchId(launch.getId()).get();
if (isRetry) {
ofNullable(rq.getRetryOf()).flatMap(testItemRepository::findIdByUuidForUpdate).ifPresentOrElse(retryParentId -> {
saveChildItem(launch, item, parentItem);
retryHandler.handleRetries(launch, item, retryParentId);
}, () -> retrySearcher.findPreviousRetry(launch, item, parentItem).ifPresentOrElse(previousRetryId -> {
saveChildItem(launch, item, parentItem);
retryHandler.handleRetries(launch, item, previousRetryId);
}, () -> saveChildItem(launch, item, parentItem)));
} else {
saveChildItem(launch, item, parentItem);
}
LOGGER.debug("Created new child TestItem {} with root {}", item.getUuid(), parentId);
if (rq.isHasStats() && !parentItem.isHasChildren()) {
parentItem.setHasChildren(true);
}
return new ItemCreatedRS(item.getUuid(), item.getUniqueId());
}
use of com.epam.ta.reportportal.ws.converter.builders.TestItemBuilder in project service-api by reportportal.
the class FinishTestItemHandlerImpl method finishTestItem.
@Override
public OperationCompletionRS finishTestItem(ReportPortalUser user, ReportPortalUser.ProjectDetails projectDetails, String testItemId, FinishTestItemRQ finishExecutionRQ) {
final TestItem testItem = testItemRepository.findByUuid(testItemId).filter(it -> it.isHasChildren() || (!it.isHasChildren() && it.getItemResults().getStatus() == IN_PROGRESS)).orElseGet(() -> testItemRepository.findIdByUuidForUpdate(testItemId).flatMap(testItemRepository::findById).orElseThrow(() -> new ReportPortalException(TEST_ITEM_NOT_FOUND, testItemId)));
final Launch launch = retrieveLaunch(testItem);
final TestItemResults testItemResults = processItemResults(user, projectDetails, launch, testItem, finishExecutionRQ, testItem.isHasChildren());
final TestItem itemForUpdate = new TestItemBuilder(testItem).addDescription(finishExecutionRQ.getDescription()).addTestCaseId(finishExecutionRQ.getTestCaseId()).addAttributes(finishExecutionRQ.getAttributes()).addTestItemResults(testItemResults).get();
testItemRepository.save(itemForUpdate);
if (BooleanUtils.toBoolean(finishExecutionRQ.isRetry()) || StringUtils.isNotBlank(finishExecutionRQ.getRetryOf())) {
Optional.of(testItem).filter(it -> !it.isHasChildren() && !it.isHasRetries() && Objects.isNull(it.getRetryOf())).map(TestItem::getParentId).flatMap(testItemRepository::findById).ifPresent(parentItem -> ofNullable(finishExecutionRQ.getRetryOf()).flatMap(testItemRepository::findIdByUuidForUpdate).ifPresentOrElse(retryParentId -> retryHandler.handleRetries(launch, itemForUpdate, retryParentId), () -> retrySearcher.findPreviousRetry(launch, itemForUpdate, parentItem).ifPresent(previousRetryId -> retryHandler.handleRetries(launch, itemForUpdate, previousRetryId))));
}
return new OperationCompletionRS("TestItem with ID = '" + testItemId + "' successfully finished.");
}
use of com.epam.ta.reportportal.ws.converter.builders.TestItemBuilder in project service-api by reportportal.
the class UpdateTestItemHandlerImpl method updateTestItem.
@Override
public OperationCompletionRS updateTestItem(ReportPortalUser.ProjectDetails projectDetails, Long itemId, UpdateTestItemRQ rq, ReportPortalUser user) {
TestItem testItem = testItemRepository.findById(itemId).orElseThrow(() -> new ReportPortalException(ErrorType.TEST_ITEM_NOT_FOUND, itemId));
validate(projectDetails, user, testItem);
Optional<StatusEnum> providedStatus = StatusEnum.fromValue(rq.getStatus());
if (providedStatus.isPresent() && !providedStatus.get().equals(testItem.getItemResults().getStatus())) {
expect(testItem.isHasChildren() && !testItem.getType().sameLevel(TestItemTypeEnum.STEP), equalTo(FALSE)).verify(INCORRECT_REQUEST, "Unable to change status on test item with children");
checkInitialStatusAttribute(testItem, rq);
StatusChangingStrategy strategy = statusChangingStrategyMapping.get(providedStatus.get());
expect(strategy, notNull()).verify(INCORRECT_REQUEST, formattedSupplier("Actual status: '{}' cannot be changed to '{}'.", testItem.getItemResults().getStatus(), providedStatus.get()));
TestItemActivityResource before = TO_ACTIVITY_RESOURCE.apply(testItem, projectDetails.getProjectId());
strategy.changeStatus(testItem, providedStatus.get(), user);
messageBus.publishActivity(new TestItemStatusChangedEvent(before, TO_ACTIVITY_RESOURCE.apply(testItem, projectDetails.getProjectId()), user.getUserId(), user.getUsername()));
}
testItem = new TestItemBuilder(testItem).overwriteAttributes(rq.getAttributes()).addDescription(rq.getDescription()).get();
testItemRepository.save(testItem);
return COMPOSE_UPDATE_RESPONSE.apply(itemId);
}
Aggregations