Search in sources :

Example 1 with LaunchFinishedEvent

use of com.epam.ta.reportportal.core.events.activity.LaunchFinishedEvent in project service-api by reportportal.

the class StopLaunchHandlerImpl method stopLaunch.

@Override
public OperationCompletionRS stopLaunch(Long launchId, FinishExecutionRQ finishLaunchRQ, ReportPortalUser.ProjectDetails projectDetails, ReportPortalUser user) {
    Launch launch = launchRepository.findById(launchId).orElseThrow(() -> new ReportPortalException(ErrorType.LAUNCH_NOT_FOUND, launchId));
    validateRoles(launch, user, projectDetails);
    validate(launch, finishLaunchRQ);
    launch = new LaunchBuilder(launch).addDescription(ofNullable(finishLaunchRQ.getDescription()).orElse(ofNullable(launch.getDescription()).orElse("")).concat(LAUNCH_STOP_DESCRIPTION)).addStatus(ofNullable(finishLaunchRQ.getStatus()).orElse(STOPPED.name())).addEndTime(ofNullable(finishLaunchRQ.getEndTime()).orElse(new Date())).addAttributes(finishLaunchRQ.getAttributes()).addAttribute(new ItemAttributeResource("status", "stopped")).get();
    launchRepository.save(launch);
    testItemRepository.interruptInProgressItems(launch.getId());
    messageBus.publishActivity(new LaunchFinishForcedEvent(TO_ACTIVITY_RESOURCE.apply(launch), user.getUserId(), user.getUsername()));
    eventPublisher.publishEvent(new LaunchFinishedEvent(TO_ACTIVITY_RESOURCE.apply(launch), user.getUserId(), user.getUsername()));
    return new OperationCompletionRS("Launch with ID = '" + launchId + "' successfully stopped.");
}
Also used : ItemAttributeResource(com.epam.ta.reportportal.ws.model.attribute.ItemAttributeResource) LaunchFinishForcedEvent(com.epam.ta.reportportal.core.events.activity.LaunchFinishForcedEvent) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) LaunchFinishedEvent(com.epam.ta.reportportal.core.events.activity.LaunchFinishedEvent) Launch(com.epam.ta.reportportal.entity.launch.Launch) Date(java.util.Date) LaunchBuilder(com.epam.ta.reportportal.ws.converter.builders.LaunchBuilder) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Example 2 with LaunchFinishedEvent

use of com.epam.ta.reportportal.core.events.activity.LaunchFinishedEvent in project service-api by reportportal.

the class LaunchFinishedEventHandlerTest method shouldNotSendWhenLaunchInDebug.

@Test
void shouldNotSendWhenLaunchInDebug() {
    LaunchActivityResource resource = new LaunchActivityResource();
    resource.setId(1L);
    resource.setName("name");
    resource.setProjectId(1L);
    LaunchFinishedEvent event = new LaunchFinishedEvent(resource, 1L, "user");
    Optional<Launch> launch = LaunchTestUtil.getLaunch(StatusEnum.FAILED, LaunchModeEnum.DEBUG);
    when(launchRepository.findById(event.getLaunchActivityResource().getId())).thenReturn(launch);
    launchFinishedEventHandler.onApplicationEvent(event);
    verify(projectRepository, times(0)).findById(launch.get().getId());
}
Also used : LaunchActivityResource(com.epam.ta.reportportal.ws.model.activity.LaunchActivityResource) LaunchFinishedEvent(com.epam.ta.reportportal.core.events.activity.LaunchFinishedEvent) Launch(com.epam.ta.reportportal.entity.launch.Launch) Test(org.junit.jupiter.api.Test)

Example 3 with LaunchFinishedEvent

use of com.epam.ta.reportportal.core.events.activity.LaunchFinishedEvent in project service-api by reportportal.

the class LaunchAutoAnalysisSubscriberTest method shouldAnalyzeWhenEnabled.

@Test
void shouldAnalyzeWhenEnabled() {
    LaunchActivityResource resource = new LaunchActivityResource();
    resource.setId(1L);
    resource.setName("name");
    resource.setProjectId(1L);
    LaunchFinishedEvent event = new LaunchFinishedEvent(resource, 1L, "user");
    Optional<Launch> launch = LaunchTestUtil.getLaunch(StatusEnum.FAILED, LaunchModeEnum.DEFAULT);
    Map<ProjectAttributeEnum, String> mapping = ImmutableMap.<ProjectAttributeEnum, String>builder().put(ProjectAttributeEnum.AUTO_ANALYZER_ENABLED, "true").build();
    Project project = new Project();
    project.setId(1L);
    project.setProjectAttributes(LaunchFinishedTestUtils.getProjectAttributes(mapping));
    when(analyzerServiceAsync.hasAnalyzers()).thenReturn(true);
    when(analyzeCollectorFactory.getCollector(AnalyzeItemsMode.TO_INVESTIGATE)).thenReturn(analyzeItemsCollector);
    when(analyzeItemsCollector.collectItems(any(), any(), any())).thenReturn(Lists.newArrayList(1L, 2L));
    when(logIndexer.indexLaunchLogs(any(), any(), any())).thenReturn(indexed);
    when(analyzerServiceAsync.analyze(any(), any(), any())).thenReturn(analyzed);
    doNothing().when(eventPublisher).publishEvent(any());
    autoAnalysisSubscriber.handleEvent(event, project, launch.get());
    verify(logIndexer, times(1)).indexLaunchLogs(any(), any(), any());
    verify(analyzerServiceAsync, times(1)).analyze(any(), any(), any());
    verify(eventPublisher, times(1)).publishEvent(any());
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) LaunchActivityResource(com.epam.ta.reportportal.ws.model.activity.LaunchActivityResource) LaunchFinishedEvent(com.epam.ta.reportportal.core.events.activity.LaunchFinishedEvent) ProjectAttributeEnum(com.epam.ta.reportportal.entity.enums.ProjectAttributeEnum) Launch(com.epam.ta.reportportal.entity.launch.Launch) Test(org.junit.jupiter.api.Test)

