Search in sources :

Example 11 with UpdateTestItemRQ

use of com.epam.ta.reportportal.ws.model.item.UpdateTestItemRQ in project service-api by reportportal.

the class UpdateTestItemHandlerImplTest method updateTestItemUnderNotOwnLaunch.

@Test
void updateTestItemUnderNotOwnLaunch() {
    final ReportPortalUser rpUser = getRpUser("not owner", UserRole.USER, ProjectRole.MEMBER, 1L);
    TestItem item = new TestItem();
    Launch launch = new Launch();
    launch.setId(1L);
    User user = new User();
    user.setId(1L);
    user.setLogin("owner");
    launch.setUserId(2L);
    launch.setProjectId(1L);
    item.setLaunchId(launch.getId());
    when(testItemService.getEffectiveLaunch(item)).thenReturn(launch);
    when(itemRepository.findById(1L)).thenReturn(Optional.of(item));
    final ReportPortalException exception = assertThrows(ReportPortalException.class, () -> handler.updateTestItem(extractProjectDetails(rpUser, "test_project"), 1L, new UpdateTestItemRQ(), rpUser));
    assertEquals("You do not have enough permissions. You are not a launch owner.", exception.getMessage());
}
Also used : ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) User(com.epam.ta.reportportal.entity.user.User) ReportPortalUserUtil.getRpUser(com.epam.ta.reportportal.ReportPortalUserUtil.getRpUser) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) UpdateTestItemRQ(com.epam.ta.reportportal.ws.model.item.UpdateTestItemRQ) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) Launch(com.epam.ta.reportportal.entity.launch.Launch) TestItem(com.epam.ta.reportportal.entity.item.TestItem) Test(org.junit.jupiter.api.Test)

Example 12 with UpdateTestItemRQ

use of com.epam.ta.reportportal.ws.model.item.UpdateTestItemRQ in project service-api by reportportal.

the class UpdateTestItemHandlerImplTest method updateTestItemFromAnotherProject.

@Test
void updateTestItemFromAnotherProject() {
    final ReportPortalUser rpUser = getRpUser("test", UserRole.USER, ProjectRole.MEMBER, 1L);
    TestItem item = new TestItem();
    Launch launch = new Launch();
    launch.setId(1L);
    User user = new User();
    user.setId(1L);
    user.setLogin("owner");
    launch.setUserId(user.getId());
    launch.setProjectId(2L);
    item.setLaunchId(launch.getId());
    when(testItemService.getEffectiveLaunch(item)).thenReturn(launch);
    when(itemRepository.findById(1L)).thenReturn(Optional.of(item));
    final ReportPortalException exception = assertThrows(ReportPortalException.class, () -> handler.updateTestItem(extractProjectDetails(rpUser, "test_project"), 1L, new UpdateTestItemRQ(), rpUser));
    assertEquals("You do not have enough permissions. Launch is not under the specified project.", exception.getMessage());
}
Also used : ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) User(com.epam.ta.reportportal.entity.user.User) ReportPortalUserUtil.getRpUser(com.epam.ta.reportportal.ReportPortalUserUtil.getRpUser) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) UpdateTestItemRQ(com.epam.ta.reportportal.ws.model.item.UpdateTestItemRQ) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) Launch(com.epam.ta.reportportal.entity.launch.Launch) TestItem(com.epam.ta.reportportal.entity.item.TestItem) Test(org.junit.jupiter.api.Test)

Example 13 with UpdateTestItemRQ

use of com.epam.ta.reportportal.ws.model.item.UpdateTestItemRQ in project service-api by reportportal.

the class UpdateTestItemHandlerImplTest method updateTestItemUnderNotExistedLaunch.

@Test
void updateTestItemUnderNotExistedLaunch() {
    final ReportPortalUser rpUser = getRpUser("test", UserRole.USER, ProjectRole.PROJECT_MANAGER, 1L);
    TestItem testItem = new TestItem();
    testItem.setLaunchId(2L);
    when(itemRepository.findById(1L)).thenReturn(Optional.of(testItem));
    when(testItemService.getEffectiveLaunch(testItem)).thenThrow(new ReportPortalException(ErrorType.LAUNCH_NOT_FOUND));
    final ReportPortalException exception = assertThrows(ReportPortalException.class, () -> handler.updateTestItem(extractProjectDetails(rpUser, "test_project"), 1L, new UpdateTestItemRQ(), rpUser));
    assertEquals("Launch '' not found. Did you use correct Launch ID?", exception.getMessage());
}
Also used : ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) UpdateTestItemRQ(com.epam.ta.reportportal.ws.model.item.UpdateTestItemRQ) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) TestItem(com.epam.ta.reportportal.entity.item.TestItem) Test(org.junit.jupiter.api.Test)

Example 14 with UpdateTestItemRQ

use of com.epam.ta.reportportal.ws.model.item.UpdateTestItemRQ in project service-api by reportportal.

the class UpdateTestItemHandlerImplTest method shouldCreateInitialStatusAttribute.

