use of org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel in project sts4 by spring-projects.
the class ComponentInjectionsHoverProviderTest method componentWithMultipleInjectionsAndMultipleProcesses.
@Test
public void componentWithMultipleInjectionsAndMultipleProcesses() throws Exception {
LiveBeansModel beans = LiveBeansModel.builder().add(LiveBean.builder().id("fooImplementation").type("com.example.FooImplementation").build()).add(LiveBean.builder().id("myController").type("com.example.MyController").dependencies("fooImplementation").build()).add(LiveBean.builder().id("otherBean").type("com.example.OtherBean").dependencies("fooImplementation").build()).build();
for (int i = 1; i <= 2; i++) {
mockAppProvider.builder().isSpringBootApp(true).processId("100" + i).processName("app-instance-" + i).beans(beans).build();
}
Editor editor = harness.newEditor(LanguageId.JAVA, "package com.example;\n" + "\n" + "import org.springframework.stereotype.Component;\n" + "\n" + "@Component\n" + "public class FooImplementation implements Foo {\n" + "\n" + " @Override\n" + " public void doSomeFoo() {\n" + " System.out.println(\"Foo do do do!\");\n" + " }\n" + "}\n");
editor.assertHighlights("@Component");
editor.assertTrimmedHover("@Component", "**Injection report for Bean [id: fooImplementation, type: `com.example.FooImplementation`]**\n" + "\n" + "Process [PID=1001, name=`app-instance-1`]:\n" + "\n" + "Bean [id: fooImplementation, type: `com.example.FooImplementation`] injected into:\n" + "\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: myController \n" + " Type: `com.example.MyController`\n" + "- Bean: otherBean \n" + " Type: `com.example.OtherBean`\n");
}
use of org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel in project sts4 by spring-projects.
the class ComponentInjectionsHoverProviderTest method componentWithOneInjection.
@Test
public void componentWithOneInjection() throws Exception {
LiveBeansModel beans = LiveBeansModel.builder().add(LiveBean.builder().id("fooImplementation").type("com.example.FooImplementation").build()).add(LiveBean.builder().id("myController").type("com.example.MyController").dependencies("fooImplementation").build()).add(LiveBean.builder().id("irrelevantBean").type("com.example.IrrelevantBean").dependencies("myController").build()).build();
mockAppProvider.builder().isSpringBootApp(true).processId("111").processName("the-app").beans(beans).build();
Editor editor = harness.newEditor(LanguageId.JAVA, "package com.example;\n" + "\n" + "import org.springframework.stereotype.Component;\n" + "\n" + "@Component\n" + "public class FooImplementation implements Foo {\n" + "\n" + " @Override\n" + " public void doSomeFoo() {\n" + " System.out.println(\"Foo do do do!\");\n" + " }\n" + "}\n");
editor.assertHighlights("@Component");
editor.assertTrimmedHover("@Component", "**Injection report for Bean [id: fooImplementation, type: `com.example.FooImplementation`]**\n" + "\n" + "Process [PID=111, name=`the-app`]:\n" + "\n" + "Bean [id: fooImplementation, type: `com.example.FooImplementation`] injected into:\n" + "\n" + "- Bean: myController \n" + " Type: `com.example.MyController`");
}
use of org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel in project sts4 by spring-projects.
the class AutowiredHoverProviderTest method noHoversWhenRunningAppDoesntHaveDependenciesForTheAutowiring.
@Test
public void noHoversWhenRunningAppDoesntHaveDependenciesForTheAutowiring() throws Exception {
LiveBeansModel beans = LiveBeansModel.builder().add(LiveBean.builder().id("autowiredClass").type("com.example.AutowiredClass").build()).add(LiveBean.builder().id("dependencyA").type("com.example.DependencyA").build()).add(LiveBean.builder().id("dependencyB").type("com.example.DependencyB").build()).build();
mockAppProvider.builder().isSpringBootApp(true).processId("111").processName("the-app").beans(beans).build();
Editor editor = harness.newEditor(LanguageId.JAVA, "package com.example;\n" + "\n" + "import org.springframework.beans.factory.annotation.Autowired;\n" + "import org.springframework.stereotype.Component;\n" + "\n" + "@Component\n" + "public class AutowiredClass {\n" + "\n" + " @Autowired\n" + " public AutowiredClass(DependencyA depA, DependencyB depB) {\n" + " }\n" + "}\n");
editor.assertHighlights("@Component");
editor.assertNoHover("@Autowired");
}
use of org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel in project sts4 by spring-projects.
the class AutowiredHoverProviderTest method componentWithAutomaticallyWiredConstructorInjections.
@Test
public void componentWithAutomaticallyWiredConstructorInjections() throws Exception {
LiveBeansModel beans = LiveBeansModel.builder().add(LiveBean.builder().id("autowiredClass").type("com.example.AutowiredClass").dependencies("dependencyA", "dependencyB").build()).add(LiveBean.builder().id("dependencyA").type("com.example.DependencyA").fileResource(harness.getOutputFolder() + Paths.get("/com/example/DependencyA.class").toString()).build()).add(LiveBean.builder().id("dependencyB").type("com.example.DependencyB").classpathResource("com/example/DependencyB.class").build()).build();
mockAppProvider.builder().isSpringBootApp(true).processId("111").processName("the-app").beans(beans).build();
Editor editor = harness.newEditor(LanguageId.JAVA, "package com.example;\n" + "\n" + "import org.springframework.beans.factory.annotation.Autowired;\n" + "import org.springframework.stereotype.Component;\n" + "\n" + "@Component\n" + "public class AutowiredClass {\n" + "\n" + " @Autowired\n" + " public AutowiredClass(DependencyA depA, DependencyB depB) {\n" + " }\n" + "}\n");
editor.assertHighlights("@Component", "@Autowired");
editor.assertTrimmedHover("@Autowired", "**Injection report for Bean [id: autowiredClass, type: `com.example.AutowiredClass`]**\n" + "\n" + "Process [PID=111, name=`the-app`]:\n" + "\n" + "Bean [id: autowiredClass, type: `com.example.AutowiredClass`] got autowired with:\n" + "\n" + "- Bean: dependencyA \n" + " Type: `com.example.DependencyA` \n" + " Resource: `" + Paths.get("com/example/DependencyA.class") + "`\n" + "- Bean: dependencyB \n" + " Type: `com.example.DependencyB` \n" + " Resource: `com/example/DependencyB.class`\n");
}
use of org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel in project sts4 by spring-projects.
the class AutowiredHoverProviderTest method bug_152621242_autowired_constructor_on_a_controller.
@Test
public void bug_152621242_autowired_constructor_on_a_controller() throws Exception {
// https://www.pivotaltracker.com/story/show/152621242
LiveBeansModel beans = LiveBeansModel.builder().add(LiveBean.builder().id("myController").type("com.example.MyController").dependencies("restTemplate").build()).add(LiveBean.builder().id("restTemplate").type("org.springframework.web.client.RestTemplate").build()).build();
mockAppProvider.builder().isSpringBootApp(true).processId("111").processName("the-app").beans(beans).build();
Editor editor = harness.newEditor("package com.example;\n" + "\n" + "import org.springframework.beans.factory.annotation.Autowired;\n" + "import org.springframework.stereotype.Component;\n" + "import org.springframework.stereotype.Controller;\n" + "import org.springframework.web.client.RestTemplate;\n" + "\n" + "@Controller\n" + "public class MyController {\n" + "\n" + " private RestTemplate restClient;\n" + "\n" + " @Autowired\n" + " public MyController(RestTemplate restClient) {\n" + " this.restClient = restClient;\n" + " }\n" + " \n" + "}");
editor.assertHighlights("@Controller", "@Autowired");
editor.assertHoverContains("@Autowired", "Bean [id: myController, type: `com.example.MyController`] got autowired with:\n" + "\n" + "- Bean: restTemplate \n" + " Type: `org.springframework.web.client.RestTemplate`");
editor.assertHoverContains("@Controller", "**Injection report for Bean [id: myController, type: `com.example.MyController`]**");
}
Aggregations