Search in sources :

Example 1 with MergeLaunchesRQ

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));
}
Also used : MergeLaunchesRQ(com.epam.ta.reportportal.ws.model.launch.MergeLaunchesRQ) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test)

Example 2 with MergeLaunchesRQ

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());
}
Also used : MergeLaunchesRQ(com.epam.ta.reportportal.ws.model.launch.MergeLaunchesRQ) ErrorRS(com.epam.ta.reportportal.ws.model.ErrorRS) MvcResult(org.springframework.test.web.servlet.MvcResult) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test)

Example 3 with MergeLaunchesRQ

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());
}
Also used : MergeLaunchesRQ(com.epam.ta.reportportal.ws.model.launch.MergeLaunchesRQ) ErrorRS(com.epam.ta.reportportal.ws.model.ErrorRS) MvcResult(org.springframework.test.web.servlet.MvcResult) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test)

Example 4 with MergeLaunchesRQ

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());
}
Also used : MergeLaunchesRQ(com.epam.ta.reportportal.ws.model.launch.MergeLaunchesRQ) ErrorRS(com.epam.ta.reportportal.ws.model.ErrorRS) MvcResult(org.springframework.test.web.servlet.MvcResult) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test)

Example 5 with MergeLaunchesRQ

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;
}
Also used : TestItemTypeEnum(com.epam.ta.reportportal.entity.enums.TestItemTypeEnum) java.util(java.util) TestItemUniqueIdGenerator(com.epam.ta.reportportal.core.item.identity.TestItemUniqueIdGenerator) Project(com.epam.ta.reportportal.entity.project.Project) TestItem(com.epam.ta.reportportal.entity.item.TestItem) TO_LOCAL_DATE_TIME(com.epam.ta.reportportal.commons.EntityUtils.TO_LOCAL_DATE_TIME) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) Supplier(java.util.function.Supplier) ItemAttribute(com.epam.ta.reportportal.entity.ItemAttribute) ItemAttributeResource(com.epam.ta.reportportal.ws.model.attribute.ItemAttributeResource) EntityUtils(com.epam.ta.reportportal.commons.EntityUtils) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) LaunchBuilder(com.epam.ta.reportportal.ws.converter.builders.LaunchBuilder) LogRepository(com.epam.ta.reportportal.dao.LogRepository) TestItemRepository(com.epam.ta.reportportal.dao.TestItemRepository) MergeLaunchesRQ(com.epam.ta.reportportal.ws.model.launch.MergeLaunchesRQ) Launch(com.epam.ta.reportportal.entity.launch.Launch) AttachmentRepository(com.epam.ta.reportportal.dao.AttachmentRepository) BusinessRule.expect(com.epam.ta.reportportal.commons.validation.BusinessRule.expect) Optional.ofNullable(java.util.Optional.ofNullable) IdentityUtil(com.epam.ta.reportportal.core.item.identity.IdentityUtil) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Collectors.joining(java.util.stream.Collectors.joining) Collectors.toList(java.util.stream.Collectors.toList) StartLaunchRQ(com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ) FINISH_TIME_EARLIER_THAN_START_TIME(com.epam.ta.reportportal.ws.model.ErrorType.FINISH_TIME_EARLIER_THAN_START_TIME) LaunchRepository(com.epam.ta.reportportal.dao.LaunchRepository) FROM_RESOURCE(com.epam.ta.reportportal.ws.converter.converters.ItemAttributeConverter.FROM_RESOURCE) Suppliers(com.epam.ta.reportportal.commons.validation.Suppliers) Mode(com.epam.ta.reportportal.ws.model.launch.Mode) IN_PROGRESS(com.epam.ta.reportportal.entity.enums.StatusEnum.IN_PROGRESS) LaunchMergeStrategy(com.epam.ta.reportportal.core.item.merge.LaunchMergeStrategy) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) StartLaunchRQ(com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ) Launch(com.epam.ta.reportportal.entity.launch.Launch) LaunchBuilder(com.epam.ta.reportportal.ws.converter.builders.LaunchBuilder)

Aggregations

MergeLaunchesRQ (com.epam.ta.reportportal.ws.model.launch.MergeLaunchesRQ)8 Test (org.junit.jupiter.api.Test)6 BaseMvcTest (com.epam.ta.reportportal.ws.BaseMvcTest)5 ErrorRS (com.epam.ta.reportportal.ws.model.ErrorRS)4 MvcResult (org.springframework.test.web.servlet.MvcResult)4 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)2 EntityUtils (com.epam.ta.reportportal.commons.EntityUtils)1 TO_LOCAL_DATE_TIME (com.epam.ta.reportportal.commons.EntityUtils.TO_LOCAL_DATE_TIME)1 BusinessRule.expect (com.epam.ta.reportportal.commons.validation.BusinessRule.expect)1 Suppliers (com.epam.ta.reportportal.commons.validation.Suppliers)1 IdentityUtil (com.epam.ta.reportportal.core.item.identity.IdentityUtil)1 TestItemUniqueIdGenerator (com.epam.ta.reportportal.core.item.identity.TestItemUniqueIdGenerator)1 LaunchMergeStrategy (com.epam.ta.reportportal.core.item.merge.LaunchMergeStrategy)1 AttachmentRepository (com.epam.ta.reportportal.dao.AttachmentRepository)1 LaunchRepository (com.epam.ta.reportportal.dao.LaunchRepository)1 LogRepository (com.epam.ta.reportportal.dao.LogRepository)1 TestItemRepository (com.epam.ta.reportportal.dao.TestItemRepository)1 ItemAttribute (com.epam.ta.reportportal.entity.ItemAttribute)1 IN_PROGRESS (com.epam.ta.reportportal.entity.enums.StatusEnum.IN_PROGRESS)1 TestItemTypeEnum (com.epam.ta.reportportal.entity.enums.TestItemTypeEnum)1