Added junit to test actual CF client in LS using LS target cache
This commit is contained in:
@@ -56,4 +56,10 @@ public interface CfClientConfig {
|
||||
static CfClientConfig createDefault() {
|
||||
return new CfClientConfigImpl();
|
||||
}
|
||||
|
||||
static CfClientConfig createDefault(ClientParamsProvider provider) {
|
||||
CfClientConfigImpl config = new CfClientConfigImpl();
|
||||
config.setClientParamsProvider(provider);
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018 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.io.IOException;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CFCredentials;
|
||||
import org.springframework.ide.vscode.commons.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* @author Kris De Volder
|
||||
*/
|
||||
public class CfTestTargetParams {
|
||||
|
||||
public final String api;
|
||||
public final CFCredentials credentials;
|
||||
public final String space;
|
||||
public final String org;
|
||||
|
||||
public CfTestTargetParams(String api, CFCredentials credentials, String org, String space) {
|
||||
this.api = api;
|
||||
this.credentials = credentials;
|
||||
this.org = org;
|
||||
this.space = space;
|
||||
}
|
||||
|
||||
public static CfTestTargetParams fromEnv() {
|
||||
try {
|
||||
String refreshToken = fromEnv("CF_TEST_REFRESH_TOKEN");
|
||||
CFCredentials credentials = CFCredentials.fromRefreshToken(refreshToken);
|
||||
return new CfTestTargetParams(fromEnv("CF_TEST_API_URL"), credentials, fromEnv("CF_TEST_ORG"),
|
||||
fromEnvOrFile("CF_TEST_SPACE"));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String fromEnvOrFile(String name) throws IOException {
|
||||
String envVal = getEnvMaybe(name);
|
||||
if (envVal != null) {
|
||||
return envVal;
|
||||
} else {
|
||||
String fileName = fromEnv(name + "_FILE");
|
||||
Path path = FileSystems.getDefault().getPath(fileName);
|
||||
return Files.readAllLines(path).get(0);
|
||||
}
|
||||
}
|
||||
|
||||
private static String getEnvMaybe(String name) {
|
||||
String val = System.getenv(name);
|
||||
if (!StringUtils.hasText(val)) {
|
||||
val = System.getenv("bamboo_" + name);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
public static String fromEnv(String name) {
|
||||
String value = getEnvMaybe(name);
|
||||
Assert.isLegal(StringUtils.hasText(value), "The environment varable '" + name + "' must be set");
|
||||
return value;
|
||||
}
|
||||
|
||||
private static boolean fromEnvBoolean(String name) {
|
||||
String value = getEnvMaybe(name);
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
return Boolean.parseBoolean(value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018 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 static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.ide.vscode.commons.cloudfoundry.client.CFBuildpack;
|
||||
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.CFTarget;
|
||||
import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CFTargetCache;
|
||||
import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CfClientConfig;
|
||||
import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CfTargetsInfo;
|
||||
import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CfTargetsInfoProvder;
|
||||
import org.springframework.ide.vscode.commons.cloudfoundry.client.v2.DefaultCloudFoundryClientFactoryV2;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class ManifestYamlActualCfClientTest {
|
||||
|
||||
private CFTargetCache cfTargetCache;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
CfTargetsInfo info = getTargetsInfoFromEnv();
|
||||
CfTargetsInfoProvder provider = new CfTargetsInfoProvder(info);
|
||||
CfClientConfig cfClientConfig = CfClientConfig.createDefault(provider);
|
||||
CloudFoundryClientFactory clientFactory = DefaultCloudFoundryClientFactoryV2.INSTANCE;
|
||||
cfTargetCache = new CFTargetCache(cfClientConfig, clientFactory, new ClientTimeouts());
|
||||
}
|
||||
|
||||
private CfTargetsInfo getTargetsInfoFromEnv() {
|
||||
CfTestTargetParams testParams = CfTestTargetParams.fromEnv();
|
||||
String rawJson = "{\n" + " \"cfTargets\": [\n" + " {\n"
|
||||
+ " \"api\":\"" + testParams.api + "\",\n"
|
||||
+ " \"org\":\"" + testParams.org + "\",\n"
|
||||
+ " \"space\": \"" + testParams.space + "\",\n"
|
||||
+ " \"refreshToken\": \"" + testParams.credentials.getSecret() + "\",\n"
|
||||
+ " \"sslDisabled\": false\n"
|
||||
+ " }\n" + " ],\n" + " \"cfDiagnosticMessages\": {\n"
|
||||
+ " \"noTargetsFound\": \"No Cloud Foundry targets found: Connect CF Target(s) in Boot Dashboard or login via CF CLI\",\n"
|
||||
+ " \"unauthorised\": \"Permission denied: Verify credentials to CF Target from Boot Dashboard or CF CLI are correct\",\n"
|
||||
+ " \"noNetworkConnection\": \"No connection to Cloud Foundry: Connect CF Target via Boot Dashboard or login via CF CLI or verify network connections\",\n"
|
||||
+ " \"noOrgSpace\": \"No org/space selected: Connect CF Target in Boot Dashboard or login via CF CLI\"\n"
|
||||
+ " }\n" + "}";
|
||||
return new Gson().fromJson(rawJson, CfTargetsInfo.class);
|
||||
}
|
||||
|
||||
@Ignore @Test
|
||||
public void testGetBuildpacks() throws Exception {
|
||||
List<CFTarget> targets = cfTargetCache.getOrCreate();
|
||||
assertTrue(targets.size() == 1);
|
||||
CFTarget target = targets.get(0);
|
||||
List<CFBuildpack> buildpacks = target.getBuildpacks();
|
||||
assertTrue(!buildpacks.isEmpty());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user