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.");
}
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());
}
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());
}
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());
}
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());
}
Aggregations