use of org.sonar.scanner.report.ActiveRulesPublisher 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 ActiveRulesBuilder().create(RuleKey.of("java", "S001")).setSeverity("BLOCKER").setParam("p1", "v1");
ActiveRules activeRules = new DefaultActiveRules(Arrays.asList(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.getParamsByKey()).hasSize(1);
assertThat(reportAr.getParamsByKey().entrySet().iterator().next().getKey()).isEqualTo("p1");
assertThat(reportAr.getParamsByKey().entrySet().iterator().next().getValue()).isEqualTo("v1");
assertThat(readIt.hasNext()).isFalse();
}
}
Aggregations