Package org.jclouds.ec2.features

Examples of org.jclouds.ec2.features.AMIApi


   @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);
View Full Code Here


   @Test(expectedExceptions = ExecutionException.class)
   public void testApplyNotFoundMakesExecutionException() 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)).andThrow(new ResourceNotFoundException());

      replay(caller);
      replay(image);
      replay(parser);
View Full Code Here

   @Test(expectedExceptions = ExecutionException.class)
   public void testApplyNoSuchElementExceptionMakesExecutionException() 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)).andThrow(new NoSuchElementException());

      replay(caller);
      replay(image);
      replay(parser);
View Full Code Here

@Test(groups = "unit", testName = "NovaEC2ElasticBlockStoreApiTest")
public class NovaEC2AMIApiExpectTest extends BaseNovaEC2RestApiExpectTest {

   public void testDescribeImagesWithNonMachineTypes() {
      AMIApi client = requestsSendResponses(
            describeAvailabilityZonesRequest,
            describeAvailabilityZonesResponse,
            HttpRequest.builder().method("POST")
                  .endpoint("http://localhost:8773/services/Cloud/")
                  .addHeader("Host", "localhost:8773")
                  .payload(payloadFromStringWithContentType("Action=DescribeImages&Signature=Z3q3jSutwlfgvbcINT0Ed3AjrjxM4WMvQloXu/1kd40%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-04-16T15%3A54%3A08.897Z&Version=2009-04-04&AWSAccessKeyId=identity", "application/x-www-form-urlencoded")).build(),
            HttpResponse.builder().statusCode(200).payload(payloadFromResource("/nova_ec2_images_with_ramdisk.xml")).build()
                                               ).getAMIApi().get();

      Set<? extends Image> images = client.describeImagesInRegion("nova");
     
      assertEquals(images.size(), 1);
     
   }
View Full Code Here

   @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);
View Full Code Here

   @Test(expectedExceptions = ExecutionException.class)
   public void testApplyNotFoundMakesExecutionException() 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)).andThrow(new ResourceNotFoundException());

      replay(caller);
      replay(image);
      replay(parser);
View Full Code Here

   @Test(expectedExceptions = ExecutionException.class)
   public void testApplyNoSuchElementExceptionMakesExecutionException() 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)).andThrow(new NoSuchElementException());

      replay(caller);
      replay(image);
      replay(parser);
View Full Code Here

   @Override
   public LoginCredentials apply(final RunningInstance instance) {
      Optional<? extends WindowsApi> windowsOption = ec2Client.getWindowsApiForRegion(instance.getRegion());
      checkState(windowsOption.isPresent(), "windows feature not present in region %s", instance.getRegion());
     
      final WindowsApi windowsApi = windowsOption.get();
     
      LoginCredentials credentials = LoginCredentials.builder().user("Administrator").noPrivateKey().build();
      String privateKey = getPrivateKeyOrNull(instance);
      if (privateKey == null) {
         return credentials;
      }
      // The Administrator password will take some time before it is ready - Amazon says
      // sometimes
      // 15 minutes.
      // So we create a predicate that tests if the password is ready, and wrap it in a retryable
      // predicate.
      final AtomicReference<PasswordData> data = Atomics.newReference();
      Predicate<String> passwordReady = new Predicate<String>() {
         @Override
         public boolean apply(@Nullable String s) {
            if (Strings.isNullOrEmpty(s))
               return false;
            data.set(windowsApi.getPasswordDataForInstance(instance.getId()));
            if (data.get() == null)
               return false;
            return !Strings.isNullOrEmpty(data.get().getPasswordData());
         }
      };
View Full Code Here

                                               .addFormParam("NoReboot", "true").build();

   public void testCreateImageOptions() throws SecurityException, NoSuchMethodException, IOException {
      Invokable<?, ?> method = method(AWSAMIAsyncClient.class, "createImageInRegion", String.class, String.class, String.class,
               CreateImageOptions[].class);
      GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, "name", "instanceId", new CreateImageOptions()
               .withDescription("description").noReboot()));

      request = (GeneratedHttpRequest) request.getFilters().get(0).filter(request);
     
      assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
View Full Code Here

   public void testRegisterImageBackedByEBSOptions() throws SecurityException, NoSuchMethodException, IOException {
      Invokable<?, ?> method = method(AWSAMIAsyncClient.class, "registerUnixImageBackedByEbsInRegion", String.class,
               String.class, String.class, RegisterImageBackedByEbsOptions[].class);
      GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, "imageName", "snapshotId",
               new RegisterImageBackedByEbsOptions().withDescription("description").addBlockDeviceFromSnapshot(
                        "/dev/device", null, "snapshot").addNewBlockDevice("/dev/newdevice", "newblock", 100)));

      request = (GeneratedHttpRequest) request.getFilters().get(0).filter(request);
     
      assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
View Full Code Here

TOP

Related Classes of org.jclouds.ec2.features.AMIApi

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.