Search in sources :

Example 1 with StartLaunchRS

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

the class StartLaunchHandlerImpl method startLaunch.

@Override
@Transactional
public StartLaunchRS startLaunch(ReportPortalUser user, ReportPortalUser.ProjectDetails projectDetails, StartLaunchRQ request) {
    validateRoles(projectDetails, request);
    final Launch savedLaunch = Optional.of(request.isRerun()).filter(Boolean::booleanValue).map(rerun -> rerunHandler.handleLaunch(request, projectDetails.getProjectId(), user)).orElseGet(() -> {
        Launch launch = new LaunchBuilder().addStartRQ(request).addAttributes(request.getAttributes()).addProject(projectDetails.getProjectId()).addUserId(user.getUserId()).get();
        launchRepository.save(launch);
        launchRepository.refresh(launch);
        return launch;
    });
    eventPublisher.publishEvent(new StartLaunchEvent(savedLaunch.getId()));
    messageBus.publishActivity(new LaunchStartedEvent(TO_ACTIVITY_RESOURCE.apply(savedLaunch), user.getUserId(), user.getUsername()));
    StartLaunchRS response = new StartLaunchRS();
    response.setId(savedLaunch.getUuid());
    response.setNumber(savedLaunch.getNumber());
    return response;
}
Also used : Primary(org.springframework.context.annotation.Primary) Launch(com.epam.ta.reportportal.entity.launch.Launch) Autowired(org.springframework.beans.factory.annotation.Autowired) MessageBus(com.epam.ta.reportportal.core.events.MessageBus) StartLaunchEvent(com.epam.reportportal.extension.event.StartLaunchEvent) RerunHandler(com.epam.ta.reportportal.core.launch.rerun.RerunHandler) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) StartLaunchRQ(com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ) LaunchRepository(com.epam.ta.reportportal.dao.LaunchRepository) LaunchStartedEvent(com.epam.ta.reportportal.core.events.activity.LaunchStartedEvent) LaunchBuilder(com.epam.ta.reportportal.ws.converter.builders.LaunchBuilder) StartLaunchRS(com.epam.ta.reportportal.ws.model.launch.StartLaunchRS) Service(org.springframework.stereotype.Service) TO_ACTIVITY_RESOURCE(com.epam.ta.reportportal.ws.converter.converters.LaunchConverter.TO_ACTIVITY_RESOURCE) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) Optional(java.util.Optional) StartLaunchHandler(com.epam.ta.reportportal.core.launch.StartLaunchHandler) Transactional(org.springframework.transaction.annotation.Transactional) LaunchStartedEvent(com.epam.ta.reportportal.core.events.activity.LaunchStartedEvent) StartLaunchRS(com.epam.ta.reportportal.ws.model.launch.StartLaunchRS) StartLaunchEvent(com.epam.reportportal.extension.event.StartLaunchEvent) Launch(com.epam.ta.reportportal.entity.launch.Launch) LaunchBuilder(com.epam.ta.reportportal.ws.converter.builders.LaunchBuilder) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with StartLaunchRS

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

Example 3 with StartLaunchRS

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

the class StartLaunchHandlerImplTest method startLaunch.

@Test
void startLaunch() {
    final ReportPortalUser rpUser = getRpUser("test", UserRole.ADMINISTRATOR, ProjectRole.PROJECT_MANAGER, 1L);
    StartLaunchRQ startLaunchRQ = new StartLaunchRQ();
    startLaunchRQ.setStartTime(new Date());
    startLaunchRQ.setName("test");
    Launch launch = new Launch();
    launch.setId(1L);
    when(launchRepository.save(any(Launch.class))).then(a -> {
        Launch l = a.getArgument(0);
        l.setId(1L);
        return l;
    }).thenReturn(launch);
    final StartLaunchRS startLaunchRS = startLaunchHandlerImpl.startLaunch(rpUser, extractProjectDetails(rpUser, "test_project"), startLaunchRQ);
    verify(launchRepository, times(1)).refresh(any(Launch.class));
    verify(eventPublisher, times(1)).publishEvent(any());
    assertNotNull(startLaunchRS);
}
Also used : InjectMocks(org.mockito.InjectMocks) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Launch(com.epam.ta.reportportal.entity.launch.Launch) Mock(org.mockito.Mock) Date(java.util.Date) UserRepository(com.epam.ta.reportportal.dao.UserRepository) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) MessageBus(com.epam.ta.reportportal.core.events.MessageBus) RerunHandler(com.epam.ta.reportportal.core.launch.rerun.RerunHandler) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) ProjectRole(com.epam.ta.reportportal.entity.project.ProjectRole) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) StartLaunchRQ(com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) LaunchRepository(com.epam.ta.reportportal.dao.LaunchRepository) StartLaunchRS(com.epam.ta.reportportal.ws.model.launch.StartLaunchRS) UserRole(com.epam.ta.reportportal.entity.user.UserRole) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) Assertions(org.junit.jupiter.api.Assertions) TestProjectExtractor.extractProjectDetails(com.epam.ta.reportportal.util.TestProjectExtractor.extractProjectDetails) Mode(com.epam.ta.reportportal.ws.model.launch.Mode) ReportPortalUserUtil.getRpUser(com.epam.ta.reportportal.ReportPortalUserUtil.getRpUser) StartLaunchRQ(com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ) StartLaunchRS(com.epam.ta.reportportal.ws.model.launch.StartLaunchRS) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) Launch(com.epam.ta.reportportal.entity.launch.Launch) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 4 with StartLaunchRS

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

