Search in sources :

Example 1 with RESOLUTION_FIXED

use of org.sonar.api.issue.Issue.RESOLUTION_FIXED in project sonarqube by SonarSource.

the class SearchActionTest method returns_hotpots_reviewed_as_fixed_if_status_is_REVIEWED_and_resolution_is_FIXED.

@Test
public void returns_hotpots_reviewed_as_fixed_if_status_is_REVIEWED_and_resolution_is_FIXED() {
    ComponentDto project = dbTester.components().insertPublicProject();
    userSessionRule.registerComponents(project);
    indexPermissions();
    ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
    List<IssueDto> fixedHotspots = insertRandomNumberOfHotspotsOfAllSupportedStatusesAndResolutions(project, file).filter(t -> STATUS_REVIEWED.equals(t.getStatus()) && RESOLUTION_FIXED.equals(t.getResolution())).collect(toList());
    indexIssues();
    SearchWsResponse response = newRequest(project, STATUS_REVIEWED, RESOLUTION_FIXED).executeProtobuf(SearchWsResponse.class);
    assertThat(response.getHotspotsList()).extracting(SearchWsResponse.Hotspot::getKey).containsExactlyInAnyOrder(fixedHotspots.stream().map(IssueDto::getKey).toArray(String[]::new));
}
Also used : Arrays(java.util.Arrays) AsyncIssueIndexing(org.sonar.server.issue.index.AsyncIssueIndexing) SecurityStandards(org.sonar.server.security.SecurityStandards) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Random(java.util.Random) ViewIndexer(org.sonar.server.view.index.ViewIndexer) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) STATUS_CLOSED(org.sonar.api.issue.Issue.STATUS_CLOSED) DbIssues(org.sonar.db.protobuf.DbIssues) WebService(org.sonar.api.server.ws.WebService) Collections.singleton(java.util.Collections.singleton) IssueIndex(org.sonar.server.issue.index.IssueIndex) IssueIteratorFactory(org.sonar.server.issue.index.IssueIteratorFactory) IssueTesting.newIssue(org.sonar.db.issue.IssueTesting.newIssue) Map(java.util.Map) ComponentTesting(org.sonar.db.component.ComponentTesting) DateUtils.formatDateTime(org.sonar.api.utils.DateUtils.formatDateTime) Collectors.toSet(java.util.stream.Collectors.toSet) DbTester(org.sonar.db.DbTester) RuleTesting(org.sonar.db.rule.RuleTesting) PermissionIndexer(org.sonar.server.permission.index.PermissionIndexer) REFERENCE_BRANCH(org.sonar.db.newcodeperiod.NewCodePeriodType.REFERENCE_BRANCH) System2(org.sonar.api.utils.System2) Hotspots(org.sonarqube.ws.Hotspots) Collection(java.util.Collection) Set(java.util.Set) SearchWsResponse(org.sonarqube.ws.Hotspots.SearchWsResponse) Sets(com.google.common.collect.Sets) NotFoundException(org.sonar.server.exceptions.NotFoundException) Collectors.joining(java.util.stream.Collectors.joining) Common(org.sonarqube.ws.Common) STATUS_TO_REVIEW(org.sonar.api.issue.Issue.STATUS_TO_REVIEW) DbClient(org.sonar.db.DbClient) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Stream(java.util.stream.Stream) STATUS_REVIEWED(org.sonar.api.issue.Issue.STATUS_REVIEWED) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) ProjectDto(org.sonar.db.project.ProjectDto) MoreCollectors.uniqueIndex(org.sonar.core.util.stream.MoreCollectors.uniqueIndex) STATUSES(org.sonar.api.issue.Issue.STATUSES) IssueTesting.newCodeReferenceIssue(org.sonar.db.issue.IssueTesting.newCodeReferenceIssue) SQCategory(org.sonar.server.security.SecurityStandards.SQCategory) ComponentTesting.newDirectory(org.sonar.db.component.ComponentTesting.newDirectory) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) BranchDto(org.sonar.db.component.BranchDto) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IssueDto(org.sonar.db.issue.IssueDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) EsTester(org.sonar.server.es.EsTester) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) RunWith(org.junit.runner.RunWith) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) TestSystem2(org.sonar.api.impl.utils.TestSystem2) RuleType(org.sonar.api.rules.RuleType) WebAuthorizationTypeSupport(org.sonar.server.permission.index.WebAuthorizationTypeSupport) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) TextRangeResponseFormatter(org.sonar.server.issue.TextRangeResponseFormatter) SECURITY_HOTSPOT(org.sonar.api.rules.RuleType.SECURITY_HOTSPOT) RESOLUTION_FIXED(org.sonar.api.issue.Issue.RESOLUTION_FIXED) Nullable(javax.annotation.Nullable) ImmutableSet.of(com.google.common.collect.ImmutableSet.of) UserSessionRule(org.sonar.server.tester.UserSessionRule) BranchType(org.sonar.db.component.BranchType) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) USER(org.sonar.api.web.UserRole.USER) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) RESOLUTION_SAFE(org.sonar.api.issue.Issue.RESOLUTION_SAFE) WsActionTester(org.sonar.server.ws.WsActionTester) DbCommons(org.sonar.db.protobuf.DbCommons) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) Component(org.sonarqube.ws.Hotspots.Component) Collectors.toList(java.util.stream.Collectors.toList) Rule(org.junit.Rule) Ordering(com.google.common.collect.Ordering) Issue(org.sonar.api.issue.Issue) IssueIndexSyncProgressChecker(org.sonar.server.issue.index.IssueIndexSyncProgressChecker) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) Comparator(java.util.Comparator) Collections(java.util.Collections) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) ComponentDto(org.sonar.db.component.ComponentDto) IssueDto(org.sonar.db.issue.IssueDto) SearchWsResponse(org.sonarqube.ws.Hotspots.SearchWsResponse) Test(org.junit.Test)

