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"));
}
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);
}
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);
}
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"));
}
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");
}
Aggregations