From b5888a5d9b9791701f688b17cd6bb664ffaaa6dc Mon Sep 17 00:00:00 2001 From: Kris De Volder Date: Fri, 5 Oct 2018 16:20:45 -0700 Subject: [PATCH] Some more cleanups to CF editor test Extracted mock cf client config for (hopefully) easier reuse --- .../manifest/yaml/ManifestYamlEditorTest.java | 45 +----------------- .../manifest/yaml/MockCloudfoundry.java | 2 +- .../ManifestLanguageServerTest.java | 7 ++- ...stYamlLanguageServerTestConfiguration.java | 46 +++++++++++++++++++ 4 files changed, 53 insertions(+), 47 deletions(-) rename headless-services/manifest-yaml-language-server/src/test/java/org/springframework/ide/vscode/manifest/yaml/{annotations => bootiful}/ManifestLanguageServerTest.java (87%) create mode 100644 headless-services/manifest-yaml-language-server/src/test/java/org/springframework/ide/vscode/manifest/yaml/bootiful/ManifestYamlLanguageServerTestConfiguration.java diff --git a/headless-services/manifest-yaml-language-server/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorTest.java b/headless-services/manifest-yaml-language-server/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorTest.java index 1c8bb328d..48421c211 100644 --- a/headless-services/manifest-yaml-language-server/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorTest.java +++ b/headless-services/manifest-yaml-language-server/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorTest.java @@ -28,24 +28,18 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.TestConfiguration; -import org.springframework.context.annotation.Bean; import org.springframework.ide.vscode.commons.cloudfoundry.client.CFBuildpack; import org.springframework.ide.vscode.commons.cloudfoundry.client.CFDomain; import org.springframework.ide.vscode.commons.cloudfoundry.client.CFServiceInstance; import org.springframework.ide.vscode.commons.cloudfoundry.client.CFStack; import org.springframework.ide.vscode.commons.cloudfoundry.client.ClientRequests; -import org.springframework.ide.vscode.commons.cloudfoundry.client.CloudFoundryClientFactory; -import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.ClientParamsProvider; import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.NoTargetsException; -import org.springframework.ide.vscode.commons.languageserver.config.LanguageServerInitializer; import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer; import org.springframework.ide.vscode.commons.util.Unicodes; -import org.springframework.ide.vscode.commons.util.text.LanguageId; import org.springframework.ide.vscode.languageserver.testharness.CodeAction; import org.springframework.ide.vscode.languageserver.testharness.Editor; import org.springframework.ide.vscode.languageserver.testharness.LanguageServerHarness; -import org.springframework.ide.vscode.manifest.yaml.annotations.ManifestLanguageServerTest; +import org.springframework.ide.vscode.manifest.yaml.bootiful.ManifestLanguageServerTest; import org.springframework.test.context.junit4.SpringRunner; import com.google.common.collect.ImmutableList; @@ -57,44 +51,10 @@ public class ManifestYamlEditorTest { @Autowired MockCloudfoundry cloudfoundry; - @Autowired - SimpleLanguageServer server; - - @Autowired - LanguageServerInitializer serverInit; - @Autowired LanguageServerHarness harness; - - @TestConfiguration - public static class MockCloudfoundryConfiguration { - - @Bean public MockCloudfoundry cloudfoundry() { - return new MockCloudfoundry(); - } - - @Bean public CloudFoundryClientFactory cloudfoundryClientFactory(MockCloudfoundry cf) { - return cf.factory; - } - - @Bean public ClientParamsProvider cloudfoundryParams(MockCloudfoundry cf) { - return cf.defaultParamsProvider; - } - - @Bean public LanguageServerHarness harness(SimpleLanguageServer server) throws Exception { - LanguageServerHarness harness = new LanguageServerHarness<>( - ()-> server, - LanguageId.CF_MANIFEST - ); - harness.intialize(null); - System.setProperty("lsp.yaml.completions.errors.disable", "false"); - return harness; - } - } - @Test public void testReconcileCatchesParseError() throws Exception { - Editor editor = harness.newEditor( "somemap: val\n"+ "- sequence" @@ -105,9 +65,6 @@ public class ManifestYamlEditorTest { } @Test public void reconcileRunsOnDocumentOpenAndChange() throws Exception { -// LanguageServerHarness harness = new LanguageServerHarness(ManifestYamlLanguageServerInitializer::new, LanguageId.CF_MANIFEST); -// harness.intialize(null); - Editor editor = harness.newEditor( "somemap: val\n"+ "- sequence" diff --git a/headless-services/manifest-yaml-language-server/src/test/java/org/springframework/ide/vscode/manifest/yaml/MockCloudfoundry.java b/headless-services/manifest-yaml-language-server/src/test/java/org/springframework/ide/vscode/manifest/yaml/MockCloudfoundry.java index 093822f31..86fba2af0 100644 --- a/headless-services/manifest-yaml-language-server/src/test/java/org/springframework/ide/vscode/manifest/yaml/MockCloudfoundry.java +++ b/headless-services/manifest-yaml-language-server/src/test/java/org/springframework/ide/vscode/manifest/yaml/MockCloudfoundry.java @@ -50,7 +50,7 @@ public class MockCloudfoundry { /** * Reset the mocks. Use this if the default's programmed into the mocks don't suite your test case. *

- * Note: you may also choose to call {@link Mockito}.mock directly if you do not want to + * Note: you may also choose to call {@link Mockito}.reset directly if you do not want to * reset all of the mocks. */ public void reset() throws Exception { diff --git a/headless-services/manifest-yaml-language-server/src/test/java/org/springframework/ide/vscode/manifest/yaml/annotations/ManifestLanguageServerTest.java b/headless-services/manifest-yaml-language-server/src/test/java/org/springframework/ide/vscode/manifest/yaml/bootiful/ManifestLanguageServerTest.java similarity index 87% rename from headless-services/manifest-yaml-language-server/src/test/java/org/springframework/ide/vscode/manifest/yaml/annotations/ManifestLanguageServerTest.java rename to headless-services/manifest-yaml-language-server/src/test/java/org/springframework/ide/vscode/manifest/yaml/bootiful/ManifestLanguageServerTest.java index 591d36e51..87bc22930 100644 --- a/headless-services/manifest-yaml-language-server/src/test/java/org/springframework/ide/vscode/manifest/yaml/annotations/ManifestLanguageServerTest.java +++ b/headless-services/manifest-yaml-language-server/src/test/java/org/springframework/ide/vscode/manifest/yaml/bootiful/ManifestLanguageServerTest.java @@ -8,7 +8,7 @@ * Contributors: * Pivotal, Inc. - initial API and implementation *******************************************************************************/ -package org.springframework.ide.vscode.manifest.yaml.annotations; +package org.springframework.ide.vscode.manifest.yaml.bootiful; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -24,7 +24,10 @@ import org.springframework.test.annotation.DirtiesContext.ClassMode; @Retention(RetentionPolicy.RUNTIME) @OverrideAutoConfiguration(enabled=false) @ImportAutoConfiguration(classes=LanguageServerAutoConf.class) -@SpringBootTest(classes=ManifestYamlLanguageServerBootApp.class) +@SpringBootTest(classes={ + ManifestYamlLanguageServerBootApp.class, + ManifestYamlLanguageServerTestConfiguration.class +}) @DirtiesContext(classMode=ClassMode.AFTER_EACH_TEST_METHOD) public @interface ManifestLanguageServerTest { } diff --git a/headless-services/manifest-yaml-language-server/src/test/java/org/springframework/ide/vscode/manifest/yaml/bootiful/ManifestYamlLanguageServerTestConfiguration.java b/headless-services/manifest-yaml-language-server/src/test/java/org/springframework/ide/vscode/manifest/yaml/bootiful/ManifestYamlLanguageServerTestConfiguration.java new file mode 100644 index 000000000..7f98b8cba --- /dev/null +++ b/headless-services/manifest-yaml-language-server/src/test/java/org/springframework/ide/vscode/manifest/yaml/bootiful/ManifestYamlLanguageServerTestConfiguration.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2018 Pivotal, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Pivotal, Inc. - initial API and implementation + *******************************************************************************/ +package org.springframework.ide.vscode.manifest.yaml.bootiful; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.ide.vscode.commons.cloudfoundry.client.CloudFoundryClientFactory; +import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.ClientParamsProvider; +import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer; +import org.springframework.ide.vscode.commons.util.text.LanguageId; +import org.springframework.ide.vscode.languageserver.testharness.LanguageServerHarness; +import org.springframework.ide.vscode.manifest.yaml.MockCloudfoundry; + +@Configuration +public class ManifestYamlLanguageServerTestConfiguration { + + @Bean public MockCloudfoundry cloudfoundry() { + return new MockCloudfoundry(); + } + + @Bean public CloudFoundryClientFactory cloudfoundryClientFactory(MockCloudfoundry cf) { + return cf.factory; + } + + @Bean public ClientParamsProvider cloudfoundryParams(MockCloudfoundry cf) { + return cf.defaultParamsProvider; + } + + @Bean public LanguageServerHarness harness(SimpleLanguageServer server) throws Exception { + LanguageServerHarness harness = new LanguageServerHarness<>( + ()-> server, + LanguageId.CF_MANIFEST + ); + harness.intialize(null); + System.setProperty("lsp.yaml.completions.errors.disable", "false"); //Yuck! Do we really need this?? + return harness; + } +} \ No newline at end of file