Search in sources :

Example 26 with LiveBeansModel

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

the class BeansByTypeHoverProviderTest method generalBeanLiveHoverAvoidOverlapWithAnnotation.

@Test
public void generalBeanLiveHoverAvoidOverlapWithAnnotation() throws Exception {
    LiveBeansModel beans = LiveBeansModel.builder().add(LiveBean.builder().id("fooImplementation").type("com.example.FooImplementation").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`] 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 27 with LiveBeansModel

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

the class ComponentInjectionsHoverProviderTest method componentWithMultipleInjections.

@Test
public void componentWithMultipleInjections() 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();
    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`\n" + "- Bean: otherBean  \n" + "  Type: `com.example.OtherBean`");
}
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 28 with LiveBeansModel

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

the class ComponentInjectionsHoverProviderTest 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.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();
    editor.assertNoHover("@Component");
}
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 29 with LiveBeansModel

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

the class ComponentInjectionsHoverProviderTest method componentFromInnerClass.

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

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

the class ComponentInjectionsHoverProviderTest 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() + "/com/example/DependencyA.class").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.stereotype.Component;\n" + "\n" + "@Component\n" + "public class AutowiredClass {\n" + "\n" + "	public AutowiredClass(DependencyA depA, DependencyB depB) {\n" + "	}\n" + "}\n");
    editor.assertHighlights("@Component");
    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" + "\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`");
}
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