Search in sources :

Example 11 with ServerApiHelper

use of org.sonarsource.sonarlint.core.serverapi.ServerApiHelper in project sonarlint-core by SonarSource.

the class ConnectionValidatorTests method testConnectionOrganizationNotFound.

@Test
void testConnectionOrganizationNotFound() throws Exception {
    var underTest = new ConnectionValidator(new ServerApiHelper(mockServer.endpointParams("myOrg"), MockWebServerExtension.httpClient()));
    mockServer.addStringResponse("/api/system/status", "{\"id\": \"20160308094653\",\"version\": \"7.9\",\"status\": \"UP\"}");
    mockServer.addStringResponse("/api/authentication/validate?format=json", "{\"valid\": true}");
    mockServer.addResponseFromResource("/api/organizations/search.protobuf?organizations=myOrg&ps=500&p=1", "/orgs/empty.pb");
    var futureValidation = underTest.validateConnection();
    var validation = futureValidation.get();
    assertThat(validation.success()).isFalse();
    assertThat(validation.message()).isEqualTo("No organizations found for key: myOrg");
}
Also used : ServerApiHelper(org.sonarsource.sonarlint.core.serverapi.ServerApiHelper) Test(org.junit.jupiter.api.Test)

Example 12 with ServerApiHelper

use of org.sonarsource.sonarlint.core.serverapi.ServerApiHelper in project sonarlint-core by SonarSource.

the class ConnectedModeExcludeByVersionTest method dontCheckMinimalPluginVersionWhenValidatingConnection.

@Test
public void dontCheckMinimalPluginVersionWhenValidatingConnection() throws ExecutionException, InterruptedException {
    engine = createEngine(e -> e.addEnabledLanguages(Language.PYTHON));
    var result = new ConnectionValidator(new ServerApiHelper(endpointParams(ORCHESTRATOR), sqHttpClient())).validateConnection().get();
    assertThat(result.success()).isTrue();
}
Also used : BeforeClass(org.junit.BeforeClass) ValidationResult(org.sonarsource.sonarlint.core.serverapi.system.ValidationResult) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ConnectedSonarLintEngineImpl(org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl) Language(org.sonarsource.sonarlint.core.commons.Language) CreateRequest(org.sonarqube.ws.client.users.CreateRequest) ConnectedGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration) ServerApiHelper(org.sonarsource.sonarlint.core.serverapi.ServerApiHelper) ArrayList(java.util.ArrayList) UpdateResult(org.sonarsource.sonarlint.core.client.api.connected.UpdateResult) SONAR_VERSION(its.tools.ItUtils.SONAR_VERSION) ConnectionValidator(org.sonarsource.sonarlint.core.client.api.connected.ConnectionValidator) After(org.junit.After) ClassRule(org.junit.ClassRule) Path(java.nio.file.Path) ExpectedException(org.junit.rules.ExpectedException) ConnectedSonarLintEngine(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine) Before(org.junit.Before) Collections.emptySet(java.util.Collections.emptySet) MavenLocation(com.sonar.orchestrator.locator.MavenLocation) PluginDetails(org.sonarsource.sonarlint.core.client.api.common.PluginDetails) Test(org.junit.Test) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) List(java.util.List) Rule(org.junit.Rule) Assume.assumeTrue(org.junit.Assume.assumeTrue) Orchestrator(com.sonar.orchestrator.Orchestrator) TemporaryFolder(org.junit.rules.TemporaryFolder) ServerApiHelper(org.sonarsource.sonarlint.core.serverapi.ServerApiHelper) ConnectionValidator(org.sonarsource.sonarlint.core.client.api.connected.ConnectionValidator) Test(org.junit.Test)

Example 13 with ServerApiHelper

use of org.sonarsource.sonarlint.core.serverapi.ServerApiHelper in project sonarlint-core by SonarSource.

the class SonarCloudTest method testConnection.

