Improve reconciler errors around wrong domains

This commit is contained in:
Kris De Volder
2017-04-27 14:43:39 -07:00
parent 6ab32ac53e
commit f7bde8559b
4 changed files with 57 additions and 13 deletions

View File

@@ -14,8 +14,6 @@ import java.util.Collection;
import java.util.Set;
import java.util.concurrent.Callable;
import org.springframework.ide.vscode.commons.languageserver.reconcile.ReconcileException;
import org.springframework.ide.vscode.commons.util.EnumValueParser;
import org.springframework.ide.vscode.commons.util.IntegerRange;
import org.springframework.ide.vscode.commons.util.Renderable;
import org.springframework.ide.vscode.commons.util.Renderables;
@@ -73,18 +71,15 @@ public class ManifestYmlSchema implements YamlSchema {
}
YAtomicType t_stack = f.yatomic("Stack");
t_stack.addHintProvider(stacksProvider);
t_stack.parseWith(new EnumValueParser(t_stack.toString(), YTypeFactory.valuesFromHintProvider(stacksProvider)) {
@Override
protected Exception errorOnParse(String message) {
return new ReconcileException(message, ManifestYamlSchemaProblemsTypes.UNKNOWN_STACK_PROBLEM);
}
});
if (stacksProvider!=null) {
t_stack.addHintProvider(stacksProvider);
t_stack.parseWith(ManifestYmlValueParsers.fromValueHints(stacksProvider, t_stack, ManifestYamlSchemaProblemsTypes.UNKNOWN_STACK_PROBLEM));
}
YAtomicType t_domain = f.yatomic("Domain");
if (domainsProvider != null) {
t_domain.addHintProvider(domainsProvider);
t_domain.parseWith(ManifestYmlValueParsers.fromValueHints(domainsProvider, t_domain, ManifestYamlSchemaProblemsTypes.UNKNOWN_DOMAIN_PROBLEM));
}
YAtomicType t_service = f.yatomic("Service");

View File

@@ -10,10 +10,18 @@
*******************************************************************************/
package org.springframework.ide.vscode.manifest.yaml;
import java.util.Collection;
import java.util.Set;
import java.util.concurrent.Callable;
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemType;
import org.springframework.ide.vscode.commons.languageserver.reconcile.ReconcileException;
import org.springframework.ide.vscode.commons.util.Assert;
import org.springframework.ide.vscode.commons.util.EnumValueParser;
import org.springframework.ide.vscode.commons.util.ValueParser;
import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory;
import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YAtomicType;
import org.springframework.ide.vscode.commons.yaml.schema.YValueHint;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
@@ -87,4 +95,13 @@ public class ManifestYmlValueParsers {
};
}
public static EnumValueParser fromValueHints(Callable<Collection<YValueHint>> hintProvider, YAtomicType type, ProblemType problemType) {
return new EnumValueParser(type.toString(), YTypeFactory.valuesFromHintProvider(hintProvider)) {
@Override
protected Exception errorOnParse(String message) {
return new ReconcileException(message, problemType);
}
};
}
}

View File

@@ -63,7 +63,7 @@ public class RouteValueParser extends RegexpParser {
}
if (!cloudDomains.contains(route.getDomain())) {
String hostDomain = matcher.group(1);
throw new ReconcileException("Unknown domain", ManifestYamlSchemaProblemsTypes.UNKNOWN_DOMAIN_PROBLEM, hostDomain.lastIndexOf(route.getDomain()), hostDomain.length());
throw new ReconcileException("Unknown 'Domain'. Valid domains are: "+cloudDomains, ManifestYamlSchemaProblemsTypes.UNKNOWN_DOMAIN_PROBLEM, hostDomain.lastIndexOf(route.getDomain()), hostDomain.length());
}
return route;
} catch (ConnectionException | NoTargetsException e) {

View File

@@ -606,6 +606,28 @@ public class ManifestYamlEditorTest {
assertEquals("an-org : a-space [test.io]", c.getDocumentation());
}
@Test public void domainReconcile() throws Exception {
List<CFDomain> domains = ImmutableList.of(mockDomain("one.com"), mockDomain("two.com"));
when(cloudfoundry.client.getDomains()).thenReturn(domains);
Editor editor;
Diagnostic p;
editor = harness.newEditor(
"domain: bad.com"
);
p = editor.assertProblems("bad.com|unknown 'Domain'. Valid values are: [one.com, two.com]").get(0);
assertEquals(DiagnosticSeverity.Warning, p.getSeverity());
editor= harness.newEditor(
"domains:\n" +
"- one.com\n" +
"- bad.com\n" +
"- two.com"
);
editor.assertProblems("bad.com|unknown 'Domain'. Valid values are: [one.com, two.com]");
}
@Test public void stacksReconcile() throws Exception {
List<CFStack> stacks = ImmutableList.of(
mockStack("linux"), mockStack("windows")
@@ -637,6 +659,8 @@ public class ManifestYamlEditorTest {
@Test
public void reconcileDuplicateKeys() throws Exception {
ImmutableList<CFDomain> domains = ImmutableList.of(mockDomain("pivotal.io"), mockDomain("otherdomain.org"));
when(cloudfoundry.client.getDomains()).thenReturn(domains);
Editor editor = harness.newEditor(
"#comment\n" +
"applications:\n" +
@@ -1153,6 +1177,8 @@ public class ManifestYamlEditorTest {
@Test
public void reconcileRoute_Advanced() throws Exception {
ImmutableList<CFDomain> domains = ImmutableList.of(mockDomain("somedomain.com"));
when(cloudfoundry.client.getDomains()).thenReturn(domains);
Editor editor = harness.newEditor(
"applications:\n" +
"- name: foo\n" +
@@ -1176,11 +1202,17 @@ public class ManifestYamlEditorTest {
"- name: foo\n" +
" routes:\n" +
" - route: host.springsource.org\n");
editor.assertProblems("springsource.org|Unknown domain");
editor.assertProblems("springsource.org|Unknown 'Domain'. Valid domains are: [somedomain.com]");
problem = editor.assertProblem("springsource.org");
assertEquals(DiagnosticSeverity.Warning, problem.getSeverity());
}
private CFDomain mockDomain(String name) {
CFDomain domain = mock(CFDomain.class);
when(domain.getName()).thenReturn(name);
return domain;
}
@Test
public void reconcileRouteValidDomain() throws Exception {
ClientRequests cfClient = cloudfoundry.client;
@@ -1194,7 +1226,7 @@ public class ManifestYamlEditorTest {
" - route: host.springsource.org\n");
editor.assertProblems();
}
@Test public void dashedContentAssistForServices() throws Exception {
Editor editor;
CFServiceInstance service = mock(CFServiceInstance.class);