Search in sources :

Example 6 with Builder

use of org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration.Builder in project sonarlint-core by SonarSource.

the class IssueStoreReaderTest method testMultiModule2.

@Test
public void testMultiModule2() {
    // setup module hierarchy
    Map<String, String> modulePaths = new HashMap<>();
    modulePaths.put(MODULE_KEY, "");
    modulePaths.put("root:module1", "module1");
    modulePaths.put("root:module12", "module12");
    Builder moduleConfigBuilder = ModuleConfiguration.newBuilder();
    moduleConfigBuilder.getMutableModulePathByKey().putAll(modulePaths);
    when(storage.readModuleConfig(MODULE_KEY)).thenReturn(moduleConfigBuilder.build());
    // setup issues
    issueStore.save(Arrays.asList(createServerIssue("root:module1", "path1"), createServerIssue("root:module12", "path12")));
    // test
    // matches module12 path
    assertThat(issueStoreReader.getServerIssues(MODULE_KEY, "module12/path12")).usingElementComparator(simpleComparator).containsOnly(createApiIssue(MODULE_KEY, "module12/path12"));
}
Also used : HashMap(java.util.HashMap) Builder(org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration.Builder) Test(org.junit.Test)

Example 7 with Builder

use of org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration.Builder in project sonarlint-core by SonarSource.

the class IssueStoreReaderTest method testSingleModule.

@Test
public void testSingleModule() {
    // setup module hierarchy
    Map<String, String> modulePaths = new HashMap<>();
    modulePaths.put(MODULE_KEY, "");
    Builder moduleConfigBuilder = ModuleConfiguration.newBuilder();
    moduleConfigBuilder.getMutableModulePathByKey().putAll(modulePaths);
    when(storage.readModuleConfig(MODULE_KEY)).thenReturn(moduleConfigBuilder.build());
    // setup issues
    issueStore.save(Arrays.asList(createServerIssue(MODULE_KEY, "src/path1")));
    // test
    // matches path
    assertThat(issueStoreReader.getServerIssues(MODULE_KEY, "src/path1")).usingElementComparator(simpleComparator).containsOnly(createApiIssue(MODULE_KEY, "src/path1"));
    // no file found
    assertThat(issueStoreReader.getServerIssues(MODULE_KEY, "src/path3")).isEmpty();
    // module not in storage
    exception.expect(IllegalStateException.class);
    exception.expectMessage("module not in storage");
    assertThat(issueStoreReader.getServerIssues("root:module1", "path2")).usingElementComparator(simpleComparator).containsOnly(createApiIssue("module1", "path2"));
}
Also used : HashMap(java.util.HashMap) Builder(org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration.Builder) Test(org.junit.Test)

Example 8 with Builder

use of org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration.Builder in project sonarlint-core by SonarSource.

the class IssueStoreReaderTest method testDontSetTypeIfDoesntExist.

@Test
public void testDontSetTypeIfDoesntExist() {
    // setup module hierarchy
    Map<String, String> modulePaths = new HashMap<>();
    modulePaths.put(MODULE_KEY, "");
    Builder moduleConfigBuilder = ModuleConfiguration.newBuilder();
    moduleConfigBuilder.getMutableModulePathByKey().putAll(modulePaths);
    when(storage.readModuleConfig(MODULE_KEY)).thenReturn(moduleConfigBuilder.build());
    ScannerInput.ServerIssue serverIssue = ScannerInput.ServerIssue.newBuilder().setModuleKey(MODULE_KEY).setPath("path").build();
    issueStore.save(Collections.singletonList(serverIssue));
    ServerIssue issue = issueStoreReader.getServerIssues(MODULE_KEY, "path").iterator().next();
    assertThat(issue.type()).isNull();
}
Also used : ScannerInput(org.sonar.scanner.protocol.input.ScannerInput) HashMap(java.util.HashMap) Builder(org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration.Builder) ServerIssue(org.sonarsource.sonarlint.core.client.api.connected.ServerIssue) DefaultServerIssue(org.sonarsource.sonarlint.core.container.model.DefaultServerIssue) Test(org.junit.Test)

Example 9 with Builder

use of org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration.Builder in project sonarlint-core by SonarSource.

the class SettingsDownloaderTest method testFetchProjectProperties.

@Test
public void testFetchProjectProperties() throws Exception {
    SonarLintWsClient wsClient = WsClientTestUtils.createMockWithReaderResponse("/api/properties?format=json&resource=foo", new StringReader("[{\"key\": \"sonar.inclusions\",\"value\": \"**/*.java\"}," + "{\"key\": \"sonar.java.fileSuffixes\",\"value\": \"*.java\"}]"));
    Builder builder = ModuleConfiguration.newBuilder();
    new SettingsDownloader(wsClient).fetchProjectSettings("6.2", "foo", GlobalProperties.newBuilder().build(), builder);
    assertThat(builder.getPropertiesMap()).containsOnly(entry("sonar.inclusions", "**/*.java"), entry("sonar.java.fileSuffixes", "*.java"));
}
Also used : Builder(org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration.Builder) StringReader(java.io.StringReader) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Aggregations

Builder (org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration.Builder)9 Test (org.junit.Test)7 HashMap (java.util.HashMap)4 SonarLintWsClient (org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient)3 StringReader (java.io.StringReader)2 PipedInputStream (java.io.PipedInputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 ScannerInput (org.sonar.scanner.protocol.input.ScannerInput)1 Settings (org.sonarqube.ws.Settings)1 Value (org.sonarqube.ws.Settings.FieldValues.Value)1 ValuesWsResponse (org.sonarqube.ws.Settings.ValuesWsResponse)1 ServerIssue (org.sonarsource.sonarlint.core.client.api.connected.ServerIssue)1 DefaultServerIssue (org.sonarsource.sonarlint.core.container.model.DefaultServerIssue)1