Add resource info to beans in injection reports

This commit is contained in:
Kris De Volder
2017-11-03 09:58:06 -07:00
parent 443b8ad62f
commit a70bc1a77f
15 changed files with 289 additions and 29 deletions

View File

@@ -127,8 +127,10 @@ public class AutowiredHoverProviderTest {
"\n" +
"Bean [id: autowiredClass, type: `com.example.AutowiredClass`] got autowired with:\n" +
"\n" +
"- Bean [id: dependencyA, type: `com.example.DependencyA`]\n" +
"- Bean [id: dependencyB, type: `com.example.DependencyB`]\n"
"- Bean: dependencyA \n" +
" Type: `com.example.DependencyA`\n" +
"- Bean: dependencyB \n" +
" Type: `com.example.DependencyB`\n"
);
}

View File

@@ -12,12 +12,15 @@ package org.springframework.ide.vscode.boot.java.livehover.test;
import static org.junit.Assert.assertTrue;
import java.nio.file.Path;
import java.time.Duration;
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBean;
import org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel;
import org.springframework.ide.vscode.commons.java.IJavaProject;
import org.springframework.ide.vscode.commons.maven.java.MavenJavaProject;
import org.springframework.ide.vscode.commons.util.text.LanguageId;
import org.springframework.ide.vscode.languageserver.testharness.Editor;
@@ -213,10 +216,125 @@ public class BeanInjectedIntoHoverProviderTest {
"\n" +
"Bean [id: fooImplementation, type: `hello.FooImplementation`] injected into:\n" +
"\n" +
"- Bean [id: myController, type: `hello.MyController`]\n"
"- Bean: myController \n" +
" Type: `hello.MyController`\n"
);
}
@Test
public void beanWithFileResource() throws Exception {
Path of = getOutputFolder();
LiveBeansModel beans = LiveBeansModel.builder()
.add(LiveBean.builder()
.id("fooImplementation")
.type("hello.FooImplementation")
.fileResource("should/not/matter")
.build()
)
.add(LiveBean.builder()
.id("myController")
.type("hello.MyController")
.fileResource(of+"/hello/MyController.class")
.dependencies("fooImplementation")
.build()
)
.build();
mockAppProvider.builder()
.isSpringBootApp(true)
.processId("111")
.processName("the-app")
.beans(beans)
.build();
Editor editor = harness.newEditor(LanguageId.JAVA,
"package hello;\n" +
"\n" +
"import org.springframework.context.annotation.Bean;\n" +
"import org.springframework.context.annotation.Configuration;\n" +
"import org.springframework.context.annotation.Profile;\n" +
"\n" +
"@Configuration\n" +
"public class LocalConfig {\n" +
" \n" +
" @Bean(\"fooImplementation\")\n" +
" Foo someFoo() {\n" +
" return new FooImplementation();\n" +
" }\n" +
"}"
);
editor.assertHighlights("@Bean");
editor.assertTrimmedHover("@Bean",
"**Injection report for Bean [id: fooImplementation]**\n" +
"\n" +
"Process [PID=111, name=`the-app`]:\n" +
"\n" +
"Bean [id: fooImplementation, type: `hello.FooImplementation`] injected into:\n" +
"\n" +
"- Bean: myController \n" +
" Type: `hello.MyController` \n" +
" Resource: `hello/MyController.class`"
);
}
@Test
public void beanWithClasspathResource() throws Exception {
Path of = getOutputFolder();
LiveBeansModel beans = LiveBeansModel.builder()
.add(LiveBean.builder()
.id("fooImplementation")
.type("hello.FooImplementation")
.fileResource("should/not/matter")
.build()
)
.add(LiveBean.builder()
.id("myController")
.type("hello.MyController")
.classpathResource("hello/MyController.class")
.dependencies("fooImplementation")
.build()
)
.build();
mockAppProvider.builder()
.isSpringBootApp(true)
.processId("111")
.processName("the-app")
.beans(beans)
.build();
Editor editor = harness.newEditor(LanguageId.JAVA,
"package hello;\n" +
"\n" +
"import org.springframework.context.annotation.Bean;\n" +
"import org.springframework.context.annotation.Configuration;\n" +
"import org.springframework.context.annotation.Profile;\n" +
"\n" +
"@Configuration\n" +
"public class LocalConfig {\n" +
" \n" +
" @Bean(\"fooImplementation\")\n" +
" Foo someFoo() {\n" +
" return new FooImplementation();\n" +
" }\n" +
"}"
);
editor.assertHighlights("@Bean");
editor.assertTrimmedHover("@Bean",
"**Injection report for Bean [id: fooImplementation]**\n" +
"\n" +
"Process [PID=111, name=`the-app`]:\n" +
"\n" +
"Bean [id: fooImplementation, type: `hello.FooImplementation`] injected into:\n" +
"\n" +
"- Bean: myController \n" +
" Type: `hello.MyController` \n" +
" Resource: `hello/MyController.class`"
);
}
private Path getOutputFolder() {
return harness.getProjectFinder().find(null).get().getClasspath().getOutputFolder();
}
@Test
public void beanWithMultipleInjections() throws Exception {
LiveBeansModel beans = LiveBeansModel.builder()
@@ -269,8 +387,10 @@ public class BeanInjectedIntoHoverProviderTest {
"\n" +
"Bean [id: fooImplementation, type: `hello.FooImplementation`] injected into:\n" +
"\n" +
"- Bean [id: myController, type: `hello.MyController`]\n" +
"- Bean [id: otherBean, type: `hello.OtherBean`]\n"
"- Bean: myController \n" +
" Type: `hello.MyController`\n" +
"- Bean: otherBean \n" +
" Type: `hello.OtherBean`\n"
);
}

