Removed alternate CF mock tests
Now that mockito tests run, the alternate way of mocking CF is no longer needed. Copied over the extra tests from the alternate implementation into the editor tests
This commit is contained in:
@@ -1,166 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.springframework.ide.vscode.commons.cloudfoundry.client.CFBuildpack;
|
||||
import org.springframework.ide.vscode.commons.cloudfoundry.client.CFEntities;
|
||||
import org.springframework.ide.vscode.commons.cloudfoundry.client.CFServiceInstance;
|
||||
import org.springframework.ide.vscode.commons.cloudfoundry.client.ClientRequests;
|
||||
import org.springframework.ide.vscode.commons.cloudfoundry.client.ClientTimeouts;
|
||||
import org.springframework.ide.vscode.commons.cloudfoundry.client.CloudFoundryClientFactory;
|
||||
import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CFClientParams;
|
||||
import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CFCredentials;
|
||||
import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.ClientParamsProvider;
|
||||
import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.NoTargetsException;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
/**
|
||||
* An alternative to using mockito for mocking the CF client, as the mockito
|
||||
* version of the CF client seems to fail when run on OpenJDK (which is used for
|
||||
* the sts4 concourse ci build).
|
||||
* <p/>
|
||||
* This also allows additional testing of the general manifest-yaml vscode
|
||||
* framework, as the framework should be able to take any client factory,
|
||||
* including the basic one below, and still produce correct results for content
|
||||
* assist as well as reconcile
|
||||
*
|
||||
*/
|
||||
public class BasicCfClientHarness {
|
||||
|
||||
private BasicCFClientFactory clientFactory = new BasicCFClientFactory();
|
||||
|
||||
private ClientParamsProvider paramsProvider = new BasicClientParamsProvider(ImmutableList.of(DEFAULT_PARAMS));
|
||||
|
||||
public static CFClientParams DEFAULT_PARAMS = new CFClientParams("test.io", "testuser",
|
||||
CFCredentials.fromRefreshToken("refreshtoken"), false);
|
||||
|
||||
public BasicCFClientFactory getBasicClientFactory() {
|
||||
return clientFactory;
|
||||
}
|
||||
|
||||
public ClientParamsProvider getParamsProvider() {
|
||||
return paramsProvider;
|
||||
}
|
||||
|
||||
public void addServiceInstances(String... serviceInstances) {
|
||||
List<CFServiceInstance> services = null;
|
||||
if (serviceInstances != null) {
|
||||
services = new ArrayList<CFServiceInstance>();
|
||||
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
|
||||
// the client and
|
||||
// client returns null instead of empty list
|
||||
List<CFBuildpack> asList = null;
|
||||
if (buildpacks != null) {
|
||||
asList = new ArrayList<CFBuildpack>();
|
||||
for (String name : buildpacks) {
|
||||
asList.add(CFEntities.createBuildpack(name));
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
/*
|
||||
* Create the client "ahead of time" so that it can be configured before
|
||||
* the language server is tested
|
||||
*/
|
||||
private BasicClientRequests preexistingClient = new BasicClientRequests(DEFAULT_PARAMS, new ClientTimeouts());
|
||||
|
||||
@Override
|
||||
public ClientRequests getClient(CFClientParams params, ClientTimeouts timeouts) throws Exception {
|
||||
return this.preexistingClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenient non-framework method to fetch the existing client so that
|
||||
* values can be set to simulate values from CF.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public BasicClientRequests getExistingClientInHarness() {
|
||||
return this.preexistingClient;
|
||||
}
|
||||
}
|
||||
|
||||
static class BasicClientParamsProvider implements ClientParamsProvider {
|
||||
|
||||
private List<CFClientParams> params;
|
||||
|
||||
public BasicClientParamsProvider(List<CFClientParams> defaultParams) {
|
||||
this.params = defaultParams;
|
||||
}
|
||||
|
||||
public void setParams(List<CFClientParams> params) {
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CFClientParams> getParams() throws NoTargetsException, ExecutionException {
|
||||
return this.params;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class BasicClientRequests implements ClientRequests {
|
||||
|
||||
private List<CFBuildpack> buildpacks;
|
||||
private List<CFServiceInstance> serviceInstances;
|
||||
private CFClientParams params;
|
||||
private ClientTimeouts timeouts;
|
||||
|
||||
public BasicClientRequests(CFClientParams params, ClientTimeouts timeouts) {
|
||||
this.params = params;
|
||||
this.timeouts = timeouts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CFBuildpack> getBuildpacks() throws Exception {
|
||||
return this.buildpacks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CFServiceInstance> getServices() throws Exception {
|
||||
return this.serviceInstances;
|
||||
}
|
||||
|
||||
public void setBuildPacks(List<CFBuildpack> buildpacks) {
|
||||
this.buildpacks = buildpacks;
|
||||
}
|
||||
|
||||
public void setServices(List<CFServiceInstance> serviceInstances) {
|
||||
this.serviceInstances = serviceInstances;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 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;
|
||||
|
||||
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.
|
||||
*
|
||||
* <p/>
|
||||
* 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();
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
harness = new LanguageServerHarness(() -> new ManifestYamlLanguageServer(
|
||||
basicCfClientHarness.getBasicClientFactory(), basicCfClientHarness.getParamsProvider()));
|
||||
harness.intialize(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentAssistBuildpack() throws Exception {
|
||||
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.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 {
|
||||
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());
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private void assertContainsCompletions(String textBefore, String... textAfter) throws Exception {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,30 +12,25 @@ package org.springframework.ide.vscode.manifest.yaml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.lsp4j.CompletionItem;
|
||||
import org.eclipse.lsp4j.Diagnostic;
|
||||
import org.eclipse.lsp4j.DiagnosticSeverity;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.ide.vscode.commons.cloudfoundry.client.CFBuildpack;
|
||||
import org.springframework.ide.vscode.commons.cloudfoundry.client.CFServiceInstance;
|
||||
import org.springframework.ide.vscode.commons.cloudfoundry.client.ClientRequests;
|
||||
import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CFClientParams;
|
||||
import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CFCredentials;
|
||||
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.util.CollectionUtil;
|
||||
import org.springframework.ide.vscode.languageserver.testharness.Editor;
|
||||
import org.springframework.ide.vscode.languageserver.testharness.LanguageServerHarness;
|
||||
|
||||
import static org.springframework.ide.vscode.languageserver.testharness.TestAsserts.*;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
public class ManifestYamlEditorTest {
|
||||
@@ -896,6 +891,51 @@ public class ManifestYamlEditorTest {
|
||||
//query string should match the 'filter text' otherwise vscode will filter the item and it will be gone!
|
||||
assertEquals("something", completion.getFilterText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serviceContentAssistEmptyServices() throws Exception {
|
||||
ClientRequests cfClient = cloudfoundry.client;
|
||||
when(cfClient.getServices()).thenReturn(ImmutableList.of());
|
||||
assertDoesNotContainCompletions("services:\n" + " - <*>", "mysql");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serviceContentAssistDoesNotContainServices() throws Exception {
|
||||
ClientRequests cfClient = cloudfoundry.client;
|
||||
CFServiceInstance service = Mockito.mock(CFServiceInstance.class);
|
||||
when(service.getName()).thenReturn("mysql");
|
||||
when(cfClient.getServices()).thenReturn(ImmutableList.of(service));
|
||||
assertDoesNotContainCompletions("services:\n" + " - <*>", "wrongsql");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serviceContentAssist() throws Exception {
|
||||
ClientRequests cfClient = cloudfoundry.client;
|
||||
CFServiceInstance service = Mockito.mock(CFServiceInstance.class);
|
||||
when(service.getName()).thenReturn("mysql");
|
||||
when(cfClient.getServices()).thenReturn(ImmutableList.of(service));
|
||||
|
||||
assertContainsCompletions("services:\n" + " - <*>", "mysql");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildpackContentAssist() throws Exception {
|
||||
ClientRequests cfClient = cloudfoundry.client;
|
||||
CFBuildpack buildPack = Mockito.mock(CFBuildpack.class);
|
||||
when(buildPack.getName()).thenReturn("java_buildpack");
|
||||
when(cfClient.getBuildpacks()).thenReturn(ImmutableList.of(buildPack));
|
||||
|
||||
assertContainsCompletions("buildpack: <*>", "buildpack: java_buildpack<*>");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildpackContentAssistDoesNotContainCompletion() throws Exception {
|
||||
ClientRequests cfClient = cloudfoundry.client;
|
||||
CFBuildpack buildPack = Mockito.mock(CFBuildpack.class);
|
||||
when(buildPack.getName()).thenReturn("java_buildpack");
|
||||
when(cfClient.getBuildpacks()).thenReturn(ImmutableList.of(buildPack));
|
||||
assertDoesNotContainCompletions("buildpack: <*>", "buildpack: wrong_buildpack<*>");
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -903,5 +943,15 @@ public class ManifestYamlEditorTest {
|
||||
Editor editor = harness.newEditor(textBefore);
|
||||
editor.assertCompletions(textAfter);
|
||||
}
|
||||
|
||||
private void assertDoesNotContainCompletions(String textBefore, String... notToBeFound) throws Exception {
|
||||
Editor editor = harness.newEditor(textBefore);
|
||||
editor.assertDoesNotContainCompletions(notToBeFound);
|
||||
}
|
||||
|
||||
private void assertContainsCompletions(String textBefore, String... textAfter) throws Exception {
|
||||
Editor editor = harness.newEditor(textBefore);
|
||||
editor.assertContainsCompletions(textAfter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user