use of com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ in project service-api by reportportal.
the class RerunHandlerImpl method handleLaunch.
@Override
public Launch handleLaunch(StartLaunchRQ request, Long projectId, ReportPortalUser user) {
Optional<Launch> launchOptional = StringUtils.isEmpty(request.getRerunOf()) ? launchRepository.findLatestByNameAndProjectId(request.getName(), projectId) : launchRepository.findByUuid(request.getRerunOf());
Launch launch = launchOptional.orElseThrow(() -> new ReportPortalException(ErrorType.LAUNCH_NOT_FOUND, ofNullable(request.getRerunOf()).orElse(request.getName())));
ofNullable(request.getMode()).map(it -> LaunchModeEnum.valueOf(it.name())).ifPresent(launch::setMode);
ofNullable(request.getDescription()).ifPresent(launch::setDescription);
launch.setStatus(StatusEnum.IN_PROGRESS);
ofNullable(request.getAttributes()).map(it -> it.stream().map(attr -> TO_LAUNCH_ATTRIBUTE.apply(attr, launch)).collect(Collectors.toSet())).ifPresent(launch::setAttributes);
ofNullable(request.getUuid()).ifPresent(launch::setUuid);
launch.setRerun(true);
return launch;
}
use of com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ in project service-api by reportportal.
the class LaunchAsyncControllerTest method startLaunch.
@Test
void startLaunch() {
ReportPortalUser user = getRpUser("test", UserRole.ADMINISTRATOR, ProjectRole.PROJECT_MANAGER, 1L);
StartLaunchRQ startLaunchRQ = new StartLaunchRQ();
ArgumentCaptor<ReportPortalUser> userArgumentCaptor = ArgumentCaptor.forClass(ReportPortalUser.class);
ArgumentCaptor<ReportPortalUser.ProjectDetails> projectDetailsArgumentCaptor = ArgumentCaptor.forClass(ReportPortalUser.ProjectDetails.class);
ArgumentCaptor<StartLaunchRQ> requestArgumentCaptor = ArgumentCaptor.forClass(StartLaunchRQ.class);
when(projectExtractor.extractProjectDetails(any(ReportPortalUser.class), anyString())).thenReturn(user.getProjectDetails().get("test_project"));
launchAsyncController.startLaunch("test_project", startLaunchRQ, user);
verify(startLaunchHandler).startLaunch(userArgumentCaptor.capture(), projectDetailsArgumentCaptor.capture(), requestArgumentCaptor.capture());
assertEquals(user, userArgumentCaptor.getValue());
assertEquals(user.getProjectDetails().get("test_project"), projectDetailsArgumentCaptor.getValue());
assertEquals(startLaunchRQ, requestArgumentCaptor.getValue());
}
use of com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ in project service-api by reportportal.
the class LaunchControllerTest method happyCreateLaunch.
@Test
void happyCreateLaunch() throws Exception {
String name = "some launch name";
StartLaunchRQ startLaunchRQ = new StartLaunchRQ();
startLaunchRQ.setDescription("some description");
startLaunchRQ.setName(name);
startLaunchRQ.setStartTime(new Date());
startLaunchRQ.setMode(DEFAULT);
startLaunchRQ.setAttributes(Sets.newHashSet(new ItemAttributesRQ("key", "value")));
mockMvc.perform(post(DEFAULT_PROJECT_BASE_URL + "/launch/").with(token(oAuthHelper.getDefaultToken())).content(objectMapper.writeValueAsBytes(startLaunchRQ)).contentType(APPLICATION_JSON)).andExpect(status().isCreated());
}
use of com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ in project service-api by reportportal.
the class LaunchControllerValidationTest method prepareLaunch.
private StartLaunchRQ prepareLaunch() {
StartLaunchRQ startLaunchRQ = new StartLaunchRQ();
startLaunchRQ.setDescription("some description");
startLaunchRQ.setStartTime(new Date());
startLaunchRQ.setMode(DEFAULT);
startLaunchRQ.setAttributes(Sets.newHashSet(new ItemAttributesRQ("key", "value")));
return startLaunchRQ;
}
use of com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ in project service-api by reportportal.
the class LaunchControllerValidationTest method createLaunchShouldReturnErrorWhenNameIsNull.
@Test
public void createLaunchShouldReturnErrorWhenNameIsNull() throws Exception {
// GIVEN
StartLaunchRQ startLaunchRQ = prepareLaunch();
// WHEN
MvcResult mvcResult = mockMvc.perform(post(DEFAULT_PROJECT_BASE_URL + LAUNCH_PATH).with(token(oAuthHelper.getDefaultToken())).content(objectMapper.writeValueAsBytes(startLaunchRQ)).contentType(APPLICATION_JSON)).andExpect(status().isBadRequest()).andReturn();
// THEN
ErrorRS error = objectMapper.readValue(mvcResult.getResponse().getContentAsString(), ErrorRS.class);
assertEquals(INCORRECT_REQUEST, error.getErrorType());
assertEquals(INCORRECT_REQUEST_MESSAGE + FIELD_NAME_IS_NULL_MESSAGE, error.getMessage());
}
Aggregations