VAppToNodeMetadata implements Function<VApp, NodeMetadata> { public NodeMetadata apply(VApp from) { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(from.getHref().toASCIIString()); builder.uri(from.getHref()); builder.name(from.getName()); if (!isNullOrEmpty(from.getDescription()) && from.getDescription().indexOf('=') != -1 && from.getDescription().indexOf('\n') != -1) { try { addMetadataAndParseTagsFromCommaDelimitedValue(builder, Splitter.on('\n').withKeyValueSeparator("=").split(from.getDescription())); } catch (IllegalArgumentException iae) { } } builder.hostname(from.getName()); builder.location(findLocationForResourceInVDC.apply(from.getVDC())); builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName())); builder.operatingSystem(toComputeOs(from, null)); builder.hardware(hardwareForVApp.apply(from)); builder.status(vAppStatusToNodeStatus.get(from.getStatus())); Set<String> addresses = getIpsFromVApp(from); builder.publicAddresses(filter(addresses, not(IsPrivateIPAddress.INSTANCE))); builder.privateAddresses(filter(addresses, IsPrivateIPAddress.INSTANCE)); Credentials fromApi = getCredentialsFrom(from); if (fromApi != null && !credentialStore.containsKey("node#" + from.getHref().toASCIIString())) credentialStore.put("node#" + from.getHref().toASCIIString(), fromApi); return builder.build(); } @Inject protected  VAppToNodeMetadata(Map<Status, NodeMetadata.Status> vAppStatusToNodeStatus, Map<String, Credentials> credentialStore,
                                FindLocationForResource findLocationForResourceInVDC, Function<VApp, Hardware> hardwareForVApp,
                                GroupNamingConvention.Factory namingConvention); NodeMetadata apply(VApp from);  }
@Test(expectedExceptions = NoSuchElementException.class) public void testGracefulWhenVDCIsNotLocation() { Location location = new LocationBuilder().id("https: .scope(LocationScope.PROVIDER).build(); Injector injector = createInjectorWithLocation(location); InputStream is = getClass().getResourceAsStream("/vapp-pool.xml"); Factory factory = injector.getInstance(ParseSax.Factory.class); VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is); VAppToNodeMetadata converter = injector.getInstance(VAppToNodeMetadata.class); NodeMetadata node = converter.apply(result); assertNotNull(node); assertEquals(node.getLocation(), location); }