Fixes related config settings now being JsonElement

This commit is contained in:
Kris De Volder
2018-03-19 11:25:31 -07:00
parent 68bb25d673
commit 1d287b0529
8 changed files with 71 additions and 23 deletions

View File

@@ -30,13 +30,13 @@ public class BoshCliConfig {
private Settings settings = new Settings(null);
public String getCommand() {
return (String) settings.getProperty("bosh", "cli", "command");
return settings.getString("bosh", "cli", "command");
}
public String getTarget() {
return (String) settings.getProperty("bosh", "cli", "target");
return settings.getString("bosh", "cli", "target");
}
public Duration getTimeout() {
Integer seconds = (Integer) settings.getProperty("cli", "timeout");
Integer seconds = settings.getInt("cli", "timeout");
return seconds == null ? Duration.ofSeconds(3) : Duration.ofSeconds(seconds);
}

View File

@@ -30,6 +30,8 @@ import org.springframework.ide.vscode.commons.yaml.schema.DynamicSchemaContext;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
public class BoshCommandStemcellsProviderTest {
@@ -83,12 +85,12 @@ public class BoshCommandStemcellsProviderTest {
// }
@Test public void obeysCliConfigCommandAndTarget() throws Exception {
Map<String, Object> settings = ImmutableMap.of("bosh", ImmutableMap.of("cli",
JsonElement settings = settings(ImmutableMap.of("bosh", ImmutableMap.of("cli",
ImmutableMap.of(
"command", "alternate-command",
"target", "some-target"
)
));
)));
cliConfig.handleConfigurationChange(new Settings(settings));
assertEquals(ImmutableList.of(
new StemcellData("bosh-vsphere-esxi-centos-7-go_agent", "3421.11", "centos-7"),
@@ -100,12 +102,12 @@ public class BoshCommandStemcellsProviderTest {
}
@Test public void obeysCliConfigTarget() throws Exception {
Map<String, Object> settings = ImmutableMap.of("bosh", ImmutableMap.of("cli",
JsonElement settings = settings(ImmutableMap.of("bosh", ImmutableMap.of("cli",
ImmutableMap.of(
"command", "alternate-command",
"target", "explicit-target"
)
));
)));
cliConfig.handleConfigurationChange(new Settings(settings));
assertEquals(ImmutableList.of(
new StemcellData("bosh-vsphere-esxi-centos-7-go_agent", "3421.11", "centos-7"),
@@ -116,4 +118,8 @@ public class BoshCommandStemcellsProviderTest {
verify(provider).executeCommand(eq(new ExternalCommand("alternate-command", "-e", "explicit-target", "stemcells", "--json")));
}
private JsonElement settings(Object configObject) {
Gson gson = new Gson();
return gson.toJsonTree(configObject);
}
}