@SuppressWarnings("unchecked") @Test public void testNothingUsesDefaultTemplateBuilder() { Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet .<Location> of()); Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()); Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet .<Hardware> of()); Location defaultLocation = createMock(Location.class); Provider<TemplateOptions> optionsProvider = createMock(Provider.class); Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class); TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class); GetImageStrategy getImageStrategy = createMock(GetImageStrategy.class); expect(templateBuilderProvider.get()).andReturn(defaultTemplate); expect(defaultTemplate.build()).andReturn(null); replay(defaultTemplate, defaultLocation, optionsProvider, templateBuilderProvider, getImageStrategy); TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, hardwares, defaultLocation, optionsProvider, templateBuilderProvider, getImageStrategy); template.build(); verify(defaultTemplate, defaultLocation, optionsProvider, templateBuilderProvider, getImageStrategy); }
@Override public Template build() { if (nothingChangedExceptOptions()) { TemplateBuilder defaultTemplate = defaultTemplateProvider.get(); if (options != null) defaultTemplate.options(options); return defaultTemplate.build(); } if (options == null) options = optionsProvider.get(); logger.debug(">> searching params(%s)", this); Set<? extends Image> images = getImages(); checkState(!images.isEmpty(), "no images present!"); Set<? extends Hardware> hardwaresToSearch = hardwares.get(); checkState(!hardwaresToSearch.isEmpty(), "no hardware profiles present!"); Image image = null; if (imageId != null) { image = loadImageWithId(images); if (currentLocationWiderThan(image.getLocation())) this.location = image.getLocation(); } Hardware hardware = null; if (hardwareId != null) { hardware = findHardwareWithId(hardwaresToSearch); if (currentLocationWiderThan(hardware.getLocation())) this.location = hardware.getLocation(); } if (location == null) location = defaultLocation.get(); if (image == null) { Iterable<? extends Image> supportedImages = findSupportedImages(images); if (hardware == null) hardware = resolveHardware(hardwaresToSearch, supportedImages); image = resolveImage(hardware, supportedImages); } else { if (hardware == null) hardware = resolveHardware(hardwaresToSearch, ImmutableSet.of(image)); } logger.debug("<< matched image(%s) hardware(%s) location(%s)", image.getId(), hardware.getId(), location.getId()); return new TemplateImpl(image, hardware, location, options); }
TemplateBuilderImpl implements TemplateBuilder { @Override public Template build() { if (nothingChangedExceptOptions()) { TemplateBuilder defaultTemplate = defaultTemplateProvider.get(); if (options != null) defaultTemplate.options(options); return defaultTemplate.build(); } if (options == null) options = optionsProvider.get(); logger.debug(">> searching params(%s)", this); Set<? extends Image> images = getImages(); checkState(!images.isEmpty(), "no images present!"); Set<? extends Hardware> hardwaresToSearch = hardwares.get(); checkState(!hardwaresToSearch.isEmpty(), "no hardware profiles present!"); Image image = null; if (imageId != null) { image = loadImageWithId(images); if (currentLocationWiderThan(image.getLocation())) this.location = image.getLocation(); } Hardware hardware = null; if (hardwareId != null) { hardware = findHardwareWithId(hardwaresToSearch); if (currentLocationWiderThan(hardware.getLocation())) this.location = hardware.getLocation(); } if (location == null) location = defaultLocation.get(); if (image == null) { Iterable<? extends Image> supportedImages = findSupportedImages(images); if (hardware == null) hardware = resolveHardware(hardwaresToSearch, supportedImages); image = resolveImage(hardware, supportedImages); } else { if (hardware == null) hardware = resolveHardware(hardwaresToSearch, ImmutableSet.of(image)); } logger.debug("<< matched image(%s) hardware(%s) location(%s)", image.getId(), hardware.getId(), location.getId()); return new TemplateImpl(image, hardware, location, options); } }
TemplateBuilderImpl implements TemplateBuilder { @Override public Template build() { if (nothingChangedExceptOptions()) { TemplateBuilder defaultTemplate = defaultTemplateProvider.get(); if (options != null) defaultTemplate.options(options); return defaultTemplate.build(); } if (options == null) options = optionsProvider.get(); logger.debug(">> searching params(%s)", this); Set<? extends Image> images = getImages(); checkState(!images.isEmpty(), "no images present!"); Set<? extends Hardware> hardwaresToSearch = hardwares.get(); checkState(!hardwaresToSearch.isEmpty(), "no hardware profiles present!"); Image image = null; if (imageId != null) { image = loadImageWithId(images); if (currentLocationWiderThan(image.getLocation())) this.location = image.getLocation(); } Hardware hardware = null; if (hardwareId != null) { hardware = findHardwareWithId(hardwaresToSearch); if (currentLocationWiderThan(hardware.getLocation())) this.location = hardware.getLocation(); } if (location == null) location = defaultLocation.get(); if (image == null) { Iterable<? extends Image> supportedImages = findSupportedImages(images); if (hardware == null) hardware = resolveHardware(hardwaresToSearch, supportedImages); image = resolveImage(hardware, supportedImages); } else { if (hardware == null) hardware = resolveHardware(hardwaresToSearch, ImmutableSet.of(image)); } logger.debug("<< matched image(%s) hardware(%s) location(%s)", image.getId(), hardware.getId(), location.getId()); return new TemplateImpl(image, hardware, location, options); } @Inject protected  TemplateBuilderImpl(@Memoized Supplier<Set<? extends Location>> locations,
         @Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> hardwares,
         Supplier<Location> defaultLocation, @Named("DEFAULT") Provider<TemplateOptions> optionsProvider,
         @Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider); }
