Search in sources :

Example 1 with TestItemBuilder

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));
    });
}
Also used : TestItemBuilder(com.epam.ta.reportportal.ws.converter.builders.TestItemBuilder) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Filter(com.epam.ta.reportportal.commons.querygen.Filter) FilterCondition(com.epam.ta.reportportal.commons.querygen.FilterCondition) TestItem(com.epam.ta.reportportal.entity.item.TestItem)

Example 2 with TestItemBuilder

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());
}
Also used : TestItemBuilder(com.epam.ta.reportportal.ws.converter.builders.TestItemBuilder) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Launch(com.epam.ta.reportportal.entity.launch.Launch) ItemCreatedRS(com.epam.ta.reportportal.ws.model.item.ItemCreatedRS) TestItem(com.epam.ta.reportportal.entity.item.TestItem)

Example 3 with TestItemBuilder

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());
}
Also used : Primary(org.springframework.context.annotation.Primary) Project(com.epam.ta.reportportal.entity.project.Project) TestItem(com.epam.ta.reportportal.entity.item.TestItem) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) BooleanUtils(org.apache.commons.lang3.BooleanUtils) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) StringUtils(org.apache.commons.lang3.StringUtils) RerunHandler(com.epam.ta.reportportal.core.launch.rerun.RerunHandler) ParentItemValidator(com.epam.ta.reportportal.core.item.validator.parent.ParentItemValidator) StartTestItemRQ(com.epam.ta.reportportal.ws.model.StartTestItemRQ) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) TestCaseHashGenerator(com.epam.ta.reportportal.core.item.identity.TestCaseHashGenerator) Predicates.equalTo(com.epam.ta.reportportal.commons.Predicates.equalTo) Service(org.springframework.stereotype.Service) UserRole(com.epam.ta.reportportal.entity.user.UserRole) Qualifier(org.springframework.beans.factory.annotation.Qualifier) UniqueIdGenerator(com.epam.ta.reportportal.core.item.identity.UniqueIdGenerator) ItemCreatedRS(com.epam.ta.reportportal.ws.model.item.ItemCreatedRS) Preconditions(com.epam.ta.reportportal.commons.Preconditions) TestItemRepository(com.epam.ta.reportportal.dao.TestItemRepository) RetrySearcher(com.epam.ta.reportportal.core.item.impl.retry.RetrySearcher) Logger(org.slf4j.Logger) Launch(com.epam.ta.reportportal.entity.launch.Launch) BusinessRule.expect(com.epam.ta.reportportal.commons.validation.BusinessRule.expect) Optional.ofNullable(java.util.Optional.ofNullable) IdentityUtil(com.epam.ta.reportportal.core.item.identity.IdentityUtil) 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) Objects(java.util.Objects) List(java.util.List) LaunchRepository(com.epam.ta.reportportal.dao.LaunchRepository) Optional(java.util.Optional) BooleanUtils.isTrue(org.apache.commons.lang3.BooleanUtils.isTrue) StartTestItemHandler(com.epam.ta.reportportal.core.item.StartTestItemHandler) 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) ItemCreatedRS(com.epam.ta.reportportal.ws.model.item.ItemCreatedRS) TestItem(com.epam.ta.reportportal.entity.item.TestItem)

Example 4 with TestItemBuilder

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.");
}
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 5 with TestItemBuilder

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);
}
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)

Aggregations

TestItemBuilder (com.epam.ta.reportportal.ws.converter.builders.TestItemBuilder)6 TestItem (com.epam.ta.reportportal.entity.item.TestItem)5 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)5 Launch (com.epam.ta.reportportal.entity.launch.Launch)3 Preconditions (com.epam.ta.reportportal.commons.Preconditions)2 Predicates.equalTo (com.epam.ta.reportportal.commons.Predicates.equalTo)2 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)2 BusinessRule.expect (com.epam.ta.reportportal.commons.validation.BusinessRule.expect)2 TestItemStatusChangedEvent (com.epam.ta.reportportal.core.events.activity.TestItemStatusChangedEvent)2 RetryHandler (com.epam.ta.reportportal.core.item.impl.retry.RetryHandler)2 RetrySearcher (com.epam.ta.reportportal.core.item.impl.retry.RetrySearcher)2 StatusChangingStrategy (com.epam.ta.reportportal.core.item.impl.status.StatusChangingStrategy)2 LaunchRepository (com.epam.ta.reportportal.dao.LaunchRepository)2 TestItemRepository (com.epam.ta.reportportal.dao.TestItemRepository)2 StatusEnum (com.epam.ta.reportportal.entity.enums.StatusEnum)2 UserRole (com.epam.ta.reportportal.entity.user.UserRole)2 TestItemActivityResource (com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource)2 ItemCreatedRS (com.epam.ta.reportportal.ws.model.item.ItemCreatedRS)2 TO_LOCAL_DATE_TIME (com.epam.ta.reportportal.commons.EntityUtils.TO_LOCAL_DATE_TIME)1 Filter (com.epam.ta.reportportal.commons.querygen.Filter)1