NodeFlavors { public Optional<Flavor> getFlavor(String name) { if (configuredFlavors.containsKey(name)) return Optional.of(configuredFlavors.get(name)); NodeResources nodeResources = NodeResources.fromLegacyName(name); return Optional.of(new Flavor(nodeResources)); } @Inject  NodeFlavors(FlavorsConfig config); List<Flavor> getFlavors(); Optional<Flavor> getFlavor(String name); Flavor getFlavorOrThrow(String flavorName); boolean exists(String flavorName);  }
@Test public void testConfigParsing() { FlavorsConfig.Builder builder = new FlavorsConfig.Builder(); List<FlavorsConfig.Flavor.Builder> flavorBuilderList = new ArrayList<>(); { FlavorsConfig.Flavor.Builder flavorBuilder = new FlavorsConfig.Flavor.Builder(); flavorBuilder.name("strawberry").cost(2); flavorBuilderList.add(flavorBuilder); } { FlavorsConfig.Flavor.Builder flavorBuilder = new FlavorsConfig.Flavor.Builder(); flavorBuilder.minCpuCores(10); flavorBuilder.cpuSpeedup(1.3); flavorBuilder.name("banana").cost(3); flavorBuilderList.add(flavorBuilder); } builder.flavor(flavorBuilderList); FlavorsConfig config = new FlavorsConfig(builder); NodeFlavors nodeFlavors = new NodeFlavors(config); Flavor banana = nodeFlavors.getFlavor("banana").get(); assertEquals(3, banana.cost()); assertEquals(13, banana.resources().vcpu(), delta); assertEquals("10 * 1.3", 13, banana.resources().vcpu(), delta); }