Search in sources :

Example 16 with SensorStorage

use of org.sonar.api.batch.sensor.internal.SensorStorage in project sonarqube by SonarSource.

the class DefaultIssueTest method move_directory_issue_to_project_root.

@Test
public void move_directory_issue_to_project_root() {
    SensorStorage storage = mock(SensorStorage.class);
    DefaultIssue issue = new DefaultIssue(project, storage).at(new DefaultIssueLocation().on(new DefaultInputDir("foo", "src/main").setModuleBaseDir(project.getBaseDir())).message("Wrong way!")).forRule(RuleKey.of("repo", "rule")).overrideSeverity(Severity.BLOCKER);
    assertThat(issue.primaryLocation().inputComponent()).isEqualTo(project);
    assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("repo", "rule"));
    assertThat(issue.primaryLocation().textRange()).isNull();
    assertThat(issue.primaryLocation().message()).isEqualTo("[src/main] Wrong way!");
    assertThat(issue.overriddenSeverity()).isEqualTo(Severity.BLOCKER);
    issue.save();
    verify(storage).store(issue);
}
Also used : DefaultInputDir(org.sonar.api.batch.fs.internal.DefaultInputDir) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Test(org.junit.Test)

Example 17 with SensorStorage

use of org.sonar.api.batch.sensor.internal.SensorStorage in project sonarqube by SonarSource.

the class DefaultAdHocRuleTest method fail_to_store_if_no_rule_id.

@Test
public void fail_to_store_if_no_rule_id() {
    SensorStorage storage = mock(SensorStorage.class);
    NewAdHocRule rule = new DefaultAdHocRule(storage).engineId("engine").ruleId("  ").name("name").description("desc").severity(Severity.BLOCKER).type(RuleType.CODE_SMELL);
    assertThatThrownBy(() -> rule.save()).isInstanceOf(IllegalStateException.class).hasMessageContaining("Rule id is mandatory");
}
Also used : NewAdHocRule(org.sonar.api.batch.sensor.rule.NewAdHocRule) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Test(org.junit.Test)

Example 18 with SensorStorage

use of org.sonar.api.batch.sensor.internal.SensorStorage in project sonarqube by SonarSource.

the class DefaultAdHocRuleTest method store.

@Test
public void store() {
    SensorStorage storage = mock(SensorStorage.class);
    DefaultAdHocRule rule = new DefaultAdHocRule(storage).engineId("engine").ruleId("ruleId").name("name").description("desc").severity(Severity.BLOCKER).type(RuleType.CODE_SMELL);
    rule.save();
    assertThat(rule.engineId()).isEqualTo("engine");
    assertThat(rule.ruleId()).isEqualTo("ruleId");
    assertThat(rule.name()).isEqualTo("name");
    assertThat(rule.description()).isEqualTo("desc");
    assertThat(rule.severity()).isEqualTo(Severity.BLOCKER);
    assertThat(rule.type()).isEqualTo(RuleType.CODE_SMELL);
    verify(storage).store(any(DefaultAdHocRule.class));
}
Also used : SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Test(org.junit.Test)

Example 19 with SensorStorage

use of org.sonar.api.batch.sensor.internal.SensorStorage in project sonarqube by SonarSource.

the class DefaultAdHocRuleTest method fail_to_store_if_no_type.

@Test
public void fail_to_store_if_no_type() {
    SensorStorage storage = mock(SensorStorage.class);
    NewAdHocRule rule = new DefaultAdHocRule(storage).engineId("engine").ruleId("ruleId").name("name").description("desc").severity(Severity.BLOCKER);
    assertThatThrownBy(() -> rule.save()).isInstanceOf(IllegalStateException.class).hasMessageContaining("Type is mandatory");
}
Also used : NewAdHocRule(org.sonar.api.batch.sensor.rule.NewAdHocRule) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Test(org.junit.Test)

Example 20 with SensorStorage

use of org.sonar.api.batch.sensor.internal.SensorStorage in project sonarqube by SonarSource.

the class DefaultAdHocRuleTest method fail_to_store_if_no_severity.

@Test
public void fail_to_store_if_no_severity() {
    SensorStorage storage = mock(SensorStorage.class);
    NewAdHocRule rule = new DefaultAdHocRule(storage).engineId("engine").ruleId("ruleId").name("name").description("desc").type(RuleType.CODE_SMELL);
    assertThatThrownBy(() -> rule.save()).isInstanceOf(IllegalStateException.class).hasMessageContaining("Severity is mandatory");
}
Also used : NewAdHocRule(org.sonar.api.batch.sensor.rule.NewAdHocRule) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Test(org.junit.Test)

Aggregations

SensorStorage (org.sonar.api.batch.sensor.internal.SensorStorage)32 Test (org.junit.Test)27 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)5 NewAdHocRule (org.sonar.api.batch.sensor.rule.NewAdHocRule)5 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)4 DefaultIssue (org.sonar.api.batch.sensor.issue.internal.DefaultIssue)4 RuleKey (org.sonar.api.rule.RuleKey)4 Before (org.junit.Before)3 InputFile (org.sonar.api.batch.fs.InputFile)3 MetricFinder (org.sonar.api.batch.measure.MetricFinder)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Test (org.junit.jupiter.api.Test)2 AnalysisMode (org.sonar.api.batch.AnalysisMode)2 SensorContext (org.sonar.api.batch.SensorContext)2 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)2 DefaultInputDir (org.sonar.api.batch.fs.internal.DefaultInputDir)2 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)2 ActiveRulesBuilder (org.sonar.api.batch.rule.internal.ActiveRulesBuilder)2 SensorContext (org.sonar.api.batch.sensor.SensorContext)2