From bc38083f4ad35f88c063a90e1ca87620edeee6a5 Mon Sep 17 00:00:00 2001 From: nsingh Date: Wed, 25 Jan 2017 15:35:16 -0800 Subject: [PATCH 1/5] Add more basic CF services tests --- .../manifest/yaml/BasicCfClientHarness.java | 18 +++ .../yaml/ManifestYamlEditorCFBasicTest.java | 113 ++++++++++-------- 2 files changed, 83 insertions(+), 48 deletions(-) diff --git a/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/BasicCfClientHarness.java b/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/BasicCfClientHarness.java index c809ac558..8eb1301cc 100644 --- a/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/BasicCfClientHarness.java +++ b/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/BasicCfClientHarness.java @@ -55,6 +55,17 @@ public class BasicCfClientHarness { return paramsProvider; } + public void addServiceInstances(String... serviceInstances) { + List services = null; + if (serviceInstances != null) { + services = new ArrayList(); + for (String name : serviceInstances) { + services.add(createServiceInstance(name)); + } + } + getBasicClientFactory().getExistingClientInHarness().setServices(services); + } + public void addBuildpacks(String... buildpacks) { // Allow testing of null condition when vscode asks for buildpacks from @@ -71,6 +82,13 @@ public class BasicCfClientHarness { getBasicClientFactory().getExistingClientInHarness().setBuildPacks(asList); } + protected CFServiceInstance createServiceInstance(String name) { + return CFEntities.createServiceInstance(name, null, null, null, null, null); + } + + //////////////////////////////////////////////// + // "Mocked" CF client types + public static final class BasicCFClientFactory implements CloudFoundryClientFactory { /* diff --git a/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorCFBasicTest.java b/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorCFBasicTest.java index c78c7f506..e2a09161f 100644 --- a/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorCFBasicTest.java +++ b/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorCFBasicTest.java @@ -10,11 +10,27 @@ *******************************************************************************/ package org.springframework.ide.vscode.manifest.yaml; +import static org.junit.Assert.assertEquals; + +import org.eclipse.lsp4j.Diagnostic; +import org.eclipse.lsp4j.DiagnosticSeverity; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.springframework.ide.vscode.languageserver.testharness.Editor; import org.springframework.ide.vscode.languageserver.testharness.LanguageServerHarness; +/** + * Basic CF tests for services and buildpacks, using a basic CF client that + * requires no actual CF connection. + * + *

+ * This is an alternative to using mockito, and also tests that the + * vscode-manifest framework can take any clients, including the basic one used + * in this test, and still function as expected for CF content assist and + * reconcile + * + */ public class ManifestYamlEditorCFBasicTest { LanguageServerHarness harness; BasicCfClientHarness basicCfClientHarness = new BasicCfClientHarness(); @@ -31,59 +47,60 @@ public class ManifestYamlEditorCFBasicTest { basicCfClientHarness.addBuildpacks("java_buildpack"); assertContainsCompletions("buildpack: <*>", "buildpack: java_buildpack<*>"); } - + @Test public void contentAssistDoesNotContainBuildpack() throws Exception { basicCfClientHarness.addBuildpacks("java_buildpack"); assertDoesNotContainCompletions("buildpack: <*>", "buildpack: wrong_buildpack<*>"); } - // @Test - // public void contentAssistServices() throws Exception { - // basicCfClientHarness.addServices("mysql"); - // assertContainsCompletions("services:\n" + " - <*>", "mysql"); - // } - // - // @Test - // public void reconcileCFService() throws Exception { - // basicCfClientHarness.addServices("myservice"); - // Editor editor = harness.newEditor("applications:\n" // - // + "- name: foo\n" // - // + " services:\n" // - // + " - myservice\n" // - // ); - // // Should have no problems - // editor.assertProblems(/* none */); - // } - // - // @Test - // public void reconcileShowsWarningOnUnknownService() throws Exception { - // basicCfClientHarness.addServices("myservice"); - // Editor editor = harness.newEditor("applications:\n" // - // + "- name: foo\n" // - // + " services:\n" // - // + " - bad-service\n" // - // - // ); - // editor.assertProblems("bad-service|There is no service instance called"); - // - // Diagnostic problem = editor.assertProblem("bad-service"); - // assertEquals(DiagnosticSeverity.Warning, problem.getSeverity()); - // } - // - // @Test - // public void reconcileShowsWarningOnEmptyServices() throws Exception { - // // Add empty list of services - // basicCfClientHarness.addServices(); - // Editor editor = harness.newEditor("applications:\n" // - // + "- name: foo\n" // - // + " services:\n" // - // + " - bad-service\n");// - // editor.assertProblems("bad-service|There is no service instance called"); - // - // Diagnostic problem = editor.assertProblem("bad-service"); - // assertEquals(DiagnosticSeverity.Warning, problem.getSeverity()); - // } + @Ignore + @Test + public void contentAssistServices() throws Exception { + basicCfClientHarness.addServiceInstances("mysql"); + assertContainsCompletions("services:\n" + " - <*>", "mysql"); + } + + @Test + public void reconcileCFService() throws Exception { + basicCfClientHarness.addServiceInstances("myservice"); + Editor editor = harness.newEditor("applications:\n" // + + "- name: foo\n" // + + " services:\n" // + + " - myservice\n" // + ); + // Should have no problems + editor.assertProblems(/* none */); + } + + @Test + public void reconcileShowsWarningOnUnknownService() throws Exception { + basicCfClientHarness.addServiceInstances("myservice"); + Editor editor = harness.newEditor("applications:\n" // + + "- name: foo\n" // + + " services:\n" // + + " - bad-service\n" // + + ); + editor.assertProblems("bad-service|There is no service instance called"); + + Diagnostic problem = editor.assertProblem("bad-service"); + assertEquals(DiagnosticSeverity.Warning, problem.getSeverity()); + } + + @Test + public void reconcileShowsWarningOnEmptyServices() throws Exception { + // Add empty list of services + basicCfClientHarness.addServiceInstances(); + Editor editor = harness.newEditor("applications:\n" // + + "- name: foo\n" // + + " services:\n" // + + " - bad-service\n");// + editor.assertProblems("bad-service|There is no service instance called"); + + Diagnostic problem = editor.assertProblem("bad-service"); + assertEquals(DiagnosticSeverity.Warning, problem.getSeverity()); + } ////////////////////////////////////////////////////////////////////////////// @@ -91,7 +108,7 @@ public class ManifestYamlEditorCFBasicTest { Editor editor = harness.newEditor(textBefore); editor.assertContainsCompletions(textAfter); } - + private void assertDoesNotContainCompletions(String textBefore, String... notToBeFound) throws Exception { Editor editor = harness.newEditor(textBefore); editor.assertDoesNotContainCompletions(notToBeFound); From bc6181d3df001b8f6c81107c4ac45a6d10fae65d Mon Sep 17 00:00:00 2001 From: nsingh Date: Wed, 25 Jan 2017 16:05:11 -0800 Subject: [PATCH 2/5] Allow subtypes in ExceptionUtil method --- .../ide/vscode/commons/util/ExceptionUtil.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vscode-extensions/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/ExceptionUtil.java b/vscode-extensions/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/ExceptionUtil.java index cfd07fa67..ac506ba7d 100644 --- a/vscode-extensions/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/ExceptionUtil.java +++ b/vscode-extensions/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/ExceptionUtil.java @@ -41,7 +41,7 @@ public class ExceptionUtil { * @return the throwable instance of the given type, or null if nothing found. */ public static Throwable getThrowable(Throwable e, Class toLookFor) { - if (e.getClass().equals(toLookFor)) { + if (e.getClass().isAssignableFrom(toLookFor)) { return e; } @@ -50,7 +50,7 @@ public class ExceptionUtil { while (parent != null && parent != e) { cause = parent; parent = cause.getCause(); - if (cause.getClass().equals(toLookFor)) { + if (cause.getClass().isAssignableFrom(toLookFor)) { return cause; } } From d34b00f28b7097407b7a7fbecf193f5a314e6340 Mon Sep 17 00:00:00 2001 From: nsingh Date: Wed, 25 Jan 2017 16:23:54 -0800 Subject: [PATCH 3/5] Fix order of checking subtype --- .../ide/vscode/commons/util/ExceptionUtil.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vscode-extensions/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/ExceptionUtil.java b/vscode-extensions/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/ExceptionUtil.java index ac506ba7d..6a8b1fc12 100644 --- a/vscode-extensions/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/ExceptionUtil.java +++ b/vscode-extensions/commons/commons-util/src/main/java/org/springframework/ide/vscode/commons/util/ExceptionUtil.java @@ -41,7 +41,7 @@ public class ExceptionUtil { * @return the throwable instance of the given type, or null if nothing found. */ public static Throwable getThrowable(Throwable e, Class toLookFor) { - if (e.getClass().isAssignableFrom(toLookFor)) { + if (toLookFor.isAssignableFrom(e.getClass())) { return e; } @@ -50,7 +50,7 @@ public class ExceptionUtil { while (parent != null && parent != e) { cause = parent; parent = cause.getCause(); - if (cause.getClass().isAssignableFrom(toLookFor)) { + if (toLookFor.isAssignableFrom(cause.getClass())) { return cause; } } From 23b493add806a370dd0a58b3d55d66659ab010e8 Mon Sep 17 00:00:00 2001 From: nsingh Date: Wed, 25 Jan 2017 16:34:15 -0800 Subject: [PATCH 4/5] Fixed failing test case for services --- .../vscode/manifest/yaml/ManifestYamlEditorCFBasicTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorCFBasicTest.java b/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorCFBasicTest.java index e2a09161f..78a121dd0 100644 --- a/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorCFBasicTest.java +++ b/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorCFBasicTest.java @@ -54,11 +54,10 @@ public class ManifestYamlEditorCFBasicTest { assertDoesNotContainCompletions("buildpack: <*>", "buildpack: wrong_buildpack<*>"); } - @Ignore @Test public void contentAssistServices() throws Exception { basicCfClientHarness.addServiceInstances("mysql"); - assertContainsCompletions("services:\n" + " - <*>", "mysql"); + assertContainsCompletions("services:\n" + " - <*>", "mysql"); } @Test From 3324eee9fbeabd7db3e7eda1701ba15fe7f3cfc3 Mon Sep 17 00:00:00 2001 From: nsingh Date: Wed, 25 Jan 2017 16:49:29 -0800 Subject: [PATCH 5/5] Added a couple more test cases for services CA --- .../manifest/yaml/ManifestYamlEditorCFBasicTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorCFBasicTest.java b/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorCFBasicTest.java index 78a121dd0..e913530fd 100644 --- a/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorCFBasicTest.java +++ b/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorCFBasicTest.java @@ -59,6 +59,18 @@ public class ManifestYamlEditorCFBasicTest { basicCfClientHarness.addServiceInstances("mysql"); assertContainsCompletions("services:\n" + " - <*>", "mysql"); } + + @Test + public void contentAssistDoesNotContainServices() throws Exception { + basicCfClientHarness.addServiceInstances("mysql"); + assertDoesNotContainCompletions("services:\n" + " - <*>", "wrongsql"); + } + + @Test + public void contentAssistDoesNotContainServicesEmptyServices() throws Exception { + basicCfClientHarness.addServiceInstances(/*no services*/); + assertDoesNotContainCompletions("services:\n" + " - <*>", "mysql"); + } @Test public void reconcileCFService() throws Exception {