Search in sources :

Example 26 with TestItemResults

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")));
}
Also used : TestItemTypeEnum(com.epam.ta.reportportal.entity.enums.TestItemTypeEnum) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) StatusEnum(com.epam.ta.reportportal.entity.enums.StatusEnum) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS) TestItemService(com.epam.ta.reportportal.core.item.TestItemService) TestItem(com.epam.ta.reportportal.entity.item.TestItem) INITIAL_STATUS_ATTRIBUTE_KEY(com.epam.ta.reportportal.core.item.impl.UpdateTestItemHandlerImpl.INITIAL_STATUS_ATTRIBUTE_KEY) Mock(org.mockito.Mock) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) DefineIssueRQ(com.epam.ta.reportportal.ws.model.issue.DefineIssueRQ) MessageBus(com.epam.ta.reportportal.core.events.MessageBus) StatusChangingStrategy(com.epam.ta.reportportal.core.item.impl.status.StatusChangingStrategy) ItemAttribute(com.epam.ta.reportportal.entity.ItemAttribute) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) UpdateTestItemRQ(com.epam.ta.reportportal.ws.model.item.UpdateTestItemRQ) UserRole(com.epam.ta.reportportal.entity.user.UserRole) Map(java.util.Map) TestProjectExtractor.extractProjectDetails(com.epam.ta.reportportal.util.TestProjectExtractor.extractProjectDetails) TestItemRepository(com.epam.ta.reportportal.dao.TestItemRepository) InjectMocks(org.mockito.InjectMocks) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Launch(com.epam.ta.reportportal.entity.launch.Launch) User(com.epam.ta.reportportal.entity.user.User) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) ProjectRole(com.epam.ta.reportportal.entity.project.ProjectRole) ProjectRepository(com.epam.ta.reportportal.dao.ProjectRepository) TestItemResults(com.epam.ta.reportportal.entity.item.TestItemResults) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) ReportPortalUserUtil.getRpUser(com.epam.ta.reportportal.ReportPortalUserUtil.getRpUser) UpdateTestItemRQ(com.epam.ta.reportportal.ws.model.item.UpdateTestItemRQ) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) TestItemResults(com.epam.ta.reportportal.entity.item.TestItemResults) Launch(com.epam.ta.reportportal.entity.launch.Launch) TestItem(com.epam.ta.reportportal.entity.item.TestItem) Test(org.junit.jupiter.api.Test)

Example 27 with TestItemResults

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;
}
Also used : TestItemResults(com.epam.ta.reportportal.entity.item.TestItemResults)

Example 28 with 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;
}
Also used : StatusEnum(com.epam.ta.reportportal.entity.enums.StatusEnum) JStatusEnum(com.epam.ta.reportportal.jooq.enums.JStatusEnum) TestItemResults(com.epam.ta.reportportal.entity.item.TestItemResults)

