@SuppressWarnings("unchecked") @Test public void testApplySetsTagFromNameAndCredentialsFromName() { Map<ServerState, Status> serverStateToNodeStatus = createMock(Map.class); org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class); Option dc = Option.createWithIdNameAndDescription(1L, "US-West-1", "US West 1 Datacenter"); Option ram = Option.createWithIdNameAndDescription(1L, "512MB", "Server with 512MB RAM"); Set<? extends org.jclouds.compute.domain.Image> images = ImmutableSet.of(jcImage); Server server = createMock(Server.class); expect(server.getId()).andReturn(1000L).atLeastOnce(); expect(server.getName()).andReturn("group-ff").atLeastOnce(); expect(server.getState()).andReturn(ServerState.ON).atLeastOnce(); expect(serverStateToNodeStatus.get(ServerState.ON)).andReturn(Status.RUNNING); Location location = new LocationBuilder().scope(LocationScope.ZONE).id("1").description("US-West-1").build(); Set< ? extends Location> locations = ImmutableSet.< Location> of( location); expect(server.getIp()).andReturn(Ip.builder().ip("127.0.0.1").build()); ServerImage image = createMock(ServerImage.class); expect(server.getImage()).andReturn(image).atLeastOnce(); expect(server.getRam()).andReturn(ram).atLeastOnce(); expect(server.getDatacenter()).andReturn(dc).atLeastOnce(); expect(image.getId()).andReturn(2000L).atLeastOnce(); expect(jcImage.getProviderId()).andReturn("2000").atLeastOnce(); expect(jcImage.getLocation()).andReturn(location).atLeastOnce(); expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce(); replay(serverStateToNodeStatus); replay(server); replay(image); replay(jcImage); ServerToNodeMetadata parser = new ServerToNodeMetadata(serverStateToNodeStatus, Suppliers .<Set<? extends Image>> ofInstance(images), Suppliers .<Set<? extends Hardware>> ofInstance(GoGridHardwareSupplier.H_ALL), Suppliers .<Set<? extends Location>> ofInstance(locations), namingConvention); NodeMetadata metadata = parser.apply(server); assertEquals(metadata.getLocation(), location); assertEquals(metadata.getImageId(), "2000"); assertEquals(metadata.getGroup(), "group"); verify(serverStateToNodeStatus); verify(image); verify(server); verify(jcImage); }
@Override public NodeMetadata apply(Server from) { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(from.getId() + ""); builder.name(from.getName()); Location location = Iterables.find(locations.get(), LocationPredicates.idEquals(from.getDatacenter().getId() + "")); builder.location(location); builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName())); builder.hardware(parseHardware(from)); builder.imageId(from.getImage().getId() + ""); Image image = parseImage(from); if (image != null) builder.operatingSystem(image.getOperatingSystem()); builder.status(serverStateToNodeStatus.get(from.getState())); builder.publicAddresses(ImmutableSet.of(from.getIp().getIp())); return builder.build(); }
ServerToNodeMetadata implements Function<Server, NodeMetadata> { @Override public NodeMetadata apply(Server from) { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(from.getId() + ""); builder.name(from.getName()); Location location = Iterables.find(locations.get(), LocationPredicates.idEquals(from.getDatacenter().getId() + "")); builder.location(location); builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName())); builder.hardware(parseHardware(from)); builder.imageId(from.getImage().getId() + ""); Image image = parseImage(from); if (image != null) builder.operatingSystem(image.getOperatingSystem()); builder.status(serverStateToNodeStatus.get(from.getState())); builder.publicAddresses(ImmutableSet.of(from.getIp().getIp())); return builder.build(); } }
ServerToNodeMetadata implements Function<Server, NodeMetadata> { @Override public NodeMetadata apply(Server from) { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(from.getId() + ""); builder.name(from.getName()); Location location = Iterables.find(locations.get(), LocationPredicates.idEquals(from.getDatacenter().getId() + "")); builder.location(location); builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName())); builder.hardware(parseHardware(from)); builder.imageId(from.getImage().getId() + ""); Image image = parseImage(from); if (image != null) builder.operatingSystem(image.getOperatingSystem()); builder.status(serverStateToNodeStatus.get(from.getState())); builder.publicAddresses(ImmutableSet.of(from.getIp().getIp())); return builder.build(); } @Inject  ServerToNodeMetadata(Map<ServerState, Status> serverStateToNodeStatus,
         @Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> hardwares,
         @Memoized Supplier<Set<? extends Location>> locations,
         GroupNamingConvention.Factory namingConvention); }
ServerToNodeMetadata implements Function<Server, NodeMetadata> { @Override public NodeMetadata apply(Server from) { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(from.getId() + ""); builder.name(from.getName()); Location location = Iterables.find(locations.get(), LocationPredicates.idEquals(from.getDatacenter().getId() + "")); builder.location(location); builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName())); builder.hardware(parseHardware(from)); builder.imageId(from.getImage().getId() + ""); Image image = parseImage(from); if (image != null) builder.operatingSystem(image.getOperatingSystem()); builder.status(serverStateToNodeStatus.get(from.getState())); builder.publicAddresses(ImmutableSet.of(from.getIp().getIp())); return builder.build(); } @Inject  ServerToNodeMetadata(Map<ServerState, Status> serverStateToNodeStatus,
         @Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> hardwares,
         @Memoized Supplier<Set<? extends Location>> locations,
         GroupNamingConvention.Factory namingConvention); @Override NodeMetadata apply(Server from); }
ServerToNodeMetadata implements Function<Server, NodeMetadata> { @Override public NodeMetadata apply(Server from) { NodeMetadataBuilder builder = new NodeMetadataBuilder(); builder.ids(from.getId() + ""); builder.name(from.getName()); Location location = Iterables.find(locations.get(), LocationPredicates.idEquals(from.getDatacenter().getId() + "")); builder.location(location); builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName())); builder.hardware(parseHardware(from)); builder.imageId(from.getImage().getId() + ""); Image image = parseImage(from); if (image != null) builder.operatingSystem(image.getOperatingSystem()); builder.status(serverStateToNodeStatus.get(from.getState())); builder.publicAddresses(ImmutableSet.of(from.getIp().getIp())); return builder.build(); } @Inject  ServerToNodeMetadata(Map<ServerState, Status> serverStateToNodeStatus,
         @Memoized Supplier<Set<? extends Image>> images, @Memoized Supplier<Set<? extends Hardware>> hardwares,
         @Memoized Supplier<Set<? extends Location>> locations,
         GroupNamingConvention.Factory namingConvention); @Override NodeMetadata apply(Server from);  }