Search in sources :

Example 6 with UpdateTestItemRQ

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());
}
Also used : UpdateTestItemRQ(com.epam.ta.reportportal.ws.model.item.UpdateTestItemRQ) Launch(com.epam.ta.reportportal.entity.launch.Launch) TestItem(com.epam.ta.reportportal.entity.item.TestItem) BaseMvcTest(com.epam.ta.reportportal.ws.BaseMvcTest) Test(org.junit.jupiter.api.Test) Sql(org.springframework.test.context.jdbc.Sql)

Example 7 with UpdateTestItemRQ

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")));
}
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) ItemAttribute(com.epam.ta.reportportal.entity.ItemAttribute) 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 8 with UpdateTestItemRQ

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());
}
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) 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 9 with UpdateTestItemRQ

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

Example 10 with UpdateTestItemRQ

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);
}
Also used : StatusEnum(com.epam.ta.reportportal.entity.enums.StatusEnum) IssueEntity(com.epam.ta.reportportal.entity.item.issue.IssueEntity) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS) TestItemService(com.epam.ta.reportportal.core.item.TestItemService) LogIndexerService(com.epam.ta.reportportal.core.analyzer.auto.impl.LogIndexerService) Autowired(org.springframework.beans.factory.annotation.Autowired) DefineIssueRQ(com.epam.ta.reportportal.ws.model.issue.DefineIssueRQ) UnlinkExternalIssueRQ(com.epam.ta.reportportal.ws.model.item.UnlinkExternalIssueRQ) MessageBus(com.epam.ta.reportportal.core.events.MessageBus) StringUtils(org.apache.commons.lang3.StringUtils) ItemAttribute(com.epam.ta.reportportal.entity.ItemAttribute) Predicates(com.epam.ta.reportportal.commons.Predicates) TestItemRepository(com.epam.ta.reportportal.dao.TestItemRepository) Suppliers.formattedSupplier(com.epam.ta.reportportal.commons.validation.Suppliers.formattedSupplier) TestItemActivityResource(com.epam.ta.reportportal.ws.model.activity.TestItemActivityResource) Launch(com.epam.ta.reportportal.entity.launch.Launch) TestItemStatusChangedEvent(com.epam.ta.reportportal.core.events.activity.TestItemStatusChangedEvent) Predicate(java.util.function.Predicate) BusinessRule.expect(com.epam.ta.reportportal.commons.validation.BusinessRule.expect) IssueConverter(com.epam.ta.reportportal.ws.converter.converters.IssueConverter) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) TestItemBuilder(com.epam.ta.reportportal.ws.converter.builders.TestItemBuilder) Collectors(java.util.stream.Collectors) LinkExternalIssueRQ(com.epam.ta.reportportal.ws.model.item.LinkExternalIssueRQ) AnalyzerUtils(com.epam.ta.reportportal.core.analyzer.auto.impl.AnalyzerUtils) ProjectRole(com.epam.ta.reportportal.entity.project.ProjectRole) Stream(java.util.stream.Stream) ITEM_CAN_BE_INDEXED(com.epam.ta.reportportal.util.Predicates.ITEM_CAN_BE_INDEXED) IssueEntityRepository(com.epam.ta.reportportal.dao.IssueEntityRepository) BusinessRuleViolationException(com.epam.ta.reportportal.commons.validation.BusinessRuleViolationException) UpdateTestItemHandler(com.epam.ta.reportportal.core.item.UpdateTestItemHandler) ItemInfoUtils.extractAttributeResource(com.epam.ta.reportportal.util.ItemInfoUtils.extractAttributeResource) TRUE(java.lang.Boolean.TRUE) TestItemTypeEnum(com.epam.ta.reportportal.entity.enums.TestItemTypeEnum) java.util(java.util) Project(com.epam.ta.reportportal.entity.project.Project) Issue(com.epam.ta.reportportal.ws.model.issue.Issue) TestItem(com.epam.ta.reportportal.entity.item.TestItem) ItemInfoUtils.extractAttribute(com.epam.ta.reportportal.util.ItemInfoUtils.extractAttribute) BulkInfoUpdateRQ(com.epam.ta.reportportal.ws.model.BulkInfoUpdateRQ) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) StatusChangingStrategy(com.epam.ta.reportportal.core.item.impl.status.StatusChangingStrategy) Function(java.util.function.Function) ExternalTicketHandler(com.epam.ta.reportportal.core.item.ExternalTicketHandler) ItemIssueTypeDefinedEvent(com.epam.ta.reportportal.core.events.activity.ItemIssueTypeDefinedEvent) ReportPortalUser(com.epam.ta.reportportal.commons.ReportPortalUser) CollectionUtils(org.apache.commons.collections.CollectionUtils) UpdateTestItemRQ(com.epam.ta.reportportal.ws.model.item.UpdateTestItemRQ) Service(org.springframework.stereotype.Service) UserRole(com.epam.ta.reportportal.entity.user.UserRole) IssueDefinition(com.epam.ta.reportportal.ws.model.issue.IssueDefinition) IssueType(com.epam.ta.reportportal.entity.item.issue.IssueType) ActivityAction(com.epam.ta.reportportal.entity.activity.ActivityAction) FALSE(java.lang.Boolean.FALSE) ExternalIssueRQ(com.epam.ta.reportportal.ws.model.item.ExternalIssueRQ) TestItemIssueGroup(com.epam.ta.reportportal.entity.enums.TestItemIssueGroup) TO_ACTIVITY_RESOURCE(com.epam.ta.reportportal.ws.converter.converters.TestItemConverter.TO_ACTIVITY_RESOURCE) Consumer(java.util.function.Consumer) Collectors.toList(java.util.stream.Collectors.toList) IssueEntityBuilder(com.epam.ta.reportportal.ws.converter.builders.IssueEntityBuilder) ProjectRepository(com.epam.ta.reportportal.dao.ProjectRepository) LinkTicketEvent(com.epam.ta.reportportal.core.events.activity.LinkTicketEvent) ItemAttributeConverter(com.epam.ta.reportportal.ws.converter.converters.ItemAttributeConverter) ItemInfoUtils(com.epam.ta.reportportal.util.ItemInfoUtils) ItemAttribute(com.epam.ta.reportportal.entity.ItemAttribute)

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