issue 384: preparing vbox 1.5.1 - adapt ContextModule to external changes

This commit is contained in:
Andrea Turli 2012-03-29 11:35:49 +01:00
parent e27db18cfd
commit af309232ad
3 changed files with 20 additions and 26 deletions

View File

@ -138,8 +138,7 @@ public class VirtualBoxComputeServiceContextModule extends
bind(new TypeLiteral<Supplier<Map<Image, YamlImage>>>() {
}).to((Class) ImagesToYamlImagesFromYamlDescriptor.class);
// the yaml config provider
bind(new TypeLiteral<Supplier<String>>() {
}).to((Class) YamlImagesFromFileConfig.class);
bind(YamlImagesFromFileConfig.class);
// the master machines cache
bind(new TypeLiteral<LoadingCache<Image, Master>>() {
}).to((Class) MastersLoadingCache.class);

View File

@ -30,6 +30,7 @@ import javax.inject.Singleton;
import org.jclouds.compute.domain.Image;
import org.jclouds.virtualbox.domain.YamlImage;
import org.jclouds.virtualbox.functions.YamlImagesFromFileConfig;
import org.yaml.snakeyaml.Loader;
import org.yaml.snakeyaml.TypeDescription;
import org.yaml.snakeyaml.Yaml;
@ -47,7 +48,7 @@ public class ImagesToYamlImagesFromYamlDescriptor implements Supplier<Map<Image,
private String yamlDescriptor;
@Inject
public ImagesToYamlImagesFromYamlDescriptor(Supplier<String> yamlDescriptorSupplier) {
public ImagesToYamlImagesFromYamlDescriptor(/*Supplier<String> yamlDescriptorSupplier*/YamlImagesFromFileConfig yamlDescriptorSupplier) {
this.yamlDescriptor = yamlDescriptorSupplier.get();
checkNotNull(yamlDescriptor, "yaml descriptor");
checkState(!yamlDescriptor.equals(""), "yaml descriptor is empty");

View File

@ -28,9 +28,9 @@ import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.virtualbox.functions.YamlImagesFromFileConfig;
import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
/**
@ -39,29 +39,23 @@ import com.google.common.collect.Iterables;
@Test(groups = "unit")
public class ImageFromYamlStringTest {
public static final Image TEST1 = new ImageBuilder()
.id("default-ubuntu-11.04-i386")
.name("ubuntu-11.04-server-i386")
.description("ubuntu 11.04 server (i386)")
.operatingSystem(
OperatingSystem.builder().description("ubuntu").family(OsFamily.UBUNTU)
.version("11.04").build()).build();
public static final Image TEST1 = new ImageBuilder()
.id("default-ubuntu-11.04-i386")
.name("ubuntu-11.04-server-i386")
.description("ubuntu 11.04 server (i386)")
.operatingSystem(
OperatingSystem.builder().description("ubuntu").family(OsFamily.UBUNTU).version("11.04").build())
.build();
@Test
public void testNodesParse() throws Exception {
@Test
public void testNodesParse() throws Exception {
final StringBuilder yamlFileLines = new StringBuilder();
for (Object line : IOUtils.readLines(new InputStreamReader(getClass().getResourceAsStream("/default-images.yaml")))) {
yamlFileLines.append(line).append("\n");
}
ImagesToYamlImagesFromYamlDescriptor parser = new ImagesToYamlImagesFromYamlDescriptor(new Supplier<String>() {
@Override
public String get() {
return yamlFileLines.toString();
final StringBuilder yamlFileLines = new StringBuilder();
for (Object line : IOUtils
.readLines(new InputStreamReader(getClass().getResourceAsStream("/default-images.yaml")))) {
yamlFileLines.append(line).append("\n");
}
});
assertEquals(Iterables.getFirst(parser.get().keySet(), null), TEST1);
}
ImagesToYamlImagesFromYamlDescriptor parser = new ImagesToYamlImagesFromYamlDescriptor(new YamlImagesFromFileConfig("/default-images.yaml"));
assertEquals(Iterables.getFirst(parser.get().keySet(), null), TEST1);
}
}