use of org.sonar.api.batch.rule.internal.DefaultActiveRules in project sonarqube by SonarSource.
the class ActiveRulesProviderTest method testCombinationOfRules.
@Test
public void testCombinationOfRules() {
LoadedActiveRule r1 = mockRule("rule1");
LoadedActiveRule r2 = mockRule("rule2");
LoadedActiveRule r3 = mockRule("rule3");
List<LoadedActiveRule> qp1Rules = ImmutableList.of(r1, r2);
List<LoadedActiveRule> qp2Rules = ImmutableList.of(r2, r3);
List<LoadedActiveRule> qp3Rules = ImmutableList.of(r1, r3);
when(loader.load("qp1")).thenReturn(qp1Rules);
when(loader.load("qp2")).thenReturn(qp2Rules);
when(loader.load("qp3")).thenReturn(qp3Rules);
QualityProfiles profiles = mockProfiles("qp1", "qp2", "qp3");
DefaultActiveRules activeRules = provider.provide(loader, profiles);
assertThat(activeRules.findAll()).hasSize(3);
assertThat(activeRules.findAll()).extracting("ruleKey").containsOnly(RuleKey.of("rule1", "rule1"), RuleKey.of("rule2", "rule2"), RuleKey.of("rule3", "rule3"));
verify(loader).load("qp1");
verify(loader).load("qp2");
verify(loader).load("qp3");
assertThat(activeRules.getDeprecatedRuleKeys(RuleKey.of("rule1", "rule1"))).containsOnly("rule1old:rule1old");
verifyNoMoreInteractions(loader);
}
use of org.sonar.api.batch.rule.internal.DefaultActiveRules in project sonarqube by SonarSource.
the class EnforceIssuesFilterTest method shouldAcceptIssueIfFullyMatched.
@Test
public void shouldAcceptIssueIfFullyMatched() {
DefaultActiveRules activeRules = new DefaultActiveRules(ImmutableSet.of());
String path = "org/sonar/api/Issue.java";
RuleKey ruleKey = RuleKey.of("repo", "rule");
when(issue.ruleKey()).thenReturn(ruleKey);
IssuePattern matching = new IssuePattern(path, ruleKey.toString());
when(exclusionPatternInitializer.getMulticriteriaPatterns()).thenReturn(ImmutableList.of(matching));
when(issue.getComponent()).thenReturn(createComponentWithPath(path));
ignoreFilter = new EnforceIssuesFilter(exclusionPatternInitializer, analysisWarnings, activeRules);
assertThat(ignoreFilter.accept(issue, chain)).isTrue();
verifyNoInteractions(chain);
}
use of org.sonar.api.batch.rule.internal.DefaultActiveRules in project sonarqube by SonarSource.
the class ActiveRulesPublisherTest method write.
@Test
public void write() throws Exception {
File outputDir = temp.newFolder();
ScannerReportWriter writer = new ScannerReportWriter(outputDir);
NewActiveRule ar = new NewActiveRule.Builder().setRuleKey(RuleKey.of("java", "S001")).setSeverity("BLOCKER").setParam("p1", "v1").setCreatedAt(1_000L).setUpdatedAt(2_000L).setQProfileKey("qp1").build();
ActiveRules activeRules = new DefaultActiveRules(singletonList(ar));
ActiveRulesPublisher underTest = new ActiveRulesPublisher(activeRules);
underTest.publish(writer);
ScannerReportReader reader = new ScannerReportReader(outputDir);
try (CloseableIterator<ScannerReport.ActiveRule> readIt = reader.readActiveRules()) {
ScannerReport.ActiveRule reportAr = readIt.next();
assertThat(reportAr.getRuleRepository()).isEqualTo("java");
assertThat(reportAr.getRuleKey()).isEqualTo("S001");
assertThat(reportAr.getSeverity()).isEqualTo(Constants.Severity.BLOCKER);
assertThat(reportAr.getCreatedAt()).isEqualTo(1_000L);
assertThat(reportAr.getUpdatedAt()).isEqualTo(2_000L);
assertThat(reportAr.getQProfileKey()).isEqualTo("qp1");
assertThat(reportAr.getParamsByKeyMap()).hasSize(1);
assertThat(reportAr.getParamsByKeyMap().entrySet().iterator().next().getKey()).isEqualTo("p1");
assertThat(reportAr.getParamsByKeyMap().entrySet().iterator().next().getValue()).isEqualTo("v1");
assertThat(readIt.hasNext()).isFalse();
}
}
use of org.sonar.api.batch.rule.internal.DefaultActiveRules in project sonar-web by SonarSource.
the class HtmlSensorTest method test_descriptor_sonarqube_9_3.
@Test
public void test_descriptor_sonarqube_9_3() {
final boolean[] called = { false };
DefaultSensorDescriptor sensorDescriptor = new DefaultSensorDescriptor() {
public SensorDescriptor processesFilesIndependently() {
called[0] = true;
return this;
}
};
SonarRuntime sonarRuntime = SonarRuntimeImpl.forSonarQube(Version.create(9, 3), SonarQubeSide.SCANNER, SonarEdition.COMMUNITY);
new HtmlSensor(sonarRuntime, null, null, new CheckFactory(new DefaultActiveRules(Collections.emptyList()))).describe(sensorDescriptor);
assertThat(sensorDescriptor.name()).isEqualTo("HTML");
assertThat(sensorDescriptor.languages()).isEmpty();
assertTrue(called[0]);
}
use of org.sonar.api.batch.rule.internal.DefaultActiveRules in project sonarqube by SonarSource.
the class IgnoreIssuesFilterTest method shouldRejectIfRulePatternMatches.
@Test
public void shouldRejectIfRulePatternMatches() {
DefaultActiveRules activeRules = new DefaultActiveRules(ImmutableSet.of());
IgnoreIssuesFilter underTest = new IgnoreIssuesFilter(activeRules, analysisWarnings);
WildcardPattern pattern = mock(WildcardPattern.class);
when(pattern.match(ruleKey.toString())).thenReturn(true);
underTest.addRuleExclusionPatternForComponent(component, pattern);
assertThat(underTest.accept(issue, chain)).isFalse();
verifyNoInteractions(analysisWarnings);
}
Aggregations