PT 161583390 - Initial implementation to support context path

Added support for context path for boot 1.x and 2.x when property
defined via command line args. Also added some relevant junits for
request mappings with context paths.
This commit is contained in:
nsingh
2018-11-08 16:10:11 -08:00
parent a9a27c6c4e
commit b41cd42741
8 changed files with 230 additions and 5 deletions

View File

@@ -326,6 +326,87 @@ 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 {

View File

@@ -92,6 +92,11 @@ public class MockRunningAppProvider {
return this;
}
public MockAppBuilder contextPath(String contextPath) throws Exception {
when(app.getContextPath()).thenReturn(contextPath);
return this;
}
public MockAppBuilder port(String port) throws Exception {
when(app.getPort()).thenReturn(port);
return this;