Search in sources :

Example 1 with BLOCKER

use of org.sonar.api.rule.Severity.BLOCKER in project sonarqube by SonarSource.

the class IssueUpdaterTest method verify_notification_on_branch.

@Test
public void verify_notification_on_branch() {
    RuleDefinitionDto rule = db.rules().insertIssueRule();
    ComponentDto project = db.components().insertPublicProject();
    ComponentDto branch = db.components().insertProjectBranch(project, t -> t.setBranchType(BRANCH));
    ComponentDto file = db.components().insertComponent(newFileDto(branch));
    DefaultIssue issue = db.issues().insertIssue(rule, branch, file, t -> t.setSeverity(MAJOR)).toDefaultIssue();
    UserDto changeAuthor = db.users().insertUser();
    IssueChangeContext context = IssueChangeContext.createUser(new Date(), changeAuthor.getUuid());
    issueFieldsSetter.setSeverity(issue, BLOCKER, 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()).isEmpty();
    assertThat(changedIssue.getAssignee()).isEmpty();
    assertThat(changedIssue.getRule()).isEqualTo(ruleOf(rule));
    assertThat(changedIssue.getProject()).isEqualTo(projectBranchOf(db, branch));
    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)

Example 2 with BLOCKER

use of org.sonar.api.rule.Severity.BLOCKER in project sonarqube by SonarSource.

the class IssueUpdaterTest method verify_no_notification_on_pr.

@Test
public void verify_no_notification_on_pr() {
    RuleDefinitionDto rule = db.rules().insertIssueRule();
    ComponentDto project = db.components().insertPublicProject();
    ComponentDto branch = db.components().insertProjectBranch(project, t -> t.setBranchType(BranchType.PULL_REQUEST));
    ComponentDto file = db.components().insertComponent(newFileDto(branch));
    DefaultIssue issue = db.issues().insertIssue(rule, branch, file, t -> t.setSeverity(MAJOR)).toDefaultIssue();
    IssueChangeContext context = IssueChangeContext.createUser(new Date(), "user_uuid");
    issueFieldsSetter.setSeverity(issue, BLOCKER, context);
    underTest.saveIssueAndPreloadSearchResponseData(db.getSession(), issue, context, false);
    verifyZeroInteractions(notificationManager);
}
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) IssueChangeContext(org.sonar.core.issue.IssueChangeContext) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) DefaultIssue(org.sonar.core.issue.DefaultIssue) Date(java.util.Date) Test(org.junit.Test)

Example 3 with BLOCKER

use of org.sonar.api.rule.Severity.BLOCKER in project sonarqube by SonarSource.

the class SearchActionTest method facet_filtering_when_searching_for_inactive_rules.

/**
 * When the user searches for inactive rules (for example for to "activate more"), then
 * only rules of the quality profiles' language are relevant
 */
