Search in sources :

Example 11 with TestItemActivityResource

use of com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource 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);
}
Also used : StatusEnum(com.epam.ta.reportportal.entity.enums.StatusEnum) TestItemBuilder(com.epam.ta.reportportal.ws.converter.builders.TestItemBuilder) TestItemStatusChangedEvent(com.epam.ta.reportportal.core.events.activity.TestItemStatusChangedEvent) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) StatusChangingStrategy(com.epam.ta.reportportal.core.item.impl.status.StatusChangingStrategy) TestItemActivityResource(com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource) TestItem(com.epam.ta.reportportal.entity.item.TestItem)

Example 12 with TestItemActivityResource

use of com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource in project service-api by reportportal.

the class AbstractStatusChangingStrategy method changeParentsStatuses.

protected List<Long> changeParentsStatuses(TestItem testItem, Launch launch, boolean issueRequired, ReportPortalUser user) {
    List<Long> updatedParents = Lists.newArrayList();
    Long parentId = testItem.getParentId();
    while (parentId != null) {
        TestItem parent = testItemRepository.findById(parentId).orElseThrow(() -> new ReportPortalException(ErrorType.TEST_ITEM_NOT_FOUND, testItem.getParentId()));
        StatusEnum currentParentStatus = parent.getItemResults().getStatus();
        if (!StatusEnum.IN_PROGRESS.equals(currentParentStatus)) {
            StatusEnum newParentStatus = evaluateParentItemStatus(parent, testItem);
            if (!currentParentStatus.equals(newParentStatus)) {
                TestItemActivityResource before = TO_ACTIVITY_RESOURCE.apply(parent, launch.getProjectId());
                parent.getItemResults().setStatus(newParentStatus);
                updateItem(parent, launch.getProjectId(), issueRequired).ifPresent(updatedParents::add);
                publishUpdateActivity(before, TO_ACTIVITY_RESOURCE.apply(parent, launch.getProjectId()), user);
            } else {
                return updatedParents;
            }
        } else {
            return updatedParents;
        }
        parentId = parent.getParentId();
    }
    if (launch.getStatus() != IN_PROGRESS) {
        launch.setStatus(launchRepository.hasRootItemsWithStatusNotEqual(launch.getId(), StatusEnum.PASSED.name(), INFO.name(), WARN.name()) ? FAILED : PASSED);
    }
    return updatedParents;
}
Also used : StatusEnum(com.epam.ta.reportportal.entity.enums.StatusEnum) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) TestItemActivityResource(com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource) TestItem(com.epam.ta.reportportal.entity.item.TestItem)

Example 13 with TestItemActivityResource

use of com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource in project service-api by reportportal.

the class TestItemConverterTest method toActivityResource.

@Test
void toActivityResource() {
    final TestItem item = getItem(true);
    final TestItemActivityResource activityResource = TestItemConverter.TO_ACTIVITY_RESOURCE.apply(item, 4L);
    assertEquals(activityResource.getId(), item.getItemId());
    assertEquals(activityResource.getName(), item.getName());
    assertEquals((long) activityResource.getProjectId(), 4L);
    assertEquals(activityResource.getIssueDescription(), item.getItemResults().getIssue().getIssueDescription());
    assertEquals(activityResource.getIssueTypeLongName(), item.getItemResults().getIssue().getIssueType().getLongName());
    assertEquals(activityResource.getStatus(), item.getItemResults().getStatus().name());
    assertEquals(activityResource.getTickets(), item.getItemResults().getIssue().getTickets().stream().map(it -> it.getTicketId().concat(":").concat(it.getUrl())).collect(Collectors.joining(", ")));
    assertEquals(activityResource.isIgnoreAnalyzer(), item.getItemResults().getIssue().getIgnoreAnalyzer());
    assertEquals(activityResource.isAutoAnalyzed(), item.getItemResults().getIssue().getAutoAnalyzed());
}
Also used : TestItemActivityResource(com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource) TestItem(com.epam.ta.reportportal.entity.item.TestItem) Test(org.junit.jupiter.api.Test)

Aggregations

TestItemActivityResource (com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource)13 TestItem (com.epam.ta.reportportal.entity.item.TestItem)7 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)6 StatusEnum (com.epam.ta.reportportal.entity.enums.StatusEnum)4 ItemIssueTypeDefinedEvent (com.epam.ta.reportportal.core.events.activity.ItemIssueTypeDefinedEvent)3 TestItemStatusChangedEvent (com.epam.ta.reportportal.core.events.activity.TestItemStatusChangedEvent)3 StatusChangingStrategy (com.epam.ta.reportportal.core.item.impl.status.StatusChangingStrategy)3 IssueEntity (com.epam.ta.reportportal.entity.item.issue.IssueEntity)3 IssueType (com.epam.ta.reportportal.entity.item.issue.IssueType)3 IssueEntityBuilder (com.epam.ta.reportportal.ws.converter.builders.IssueEntityBuilder)3 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)2 BusinessRule.expect (com.epam.ta.reportportal.commons.validation.BusinessRule.expect)2 BusinessRuleViolationException (com.epam.ta.reportportal.commons.validation.BusinessRuleViolationException)2 MessageBus (com.epam.ta.reportportal.core.events.MessageBus)2 TestItemRepository (com.epam.ta.reportportal.dao.TestItemRepository)2 Project (com.epam.ta.reportportal.entity.project.Project)2 TestItemBuilder (com.epam.ta.reportportal.ws.converter.builders.TestItemBuilder)2 BtsConstants (com.epam.reportportal.extension.bugtracking.BtsConstants)1 BtsExtension (com.epam.reportportal.extension.bugtracking.BtsExtension)1 Predicates (com.epam.ta.reportportal.commons.Predicates)1