Search in sources :

Example 1 with MessageBus

use of com.epam.ta.reportportal.core.events.MessageBus 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 2 with MessageBus

use of com.epam.ta.reportportal.core.events.MessageBus 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 3 with MessageBus

use of com.epam.ta.reportportal.core.events.MessageBus in project service-api by reportportal.

the class AnalyzerServiceServiceTest method analyze.

@Test
void analyze() {
    int itemsCount = 2;
    Launch launch = launch();
    List<TestItem> items = testItemsTI(itemsCount);
    items.forEach(item -> item.setLaunchId(launch.getId()));
    AnalyzerConfig analyzerConfig = analyzerConfig();
    final IndexLaunch indexLaunch = new IndexLaunch();
    indexLaunch.setLaunchId(launch.getId());
    indexLaunch.setAnalyzerConfig(analyzerConfig);
    final List<IndexTestItem> indexTestItems = items.stream().map(AnalyzerUtils::fromTestItem).peek(item -> item.setLogs(errorLogs(2))).collect(Collectors.toList());
    indexLaunch.setTestItems(indexTestItems);
    when(testItemRepository.findAllById(anyList())).thenReturn(items);
    when(launchPreparerService.prepare(any(Launch.class), anyList(), any(AnalyzerConfig.class))).thenReturn(Optional.of(indexLaunch));
    when(analyzerServiceClient.analyze(any())).thenReturn(analyzedItems(itemsCount));
    when(issueTypeHandler.defineIssueType(anyLong(), eq("pb001"))).thenReturn(issueProductBug().getIssueType());
    issuesAnalyzer.runAnalyzers(launch, items.stream().map(TestItem::getItemId).collect(Collectors.toList()), analyzerConfig);
    verify(analyzerServiceClient, times(1)).analyze(any());
    verify(testItemRepository, times(itemsCount)).save(any());
    verify(messageBus, times(4)).publishActivity(any());
}
Also used : AnalyzedItemRs(com.epam.ta.reportportal.ws.model.analyzer.AnalyzedItemRs) StatusEnum(com.epam.ta.reportportal.entity.enums.StatusEnum) IssueEntity(com.epam.ta.reportportal.entity.item.issue.IssueEntity) java.util(java.util) Project(com.epam.ta.reportportal.entity.project.Project) IssueTypeHandler(com.epam.ta.reportportal.core.item.impl.IssueTypeHandler) TestItem(com.epam.ta.reportportal.entity.item.TestItem) LogLevel(com.epam.ta.reportportal.entity.enums.LogLevel) IndexLaunch(com.epam.ta.reportportal.ws.model.analyzer.IndexLaunch) IndexTestItem(com.epam.ta.reportportal.ws.model.analyzer.IndexTestItem) MessageBus(com.epam.ta.reportportal.core.events.MessageBus) IssueType(com.epam.ta.reportportal.entity.item.issue.IssueType) TestItemRepository(com.epam.ta.reportportal.dao.TestItemRepository) LaunchPreparerService(com.epam.ta.reportportal.core.analyzer.auto.impl.preparer.LaunchPreparerService) Launch(com.epam.ta.reportportal.entity.launch.Launch) AnalyzerConfig(com.epam.ta.reportportal.ws.model.project.AnalyzerConfig) ALL_LAUNCHES(com.epam.ta.reportportal.entity.AnalyzeMode.ALL_LAUNCHES) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) VerificationModeFactory.times(org.mockito.internal.verification.VerificationModeFactory.times) TestItemResults(com.epam.ta.reportportal.entity.item.TestItemResults) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) PRODUCT_BUG(com.epam.ta.reportportal.entity.enums.TestItemIssueGroup.PRODUCT_BUG) IndexLog(com.epam.ta.reportportal.ws.model.analyzer.IndexLog) AnalyzerServiceClient(com.epam.ta.reportportal.core.analyzer.auto.client.AnalyzerServiceClient) AnalyzerConfig(com.epam.ta.reportportal.ws.model.project.AnalyzerConfig) IndexLaunch(com.epam.ta.reportportal.ws.model.analyzer.IndexLaunch) IndexTestItem(com.epam.ta.reportportal.ws.model.analyzer.IndexTestItem) IndexLaunch(com.epam.ta.reportportal.ws.model.analyzer.IndexLaunch) Launch(com.epam.ta.reportportal.entity.launch.Launch) TestItem(com.epam.ta.reportportal.entity.item.TestItem) IndexTestItem(com.epam.ta.reportportal.ws.model.analyzer.IndexTestItem) Test(org.junit.jupiter.api.Test)

Aggregations

MessageBus (com.epam.ta.reportportal.core.events.MessageBus)3 TestItemRepository (com.epam.ta.reportportal.dao.TestItemRepository)3 StatusEnum (com.epam.ta.reportportal.entity.enums.StatusEnum)3 TestItem (com.epam.ta.reportportal.entity.item.TestItem)3 TestItemResults (com.epam.ta.reportportal.entity.item.TestItemResults)3 Launch (com.epam.ta.reportportal.entity.launch.Launch)3 Test (org.junit.jupiter.api.Test)3 Mockito (org.mockito.Mockito)3 ReportPortalUserUtil.getRpUser (com.epam.ta.reportportal.ReportPortalUserUtil.getRpUser)2 ReportPortalUser (com.epam.ta.reportportal.commons.ReportPortalUser)2 TestItemService (com.epam.ta.reportportal.core.item.TestItemService)2 INITIAL_STATUS_ATTRIBUTE_KEY (com.epam.ta.reportportal.core.item.impl.UpdateTestItemHandlerImpl.INITIAL_STATUS_ATTRIBUTE_KEY)2 StatusChangingStrategy (com.epam.ta.reportportal.core.item.impl.status.StatusChangingStrategy)2 ProjectRepository (com.epam.ta.reportportal.dao.ProjectRepository)2 ItemAttribute (com.epam.ta.reportportal.entity.ItemAttribute)2 TestItemTypeEnum (com.epam.ta.reportportal.entity.enums.TestItemTypeEnum)2 ProjectRole (com.epam.ta.reportportal.entity.project.ProjectRole)2 User (com.epam.ta.reportportal.entity.user.User)2 UserRole (com.epam.ta.reportportal.entity.user.UserRole)2 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)2