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