From bc38083f4ad35f88c063a90e1ca87620edeee6a5 Mon Sep 17 00:00:00 2001 From: nsingh Date: Wed, 25 Jan 2017 15:35:16 -0800 Subject: [PATCH] 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);