Example 2 with RESOLUTION_FIXED

use of org.sonar.api.issue.Issue.RESOLUTION_FIXED in project sonarqube by SonarSource.

the class IssueUpdaterTest method verify_notification_with_resolution.

@Test
public void verify_notification_with_resolution() {
    UserDto assignee = db.users().insertUser();
    RuleDefinitionDto rule = db.rules().insertIssueRule();
    ComponentDto project = db.components().insertPublicProject();
    ComponentDto file = db.components().insertComponent(newFileDto(project));
    DefaultIssue issue = db.issues().insertIssue(rule, project, file, t -> t.setSeverity(MAJOR).setAssigneeUuid(assignee.getUuid())).toDefaultIssue();
    UserDto changeAuthor = db.users().insertUser();
    IssueChangeContext context = IssueChangeContext.createUser(new Date(), changeAuthor.getUuid());
    issueFieldsSetter.setResolution(issue, RESOLUTION_FIXED, context);
    underTest.saveIssueAndPreloadSearchResponseData(db.getSession(), issue, context, false);
    verify(notificationManager).scheduleForSending(notificationArgumentCaptor.capture());
    IssuesChangesNotification issueChangeNotification = notificationArgumentCaptor.getValue();
    IssuesChangesNotificationBuilder builder = issuesChangesSerializer.from(issueChangeNotification);
    assertThat(builder.getIssues()).hasSize(1);
    ChangedIssue changedIssue = builder.getIssues().iterator().next();
    assertThat(changedIssue.getKey()).isEqualTo(issue.key());
    assertThat(changedIssue.getNewStatus()).isEqualTo(issue.status());
    assertThat(changedIssue.getNewResolution()).contains(RESOLUTION_FIXED);
    assertThat(changedIssue.getAssignee()).contains(userOf(assignee));
    assertThat(changedIssue.getRule()).isEqualTo(ruleOf(rule));
    assertThat(changedIssue.getProject()).isEqualTo(projectOf(project));
    assertThat(builder.getChange()).isEqualTo(new UserChange(issue.updateDate().getTime(), userOf(changeAuthor)));
}
Also used : MAJOR(org.sonar.api.rule.Severity.MAJOR) IssueDto(org.sonar.db.issue.IssueDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) Date(java.util.Date) EsTester(org.sonar.server.es.EsTester) ComponentTesting.newFileDto(org.sonar.db.component.ComponentTesting.newFileDto) RuleStatus(org.sonar.api.rule.RuleStatus) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) IssueFieldsSetter(org.sonar.server.issue.IssueFieldsSetter) WebIssueStorage(org.sonar.server.issue.WebIssueStorage) ArgumentCaptor(org.mockito.ArgumentCaptor) IssueIteratorFactory(org.sonar.server.issue.index.IssueIteratorFactory) BLOCKER(org.sonar.api.rule.Severity.BLOCKER) IssueChangeContext(org.sonar.core.issue.IssueChangeContext) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) NotificationManager(org.sonar.server.notification.NotificationManager) RESOLUTION_FIXED(org.sonar.api.issue.Issue.RESOLUTION_FIXED) DbTester(org.sonar.db.DbTester) BranchType(org.sonar.db.component.BranchType) TestIssueChangePostProcessor(org.sonar.server.issue.TestIssueChangePostProcessor) DefaultIssue(org.sonar.core.issue.DefaultIssue) System2(org.sonar.api.utils.System2) DefaultRuleFinder(org.sonar.server.rule.DefaultRuleFinder) IssuesChangesNotificationBuilderTesting.ruleOf(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.ruleOf) IssuesChangesNotificationBuilderTesting.userOf(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.userOf) Test(org.junit.Test) IssuesChangesNotification(org.sonar.server.issue.notification.IssuesChangesNotification) BRANCH(org.sonar.db.component.BranchType.BRANCH) UserChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange) IssuesChangesNotificationBuilderTesting.projectOf(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.projectOf) SequenceUuidFactory(org.sonar.core.util.SequenceUuidFactory) Mockito.verify(org.mockito.Mockito.verify) DbClient(org.sonar.db.DbClient) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) IssuesChangesNotificationBuilderTesting.projectBranchOf(org.sonar.server.issue.notification.IssuesChangesNotificationBuilderTesting.projectBranchOf) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) IssuesChangesNotificationSerializer(org.sonar.server.issue.notification.IssuesChangesNotificationSerializer) IssuesChangesNotificationBuilder(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder) Mockito.mock(org.mockito.Mockito.mock) UserChange(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.UserChange) IssueChangeContext(org.sonar.core.issue.IssueChangeContext) ChangedIssue(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.ChangedIssue) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) DefaultIssue(org.sonar.core.issue.DefaultIssue) IssuesChangesNotificationBuilder(org.sonar.server.issue.notification.IssuesChangesNotificationBuilder) Date(java.util.Date) IssuesChangesNotification(org.sonar.server.issue.notification.IssuesChangesNotification) Test(org.junit.Test)

Aggregations

Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Rule (org.junit.Rule)2 Test (org.junit.Test)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.verify (org.mockito.Mockito.verify)2 RESOLUTION_FIXED (org.sonar.api.issue.Issue.RESOLUTION_FIXED)2 System2 (org.sonar.api.utils.System2)2 DbClient (org.sonar.db.DbClient)2 DbTester (org.sonar.db.DbTester)2 BranchType (org.sonar.db.component.BranchType)2 ComponentDto (org.sonar.db.component.ComponentDto)2 ComponentTesting.newFileDto (org.sonar.db.component.ComponentTesting.newFileDto)2 IssueDto (org.sonar.db.issue.IssueDto)2 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)2 EsTester (org.sonar.server.es.EsTester)2 IssueIndexer (org.sonar.server.issue.index.IssueIndexer)2 IssueIteratorFactory (org.sonar.server.issue.index.IssueIteratorFactory)2 ImmutableSet.of (com.google.common.collect.ImmutableSet.of)1 Ordering (com.google.common.collect.Ordering)1 Sets (com.google.common.collect.Sets)1