@SuppressWarnings("unchecked") @Test public void testApply() throws ExecutionException { EC2ImageParser parser = createMock(EC2ImageParser.class); EC2Api caller = createMock(EC2Api.class); AMIApi client = createMock(AMIApi.class); org.jclouds.ec2.domain.Image ec2Image = createMock(org.jclouds.ec2.domain.Image.class); Image image = createNiceMock(Image.class); Set<? extends org.jclouds.ec2.domain.Image> images = ImmutableSet.<org.jclouds.ec2.domain.Image> of(ec2Image); expect(caller.getAMIApi()).andReturn((Optional) Optional.of(client)).atLeastOnce(); expect(client.describeImagesInRegion("region", imageIds("ami"))).andReturn(Set.class.cast(images)); expect(parser.apply(ec2Image)).andReturn(image); replay(caller); replay(image); replay(parser); replay(client); RegionAndIdToImage function = new RegionAndIdToImage(parser, caller); assertEquals(function.load(new RegionAndName("region", "ami")), image); verify(caller); verify(image); verify(image); verify(client); }
@Override public Image load(RegionAndName key) throws ExecutionException { try { org.jclouds.ec2.domain.Image image = Iterables.getOnlyElement(sync.getAMIApi().get() .describeImagesInRegion(key.getRegion(), imageIds(key.getName()))); return parser.apply(image); } catch (Exception e) { throw new ExecutionException(message(key, e), e); } }
RegionAndIdToImage extends CacheLoader<RegionAndName, Image> { @Override public Image load(RegionAndName key) throws ExecutionException { try { org.jclouds.ec2.domain.Image image = Iterables.getOnlyElement(sync.getAMIApi().get() .describeImagesInRegion(key.getRegion(), imageIds(key.getName()))); return parser.apply(image); } catch (Exception e) { throw new ExecutionException(message(key, e), e); } } }
RegionAndIdToImage extends CacheLoader<RegionAndName, Image> { @Override public Image load(RegionAndName key) throws ExecutionException { try { org.jclouds.ec2.domain.Image image = Iterables.getOnlyElement(sync.getAMIApi().get() .describeImagesInRegion(key.getRegion(), imageIds(key.getName()))); return parser.apply(image); } catch (Exception e) { throw new ExecutionException(message(key, e), e); } } @Inject  RegionAndIdToImage(EC2ImageParser parser, EC2Api sync); }
RegionAndIdToImage extends CacheLoader<RegionAndName, Image> { @Override public Image load(RegionAndName key) throws ExecutionException { try { org.jclouds.ec2.domain.Image image = Iterables.getOnlyElement(sync.getAMIApi().get() .describeImagesInRegion(key.getRegion(), imageIds(key.getName()))); return parser.apply(image); } catch (Exception e) { throw new ExecutionException(message(key, e), e); } } @Inject  RegionAndIdToImage(EC2ImageParser parser, EC2Api sync); @Override Image load(RegionAndName key); static String message(RegionAndName key, Exception e); }
RegionAndIdToImage extends CacheLoader<RegionAndName, Image> { @Override public Image load(RegionAndName key) throws ExecutionException { try { org.jclouds.ec2.domain.Image image = Iterables.getOnlyElement(sync.getAMIApi().get() .describeImagesInRegion(key.getRegion(), imageIds(key.getName()))); return parser.apply(image); } catch (Exception e) { throw new ExecutionException(message(key, e), e); } } @Inject  RegionAndIdToImage(EC2ImageParser parser, EC2Api sync); @Override Image load(RegionAndName key); static String message(RegionAndName key, Exception e);  }