View File

@@ -164,7 +164,8 @@ public class ComponentInjectionsHoverProviderTest {
"\n" +
"Bean [id: fooImplementation, type: `com.example.FooImplementation`] injected into:\n" +
"\n" +
"- Bean [id: myController, type: `com.example.MyController`]\n"
"- Bean: myController \n" +
" Type: `com.example.MyController`"
);
}
@@ -218,8 +219,10 @@ public class ComponentInjectionsHoverProviderTest {
"\n" +
"Bean [id: fooImplementation, type: `com.example.FooImplementation`] injected into:\n" +
"\n" +
"- Bean [id: myController, type: `com.example.MyController`]\n" +
"- Bean [id: otherBean, type: `com.example.OtherBean`]\n"
"- Bean: myController \n" +
" Type: `com.example.MyController`\n" +
"- Bean: otherBean \n" +
" Type: `com.example.OtherBean`"
);
}
@@ -275,15 +278,19 @@ public class ComponentInjectionsHoverProviderTest {
"\n" +
"Bean [id: fooImplementation, type: `com.example.FooImplementation`] injected into:\n" +
"\n" +
"- Bean [id: myController, type: `com.example.MyController`]\n" +
"- Bean [id: otherBean, type: `com.example.OtherBean`]\n" +
"- Bean: myController \n" +
" Type: `com.example.MyController`\n" +
"- Bean: otherBean \n" +
" Type: `com.example.OtherBean`\n" +
"\n" +
"Process [PID=1002, name=`app-instance-2`]:\n" +
"\n" +
"Bean [id: fooImplementation, type: `com.example.FooImplementation`] injected into:\n" +
"\n" +
"- Bean [id: myController, type: `com.example.MyController`]\n" +
"- Bean [id: otherBean, type: `com.example.OtherBean`]\n"
"- Bean: myController \n" +
" Type: `com.example.MyController`\n" +
"- Bean: otherBean \n" +
" Type: `com.example.OtherBean`\n"
);
}
@@ -342,7 +349,8 @@ public class ComponentInjectionsHoverProviderTest {
"\n" +
"Bean [id: fooImplementation, type: `com.example.FooImplementation`] injected into:\n" +
"\n" +
"- Bean [id: myController, type: `com.example.MyController`]"
"- Bean: myController \n" +
" Type: `com.example.MyController`"
);
}
@@ -401,7 +409,8 @@ public class ComponentInjectionsHoverProviderTest {
"\n" +
"Bean [id: alternateFooImplementation, type: `com.example.FooImplementation`] injected into:\n" +
"\n" +
"- Bean [id: otherBean, type: `com.example.OtherBean`]\n"
"- Bean: otherBean \n" +
" Type: `com.example.OtherBean`\n"
);
}