Search in sources :

Example 6 with StartLaunchRQ

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;
}
Also used : StatusEnum(com.epam.ta.reportportal.entity.enums.StatusEnum) TestItem(com.epam.ta.reportportal.entity.item.TestItem) Autowired(org.springframework.beans.factory.annotation.Autowired) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) ItemRetryEvent(com.epam.ta.reportportal.core.events.item.ItemRetryEvent) StringUtils(org.apache.commons.lang3.StringUtils) ParentItemValidator(com.epam.ta.reportportal.core.item.validator.parent.ParentItemValidator) StartTestItemRQ(com.epam.ta.reportportal.ws.model.StartTestItemRQ) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) TestCaseHashGenerator(com.epam.ta.reportportal.core.item.identity.TestCaseHashGenerator) Condition(com.epam.ta.reportportal.commons.querygen.Condition) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) Pair(org.springframework.data.util.Pair) CRITERIA_LAUNCH_ID(com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_LAUNCH_ID) CRITERIA_NAME(com.epam.ta.reportportal.commons.querygen.constant.GeneralCriteriaConstant.CRITERIA_NAME) UniqueIdGenerator(com.epam.ta.reportportal.core.item.identity.UniqueIdGenerator) ItemCreatedRS(com.epam.ta.reportportal.ws.model.item.ItemCreatedRS) TO_LAUNCH_ATTRIBUTE(com.epam.ta.reportportal.ws.converter.converters.ItemAttributeConverter.TO_LAUNCH_ATTRIBUTE) TestCaseIdEntry(com.epam.ta.reportportal.ws.converter.builders.TestCaseIdEntry) TestItemRepository(com.epam.ta.reportportal.dao.TestItemRepository) Launch(com.epam.ta.reportportal.entity.launch.Launch) Optional.ofNullable(java.util.Optional.ofNullable) Filter(com.epam.ta.reportportal.commons.querygen.Filter) LaunchModeEnum(com.epam.ta.reportportal.entity.enums.LaunchModeEnum) IdentityUtil(com.epam.ta.reportportal.core.item.identity.IdentityUtil) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) TestItemBuilder(com.epam.ta.reportportal.ws.converter.builders.TestItemBuilder) RerunSearcher(com.epam.ta.reportportal.core.item.impl.rerun.RerunSearcher) FilterCondition(com.epam.ta.reportportal.commons.querygen.FilterCondition) Collectors(java.util.stream.Collectors) RetryHandler(com.epam.ta.reportportal.core.item.impl.retry.RetryHandler) CRITERIA_PARENT_ID(com.epam.ta.reportportal.commons.querygen.constant.TestItemCriteriaConstant.CRITERIA_PARENT_ID) Objects(java.util.Objects) Component(org.springframework.stereotype.Component) List(java.util.List) StartLaunchRQ(com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ) LaunchRepository(com.epam.ta.reportportal.dao.LaunchRepository) CRITERIA_TEST_CASE_HASH(com.epam.ta.reportportal.commons.querygen.constant.TestItemCriteriaConstant.CRITERIA_TEST_CASE_HASH) Optional(java.util.Optional) Collections(java.util.Collections) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Launch(com.epam.ta.reportportal.entity.launch.Launch)

Example 7 with StartLaunchRQ

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

Example 8 with StartLaunchRQ

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

Example 9 with StartLaunchRQ

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;
}
Also used : StartLaunchRQ(com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ) ItemAttributesRQ(com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ) Date(java.util.Date)

Example 10 with 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());
}
Also used : StartLaunchRQ(com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ) 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)

Aggregations

StartLaunchRQ (com.epam.ta.reportportal.ws.model.launch.StartLaunchRQ)35 Test (org.junit.jupiter.api.Test)20 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)10 ItemAttributesRQ (com.epam.ta.reportportal.ws.model.attribute.ItemAttributesRQ)9 ListenerParameters (com.epam.reportportal.listeners.ListenerParameters)7 Launch (com.epam.ta.reportportal.entity.launch.Launch)7 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)6 BaseMvcTest (com.epam.ta.reportportal.ws.BaseMvcTest)5 LaunchRepository (com.epam.ta.reportportal.dao.LaunchRepository)4 ErrorRS (com.epam.ta.reportportal.ws.model.ErrorRS)4 MvcResult (org.springframework.test.web.servlet.MvcResult)4 LaunchBuilder (com.epam.ta.reportportal.ws.converter.builders.LaunchBuilder)3 Date (java.util.Date)3 ApplicationEventPublisher (org.springframework.context.ApplicationEventPublisher)3 ReportPortal (com.epam.reportportal.service.ReportPortal)2 MessageBus (com.epam.ta.reportportal.core.events.MessageBus)2 IdentityUtil (com.epam.ta.reportportal.core.item.identity.IdentityUtil)2 TestItemRepository (com.epam.ta.reportportal.dao.TestItemRepository)2 TestItem (com.epam.ta.reportportal.entity.item.TestItem)2 ErrorType (com.epam.ta.reportportal.ws.model.ErrorType)2