Search in sources :

Example 21 with LiveBeansModel

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

the class BeanInjectedIntoHoverProviderTest method noHoversWhenRunningAppDoesntHaveTheBean.

@Test
public void noHoversWhenRunningAppDoesntHaveTheBean() throws Exception {
    LiveBeansModel beans = LiveBeansModel.builder().add(LiveBean.builder().id("whateverBean").type("com.example.UnrelatedBeanType").build()).build();
    mockAppProvider.builder().isSpringBootApp(true).processId("111").processName("unrelated-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();
    editor.assertNoHover("@Bean");
}
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 22 with LiveBeansModel

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

the class BeanInjectedIntoHoverProviderTest method beanWithFileResource.

@Test
public void beanWithFileResource() throws Exception {
    Path of = harness.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: `" + Paths.get("hello/MyController.class") + "`");
}
Also used : Path(java.nio.file.Path) Editor(org.springframework.ide.vscode.languageserver.testharness.Editor) LiveBeansModel(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel) Test(org.junit.Test)

Example 23 with LiveBeansModel

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

the class BeanInjectedIntoHoverProviderTest method beanFromInnerClassWithOneInjection.

@Test
public void beanFromInnerClassWithOneInjection() throws Exception {
    LiveBeansModel beans = LiveBeansModel.builder().add(LiveBean.builder().id("fooImplementation").type("hello.FooImplementation").build()).add(LiveBean.builder().id("myController").type("hello.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 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" + "public class OuterClass {\n" + "	\n" + "	@Configuration\n" + "	public static class InnerClass {\n" + "		\n" + "		@Bean(\"fooImplementation\")\n" + "		Foo someFoo() {\n" + "			return new FooImplementation();\n" + "		}\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");
}
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 24 with LiveBeansModel

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

the class BeanInjectedIntoHoverProviderTest method beanWithNoInjections.

@Test
public void beanWithNoInjections() throws Exception {
    LiveBeansModel beans = LiveBeansModel.builder().add(LiveBean.builder().id("myFoo").type("hello.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\n" + "	Foo myFoo() {\n" + "		return new FooImplementation();\n" + "	}\n" + "}");
    editor.assertHighlights("@Bean");
    editor.assertTrimmedHover("@Bean", "**Injection report for Bean [id: myFoo]**\n" + "\n" + "Process [PID=111, name=`the-app`]:\n" + "\n" + "Bean [id: myFoo, type: `hello.FooImplementation`] 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 25 with LiveBeansModel

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

the class BeanInjectedIntoHoverProviderTest method beanWithOneInjection.

@Test
public void beanWithOneInjection() throws Exception {
    LiveBeansModel beans = LiveBeansModel.builder().add(LiveBean.builder().id("fooImplementation").type("hello.FooImplementation").build()).add(LiveBean.builder().id("myController").type("hello.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 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");
}
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