@Test
public void testConnection() throws ExecutionException, InterruptedException {
    assertThat(new ConnectionValidator(new ServerApiHelper(sonarcloudEndpoint(SONARCLOUD_ORGANIZATION), new SonarLintHttpClientOkHttpImpl(SC_CLIENT))).validateConnection().get().success()).isTrue();
    assertThat(new ConnectionValidator(new ServerApiHelper(sonarcloudEndpoint(null), new SonarLintHttpClientOkHttpImpl(SC_CLIENT))).validateConnection().get().success()).isTrue();
    assertThat(new ConnectionValidator(new ServerApiHelper(sonarcloudEndpoint("not-exists"), new SonarLintHttpClientOkHttpImpl(SC_CLIENT))).validateConnection().get().success()).isFalse();
}
Also used : ServerApiHelper(org.sonarsource.sonarlint.core.serverapi.ServerApiHelper) ConnectionValidator(org.sonarsource.sonarlint.core.client.api.connected.ConnectionValidator) Test(org.junit.Test)

Example 14 with ServerApiHelper

use of org.sonarsource.sonarlint.core.serverapi.ServerApiHelper in project sonarlint-core by SonarSource.

the class ConnectedSonarLintEngineImpl method downloadServerIssues.

private void downloadServerIssues(EndpointParams endpoint, HttpClient client, String projectKey, boolean fetchTaintVulnerabilities, @Nullable String branchName, ProgressMonitor progress) {
    var updater = partialUpdaterFactory.create();
    var configuration = storageReader.readProjectConfig(projectKey);
    updater.updateFileIssues(new ServerApiHelper(endpoint, client), projectKey, configuration, fetchTaintVulnerabilities, branchName, progress);
}
Also used : ServerApiHelper(org.sonarsource.sonarlint.core.serverapi.ServerApiHelper)

Example 15 with ServerApiHelper

use of org.sonarsource.sonarlint.core.serverapi.ServerApiHelper in project sonarlint-core by SonarSource.

the class ConnectedSonarLintEngineImpl method sync.

@Override
public void sync(EndpointParams endpoint, HttpClient client, Set<String> projectKeys, @Nullable ClientProgressMonitor monitor) {
    var serverApi = new ServerApi(new ServerApiHelper(endpoint, client));
    var result = storageSynchronizer.synchronize(serverApi, projectKeys, new ProgressMonitor(monitor));
    if (result.hasAnalyzerBeenUpdated()) {
        restartAnalysisEngine();
    }
}
Also used : ClientProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ClientProgressMonitor) ProgressMonitor(org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor) ServerApi(org.sonarsource.sonarlint.core.serverapi.ServerApi) ServerApiHelper(org.sonarsource.sonarlint.core.serverapi.ServerApiHelper)

Aggregations

ServerApiHelper (org.sonarsource.sonarlint.core.serverapi.ServerApiHelper)18 Test (org.junit.jupiter.api.Test)10 ClientProgressMonitor (org.sonarsource.sonarlint.core.commons.progress.ClientProgressMonitor)4 ProgressMonitor (org.sonarsource.sonarlint.core.commons.progress.ProgressMonitor)4 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Test (org.junit.Test)2 PluginDetails (org.sonarsource.sonarlint.core.client.api.common.PluginDetails)2 ConnectedGlobalConfiguration (org.sonarsource.sonarlint.core.client.api.connected.ConnectedGlobalConfiguration)2 ConnectedSonarLintEngine (org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine)2 ConnectionValidator (org.sonarsource.sonarlint.core.client.api.connected.ConnectionValidator)2 UpdateResult (org.sonarsource.sonarlint.core.client.api.connected.UpdateResult)2 StorageException (org.sonarsource.sonarlint.core.client.api.exceptions.StorageException)2 Orchestrator (com.sonar.orchestrator.Orchestrator)1 MavenLocation (com.sonar.orchestrator.locator.MavenLocation)1 SONAR_VERSION (its.tools.ItUtils.SONAR_VERSION)1 Paths (java.nio.file.Paths)1 Collection (java.util.Collection)1 Collections.emptySet (java.util.Collections.emptySet)1