Search in sources :

Example 31 with SonarLintWsClient

use of org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient in project sonarlint-core by SonarSource.

the class QualityProfilesDownloaderTest method testWithOrg.

@Test
public void testWithOrg() {
    SonarLintWsClient wsClient = WsClientTestUtils.createMockWithStreamResponse("/api/qualityprofiles/search.protobuf?organization=myOrg", "/update/qualityprofiles.pb");
    when(wsClient.getOrganizationKey()).thenReturn("myOrg");
    qProfilesDownloader = new QualityProfilesDownloader(wsClient);
    qProfilesDownloader.fetchQualityProfilesTo(temp.getRoot().toPath());
    QProfiles qProfiles = ProtobufUtil.readFile(temp.getRoot().toPath().resolve(StoragePaths.QUALITY_PROFILES_PB), QProfiles.parser());
    assertThat(qProfiles.getQprofilesByKeyMap()).containsOnlyKeys("cs-sonar-way-58886", "java-sonar-way-74592", "java-empty-74333", "js-sonar-security-way-70539", "js-sonar-way-60746");
    assertThat(qProfiles.getDefaultQProfilesByLanguageMap()).containsOnly(entry("cs", "cs-sonar-way-58886"), entry("java", "java-sonar-way-74592"), entry("js", "js-sonar-way-60746"));
}
Also used : SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) QProfiles(org.sonarsource.sonarlint.core.proto.Sonarlint.QProfiles) Test(org.junit.Test)

Example 32 with SonarLintWsClient

use of org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient in project sonarlint-core by SonarSource.

the class RulesDownloaderTest method rules_update_protobuf.

@Test
public void rules_update_protobuf() throws Exception {
    SonarLintWsClient wsClient = WsClientTestUtils.createMockWithStreamResponse(RULES_SEARCH_URL + "&p=1&ps=500", "/update/rulesp1.pb");
    WsClientTestUtils.addStreamResponse(wsClient, RULES_SEARCH_URL + "&p=2&ps=500", "/update/rulesp2.pb");
    RulesDownloader rulesUpdate = new RulesDownloader(wsClient);
    File tempDir = temp.newFolder();
    rulesUpdate.fetchRulesTo(tempDir.toPath(), new ProgressWrapper(null));
    Rules rules = ProtobufUtil.readFile(tempDir.toPath().resolve(StoragePaths.RULES_PB), Rules.parser());
    assertThat(rules.getRulesByKeyMap()).hasSize(939);
    ActiveRules jsActiveRules = ProtobufUtil.readFile(tempDir.toPath().resolve(StoragePaths.ACTIVE_RULES_FOLDER).resolve("js-sonar-way-62960.pb"), ActiveRules.parser());
    assertThat(jsActiveRules.getActiveRulesByKeyMap()).hasSize(85);
}
Also used : ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) ActiveRules(org.sonarsource.sonarlint.core.proto.Sonarlint.ActiveRules) File(java.io.File) Rules(org.sonarsource.sonarlint.core.proto.Sonarlint.Rules) ActiveRules(org.sonarsource.sonarlint.core.proto.Sonarlint.ActiveRules) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Example 33 with SonarLintWsClient

use of org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient in project sonarlint-core by SonarSource.

the class RulesDownloaderTest method rules_update_protobuf_with_org.

@Test
public void rules_update_protobuf_with_org() throws Exception {
    SonarLintWsClient wsClient = WsClientTestUtils.createMockWithStreamResponse(RULES_SEARCH_URL + "&organization=myOrg&p=1&ps=500", "/update/rulesp1.pb");
    WsClientTestUtils.addStreamResponse(wsClient, RULES_SEARCH_URL + "&organization=myOrg&p=2&ps=500", "/update/rulesp2.pb");
    when(wsClient.getOrganizationKey()).thenReturn("myOrg");
    RulesDownloader rulesUpdate = new RulesDownloader(wsClient);
    File tempDir = temp.newFolder();
    rulesUpdate.fetchRulesTo(tempDir.toPath(), new ProgressWrapper(null));
    Rules rules = ProtobufUtil.readFile(tempDir.toPath().resolve(StoragePaths.RULES_PB), Rules.parser());
    assertThat(rules.getRulesByKeyMap()).hasSize(939);
    ActiveRules jsActiveRules = ProtobufUtil.readFile(tempDir.toPath().resolve(StoragePaths.ACTIVE_RULES_FOLDER).resolve("js-sonar-way-62960.pb"), ActiveRules.parser());
    assertThat(jsActiveRules.getActiveRulesByKeyMap()).hasSize(85);
}
Also used : ProgressWrapper(org.sonarsource.sonarlint.core.util.ProgressWrapper) ActiveRules(org.sonarsource.sonarlint.core.proto.Sonarlint.ActiveRules) File(java.io.File) Rules(org.sonarsource.sonarlint.core.proto.Sonarlint.Rules) ActiveRules(org.sonarsource.sonarlint.core.proto.Sonarlint.ActiveRules) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Example 34 with SonarLintWsClient

use of org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient 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)

Example 35 with SonarLintWsClient

use of org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient in project sonarlint-core by SonarSource.

the class AuthenticationCheckerTest method test_connection_issue.

@Test
public void test_connection_issue() {
    SonarLintWsClient wsClient = WsClientTestUtils.createMock();
    WsClientTestUtils.addFailedResponse(wsClient, "api/authentication/validate?format=json", 500, "Foo");
    AuthenticationChecker checker = new AuthenticationChecker(wsClient);
    ValidationResult validationResult = checker.validateCredentials();
    assertThat(validationResult.success()).isFalse();
    assertThat(validationResult.message()).isEqualTo("HTTP Connection failed (500): Foo");
}
Also used : ValidationResult(org.sonarsource.sonarlint.core.client.api.connected.ValidationResult) SonarLintWsClient(org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient) Test(org.junit.Test)

Aggregations

SonarLintWsClient (org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient)40 Test (org.junit.Test)37 ProgressWrapper (org.sonarsource.sonarlint.core.util.ProgressWrapper)8 File (java.io.File)7 UnsupportedServerException (org.sonarsource.sonarlint.core.client.api.exceptions.UnsupportedServerException)6 NotFoundException (org.sonarsource.sonarlint.core.container.connected.exceptions.NotFoundException)6 ValidationResult (org.sonarsource.sonarlint.core.client.api.connected.ValidationResult)5 StringReader (java.io.StringReader)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ZonedDateTime (java.time.ZonedDateTime)3 SonarQubeNotification (org.sonarsource.sonarlint.core.client.api.notifications.SonarQubeNotification)3 ActiveRules (org.sonarsource.sonarlint.core.proto.Sonarlint.ActiveRules)3 Builder (org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration.Builder)3 ModuleList (org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleList)3 Rules (org.sonarsource.sonarlint.core.proto.Sonarlint.Rules)3 InputStream (java.io.InputStream)2 PipedInputStream (java.io.PipedInputStream)2 PipedOutputStream (java.io.PipedOutputStream)2 ValuesWsResponse (org.sonarqube.ws.Settings.ValuesWsResponse)2 GlobalProperties (org.sonarsource.sonarlint.core.proto.Sonarlint.GlobalProperties)2