Search in sources :

Example 1 with FinishLaunchRS

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

the class FinishLaunchHandlerAsyncImpl method finishLaunch.

@Override
public FinishLaunchRS finishLaunch(String launchId, FinishExecutionRQ request, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user, String baseUrl) {
    // todo: may be problem - no access to repository, so no possibility to validateRoles() here
    amqpTemplate.convertAndSend(EXCHANGE_REPORTING, reportingQueueService.getReportingQueueKey(launchId), request, message -> {
        Map<String, Object> headers = message.getMessageProperties().getHeaders();
        headers.put(MessageHeaders.REQUEST_TYPE, RequestType.FINISH_LAUNCH);
        headers.put(MessageHeaders.USERNAME, user.getUsername());
        headers.put(MessageHeaders.PROJECT_NAME, projectDetails.getProjectName());
        headers.put(MessageHeaders.LAUNCH_ID, launchId);
        headers.put(MessageHeaders.BASE_URL, baseUrl);
        return message;
    });
    FinishLaunchRS response = new FinishLaunchRS();
    response.setId(launchId);
    return response;
}
Also used : FinishLaunchRS(com.epam.ta.reportportal.ws.model.launch.FinishLaunchRS)

Example 2 with FinishLaunchRS

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

the class FinishLaunchHandlerImplTest method finishLaunchWithLink.

@Test
void finishLaunchWithLink() {
    FinishExecutionRQ finishExecutionRQ = new FinishExecutionRQ();
    finishExecutionRQ.setEndTime(Date.from(LocalDateTime.now().atZone(ZoneId.of("UTC")).toInstant()));
    ReportPortalUser rpUser = getRpUser("test", UserRole.ADMINISTRATOR, ProjectRole.PROJECT_MANAGER, 1L);
    when(launchRepository.findByUuid("1")).thenReturn(getLaunch(StatusEnum.IN_PROGRESS, LaunchModeEnum.DEFAULT));
    final FinishLaunchRS finishLaunchRS = handler.finishLaunch("1", finishExecutionRQ, extractProjectDetails(rpUser, "test_project"), rpUser, "http://example.com");
    verify(finishHierarchyHandler, times(1)).finishDescendants(any(), any(), any(), any(), any());
    assertNotNull(finishLaunchRS);
    assertEquals("http://example.com/ui/#test_project/launches/all/1", finishLaunchRS.getLink());
}
Also used : ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) FinishExecutionRQ(com.epam.ta.reportportal.ws.model.FinishExecutionRQ) FinishLaunchRS(com.epam.ta.reportportal.ws.model.launch.FinishLaunchRS) Test(org.junit.jupiter.api.Test)

Example 3 with FinishLaunchRS

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

the class FinishLaunchHandlerImplTest method finishLaunch.

@Test
void finishLaunch() {
    FinishExecutionRQ finishExecutionRQ = new FinishExecutionRQ();
    finishExecutionRQ.setEndTime(Date.from(LocalDateTime.now().atZone(ZoneId.of("UTC")).toInstant()));
    ReportPortalUser rpUser = getRpUser("test", UserRole.ADMINISTRATOR, ProjectRole.PROJECT_MANAGER, 1L);
    when(launchRepository.findByUuid("1")).thenReturn(getLaunch(StatusEnum.IN_PROGRESS, LaunchModeEnum.DEFAULT));
    FinishLaunchRS response = handler.finishLaunch("1", finishExecutionRQ, extractProjectDetails(rpUser, "test_project"), rpUser, null);
    verify(finishHierarchyHandler, times(1)).finishDescendants(any(), any(), any(), any(), any());
    assertNotNull(response);
}
Also used : ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) FinishExecutionRQ(com.epam.ta.reportportal.ws.model.FinishExecutionRQ) FinishLaunchRS(com.epam.ta.reportportal.ws.model.launch.FinishLaunchRS) Test(org.junit.jupiter.api.Test)

Example 4 with FinishLaunchRS

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

the class FinishLaunchHandlerImpl method finishLaunch.

@Override
public FinishLaunchRS finishLaunch(String launchId, FinishExecutionRQ finishLaunchRQ, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user, String baseUrl) {
    Launch launch = launchRepository.findByUuid(launchId).orElseThrow(() -> new ReportPortalException(LAUNCH_NOT_FOUND, launchId));
    validateRoles(launch, user, projectDetails);
    validate(launch, finishLaunchRQ);
    Optional<StatusEnum> status = StatusEnum.fromValue(finishLaunchRQ.getStatus());
    Long id = launch.getId();
    final int finishedCount = finishHierarchyHandler.finishDescendants(launch, status.orElse(StatusEnum.INTERRUPTED), finishLaunchRQ.getEndTime(), user, projectDetails);
    if (finishedCount > 0) {
        launch.setStatus(launchRepository.hasRootItemsWithStatusNotEqual(id, StatusEnum.PASSED.name(), StatusEnum.INFO.name(), StatusEnum.WARN.name()) ? FAILED : PASSED);
    } else {
        launch.setStatus(status.orElseGet(() -> launchRepository.hasRootItemsWithStatusNotEqual(id, StatusEnum.PASSED.name(), StatusEnum.INFO.name(), StatusEnum.WARN.name()) ? FAILED : PASSED));
    }
    launch = new LaunchBuilder(launch).addDescription(buildDescription(launch.getDescription(), finishLaunchRQ.getDescription())).addAttributes(finishLaunchRQ.getAttributes()).addEndTime(finishLaunchRQ.getEndTime()).get();
    LaunchFinishedEvent event = new LaunchFinishedEvent(TO_ACTIVITY_RESOURCE.apply(launch), user, baseUrl);
    messageBus.publishActivity(event);
    eventPublisher.publishEvent(event);
    FinishLaunchRS response = new FinishLaunchRS();
    response.setId(launch.getUuid());
    response.setNumber(launch.getNumber());
    response.setLink(generateLaunchLink(baseUrl, projectDetails.getProjectName(), String.valueOf(launch.getId())));
    return response;
}
Also used : StatusEnum(com.epam.ta.reportportal.entity.enums.StatusEnum) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) LaunchFinishedEvent(com.epam.ta.reportportal.core.events.activity.LaunchFinishedEvent) Launch(com.epam.ta.reportportal.entity.launch.Launch) FinishLaunchRS(com.epam.ta.reportportal.ws.model.launch.FinishLaunchRS) LaunchBuilder(com.epam.ta.reportportal.ws.converter.builders.LaunchBuilder)

Aggregations

FinishLaunchRS (com.epam.ta.reportportal.ws.model.launch.FinishLaunchRS)4 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)2 FinishExecutionRQ (com.epam.ta.reportportal.ws.model.FinishExecutionRQ)2 Test (org.junit.jupiter.api.Test)2 LaunchFinishedEvent (com.epam.ta.reportportal.core.events.activity.LaunchFinishedEvent)1 StatusEnum (com.epam.ta.reportportal.entity.enums.StatusEnum)1 Launch (com.epam.ta.reportportal.entity.launch.Launch)1 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)1 LaunchBuilder (com.epam.ta.reportportal.ws.converter.builders.LaunchBuilder)1