-
Notifications
You must be signed in to change notification settings - Fork 386
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
4 changed files
with
99 additions
and
0 deletions.
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
80 changes: 80 additions & 0 deletions
80
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,80 @@ | ||
/******************************************************************************* | ||
* 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.assertTrue; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
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.ExecuteCommandCapabilities; | ||
import org.eclipse.lsp4j.InitializeParams; | ||
import org.eclipse.lsp4j.InitializeResult; | ||
import org.eclipse.lsp4j.TextDocumentClientCapabilities; | ||
import org.eclipse.lsp4j.WorkspaceClientCapabilities; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mockito; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
/** | ||
* @author snjeza | ||
* | ||
*/ | ||
@RunWith(MockitoJUnitRunner.class) | ||
public class InitHandlerTest extends AbstractProjectsManagerBasedTest { | ||
|
||
protected JDTLanguageServer server; | ||
|
||
@Before | ||
public void setup() throws Exception { | ||
server = new JDTLanguageServer(projectsManager, preferenceManager); | ||
} | ||
|
||
@Test | ||
public void testExecuteCommandProvider() throws Exception { | ||
ClientPreferences mockCapabilies = Mockito.mock(ClientPreferences.class); | ||
Mockito.when(mockCapabilies.isExecuteCommandDynamicRegistrationSupported()).thenReturn(Boolean.FALSE); | ||
Mockito.when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies); | ||
InitializeResult result = initialize(false); | ||
List<String> commands = result.getCapabilities().getExecuteCommandProvider().getCommands(); | ||
assertTrue(commands.size() > 0); | ||
} | ||
|
||
@Test | ||
public void testExecuteCommandProviderDynamicRegistration() throws Exception { | ||
ClientPreferences mockCapabilies = Mockito.mock(ClientPreferences.class); | ||
Mockito.when(mockCapabilies.isExecuteCommandDynamicRegistrationSupported()).thenReturn(Boolean.TRUE); | ||
Mockito.when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies); | ||
InitializeResult result = initialize(true); | ||
assertTrue(result.getCapabilities().getExecuteCommandProvider() == null); | ||
} | ||
|
||
private InitializeResult initialize(boolean dynamicRegistration) throws InterruptedException, ExecutionException { | ||
InitializeParams params = new InitializeParams(); | ||
ClientCapabilities capabilities = new ClientCapabilities(); | ||
WorkspaceClientCapabilities workspaceCapabilities = new WorkspaceClientCapabilities(); | ||
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(); | ||
} | ||
} | ||
|