Search in sources :

Example 6 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 7 with SensorStorage

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

the class DefaultMeasureTest method build_project_measure.

@Test
public void build_project_measure() {
    SensorStorage storage = mock(SensorStorage.class);
    DefaultInputModule module = new DefaultInputModule("foo");
    DefaultMeasure<Integer> newMeasure = new DefaultMeasure<Integer>(storage).forMetric(CoreMetrics.LINES).on(module).withValue(3);
    assertThat(newMeasure.inputComponent()).isEqualTo(new DefaultInputModule("foo"));
    assertThat(newMeasure.metric()).isEqualTo(CoreMetrics.LINES);
    assertThat(newMeasure.value()).isEqualTo(3);
    newMeasure.save();
    verify(storage).store(newMeasure);
}
Also used : DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Test(org.junit.Test)

Example 8 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 9 with SensorStorage

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

the class DefaultCpdTokensTest method validate_tokens_order.

@Test
public void validate_tokens_order() {
    SensorStorage sensorStorage = mock(SensorStorage.class);
    DefaultCpdTokens tokens = new DefaultCpdTokens(new MapSettings(), sensorStorage).onFile(INPUT_FILE).addToken(INPUT_FILE.newRange(1, 6, 1, 10), "bar");
    try {
        tokens.addToken(INPUT_FILE.newRange(1, 2, 1, 5), "foo");
        fail("Expected exception");
    } catch (Exception e) {
        assertThat(e).hasMessage("Tokens of file [moduleKey=foo, relative=src/Foo.java, basedir=foo] should be provided in order.\n" + "Previous token: Range[from [line=1, lineOffset=6] to [line=1, lineOffset=10]]\n" + "Last token: Range[from [line=1, lineOffset=2] to [line=1, lineOffset=5]]");
    }
}
Also used : MapSettings(org.sonar.api.config.MapSettings) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Test(org.junit.Test)

Example 10 with SensorStorage

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

the class DefaultCpdTokensTest method save_one_token.

@Test
public void save_one_token() {
    SensorStorage sensorStorage = mock(SensorStorage.class);
    DefaultCpdTokens tokens = new DefaultCpdTokens(new MapSettings(), sensorStorage).onFile(INPUT_FILE).addToken(INPUT_FILE.newRange(1, 2, 1, 5), "foo");
    tokens.save();
    verify(sensorStorage).store(tokens);
    assertThat(tokens.getTokenLines()).extracting("value", "startLine", "hashCode", "startUnit", "endUnit").containsExactly(tuple("foo", 1, "foo".hashCode(), 1, 1));
}
Also used : MapSettings(org.sonar.api.config.MapSettings) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Test(org.junit.Test)

Aggregations

SensorStorage (org.sonar.api.batch.sensor.internal.SensorStorage)13 Test (org.junit.Test)12 MapSettings (org.sonar.api.config.MapSettings)7 AnalysisMode (org.sonar.api.batch.AnalysisMode)2 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)2 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)2 Before (org.junit.Before)1 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)1 DefaultInputDir (org.sonar.api.batch.fs.internal.DefaultInputDir)1 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)1 MetricFinder (org.sonar.api.batch.measure.MetricFinder)1 ActiveRulesBuilder (org.sonar.api.batch.rule.internal.ActiveRulesBuilder)1 DefaultHighlighting (org.sonar.api.batch.sensor.highlighting.internal.DefaultHighlighting)1 Settings (org.sonar.api.config.Settings)1 DefaultHighlightable (org.sonar.scanner.source.DefaultHighlightable)1