@Test public void testMatchesHardwareWithIdPredicate() { final Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>>ofInstance(ImmutableSet.<Location>of(region)); final Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>>ofInstance( ImmutableSet.<Image>of( new ImageBuilder() .ids("Ubuntu 11.04 x64") .name("Ubuntu 11.04 x64") .description("Ubuntu 11.04 x64") .location(region) .status(Status.AVAILABLE) .operatingSystem( OperatingSystem.builder() .name("Ubuntu 11.04 x64") .description("Ubuntu 11.04 x64") .is64Bit(true) .version("11.04") .family(OsFamily.UBUNTU) .build()) .build(), new ImageBuilder() .ids("Ubuntu 11.04 64-bit") .name("Ubuntu 11.04 64-bit") .description("Ubuntu 11.04 64-bit") .location(region) .status(Status.AVAILABLE) .operatingSystem( OperatingSystem.builder() .name("Ubuntu 11.04 64-bit") .description("Ubuntu 11.04 64-bit") .is64Bit(true) .version("11.04") .family(OsFamily.UBUNTU) .build()) .build())); final Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>>ofInstance( ImmutableSet.<Hardware>of( new HardwareBuilder() .ids( String.format( "datacenter(%s)platform(%s)cpuCores(%d)memorySizeMB(%d)diskSizeGB(%d)", "Falkenberg", "Xen", 1, 512, 5)) .ram(512) .processors(ImmutableList.of(new Processor(1, 1.0))) .volumes(ImmutableList.<Volume>of(new VolumeImpl((float) 5, true, true))) .hypervisor("Xen") .location(region) .supportsImage(ImagePredicates.idIn(ImmutableSet.of("Ubuntu 11.04 x64"))) .build(), new HardwareBuilder() .ids( String.format( "datacenter(%s)platform(%s)cpuCores(%d)memorySizeMB(%d)diskSizeGB(%d)", "Falkenberg", "OpenVZ", 1, 512, 5)) .ram(512) .processors(ImmutableList.of(new Processor(1, 1.0))) .volumes(ImmutableList.<Volume>of(new VolumeImpl((float) 5, true, true))) .hypervisor("OpenVZ") .location(region) .supportsImage(ImagePredicates.idIn(ImmutableSet.of("Ubuntu 11.04 64-bit"))) .build())); final Provider<TemplateOptions> optionsProvider = new Provider<TemplateOptions>() { @Override public TemplateOptions get() { return new TemplateOptions(); } }; Provider<TemplateBuilder> templateBuilderProvider = new Provider<TemplateBuilder>() { @Override public TemplateBuilder get() { return createTemplateBuilder( null, locations, images, hardwares, region, optionsProvider, this); } }; TemplateBuilder templateBuilder = templateBuilderProvider .get() .minRam(512) .osFamily(OsFamily.UBUNTU) .hypervisorMatches("OpenVZ") .osVersionMatches("1[10].[10][04]") .os64Bit(true); assertEquals( templateBuilder.toString(), "{minRam=512, minRam=512, osFamily=ubuntu, osVersion=1[10].[10][04], os64Bit=true, hypervisor=OpenVZ}"); Template template = templateBuilder.build(); assertEquals(template.getHardware().getHypervisor(), "OpenVZ"); assertEquals(template.getImage().getId(), "Ubuntu 11.04 64-bit"); }
@Test public void testFromSpecWithLoginUser() { final Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>>ofInstance(ImmutableSet.<Location>of(region)); final Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>>ofInstance( ImmutableSet.<Image>of( new ImageBuilder() .id("us-east-2/ami-ffff") .providerId("ami-ffff") .name("Ubuntu 11.04 x64") .description("Ubuntu 11.04 x64") .location(region2) .status(Status.AVAILABLE) .operatingSystem( OperatingSystem.builder() .name("Ubuntu 11.04 x64") .description("Ubuntu 11.04 x64") .is64Bit(true) .version("11.04") .family(OsFamily.UBUNTU) .build()) .build())); final Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>>ofInstance( ImmutableSet.<Hardware>of( new HardwareBuilder() .ids("m1.small") .ram(512) .processors(ImmutableList.of(new Processor(1, 1.0))) .volumes(ImmutableList.<Volume>of(new VolumeImpl((float) 5, true, true))) .build())); final Provider<TemplateOptions> optionsProvider = new Provider<TemplateOptions>() { @Override public TemplateOptions get() { return new TemplateOptions(); } }; Provider<TemplateBuilder> templateBuilderProvider = new Provider<TemplateBuilder>() { @Override public TemplateBuilder get() { return createTemplateBuilder( null, locations, images, hardwares, region, optionsProvider, this); } }; TemplateBuilder templateBuilder = templateBuilderProvider .get() .from( "hardwareId=m1.small,imageId=us-east-2/ami-ffff,loginUser=user:Password01,authenticateSudo=true"); assertEquals(templateBuilder.toString(), "{imageId=us-east-2/ami-ffff, hardwareId=m1.small}"); Template template = templateBuilder.build(); assertEquals(template.getLocation().getId(), "us-east-2"); assertEquals(template.getOptions().getLoginUser(), "user"); assertEquals(template.getOptions().getLoginPassword(), "Password01"); assertEquals(template.getOptions().getLoginPrivateKey(), null); assertEquals(template.getOptions().shouldAuthenticateSudo(), Boolean.TRUE); }