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));
}
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());
}
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());
}
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);
}
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.");
}
Aggregations