Skip to content

Commit

Permalink
SLLS-85 get remote projects request
Browse files Browse the repository at this point in the history
  • Loading branch information
sophio-japharidze-sonarsource committed Aug 3, 2022
1 parent 8ed1e26 commit 3441997
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,25 @@ public void setConnectionId(String connectionId) {
}
}

@JsonRequest("sonarlint/getRemoteProjectsForConnection")
CompletableFuture<Map<String, String>> getRemoteProjectsForConnection(GetRemoteProjectsForConnectionParams getRemoteProjectsForConnectionParams);

class GetRemoteProjectsForConnectionParams {
private String connectionId;

public GetRemoteProjectsForConnectionParams(String connectionId) {
this.connectionId = connectionId;
}

public String getConnectionId() {
return connectionId;
}

public void setConnectionId(String connectionId) {
this.connectionId = connectionId;
}
}

class DidClasspathUpdateParams {

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,12 @@ public CompletableFuture<ConnectionCheckResult> checkConnection(ConnectionCheckP
return CompletableFuture.completedFuture(failure(connectionId, String.format("Connection '%s' is unknown", connectionId)));
}

@Override
public CompletableFuture<Map<String, String>> getRemoteProjectsForConnection(GetRemoteProjectsForConnectionParams getRemoteProjectsForConnectionParams) {
return CompletableFuture.completedFuture(
bindingManager.getRemoteProjects(getRemoteProjectsForConnectionParams.getConnectionId()));
}

@Override
public void onTokenUpdate() {
SonarLintLogger.get().info("Updating configuration on token change.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;

import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.DiagnosticSeverity;
import org.eclipse.lsp4j.ExecuteCommandParams;
Expand All @@ -33,6 +35,7 @@
import org.junit.jupiter.api.io.TempDir;
import org.sonar.scanner.protocol.Constants.Severity;
import org.sonar.scanner.protocol.input.ScannerInput;
import org.sonarsource.sonarlint.ls.SonarLintExtendedLanguageServer;
import org.sonarsource.sonarlint.ls.SonarLintExtendedLanguageServer.GetRemoteProjectsNamesParams;
import org.sonarsource.sonarlint.shaded.org.sonarqube.ws.Common;
import org.sonarsource.sonarlint.shaded.org.sonarqube.ws.Components;
Expand All @@ -49,9 +52,7 @@
import org.sonarsource.sonarlint.shaded.org.sonarqube.ws.Settings;
import testutils.MockWebServerExtension;

import static org.assertj.core.api.Assertions.as;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.groups.Tuple.tuple;

class ConnectedModeMediumTests extends AbstractLanguageServerMediumTests {
Expand Down Expand Up @@ -204,4 +205,27 @@ void shouldThrowGettingServerNamesForUnknownConnection() throws Exception {
var future = lsProxy.getRemoteProjectNames(params);
awaitUntilAsserted(() -> assertThat(future).isCompletedExceptionally());
}

@Test
void shouldReturnRemoteProjectsForKnownConnection() throws ExecutionException, InterruptedException {
SonarLintExtendedLanguageServer.GetRemoteProjectsForConnectionParams testParams = new SonarLintExtendedLanguageServer.GetRemoteProjectsForConnectionParams(CONNECTION_ID);
var result = lsProxy.getRemoteProjectsForConnection(testParams);

var actual = result.get();
awaitUntilAsserted(() -> assertThat(actual)
.isNotNull()
.hasSize(2)
.containsKey(PROJECT_KEY1)
.containsKey(PROJECT_KEY2)
.containsValue(PROJECT_NAME1)
.containsValue(PROJECT_NAME2));
}

@Test
void shouldThrowExceptionForUnknownConnection() {
SonarLintExtendedLanguageServer.GetRemoteProjectsForConnectionParams testParams = new SonarLintExtendedLanguageServer.GetRemoteProjectsForConnectionParams("random_string");
var future = lsProxy.getRemoteProjectsForConnection(testParams);

awaitUntilAsserted(() -> assertThat(future).isCompletedExceptionally());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,17 @@ void shouldUpdateConfigurationOnTokenChange() {
client.logs.clear();
}

@Test
void shouldSetConnectionIdForGetRemoteProjectsParams() {
String OLD = "old";
String NEW = "new";

SonarLintExtendedLanguageServer.GetRemoteProjectsForConnectionParams testParams = new SonarLintExtendedLanguageServer.GetRemoteProjectsForConnectionParams(OLD);
testParams.setConnectionId(NEW);

assertThat(testParams.getConnectionId()).isEqualTo(NEW);
}

@Override
protected void setUpFolderSettings(Map<String, Map<String, Object>> folderSettings){
addSonarQubeConnection(client.globalSettings, CONNECTION_ID, mockWebServerExtension.url("/"), TOKEN);
Expand Down

0 comments on commit 3441997

Please sign in to comment.