@Test
public void facet_filtering_when_searching_for_inactive_rules() {
    QProfileDto profile = db.qualityProfiles().insert(q -> q.setLanguage("language1"));
    // on same language, not activated => match
    RuleDefinitionDto rule1 = db.rules().insert(r -> r.setLanguage(profile.getLanguage()).setRepositoryKey("repositoryKey1").setSystemTags(new HashSet<>(singletonList("tag1"))).setSeverity("CRITICAL").setStatus(RuleStatus.BETA).setType(RuleType.CODE_SMELL));
    // on same language, activated => no match
    RuleDefinitionDto rule2 = db.rules().insert(r -> r.setLanguage(profile.getLanguage()).setRepositoryKey("repositoryKey2").setSystemTags(new HashSet<>(singletonList("tag2"))).setSeverity("MAJOR").setStatus(RuleStatus.DEPRECATED).setType(RuleType.VULNERABILITY));
    RuleActivation activation = RuleActivation.create(rule2.getUuid(), null, null);
    qProfileRules.activateAndCommit(db.getSession(), profile, singleton(activation));
    // on other language, not activated => no match
    RuleDefinitionDto rule3 = db.rules().insert(r -> r.setLanguage("language3").setRepositoryKey("repositoryKey3").setSystemTags(new HashSet<>(singletonList("tag3"))).setSeverity("BLOCKER").setStatus(RuleStatus.READY).setType(RuleType.BUG));
    indexRules();
    indexActiveRules();
    SearchResponse result = ws.newRequest().setParam("facets", "languages,repositories,tags,severities,statuses,types").setParam("activation", "false").setParam("qprofile", profile.getKee()).executeProtobuf(SearchResponse.class);
    assertThat(result.getRulesList()).extracting(Rule::getKey).containsExactlyInAnyOrder(rule1.getKey().toString());
    assertThat(result.getFacets().getFacetsList().stream().filter(f -> "languages".equals(f.getProperty())).findAny().get().getValuesList()).extracting(Common.FacetValue::getVal, Common.FacetValue::getCount).as("Facet languages").containsExactlyInAnyOrder(tuple(rule1.getLanguage(), 1L), // known limitation: irrelevant languages are shown in this case (SONAR-9683)
    tuple(rule3.getLanguage(), 1L));
    assertThat(result.getFacets().getFacetsList().stream().filter(f -> "tags".equals(f.getProperty())).findAny().get().getValuesList()).extracting(Common.FacetValue::getVal, Common.FacetValue::getCount).as("Facet tags").containsExactlyInAnyOrder(tuple(rule1.getSystemTags().iterator().next(), 1L));
    assertThat(result.getFacets().getFacetsList().stream().filter(f -> "repositories".equals(f.getProperty())).findAny().get().getValuesList()).extracting(Common.FacetValue::getVal, Common.FacetValue::getCount).as("Facet repositories").containsExactlyInAnyOrder(tuple(rule1.getRepositoryKey(), 1L));
    assertThat(result.getFacets().getFacetsList().stream().filter(f -> "severities".equals(f.getProperty())).findAny().get().getValuesList()).extracting(Common.FacetValue::getVal, Common.FacetValue::getCount).as("Facet severities").containsExactlyInAnyOrder(tuple("BLOCKER", /* rule2 */
    0L), tuple("CRITICAL", /* rule1 */
    1L), tuple("MAJOR", 0L), tuple("MINOR", 0L), tuple("INFO", 0L));
    assertThat(result.getFacets().getFacetsList().stream().filter(f -> "statuses".equals(f.getProperty())).findAny().get().getValuesList()).extracting(Common.FacetValue::getVal, Common.FacetValue::getCount).as("Facet statuses").containsExactlyInAnyOrder(tuple("READY", /* rule2 */
    0L), tuple("BETA", /* rule1 */
    1L), tuple("DEPRECATED", 0L));
    assertThat(result.getFacets().getFacetsList().stream().filter(f -> "types".equals(f.getProperty())).findAny().get().getValuesList()).extracting(Common.FacetValue::getVal, Common.FacetValue::getCount).as("Facet types").containsExactlyInAnyOrder(tuple("BUG", /* rule2 */
    0L), tuple("CODE_SMELL", /* rule1 */
    1L), tuple("VULNERABILITY", 0L), tuple("SECURITY_HOTSPOT", 0L));
}
Also used : RandomStringUtils.randomAlphanumeric(org.apache.commons.lang.RandomStringUtils.randomAlphanumeric) ActiveRuleIndexer(org.sonar.server.qualityprofile.index.ActiveRuleIndexer) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Collections.singletonList(java.util.Collections.singletonList) Rules(org.sonarqube.ws.Rules) Languages(org.sonar.api.resources.Languages) WebService(org.sonar.api.server.ws.WebService) Collections.singleton(java.util.Collections.singleton) Assertions.entry(org.assertj.guava.api.Assertions.entry) BLOCKER(org.sonar.api.rule.Severity.BLOCKER) Arrays.asList(java.util.Arrays.asList) DebtRemediationFunction(org.sonar.api.server.debt.DebtRemediationFunction) ActiveRuleChange(org.sonar.server.qualityprofile.ActiveRuleChange) RuleTesting.setSystemTags(org.sonar.db.rule.RuleTesting.setSystemTags) RuleIndexer(org.sonar.server.rule.index.RuleIndexer) Mockito.doReturn(org.mockito.Mockito.doReturn) Rule(org.sonarqube.ws.Rules.Rule) DbTester(org.sonar.db.DbTester) QProfileRulesImpl(org.sonar.server.qualityprofile.QProfileRulesImpl) RuleActivation(org.sonar.server.qualityprofile.RuleActivation) System2(org.sonar.api.utils.System2) AlwaysIncreasingSystem2(org.sonar.api.impl.utils.AlwaysIncreasingSystem2) ActiveRuleParamDto(org.sonar.db.qualityprofile.ActiveRuleParamDto) RuleMetadataDto(org.sonar.db.rule.RuleMetadataDto) Collectors(java.util.stream.Collectors) NotFoundException(org.sonar.server.exceptions.NotFoundException) Common(org.sonarqube.ws.Common) QProfileRules(org.sonar.server.qualityprofile.QProfileRules) RuleTesting.setTags(org.sonar.db.rule.RuleTesting.setTags) List(java.util.List) LanguageTesting(org.sonar.server.language.LanguageTesting) RuleKey(org.sonar.api.rule.RuleKey) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) Arrays.stream(java.util.Arrays.stream) Mockito.mock(org.mockito.Mockito.mock) SearchResponse(org.sonarqube.ws.Rules.SearchResponse) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) UserDto(org.sonar.db.user.UserDto) EsTester(org.sonar.server.es.EsTester) RuleActivator(org.sonar.server.qualityprofile.builtin.RuleActivator) RuleStatus(org.sonar.api.rule.RuleStatus) PARAM_ACTIVATION(org.sonar.server.rule.ws.RulesWsParameters.PARAM_ACTIVATION) TypeValidations(org.sonar.server.util.TypeValidations) RuleType(org.sonar.api.rules.RuleType) HashSet(java.util.HashSet) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Extractor(org.assertj.core.api.iterable.Extractor) IntegerTypeValidation(org.sonar.server.util.IntegerTypeValidation) PARAM_COMPARE_TO_PROFILE(org.sonar.server.rule.ws.RulesWsParameters.PARAM_COMPARE_TO_PROFILE) MoreCollectors(org.sonar.core.util.stream.MoreCollectors) Before(org.junit.Before) QualityProfileChangeEventService(org.sonar.server.pushapi.qualityprofile.QualityProfileChangeEventService) UserSessionRule(org.sonar.server.tester.UserSessionRule) Assertions.tuple(org.assertj.core.api.Assertions.tuple) PARAM_QPROFILE(org.sonar.server.rule.ws.RulesWsParameters.PARAM_QPROFILE) MacroInterpreter(org.sonar.server.text.MacroInterpreter) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test) RuleIndex(org.sonar.server.rule.index.RuleIndex) WsActionTester(org.sonar.server.ws.WsActionTester) PARAM_RULE_KEY(org.sonar.server.rule.ws.RulesWsParameters.PARAM_RULE_KEY) Consumer(java.util.function.Consumer) RuleParamDto(org.sonar.db.rule.RuleParamDto) StringTypeValidation(org.sonar.server.util.StringTypeValidation) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) QProfileDto(org.sonar.db.qualityprofile.QProfileDto) RuleActivation(org.sonar.server.qualityprofile.RuleActivation) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) SearchResponse(org.sonarqube.ws.Rules.SearchResponse) Test(org.junit.Test)

