|
13 | 13 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
14 | 14 |
|
15 | 15 | import java.io.File;
|
| 16 | +import java.nio.charset.Charset; |
16 | 17 | import java.util.List;
|
17 | 18 | import java.util.concurrent.CompletableFuture;
|
18 | 19 | import java.util.concurrent.TimeUnit;
|
19 | 20 |
|
| 21 | +import org.apache.commons.io.FileUtils; |
20 | 22 | import org.eclipse.lsp4j.Diagnostic;
|
21 | 23 | import org.eclipse.lsp4j.PublishDiagnosticsParams;
|
22 | 24 | import org.eclipse.lsp4j.TextDocumentIdentifier;
|
|
31 | 33 | import org.springframework.ide.vscode.boot.bootiful.BootLanguageServerTest;
|
32 | 34 | import org.springframework.ide.vscode.boot.bootiful.SymbolProviderTestConf;
|
33 | 35 | import org.springframework.ide.vscode.boot.java.SpringAotJavaProblemType;
|
| 36 | +import org.springframework.ide.vscode.boot.java.utils.test.TestFileScanListener; |
34 | 37 | import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
|
35 | 38 | import org.springframework.ide.vscode.commons.languageserver.util.Settings;
|
| 39 | +import org.springframework.ide.vscode.commons.util.UriUtil; |
36 | 40 | import org.springframework.ide.vscode.project.harness.BootLanguageServerHarness;
|
37 | 41 | import org.springframework.ide.vscode.project.harness.ProjectsHarness;
|
38 | 42 | import org.springframework.test.context.junit.jupiter.SpringExtension;
|
@@ -127,24 +131,128 @@ void testBasicValidationOfAotProcessorRegisteredViaFactoriesFile() throws Except
|
127 | 131 | assertEquals(0, diagnostics.size());
|
128 | 132 | }
|
129 | 133 |
|
| 134 | + @Test |
| 135 | + @Disabled |
| 136 | + void testValidationDisappearsWhenAotProcessorAddedToFactoriesFile() throws Exception { |
| 137 | + } |
| 138 | + |
| 139 | + @Test |
| 140 | + @Disabled |
| 141 | + void testValidationAppearsWhenAotProcessorRemovedFromFactoriesFile() throws Exception { |
| 142 | + } |
| 143 | + |
130 | 144 | @Test
|
131 | 145 | void testValidationDisappearsWhenComponentAnnotationIsAdded() throws Exception {
|
132 |
| - // TODO |
| 146 | + String docUri = directory.toPath().resolve("src/main/java/org/test/aot/NotRegisteredBeanRegistrationAotProcessor.java").toUri().toString(); |
| 147 | + |
| 148 | + // now change the config class source code and update doc |
| 149 | + TestFileScanListener fileScanListener = new TestFileScanListener(); |
| 150 | + indexer.getJavaIndexer().setFileScanListener(fileScanListener); |
| 151 | + |
| 152 | + String notRegisteredSource = FileUtils.readFileToString(UriUtil.toFile(docUri), Charset.defaultCharset()); |
| 153 | + String updatedSource = notRegisteredSource.replace("public class NotRegisteredBeanRegistrationAotProcessor", |
| 154 | + "import org.springframework.stereotype.Component;\n" + |
| 155 | + "\n" + |
| 156 | + "@Component public class NotRegisteredBeanRegistrationAotProcessor"); |
| 157 | + |
| 158 | + CompletableFuture<Void> updateFuture = indexer.updateDocument(docUri, updatedSource, "test triggered"); |
| 159 | + updateFuture.get(5, TimeUnit.SECONDS); |
| 160 | + |
| 161 | + // check if the bean registrar files have been re-scanned |
| 162 | + fileScanListener.assertScannedUri(docUri, 1); |
| 163 | + fileScanListener.assertFileScanCount(1); |
| 164 | + |
| 165 | + // check diagnostics result |
| 166 | + PublishDiagnosticsParams diagnosticsResult = harness.getDiagnostics(docUri); |
| 167 | + List<Diagnostic> diagnostics = diagnosticsResult.getDiagnostics(); |
| 168 | + assertEquals(0, diagnostics.size()); |
133 | 169 | }
|
134 | 170 |
|
135 | 171 | @Test
|
136 | 172 | void testValidationAppearsWhenComponentAnnotationIsRemoved() throws Exception {
|
137 |
| - // TODO |
| 173 | + String docUri = directory.toPath().resolve("src/main/java/org/test/aot/RegisteredAsComponentBeanRegistrationAotProcessor.java").toUri().toString(); |
| 174 | + |
| 175 | + // now change the config class source code and update doc |
| 176 | + TestFileScanListener fileScanListener = new TestFileScanListener(); |
| 177 | + indexer.getJavaIndexer().setFileScanListener(fileScanListener); |
| 178 | + |
| 179 | + String registeredSource = FileUtils.readFileToString(UriUtil.toFile(docUri), Charset.defaultCharset()); |
| 180 | + String updatedSource = registeredSource.replace("@Component", ""); |
| 181 | + |
| 182 | + CompletableFuture<Void> updateFuture = indexer.updateDocument(docUri, updatedSource, "test triggered"); |
| 183 | + updateFuture.get(5, TimeUnit.SECONDS); |
| 184 | + |
| 185 | + // check if the bean registrar files have been re-scanned |
| 186 | + fileScanListener.assertScannedUri(docUri, 1); |
| 187 | + fileScanListener.assertFileScanCount(1); |
| 188 | + |
| 189 | + // check diagnostics result |
| 190 | + PublishDiagnosticsParams diagnosticsResult = harness.getDiagnostics(docUri); |
| 191 | + List<Diagnostic> diagnostics = diagnosticsResult.getDiagnostics(); |
| 192 | + assertEquals(1, diagnostics.size()); |
| 193 | + assertEquals(SpringAotJavaProblemType.JAVA_BEAN_NOT_REGISTERED_IN_AOT.getCode(), diagnostics.get(0).getCode().getLeft()); |
138 | 194 | }
|
139 | 195 |
|
140 | 196 | @Test
|
141 | 197 | void testValidationDisappearsWhenBeanMethodIsAddedToConfig() throws Exception {
|
142 |
| - // TODO |
| 198 | + String docUri = directory.toPath().resolve("src/main/java/org/test/aot/NotRegisteredBeanRegistrationAotProcessor.java").toUri().toString(); |
| 199 | + String alreadyRegisteredViaCondigDocUri = directory.toPath().resolve("src/main/java/org/test/aot/RegistetedViaConfigBeanRegistrationAotProcessor.java").toUri().toString(); |
| 200 | + String configDocUri = directory.toPath().resolve("src/main/java/org/test/aot/Config.java").toUri().toString(); |
| 201 | + |
| 202 | + // now change the config class source code and update doc |
| 203 | + TestFileScanListener fileScanListener = new TestFileScanListener(); |
| 204 | + indexer.getJavaIndexer().setFileScanListener(fileScanListener); |
| 205 | + |
| 206 | + String configSource = FileUtils.readFileToString(UriUtil.toFile(configDocUri), Charset.defaultCharset()); |
| 207 | + String updatedConfigSource = configSource.replace("@Bean", """ |
| 208 | + @Bean |
| 209 | + NotRegisteredBeanRegistrationAotProcessor registeredViaConfigAotProcessor2() { |
| 210 | + return new NotRegisteredBeanRegistrationAotProcessor(); |
| 211 | + } |
| 212 | +
|
| 213 | + @Bean |
| 214 | + """); |
| 215 | + |
| 216 | + CompletableFuture<Void> updateFuture = indexer.updateDocument(configDocUri, updatedConfigSource, "test triggered"); |
| 217 | + updateFuture.get(5, TimeUnit.SECONDS); |
| 218 | + |
| 219 | + // check if the bean registrar files have been re-scanned |
| 220 | + fileScanListener.assertScannedUri(configDocUri, 1); |
| 221 | + fileScanListener.assertScannedUri(docUri, 1); |
| 222 | + fileScanListener.assertScannedUri(alreadyRegisteredViaCondigDocUri, 1); // because we changed the config class that refers to this one as well |
| 223 | + fileScanListener.assertFileScanCount(3); |
| 224 | + |
| 225 | + // check diagnostics result |
| 226 | + PublishDiagnosticsParams diagnosticsResult = harness.getDiagnostics(docUri); |
| 227 | + List<Diagnostic> diagnostics = diagnosticsResult.getDiagnostics(); |
| 228 | + assertEquals(0, diagnostics.size()); |
143 | 229 | }
|
144 | 230 |
|
145 | 231 | @Test
|
146 | 232 | void testValidationAppearsWhenBeanMethodIsRemovedFromConfig() throws Exception {
|
147 |
| - // TODO |
| 233 | + String docUri = directory.toPath().resolve("src/main/java/org/test/aot/RegistetedViaConfigBeanRegistrationAotProcessor.java").toUri().toString(); |
| 234 | + String configDocUri = directory.toPath().resolve("src/main/java/org/test/aot/Config.java").toUri().toString(); |
| 235 | + |
| 236 | + // now change the config class source code and update doc |
| 237 | + TestFileScanListener fileScanListener = new TestFileScanListener(); |
| 238 | + indexer.getJavaIndexer().setFileScanListener(fileScanListener); |
| 239 | + |
| 240 | + String configSource = FileUtils.readFileToString(UriUtil.toFile(configDocUri), Charset.defaultCharset()); |
| 241 | + String updatedConfigSource = configSource.replace("@Bean", ""); |
| 242 | + |
| 243 | + CompletableFuture<Void> updateFuture = indexer.updateDocument(configDocUri, updatedConfigSource, "test triggered"); |
| 244 | + updateFuture.get(5, TimeUnit.SECONDS); |
| 245 | + |
| 246 | + // check if the bean registrar files have been re-scanned |
| 247 | + fileScanListener.assertScannedUri(docUri, 1); |
| 248 | + fileScanListener.assertScannedUri(configDocUri, 1); |
| 249 | + fileScanListener.assertFileScanCount(2); |
| 250 | + |
| 251 | + // check diagnostics result |
| 252 | + PublishDiagnosticsParams diagnosticsResult = harness.getDiagnostics(docUri); |
| 253 | + List<Diagnostic> diagnostics = diagnosticsResult.getDiagnostics(); |
| 254 | + assertEquals(1, diagnostics.size()); |
| 255 | + assertEquals(SpringAotJavaProblemType.JAVA_BEAN_NOT_REGISTERED_IN_AOT.getCode(), diagnostics.get(0).getCode().getLeft()); |
148 | 256 | }
|
149 |
| - |
| 257 | + |
150 | 258 | }
|
0 commit comments