TemplateBuilderImpl implements TemplateBuilder { @Override public Template build() { if (nothingChangedExceptOptions()) { TemplateBuilder defaultTemplate = defaultTemplateProvider.get(); if (options != null) defaultTemplate.options(options); return defaultTemplate.build(); } if (options == null) options = optionsProvider.get(); logger.debug(">> searching params(%s)", this); Set<? extends Image> images = getImages(); checkState(!images.isEmpty(), "no images present!"); Set<? extends Hardware> hardwaresToSearch = hardwares.get(); checkState(!hardwaresToSearch.isEmpty(), "no hardware profiles present!"); Image image = null; if (imageId != null) { image = loadImageWithId(images); if (currentLocationWiderThan(image.getLocation())) this.location = image.getLocation(); } Hardware hardware = null; if (hardwareId != null) { hardware = findHardwareWithId(hardwaresToSearch); if (currentLocationWiderThan(hardware.getLocation())) this.location = hardware.getLocation(); } if (location == null) location = defaultLocation.get(); if (image == null) { Iterable<? extends Image> supportedImages = findSupportedImages(images); if (hardware == null) hardware = resolveHardware(hardwaresToSearch, supportedImages); image = resolveImage(hardware, supportedImages); } else { if (hardware == null) hardware = resolveHardware(hardwaresToSearch, ImmutableSet.of(image)); } logger.debug("<< matched image(%s) hardware(%s) location(%s)", image.getId(), hardware.getId(), location.getId()); return new TemplateImpl(image, hardware, location, options); } @Inject protected  TemplateBuilderImpl(@Memoized Supplier<Set<? extends Location>> locations,
         @Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> hardwares,
         Supplier<Location> defaultLocation, @Named("DEFAULT") Provider<TemplateOptions> optionsProvider,
         @Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider); @Override TemplateBuilder fromTemplate(Template template); @Override TemplateBuilder fromHardware(Hardware hardware); @Override TemplateBuilder fromImage(Image image); @Override TemplateBuilder smallest(); @Override TemplateBuilder biggest(); @Override TemplateBuilder fastest(); @Override TemplateBuilder locationId(final String locationId); @Override TemplateBuilder osFamily(OsFamily os); @Override Template build(); @Override TemplateBuilder imageId(String imageId); @Override TemplateBuilder imageNameMatches(String nameRegex); @Override TemplateBuilder imageDescriptionMatches(String descriptionRegex); @Override TemplateBuilder imageMatches(Predicate<Image> condition); @Override TemplateBuilderImpl imageChooser(Function<Iterable<? extends Image>, Image> imageChooser); @Override TemplateBuilder imageVersionMatches(String imageVersionRegex); @Override TemplateBuilder osVersionMatches(String osVersionRegex); @Override TemplateBuilder osArchMatches(String osArchitectureRegex); @Override TemplateBuilder minCores(double minCores); @Override TemplateBuilder minRam(int megabytes); @Override TemplateBuilder minDisk(double gigabytes); @Override TemplateBuilder osNameMatches(String osNameRegex); @Override TemplateBuilder osDescriptionMatches(String osDescriptionRegex); @Override TemplateBuilder hardwareId(String hardwareId); @Override TemplateBuilder hypervisorMatches(String hypervisor); @Override TemplateBuilder options(TemplateOptions options); @Override TemplateBuilder any(); @Override String toString(); @Override TemplateBuilder os64Bit(boolean is64Bit); @Override TemplateBuilder from(TemplateBuilderSpec spec); @Override TemplateBuilder from(String spec); @Override TemplateBuilder forceCacheReload(); }
