use of com.epam.ta.reportportal.dao.TestItemRepository 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.dao.TestItemRepository 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.dao.TestItemRepository in project service-api by reportportal.
the class AnalyzerServiceServiceTest method analyze.
@Test
void analyze() {
int itemsCount = 2;
Launch launch = launch();
List<TestItem> items = testItemsTI(itemsCount);
items.forEach(item -> item.setLaunchId(launch.getId()));
AnalyzerConfig analyzerConfig = analyzerConfig();
final IndexLaunch indexLaunch = new IndexLaunch();
indexLaunch.setLaunchId(launch.getId());
indexLaunch.setAnalyzerConfig(analyzerConfig);
final List<IndexTestItem> indexTestItems = items.stream().map(AnalyzerUtils::fromTestItem).peek(item -> item.setLogs(errorLogs(2))).collect(Collectors.toList());
indexLaunch.setTestItems(indexTestItems);
when(testItemRepository.findAllById(anyList())).thenReturn(items);
when(launchPreparerService.prepare(any(Launch.class), anyList(), any(AnalyzerConfig.class))).thenReturn(Optional.of(indexLaunch));
when(analyzerServiceClient.analyze(any())).thenReturn(analyzedItems(itemsCount));
when(issueTypeHandler.defineIssueType(anyLong(), eq("pb001"))).thenReturn(issueProductBug().getIssueType());
issuesAnalyzer.runAnalyzers(launch, items.stream().map(TestItem::getItemId).collect(Collectors.toList()), analyzerConfig);
verify(analyzerServiceClient, times(1)).analyze(any());
verify(testItemRepository, times(itemsCount)).save(any());
verify(messageBus, times(4)).publishActivity(any());
}
Aggregations