use of com.epam.ta.reportportal.entity.item.TestItemResults in project service-api by reportportal.
the class UpdateTestItemHandlerImplTest method shouldCreateInitialStatusAttribute.
@Test
void shouldCreateInitialStatusAttribute() {
ReportPortalUser user = getRpUser("user", UserRole.ADMINISTRATOR, ProjectRole.PROJECT_MANAGER, 1L);
UpdateTestItemRQ rq = new UpdateTestItemRQ();
rq.setStatus("PASSED");
long itemId = 1L;
TestItem item = new TestItem();
item.setItemId(itemId);
item.setHasChildren(false);
item.setType(TestItemTypeEnum.STEP);
TestItemResults itemResults = new TestItemResults();
itemResults.setStatus(StatusEnum.FAILED);
item.setItemResults(itemResults);
Launch launch = new Launch();
launch.setId(2L);
item.setLaunchId(launch.getId());
when(testItemService.getEffectiveLaunch(item)).thenReturn(launch);
when(itemRepository.findById(itemId)).thenReturn(Optional.of(item));
doNothing().when(messageBus).publishActivity(any());
when(statusChangingStrategyMapping.get(StatusEnum.PASSED)).thenReturn(statusChangingStrategy);
doNothing().when(statusChangingStrategy).changeStatus(item, StatusEnum.PASSED, user);
handler.updateTestItem(extractProjectDetails(user, "test_project"), itemId, rq, user);
assertTrue(item.getAttributes().stream().anyMatch(attribute -> INITIAL_STATUS_ATTRIBUTE_KEY.equalsIgnoreCase(attribute.getKey()) && StatusEnum.FAILED.getExecutionCounterField().equalsIgnoreCase("failed")));
}
use of com.epam.ta.reportportal.entity.item.TestItemResults in project service-api by reportportal.
the class FinishTestItemHandlerImpl method processItemResults.
/**
* If test item has descendants, it's status is resolved from statistics
* When status provided, no matter test item has or not descendants, test
* item status is resolved to provided
*
* @param testItem {@link TestItem}
* @param finishTestItemRQ {@link FinishTestItemRQ}
* @return TestItemResults {@link TestItemResults}
*/
private TestItemResults processItemResults(ReportPortalUser user, ReportPortalUser.ProjectDetails projectDetails, Launch launch, TestItem testItem, FinishTestItemRQ finishTestItemRQ, boolean hasChildren) {
validateRoles(user, projectDetails, launch);
verifyTestItem(testItem, fromValue(finishTestItemRQ.getStatus()), testItem.isHasChildren());
TestItemResults testItemResults;
if (hasChildren) {
testItemResults = processParentItemResult(testItem, finishTestItemRQ, launch, user, projectDetails);
} else {
testItemResults = processChildItemResult(testItem, finishTestItemRQ, user, projectDetails, launch);
}
testItemResults.setEndTime(TO_LOCAL_DATE_TIME.apply(finishTestItemRQ.getEndTime()));
return testItemResults;
}
use of com.epam.ta.reportportal.entity.item.TestItemResults in project service-api by reportportal.
the class FinishTestItemHandlerImpl method processParentItemResult.
private TestItemResults processParentItemResult(TestItem testItem, FinishTestItemRQ finishTestItemRQ, Launch launch, ReportPortalUser user, ReportPortalUser.ProjectDetails projectDetails) {
TestItemResults testItemResults = testItem.getItemResults();
Optional<StatusEnum> actualStatus = fromValue(finishTestItemRQ.getStatus());
if (testItemRepository.hasItemsInStatusByParent(testItem.getItemId(), testItem.getPath(), IN_PROGRESS.name())) {
finishHierarchyHandler.finishDescendants(testItem, actualStatus.orElse(INTERRUPTED), finishTestItemRQ.getEndTime(), user, projectDetails);
testItemResults.setStatus(resolveStatus(testItem.getItemId()));
} else {
testItemResults.setStatus(actualStatus.orElseGet(() -> resolveStatus(testItem.getItemId())));
}
testItem.getAttributes().removeIf(attribute -> ATTRIBUTE_KEY_STATUS.equalsIgnoreCase(attribute.getKey()) && ATTRIBUTE_VALUE_INTERRUPTED.equalsIgnoreCase(attribute.getValue()));
changeStatusHandler.changeParentStatus(testItem, projectDetails.getProjectId(), user);
changeStatusHandler.changeLaunchStatus(launch);
return testItemResults;
}
use of com.epam.ta.reportportal.entity.item.TestItemResults 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.entity.item.TestItemResults in project service-api by reportportal.
the class TestItemConverterTest method getItem.
private TestItem getItem(boolean hasIssue) {
TestItem item = new TestItem();
item.setName("name");
item.setDescription("description");
item.setStartTime(LocalDateTime.now());
item.setUniqueId("uniqueId");
item.setUuid("uuid");
item.setItemId(1L);
item.setType(TestItemTypeEnum.STEP);
item.setPath("1.2.3");
final Parameter parameter = new Parameter();
parameter.setKey("key");
parameter.setValue("value");
item.setParameters(Sets.newHashSet(parameter));
item.setAttributes(Sets.newHashSet(new ItemAttribute("key1", "value1", false), new ItemAttribute("key2", "value2", false)));
final Launch launch = new Launch();
launch.setProjectId(4L);
launch.setId(2L);
item.setLaunchId(launch.getId());
item.setHasChildren(false);
final TestItem parent = new TestItem();
parent.setItemId(3L);
item.setParentId(parent.getItemId());
final TestItemResults itemResults = new TestItemResults();
itemResults.setStatus(StatusEnum.FAILED);
itemResults.setEndTime(LocalDateTime.now());
if (hasIssue) {
final IssueEntity issue = new IssueEntity();
issue.setIssueId(3L);
issue.setIssueType(new IssueType(new IssueGroup(TestItemIssueGroup.PRODUCT_BUG), "locator", "long name", "SNA", "color"));
issue.setIgnoreAnalyzer(false);
issue.setAutoAnalyzed(false);
issue.setIssueDescription("issue description");
final Ticket ticket = new Ticket();
ticket.setTicketId("ticketId1");
ticket.setUrl("http:/example.com/ticketId1");
final Ticket ticket1 = new Ticket();
ticket1.setTicketId("ticketId2");
ticket1.setUrl("http:/example.com/ticketId2");
issue.setTickets(Sets.newHashSet(ticket, ticket1));
itemResults.setIssue(issue);
}
itemResults.setStatistics(Sets.newHashSet(new Statistics(new StatisticsField("statistics$defects$automation_bug$total"), 1, 2L)));
item.setItemResults(itemResults);
return item;
}
Aggregations