From fbcbc47b981d2caaec25a23c30d9c4479b270fc7 Mon Sep 17 00:00:00 2001 From: nsingh Date: Fri, 10 Feb 2017 12:12:54 -0800 Subject: [PATCH] Added support for CF dynamic values for domains --- .../commons/cloudfoundry/client/CFDomain.java | 17 +++++ .../cloudfoundry/client/CFDomainImpl.java | 52 +++++++++++++++ .../cloudfoundry/client/CFEntities.java | 3 + .../cloudfoundry/client/ClientRequests.java | 2 + .../client/cftarget/CFTarget.java | 33 ++++++++-- .../cloudfoundry/client/v2/CFWrappingV2.java | 8 ++- .../client/v2/DefaultClientRequestsV2.java | 16 +++++ .../cloudfoundry/client/CFClientTest.java | 51 +++++++++++++++ .../yaml/ManifestYamlCFDomainProvider.java | 64 +++++++++++++++++++ .../yaml/ManifestYamlLanguageServer.java | 33 ++++++++-- .../yaml/ManifestYmlHintProviders.java | 26 ++++++++ .../manifest/yaml/ManifestYmlSchema.java | 23 +++++-- .../manifest/yaml/ManifestYamlEditorTest.java | 39 +++++++++++ .../manifest/yaml/ManifestYmlSchemaTest.java | 24 ++++++- 14 files changed, 375 insertions(+), 16 deletions(-) create mode 100644 vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFDomain.java create mode 100644 vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFDomainImpl.java create mode 100644 vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlCFDomainProvider.java create mode 100644 vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlHintProviders.java diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFDomain.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFDomain.java new file mode 100644 index 000000000..e231abde7 --- /dev/null +++ b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFDomain.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * 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.commons.cloudfoundry.client; + +public interface CFDomain { + + String getName(); + +} diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFDomainImpl.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFDomainImpl.java new file mode 100644 index 000000000..a8e7be670 --- /dev/null +++ b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFDomainImpl.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * 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.commons.cloudfoundry.client; + +class CFDomainImpl implements CFDomain { + + private final String name; + + public CFDomainImpl(String name) { + this.name = name; + } + + @Override + public String getName() { + return name; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + CFDomainImpl other = (CFDomainImpl) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + + +} diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFEntities.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFEntities.java index 9973cfdc3..395548f86 100644 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFEntities.java +++ b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFEntities.java @@ -29,4 +29,7 @@ public class CFEntities { /* dasboard Url */ null); } + public static CFDomain createDomain(String name) { + return new CFDomainImpl(name); + } } diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/ClientRequests.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/ClientRequests.java index 407b85533..74e797579 100644 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/ClientRequests.java +++ b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/ClientRequests.java @@ -17,4 +17,6 @@ public interface ClientRequests { List getBuildpacks() throws Exception; List getServices() throws Exception; + List getDomains() throws Exception; + } diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/cftarget/CFTarget.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/cftarget/CFTarget.java index 4c6ba97c1..f2087ddf4 100644 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/cftarget/CFTarget.java +++ b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/cftarget/CFTarget.java @@ -15,6 +15,7 @@ import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; 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.ClientRequests; @@ -37,15 +38,21 @@ public class CFTarget { /* * Cached information */ - private final LoadingCache> buildpacksCache; - private final LoadingCache> servicesCache; + private LoadingCache> buildpacksCache; + private LoadingCache> servicesCache; + private LoadingCache> domainCache; private CFCallableContext callableContext; - public CFTarget(String targetName, CFClientParams params, ClientRequests requests, CFCallableContext callableContext) { + public CFTarget(String targetName, CFClientParams params, ClientRequests requests, + CFCallableContext callableContext) { this.params = params; this.requests = requests; this.targetName = targetName; this.callableContext = callableContext; + initCache(requests); + } + + private void initCache(ClientRequests requests) { CacheLoader> servicesLoader = new CacheLoader>() { @Override @@ -71,12 +78,23 @@ public class CFTarget { }; this.buildpacksCache = CacheBuilder.newBuilder() .expireAfterAccess(CFTargetCache.TARGET_EXPIRATION, TimeUnit.HOURS).build(buildpacksLoader); + + CacheLoader> domainLoader = new CacheLoader>() { + + @Override + public List load(String key) throws Exception { + return runAndCheckForFailure(() -> requests.getDomains()); + } + + }; + this.domainCache = CacheBuilder.newBuilder() + .expireAfterAccess(CFTargetCache.TARGET_EXPIRATION, TimeUnit.HOURS).build(domainLoader); } - + protected T runAndCheckForFailure(Callable callable) throws Exception { return callableContext.checkConnection(callable); } - + public boolean hasConnectionError() { return callableContext.hasConnectionError(); } @@ -102,6 +120,11 @@ public class CFTarget { String key = getName(); return this.servicesCache.get(key); } + + public List getDomains() throws Exception { + String key = getName(); + return this.domainCache.get(key); + } public ClientRequests getClientRequests() { return requests; diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/CFWrappingV2.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/CFWrappingV2.java index a3b38fd70..b16829bb4 100644 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/CFWrappingV2.java +++ b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/CFWrappingV2.java @@ -11,10 +11,11 @@ package org.springframework.ide.vscode.commons.cloudfoundry.client.v2; import org.cloudfoundry.operations.buildpacks.Buildpack; -import org.cloudfoundry.operations.services.ServiceInstance; +import org.cloudfoundry.operations.domains.Domain; import org.cloudfoundry.operations.services.ServiceInstanceSummary; import org.cloudfoundry.operations.services.ServiceInstanceType; 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.CFEntities; import org.springframework.ide.vscode.commons.cloudfoundry.client.CFServiceInstance; @@ -32,6 +33,11 @@ public class CFWrappingV2 { return CFEntities.createBuildpack(name); } + public static CFDomain wrap(Domain domain) { + String name = domain.getName(); + return CFEntities.createDomain(name); + } + public static CFServiceInstance wrap(ServiceInstanceSummary serviceInstance) { String name = serviceInstance.getName(); String plan = serviceInstance.getPlan(); diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/DefaultClientRequestsV2.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/DefaultClientRequestsV2.java index 3dd656f61..30646d1d4 100644 --- a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/DefaultClientRequestsV2.java +++ b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/v2/DefaultClientRequestsV2.java @@ -18,6 +18,7 @@ import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.operations.CloudFoundryOperations; import org.cloudfoundry.operations.DefaultCloudFoundryOperations; 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.ClientRequests; import org.springframework.ide.vscode.commons.cloudfoundry.client.ClientTimeouts; @@ -82,7 +83,22 @@ public class DefaultClientRequestsV2 implements ClientRequests { ) ); } + + @Override + public List getDomains() throws Exception { + return ReactorUtils.get(timeouts.getBuildpacksTimeout(), CancelationTokens.NULL, + log("operations.domains.list", + _operations + .domains() + .list() + .map(CFWrappingV2::wrap) + .collectList() + .map(ImmutableList::copyOf) + ) + ); + } + @Override public List getBuildpacks() throws Exception { return ReactorUtils.get(timeouts.getBuildpacksTimeout(), CancelationTokens.NULL, diff --git a/vscode-extensions/commons/commons-cf/src/test/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFClientTest.java b/vscode-extensions/commons/commons-cf/src/test/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFClientTest.java index 32d6a8a65..ddf745ba2 100644 --- a/vscode-extensions/commons/commons-cf/src/test/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFClientTest.java +++ b/vscode-extensions/commons/commons-cf/src/test/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFClientTest.java @@ -20,6 +20,7 @@ import java.util.concurrent.Callable; import org.junit.Before; import org.junit.Test; +import org.mockito.Mockito; import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CFParamsProviderMessages; import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CFTarget; import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CFTargetCache; @@ -28,6 +29,8 @@ import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.Conne import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.NoTargetsException; import org.springframework.ide.vscode.commons.util.ExceptionUtil; +import com.google.common.collect.ImmutableList; + public class CFClientTest { MockCfCli cloudfoundry = new MockCfCli(); @@ -71,6 +74,54 @@ public class CFClientTest { assertError(() -> target.getBuildpacks(), ConnectionException.class, expectedMessages.noNetworkConnection()); } + @Test + public void testBuildpacksFromTarget() throws Exception { + ClientRequests client = cloudfoundry.client; + CFBuildpack buildpack = Mockito.mock(CFBuildpack.class); + when(buildpack.getName()).thenReturn("java_buildpack"); + when(client.getBuildpacks()).thenReturn(ImmutableList.of(buildpack)); + + CFTarget target = targetCache.getOrCreate().get(0); + assertEquals("java_buildpack", target.getBuildpacks().get(0).getName()); + } + + @Test + public void testDomainsFromTarget() throws Exception { + ClientRequests client = cloudfoundry.client; + CFDomain domain = Mockito.mock(CFDomain.class); + when(domain.getName()).thenReturn("cfapps.io"); + when(client.getDomains()).thenReturn(ImmutableList.of(domain)); + + CFTarget target = targetCache.getOrCreate().get(0); + assertEquals("cfapps.io", target.getDomains().get(0).getName()); + } + + @Test + public void testServicesFromTarget() throws Exception { + ClientRequests client = cloudfoundry.client; + CFServiceInstance service = Mockito.mock(CFServiceInstance.class); + when(service.getName()).thenReturn("appdb"); + when(service.getPlan()).thenReturn("spark"); + when(service.getService()).thenReturn("cleardb"); + + when(client.getServices()).thenReturn(ImmutableList.of(service)); + + CFTarget target = targetCache.getOrCreate().get(0); + assertEquals("appdb", target.getServices().get(0).getName()); + assertEquals("spark", target.getServices().get(0).getPlan()); + assertEquals("cleardb", target.getServices().get(0).getService()); + } + + @Test + public void testNoServicesFromTarget() throws Exception { + ClientRequests client = cloudfoundry.client; + + when(client.getServices()).thenReturn(ImmutableList.of()); + + CFTarget target = targetCache.getOrCreate().get(0); + assertTrue(target.getServices().isEmpty()); + } + protected void assertError(Callable callable, Class expected, String expectedMessage) throws Exception { Throwable error = null; diff --git a/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlCFDomainProvider.java b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlCFDomainProvider.java new file mode 100644 index 000000000..235b162e2 --- /dev/null +++ b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlCFDomainProvider.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * 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.Collection; +import java.util.List; + +import org.springframework.ide.vscode.commons.cloudfoundry.client.CFDomain; +import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CFTarget; +import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CFTargetCache; +import org.springframework.ide.vscode.commons.yaml.schema.BasicYValueHint; +import org.springframework.ide.vscode.commons.yaml.schema.YValueHint; + +public class ManifestYamlCFDomainProvider extends AbstractCFHintsProvider { + + public ManifestYamlCFDomainProvider(CFTargetCache cache) { + super(cache); + } + + @Override + public Collection getHints(List targets) throws Exception { + + List hints = new ArrayList<>(); + + for (CFTarget cfTarget : targets) { + + List domains = cfTarget.getDomains(); + if (domains != null && !domains.isEmpty()) { + + for (CFDomain domain : domains) { + String name = domain.getName(); + String label = getBuildpackLabel(cfTarget, domain); + YValueHint hint = new BasicYValueHint(name, label); + if (!hints.contains(hint)) { + hints.add(hint); + } + } + return hints; + } + } + // Contract for the reconciler: return null if values cannot be + // resolved. Otherwise + // return non-empty list + return !hints.isEmpty() ? hints : null; + } + + protected String getBuildpackLabel(CFTarget target, CFDomain domain) { + return domain.getName() + " (" + target.getName() + ")"; + } + + @Override + protected String getTypeName() { + return "Domain"; + } +} diff --git a/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlLanguageServer.java b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlLanguageServer.java index f1fe59da7..9d5e46522 100644 --- a/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlLanguageServer.java +++ b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlLanguageServer.java @@ -63,10 +63,7 @@ public class ManifestYamlLanguageServer extends SimpleLanguageServer { YamlASTProvider parser = new YamlParser(yaml); - Callable> buildPacksProvider = getBuildpacksProvider(); - Callable> servicesProvider = getServicesProvider(); - - schema = new ManifestYmlSchema(buildPacksProvider, servicesProvider); + schema = new ManifestYmlSchema(getHintProviders()); YamlStructureProvider structureProvider = YamlStructureProvider.DEFAULT; YamlAssistContextProvider contextProvider = new SchemaBasedYamlAssistContextProvider(schema); @@ -98,6 +95,30 @@ public class ManifestYamlLanguageServer extends SimpleLanguageServer { documents.onHover(hoverEngine ::getHover); } + protected ManifestYmlHintProviders getHintProviders() { + Callable> buildPacksProvider = getBuildpacksProvider(); + Callable> servicesProvider = getServicesProvider(); + Callable> domainsProvider = getDomainsProvider(); + + return new ManifestYmlHintProviders() { + + @Override + public Callable> getServicesProvider() { + return servicesProvider; + } + + @Override + public Callable> getDomainsProvider() { + return domainsProvider; + } + + @Override + public Callable> getBuildpackProviders() { + return buildPacksProvider; + } + }; + } + private CFTargetCache getCfTargetCache() { if (cfTargetCache == null) { ClientParamsProvider paramsProvider = cfParamsProvider; @@ -114,6 +135,10 @@ public class ManifestYamlLanguageServer extends SimpleLanguageServer { private Callable> getServicesProvider() { return new ManifestYamlCFServicesProvider(getCfTargetCache()); } + + private Callable> getDomainsProvider() { + return new ManifestYamlCFDomainProvider(getCfTargetCache()); + } @Override protected ServerCapabilities getServerCapabilities() { diff --git a/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlHintProviders.java b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlHintProviders.java new file mode 100644 index 000000000..09558ba5b --- /dev/null +++ b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlHintProviders.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * 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.Collection; +import java.util.concurrent.Callable; + +import org.springframework.ide.vscode.commons.yaml.schema.YValueHint; + +public interface ManifestYmlHintProviders { + + Callable> getBuildpackProviders(); + + Callable> getServicesProvider(); + + Callable> getDomainsProvider(); + +} diff --git a/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchema.java b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchema.java index 8f2e0f722..1c2a46ec2 100644 --- a/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchema.java +++ b/vscode-extensions/vscode-manifest-yaml/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchema.java @@ -47,8 +47,13 @@ public class ManifestYmlSchema implements YamlSchema { return IntegerRange.exactly(1); } - public ManifestYmlSchema(Callable> buildpackProvider, Callable> servicesProvider) { - this.buildpackProvider = buildpackProvider; + + public ManifestYmlSchema(ManifestYmlHintProviders providers) { + this.buildpackProvider = providers.getBuildpackProviders(); + Callable> servicesProvider = providers.getServicesProvider(); + Callable> domainsProvider = providers.getDomainsProvider(); + + YTypeFactory f = new YTypeFactory(); TYPE_UTIL = f.TYPE_UTIL; @@ -63,7 +68,17 @@ public class ManifestYmlSchema implements YamlSchema { t_buildpack.addHintProvider(this.buildpackProvider); // t_buildpack.parseWith(ManifestYmlValueParsers.fromHints(t_buildpack.toString(), buildpackProvider)); } + + YAtomicType t_domain = f.yatomic("Domain"); + YAtomicType t_domains_string = f.yatomic("Domains"); + if (domainsProvider != null) { + t_domain.addHintProvider(domainsProvider); + t_domains_string.addHintProvider(domainsProvider); + } + + YType t_domains = f.yseq(t_domains_string); + YAtomicType t_service_string = f.yatomic("Service"); if (servicesProvider != null) { t_service_string.addHintProvider(servicesProvider); @@ -112,8 +127,8 @@ public class ManifestYmlSchema implements YamlSchema { f.yprop("buildpack", t_buildpack), f.yprop("command", t_string), f.yprop("disk_quota", t_memory), - f.yprop("domain", t_string), - f.yprop("domains", t_strings), + f.yprop("domain", t_domain), + f.yprop("domains", t_domains), f.yprop("env", t_env), f.yprop("host", t_string), f.yprop("hosts", t_strings), diff --git a/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorTest.java b/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorTest.java index 4444cf279..94d089d50 100644 --- a/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorTest.java +++ b/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYamlEditorTest.java @@ -25,6 +25,7 @@ import org.junit.Before; 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.CFDomain; 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.NoTargetsException; @@ -936,6 +937,44 @@ public class ManifestYamlEditorTest { when(cfClient.getBuildpacks()).thenReturn(ImmutableList.of(buildPack)); assertDoesNotContainCompletions("buildpack: <*>", "buildpack: wrong_buildpack<*>"); } + + @Test + public void domainContentAssist() throws Exception { + ClientRequests cfClient = cloudfoundry.client; + CFDomain domain = Mockito.mock(CFDomain.class); + when(domain.getName()).thenReturn("cfapps.io"); + when(cfClient.getDomains()).thenReturn(ImmutableList.of(domain)); + + assertContainsCompletions("domain: <*>", "domain: cfapps.io<*>"); + } + + @Test + public void domainContentAssistDoesNotContainCompletion() throws Exception { + ClientRequests cfClient = cloudfoundry.client; + CFDomain domain = Mockito.mock(CFDomain.class); + when(domain.getName()).thenReturn("cfapps.io"); + when(cfClient.getDomains()).thenReturn(ImmutableList.of(domain)); + assertDoesNotContainCompletions("domain: <*>", "domain: wrong.cfapps.io<*>"); + } + + @Test + public void domainsContentAssist() throws Exception { + ClientRequests cfClient = cloudfoundry.client; + CFDomain domain = Mockito.mock(CFDomain.class); + when(domain.getName()).thenReturn("cfapps.io"); + when(cfClient.getDomains()).thenReturn(ImmutableList.of(domain)); + + assertContainsCompletions("domains:\n" + " - <*>", "cfapps.io"); + } + + @Test + public void domainsContentAssistWrongDomain() throws Exception { + ClientRequests cfClient = cloudfoundry.client; + CFDomain domain = Mockito.mock(CFDomain.class); + when(domain.getName()).thenReturn("cfapps.io"); + when(cfClient.getDomains()).thenReturn(ImmutableList.of(domain)); + assertDoesNotContainCompletions("domains:\n" + " - <*>", "wrong.cfapps.io"); + } ////////////////////////////////////////////////////////////////////////////// diff --git a/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchemaTest.java b/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchemaTest.java index 5d7af42c8..a1e726ee9 100644 --- a/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchemaTest.java +++ b/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchemaTest.java @@ -14,13 +14,16 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.concurrent.Callable; import org.junit.Test; import org.springframework.ide.vscode.commons.util.Renderables; import org.springframework.ide.vscode.commons.util.StringUtil; import org.springframework.ide.vscode.commons.yaml.schema.YTypedProperty; +import org.springframework.ide.vscode.commons.yaml.schema.YValueHint; import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.AbstractType; import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YSeqType; import org.springframework.ide.vscode.manifest.yaml.ManifestYmlSchema; @@ -81,7 +84,7 @@ public class ManifestYmlSchemaTest { "timeout" }; - ManifestYmlSchema schema = new ManifestYmlSchema(null, null); + ManifestYmlSchema schema = new ManifestYmlSchema(EMPTY_PROVIDERS); @Test public void toplevelProperties() throws Exception { @@ -150,5 +153,22 @@ public class ManifestYmlSchemaTest { } return builder.build(); } - + + private static final ManifestYmlHintProviders EMPTY_PROVIDERS = new ManifestYmlHintProviders() { + + @Override + public Callable> getServicesProvider() { + return null; + } + + @Override + public Callable> getDomainsProvider() { + return null; + } + + @Override + public Callable> getBuildpackProviders() { + return null; + } + }; }