Search in sources :

Example 46 with IJavaProject

use of org.springframework.ide.vscode.commons.java.IJavaProject in project sts4 by spring-projects.

the class ApplicationPropertiesEditorTest method testEnumMapKeyReconciling.

@Test
public void testEnumMapKeyReconciling() throws Exception {
    IJavaProject p = createPredefinedMavenProject("enums-boot-1.3.2-app");
    useProject(p);
    assertNotNull(p.getClasspath().findType("demo.Color"));
    assertNotNull(p.getClasspath().findType("demo.ColorData"));
    Editor editor = newEditor("foo.color-names.RED=Rood\n" + "foo.color-names.GREEN=Groen\n" + "foo.color-names.BLUE=Blauw\n" + "foo.color-names.NOT_A_COLOR=Wrong\n" + "foo.color-names.BLUE.bad=Blauw\n");
    editor.assertProblems("NOT_A_COLOR|Color", // because value type is not dotable the dots will be taken to be part of map key
    "BLUE.bad|Color");
}
Also used : IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) Editor(org.springframework.ide.vscode.languageserver.testharness.Editor) AbstractPropsEditorTest(org.springframework.ide.vscode.boot.editor.harness.AbstractPropsEditorTest) Test(org.junit.Test)

Example 47 with IJavaProject

use of org.springframework.ide.vscode.commons.java.IJavaProject in project sts4 by spring-projects.

the class ApplicationYamlEditorTest method testReconcilePojoArray.

@Test
public void testReconcilePojoArray() throws Exception {
    IJavaProject p = createPredefinedMavenProject("boot-1.2.1-app-properties-list-of-pojo");
    useProject(p);
    assertNotNull(p.getClasspath().findType("demo.Foo"));
    {
        Editor editor = newEditor("token-bad-guy: problem\n" + "volder:\n" + "  foo:\n" + "    list:\n" + "      - name: Kris\n" + "        description: Kris\n" + "        roles:\n" + "          - Developer\n" + "          - Admin\n" + "        bogus: Bad\n");
        editor.assertProblems("token-bad-guy|Unknown property", // 'description' is ok
        "bogus|Unknown property 'bogus' for type 'demo.Foo'");
    }
    {
        // Pojo array can also be entered as a map with integer keys
        Editor editor = newEditor("token-bad-guy: problem\n" + "volder:\n" + "  foo:\n" + "    list:\n" + "      0:\n" + "        name: Kris\n" + "        description: Kris\n" + "        roles:\n" + "          0: Developer\n" + "          one: Admin\n" + "        bogus: Bad\n");
        editor.assertProblems("token-bad-guy|Unknown property", "one|Expecting a 'int' but got 'one'", "bogus|Unknown property 'bogus' for type 'demo.Foo'");
    }
}
Also used : IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) Editor(org.springframework.ide.vscode.languageserver.testharness.Editor) AbstractPropsEditorTest(org.springframework.ide.vscode.boot.editor.harness.AbstractPropsEditorTest) Test(org.junit.Test)

Example 48 with IJavaProject

use of org.springframework.ide.vscode.commons.java.IJavaProject in project sts4 by spring-projects.

the class ApplicationYamlEditorTest method testHyperlinkTargets.

@Ignore
@Test
public void testHyperlinkTargets() throws Exception {
    IJavaProject p = createPredefinedMavenProject("tricky-getters-boot-1.3.1-app");
    useProject(p);
    Editor editor = newEditor("server:\n" + "  port: 888\n" + "spring:\n" + "  datasource:\n" + "    login-timeout: 1000\n" + "flyway:\n" + "  init-sqls: a,b,c\n");
    editor.assertLinkTargets("port", "org.springframework.boot.autoconfigure.web.ServerProperties.setPort(Integer)");
    editor.assertLinkTargets("login-", "org.springframework.boot.autoconfigure.jdbc.DataSourceConfigMetadata.hikariDataSource()", "org.springframework.boot.autoconfigure.jdbc.DataSourceConfigMetadata.tomcatDataSource()", "org.springframework.boot.autoconfigure.jdbc.DataSourceConfigMetadata.dbcpDataSource()");
    editor.assertLinkTargets("init-sql", "org.springframework.boot.autoconfigure.flyway.FlywayProperties.setInitSqls(List<String>)");
}
Also used : IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) Editor(org.springframework.ide.vscode.languageserver.testharness.Editor) Ignore(org.junit.Ignore) AbstractPropsEditorTest(org.springframework.ide.vscode.boot.editor.harness.AbstractPropsEditorTest) Test(org.junit.Test)

