Create CF service instances via a factory

This commit is contained in:
nsingh
2017-01-25 14:38:37 -08:00
parent c81bafc95f
commit 4dc0665bdb
4 changed files with 146 additions and 109 deletions

View File

@@ -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);
}
}

View File

@@ -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.
* <p/>
* 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;
}
}

View File

@@ -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;
}
}
}

View File

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