Example 4 with LaunchFinishedEvent

use of com.epam.ta.reportportal.core.events.activity.LaunchFinishedEvent in project service-api by reportportal.

the class LaunchAutoAnalysisSubscriberTest method shouldNotAnalyzeWhenDisabled.

@Test
void shouldNotAnalyzeWhenDisabled() {
    LaunchActivityResource resource = new LaunchActivityResource();
    resource.setId(1L);
    resource.setName("name");
    resource.setProjectId(1L);
    LaunchFinishedEvent event = new LaunchFinishedEvent(resource, 1L, "user");
    Optional<Launch> launch = LaunchTestUtil.getLaunch(StatusEnum.FAILED, LaunchModeEnum.DEFAULT);
    Map<ProjectAttributeEnum, String> mapping = ImmutableMap.<ProjectAttributeEnum, String>builder().put(ProjectAttributeEnum.AUTO_ANALYZER_ENABLED, "false").build();
    Project project = new Project();
    project.setId(1L);
    project.setProjectAttributes(LaunchFinishedTestUtils.getProjectAttributes(mapping));
    autoAnalysisSubscriber.handleEvent(event, project, launch.get());
    verify(analyzerServiceAsync, times(0)).analyze(any(), any(), any());
    verify(logIndexer, times(1)).indexLaunchLogs(any(), any(), any());
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) LaunchActivityResource(com.epam.ta.reportportal.ws.model.activity.LaunchActivityResource) LaunchFinishedEvent(com.epam.ta.reportportal.core.events.activity.LaunchFinishedEvent) ProjectAttributeEnum(com.epam.ta.reportportal.entity.enums.ProjectAttributeEnum) Launch(com.epam.ta.reportportal.entity.launch.Launch) Test(org.junit.jupiter.api.Test)

Example 5 with LaunchFinishedEvent

use of com.epam.ta.reportportal.core.events.activity.LaunchFinishedEvent in project service-api by reportportal.

the class LaunchNotificationSubscriberTest method shouldSendWhenNotificationsEnabled.

@Test
void shouldSendWhenNotificationsEnabled() {
    LaunchActivityResource resource = new LaunchActivityResource();
    resource.setId(1L);
    resource.setName("name");
    resource.setProjectId(1L);
    LaunchFinishedEvent event = new LaunchFinishedEvent(resource, 1L, "user");
    Optional<Launch> launch = LaunchTestUtil.getLaunch(StatusEnum.FAILED, LaunchModeEnum.DEFAULT);
    launch.get().setName("name1");
    Map<ProjectAttributeEnum, String> mapping = ImmutableMap.<ProjectAttributeEnum, String>builder().put(ProjectAttributeEnum.NOTIFICATIONS_ENABLED, "true").put(ProjectAttributeEnum.AUTO_ANALYZER_ENABLED, "true").build();
    Project project = new Project();
    project.setId(1L);
    project.setProjectAttributes(LaunchFinishedTestUtils.getProjectAttributes(mapping));
    project.setSenderCases(LaunchFinishedTestUtils.getSenderCases());
    when(getIntegrationHandler.getEnabledByProjectIdOrGlobalAndIntegrationGroup(project.getId(), IntegrationGroupEnum.NOTIFICATION)).thenReturn(Optional.ofNullable(emailIntegration));
    when(userRepository.findLoginById(any())).thenReturn(Optional.of("owner"));
    when(mailServiceFactory.getDefaultEmailService(emailIntegration)).thenReturn(Optional.ofNullable(emailService));
    launchNotificationSubscriber.handleEvent(event, project, launch.get());
    verify(emailService, times(2)).sendLaunchFinishNotification(any(), any(), any(), any());
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) LaunchActivityResource(com.epam.ta.reportportal.ws.model.activity.LaunchActivityResource) LaunchFinishedEvent(com.epam.ta.reportportal.core.events.activity.LaunchFinishedEvent) ProjectAttributeEnum(com.epam.ta.reportportal.entity.enums.ProjectAttributeEnum) Launch(com.epam.ta.reportportal.entity.launch.Launch) Test(org.junit.jupiter.api.Test)

Aggregations

LaunchFinishedEvent (com.epam.ta.reportportal.core.events.activity.LaunchFinishedEvent)11 Launch (com.epam.ta.reportportal.entity.launch.Launch)10 LaunchActivityResource (com.epam.ta.reportportal.ws.model.activity.LaunchActivityResource)9 Test (org.junit.jupiter.api.Test)8 ProjectAttributeEnum (com.epam.ta.reportportal.entity.enums.ProjectAttributeEnum)7 Project (com.epam.ta.reportportal.entity.project.Project)7 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)2 LaunchBuilder (com.epam.ta.reportportal.ws.converter.builders.LaunchBuilder)2 LaunchFinishForcedEvent (com.epam.ta.reportportal.core.events.activity.LaunchFinishForcedEvent)1 StatusEnum (com.epam.ta.reportportal.entity.enums.StatusEnum)1 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)1 ItemAttributeResource (com.epam.ta.reportportal.ws.model.attribute.ItemAttributeResource)1 FinishLaunchRS (com.epam.ta.reportportal.ws.model.launch.FinishLaunchRS)1 Date (java.util.Date)1