Package org.jclouds.digitalocean

Examples of org.jclouds.digitalocean.DigitalOceanApi


   public void testDestroyWithOptionsNonexistentDroplet() throws Exception {
      MockWebServer server = mockWebServer();
      server.enqueue(new MockResponse().setResponseCode(404));

      DigitalOceanApi api = api(server.getUrl("/"));
      DropletApi dropletApi = api.getDropletApi();

      try {
         try {
            dropletApi.destroy(1, true);
            fail("Destroy droplet should fail on 404");
         } catch (ResourceNotFoundException ex) {
            // Expected exception
         }

         assertRequestHasParameters(server.takeRequest(), "/droplets/1/destroy",
               ImmutableMultimap.of("scrub_data", "true"));
      } finally {
         api.close();
         server.shutdown();
      }
   }
View Full Code Here


   public void testAccessDenied() throws Exception {
      MockWebServer server = mockWebServer();
      server.enqueue(new MockResponse().setBody(payloadFromResource("/access-denied.json")));

      DigitalOceanApi api = api(server.getUrl("/"));
      ImageApi imageApi = api.getImageApi();

      try {
         imageApi.list();
         fail("Request should have failed");
      } catch (Exception ex) {
         assertTrue(ex instanceof AuthorizationException, "Exception should be an AuthorizationException");
         assertEquals(ex.getMessage(), ACCESS_DENIED);
      } finally {
         api.close();
         server.shutdown();
      }
   }
View Full Code Here

   public void testNotFound() throws Exception {
      MockWebServer server = mockWebServer();
      server.enqueue(new MockResponse().setBody(payloadFromResource("/not-found.json")));

      DigitalOceanApi api = api(server.getUrl("/"));
      ImageApi imageApi = api.getImageApi();

      try {
         imageApi.list();
         fail("Request should have failed");
      } catch (Exception ex) {
         assertTrue(ex instanceof ResourceNotFoundException, "Exception should be a ResourceNotFoundException");
         assertEquals(ex.getMessage(), NOT_FOUND);
      } finally {
         api.close();
         server.shutdown();
      }
   }
View Full Code Here

      MockWebServer server = mockWebServer();
      server.enqueue(new MockResponse().setBody(payloadFromResource("/error.json")));
      // Response to be sent for the retried request
      server.enqueue(new MockResponse().setBody(payloadFromResource("/error.json")));

      DigitalOceanApi api = api(server.getUrl("/"));
      ImageApi imageApi = api.getImageApi();

      try {
         imageApi.list();
         fail("Request should have failed after retrying");
      } catch (Exception ex) {
         assertTrue(ex instanceof HttpResponseException, "Exception should be an HttpResponseException");
         HttpResponseException exception = HttpResponseException.class.cast(ex);
         assertEquals(exception.getResponse().getStatusCode(), 500);
         assertEquals(exception.getMessage(), "No Image Found");
      } finally {
         api.close();
         server.shutdown();
      }
   }
View Full Code Here

   public void testListSizes() throws Exception {
      MockWebServer server = mockWebServer();
      server.enqueue(new MockResponse().setBody(payloadFromResource("/sizes.json")));

      DigitalOceanApi api = api(server.getUrl("/"));
      SizesApi sizesApi = api.getSizesApi();

      try {
         List<Size> sizes = sizesApi.list();

         assertRequestHasCommonFields(server.takeRequest(), "/sizes");
         assertEquals(sizes.size(), 4);
      } finally {
         api.close();
         server.shutdown();
      }
   }
View Full Code Here

   public void testListRegions() throws Exception {
      MockWebServer server = mockWebServer();
      server.enqueue(new MockResponse().setBody(payloadFromResource("/regions.json")));

      DigitalOceanApi api = api(server.getUrl("/"));
      RegionApi regionApi = api.getRegionApi();

      try {
         List<Region> regions = regionApi.list();

         assertRequestHasCommonFields(server.takeRequest(), "/regions");
         assertEquals(regions.size(), 4);
      } finally {
         api.close();
         server.shutdown();
      }
   }
View Full Code Here

   public void testListSizes() throws Exception {
      MockWebServer server = mockWebServer();
      server.enqueue(new MockResponse().setBody(payloadFromResource("/sizes.json")));

      DigitalOceanApi api = api(server.getUrl("/"));
      SizesApi sizesApi = api.getSizesApi();

      try {
         List<Size> sizes = sizesApi.list();

         assertRequestHasCommonFields(server.takeRequest(), "/sizes");
         assertEquals(sizes.size(), 4);
      } finally {
         api.close();
         server.shutdown();
      }
   }
View Full Code Here

   public void testListDroplets() throws Exception {
      MockWebServer server = mockWebServer();
      server.enqueue(new MockResponse().setBody(payloadFromResource("/droplets.json")));

      DigitalOceanApi api = api(server.getUrl("/"));
      DropletApi dropletApi = api.getDropletApi();

      try {
         List<Droplet> sizes = dropletApi.list();

         assertRequestHasCommonFields(server.takeRequest(), "/droplets");
         assertEquals(sizes.size(), 1);
      } finally {
         api.close();
         server.shutdown();
      }
   }
View Full Code Here

   public void testGetDroplet() throws Exception {
      MockWebServer server = mockWebServer();
      server.enqueue(new MockResponse().setBody(payloadFromResource("/droplet.json")));

      DigitalOceanApi api = api(server.getUrl("/"));
      DropletApi dropletApi = api.getDropletApi();

      try {
         Droplet droplet = dropletApi.get(100823);

         assertRequestHasCommonFields(server.takeRequest(), "/droplets/100823");
         assertNotNull(droplet);
         assertNotNull(droplet.getBackups());
         assertNotNull(droplet.getSnapshots());
         assertEquals(droplet.getName(), "test222");
         assertEquals(droplet.getStatus(), Status.ACTIVE);
      } finally {
         api.close();
         server.shutdown();
      }
   }
View Full Code Here

   public void testGetNonexistentDroplet() throws Exception {
      MockWebServer server = mockWebServer();
      server.enqueue(new MockResponse().setResponseCode(404));

      DigitalOceanApi api = api(server.getUrl("/"));
      DropletApi dropletApi = api.getDropletApi();

      try {
         Droplet droplet = dropletApi.get(100823);

         assertRequestHasCommonFields(server.takeRequest(), "/droplets/100823");
         assertNull(droplet);
      } finally {
         api.close();
         server.shutdown();
      }
   }
View Full Code Here

TOP

Related Classes of org.jclouds.digitalocean.DigitalOceanApi

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.