|
10 | 10 | *******************************************************************************/
|
11 | 11 | package org.springframework.ide.vscode.boot.index.test;
|
12 | 12 |
|
| 13 | +import static org.junit.Assert.assertTrue; |
13 | 14 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
14 | 15 |
|
15 | 16 | import java.io.File;
|
|
28 | 29 | import org.springframework.ide.vscode.boot.bootiful.BootLanguageServerTest;
|
29 | 30 | import org.springframework.ide.vscode.boot.bootiful.SymbolProviderTestConf;
|
30 | 31 | import org.springframework.ide.vscode.boot.index.SpringMetamodelIndex;
|
| 32 | +import org.springframework.ide.vscode.boot.java.Annotations; |
31 | 33 | import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
|
| 34 | +import org.springframework.ide.vscode.commons.protocol.spring.AnnotationMetadata; |
32 | 35 | import org.springframework.ide.vscode.commons.protocol.spring.Bean;
|
33 | 36 | import org.springframework.ide.vscode.commons.protocol.spring.SpringIndexElement;
|
34 | 37 | import org.springframework.ide.vscode.project.harness.BootLanguageServerHarness;
|
@@ -94,5 +97,21 @@ void testSimpleBeanRegistration() throws Exception {
|
94 | 97 | assertEquals("baz", baz.getName());
|
95 | 98 | assertEquals("com.example.Baz", baz.getType());
|
96 | 99 | }
|
| 100 | + |
| 101 | + @Test |
| 102 | + void testNonRegisteredBeanRegistrar() throws Exception { |
| 103 | + |
| 104 | + Bean[] beans = springIndex.getBeansOfProject("test-framework-7-indexing"); |
| 105 | + String registrarName = "com.example.MyBeanRegistrar"; |
| 106 | + |
| 107 | + boolean anyMatch = Arrays.stream(beans) |
| 108 | + .filter(bean -> bean.isConfiguration()) // look into beans with @Configuration only |
| 109 | + .flatMap(bean -> Arrays.stream(bean.getAnnotations())) // look into annotations on this bean definition |
| 110 | + .filter(annotation -> Annotations.IMPORT.equals(annotation.getAnnotationType())) // look into @Import annotations only |
| 111 | + .flatMap(annotation -> Arrays.stream(annotation.getAttributes().get("value"))) // look into the attribute values of "value" attribute |
| 112 | + .anyMatch(annotationValue -> annotationValue.getName().equals(registrarName)); |
| 113 | + |
| 114 | + assertTrue(anyMatch); |
| 115 | + } |
97 | 116 |
|
98 | 117 | }
|
0 commit comments