Search in sources :

Example 31 with LiveBeansModel

use of org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel in project sts4 by spring-projects.

the class ComponentInjectionsHoverProviderTest method componentFromInnerInnerClass.

@Test
public void componentFromInnerInnerClass() throws Exception {
    LiveBeansModel beans = LiveBeansModel.builder().add(LiveBean.builder().id("demoApplication.InnerClass.InnerInnerClass").type("com.example.DemoApplication$InnerClass$InnerInnerClass").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.boot.SpringApplication;\n" + "import org.springframework.boot.autoconfigure.SpringBootApplication;\n" + "import org.springframework.context.annotation.Bean;\n" + "import org.springframework.web.client.RestTemplate;\n" + "\n" + "public class DemoApplication {\n" + "	\n" + "	public static class InnerClass {\n" + "		\n" + "		@SpringBootApplication\n" + "		public static class InnerInnerClass {\n" + "		\n" + "			public static void main(String[] args) {\n" + "				SpringApplication.run(DemoApplication.InnerClass.InnerInnerClass.class, args);\n" + "			}\n" + "		}\n" + "	}\n" + "}\n");
    editor.assertHighlights("@SpringBootApplication");
    editor.assertHoverContains("@SpringBootApplication", "**Injection report for Bean [id: demoApplication.InnerClass.InnerInnerClass, type: `com.example.DemoApplication.InnerClass.InnerInnerClass`]**");
}
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 32 with LiveBeansModel

use of org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel in project sts4 by spring-projects.

the class ComponentInjectionsHoverProviderTest method bug_153072942_SpringBootApplication__withCGLib_is_a_Component.

@Test
public void bug_153072942_SpringBootApplication__withCGLib_is_a_Component() throws Exception {
    LiveBeansModel beans = LiveBeansModel.builder().add(LiveBean.builder().id("demoApplication").type("com.example.DemoApplication$$EnhancerBySpringCGLIB$$f378241f").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.boot.SpringApplication;\n" + "import org.springframework.boot.autoconfigure.SpringBootApplication;\n" + "import org.springframework.context.annotation.Bean;\n" + "import org.springframework.web.client.RestTemplate;\n" + "\n" + "@SpringBootApplication\n" + "public class DemoApplication {\n" + "	\n" + "\n" + "	public static void main(String[] args) {\n" + "		SpringApplication.run(DemoApplication.class, args);\n" + "	}\n" + "}\n");
    editor.assertHighlights("@SpringBootApplication");
    editor.assertHoverContains("@SpringBootApplication", "**Injection report for Bean [id: demoApplication, type: `com.example.DemoApplication`]**");
}
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 33 with LiveBeansModel

use of org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel in project sts4 by spring-projects.

the class ComponentInjectionsHoverProviderTest method componentWithAutowiredConstructorNoAdditionalHovers.

@Test
public void componentWithAutowiredConstructorNoAdditionalHovers() 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").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", "@Autowired");
    editor.assertTrimmedHover("@Component", "**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`] exists but is **Not injected anywhere**\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 34 with LiveBeansModel

use of org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel in project sts4 by spring-projects.

the class AutowiredHoverProviderTest method noHoversWhenRunningAppDoesntHaveTheComponent.

@Test
public void noHoversWhenRunningAppDoesntHaveTheComponent() throws Exception {
    LiveBeansModel beans = LiveBeansModel.builder().add(LiveBean.builder().id("whateverBean").type("com.example.UnrelatedComponent").build()).add(LiveBean.builder().id("myController").type("com.example.UnrelatedComponent").dependencies("whateverBean").build()).build();
    mockAppProvider.builder().isSpringBootApp(true).processId("111").processName("unrelated-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();
    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 35 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_152553935.

@Test
public void bug_152553935() throws Exception {
    // https://www.pivotaltracker.com/story/show/152553935
    LiveBeansModel beans = LiveBeansModel.builder().add(LiveBean.builder().id("defaultFoo").type("com.example.FooImplementation").dependencies("defaultFoo").dependencies("otherBean").build()).add(LiveBean.builder().id("otherBean").type("com.example.DependencyA").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.scheduling.TaskScheduler;\n" + "import org.springframework.stereotype.Component;\n" + "\n" + "@Component(\"defaultFoo\")\n" + "public class FooImplementation implements Foo {\n" + "	\n" + "	private TaskScheduler scheduler;\n" + "	\n" + "	@Autowired Foo self;\n" + "		\n" + "	@Override\n" + "	public void doSomeFoo() {\n" + "		scheduler.scheduleWithFixedDelay(() -> {\n" + "			System.out.println(\"Doo Done done!\");\n" + "		}, 1000);\n" + "		System.out.println(\"Foo do do do do!\");\n" + "	}\n" + "\n" + "	@Autowired\n" + "	public void setScheduler(TaskScheduler scheduler) {\n" + "		this.scheduler = scheduler;\n" + "	}\n" + "\n" + "}");
    editor.assertHighlights("@Component", "@Autowired", "@Autowired");
    for (int i = 1; i <= 2; i++) {
        editor.assertHoverContains("@Autowired", i, "Bean [id: defaultFoo, type: `com.example.FooImplementation`] got autowired with:\n" + "\n" + "- Bean: otherBean  \n" + "  Type: `com.example.DependencyA`");
    }
}
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