Example 49 with IJavaProject

use of org.springframework.ide.vscode.commons.java.IJavaProject in project sts4 by spring-projects.

the class ApplicationYamlEditorTest method testEnumPropertyReconciling.

@Test
public void testEnumPropertyReconciling() throws Exception {
    IJavaProject p = createPredefinedMavenProject("enums-boot-1.3.2-app");
    useProject(p);
    assertNotNull(p.getClasspath().findType("demo.Color"));
    data("foo.color", "demo.Color", null, "A foonky colour");
    Editor editor = newEditor("foo:\n" + "  color: BLUE\n" + "---\n" + "foo:\n" + "  color: RED\n" + "---\n" + "foo:\n" + "  color: GREEN\n" + "---\n" + "foo:\n" + "  color:\n" + "    bad: BLUE\n" + "---\n" + "foo:\n" + "  color: Bogus\n");
    editor.assertProblems("bad: BLUE|demo.Color", "Bogus|demo.Color");
}
Also used : IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) Editor(org.springframework.ide.vscode.languageserver.testharness.Editor) AbstractPropsEditorTest(org.springframework.ide.vscode.boot.editor.harness.AbstractPropsEditorTest) Test(org.junit.Test)

Example 50 with IJavaProject

use of org.springframework.ide.vscode.commons.java.IJavaProject in project sts4 by spring-projects.

the class ApplicationYamlEditorTest method testReconcileCamelCaseBeanProp.

@Test
public void testReconcileCamelCaseBeanProp() throws Exception {
    Editor editor;
    IJavaProject p = createPredefinedMavenProject("tricky-getters-boot-1.3.1-app");
    useProject(p);
    data("demo.bean", "demo.CamelCaser", "For testing tolerance of camelCase", null);
    // Nothing special... not using camel case
    editor = newEditor("#Comment for good measure\n" + "demo:\n" + "  bean:\n" + "    the-answer-to-everything: not-a-number\n");
    editor.assertProblems("not-a-number|Expecting a 'int'");
    // Now check that reconcile also tolerates camel case and reports no error for it
    editor = newEditor("#Comment for good measure\n" + "demo:\n" + "  bean:\n" + "    theAnswerToEverything: 42\n");
    editor.assertProblems();
    // Now check that reconciler traverses camelCase and reports errors assigning to camelCase names
    editor = newEditor("#Comment for good measure\n" + "demo:\n" + "  bean:\n" + "    theAnswerToEverything: not-a-number\n");
    editor.assertProblems("not-a-number|Expecting a 'int'");
    // Now check also that camelcase tolerance works if its not in the end of the path
    editor = newEditor("#Comment for good measure\n" + "demo:\n" + "  bean:\n" + "    theAnswerToEverything: not-a-number\n" + "    theLeft:\n" + "      bad: wrong\n" + "      theAnswerToEverything: not-this\n");
    editor.assertProblems("not-a-number|Expecting a 'int'", "bad|Unknown property", "not-this|Expecting a 'int'");
}
Also used : IJavaProject(org.springframework.ide.vscode.commons.java.IJavaProject) Editor(org.springframework.ide.vscode.languageserver.testharness.Editor) AbstractPropsEditorTest(org.springframework.ide.vscode.boot.editor.harness.AbstractPropsEditorTest) Test(org.junit.Test)

Aggregations

IJavaProject (org.springframework.ide.vscode.commons.java.IJavaProject)63 Test (org.junit.Test)52 AbstractPropsEditorTest (org.springframework.ide.vscode.boot.editor.harness.AbstractPropsEditorTest)35 Editor (org.springframework.ide.vscode.languageserver.testharness.Editor)24 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)8 Ignore (org.junit.Ignore)8 IClasspath (org.springframework.ide.vscode.commons.java.IClasspath)7 TextDocument (org.springframework.ide.vscode.commons.util.text.TextDocument)7 File (java.io.File)6 Path (java.nio.file.Path)6 TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)6 URI (java.net.URI)5 Map (java.util.Map)5 Listener (org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver.Listener)5 Stream (java.util.stream.Stream)4 JavaCore (org.eclipse.jdt.core.JavaCore)4 AST (org.eclipse.jdt.core.dom.AST)4 ASTParser (org.eclipse.jdt.core.dom.ASTParser)4 JavaProjectFinder (org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder)4 List (java.util.List)3