Merge branch 'master' of github.com:spring-projects/sts4
This commit is contained in:
@@ -1 +1,2 @@
|
||||
bin.includes = feature.xml
|
||||
bin.includes = feature.xml,\
|
||||
p2.inf
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
# tell pde.build not to generate start levels
|
||||
org.eclipse.pde.build.append.startlevels=false
|
||||
|
||||
# add requirement on org.eclipse.platform.ide
|
||||
requires.1.namespace=org.eclipse.equinox.p2.iu
|
||||
requires.1.name=org.eclipse.platform.ide
|
||||
requires.1.greedy=true
|
||||
@@ -14,3 +14,4 @@ Bundle-ActivationPolicy: lazy
|
||||
Import-Package: org.eclipse.core.runtime,
|
||||
org.eclipse.osgi.service.datalocation,
|
||||
org.osgi.framework
|
||||
Eclipse-BundleShape: dir
|
||||
|
||||
@@ -7,25 +7,28 @@
|
||||
|
||||
<launcherArgs>
|
||||
<programArgs>-product org.springframework.boot.ide.branding.sts4
|
||||
--launcher.defaultAction
|
||||
openFile</programArgs>
|
||||
--launcher.defaultAction openFile
|
||||
</programArgs>
|
||||
<vmArgs>-Dosgi.requiredJavaVersion=1.8
|
||||
-Xms256m
|
||||
-Xmx1024m
|
||||
-XX:+UseG1GC
|
||||
-XX:+UseStringDeduplication
|
||||
--add-modules=ALL-SYSTEM
|
||||
-Xms40m</vmArgs>
|
||||
<vmArgsMac>-XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts -Xdock:icon=../Resources/sts4.icns
|
||||
<argsX86_64>-Xmx1200m</argsX86_64>
|
||||
</vmArgs>
|
||||
<vmArgsLin>
|
||||
</vmArgsLin>
|
||||
<vmArgsMac>-XstartOnFirstThread
|
||||
-Dorg.eclipse.swt.internal.carbon.smallFonts -Xdock:icon=../Resources/sts4.icns
|
||||
</vmArgsMac>
|
||||
<vmArgsWin>
|
||||
<argsX86_64>-Xmx1200m</argsX86_64>
|
||||
</vmArgsWin>
|
||||
<vmArgsLin>
|
||||
<argsX86_64>-Xmx1200m</argsX86_64>
|
||||
</vmArgsLin>
|
||||
</launcherArgs>
|
||||
|
||||
<windowImages i16="/org.springframework.boot.ide.branding/sts4-16.png" i32="/org.springframework.boot.ide.branding/sts4-32.png" i48="/orgorg.springframework.boot.ide.branding/sts4-48.png" i64="/org.springframework.boot.ide.branding/sts4-64.png" i128="/org.springframework.boot.ide.branding/sts4-128.png"/>
|
||||
|
||||
<splash
|
||||
location="org.springframework.boot.ide.branding"
|
||||
startupProgressRect="0,225,455,15"
|
||||
startupMessageRect="7,220,441,20"
|
||||
startupForegroundColor="c1d72e" />
|
||||
@@ -40,8 +43,8 @@ openFile</programArgs>
|
||||
<linux icon="../org.springframework.boot.ide.branding/sts4.xpm"/>
|
||||
</launcher>
|
||||
|
||||
<vm>
|
||||
</vm>
|
||||
<plugins>
|
||||
</plugins>
|
||||
|
||||
<features>
|
||||
<feature id="org.eclipse.platform" installMode="root"/>
|
||||
@@ -95,20 +98,13 @@ openFile</programArgs>
|
||||
|
||||
<feature id="org.springframework.tooling.bosh.ls.feature" installMode="root"/>
|
||||
<feature id="org.springframework.tooling.concourse.ls.feature" installMode="root"/>
|
||||
|
||||
</features>
|
||||
|
||||
|
||||
<configurations>
|
||||
<property name="eclipse.buildId" value="${unqualifiedVersion}.${buildQualifier}"/>
|
||||
<property name="osgi.instance.area.default" value="@user.home/Documents/workspace-spring-tool-suite-4-${unqualifiedVersion}.${p2.qualifier}"/>
|
||||
<property name="osgi.splashPath" value="platform:/base/plugins/org.springframework.boot.ide.branding"/>
|
||||
|
||||
<plugin id="org.eclipse.core.runtime" autoStart="true" startLevel="4" />
|
||||
<plugin id="org.eclipse.equinox.common" autoStart="true" startLevel="2" />
|
||||
<plugin id="org.eclipse.equinox.ds" autoStart="true" startLevel="2" />
|
||||
<plugin id="org.eclipse.equinox.simpleconfigurator" autoStart="true" startLevel="1" />
|
||||
<plugin id="org.eclipse.equinox.p2.reconciler.dropins" autoStart="true" startLevel="4" />
|
||||
<plugin id="org.eclipse.update.configurator" autoStart="false" startLevel="4" />
|
||||
</configurations>
|
||||
|
||||
|
||||
</product>
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
package org.springframework.ide.vscode.commons.boot.app.cli;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
@@ -26,57 +25,37 @@ public class ContextPath {
|
||||
protected static Logger logger = LoggerFactory.getLogger(ContextPath.class);
|
||||
|
||||
public static final Collection<String> BOOT_1X_CONTEXTPATH = ImmutableList.of("server.context-path",
|
||||
"server.contextPath");
|
||||
"server.contextPath", "SERVER_CONTEXT_PATH");
|
||||
|
||||
public static final Collection<String> BOOT_2X_CONTEXTPATH = ImmutableList.of("server.servlet.context-path",
|
||||
"server.servlet.contextPath");
|
||||
"server.servlet.contextPath", "SERVER_SERVLET_CONTEXT_PATH");
|
||||
|
||||
public static String getContextPath(String bootVersion, String environment) {
|
||||
|
||||
String contextPath = null;
|
||||
if (environment != null) {
|
||||
JSONObject env = new JSONObject(environment);
|
||||
|
||||
Collection<String> contextPathProperties = null;
|
||||
if ("1.x".equals(bootVersion)) {
|
||||
contextPathProperties = BOOT_1X_CONTEXTPATH;
|
||||
contextPath = findContextPathInBoot1x(env);
|
||||
} else if ("2.x".equals(bootVersion)) {
|
||||
contextPathProperties = BOOT_2X_CONTEXTPATH;
|
||||
}
|
||||
|
||||
if (contextPathProperties != null) {
|
||||
for (String prop : contextPathProperties) {
|
||||
String contextPath = findContextPath(env, prop);
|
||||
if (StringUtil.hasText(contextPath)) {
|
||||
return contextPath;
|
||||
}
|
||||
}
|
||||
contextPath = findContextPathInBoot2x(env);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String findContextPath(JSONObject env, String contextPathProp) {
|
||||
String contextPath = null;
|
||||
if (env != null) {
|
||||
// Properties defined in command line args have higher priority over
|
||||
// those defined in application configuration files (properties/yaml files)
|
||||
contextPath = findInCommandLineArgs(env, contextPathProp);
|
||||
if (contextPath == null) {
|
||||
contextPath = findInApplicationConfig(env, contextPathProp);
|
||||
}
|
||||
}
|
||||
return contextPath;
|
||||
}
|
||||
|
||||
private static String findInApplicationConfig(JSONObject env, String contextPathProp) {
|
||||
// boot 1.x
|
||||
JSONObject applicationConfig = null;
|
||||
private static String findContextPathInBoot1x(JSONObject env) {
|
||||
// IMPORTANT: The order in which the env objects appear are assumed to be the
|
||||
// priority order defined
|
||||
// by boot rules in terms of which property source has higher precedence. Iterate
|
||||
// through ALL
|
||||
// sources in the order obtained from the env JSON
|
||||
for (String key : env.keySet()) {
|
||||
if (key.startsWith("applicationConfig")) {
|
||||
applicationConfig = env.getJSONObject(key);
|
||||
if (applicationConfig != null) {
|
||||
String contextPathValue = applicationConfig.optString(contextPathProp);
|
||||
JSONObject jsonObj = env.optJSONObject(key);
|
||||
if (jsonObj != null) {
|
||||
for (String prop : BOOT_1X_CONTEXTPATH) {
|
||||
String contextPathValue = jsonObj.optString(prop);
|
||||
// Warning: fetching value above may return empty string, so null check on the
|
||||
// value is not enough
|
||||
if (StringUtil.hasText(contextPathValue)) {
|
||||
@@ -85,70 +64,27 @@ public class ContextPath {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// boot 2.x
|
||||
if (applicationConfig == null) {
|
||||
// Not found as direct property value... in Boot 2.0 we must look inside the
|
||||
// 'propertySources'.
|
||||
// Similar... but structure is more complex.
|
||||
JSONArray propertySources = env.optJSONArray("propertySources");
|
||||
if (propertySources != null) {
|
||||
for (Object _source : propertySources) {
|
||||
if (_source instanceof JSONObject) {
|
||||
JSONObject source = (JSONObject) _source;
|
||||
String sourceName = source.optString("name");
|
||||
if (sourceName != null && sourceName.startsWith("applicationConfig")) {
|
||||
JSONObject props = source.optJSONObject("properties");
|
||||
Set<String> keySet = props.keySet();
|
||||
// Check that the context is a key before retrieving the JSON object value.
|
||||
// Note: attempting to fetch the JSON object value on a key that may not exist
|
||||
// throws exception
|
||||
// thus the reason why we are checking that the key exists first
|
||||
if (keySet.contains(contextPathProp)) {
|
||||
JSONObject jsonObject = props.getJSONObject(contextPathProp);
|
||||
if (jsonObject != null) {
|
||||
String contextPathValue = jsonObject.optString("value");
|
||||
if (StringUtil.hasText(contextPathValue)) {
|
||||
return contextPathValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static String findInCommandLineArgs(JSONObject env, String contextPathProp) {
|
||||
// boot 1.x
|
||||
JSONObject commandLineArgs = env.optJSONObject("commandLineArgs");
|
||||
if (commandLineArgs != null) {
|
||||
String contextPathValue = commandLineArgs.optString(contextPathProp);
|
||||
// Warning: fetching value above may return empty string, so null check on the
|
||||
// value is not enough
|
||||
if (StringUtil.hasText(contextPathValue)) {
|
||||
return contextPathValue;
|
||||
}
|
||||
}
|
||||
// boot 2.x
|
||||
if (commandLineArgs == null) {
|
||||
// Not found as direct property value... in Boot 2.0 we must look inside the
|
||||
// 'propertySources'.
|
||||
// Similar... but structure is more complex.
|
||||
JSONArray propertySources = env.optJSONArray("propertySources");
|
||||
if (propertySources != null) {
|
||||
for (Object _source : propertySources) {
|
||||
if (_source instanceof JSONObject) {
|
||||
JSONObject source = (JSONObject) _source;
|
||||
String sourceName = source.optString("name");
|
||||
if ("commandLineArgs".equals(sourceName)) {
|
||||
JSONObject props = source.optJSONObject("properties");
|
||||
// Find the contextPathProp in the command line args
|
||||
JSONObject valueObject = props.optJSONObject(contextPathProp);
|
||||
if (valueObject != null) {
|
||||
String contextPathValue = valueObject.optString("value");
|
||||
private static String findContextPathInBoot2x(JSONObject env) {
|
||||
JSONArray propertySources = env.optJSONArray("propertySources");
|
||||
if (propertySources != null) {
|
||||
|
||||
// IMPORTANT: The order in which the env objects appear are assumed to be the
|
||||
// priority order defined
|
||||
// by boot rules in terms of which property source has higher precedence. Iterate
|
||||
// through ALL
|
||||
// sources in the order obtained from the env JSON
|
||||
for (Object _source : propertySources) {
|
||||
if (_source instanceof JSONObject) {
|
||||
JSONObject source = (JSONObject) _source;
|
||||
JSONObject props = source.optJSONObject("properties");
|
||||
if (props != null) {
|
||||
for (String property : BOOT_2X_CONTEXTPATH) {
|
||||
JSONObject propertyObj = props.optJSONObject(property);
|
||||
if (propertyObj != null) {
|
||||
String contextPathValue = propertyObj.optString("value");
|
||||
if (StringUtil.hasText(contextPathValue)) {
|
||||
return contextPathValue;
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -326,87 +326,6 @@ public class RequestMappingLiveHoverTest {
|
||||
editor.assertNoHover("@PutMapping(\"/greetings\")");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLiveHoverHintWithContextPath() throws Exception {
|
||||
|
||||
File directory = new File(
|
||||
ProjectsHarness.class.getResource("/test-projects/test-request-mapping-live-hover/").toURI());
|
||||
String docUri = directory.toPath().resolve("src/main/java/example/HelloWorldController.java").toUri()
|
||||
.toString();
|
||||
|
||||
// Build a mock running boot app
|
||||
mockAppProvider.builder()
|
||||
.isSpringBootApp(true)
|
||||
.port("1111")
|
||||
.processId("22022")
|
||||
.host("cfapps.io")
|
||||
.contextPath("/adifferentpath")
|
||||
.processName("test-request-mapping-live-hover")
|
||||
// Ugly, but this is real JSON copied from a real live running app. We want the
|
||||
// mock app to return realistic results if possible
|
||||
.requestMappingsJson(
|
||||
"{\"/webjars/**\":{\"bean\":\"resourceHandlerMapping\"},\"/**\":{\"bean\":\"resourceHandlerMapping\"},\"/**/favicon.ico\":{\"bean\":\"faviconHandlerMapping\"},\"{[/hello-world],methods=[GET]}\":{\"bean\":\"requestMappingHandlerMapping\",\"method\":\"public example.Greeting example.HelloWorldController.sayHello(java.lang.String)\"},\"{[/goodbye]}\":{\"bean\":\"requestMappingHandlerMapping\",\"method\":\"public java.lang.String example.RestApi.goodbye()\"},\"{[/hello]}\":{\"bean\":\"requestMappingHandlerMapping\",\"method\":\"public java.lang.String example.RestApi.hello()\"},\"{[/error]}\":{\"bean\":\"requestMappingHandlerMapping\",\"method\":\"public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)\"},\"{[/error],produces=[text/html]}\":{\"bean\":\"requestMappingHandlerMapping\",\"method\":\"public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)\"}}")
|
||||
.build();
|
||||
|
||||
harness.intialize(directory);
|
||||
|
||||
Editor editor = harness.newEditorFromFileUri(docUri, LanguageId.JAVA);
|
||||
editor.assertHighlights("@RequestMapping(method=RequestMethod.GET)");
|
||||
editor.assertHoverContains("@RequestMapping(method=RequestMethod.GET)", "[http://cfapps.io:1111/adifferentpath/hello-world](http://cfapps.io:1111/adifferentpath/hello-world) \n" +
|
||||
"\n" +
|
||||
"Process [PID=22022, name=`test-request-mapping-live-hover`]");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiPathMappingWithContextPath() throws Exception {
|
||||
|
||||
File directory = new File(
|
||||
ProjectsHarness.class.getResource("/test-projects/test-request-mapping-live-hover/").toURI());
|
||||
String docUri = directory.toPath().resolve("src/main/java/example/RestApi.java").toUri()
|
||||
.toString();
|
||||
|
||||
|
||||
// Build a mock running boot app
|
||||
mockAppProvider.builder()
|
||||
.isSpringBootApp(true)
|
||||
.port("999")
|
||||
.processId("76543")
|
||||
.host("cfapps.io")
|
||||
.contextPath("/differentPaath")
|
||||
.processName("test-request-mapping-live-hover")
|
||||
// Ugly, but this is real JSON copied from a real live running app. We want the
|
||||
// mock app to return realistic results if possible
|
||||
.requestMappingsJson(
|
||||
"{\"{[/greetings || /hello],methods=[GET]}\": {\"bean\": \"requestMappingHandlerMapping\", \"method\":\"public java.lang.String com.example.RestApi.greetings()\"}}")
|
||||
. build();
|
||||
|
||||
harness.intialize(directory);
|
||||
|
||||
Editor editor = harness.newEditor(LanguageId.JAVA,
|
||||
"package com.example;\n" +
|
||||
"\n" +
|
||||
"import org.springframework.stereotype.Controller;\n" +
|
||||
"import org.springframework.web.bind.annotation.RequestMapping;\n" +
|
||||
"import org.springframework.web.bind.annotation.RequestMethod.*;\n" +
|
||||
"\n" +
|
||||
"@Controller\n" +
|
||||
"public class RestApi {\n" +
|
||||
"\n" +
|
||||
"@RequestMapping(value={\"/greetings\", \"/hello\"}, method=GET)\n" +
|
||||
"public String greetings() {\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
"}",
|
||||
docUri);
|
||||
|
||||
editor.assertHoverContains("@RequestMapping(value={\"/greetings\", \"/hello\"}, method=GET)", "[http://cfapps.io:999/differentPaath/greetings](http://cfapps.io:999/differentPaath/greetings) \n" +
|
||||
"[http://cfapps.io:999/differentPaath/hello](http://cfapps.io:999/differentPaath/hello) \n" +
|
||||
"\n" +
|
||||
"Process [PID=76543, name=`test-request-mapping-live-hover`]");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiPathMappingHoverHintMethod1() throws Exception {
|
||||
|
||||
|
||||
@@ -0,0 +1,196 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018 Pivotal, Inc.
|
||||
* 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:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.java.requestmapping.test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Before;
|
||||
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.commons.util.text.LanguageId;
|
||||
import org.springframework.ide.vscode.languageserver.testharness.Editor;
|
||||
import org.springframework.ide.vscode.project.harness.BootLanguageServerHarness;
|
||||
import org.springframework.ide.vscode.project.harness.MockRunningAppProvider;
|
||||
import org.springframework.ide.vscode.project.harness.ProjectsHarness;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@BootLanguageServerTest
|
||||
@Import(HoverTestConf.class)
|
||||
public class RequestMappingLiveHoverTestWithContextPath {
|
||||
|
||||
@Autowired BootLanguageServerHarness harness;
|
||||
@Autowired MockRunningAppProvider mockAppProvider;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
harness.useProject(ProjectsHarness.INSTANCE.mavenProject("test-request-mapping-live-hover"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testActuatorEnvOrderedPropertySourceCamelCase() throws Exception {
|
||||
// Tests an actuator env json that contains camel case context path in command line arg and application config.
|
||||
|
||||
File directory = new File(
|
||||
ProjectsHarness.class.getResource("/test-projects/test-request-mapping-live-hover/").toURI());
|
||||
String docUri = directory.toPath().resolve("src/main/java/example/HelloWorldController.java").toUri()
|
||||
.toString();
|
||||
|
||||
// Build a mock running boot app
|
||||
mockAppProvider.builder()
|
||||
.isSpringBootApp(true)
|
||||
.port("1111")
|
||||
.processId("22022")
|
||||
.host("cfapps.io")
|
||||
.processName("test-request-mapping-live-hover")
|
||||
// Ugly, but this is real JSON copied from a real live running app. We want the
|
||||
// mock app to return realistic results if possible
|
||||
.requestMappingsJson(
|
||||
"{\"/webjars/**\":{\"bean\":\"resourceHandlerMapping\"},\"/**\":{\"bean\":\"resourceHandlerMapping\"},\"/**/favicon.ico\":{\"bean\":\"faviconHandlerMapping\"},\"{[/hello-world],methods=[GET]}\":{\"bean\":\"requestMappingHandlerMapping\",\"method\":\"public example.Greeting example.HelloWorldController.sayHello(java.lang.String)\"},\"{[/goodbye]}\":{\"bean\":\"requestMappingHandlerMapping\",\"method\":\"public java.lang.String example.RestApi.goodbye()\"},\"{[/hello]}\":{\"bean\":\"requestMappingHandlerMapping\",\"method\":\"public java.lang.String example.RestApi.hello()\"},\"{[/error]}\":{\"bean\":\"requestMappingHandlerMapping\",\"method\":\"public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)\"},\"{[/error],produces=[text/html]}\":{\"bean\":\"requestMappingHandlerMapping\",\"method\":\"public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)\"}}")
|
||||
.contextPathEnvJson("2.x", AcuatorEnvTestConstants.BOOT_2x_ENV_CONTEXT_PATH_CAMEL_CASE)
|
||||
.build();
|
||||
|
||||
harness.intialize(directory);
|
||||
|
||||
Editor editor = harness.newEditorFromFileUri(docUri, LanguageId.JAVA);
|
||||
editor.assertHighlights("@RequestMapping(method=RequestMethod.GET)");
|
||||
|
||||
// test that the command line arg context path appears
|
||||
editor.assertHoverContains("@RequestMapping(method=RequestMethod.GET)", "[http://cfapps.io:1111/pathfromcommandlineargs/hello-world](http://cfapps.io:1111/pathfromcommandlineargs/hello-world) \n" +
|
||||
"\n" +
|
||||
"Process [PID=22022, name=`test-request-mapping-live-hover`]");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testActuatorEnvOrderedPropertySourceKebabCase() throws Exception {
|
||||
|
||||
// Tests an actuator env json that contains kebab case context path in command line arg and application config.
|
||||
|
||||
File directory = new File(
|
||||
ProjectsHarness.class.getResource("/test-projects/test-request-mapping-live-hover/").toURI());
|
||||
String docUri = directory.toPath().resolve("src/main/java/example/HelloWorldController.java").toUri()
|
||||
.toString();
|
||||
|
||||
// Build a mock running boot app
|
||||
mockAppProvider.builder()
|
||||
.isSpringBootApp(true)
|
||||
.port("1111")
|
||||
.processId("22022")
|
||||
.host("cfapps.io")
|
||||
.processName("test-request-mapping-live-hover")
|
||||
// Ugly, but this is real JSON copied from a real live running app. We want the
|
||||
// mock app to return realistic results if possible
|
||||
.requestMappingsJson(
|
||||
"{\"/webjars/**\":{\"bean\":\"resourceHandlerMapping\"},\"/**\":{\"bean\":\"resourceHandlerMapping\"},\"/**/favicon.ico\":{\"bean\":\"faviconHandlerMapping\"},\"{[/hello-world],methods=[GET]}\":{\"bean\":\"requestMappingHandlerMapping\",\"method\":\"public example.Greeting example.HelloWorldController.sayHello(java.lang.String)\"},\"{[/goodbye]}\":{\"bean\":\"requestMappingHandlerMapping\",\"method\":\"public java.lang.String example.RestApi.goodbye()\"},\"{[/hello]}\":{\"bean\":\"requestMappingHandlerMapping\",\"method\":\"public java.lang.String example.RestApi.hello()\"},\"{[/error]}\":{\"bean\":\"requestMappingHandlerMapping\",\"method\":\"public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)\"},\"{[/error],produces=[text/html]}\":{\"bean\":\"requestMappingHandlerMapping\",\"method\":\"public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)\"}}")
|
||||
.contextPathEnvJson("2.x", AcuatorEnvTestConstants.BOOT_2x_ENV_CONTEXT_PATH_KEBAB_CASE)
|
||||
.build();
|
||||
|
||||
harness.intialize(directory);
|
||||
|
||||
Editor editor = harness.newEditorFromFileUri(docUri, LanguageId.JAVA);
|
||||
editor.assertHighlights("@RequestMapping(method=RequestMethod.GET)");
|
||||
|
||||
// test that the command line arg context path appears
|
||||
editor.assertHoverContains("@RequestMapping(method=RequestMethod.GET)", "[http://cfapps.io:1111/pathfromcommandlineargs/hello-world](http://cfapps.io:1111/pathfromcommandlineargs/hello-world) \n" +
|
||||
"\n" +
|
||||
"Process [PID=22022, name=`test-request-mapping-live-hover`]");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testWithMockedContextPath() throws Exception {
|
||||
|
||||
File directory = new File(
|
||||
ProjectsHarness.class.getResource("/test-projects/test-request-mapping-live-hover/").toURI());
|
||||
String docUri = directory.toPath().resolve("src/main/java/example/HelloWorldController.java").toUri()
|
||||
.toString();
|
||||
|
||||
// Build a mock running boot app
|
||||
mockAppProvider.builder()
|
||||
.isSpringBootApp(true)
|
||||
.port("1111")
|
||||
.processId("22022")
|
||||
.host("cfapps.io")
|
||||
.contextPath("/adifferentpath")
|
||||
.processName("test-request-mapping-live-hover")
|
||||
// Ugly, but this is real JSON copied from a real live running app. We want the
|
||||
// mock app to return realistic results if possible
|
||||
.requestMappingsJson(
|
||||
"{\"/webjars/**\":{\"bean\":\"resourceHandlerMapping\"},\"/**\":{\"bean\":\"resourceHandlerMapping\"},\"/**/favicon.ico\":{\"bean\":\"faviconHandlerMapping\"},\"{[/hello-world],methods=[GET]}\":{\"bean\":\"requestMappingHandlerMapping\",\"method\":\"public example.Greeting example.HelloWorldController.sayHello(java.lang.String)\"},\"{[/goodbye]}\":{\"bean\":\"requestMappingHandlerMapping\",\"method\":\"public java.lang.String example.RestApi.goodbye()\"},\"{[/hello]}\":{\"bean\":\"requestMappingHandlerMapping\",\"method\":\"public java.lang.String example.RestApi.hello()\"},\"{[/error]}\":{\"bean\":\"requestMappingHandlerMapping\",\"method\":\"public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)\"},\"{[/error],produces=[text/html]}\":{\"bean\":\"requestMappingHandlerMapping\",\"method\":\"public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)\"}}")
|
||||
.build();
|
||||
|
||||
harness.intialize(directory);
|
||||
|
||||
Editor editor = harness.newEditorFromFileUri(docUri, LanguageId.JAVA);
|
||||
editor.assertHighlights("@RequestMapping(method=RequestMethod.GET)");
|
||||
editor.assertHoverContains("@RequestMapping(method=RequestMethod.GET)", "[http://cfapps.io:1111/adifferentpath/hello-world](http://cfapps.io:1111/adifferentpath/hello-world) \n" +
|
||||
"\n" +
|
||||
"Process [PID=22022, name=`test-request-mapping-live-hover`]");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiPathMockedContextPath() throws Exception {
|
||||
|
||||
File directory = new File(
|
||||
ProjectsHarness.class.getResource("/test-projects/test-request-mapping-live-hover/").toURI());
|
||||
String docUri = directory.toPath().resolve("src/main/java/example/RestApi.java").toUri()
|
||||
.toString();
|
||||
|
||||
|
||||
// Build a mock running boot app
|
||||
mockAppProvider.builder()
|
||||
.isSpringBootApp(true)
|
||||
.port("999")
|
||||
.processId("76543")
|
||||
.host("cfapps.io")
|
||||
.contextPath("/differentPaath")
|
||||
.processName("test-request-mapping-live-hover")
|
||||
// Ugly, but this is real JSON copied from a real live running app. We want the
|
||||
// mock app to return realistic results if possible
|
||||
.requestMappingsJson(
|
||||
"{\"{[/greetings || /hello],methods=[GET]}\": {\"bean\": \"requestMappingHandlerMapping\", \"method\":\"public java.lang.String com.example.RestApi.greetings()\"}}")
|
||||
. build();
|
||||
|
||||
harness.intialize(directory);
|
||||
|
||||
Editor editor = harness.newEditor(LanguageId.JAVA,
|
||||
"package com.example;\n" +
|
||||
"\n" +
|
||||
"import org.springframework.stereotype.Controller;\n" +
|
||||
"import org.springframework.web.bind.annotation.RequestMapping;\n" +
|
||||
"import org.springframework.web.bind.annotation.RequestMethod.*;\n" +
|
||||
"\n" +
|
||||
"@Controller\n" +
|
||||
"public class RestApi {\n" +
|
||||
"\n" +
|
||||
"@RequestMapping(value={\"/greetings\", \"/hello\"}, method=GET)\n" +
|
||||
"public String greetings() {\n" +
|
||||
"}\n" +
|
||||
"\n" +
|
||||
"}",
|
||||
docUri);
|
||||
|
||||
editor.assertHoverContains("@RequestMapping(value={\"/greetings\", \"/hello\"}, method=GET)", "[http://cfapps.io:999/differentPaath/greetings](http://cfapps.io:999/differentPaath/greetings) \n" +
|
||||
"[http://cfapps.io:999/differentPaath/hello](http://cfapps.io:999/differentPaath/hello) \n" +
|
||||
"\n" +
|
||||
"Process [PID=76543, name=`test-request-mapping-live-hover`]");
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -10,7 +10,6 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.project.harness;
|
||||
|
||||
import static org.mockito.Matchers.anyObject;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -19,6 +18,7 @@ import java.util.Collection;
|
||||
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.ide.vscode.boot.java.handlers.RunningAppProvider;
|
||||
import org.springframework.ide.vscode.commons.boot.app.cli.ContextPath;
|
||||
import org.springframework.ide.vscode.commons.boot.app.cli.LocalSpringBootApp;
|
||||
import org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp;
|
||||
import org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel;
|
||||
@@ -66,11 +66,6 @@ public class MockRunningAppProvider {
|
||||
this.runningAppProvider = runningAppProvider;
|
||||
}
|
||||
|
||||
public MockAppBuilder enviroment(String env) throws Exception {
|
||||
when(app.getEnvironment()).thenReturn(env);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MockAppBuilder beans(String beans) throws Exception {
|
||||
return beans(LiveBeansModel.parse(beans));
|
||||
}
|
||||
@@ -97,6 +92,12 @@ public class MockRunningAppProvider {
|
||||
return this;
|
||||
}
|
||||
|
||||
public MockAppBuilder contextPathEnvJson(String bootVersion, String envJson) throws Exception {
|
||||
String contextPath = ContextPath.getContextPath(bootVersion, envJson);
|
||||
when(app.getContextPath()).thenReturn(contextPath);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MockAppBuilder port(String port) throws Exception {
|
||||
when(app.getPort()).thenReturn(port);
|
||||
return this;
|
||||
|
||||
Reference in New Issue
Block a user