@Test
void shouldCreateInitialStatusAttribute() {
    ReportPortalUser user = getRpUser("user", UserRole.ADMINISTRATOR, ProjectRole.PROJECT_MANAGER, 1L);
    UpdateTestItemRQ rq = new UpdateTestItemRQ();
    rq.setStatus("PASSED");
    long itemId = 1L;
    TestItem item = new TestItem();
    item.setItemId(itemId);
    item.setHasChildren(false);
    item.setType(TestItemTypeEnum.STEP);
    TestItemResults itemResults = new TestItemResults();
    itemResults.setStatus(StatusEnum.FAILED);
    item.setItemResults(itemResults);
    Launch launch = new Launch();
    launch.setId(2L);
    item.setLaunchId(launch.getId());
    when(testItemService.getEffectiveLaunch(item)).thenReturn(launch);
    when(itemRepository.findById(itemId)).thenReturn(Optional.of(item));
    doNothing().when(messageBus).publishActivity(any());
    when(statusChangingStrategyMapping.get(StatusEnum.PASSED)).thenReturn(statusChangingStrategy);
    doNothing().when(statusChangingStrategy).changeStatus(item, StatusEnum.PASSED, user);
    handler.updateTestItem(extractProjectDetails(user, "test_project"), itemId, rq, user);
    assertTrue(item.getAttributes().stream().anyMatch(attribute -> INITIAL_STATUS_ATTRIBUTE_KEY.equalsIgnoreCase(attribute.getKey()) && StatusEnum.FAILED.getExecutionCounterField().equalsIgnoreCase("failed")));
}
Also used : TestItemTypeEnum(com.epam.ta.reportportal.entity.enums.TestItemTypeEnum) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) StatusEnum(com.epam.ta.reportportal.entity.enums.StatusEnum) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS) TestItemService(com.epam.ta.reportportal.core.item.TestItemService) TestItem(com.epam.ta.reportportal.entity.item.TestItem) INITIAL_STATUS_ATTRIBUTE_KEY(com.epam.ta.reportportal.core.item.impl.UpdateTestItemHandlerImpl.INITIAL_STATUS_ATTRIBUTE_KEY) Mock(org.mockito.Mock) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) DefineIssueRQ(com.epam.ta.reportportal.ws.model.issue.DefineIssueRQ) MessageBus(com.epam.ta.reportportal.core.events.MessageBus) StatusChangingStrategy(com.epam.ta.reportportal.core.item.impl.status.StatusChangingStrategy) ItemAttribute(com.epam.ta.reportportal.entity.ItemAttribute) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) UpdateTestItemRQ(com.epam.ta.reportportal.ws.model.item.UpdateTestItemRQ) UserRole(com.epam.ta.reportportal.entity.user.UserRole) Map(java.util.Map) TestProjectExtractor.extractProjectDetails(com.epam.ta.reportportal.util.TestProjectExtractor.extractProjectDetails) TestItemRepository(com.epam.ta.reportportal.dao.TestItemRepository) InjectMocks(org.mockito.InjectMocks) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Launch(com.epam.ta.reportportal.entity.launch.Launch) User(com.epam.ta.reportportal.entity.user.User) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) ProjectRole(com.epam.ta.reportportal.entity.project.ProjectRole) ProjectRepository(com.epam.ta.reportportal.dao.ProjectRepository) TestItemResults(com.epam.ta.reportportal.entity.item.TestItemResults) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) ReportPortalUserUtil.getRpUser(com.epam.ta.reportportal.ReportPortalUserUtil.getRpUser) UpdateTestItemRQ(com.epam.ta.reportportal.ws.model.item.UpdateTestItemRQ) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) TestItemResults(com.epam.ta.reportportal.entity.item.TestItemResults) Launch(com.epam.ta.reportportal.entity.launch.Launch) TestItem(com.epam.ta.reportportal.entity.item.TestItem) Test(org.junit.jupiter.api.Test)

Example 15 with UpdateTestItemRQ

use of com.epam.ta.reportportal.ws.model.item.UpdateTestItemRQ in project service-api by reportportal.

the class UpdateTestItemHandlerImplTest method updateNotExistedTestItem.

@Test
void updateNotExistedTestItem() {
    final ReportPortalUser rpUser = getRpUser("test", UserRole.USER, ProjectRole.PROJECT_MANAGER, 1L);
    when(itemRepository.findById(1L)).thenReturn(Optional.empty());
    final ReportPortalException exception = assertThrows(ReportPortalException.class, () -> handler.updateTestItem(extractProjectDetails(rpUser, "test_project"), 1L, new UpdateTestItemRQ(), rpUser));
    assertEquals("Test Item '1' not found. Did you use correct Test Item ID?", exception.getMessage());
}
Also used : ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) UpdateTestItemRQ(com.epam.ta.reportportal.ws.model.item.UpdateTestItemRQ) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) Test(org.junit.jupiter.api.Test)

Aggregations

UpdateTestItemRQ (com.epam.ta.reportportal.ws.model.item.UpdateTestItemRQ)21 Test (org.junit.jupiter.api.Test)20 TestItem (com.epam.ta.reportportal.entity.item.TestItem)18 Launch (com.epam.ta.reportportal.entity.launch.Launch)17 BaseMvcTest (com.epam.ta.reportportal.ws.BaseMvcTest)12 Sql (org.springframework.test.context.jdbc.Sql)10 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)9 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)8 ReportPortalUserUtil.getRpUser (com.epam.ta.reportportal.ReportPortalUserUtil.getRpUser)4 TestItemResults (com.epam.ta.reportportal.entity.item.TestItemResults)4 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)4 MessageBus (com.epam.ta.reportportal.core.events.MessageBus)3 TestItemService (com.epam.ta.reportportal.core.item.TestItemService)3 StatusChangingStrategy (com.epam.ta.reportportal.core.item.impl.status.StatusChangingStrategy)3 ProjectRepository (com.epam.ta.reportportal.dao.ProjectRepository)3 TestItemRepository (com.epam.ta.reportportal.dao.TestItemRepository)3 ItemAttribute (com.epam.ta.reportportal.entity.ItemAttribute)3 StatusEnum (com.epam.ta.reportportal.entity.enums.StatusEnum)3 TestItemTypeEnum (com.epam.ta.reportportal.entity.enums.TestItemTypeEnum)3 ProjectRole (com.epam.ta.reportportal.entity.project.ProjectRole)3