Add more basic CF services tests

This commit is contained in:
nsingh
2017-01-25 15:35:16 -08:00
parent 1306dbac98
commit bc38083f4a
2 changed files with 83 additions and 48 deletions

View File

@@ -55,6 +55,17 @@ public class BasicCfClientHarness {
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
@@ -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 {
/*

View File

@@ -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.
*
* <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();
@@ -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);