Search in sources :

Example 1 with TestItemRepository

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());
}
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 2 with TestItemRepository

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.");
}
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 3 with TestItemRepository

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());
}
Also used : AnalyzedItemRs(com.epam.ta.reportportal.ws.model.analyzer.AnalyzedItemRs) StatusEnum(com.epam.ta.reportportal.entity.enums.StatusEnum) IssueEntity(com.epam.ta.reportportal.entity.item.issue.IssueEntity) java.util(java.util) Project(com.epam.ta.reportportal.entity.project.Project) IssueTypeHandler(com.epam.ta.reportportal.core.item.impl.IssueTypeHandler) TestItem(com.epam.ta.reportportal.entity.item.TestItem) LogLevel(com.epam.ta.reportportal.entity.enums.LogLevel) IndexLaunch(com.epam.ta.reportportal.ws.model.analyzer.IndexLaunch) IndexTestItem(com.epam.ta.reportportal.ws.model.analyzer.IndexTestItem) MessageBus(com.epam.ta.reportportal.core.events.MessageBus) IssueType(com.epam.ta.reportportal.entity.item.issue.IssueType) TestItemRepository(com.epam.ta.reportportal.dao.TestItemRepository) LaunchPreparerService(com.epam.ta.reportportal.core.analyzer.auto.impl.preparer.LaunchPreparerService) Launch(com.epam.ta.reportportal.entity.launch.Launch) AnalyzerConfig(com.epam.ta.reportportal.ws.model.project.AnalyzerConfig) ALL_LAUNCHES(com.epam.ta.reportportal.entity.AnalyzeMode.ALL_LAUNCHES) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) VerificationModeFactory.times(org.mockito.internal.verification.VerificationModeFactory.times) TestItemResults(com.epam.ta.reportportal.entity.item.TestItemResults) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) PRODUCT_BUG(com.epam.ta.reportportal.entity.enums.TestItemIssueGroup.PRODUCT_BUG) IndexLog(com.epam.ta.reportportal.ws.model.analyzer.IndexLog) AnalyzerServiceClient(com.epam.ta.reportportal.core.analyzer.auto.client.AnalyzerServiceClient) AnalyzerConfig(com.epam.ta.reportportal.ws.model.project.AnalyzerConfig) IndexLaunch(com.epam.ta.reportportal.ws.model.analyzer.IndexLaunch) IndexTestItem(com.epam.ta.reportportal.ws.model.analyzer.IndexTestItem) IndexLaunch(com.epam.ta.reportportal.ws.model.analyzer.IndexLaunch) Launch(com.epam.ta.reportportal.entity.launch.Launch) TestItem(com.epam.ta.reportportal.entity.item.TestItem) IndexTestItem(com.epam.ta.reportportal.ws.model.analyzer.IndexTestItem) Test(org.junit.jupiter.api.Test)

Aggregations

TestItemRepository (com.epam.ta.reportportal.dao.TestItemRepository)3 TestItem (com.epam.ta.reportportal.entity.item.TestItem)3 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 MessageBus (com.epam.ta.reportportal.core.events.MessageBus)2 RetryHandler (com.epam.ta.reportportal.core.item.impl.retry.RetryHandler)2 RetrySearcher (com.epam.ta.reportportal.core.item.impl.retry.RetrySearcher)2 LaunchRepository (com.epam.ta.reportportal.dao.LaunchRepository)2 StatusEnum (com.epam.ta.reportportal.entity.enums.StatusEnum)2 TestItemResults (com.epam.ta.reportportal.entity.item.TestItemResults)2 IssueEntity (com.epam.ta.reportportal.entity.item.issue.IssueEntity)2 IssueType (com.epam.ta.reportportal.entity.item.issue.IssueType)2 Project (com.epam.ta.reportportal.entity.project.Project)2 java.util (java.util)2 TO_LOCAL_DATE_TIME (com.epam.ta.reportportal.commons.EntityUtils.TO_LOCAL_DATE_TIME)1 Suppliers.formattedSupplier (com.epam.ta.reportportal.commons.validation.Suppliers.formattedSupplier)1 LogIndexer (com.epam.ta.reportportal.core.analyzer.auto.LogIndexer)1