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());
}
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());
}
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());
}
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")));
}
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());
}
Aggregations