Example 4 with BLOCKER

use of org.sonar.api.rule.Severity.BLOCKER in project sonarqube by SonarSource.

the class IssueUpdaterTest method verify_notification_without_resolution.

@Test
public void verify_notification_without_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.setSeverity(issue, BLOCKER, 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()).isEmpty();
    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)

Example 5 with BLOCKER

use of org.sonar.api.rule.Severity.BLOCKER in project sonarqube by SonarSource.

the class IssueUpdaterTest method verify_notification_when_issue_is_linked_on_removed_rule.

@Test
public void verify_notification_when_issue_is_linked_on_removed_rule() {
    RuleDefinitionDto rule = db.rules().insertIssueRule(r -> r.setStatus(RuleStatus.REMOVED));
    ComponentDto project = db.components().insertPublicProject();
    ComponentDto file = db.components().insertComponent(newFileDto(project));
    DefaultIssue issue = db.issues().insertIssue(rule, project, file, t -> t.setSeverity(MAJOR)).toDefaultIssue();
    IssueChangeContext context = IssueChangeContext.createUser(new Date(), "user_uuid");
    issueFieldsSetter.setSeverity(issue, BLOCKER, context);
    underTest.saveIssueAndPreloadSearchResponseData(db.getSession(), issue, context, false);
    verifyZeroInteractions(notificationManager);
}
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) IssueChangeContext(org.sonar.core.issue.IssueChangeContext) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) DefaultIssue(org.sonar.core.issue.DefaultIssue) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)6 Test (org.junit.Test)6 Mockito.mock (org.mockito.Mockito.mock)6 RuleStatus (org.sonar.api.rule.RuleStatus)6 BLOCKER (org.sonar.api.rule.Severity.BLOCKER)6 System2 (org.sonar.api.utils.System2)6 DbTester (org.sonar.db.DbTester)6 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)6 UserDto (org.sonar.db.user.UserDto)6 EsTester (org.sonar.server.es.EsTester)6 Date (java.util.Date)5 Rule (org.junit.Rule)5 ArgumentCaptor (org.mockito.ArgumentCaptor)5 Mockito.verify (org.mockito.Mockito.verify)5 Mockito.verifyZeroInteractions (org.mockito.Mockito.verifyZeroInteractions)5 RESOLUTION_FIXED (org.sonar.api.issue.Issue.RESOLUTION_FIXED)5 MAJOR (org.sonar.api.rule.Severity.MAJOR)5 DefaultIssue (org.sonar.core.issue.DefaultIssue)5 IssueChangeContext (org.sonar.core.issue.IssueChangeContext)5 SequenceUuidFactory (org.sonar.core.util.SequenceUuidFactory)5