Search in sources :

Example 1 with DefectTypeDeletedEvent

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

the class DefectTypeDeletedHandlerTest method successfullyReindex.

@Test
void successfullyReindex() {
    long projectId = 2L;
    when(projectRepository.findById(projectId)).thenReturn(Optional.of(getProjectWithAnalyzerAttributes(projectId)));
    when(analyzerServiceClient.hasClients()).thenReturn(true);
    when(analyzerStatusCache.getAnalyzeStatus(AnalyzerStatusCache.AUTO_ANALYZER_KEY)).thenReturn(Optional.of(CacheBuilder.newBuilder().build()));
    List<Long> launchIds = Arrays.asList(1L, 2L, 3L);
    handler.handleDefectTypeDeleted(new DefectTypeDeletedEvent(new IssueTypeActivityResource(), 1L, "user", projectId));
    verify(logIndexer, times(1)).index(eq(projectId), any(AnalyzerConfig.class));
}
Also used : DefectTypeDeletedEvent(com.epam.ta.reportportal.core.events.activity.DefectTypeDeletedEvent) AnalyzerConfig(com.epam.ta.reportportal.ws.model.project.AnalyzerConfig) IssueTypeActivityResource(com.epam.ta.reportportal.ws.model.activity.IssueTypeActivityResource) Test(org.junit.jupiter.api.Test)

Example 2 with DefectTypeDeletedEvent

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

the class DefectTypeDeletedHandlerTest method deleteSubTypeOnNotExistProject.

@Test
void deleteSubTypeOnNotExistProject() {
    long projectId = 2L;
    when(projectRepository.findById(projectId)).thenReturn(Optional.empty());
    ReportPortalException exception = assertThrows(ReportPortalException.class, () -> handler.handleDefectTypeDeleted(new DefectTypeDeletedEvent(new IssueTypeActivityResource(), 1L, "user", projectId)));
    assertEquals("Project '2' not found. Did you use correct project name?", exception.getMessage());
}
Also used : DefectTypeDeletedEvent(com.epam.ta.reportportal.core.events.activity.DefectTypeDeletedEvent) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) IssueTypeActivityResource(com.epam.ta.reportportal.ws.model.activity.IssueTypeActivityResource) Test(org.junit.jupiter.api.Test)

Example 3 with DefectTypeDeletedEvent

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

the class DefectTypeDeletedHandlerTest method analysisAlreadyRunningTest.

@Test
void analysisAlreadyRunningTest() {
    long projectId = 2L;
    when(projectRepository.findById(projectId)).thenReturn(Optional.of(new Project()));
    when(analyzerServiceClient.hasClients()).thenReturn(true);
    Cache<Long, Long> cache = CacheBuilder.newBuilder().build();
    cache.put(2L, projectId);
    when(analyzerStatusCache.getAnalyzeStatus(AnalyzerStatusCache.AUTO_ANALYZER_KEY)).thenReturn(Optional.of(cache));
    ReportPortalException exception = assertThrows(ReportPortalException.class, () -> handler.handleDefectTypeDeleted(new DefectTypeDeletedEvent(new IssueTypeActivityResource(), 1L, "user", projectId)));
    assertEquals("Forbidden operation. Index can not be removed until auto-analysis proceeds.", exception.getMessage());
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) DefectTypeDeletedEvent(com.epam.ta.reportportal.core.events.activity.DefectTypeDeletedEvent) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) IssueTypeActivityResource(com.epam.ta.reportportal.ws.model.activity.IssueTypeActivityResource) Test(org.junit.jupiter.api.Test)

Example 4 with DefectTypeDeletedEvent

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

the class DefectTypeDeletedHandlerTest method noClientsTest.

@Test
void noClientsTest() {
    long projectId = 2L;
    when(projectRepository.findById(projectId)).thenReturn(Optional.of(new Project()));
    when(analyzerServiceClient.hasClients()).thenReturn(false);
    handler.handleDefectTypeDeleted(new DefectTypeDeletedEvent(new IssueTypeActivityResource(), 1L, "user", projectId));
    verifyZeroInteractions(logIndexer);
}
Also used : Project(com.epam.ta.reportportal.entity.project.Project) DefectTypeDeletedEvent(com.epam.ta.reportportal.core.events.activity.DefectTypeDeletedEvent) IssueTypeActivityResource(com.epam.ta.reportportal.ws.model.activity.IssueTypeActivityResource) Test(org.junit.jupiter.api.Test)

