Search in sources :

Example 1 with SensorStorage

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

the class DefaultCpdTokensTest method handle_exclusions_by_pattern.

@Test
public void handle_exclusions_by_pattern() {
    SensorStorage sensorStorage = mock(SensorStorage.class);
    Settings settings = new MapSettings();
    settings.setProperty("sonar.cpd.exclusions", "src/Foo.java,another");
    DefaultCpdTokens tokens = new DefaultCpdTokens(settings, sensorStorage).onFile(INPUT_FILE).addToken(INPUT_FILE.newRange(1, 2, 1, 5), "foo");
    tokens.save();
    verifyZeroInteractions(sensorStorage);
    assertThat(tokens.getTokenLines()).isEmpty();
}
Also used : MapSettings(org.sonar.api.config.MapSettings) Settings(org.sonar.api.config.Settings) MapSettings(org.sonar.api.config.MapSettings) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Test(org.junit.Test)

Example 2 with SensorStorage

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

the class DefaultIssueTest method build_directory_issue.

@Test
public void build_directory_issue() {
    SensorStorage storage = mock(SensorStorage.class);
    DefaultIssue issue = new DefaultIssue(storage).at(new DefaultIssueLocation().on(new DefaultInputDir("foo", "src")).message("Wrong way!")).forRule(RuleKey.of("repo", "rule")).overrideSeverity(Severity.BLOCKER);
    assertThat(issue.primaryLocation().inputComponent()).isEqualTo(new DefaultInputDir("foo", "src"));
    assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("repo", "rule"));
    assertThat(issue.primaryLocation().textRange()).isNull();
    assertThat(issue.primaryLocation().message()).isEqualTo("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 3 with SensorStorage

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

the class DefaultHighlightableTest method should_store_highlighting_rules.

@Test
public void should_store_highlighting_rules() {
    SensorStorage sensorStorage = mock(SensorStorage.class);
    DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/Foo.php").initMetadata("azerty\nbla bla").build();
    DefaultHighlightable highlightablePerspective = new DefaultHighlightable(inputFile, sensorStorage, mock(AnalysisMode.class));
    highlightablePerspective.newHighlighting().highlight(0, 6, "k").highlight(7, 10, "cppd").done();
    ArgumentCaptor<DefaultHighlighting> argCaptor = ArgumentCaptor.forClass(DefaultHighlighting.class);
    verify(sensorStorage).store(argCaptor.capture());
    assertThat(argCaptor.getValue().getSyntaxHighlightingRuleSet()).hasSize(2);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) DefaultHighlighting(org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting) AnalysisMode(org.sonar.api.batch.AnalysisMode) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) DefaultHighlightable(org.sonar.scanner.source.DefaultHighlightable) Test(org.junit.Test)

Example 4 with SensorStorage

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

the class JavaIssueTest method test_addFlow.

@Test
public void test_addFlow() throws Exception {
    TestInputFileBuilder tifb = new TestInputFileBuilder("module", "relPath");
    tifb.setModuleBaseDir(new java.io.File("").toPath());
    tifb.setLines(3);
    tifb.setOriginalLineOffsets(new int[] { 0, 10, 15 });
    tifb.setLastValidOffset(25);
    DefaultInputFile file = tifb.build();
    RuleKey ruleKey = RuleKey.of("squid", "ruleKey");
    SensorContext sensorContext = mock(SensorContext.class);
    SensorStorage storage = mock(SensorStorage.class);
    DefaultIssue newIssueEmptyFlow = new DefaultIssue(storage);
    DefaultIssue newIssueWithFlow = new DefaultIssue(storage);
    Mockito.when(sensorContext.newIssue()).thenReturn(newIssueEmptyFlow, newIssueWithFlow);
    JavaIssue javaIssue = JavaIssue.create(sensorContext, ruleKey, null);
    javaIssue.setPrimaryLocation(file, "main message", 1, 2, 1, 6);
    javaIssue.addFlow(file, new ArrayList<>());
    javaIssue.save();
    Mockito.verify(storage, Mockito.times(1)).store(newIssueEmptyFlow);
    assertThat(newIssueEmptyFlow.flows()).isEmpty();
    javaIssue = JavaIssue.create(sensorContext, ruleKey, null);
    javaIssue.setPrimaryLocation(file, "main message", 1, 2, 1, 6);
    List<List<AnalyzerMessage>> flows = new ArrayList<>();
    flows.add(Lists.newArrayList(new AnalyzerMessage(null, file.file(), new AnalyzerMessage.TextSpan(2, 2, 2, 4), "flow message 1", 0)));
    flows.add(Lists.newArrayList(new AnalyzerMessage(null, file.file(), new AnalyzerMessage.TextSpan(3, 1, 3, 5), "flow message 2", 0)));
    javaIssue.addFlow(file, flows);
    javaIssue.save();
    Mockito.verify(storage, Mockito.times(1)).store(newIssueWithFlow);
    assertThat(newIssueWithFlow.flows()).hasSize(2);
}
Also used : SensorContext(org.sonar.api.batch.SensorContext) RuleKey(org.sonar.api.rule.RuleKey) ArrayList(java.util.ArrayList) DefaultIssue(org.sonar.api.batch.sensor.issue.internal.DefaultIssue) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) ArrayList(java.util.ArrayList) List(java.util.List) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) Test(org.junit.Test)

Example 5 with SensorStorage

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

the class DefaultAdHocRuleTest method description_is_optional.

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

Aggregations

SensorStorage (org.sonar.api.batch.sensor.internal.SensorStorage)30 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 Before (org.junit.Before)3 MetricFinder (org.sonar.api.batch.measure.MetricFinder)3 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 DefaultCpdTokens (org.sonar.api.batch.sensor.cpd.internal.DefaultCpdTokens)2 DefaultIssue (org.sonar.api.batch.sensor.issue.internal.DefaultIssue)2 MapSettings (org.sonar.api.config.MapSettings)2 RuleKey (org.sonar.api.rule.RuleKey)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1