Search in sources :

Example 91 with RuleKey

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

the class DefaultIssueCallbackTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    RuleKey ruleKey = RuleKey.of("repo", "key");
    issue = new TrackedIssue();
    issue.setKey("key");
    issue.setAssignee("user");
    issue.setRuleKey(ruleKey);
    when(issueCache.all()).thenReturn(ImmutableList.of(issue));
    ScannerInput.User.Builder userBuilder = ScannerInput.User.newBuilder();
    userBuilder.setLogin("user");
    userBuilder.setName("name");
    when(userRepository.map(Collections.singleton("user"))).thenReturn(Collections.singletonMap("user", userBuilder.build()));
    Rule r = mock(Rule.class);
    when(r.name()).thenReturn("rule name");
    when(rules.find(ruleKey)).thenReturn(r);
}
Also used : TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue) RuleKey(org.sonar.api.rule.RuleKey) Rule(org.sonar.api.batch.rule.Rule) Before(org.junit.Before)

Example 92 with RuleKey

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

the class EnforceIssuesFilterTest method shouldPassToChainIfRuleDoesNotMatch.

@Test
public void shouldPassToChainIfRuleDoesNotMatch() {
    String rule = "rule";
    RuleKey ruleKey = mock(RuleKey.class);
    when(ruleKey.toString()).thenReturn(rule);
    when(issue.ruleKey()).thenReturn(ruleKey);
    IssuePattern matching = mock(IssuePattern.class);
    WildcardPattern rulePattern = mock(WildcardPattern.class);
    when(matching.getRulePattern()).thenReturn(rulePattern);
    when(rulePattern.match(rule)).thenReturn(false);
    when(exclusionPatternInitializer.getMulticriteriaPatterns()).thenReturn(ImmutableList.of(matching));
    assertThat(ignoreFilter.accept(issue, chain)).isTrue();
    verify(chain).accept(issue);
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) IssuePattern(org.sonar.scanner.issue.ignore.pattern.IssuePattern) WildcardPattern(org.sonar.api.utils.WildcardPattern) Test(org.junit.Test)

Example 93 with RuleKey

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

the class EnforceIssuesFilterTest method shouldRefuseIssueIfRuleMatchesAndPathUnknown.

@Test
public void shouldRefuseIssueIfRuleMatchesAndPathUnknown() {
    String rule = "rule";
    String path = "org/sonar/api/Issue.java";
    String componentKey = "org.sonar.api.Issue";
    RuleKey ruleKey = mock(RuleKey.class);
    when(ruleKey.toString()).thenReturn(rule);
    when(issue.ruleKey()).thenReturn(ruleKey);
    when(issue.componentKey()).thenReturn(componentKey);
    IssuePattern matching = mock(IssuePattern.class);
    WildcardPattern rulePattern = mock(WildcardPattern.class);
    when(matching.getRulePattern()).thenReturn(rulePattern);
    when(rulePattern.match(rule)).thenReturn(true);
    WildcardPattern pathPattern = mock(WildcardPattern.class);
    when(matching.getResourcePattern()).thenReturn(pathPattern);
    when(pathPattern.match(path)).thenReturn(false);
    when(exclusionPatternInitializer.getMulticriteriaPatterns()).thenReturn(ImmutableList.of(matching));
    when(exclusionPatternInitializer.getPathForComponent(componentKey)).thenReturn(null);
    assertThat(ignoreFilter.accept(issue, chain)).isFalse();
    verifyZeroInteractions(chain);
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) IssuePattern(org.sonar.scanner.issue.ignore.pattern.IssuePattern) WildcardPattern(org.sonar.api.utils.WildcardPattern) Test(org.junit.Test)

Example 94 with RuleKey

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

the class EnforceIssuesFilterTest method shouldRefuseIssueIfRuleMatchesButNotPath.

@Test
public void shouldRefuseIssueIfRuleMatchesButNotPath() {
    String rule = "rule";
    String path = "org/sonar/api/Issue.java";
    String componentKey = "org.sonar.api.Issue";
    RuleKey ruleKey = mock(RuleKey.class);
    when(ruleKey.toString()).thenReturn(rule);
    when(issue.ruleKey()).thenReturn(ruleKey);
    when(issue.componentKey()).thenReturn(componentKey);
    IssuePattern matching = mock(IssuePattern.class);
    WildcardPattern rulePattern = mock(WildcardPattern.class);
    when(matching.getRulePattern()).thenReturn(rulePattern);
    when(rulePattern.match(rule)).thenReturn(true);
    WildcardPattern pathPattern = mock(WildcardPattern.class);
    when(matching.getResourcePattern()).thenReturn(pathPattern);
    when(pathPattern.match(path)).thenReturn(false);
    when(exclusionPatternInitializer.getMulticriteriaPatterns()).thenReturn(ImmutableList.of(matching));
    when(exclusionPatternInitializer.getPathForComponent(componentKey)).thenReturn(path);
    assertThat(ignoreFilter.accept(issue, chain)).isFalse();
    verifyZeroInteractions(chain);
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) IssuePattern(org.sonar.scanner.issue.ignore.pattern.IssuePattern) WildcardPattern(org.sonar.api.utils.WildcardPattern) Test(org.junit.Test)

Example 95 with RuleKey

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

the class IssuePatternTest method create.

private FilterableIssue create(Rule rule, String component, Integer line) {
    FilterableIssue mockIssue = mock(FilterableIssue.class);
    RuleKey ruleKey = null;
    if (rule != null) {
        ruleKey = rule.ruleKey();
    }
    when(mockIssue.ruleKey()).thenReturn(ruleKey);
    when(mockIssue.componentKey()).thenReturn(component);
    when(mockIssue.line()).thenReturn(line);
    return mockIssue;
}
Also used : RuleKey(org.sonar.api.rule.RuleKey) FilterableIssue(org.sonar.api.scan.issue.filter.FilterableIssue)

Aggregations

RuleKey (org.sonar.api.rule.RuleKey)95 Test (org.junit.Test)48 RuleDto (org.sonar.db.rule.RuleDto)24 ActiveRuleKey (org.sonar.db.qualityprofile.ActiveRuleKey)22 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)17 SearchOptions (org.sonar.server.es.SearchOptions)14 RuleParamDto (org.sonar.db.rule.RuleParamDto)10 NewIssue (org.sonar.api.batch.sensor.issue.NewIssue)9 ArrayList (java.util.ArrayList)5 DbSession (org.sonar.db.DbSession)5 ActiveRuleParamDto (org.sonar.db.qualityprofile.ActiveRuleParamDto)5 RulesDefinition (org.sonar.api.server.rule.RulesDefinition)4 ComponentDto (org.sonar.db.component.ComponentDto)4 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)4 Rule (org.sonar.api.batch.rule.Rule)3 WildcardPattern (org.sonar.api.utils.WildcardPattern)3 DefaultIssue (org.sonar.core.issue.DefaultIssue)3 ActiveRuleDao (org.sonar.db.qualityprofile.ActiveRuleDao)3 QualityProfileDao (org.sonar.db.qualityprofile.QualityProfileDao)3 IssuePattern (org.sonar.scanner.issue.ignore.pattern.IssuePattern)3