Search in sources :

Example 11 with DefaultActiveRules

use of org.sonar.api.batch.rule.internal.DefaultActiveRules in project sonarqube by SonarSource.

the class IgnoreIssuesFilterTest method shouldPassToChainIfMatcherHasNoPatternForIssue.

@Test
public void shouldPassToChainIfMatcherHasNoPatternForIssue() {
    DefaultActiveRules activeRules = new DefaultActiveRules(ImmutableSet.of());
    IgnoreIssuesFilter underTest = new IgnoreIssuesFilter(activeRules, analysisWarnings);
    when(chain.accept(issue)).thenReturn(true);
    assertThat(underTest.accept(issue, chain)).isTrue();
    verify(chain).accept(any());
}
Also used : DefaultActiveRules(org.sonar.api.batch.rule.internal.DefaultActiveRules) Test(org.junit.Test)

Example 12 with DefaultActiveRules

use of org.sonar.api.batch.rule.internal.DefaultActiveRules in project sonarqube by SonarSource.

the class IgnoreIssuesFilterTest method shouldAcceptIfRulePatternDoesNotMatch.

@Test
public void shouldAcceptIfRulePatternDoesNotMatch() {
    DefaultActiveRules activeRules = new DefaultActiveRules(ImmutableSet.of());
    IgnoreIssuesFilter underTest = new IgnoreIssuesFilter(activeRules, analysisWarnings);
    WildcardPattern pattern = mock(WildcardPattern.class);
    when(pattern.match(ruleKey.toString())).thenReturn(false);
    underTest.addRuleExclusionPatternForComponent(component, pattern);
    assertThat(underTest.accept(issue, chain)).isFalse();
}
Also used : DefaultActiveRules(org.sonar.api.batch.rule.internal.DefaultActiveRules) WildcardPattern(org.sonar.api.utils.WildcardPattern) Test(org.junit.Test)

Example 13 with DefaultActiveRules

use of org.sonar.api.batch.rule.internal.DefaultActiveRules in project sonarqube by SonarSource.

the class IgnoreIssuesFilterTest method shouldRejectIfRulePatternMatchesDeprecatedRule.

@Test
public void shouldRejectIfRulePatternMatchesDeprecatedRule() {
    DefaultActiveRules activeRules = new DefaultActiveRules(ImmutableSet.of(new NewActiveRule.Builder().setRuleKey(ruleKey).setDeprecatedKeys(singleton(RuleKey.of("repo", "rule"))).build()));
    IgnoreIssuesFilter underTest = new IgnoreIssuesFilter(activeRules, analysisWarnings);
    WildcardPattern pattern = WildcardPattern.create("repo:rule");
    underTest.addRuleExclusionPatternForComponent(component, pattern);
    assertThat(underTest.accept(issue, chain)).isFalse();
    verify(analysisWarnings).addUnique("A multicriteria issue exclusion uses the rule key 'repo:rule' that has been changed. The pattern should be updated to 'foo:bar'");
    assertThat(logTester.logs()).contains("A multicriteria issue exclusion uses the rule key 'repo:rule' that has been changed. The pattern should be updated to 'foo:bar'");
}
Also used : DefaultActiveRules(org.sonar.api.batch.rule.internal.DefaultActiveRules) NewActiveRule(org.sonar.api.batch.rule.internal.NewActiveRule) WildcardPattern(org.sonar.api.utils.WildcardPattern) Test(org.junit.Test)

Example 14 with DefaultActiveRules

use of org.sonar.api.batch.rule.internal.DefaultActiveRules in project sonarqube by SonarSource.

the class EnforceIssuesFilterTest method shouldRefuseIssueIfRuleMatchesButNotPath.

@Test
public void shouldRefuseIssueIfRuleMatchesButNotPath() {
    DefaultActiveRules activeRules = new DefaultActiveRules(ImmutableSet.of());
    String path = "org/sonar/api/Issue.java";
    String componentKey = "org.sonar.api.Issue";
    RuleKey ruleKey = RuleKey.of("repo", "rule");
    when(issue.ruleKey()).thenReturn(ruleKey);
    when(issue.componentKey()).thenReturn(componentKey);
    IssuePattern matching = new IssuePattern("no match", "repo:rule");
    when(exclusionPatternInitializer.getMulticriteriaPatterns()).thenReturn(ImmutableList.of(matching));
    when(issue.getComponent()).thenReturn(createComponentWithPath(path));
    ignoreFilter = new EnforceIssuesFilter(exclusionPatternInitializer, analysisWarnings, activeRules);
    assertThat(ignoreFilter.accept(issue, chain)).isFalse();
    verifyNoInteractions(chain, analysisWarnings);
}
Also used : DefaultActiveRules(org.sonar.api.batch.rule.internal.DefaultActiveRules) RuleKey(org.sonar.api.rule.RuleKey) IssuePattern(org.sonar.scanner.issue.ignore.pattern.IssuePattern) Test(org.junit.Test)

Example 15 with DefaultActiveRules

use of org.sonar.api.batch.rule.internal.DefaultActiveRules in project sonarqube by SonarSource.

the class EnforceIssuesFilterTest method shouldPassToChainIfRuleDoesNotMatch.

@Test
public void shouldPassToChainIfRuleDoesNotMatch() {
    DefaultActiveRules activeRules = new DefaultActiveRules(ImmutableSet.of());
    RuleKey ruleKey = RuleKey.of("repo", "rule");
    when(issue.ruleKey()).thenReturn(ruleKey);
    IssuePattern matching = new IssuePattern("**", "unknown");
    when(exclusionPatternInitializer.getMulticriteriaPatterns()).thenReturn(ImmutableList.of(matching));
    ignoreFilter = new EnforceIssuesFilter(exclusionPatternInitializer, analysisWarnings, activeRules);
    assertThat(ignoreFilter.accept(issue, chain)).isTrue();
    verify(chain).accept(issue);
}
Also used : DefaultActiveRules(org.sonar.api.batch.rule.internal.DefaultActiveRules) RuleKey(org.sonar.api.rule.RuleKey) IssuePattern(org.sonar.scanner.issue.ignore.pattern.IssuePattern) Test(org.junit.Test)

Aggregations

DefaultActiveRules (org.sonar.api.batch.rule.internal.DefaultActiveRules)18 Test (org.junit.Test)15 CheckFactory (org.sonar.api.batch.rule.CheckFactory)5 NewActiveRule (org.sonar.api.batch.rule.internal.NewActiveRule)5 RuleKey (org.sonar.api.rule.RuleKey)5 IssuePattern (org.sonar.scanner.issue.ignore.pattern.IssuePattern)5 SonarRuntime (org.sonar.api.SonarRuntime)4 ActiveRules (org.sonar.api.batch.rule.ActiveRules)3 DefaultSensorDescriptor (org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor)3 WildcardPattern (org.sonar.api.utils.WildcardPattern)3 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2 InputFile (org.sonar.api.batch.fs.InputFile)2 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)2 NoSonarFilter (org.sonar.api.issue.NoSonarFilter)2 FileLinesContext (org.sonar.api.measures.FileLinesContext)2 FileLinesContextFactory (org.sonar.api.measures.FileLinesContextFactory)2 RulesDefinition (org.sonar.api.server.rule.RulesDefinition)2 File (java.io.File)1 LoadedActiveRule (org.sonar.api.batch.rule.LoadedActiveRule)1