|
1 | 1 | /******************************************************************************* |
2 | | - * Copyright (c) 2024 Broadcom, Inc. |
| 2 | + * Copyright (c) 2024, 2025 Broadcom, Inc. |
3 | 3 | * All rights reserved. This program and the accompanying materials |
4 | 4 | * are made available under the terms of the Eclipse Public License v1.0 |
5 | 5 | * which accompanies this distribution, and is available at |
|
13 | 13 | import static org.junit.jupiter.api.Assertions.assertEquals; |
14 | 14 | import static org.junit.jupiter.api.Assertions.fail; |
15 | 15 |
|
| 16 | +import java.io.File; |
16 | 17 | import java.io.InputStream; |
17 | 18 | import java.nio.charset.Charset; |
18 | | -import java.util.Collection; |
19 | | -import java.util.Collections; |
20 | 19 | import java.util.Comparator; |
21 | 20 | import java.util.List; |
22 | | -import java.util.Optional; |
| 21 | +import java.util.concurrent.CompletableFuture; |
| 22 | +import java.util.concurrent.TimeUnit; |
23 | 23 |
|
24 | 24 | import org.apache.commons.io.IOUtils; |
25 | 25 | import org.eclipse.lsp4j.CompletionItem; |
26 | 26 | import org.eclipse.lsp4j.TextDocumentIdentifier; |
27 | | -import org.gradle.internal.impldep.com.google.common.collect.ImmutableList; |
28 | 27 | import org.junit.jupiter.api.BeforeEach; |
29 | 28 | import org.junit.jupiter.api.Test; |
30 | 29 | import org.junit.jupiter.api.extension.ExtendWith; |
31 | 30 | import org.springframework.beans.factory.annotation.Autowired; |
32 | | -import org.springframework.context.annotation.Bean; |
33 | | -import org.springframework.context.annotation.Configuration; |
34 | 31 | import org.springframework.context.annotation.Import; |
35 | | -import org.springframework.ide.vscode.boot.app.BootLanguageServerParams; |
36 | | -import org.springframework.ide.vscode.boot.bootiful.AdHocPropertyHarnessTestConf; |
| 32 | +import org.springframework.ide.vscode.boot.app.SpringSymbolIndex; |
37 | 33 | import org.springframework.ide.vscode.boot.bootiful.BootLanguageServerTest; |
38 | | -import org.springframework.ide.vscode.boot.editor.harness.AdHocPropertyHarness; |
39 | | -import org.springframework.ide.vscode.boot.editor.harness.PropertyIndexHarness; |
40 | | -import org.springframework.ide.vscode.boot.index.cache.IndexCache; |
41 | | -import org.springframework.ide.vscode.boot.index.cache.IndexCacheVoid; |
42 | | -import org.springframework.ide.vscode.boot.java.links.SourceLinkFactory; |
43 | | -import org.springframework.ide.vscode.boot.java.links.SourceLinks; |
44 | | -import org.springframework.ide.vscode.boot.java.utils.CompilationUnitCache; |
45 | | -import org.springframework.ide.vscode.boot.metadata.ValueProviderRegistry; |
46 | | -import org.springframework.ide.vscode.commons.java.IJavaProject; |
| 34 | +import org.springframework.ide.vscode.boot.bootiful.SymbolProviderTestConf; |
47 | 35 | import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder; |
48 | | -import org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver; |
49 | | -import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer; |
50 | | -import org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService; |
51 | | -import org.springframework.ide.vscode.commons.maven.java.MavenJavaProject; |
52 | 36 | import org.springframework.ide.vscode.commons.util.text.LanguageId; |
53 | 37 | import org.springframework.ide.vscode.languageserver.testharness.Editor; |
54 | 38 | import org.springframework.ide.vscode.project.harness.BootLanguageServerHarness; |
|
60 | 44 | */ |
61 | 45 | @ExtendWith(SpringExtension.class) |
62 | 46 | @BootLanguageServerTest |
63 | | -@Import({AdHocPropertyHarnessTestConf.class, ConditionalOnResourceCompletionTest.TestConf.class}) |
| 47 | +@Import(SymbolProviderTestConf.class) |
64 | 48 | public class ConditionalOnResourceCompletionTest { |
65 | 49 |
|
66 | 50 | @Autowired private BootLanguageServerHarness harness; |
67 | 51 | @Autowired private JavaProjectFinder projectFinder; |
| 52 | + @Autowired private SpringSymbolIndex indexer; |
68 | 53 |
|
69 | 54 | private Editor editor; |
70 | | - |
71 | | - @Autowired private PropertyIndexHarness indexHarness; |
72 | | - @Autowired private AdHocPropertyHarness adHocProperties; |
73 | | - |
74 | | - @Configuration |
75 | | - static class TestConf { |
76 | | - |
77 | | - @Bean MavenJavaProject testProject() throws Exception { |
78 | | - return ProjectsHarness.INSTANCE.mavenProject("test-annotation-conditionalonresource"); |
79 | | - } |
80 | | - |
81 | | - @Bean PropertyIndexHarness indexHarness(ValueProviderRegistry valueProviders) { |
82 | | - return new PropertyIndexHarness(valueProviders); |
83 | | - } |
84 | | - |
85 | | - @Bean JavaProjectFinder projectFinder(MavenJavaProject testProject) { |
86 | | - return new JavaProjectFinder() { |
87 | | - |
88 | | - @Override |
89 | | - public Optional<IJavaProject> find(TextDocumentIdentifier doc) { |
90 | | - return Optional.ofNullable(testProject); |
91 | | - } |
92 | | - |
93 | | - @Override |
94 | | - public Collection<? extends IJavaProject> all() { |
95 | | - // TODO Auto-generated method stub |
96 | | - return testProject == null ? Collections.emptyList() : ImmutableList.of(testProject); |
97 | | - } |
98 | | - }; |
99 | | - } |
100 | | - |
101 | | - @Bean BootLanguageServerHarness harness(SimpleLanguageServer server, BootLanguageServerParams serverParams, PropertyIndexHarness indexHarness, JavaProjectFinder projectFinder) throws Exception { |
102 | | - return new BootLanguageServerHarness(server, serverParams, indexHarness, projectFinder, LanguageId.JAVA, ".java"); |
103 | | - } |
104 | | - |
105 | | - @Bean BootLanguageServerParams serverParams(SimpleLanguageServer server, JavaProjectFinder projectFinder, ValueProviderRegistry valueProviders, PropertyIndexHarness indexHarness) { |
106 | | - BootLanguageServerParams testDefaults = BootLanguageServerHarness.createTestDefault(server, valueProviders); |
107 | | - return new BootLanguageServerParams( |
108 | | - projectFinder, |
109 | | - ProjectObserver.NULL, |
110 | | - indexHarness.getIndexProvider(), |
111 | | - testDefaults.typeUtilProvider |
112 | | - ); |
113 | | - } |
114 | | - |
115 | | - @Bean IndexCache symbolCache() { |
116 | | - return new IndexCacheVoid(); |
117 | | - } |
118 | | - |
119 | | - @Bean SourceLinks sourceLinks(SimpleTextDocumentService documents, CompilationUnitCache cuCache) { |
120 | | - return SourceLinkFactory.NO_SOURCE_LINKS; |
121 | | - } |
122 | | - |
123 | | - } |
| 55 | + private String testSourceUri; |
124 | 56 |
|
125 | 57 | @BeforeEach |
126 | 58 | public void setup() throws Exception { |
127 | | - IJavaProject testProject = ProjectsHarness.INSTANCE.mavenProject("test-annotation-conditionalonresource"); |
128 | | - harness.useProject(testProject); |
129 | 59 | harness.intialize(null); |
| 60 | + |
| 61 | + File directory = new File(ProjectsHarness.class.getResource("/test-projects/test-annotation-conditionalonresource/").toURI()); |
| 62 | + |
| 63 | + String projectDir = directory.toURI().toString(); |
| 64 | + projectFinder.find(new TextDocumentIdentifier(projectDir)).get(); |
| 65 | + |
| 66 | + testSourceUri = directory.toPath().resolve("src/main/java/org/test/TestConditionalOnResourceCompletion.java").toUri().toString(); |
| 67 | + |
| 68 | + CompletableFuture<Void> initProject = indexer.waitOperation(); |
| 69 | + initProject.get(5, TimeUnit.SECONDS); |
130 | 70 | } |
131 | 71 |
|
132 | 72 | @Test |
@@ -221,7 +161,7 @@ private void prepareCase(String selectedAnnotation, String annotationStatementBe |
221 | 161 | String content = IOUtils.toString(resource, Charset.defaultCharset()); |
222 | 162 |
|
223 | 163 | content = content.replace(selectedAnnotation, annotationStatementBeforeTest); |
224 | | - editor = new Editor(harness, content, LanguageId.JAVA); |
| 164 | + editor = harness.newEditor(LanguageId.JAVA, content, testSourceUri); |
225 | 165 | } |
226 | 166 |
|
227 | 167 | private void assertClasspathCompletions(String... completedAnnotations) throws Exception { |
|
0 commit comments