-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initialize ExecuteCommandProvider for the server's capabilities
Signed-off-by: Snjezana Peco <snjezana.peco@redhat.com>
- Loading branch information
Showing
6 changed files
with
144 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
org.eclipse.jdt.ls.tests/src/org/eclipse/jdt/ls/core/internal/handlers/InitHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2017 Red Hat Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.jdt.ls.core.internal.handlers; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNull; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
import org.eclipse.jdt.ls.core.internal.JavaClientConnection.JavaLanguageClient; | ||
import org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest; | ||
import org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences; | ||
import org.eclipse.lsp4j.ClientCapabilities; | ||
import org.eclipse.lsp4j.DidChangeConfigurationCapabilities; | ||
import org.eclipse.lsp4j.ExecuteCommandCapabilities; | ||
import org.eclipse.lsp4j.InitializeParams; | ||
import org.eclipse.lsp4j.InitializeResult; | ||
import org.eclipse.lsp4j.TextDocumentClientCapabilities; | ||
import org.eclipse.lsp4j.WorkspaceClientCapabilities; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
/** | ||
* @author snjeza | ||
* | ||
*/ | ||
@RunWith(MockitoJUnitRunner.class) | ||
public class InitHandlerTest extends AbstractProjectsManagerBasedTest { | ||
|
||
protected JDTLanguageServer server; | ||
|
||
@Mock | ||
private JavaLanguageClient client; | ||
|
||
@Before | ||
public void setup() throws Exception { | ||
server = new JDTLanguageServer(projectsManager, preferenceManager); | ||
server.connectClient(client); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
server.disconnectClient(); | ||
} | ||
|
||
@Test | ||
public void testExecuteCommandProvider() throws Exception { | ||
ClientPreferences mockCapabilies = mock(ClientPreferences.class); | ||
when(mockCapabilies.isExecuteCommandDynamicRegistrationSupported()).thenReturn(Boolean.FALSE); | ||
when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies); | ||
InitializeResult result = initialize(false); | ||
List<String> commands = result.getCapabilities().getExecuteCommandProvider().getCommands(); | ||
assertFalse(commands.isEmpty()); | ||
} | ||
|
||
@Test | ||
public void testExecuteCommandProviderDynamicRegistration() throws Exception { | ||
ClientPreferences mockCapabilies = mock(ClientPreferences.class); | ||
when(mockCapabilies.isExecuteCommandDynamicRegistrationSupported()).thenReturn(Boolean.TRUE); | ||
when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies); | ||
InitializeResult result = initialize(true); | ||
assertNull(result.getCapabilities().getExecuteCommandProvider()); | ||
} | ||
|
||
private InitializeResult initialize(boolean dynamicRegistration) throws InterruptedException, ExecutionException { | ||
InitializeParams params = new InitializeParams(); | ||
ClientCapabilities capabilities = new ClientCapabilities(); | ||
WorkspaceClientCapabilities workspaceCapabilities = new WorkspaceClientCapabilities(); | ||
workspaceCapabilities.setDidChangeConfiguration(new DidChangeConfigurationCapabilities(dynamicRegistration)); | ||
ExecuteCommandCapabilities executeCommand = new ExecuteCommandCapabilities(dynamicRegistration); | ||
workspaceCapabilities.setExecuteCommand(executeCommand); | ||
capabilities.setWorkspace(workspaceCapabilities); | ||
TextDocumentClientCapabilities textDocument = new TextDocumentClientCapabilities(); | ||
capabilities.setTextDocument(textDocument); | ||
params.setCapabilities(capabilities); | ||
CompletableFuture<InitializeResult> result = server.initialize(params); | ||
return result.get(); | ||
} | ||
} | ||
|