Search in sources :

Example 1 with ItemCreatedRS

use of com.epam.ta.reportportal.ws.model.item.ItemCreatedRS 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 2 with ItemCreatedRS

use of com.epam.ta.reportportal.ws.model.item.ItemCreatedRS 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 3 with ItemCreatedRS

use of com.epam.ta.reportportal.ws.model.item.ItemCreatedRS 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 4 with ItemCreatedRS

use of com.epam.ta.reportportal.ws.model.item.ItemCreatedRS 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 5 with ItemCreatedRS

use of com.epam.ta.reportportal.ws.model.item.ItemCreatedRS in project allure-java by reportportal.

the class TestUtils method mockLaunch.

@SuppressWarnings("unchecked")
public static <T extends Collection<String>> void mockLaunch(ReportPortalClient client, String launchUuid, String suiteUuid, Collection<Pair<String, T>> testSteps) {
    when(client.startLaunch(any())).thenReturn(createMaybe(new StartLaunchRS(launchUuid, 1L)));
    Maybe<ItemCreatedRS> suiteMaybe = createMaybe(new ItemCreatedRS(suiteUuid, suiteUuid));
    when(client.startTestItem(any())).thenReturn(suiteMaybe);
    List<Maybe<ItemCreatedRS>> testResponses = testSteps.stream().map(Pair::getKey).map(uuid -> createMaybe(new ItemCreatedRS(uuid, uuid))).collect(Collectors.toList());
    Maybe<ItemCreatedRS> first = testResponses.get(0);
    Maybe<ItemCreatedRS>[] other = testResponses.subList(1, testResponses.size()).toArray(new Maybe[0]);
    when(client.startTestItem(same(suiteUuid), any())).thenReturn(first, other);
    testSteps.forEach(test -> {
        String testClassUuid = test.getKey();
        List<Maybe<ItemCreatedRS>> stepResponses = test.getValue().stream().map(uuid -> createMaybe(new ItemCreatedRS(uuid, uuid))).collect(Collectors.toList());
        Maybe<ItemCreatedRS> myFirst = stepResponses.get(0);
        Maybe<ItemCreatedRS>[] myOther = stepResponses.subList(1, stepResponses.size()).toArray(new Maybe[0]);
        when(client.startTestItem(same(testClassUuid), any())).thenReturn(myFirst, myOther);
        new HashSet<>(test.getValue()).forEach(testMethodUuid -> when(client.finishTestItem(same(testMethodUuid), any())).thenReturn(createMaybe(new OperationCompletionRS())));
        when(client.finishTestItem(same(testClassUuid), any())).thenReturn(createMaybe(new OperationCompletionRS()));
    });
    Maybe<OperationCompletionRS> suiteFinishMaybe = createMaybe(new OperationCompletionRS());
    when(client.finishTestItem(eq(suiteUuid), any())).thenReturn(suiteFinishMaybe);
    when(client.finishLaunch(eq(launchUuid), any())).thenReturn(createMaybe(new OperationCompletionRS()));
}
Also used : CommonUtils.createMaybe(com.epam.reportportal.util.test.CommonUtils.createMaybe) java.util(java.util) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS) ArgumentMatchers(org.mockito.ArgumentMatchers) ListenerParameters(com.epam.reportportal.listeners.ListenerParameters) Maybe(io.reactivex.Maybe) Answer(org.mockito.stubbing.Answer) BatchSaveOperatingRS(com.epam.ta.reportportal.ws.model.BatchSaveOperatingRS) ArgumentCaptor(org.mockito.ArgumentCaptor) Pair(org.apache.commons.lang3.tuple.Pair) Constants(com.epam.ta.reportportal.ws.model.Constants) TestNG(org.testng.TestNG) ItemCreatedRS(com.epam.ta.reportportal.ws.model.item.ItemCreatedRS) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ExecutorService(java.util.concurrent.ExecutorService) CommonUtils.generateUniqueId(com.epam.reportportal.util.test.CommonUtils.generateUniqueId) ReportPortalClient(com.epam.reportportal.service.ReportPortalClient) Buffer(okio.Buffer) Predicate(java.util.function.Predicate) Optional.ofNullable(java.util.Optional.ofNullable) IOException(java.io.IOException) SaveLogRQ(com.epam.ta.reportportal.ws.model.log.SaveLogRQ) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) MultipartBody(okhttp3.MultipartBody) StartLaunchRS(com.epam.ta.reportportal.ws.model.launch.StartLaunchRS) HttpRequestUtils(com.epam.reportportal.utils.http.HttpRequestUtils) CommonUtils.createMaybe(com.epam.reportportal.util.test.CommonUtils.createMaybe) Maybe(io.reactivex.Maybe) StartLaunchRS(com.epam.ta.reportportal.ws.model.launch.StartLaunchRS) ItemCreatedRS(com.epam.ta.reportportal.ws.model.item.ItemCreatedRS) Pair(org.apache.commons.lang3.tuple.Pair) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Aggregations

ItemCreatedRS (com.epam.ta.reportportal.ws.model.item.ItemCreatedRS)21 ListenerParameters (com.epam.reportportal.listeners.ListenerParameters)11 ReportPortalClient (com.epam.reportportal.service.ReportPortalClient)11 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)11 StartLaunchRS (com.epam.ta.reportportal.ws.model.launch.StartLaunchRS)11 Maybe (io.reactivex.Maybe)11 java.util (java.util)10 Collectors (java.util.stream.Collectors)10 Pair (org.apache.commons.lang3.tuple.Pair)10 ArgumentCaptor (org.mockito.ArgumentCaptor)10 ArgumentMatchers (org.mockito.ArgumentMatchers)10 Mockito.when (org.mockito.Mockito.when)10 Answer (org.mockito.stubbing.Answer)10 StartTestItemRQ (com.epam.ta.reportportal.ws.model.StartTestItemRQ)9 CommonUtils (com.epam.reportportal.util.test.CommonUtils)8 BatchSaveOperatingRS (com.epam.ta.reportportal.ws.model.BatchSaveOperatingRS)8 SaveLogRQ (com.epam.ta.reportportal.ws.model.log.SaveLogRQ)7 Optional.ofNullable (java.util.Optional.ofNullable)7 HttpRequestUtils (com.epam.reportportal.utils.http.HttpRequestUtils)6 Constants (com.epam.ta.reportportal.ws.model.Constants)6