Search in sources :

Example 31 with StartTestItemRQ

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

the class StartTestItemHandlerImplTest method startRootItemUnderNotExistedLaunch.

@Test
void startRootItemUnderNotExistedLaunch() {
    final ReportPortalUser rpUser = getRpUser("test", UserRole.USER, ProjectRole.MEMBER, 1L);
    when(launchRepository.findByUuid("1")).thenReturn(Optional.empty());
    final StartTestItemRQ rq = new StartTestItemRQ();
    rq.setLaunchUuid("1");
    final ReportPortalException exception = assertThrows(ReportPortalException.class, () -> handler.startRootItem(rpUser, extractProjectDetails(rpUser, "test_project"), rq));
    assertEquals("Launch '1' not found. Did you use correct Launch ID?", exception.getMessage());
}
Also used : ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) StartTestItemRQ(com.epam.ta.reportportal.ws.model.StartTestItemRQ) Test(org.junit.jupiter.api.Test)

Example 32 with StartTestItemRQ

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

the class RerunHandlerImplTest method happyRerunRootItem.

@Test
void happyRerunRootItem() {
    StartTestItemRQ request = new StartTestItemRQ();
    request.setLaunchUuid("launch_uuid");
    request.setType("STEP");
    String itemName = "name";
    request.setName(itemName);
    final String testCaseId = "caseId";
    request.setTestCaseId(testCaseId);
    Launch launch = getLaunch("uuid");
    final TestItem item = getItem(itemName, launch);
    when(rerunSearcher.findItem(any(Queryable.class))).thenReturn(Optional.of(item.getItemId()));
    when(testItemRepository.findById(item.getItemId())).thenReturn(Optional.of(item));
    Optional<ItemCreatedRS> rerunCreatedRS = rerunHandler.handleRootItem(request, launch);
    assertTrue(rerunCreatedRS.isPresent());
}
Also used : Queryable(com.epam.ta.reportportal.commons.querygen.Queryable) StartTestItemRQ(com.epam.ta.reportportal.ws.model.StartTestItemRQ) 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) Test(org.junit.jupiter.api.Test)

Example 33 with StartTestItemRQ

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

the class RerunHandlerImplTest method returnEmptyOptionalWhenRootItemNotFound.

@Test
void returnEmptyOptionalWhenRootItemNotFound() {
    StartTestItemRQ request = new StartTestItemRQ();
    request.setLaunchUuid("launch_uuid");
    request.setType("STEP");
    String itemName = "name";
    request.setName(itemName);
    final String testCaseId = "caseId";
    request.setTestCaseId(testCaseId);
    Launch launch = getLaunch("uuid");
    when(rerunSearcher.findItem(any(Queryable.class))).thenReturn(Optional.empty());
    Optional<ItemCreatedRS> rerunCreatedRS = rerunHandler.handleRootItem(request, launch);
    assertFalse(rerunCreatedRS.isPresent());
}
Also used : Queryable(com.epam.ta.reportportal.commons.querygen.Queryable) StartTestItemRQ(com.epam.ta.reportportal.ws.model.StartTestItemRQ) Launch(com.epam.ta.reportportal.entity.launch.Launch) ItemCreatedRS(com.epam.ta.reportportal.ws.model.item.ItemCreatedRS) Test(org.junit.jupiter.api.Test)

Example 34 with StartTestItemRQ

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

the class DemoDataTestItemService method startTestItem.

@Transactional
public String startTestItem(DemoItemMetadata metadata, RootMetaData rootMetaData) {
    StartTestItemRQ rq = new StartTestItemRQ();
    if (hasChildren(metadata.getType())) {
        rq.setAttributes(ContentUtils.getAttributesInRange(ATTRIBUTES_COUNT));
        rq.setDescription(ContentUtils.getTestDescription());
    } else {
        rq.setAttributes(ContentUtils.getAttributesInRange(ATTRIBUTES_COUNT));
        rq.setDescription(ContentUtils.getStepDescription());
    }
    rq.setHasStats(!metadata.isNested());
    rq.setCodeRef(PACKAGE + metadata.getName());
    rq.setRetry(metadata.isRetry());
    rq.setLaunchUuid(rootMetaData.getLaunchUuid());
    rq.setStartTime(new Date());
    rq.setName(metadata.getName());
    rq.setType(metadata.getType().name());
    return startTestItemHandler.startChildItem(rootMetaData.getUser(), rootMetaData.getProjectDetails(), rq, metadata.getParentId()).getId();
}
Also used : StartTestItemRQ(com.epam.ta.reportportal.ws.model.StartTestItemRQ) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 35 with StartTestItemRQ

use of com.epam.ta.reportportal.ws.model.StartTestItemRQ 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)

Aggregations

StartTestItemRQ (com.epam.ta.reportportal.ws.model.StartTestItemRQ)159 Test (org.junit.jupiter.api.Test)124 FinishTestItemRQ (com.epam.ta.reportportal.ws.model.FinishTestItemRQ)30 List (java.util.List)21 TestNG (org.testng.TestNG)21 Launch (com.epam.reportportal.service.Launch)20 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)19 BeforeEach (org.junit.jupiter.api.BeforeEach)19 TestNgListener (com.epam.reportportal.testng.util.TestNgListener)18 Collectors (java.util.stream.Collectors)17 ArgumentCaptor (org.mockito.ArgumentCaptor)17 ReportPortal (com.epam.reportportal.service.ReportPortal)16 ReportPortalClient (com.epam.reportportal.service.ReportPortalClient)15 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)15 ArgumentMatchers.same (org.mockito.ArgumentMatchers.same)14 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)13 ItemAttributesRQ (com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ)13 BaseMvcTest (com.epam.ta.reportportal.ws.BaseMvcTest)12 Set (java.util.Set)12 Nonnull (javax.annotation.Nonnull)12