use of com.epam.ta.reportportal.ws.model.launch.MergeLaunchesRQ in project service-api by reportportal.
the class LaunchControllerTest method mergeLaunchesPositive.
@Test
void mergeLaunchesPositive() throws Exception {
MergeLaunchesRQ rq = new MergeLaunchesRQ();
HashSet<Long> set = new HashSet<>();
set.add(1L);
set.add(2L);
rq.setLaunches(set);
rq.setName("Merged");
rq.setMergeStrategyType("BASIC");
rq.setStartTime(new Date());
rq.setEndTime(new Date());
mockMvc.perform(post(DEFAULT_PROJECT_BASE_URL + "/launch/merge").contentType(APPLICATION_JSON).with(token(oAuthHelper.getDefaultToken())).content(objectMapper.writeValueAsBytes(rq))).andExpect(status().is(200));
}
use of com.epam.ta.reportportal.ws.model.launch.MergeLaunchesRQ in project service-api by reportportal.
the class LaunchControllerValidationTest method mergeLaunchShouldReturnErrorWhenNameIsEmpty.
@Test
public void mergeLaunchShouldReturnErrorWhenNameIsEmpty() throws Exception {
// GIVEN
MergeLaunchesRQ mergeLaunchesRQ = prepareLaunchesMerge();
mergeLaunchesRQ.setName(EMPTY);
// WHEN
MvcResult mvcResult = mockMvc.perform(post(DEFAULT_PROJECT_BASE_URL + LAUNCH_PATH + MERGE_PATH).with(token(oAuthHelper.getDefaultToken())).content(objectMapper.writeValueAsBytes(mergeLaunchesRQ)).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_BLANK_MESSAGE + " " + FIELD_NAME_SIZE_MESSAGE + "] ", error.getMessage());
}
use of com.epam.ta.reportportal.ws.model.launch.MergeLaunchesRQ in project service-api by reportportal.
the class LaunchControllerValidationTest method mergeLaunchShouldReturnErrorWhenNameIsGreaterThanTwoHundredAndFiftySixCharacters.
@Test
public void mergeLaunchShouldReturnErrorWhenNameIsGreaterThanTwoHundredAndFiftySixCharacters() throws Exception {
// GIVEN
MergeLaunchesRQ mergeLaunchesRQ = prepareLaunchesMerge();
mergeLaunchesRQ.setName(LONG_NAME_VALUE);
// WHEN
MvcResult mvcResult = mockMvc.perform(post(DEFAULT_PROJECT_BASE_URL + LAUNCH_PATH + MERGE_PATH).with(token(oAuthHelper.getDefaultToken())).content(objectMapper.writeValueAsBytes(mergeLaunchesRQ)).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_SIZE_MESSAGE + "] ", error.getMessage());
}
use of com.epam.ta.reportportal.ws.model.launch.MergeLaunchesRQ in project service-api by reportportal.
the class LaunchControllerValidationTest method mergeLaunchShouldReturnErrorWhenNameConsistsOfWhitespaces.
@Test
public void mergeLaunchShouldReturnErrorWhenNameConsistsOfWhitespaces() throws Exception {
// GIVEN
MergeLaunchesRQ mergeLaunchesRQ = prepareLaunchesMerge();
mergeLaunchesRQ.setName(WHITESPACES_NAME_VALUE);
// WHEN
MvcResult mvcResult = mockMvc.perform(post(DEFAULT_PROJECT_BASE_URL + LAUNCH_PATH + MERGE_PATH).with(token(oAuthHelper.getDefaultToken())).content(objectMapper.writeValueAsBytes(mergeLaunchesRQ)).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_BLANK_MESSAGE + " " + FIELD_NAME_SIZE_MESSAGE + "] ", error.getMessage());
}
use of com.epam.ta.reportportal.ws.model.launch.MergeLaunchesRQ in project service-api by reportportal.
the class AbstractLaunchMergeStrategy method createResultedLaunch.
/**
* Create launch that will be the result of merge
*
* @param projectId {@link Project#getId()}
* @param userId {@link ReportPortalUser#getUserId()}
* @param mergeLaunchesRQ {@link MergeLaunchesRQ}
* @param launches {@link List} of the {@link Launch}
* @return launch
*/
private Launch createResultedLaunch(Long projectId, Long userId, MergeLaunchesRQ mergeLaunchesRQ, List<Launch> launches) {
Date startTime = ofNullable(mergeLaunchesRQ.getStartTime()).orElse(EntityUtils.TO_DATE.apply(launches.stream().min(Comparator.comparing(Launch::getStartTime)).orElseThrow(() -> new ReportPortalException(ErrorType.BAD_REQUEST_ERROR, "Invalid launches")).getStartTime()));
Date endTime = ofNullable(mergeLaunchesRQ.getEndTime()).orElse(EntityUtils.TO_DATE.apply(launches.stream().max(Comparator.comparing(Launch::getEndTime)).orElseThrow(() -> new ReportPortalException(ErrorType.BAD_REQUEST_ERROR, "Invalid launches")).getEndTime()));
expect(endTime, time -> !time.before(startTime)).verify(FINISH_TIME_EARLIER_THAN_START_TIME, TO_LOCAL_DATE_TIME.apply(endTime), startTime, projectId);
StartLaunchRQ startRQ = new StartLaunchRQ();
startRQ.setMode(ofNullable(mergeLaunchesRQ.getMode()).orElse(Mode.DEFAULT));
startRQ.setDescription(ofNullable(mergeLaunchesRQ.getDescription()).orElse(launches.stream().map(Launch::getDescription).collect(joining("\n\n"))));
startRQ.setName(ofNullable(mergeLaunchesRQ.getName()).orElse("Merged: " + launches.stream().map(Launch::getName).distinct().collect(joining(", "))));
startRQ.setStartTime(startTime);
Launch launch = new LaunchBuilder().addStartRQ(startRQ).addProject(projectId).addStatus(IN_PROGRESS.name()).addUserId(userId).addEndTime(endTime).get();
launch.setHasRetries(launches.stream().anyMatch(Launch::isHasRetries));
launchRepository.save(launch);
launchRepository.refresh(launch);
mergeAttributes(mergeLaunchesRQ.getAttributes(), launches, launch);
return launch;
}
Aggregations