diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFBuildpackImpl.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFBuildpackImpl.java new file mode 100644 index 000000000..fc06596f4 --- /dev/null +++ b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFBuildpackImpl.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * 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; + +/** + * Package-private. + *
+ * Use {@link CFEntities} public API to create instance + * + */ +class CFBuildpackImpl implements CFBuildpack { + + private final String name; + + public CFBuildpackImpl(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; + CFBuildpackImpl other = (CFBuildpackImpl) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + +} \ No newline at end of file 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 new file mode 100644 index 000000000..bc4e5a401 --- /dev/null +++ b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFEntities.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * 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; + +/** + * Factory to create CF "Entities" like CF services, buildpacks, etc.. + */ +public class CFEntities { + + public static CFBuildpack createBuildpack(String name) { + return new CFBuildpackImpl(name); + } + + public static CFServiceInstance createServiceInstance(String name, String service, String plan, + String documentationUrl, String description, String dashboardUrl) { + return new CFServiceInstanceImpl(name, service, plan, documentationUrl, description, dashboardUrl); + } + +} diff --git a/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFServiceInstanceImpl.java b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFServiceInstanceImpl.java new file mode 100644 index 000000000..c6dd53138 --- /dev/null +++ b/vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFServiceInstanceImpl.java @@ -0,0 +1,123 @@ +/******************************************************************************* + * 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; + +/** + * Package-private. + * + * Use {@link CFEntities} public API to create instance + * + */ +class CFServiceInstanceImpl implements CFServiceInstance { + + private String service; + private String plan; + private String name; + private String documentationUrl; + private String description; + private String dashboardUrl; + + public CFServiceInstanceImpl(String name, String service, String plan, String documentationUrl, String description, + String dashboardUrl) { + this.name = name; + this.service = service; + this.plan = plan; + this.documentationUrl = documentationUrl; + this.description = description; + this.dashboardUrl = dashboardUrl; + } + + @Override + public String getService() { + return service; + } + + @Override + public String getPlan() { + return plan; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getDocumentationUrl() { + return documentationUrl; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public String getDashboardUrl() { + return dashboardUrl; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((dashboardUrl == null) ? 0 : dashboardUrl.hashCode()); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((documentationUrl == null) ? 0 : documentationUrl.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((plan == null) ? 0 : plan.hashCode()); + result = prime * result + ((service == null) ? 0 : service.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; + CFServiceInstanceImpl other = (CFServiceInstanceImpl) obj; + if (dashboardUrl == null) { + if (other.dashboardUrl != null) + return false; + } else if (!dashboardUrl.equals(other.dashboardUrl)) + return false; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (documentationUrl == null) { + if (other.documentationUrl != null) + return false; + } else if (!documentationUrl.equals(other.documentationUrl)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (plan == null) { + if (other.plan != null) + return false; + } else if (!plan.equals(other.plan)) + return false; + if (service == null) { + if (other.service != null) + return false; + } else if (!service.equals(other.service)) + return false; + return true; + } + +} 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 da43a475a..777c8f9bf 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 @@ -14,6 +14,7 @@ import org.cloudfoundry.operations.buildpacks.Buildpack; import org.cloudfoundry.operations.services.ServiceInstance; import org.cloudfoundry.operations.services.ServiceInstanceType; 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; /** @@ -27,159 +28,18 @@ public class CFWrappingV2 { public static CFBuildpack wrap(Buildpack buildpack) { String name = buildpack.getName(); - return new CFBuildpackImpl(name); + return CFEntities.createBuildpack(name); } - public static CFServiceInstance wrap(ServiceInstance service) { - return new CFServiceInstanceImpl(service); + public static CFServiceInstance wrap(ServiceInstance serviceInstance) { + String name = serviceInstance.getName(); + String plan = serviceInstance.getPlan(); + String dashboardUrl = serviceInstance.getDashboardUrl(); + String service = serviceInstance.getType() == ServiceInstanceType.USER_PROVIDED ? "user-provided" + : serviceInstance.getService(); + String description = serviceInstance.getDescription(); + String documentationUrl = serviceInstance.getDocumentationUrl(); + return CFEntities.createServiceInstance(name, service, plan, documentationUrl, description, dashboardUrl); } - public static CFBuildpack buildpack(String name) { - return new CFBuildpackImpl(name); - } - - public static class CFBuildpackImpl implements CFBuildpack { - - private final String name; - - public CFBuildpackImpl(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; - CFBuildpackImpl other = (CFBuildpackImpl) obj; - if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; - return true; - } - - } - - public static class CFServiceInstanceImpl implements CFServiceInstance { - - private final String name; - private final String plan; - private final String dashboardUrl; - private final String service; - private final String description; - private final String documentationUrl; - - public CFServiceInstanceImpl(ServiceInstance serviceInstance) { - this.name = serviceInstance.getName(); - this.plan = serviceInstance.getPlan(); - this.dashboardUrl = serviceInstance.getDashboardUrl(); - this.service = serviceInstance.getType() == ServiceInstanceType.USER_PROVIDED ? "user-provided" - : serviceInstance.getService(); - this.description = serviceInstance.getDescription(); - this.documentationUrl = serviceInstance.getDocumentationUrl(); - } - - @Override - public String getName() { - return this.name; - } - - @Override - public String getPlan() { - return this.plan; - } - - @Override - public String getDashboardUrl() { - return this.dashboardUrl; - } - - @Override - public String getService() { - return this.service; - } - - @Override - public String getDescription() { - return this.description; - } - - @Override - public String getDocumentationUrl() { - return this.documentationUrl; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((dashboardUrl == null) ? 0 : dashboardUrl.hashCode()); - result = prime * result + ((description == null) ? 0 : description.hashCode()); - result = prime * result + ((documentationUrl == null) ? 0 : documentationUrl.hashCode()); - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + ((plan == null) ? 0 : plan.hashCode()); - result = prime * result + ((service == null) ? 0 : service.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; - CFServiceInstanceImpl other = (CFServiceInstanceImpl) obj; - if (dashboardUrl == null) { - if (other.dashboardUrl != null) - return false; - } else if (!dashboardUrl.equals(other.dashboardUrl)) - return false; - if (description == null) { - if (other.description != null) - return false; - } else if (!description.equals(other.description)) - return false; - if (documentationUrl == null) { - if (other.documentationUrl != null) - return false; - } else if (!documentationUrl.equals(other.documentationUrl)) - return false; - if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; - if (plan == null) { - if (other.plan != null) - return false; - } else if (!plan.equals(other.plan)) - return false; - if (service == null) { - if (other.service != null) - return false; - } else if (!service.equals(other.service)) - return false; - return true; - } - } } diff --git a/vscode-extensions/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/Editor.java b/vscode-extensions/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/Editor.java index fed25236a..8dd22bd11 100644 --- a/vscode-extensions/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/Editor.java +++ b/vscode-extensions/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/Editor.java @@ -14,7 +14,7 @@ package org.springframework.ide.vscode.languageserver.testharness; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.springframework.ide.vscode.languageserver.testharness.TestAsserts.assertContains; +import static org.springframework.ide.vscode.languageserver.testharness.TestAsserts.*; import java.util.ArrayList; import java.util.Collections; @@ -264,6 +264,22 @@ public class Editor { } } + public void assertDoesNotContainCompletions(String... notToBeFound) throws Exception { + StringBuilder actual = new StringBuilder(); + + for (CompletionItem completion : getCompletions()) { + Editor editor = this.clone(); + editor.apply(completion); + actual.append(editor.getText()); + actual.append("\n-------------------\n"); + } + String actualText = actual.toString(); + + for (String after : notToBeFound) { + assertDoesNotContain(after, actualText); + } + } + public void apply(CompletionItem completion) throws Exception { TextEdit edit = completion.getTextEdit(); String docText = document.getText(); diff --git a/vscode-extensions/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/TestAsserts.java b/vscode-extensions/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/TestAsserts.java index e29df919f..0431db23b 100644 --- a/vscode-extensions/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/TestAsserts.java +++ b/vscode-extensions/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/TestAsserts.java @@ -21,4 +21,9 @@ public class TestAsserts { } } + public static void assertDoesNotContain(String needle, String haystack) { + if (haystack!=null && haystack.contains(needle)) { + fail("Found: "+needle+"\n in \n"+haystack); + } + } } diff --git a/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/BasicCfClientHarness.java b/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/BasicCfClientHarness.java new file mode 100644 index 000000000..c809ac558 --- /dev/null +++ b/vscode-extensions/vscode-manifest-yaml/src/test/java/org/springframework/ide/vscode/manifest/yaml/BasicCfClientHarness.java @@ -0,0 +1,148 @@ +/******************************************************************************* + * 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). + * + * 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 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