use of com.epam.ta.reportportal.core.item.impl.status.StatusChangingStrategy 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.core.item.impl.status.StatusChangingStrategy 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.core.item.impl.status.StatusChangingStrategy in project service-api by reportportal.
the class FinishTestItemHandlerImpl method updateFinishedItem.
private void updateFinishedItem(TestItemResults testItemResults, StatusEnum actualStatus, Optional<IssueEntity> resolvedIssue, TestItem testItem, ReportPortalUser user, Long projectId) {
resolvedIssue.ifPresent(issue -> deleteOldIssueIndex(actualStatus, testItem, testItemResults, projectId));
if (testItemResults.getStatus() != actualStatus) {
TestItemActivityResource before = TO_ACTIVITY_RESOURCE.apply(testItem, projectId);
Optional<StatusChangingStrategy> statusChangingStrategy = ofNullable(statusChangingStrategyMapping.get(actualStatus));
if (statusChangingStrategy.isPresent()) {
statusChangingStrategy.get().changeStatus(testItem, actualStatus, user);
} else {
testItemResults.setStatus(actualStatus);
}
publishUpdateActivity(before, TO_ACTIVITY_RESOURCE.apply(testItem, projectId), user);
}
resolvedIssue.ifPresent(issue -> {
updateItemIssue(testItemResults, issue);
if (ITEM_CAN_BE_INDEXED.test(testItem)) {
eventPublisher.publishEvent(new ItemFinishedEvent(testItem.getItemId(), testItem.getLaunchId(), projectId));
}
});
}
use of com.epam.ta.reportportal.core.item.impl.status.StatusChangingStrategy in project service-api by reportportal.
the class UpdateTestItemHandlerImpl method updateTestItem.
@Override
public OperationCompletionRS updateTestItem(ReportPortalUser.ProjectDetails projectDetails, Long itemId, UpdateTestItemRQ rq, ReportPortalUser user) {
TestItem testItem = testItemRepository.findById(itemId).orElseThrow(() -> new ReportPortalException(ErrorType.TEST_ITEM_NOT_FOUND, itemId));
validate(projectDetails, user, testItem);
Optional<StatusEnum> providedStatus = StatusEnum.fromValue(rq.getStatus());
if (providedStatus.isPresent() && !providedStatus.get().equals(testItem.getItemResults().getStatus())) {
expect(testItem.isHasChildren() && !testItem.getType().sameLevel(TestItemTypeEnum.STEP), equalTo(FALSE)).verify(INCORRECT_REQUEST, "Unable to change status on test item with children");
checkInitialStatusAttribute(testItem, rq);
StatusChangingStrategy strategy = statusChangingStrategyMapping.get(providedStatus.get());
expect(strategy, notNull()).verify(INCORRECT_REQUEST, formattedSupplier("Actual status: '{}' cannot be changed to '{}'.", testItem.getItemResults().getStatus(), providedStatus.get()));
TestItemActivityResource before = TO_ACTIVITY_RESOURCE.apply(testItem, projectDetails.getProjectId());
strategy.changeStatus(testItem, providedStatus.get(), user);
messageBus.publishActivity(new TestItemStatusChangedEvent(before, TO_ACTIVITY_RESOURCE.apply(testItem, projectDetails.getProjectId()), user.getUserId(), user.getUsername()));
}
testItem = new TestItemBuilder(testItem).overwriteAttributes(rq.getAttributes()).addDescription(rq.getDescription()).get();
testItemRepository.save(testItem);
return COMPOSE_UPDATE_RESPONSE.apply(itemId);
}
Aggregations