the class StartLaunchHandlerAsyncImpl method startLaunch.

@Override
public StartLaunchRS startLaunch(ReportPortalUser user, ReportPortalUser.ProjectDetails projectDetails, StartLaunchRQ request) {
    validateRoles(projectDetails, request);
    if (request.getUuid() == null) {
        request.setUuid(UUID.randomUUID().toString());
    }
    amqpTemplate.convertAndSend(EXCHANGE_REPORTING, reportingQueueService.getReportingQueueKey(request.getUuid()), request, message -> {
        Map<String, Object> headers = message.getMessageProperties().getHeaders();
        headers.put(MessageHeaders.REQUEST_TYPE, RequestType.START_LAUNCH);
        headers.put(MessageHeaders.USERNAME, user.getUsername());
        headers.put(MessageHeaders.PROJECT_NAME, projectDetails.getProjectName());
        return message;
    });
    StartLaunchRS response = new StartLaunchRS();
    response.setId(request.getUuid());
    return response;
}
Also used : StartLaunchRS(com.epam.ta.reportportal.ws.model.launch.StartLaunchRS)

Example 5 with StartLaunchRS

use of com.epam.ta.reportportal.ws.model.launch.StartLaunchRS in project agent-java-testNG by reportportal.

the class CallbackReportingIntegrationTest method initMocks.

@BeforeEach
@SuppressWarnings("unchecked")
public void initMocks() {
    ReportPortalClient reportPortalClient = mock(ReportPortalClient.class);
    when(reportPortalClient.startLaunch(any())).thenReturn(Maybe.just(new StartLaunchRS("launchUuid", 1L)));
    Maybe<ItemCreatedRS> suiteMaybe = Maybe.just(new ItemCreatedRS(suitedUuid, suitedUuid));
    when(reportPortalClient.startTestItem(any())).thenReturn(suiteMaybe);
    Maybe<ItemCreatedRS> testClassMaybe = Maybe.just(new ItemCreatedRS(testClassUuid, testClassUuid));
    when(reportPortalClient.startTestItem(eq(suiteMaybe.blockingGet().getId()), any())).thenReturn(testClassMaybe);
    Maybe<ItemCreatedRS> testMethodMaybe = Maybe.just(new ItemCreatedRS(testMethodUuid, testMethodUuid));
    when(reportPortalClient.startTestItem(eq(testClassMaybe.blockingGet().getId()), any())).thenReturn(testMethodMaybe);
    Maybe<OperationCompletionRS> finishResponse = Maybe.just(new OperationCompletionRS("finished"));
    when(reportPortalClient.finishTestItem(eq(testMethodUuid), any())).thenReturn(finishResponse);
    when(reportPortalClient.log(any(List.class))).thenReturn(Maybe.just(new BatchSaveOperatingRS()));
    when(reportPortalClient.log(any(SaveLogRQ.class))).thenReturn(Maybe.just(new EntryCreatedAsyncRS("logId")));
    ListenerParameters params = standardParameters();
    params.setCallbackReportingEnabled(true);
    final ReportPortal reportPortal = ReportPortal.create(reportPortalClient, params);
    CallbackReportingListener.initReportPortal(reportPortal);
}
Also used : StartLaunchRS(com.epam.ta.reportportal.ws.model.launch.StartLaunchRS) SaveLogRQ(com.epam.ta.reportportal.ws.model.log.SaveLogRQ) ListenerParameters(com.epam.reportportal.listeners.ListenerParameters) ReportPortal(com.epam.reportportal.service.ReportPortal) ItemCreatedRS(com.epam.ta.reportportal.ws.model.item.ItemCreatedRS) ReportPortalClient(com.epam.reportportal.service.ReportPortalClient) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

StartLaunchRS (com.epam.ta.reportportal.ws.model.launch.StartLaunchRS)8 ListenerParameters (com.epam.reportportal.listeners.ListenerParameters)5 ReportPortalClient (com.epam.reportportal.service.ReportPortalClient)5 ItemCreatedRS (com.epam.ta.reportportal.ws.model.item.ItemCreatedRS)5 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)4 StartLaunchRQ (com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ)4 Maybe (io.reactivex.Maybe)4 java.util (java.util)4 Collectors (java.util.stream.Collectors)4 Pair (org.apache.commons.lang3.tuple.Pair)4 ArgumentCaptor (org.mockito.ArgumentCaptor)4 ArgumentMatchers (org.mockito.ArgumentMatchers)4 Mockito.when (org.mockito.Mockito.when)4 Answer (org.mockito.stubbing.Answer)4 CommonUtils (com.epam.reportportal.util.test.CommonUtils)3 BatchSaveOperatingRS (com.epam.ta.reportportal.ws.model.BatchSaveOperatingRS)3 SaveLogRQ (com.epam.ta.reportportal.ws.model.log.SaveLogRQ)3 Launch (com.epam.reportportal.service.Launch)2 HttpRequestUtils (com.epam.reportportal.utils.http.HttpRequestUtils)2 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)2