Example 5 with DefectTypeDeletedEvent

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

the class DeleteProjectSettingsHandlerImpl method deleteProjectIssueSubType.

@Override
public OperationCompletionRS deleteProjectIssueSubType(String projectName, ReportPortalUser user, Long id) {
    Project project = projectRepository.findByName(projectName).orElseThrow(() -> new ReportPortalException(PROJECT_NOT_FOUND, projectName));
    ProjectIssueType type = project.getProjectIssueTypes().stream().filter(projectIssueType -> projectIssueType.getIssueType().getId().equals(id)).findFirst().orElseThrow(() -> new ReportPortalException(ISSUE_TYPE_NOT_FOUND, id));
    expect(type.getIssueType().getLocator(), not(in(Sets.newHashSet(AUTOMATION_BUG.getLocator(), PRODUCT_BUG.getLocator(), SYSTEM_ISSUE.getLocator(), NO_DEFECT.getLocator(), TO_INVESTIGATE.getLocator())))).verify(FORBIDDEN_OPERATION, "You cannot remove predefined global issue types.");
    String issueField = "statistics$defects$" + TestItemIssueGroup.fromValue(type.getIssueType().getIssueGroup().getTestItemIssueGroup().getValue()).orElseThrow(() -> new ReportPortalException(ISSUE_TYPE_NOT_FOUND, type.getIssueType().getIssueGroup())).getValue().toLowerCase() + "$" + type.getIssueType().getLocator();
    statisticsFieldRepository.deleteByName(issueField);
    IssueType defaultGroupIssueType = issueTypeRepository.findByLocator(type.getIssueType().getIssueGroup().getTestItemIssueGroup().getLocator()).orElseThrow(() -> new ReportPortalException(ErrorType.ISSUE_TYPE_NOT_FOUND, type.getIssueType()));
    List<IssueEntity> allByIssueTypeId = issueEntityRepository.findAllByIssueTypeId(id);
    allByIssueTypeId.forEach(issueEntity -> issueEntity.setIssueType(defaultGroupIssueType));
    project.getProjectIssueTypes().remove(type);
    projectRepository.save(project);
    issueTypeRepository.delete(type.getIssueType());
    updateWidgets(project, type.getIssueType());
    DefectTypeDeletedEvent defectTypeDeletedEvent = new DefectTypeDeletedEvent(TO_ACTIVITY_RESOURCE.apply(type.getIssueType()), user.getUserId(), user.getUsername(), project.getId());
    messageBus.publishActivity(defectTypeDeletedEvent);
    eventPublisher.publishEvent(defectTypeDeletedEvent);
    return new OperationCompletionRS("Issue sub-type delete operation completed successfully.");
}
Also used : ProjectIssueType(com.epam.ta.reportportal.entity.project.ProjectIssueType) Project(com.epam.ta.reportportal.entity.project.Project) DefectTypeDeletedEvent(com.epam.ta.reportportal.core.events.activity.DefectTypeDeletedEvent) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) IssueType(com.epam.ta.reportportal.entity.item.issue.IssueType) ProjectIssueType(com.epam.ta.reportportal.entity.project.ProjectIssueType) IssueEntity(com.epam.ta.reportportal.entity.item.issue.IssueEntity) OperationCompletionRS(com.epam.ta.reportportal.ws.model.OperationCompletionRS)

Aggregations

DefectTypeDeletedEvent (com.epam.ta.reportportal.core.events.activity.DefectTypeDeletedEvent)5 IssueTypeActivityResource (com.epam.ta.reportportal.ws.model.activity.IssueTypeActivityResource)4 Test (org.junit.jupiter.api.Test)4 Project (com.epam.ta.reportportal.entity.project.Project)3 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)3 IssueEntity (com.epam.ta.reportportal.entity.item.issue.IssueEntity)1 IssueType (com.epam.ta.reportportal.entity.item.issue.IssueType)1 ProjectIssueType (com.epam.ta.reportportal.entity.project.ProjectIssueType)1 OperationCompletionRS (com.epam.ta.reportportal.ws.model.OperationCompletionRS)1 AnalyzerConfig (com.epam.ta.reportportal.ws.model.project.AnalyzerConfig)1