Search in sources :

Example 16 with LiveBeansModel

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");
}
Also used : Editor(org.springframework.ide.vscode.languageserver.testharness.Editor) LiveBeansModel(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel) Test(org.junit.Test)

Example 17 with LiveBeansModel

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`");
}
Also used : Editor(org.springframework.ide.vscode.languageserver.testharness.Editor) LiveBeansModel(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel) Test(org.junit.Test)

Example 18 with LiveBeansModel

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");
}
Also used : Editor(org.springframework.ide.vscode.languageserver.testharness.Editor) LiveBeansModel(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel) Test(org.junit.Test)

Example 19 with LiveBeansModel

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");
}
Also used : Editor(org.springframework.ide.vscode.languageserver.testharness.Editor) LiveBeansModel(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel) Test(org.junit.Test)

Example 20 with LiveBeansModel

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`]**");
}
Also used : Editor(org.springframework.ide.vscode.languageserver.testharness.Editor) LiveBeansModel(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel) Test(org.junit.Test)

Aggregations

LiveBeansModel (org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel)37 Test (org.junit.Test)33 Editor (org.springframework.ide.vscode.languageserver.testharness.Editor)29 LiveBean (org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBean)7 SpringBootApp (org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp)4 Hover (org.eclipse.lsp4j.Hover)3 Path (java.nio.file.Path)1 Optional (java.util.Optional)1 Stream (java.util.stream.Stream)1 BootJavaLanguageServerComponents (org.springframework.ide.vscode.boot.java.BootJavaLanguageServerComponents)1 SourceLinkFactory (org.springframework.ide.vscode.boot.java.links.SourceLinkFactory)1 SourceLinks (org.springframework.ide.vscode.boot.java.links.SourceLinks)1 SpringResource (org.springframework.ide.vscode.boot.java.utils.SpringResource)1 IJavaProject (org.springframework.ide.vscode.commons.java.IJavaProject)1 SimpleLanguageServer (org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer)1 Renderables (org.springframework.ide.vscode.commons.util.Renderables)1 StringUtil (org.springframework.ide.vscode.commons.util.StringUtil)1