Add tests for CF reconcile on 'broken' client

This commit is contained in:
Kris De Volder
2017-01-19 16:33:02 -08:00
parent 99b28a2885
commit bed871e5f5
5 changed files with 109 additions and 19 deletions

View File

@@ -13,7 +13,5 @@ package org.springframework.ide.vscode.commons.cloudfoundry.client;
import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CFClientParams;
public interface CloudFoundryClientFactory {
ClientRequests getClient(CFClientParams params, ClientTimeouts timeouts) throws Exception;
}

View File

@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>vscode-manifest-yaml</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.ide.vscode</groupId>
<artifactId>commons-parent</artifactId>
@@ -12,11 +12,11 @@
<relativePath>../commons/pom.xml</relativePath>
</parent>
<version>0.0.2-SNAPSHOT</version>
<properties>
<dependencies.version>0.0.1-SNAPSHOT</dependencies.version>
</properties>
<repositories>
<!-- Local repository with tools.jar -->
<repository>
@@ -25,7 +25,7 @@
<url>file://${basedir}/repo</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>distribution-repository</id>
@@ -54,6 +54,12 @@
<version>${dependencies.version}</version>
</dependency>
<!-- Test harness -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.ide.vscode</groupId>
<artifactId>language-server-test-harness</artifactId>

View File

@@ -45,16 +45,22 @@ import org.yaml.snakeyaml.Yaml;
public class ManifestYamlLanguageServer extends SimpleLanguageServer {
private Yaml yaml = new Yaml();
private YamlSchema schema;
private CFTargetCache cfTargetCache;
private final CloudFoundryClientFactory cfClientFactory;
public ManifestYamlLanguageServer() {
this(DefaultCloudFoundryClientFactoryV2.INSTANCE);
}
public ManifestYamlLanguageServer(CloudFoundryClientFactory cfClientFactory) {
this.cfClientFactory = cfClientFactory;
SimpleTextDocumentService documents = getTextDocumentService();
YamlASTProvider parser = new YamlParser(yaml);
Callable<Collection<YValueHint>> buildPacksProvider = getBuildpacksProvider();
Callable<Collection<YValueHint>> servicesProvider = getServicesProvider();
@@ -73,7 +79,7 @@ public class ManifestYamlLanguageServer extends SimpleLanguageServer {
TextDocument doc = params.getDocument();
validateWith(doc, engine);
});
// workspace.onDidChangeConfiguraton(settings -> {
// System.out.println("Config changed: "+params);
// Integer val = settings.getInt("languageServerExample", "maxNumberOfProblems");
@@ -84,16 +90,16 @@ public class ManifestYamlLanguageServer extends SimpleLanguageServer {
// }
// }
// });
documents.onCompletion(completionEngine::getCompletions);
documents.onCompletionResolve(completionEngine::resolveCompletion);
documents.onHover(hoverEngine ::getHover);
}
private CFTargetCache getCfTargetCache() {
if (cfTargetCache == null) {
ClientParamsProvider paramsProvider = new CfCliParamsProvider();
CloudFoundryClientFactory clientFactory = DefaultCloudFoundryClientFactoryV2.INSTANCE;
CloudFoundryClientFactory clientFactory = cfClientFactory;
cfTargetCache = new CFTargetCache(paramsProvider, clientFactory, new ClientTimeouts());
}
return cfTargetCache;
@@ -102,22 +108,22 @@ public class ManifestYamlLanguageServer extends SimpleLanguageServer {
private Callable<Collection<YValueHint>> getBuildpacksProvider() {
return new ManifestYamlCFBuildpacksProvider(getCfTargetCache());
}
private Callable<Collection<YValueHint>> getServicesProvider() {
return new ManifestYamlCFServicesProvider(getCfTargetCache());
}
@Override
protected ServerCapabilities getServerCapabilities() {
ServerCapabilities c = new ServerCapabilities();
c.setTextDocumentSync(TextDocumentSyncKind.Incremental);
c.setHoverProvider(true);
CompletionOptions completionProvider = new CompletionOptions();
completionProvider.setResolveProvider(false);
c.setCompletionProvider(completionProvider);
return c;
}
}

View File

@@ -10,15 +10,24 @@
*******************************************************************************/
package org.springframework.ide.vscode.manifest.yaml;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import java.io.IOException;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.ide.vscode.commons.cloudfoundry.client.ClientRequests;
import org.springframework.ide.vscode.commons.cloudfoundry.client.CloudFoundryClientFactory;
import org.springframework.ide.vscode.languageserver.testharness.Editor;
import org.springframework.ide.vscode.languageserver.testharness.LanguageServerHarness;
public class ManifestYamlEditorTest {
LanguageServerHarness harness;
MockCloudfoundry cfClientFactory = new MockCloudfoundry();
@Before public void setup() throws Exception {
harness = new LanguageServerHarness(ManifestYamlLanguageServer::new);
@@ -674,6 +683,38 @@ public class ManifestYamlEditorTest {
}
@Test
@Ignore
public void noReconcileErrorsWhenCFFactoryThrows() throws Exception {
cfClientFactory.throwException(new IOException("Can't create a client!"));
Editor editor = harness.newEditor(
"applications:\n" +
"- name: foo\n" +
" buildpack: bad-buildpack\n" +
" services:\n" +
" - bad-service\n" +
" bogus: bad" //a token error to make sure reconciler is actually running!
);
editor.assertProblems("bogus|Unknown property");
}
@Test
@Ignore
public void noReconcileErrorsWhenClientThrows() throws Exception {
ClientRequests cfClient = cfClientFactory.client;
when(cfClient.getBuildpacks()).thenThrow(new IOException("Can't get buildpacks"));
when(cfClient.getServices()).thenThrow(new IOException("Can't get services"));
Editor editor = harness.newEditor(
"applications:\n" +
"- name: foo\n" +
" buildpack: bad-buildpack\n" +
" services:\n" +
" - bad-service\n" +
" bogus: bad" //a token error to make sure reconciler is actually running!
);
editor.assertProblems("bogus|Unknown property");
}
//////////////////////////////////////////////////////////////////////////////
private void assertCompletions(String textBefore, String... textAfter) throws Exception {

View File

@@ -0,0 +1,39 @@
/*******************************************************************************
* 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 org.mockito.Mockito;
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;
public class MockCloudfoundry implements CloudFoundryClientFactory {
public final ClientRequests client = Mockito.mock(ClientRequests.class);
private Exception toThrow = null;
@Override
public ClientRequests getClient(CFClientParams params, ClientTimeouts timeouts) throws Exception {
if (toThrow==null) {
return client;
}
throw toThrow;
}
/**
* Makes the factory throw the given exception when its 'getClient' method is called.
*/
public void throwException(Exception e) {
toThrow = e;
}
}