TemplateBuilderImpl implements TemplateBuilder { @Override public Template build() { if (nothingChangedExceptOptions()) { TemplateBuilder defaultTemplate = defaultTemplateProvider.get(); if (options != null) defaultTemplate.options(options); return defaultTemplate.build(); } if (options == null) options = optionsProvider.get(); logger.debug(">> searching params(%s)", this); Set<? extends Image> images = getImages(); checkState(!images.isEmpty(), "no images present!"); Set<? extends Hardware> hardwaresToSearch = hardwares.get(); checkState(!hardwaresToSearch.isEmpty(), "no hardware profiles present!"); Image image = null; if (imageId != null) { image = loadImageWithId(images); if (currentLocationWiderThan(image.getLocation())) this.location = image.getLocation(); } Hardware hardware = null; if (hardwareId != null) { hardware = findHardwareWithId(hardwaresToSearch); if (currentLocationWiderThan(hardware.getLocation())) this.location = hardware.getLocation(); } if (location == null) location = defaultLocation.get(); if (image == null) { Iterable<? extends Image> supportedImages = findSupportedImages(images); if (hardware == null) hardware = resolveHardware(hardwaresToSearch, supportedImages); image = resolveImage(hardware, supportedImages); } else { if (hardware == null) hardware = resolveHardware(hardwaresToSearch, ImmutableSet.of(image)); } logger.debug("<< matched image(%s) hardware(%s) location(%s)", image.getId(), hardware.getId(), location.getId()); return new TemplateImpl(image, hardware, location, options); } @Inject protected  TemplateBuilderImpl(@Memoized Supplier<Set<? extends Location>> locations,
         @Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> hardwares,
         Supplier<Location> defaultLocation, @Named("DEFAULT") Provider<TemplateOptions> optionsProvider,
         @Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider); @Override TemplateBuilder fromTemplate(Template template); @Override TemplateBuilder fromHardware(Hardware hardware); @Override TemplateBuilder fromImage(Image image); @Override TemplateBuilder smallest(); @Override TemplateBuilder biggest(); @Override TemplateBuilder fastest(); @Override TemplateBuilder locationId(final String locationId); @Override TemplateBuilder osFamily(OsFamily os); @Override Template build(); @Override TemplateBuilder imageId(String imageId); @Override TemplateBuilder imageNameMatches(String nameRegex); @Override TemplateBuilder imageDescriptionMatches(String descriptionRegex); @Override TemplateBuilder imageMatches(Predicate<Image> condition); @Override TemplateBuilderImpl imageChooser(Function<Iterable<? extends Image>, Image> imageChooser); @Override TemplateBuilder imageVersionMatches(String imageVersionRegex); @Override TemplateBuilder osVersionMatches(String osVersionRegex); @Override TemplateBuilder osArchMatches(String osArchitectureRegex); @Override TemplateBuilder minCores(double minCores); @Override TemplateBuilder minRam(int megabytes); @Override TemplateBuilder minDisk(double gigabytes); @Override TemplateBuilder osNameMatches(String osNameRegex); @Override TemplateBuilder osDescriptionMatches(String osDescriptionRegex); @Override TemplateBuilder hardwareId(String hardwareId); @Override TemplateBuilder hypervisorMatches(String hypervisor); @Override TemplateBuilder options(TemplateOptions options); @Override TemplateBuilder any(); @Override String toString(); @Override TemplateBuilder os64Bit(boolean is64Bit); @Override TemplateBuilder from(TemplateBuilderSpec spec); @Override TemplateBuilder from(String spec); @Override TemplateBuilder forceCacheReload();  }