|
14 | 14 | import static org.junit.jupiter.api.Assertions.assertTrue; |
15 | 15 |
|
16 | 16 | import java.io.File; |
| 17 | +import java.net.URI; |
| 18 | +import java.nio.charset.Charset; |
17 | 19 | import java.util.Arrays; |
18 | 20 | import java.util.Iterator; |
19 | 21 | import java.util.List; |
20 | 22 | import java.util.concurrent.CompletableFuture; |
21 | 23 | import java.util.concurrent.TimeUnit; |
22 | 24 | import java.util.stream.Collectors; |
23 | 25 |
|
| 26 | +import org.apache.commons.io.FileUtils; |
24 | 27 | import org.eclipse.lsp4j.TextDocumentIdentifier; |
25 | 28 | import org.eclipse.lsp4j.WorkspaceSymbol; |
26 | 29 | import org.junit.jupiter.api.BeforeEach; |
|
36 | 39 | import org.springframework.ide.vscode.commons.java.IJavaProject; |
37 | 40 | import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder; |
38 | 41 | import org.springframework.ide.vscode.commons.protocol.spring.Bean; |
| 42 | +import org.springframework.ide.vscode.commons.protocol.spring.InjectionPoint; |
39 | 43 | import org.springframework.ide.vscode.commons.protocol.spring.SpringIndexElement; |
40 | 44 | import org.springframework.ide.vscode.project.harness.BootLanguageServerHarness; |
41 | 45 | import org.springframework.ide.vscode.project.harness.ProjectsHarness; |
@@ -284,6 +288,34 @@ void testNestedRoutesMappingSymbols3() throws Exception { |
284 | 288 | assertEquals("org.test.PersonHandler3", handlerElement6.getHandlerClass()); |
285 | 289 | assertEquals("public Mono<org.springframework.web.reactive.function.server.ServerResponse> deletePerson(org.springframework.web.reactive.function.server.ServerRequest)", handlerElement6.getHandlerMethod()); |
286 | 290 | } |
| 291 | + |
| 292 | + @Test |
| 293 | + void testUpdatedRouteInChangedDocument() throws Exception { |
| 294 | + // update document and update index |
| 295 | + String changedDocURI = directory.toPath().resolve("src/main/java/org/test/QuoteRouter.java").toUri().toString(); |
| 296 | + |
| 297 | + String newContent = FileUtils.readFileToString(new File(new URI(changedDocURI)), Charset.defaultCharset()).replace("/hello", "/hello-updated"); |
| 298 | + CompletableFuture<Void> updateFuture = indexer.updateDocument(changedDocURI, newContent, "test triggered"); |
| 299 | + updateFuture.get(5, TimeUnit.SECONDS); |
| 300 | + |
| 301 | + Bean[] routeBeans = springIndex.getBeansWithName(project.getElementName(), "route"); |
| 302 | + assertEquals(1, routeBeans.length); |
| 303 | + assertEquals("route", routeBeans[0].getName()); |
| 304 | + |
| 305 | + SpringIndexElement[] children = routeBeans[0].getChildren(); |
| 306 | + assertEquals(8, children.length); |
| 307 | + |
| 308 | + WebfluxHandlerMethodIndexElement handlerElement1 = getWebfluxIndexElements(children, "/hello-updated", "GET").get(0); |
| 309 | + assertEquals("/hello-updated", handlerElement1.getPath()); |
| 310 | + assertEquals("[GET]", Arrays.toString(handlerElement1.getHttpMethods())); |
| 311 | + assertEquals(0, handlerElement1.getContentTypes().length); |
| 312 | + assertEquals("[TEXT_PLAIN]", Arrays.toString(handlerElement1.getAcceptTypes())); |
| 313 | + assertEquals("org.test.QuoteHandler", handlerElement1.getHandlerClass()); |
| 314 | + assertEquals("public Mono<org.springframework.web.reactive.function.server.ServerResponse> hello(org.springframework.web.reactive.function.server.ServerRequest)", handlerElement1.getHandlerMethod()); |
| 315 | + |
| 316 | + } |
| 317 | + |
| 318 | + |
287 | 319 |
|
288 | 320 | private boolean containsSymbol(List<? extends WorkspaceSymbol> symbols, String name, String uri, int startLine, int startCHaracter, int endLine, int endCharacter) { |
289 | 321 | for (Iterator<? extends WorkspaceSymbol> iterator = symbols.iterator(); iterator.hasNext();) { |
|
0 commit comments