From 4dc0665bdb76878eb6a8671d5bb441faff3cabab Mon Sep 17 00:00:00 2001 From: nsingh Date: Wed, 25 Jan 2017 14:38:37 -0800 Subject: [PATCH] Create CF service instances via a factory --- .../cloudfoundry/client/CFEntities.java | 6 + .../client/CFServiceInstanceImpl.java | 123 ++++++++++++++++++ .../cloudfoundry/client/v2/CFWrappingV2.java | 117 ++--------------- .../manifest/yaml/BasicCfClientHarness.java | 9 +- 4 files changed, 146 insertions(+), 109 deletions(-) create mode 100644 vscode-extensions/commons/commons-cf/src/main/java/org/springframework/ide/vscode/commons/cloudfoundry/client/CFServiceInstanceImpl.java 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 55d2653ad..bc4e5a401 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 @@ -18,4 +18,10 @@ 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 32cd7ae43..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,8 +14,8 @@ 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.CFServiceInstance; import org.springframework.ide.vscode.commons.cloudfoundry.client.CFEntities; +import org.springframework.ide.vscode.commons.cloudfoundry.client.CFServiceInstance; /** * Various helper methods to 'wrap' objects returned by CF client into our own @@ -31,112 +31,15 @@ public class CFWrappingV2 { 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 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/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 index c37fe3be7..c809ac558 100644 --- 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 @@ -30,7 +30,12 @@ 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) + * 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 { @@ -70,7 +75,7 @@ public class BasicCfClientHarness { /* * Create the client "ahead of time" so that it can be configured before - * the language server is tested + * the language server is tested */ private BasicClientRequests preexistingClient = new BasicClientRequests(DEFAULT_PARAMS, new ClientTimeouts());