Example 29 with 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.");
}
Also used : StatusEnum(com.epam.ta.reportportal.entity.enums.StatusEnum) IssueEntity(com.epam.ta.reportportal.entity.item.issue.IssueEntity) Primary(org.springframework.context.annotation.Primary) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS) ATTRIBUTE_VALUE_INTERRUPTED(com.epam.ta.reportportal.core.hierarchy.AbstractFinishHierarchyHandler.ATTRIBUTE_VALUE_INTERRUPTED) Autowired(org.springframework.beans.factory.annotation.Autowired) MessageBus(com.epam.ta.reportportal.core.events.MessageBus) StringUtils(org.apache.commons.lang3.StringUtils) FinishTestItemRQ(com.epam.ta.reportportal.ws.model.FinishTestItemRQ) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) TO_INVESTIGATE(com.epam.ta.reportportal.entity.enums.TestItemIssueGroup.TO_INVESTIGATE) Preconditions(com.epam.ta.reportportal.commons.Preconditions) TestItemRepository(com.epam.ta.reportportal.dao.TestItemRepository) Suppliers.formattedSupplier(com.epam.ta.reportportal.commons.validation.Suppliers.formattedSupplier) TestItemActivityResource(com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource) ChangeStatusHandler(com.epam.ta.reportportal.core.item.impl.status.ChangeStatusHandler) Launch(com.epam.ta.reportportal.entity.launch.Launch) LogIndexer(com.epam.ta.reportportal.core.analyzer.auto.LogIndexer) TestItemStatusChangedEvent(com.epam.ta.reportportal.core.events.activity.TestItemStatusChangedEvent) Predicate(java.util.function.Predicate) BusinessRule.expect(com.epam.ta.reportportal.commons.validation.BusinessRule.expect) IssueConverter(com.epam.ta.reportportal.ws.converter.converters.IssueConverter) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) TestItemBuilder(com.epam.ta.reportportal.ws.converter.builders.TestItemBuilder) RetryHandler(com.epam.ta.reportportal.core.item.impl.retry.RetryHandler) ITEM_CAN_BE_INDEXED(com.epam.ta.reportportal.util.Predicates.ITEM_CAN_BE_INDEXED) IssueEntityRepository(com.epam.ta.reportportal.dao.IssueEntityRepository) NOT_ISSUE_FLAG(com.epam.ta.reportportal.entity.enums.TestItemIssueGroup.NOT_ISSUE_FLAG) LaunchRepository(com.epam.ta.reportportal.dao.LaunchRepository) TestItemResults(com.epam.ta.reportportal.entity.item.TestItemResults) JStatusEnum(com.epam.ta.reportportal.jooq.enums.JStatusEnum) java.util(java.util) Issue(com.epam.ta.reportportal.ws.model.issue.Issue) TestItem(com.epam.ta.reportportal.entity.item.TestItem) TO_LOCAL_DATE_TIME(com.epam.ta.reportportal.commons.EntityUtils.TO_LOCAL_DATE_TIME) BooleanUtils(org.apache.commons.lang3.BooleanUtils) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) FinishTestItemHandler(com.epam.ta.reportportal.core.item.FinishTestItemHandler) StatusChangingStrategy(com.epam.ta.reportportal.core.item.impl.status.StatusChangingStrategy) ExternalTicketHandler(com.epam.ta.reportportal.core.item.ExternalTicketHandler) Lists(com.google.common.collect.Lists) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) Predicates.equalTo(com.epam.ta.reportportal.commons.Predicates.equalTo) CollectionUtils(org.apache.commons.collections.CollectionUtils) Service(org.springframework.stereotype.Service) UserRole(com.epam.ta.reportportal.entity.user.UserRole) IssueType(com.epam.ta.reportportal.entity.item.issue.IssueType) Qualifier(org.springframework.beans.factory.annotation.Qualifier) LogRepository(com.epam.ta.reportportal.dao.LogRepository) Nullable(javax.annotation.Nullable) ATTRIBUTE_KEY_STATUS(com.epam.ta.reportportal.core.hierarchy.AbstractFinishHierarchyHandler.ATTRIBUTE_KEY_STATUS) RetrySearcher(com.epam.ta.reportportal.core.item.impl.retry.RetrySearcher) FinishHierarchyHandler(com.epam.ta.reportportal.core.hierarchy.FinishHierarchyHandler) Optional.ofNullable(java.util.Optional.ofNullable) TO_ACTIVITY_RESOURCE(com.epam.ta.reportportal.ws.converter.converters.TestItemConverter.TO_ACTIVITY_RESOURCE) ItemFinishedEvent(com.epam.ta.reportportal.core.events.item.ItemFinishedEvent) PROJECT_MANAGER(com.epam.ta.reportportal.entity.project.ProjectRole.PROJECT_MANAGER) Transactional(org.springframework.transaction.annotation.Transactional) TestItemBuilder(com.epam.ta.reportportal.ws.converter.builders.TestItemBuilder) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Launch(com.epam.ta.reportportal.entity.launch.Launch) TestItemResults(com.epam.ta.reportportal.entity.item.TestItemResults) TestItem(com.epam.ta.reportportal.entity.item.TestItem) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Example 30 with TestItemResults

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;
}
Also used : TestItemIssueGroup(com.epam.ta.reportportal.entity.enums.TestItemIssueGroup) IssueGroup(com.epam.ta.reportportal.entity.item.issue.IssueGroup) Ticket(com.epam.ta.reportportal.entity.bts.Ticket) IssueType(com.epam.ta.reportportal.entity.item.issue.IssueType) StatisticsField(com.epam.ta.reportportal.entity.statistics.StatisticsField) IssueEntity(com.epam.ta.reportportal.entity.item.issue.IssueEntity) Parameter(com.epam.ta.reportportal.entity.item.Parameter) ItemAttribute(com.epam.ta.reportportal.entity.ItemAttribute) Launch(com.epam.ta.reportportal.entity.launch.Launch) TestItemResults(com.epam.ta.reportportal.entity.item.TestItemResults) Statistics(com.epam.ta.reportportal.entity.statistics.Statistics) TestItem(com.epam.ta.reportportal.entity.item.TestItem)

Aggregations

TestItemResults (com.epam.ta.reportportal.entity.item.TestItemResults)34 TestItem (com.epam.ta.reportportal.entity.item.TestItem)29 Test (org.junit.jupiter.api.Test)18 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)14 Launch (com.epam.ta.reportportal.entity.launch.Launch)13 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)10 IssueEntity (com.epam.ta.reportportal.entity.item.issue.IssueEntity)8 ReportPortalUserUtil.getRpUser (com.epam.ta.reportportal.ReportPortalUserUtil.getRpUser)7 IssueType (com.epam.ta.reportportal.entity.item.issue.IssueType)7 User (com.epam.ta.reportportal.entity.user.User)7 StatusEnum (com.epam.ta.reportportal.entity.enums.StatusEnum)6 ItemAttribute (com.epam.ta.reportportal.entity.ItemAttribute)5 IssueGroup (com.epam.ta.reportportal.entity.item.issue.IssueGroup)5 Statistics (com.epam.ta.reportportal.entity.statistics.Statistics)5 FinishTestItemRQ (com.epam.ta.reportportal.ws.model.FinishTestItemRQ)5 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)5 TestItemIssueGroup (com.epam.ta.reportportal.entity.enums.TestItemIssueGroup)4 Parameter (com.epam.ta.reportportal.entity.item.Parameter)4 MessageBus (com.epam.ta.reportportal.core.events.MessageBus)3 StatusChangingStrategy (com.epam.ta.reportportal.core.item.impl.status.StatusChangingStrategy)3