Add some test for '//' workspace symbols

Fix a small bug in the process too (the case without paths).
This commit is contained in:
Kris De Volder
2019-04-01 16:15:23 -07:00
parent 8468c7d67e
commit 4ed167aaae
3 changed files with 122 additions and 6 deletions

View File

@@ -11,9 +11,7 @@
package org.springframework.ide.vscode.boot.java.requestmapping;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.Position;
@@ -24,6 +22,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ide.vscode.boot.java.handlers.RunningAppProvider;
import org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp;
import org.springframework.ide.vscode.commons.boot.app.cli.requestmappings.RequestMapping;
/**
* @author Martin Lippert
@@ -49,10 +48,20 @@ public class LiveAppURLSymbolProvider {
String host = app.getHost();
String port = app.getPort();
String contextPath = app.getContextPath();
Stream<String> urls = app.getRequestMappings().stream()
.flatMap(rm -> Arrays.stream(rm.getSplitPath()))
.map(path -> UrlUtil.createUrl(urlScheme, host, port, path, contextPath));
urls.forEach(url -> result.add(new SymbolInformation(url, SymbolKind.Method, new Location(url, new Range(new Position(0, 0), new Position(0, 1))))));
for (RequestMapping rm : app.getRequestMappings()) {
String[] paths = rm.getSplitPath();
if (paths==null || paths.length==0) {
//Technically, this means the path 'predicate' is unconstrained, meaning any path matches.
//So this is not quite the same as the case where path=""... but...
//It is better for us to show one link where any path is allowed, versus showing no links where any link is allowed.
//So we'll pretend this is the same as path="" as that gives a working link.
paths = new String[] {""};
}
for (String path : paths) {
String url = UrlUtil.createUrl(urlScheme, host, port, path, contextPath);
result.add(new SymbolInformation(url, SymbolKind.Method, new Location(url, new Range(new Position(0, 0), new Position(0, 1)))));
}
}
}
catch (Exception e) {
log.error("", e);

View File

@@ -0,0 +1,91 @@
package org.springframework.ide.vscode.boot.test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Import;
import org.springframework.ide.vscode.boot.bootiful.BootLanguageServerTest;
import org.springframework.ide.vscode.boot.bootiful.HoverTestConf;
import org.springframework.ide.vscode.languageserver.testharness.LanguageServerHarness;
import org.springframework.ide.vscode.project.harness.MockRequestMapping;
import org.springframework.ide.vscode.project.harness.MockRunningAppProvider;
import org.springframework.test.context.junit4.SpringRunner;
import com.google.common.collect.ImmutableList;
@RunWith(SpringRunner.class)
@BootLanguageServerTest
@Import(HoverTestConf.class)
public class DynamicRequestMappingSymbolTest {
@Autowired LanguageServerHarness harness;
@Autowired MockRunningAppProvider mockApps;
@Test
public void runningAppProviderRequestMappingSymbol() throws Exception {
mockApps.builder()
.isSpringBootApp(true)
.port("1111")
.processId("22022")
.host("cfapps.io")
.urlScheme("https")
.processName("test-request-mapping-live-hover")
.requestMappings(ImmutableList.of(
new MockRequestMapping()
.className("example.HelloWorldController")
.methodName("sayHello")
.methodParams("java.lang.String")
.paths("/blah")
))
.build();
harness.assertWorkspaceSymbols("//",
"https://cfapps.io:1111/blah"
);
}
@Test
public void noPaths() throws Exception {
mockApps.builder()
.isSpringBootApp(true)
.port("1111")
.processId("22022")
.host("cfapps.io")
.urlScheme("https")
.processName("test-request-mapping-live-hover")
.requestMappings(ImmutableList.of(
new MockRequestMapping()
.className("example.HelloWorldController")
.methodName("sayHello")
.methodParams("java.lang.String")
.paths()
))
.build();
harness.assertWorkspaceSymbols("//",
"https://cfapps.io:1111/"
);
}
@Test
public void multiplePaths() throws Exception {
mockApps.builder()
.isSpringBootApp(true)
.port("80")
.processId("22022")
.host("localhost")
.urlScheme("http")
.processName("test-request-mapping-live-hover")
.requestMappings(ImmutableList.of(
new MockRequestMapping()
.className("example.HelloWorldController")
.methodName("sayHello")
.methodParams("java.lang.String")
.paths("foo", "/bar")
))
.build();
harness.assertWorkspaceSymbols("//",
"http://localhost/foo",
"http://localhost/bar"
);
}
}