use of com.epam.ta.reportportal.ws.model.item.UpdateTestItemRQ in project service-api by reportportal.
the class TestItemControllerTest method changeStatusFromInterruptedToSkipped.
@Sql("/db/test-item/item-change-status-from-interrupted.sql")
@Test
void changeStatusFromInterruptedToSkipped() throws Exception {
UpdateTestItemRQ request = new UpdateTestItemRQ();
request.setStatus("skipped");
mockMvc.perform(put(SUPERADMIN_PROJECT_BASE_URL + "/item/6/update").with(token(oAuthHelper.getSuperadminToken())).contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(request))).andExpect(status().isOk());
Optional<TestItem> updatedItem = testItemRepository.findById(6L);
assertTrue(updatedItem.isPresent());
assertEquals(StatusEnum.SKIPPED, updatedItem.get().getItemResults().getStatus());
assertEquals(TestItemIssueGroup.TO_INVESTIGATE, updatedItem.get().getItemResults().getIssue().getIssueType().getIssueGroup().getTestItemIssueGroup());
assertEquals(StatusEnum.FAILED, testItemRepository.findById(updatedItem.get().getParentId()).get().getItemResults().getStatus());
Launch launch = launchRepository.findById(updatedItem.get().getLaunchId()).get();
assertEquals(StatusEnum.FAILED, launch.getStatus());
verify(messageBus, times(1)).publishActivity(ArgumentMatchers.any());
}
use of com.epam.ta.reportportal.ws.model.item.UpdateTestItemRQ in project service-api by reportportal.
the class UpdateTestItemHandlerImplTest method shouldNotCreateInitialStatusAttribute.
@Test
void shouldNotCreateInitialStatusAttribute() {
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);
item.setAttributes(Sets.newHashSet(new ItemAttribute(INITIAL_STATUS_ATTRIBUTE_KEY, "passed", true)));
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.PASSED.getExecutionCounterField().equalsIgnoreCase("passed")));
}
use of com.epam.ta.reportportal.ws.model.item.UpdateTestItemRQ in project service-api by reportportal.
the class UpdateTestItemHandlerImplTest method changeNotStepItemStatus.
@Test
void changeNotStepItemStatus() {
ReportPortalUser user = getRpUser("user", UserRole.ADMINISTRATOR, ProjectRole.PROJECT_MANAGER, 1L);
UpdateTestItemRQ rq = new UpdateTestItemRQ();
rq.setStatus("FAILED");
long itemId = 1L;
TestItem item = new TestItem();
item.setItemId(itemId);
item.setHasChildren(true);
item.setType(TestItemTypeEnum.TEST);
TestItemResults itemResults = new TestItemResults();
itemResults.setStatus(StatusEnum.PASSED);
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));
ReportPortalException exception = assertThrows(ReportPortalException.class, () -> handler.updateTestItem(extractProjectDetails(user, "test_project"), itemId, rq, user));
assertEquals("Incorrect Request. Unable to change status on test item with children", exception.getMessage());
}
use of com.epam.ta.reportportal.ws.model.item.UpdateTestItemRQ in project service-api by reportportal.
the class UpdateTestItemHandlerImplTest method updateItemPositive.
@Test
void updateItemPositive() {
ReportPortalUser user = getRpUser("user", UserRole.ADMINISTRATOR, ProjectRole.PROJECT_MANAGER, 1L);
UpdateTestItemRQ rq = new UpdateTestItemRQ();
rq.setDescription("new description");
long itemId = 1L;
TestItem item = new TestItem();
item.setItemId(itemId);
item.setDescription("old description");
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));
OperationCompletionRS response = handler.updateTestItem(extractProjectDetails(user, "test_project"), itemId, rq, user);
assertEquals("TestItem with ID = '1' successfully updated.", response.getResultMessage());
assertEquals(rq.getDescription(), item.getDescription());
}
use of com.epam.ta.reportportal.ws.model.item.UpdateTestItemRQ in project service-api by reportportal.
the class UpdateTestItemHandlerImpl method checkInitialStatusAttribute.
private void checkInitialStatusAttribute(TestItem item, UpdateTestItemRQ request) {
Runnable addInitialStatusAttribute = () -> {
ItemAttribute initialStatusAttribute = new ItemAttribute(INITIAL_STATUS_ATTRIBUTE_KEY, item.getItemResults().getStatus().getExecutionCounterField(), true);
initialStatusAttribute.setTestItem(item);
item.getAttributes().add(initialStatusAttribute);
};
Consumer<ItemAttribute> removeManuallyStatusAttributeIfSameAsInitial = statusAttribute -> extractAttributeResource(request.getAttributes(), MANUALLY_CHANGED_STATUS_ATTRIBUTE_KEY).filter(it -> it.getValue().equalsIgnoreCase(statusAttribute.getValue())).ifPresent(it -> request.getAttributes().remove(it));
extractAttribute(item.getAttributes(), INITIAL_STATUS_ATTRIBUTE_KEY).ifPresentOrElse(removeManuallyStatusAttributeIfSameAsInitial, addInitialStatusAttribute);
}
Aggregations