use of org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient in project sonarlint-core by SonarSource.
the class SettingsDownloaderTest method testFetchProjectSettings.
@Test
public void testFetchProjectSettings() throws Exception {
SonarLintWsClient wsClient = WsClientTestUtils.createMock();
Settings.FieldValues.Value.Builder valuesBuilder = Value.newBuilder();
valuesBuilder.getMutableValue().put("filepattern", "**/*.xml");
valuesBuilder.getMutableValue().put("rulepattern", "*:S12345");
Value value1 = valuesBuilder.build();
valuesBuilder.clear();
valuesBuilder.getMutableValue().put("filepattern", "**/*.java");
valuesBuilder.getMutableValue().put("rulepattern", "*:S456");
Value value2 = valuesBuilder.build();
ValuesWsResponse response = ValuesWsResponse.newBuilder().addSettings(Setting.newBuilder().setKey("sonar.inclusions").setValues(Values.newBuilder().addValues("**/*.java"))).addSettings(Setting.newBuilder().setKey("sonar.java.fileSuffixes").setValue("*.java")).addSettings(Setting.newBuilder().setKey("sonar.issue.exclusions.multicriteria").setFieldValues(FieldValues.newBuilder().addFieldValues(value1).addFieldValues(value2)).build()).build();
PipedInputStream in = new PipedInputStream();
final PipedOutputStream out = new PipedOutputStream(in);
response.writeTo(out);
out.close();
WsClientTestUtils.addResponse(wsClient, "/api/settings/values.protobuf?component=foo", in);
Builder builder = ModuleConfiguration.newBuilder();
new SettingsDownloader(wsClient).fetchProjectSettings("6.3", "foo", null, builder);
assertThat(builder.getPropertiesMap()).containsOnly(entry("sonar.inclusions", "**/*.java"), entry("sonar.java.fileSuffixes", "*.java"), entry("sonar.issue.exclusions.multicriteria", "1,2"), entry("sonar.issue.exclusions.multicriteria.1.filepattern", "**/*.xml"), entry("sonar.issue.exclusions.multicriteria.1.rulepattern", "*:S12345"), entry("sonar.issue.exclusions.multicriteria.2.filepattern", "**/*.java"), entry("sonar.issue.exclusions.multicriteria.2.rulepattern", "*:S456"));
}
use of org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient in project sonarlint-core by SonarSource.
the class SettingsDownloaderTest method testFetchProjectProperties_exclude_global_props.
@Test
public void testFetchProjectProperties_exclude_global_props() 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().putProperties("sonar.inclusions", "**/*.java").build(), builder);
assertThat(builder.getPropertiesMap()).containsOnly(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_authentication_ok.
@Test
public void test_authentication_ok() {
SonarLintWsClient wsClient = WsClientTestUtils.createMockWithResponse("api/authentication/validate?format=json", "{\"valid\": true}");
AuthenticationChecker checker = new AuthenticationChecker(wsClient);
ValidationResult validationResult = checker.validateCredentials();
assertThat(validationResult.success()).isTrue();
assertThat(validationResult.message()).isEqualTo("Authentication successful");
}
use of org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient in project sonarlint-core by SonarSource.
the class ServerVersionAndStatusCheckerTest method failWhenIncompatibleVersion.
@Test
public void failWhenIncompatibleVersion() throws Exception {
SonarLintWsClient wsClient = WsClientTestUtils.createMockWithResponse("api/system/status", "{\"id\": \"20160308094653\",\"version\": \"4.5\",\"status\": \"UP\"}");
ServerVersionAndStatusChecker checker = new ServerVersionAndStatusChecker(wsClient);
try {
checker.checkVersionAndStatus();
fail("Expected exception");
} catch (Exception e) {
assertThat(e).isExactlyInstanceOf(UnsupportedServerException.class).hasMessage("SonarQube server has version 4.5. Version should be greater or equal to 5.6");
}
}
use of org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient in project sonarlint-core by SonarSource.
the class ServerVersionAndStatusCheckerTest method report_original_error_if_fallback_failed.
@Test
public void report_original_error_if_fallback_failed() throws Exception {
SonarLintWsClient wsClient = WsClientTestUtils.createMock();
WsClientTestUtils.addFailedResponse(wsClient, "api/system/status", HttpURLConnection.HTTP_NOT_FOUND, "Not found");
WsClientTestUtils.addFailedResponse(wsClient, "api/server/version", HttpURLConnection.HTTP_UNAUTHORIZED, "Unauthorized");
ServerVersionAndStatusChecker checker = new ServerVersionAndStatusChecker(wsClient);
try {
checker.checkVersionAndStatus();
fail("Expected exception");
} catch (Exception e) {
assertThat(e).isExactlyInstanceOf(NotFoundException.class).hasMessage("Error 404 on api/system/status");
}
}
Aggregations