You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by na...@apache.org on 2015/11/02 12:43:18 UTC
[2/5] jclouds-labs git commit: Remove DigitalOcean v1
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/test/java/org/jclouds/digitalocean/features/DropletApiMockTest.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/features/DropletApiMockTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/features/DropletApiMockTest.java
deleted file mode 100644
index f5feff5..0000000
--- a/digitalocean/src/test/java/org/jclouds/digitalocean/features/DropletApiMockTest.java
+++ /dev/null
@@ -1,770 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean.features;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertNull;
-import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.fail;
-
-import java.util.List;
-
-import org.jclouds.digitalocean.DigitalOceanApi;
-import org.jclouds.digitalocean.domain.Droplet;
-import org.jclouds.digitalocean.domain.Droplet.Status;
-import org.jclouds.digitalocean.domain.DropletCreation;
-import org.jclouds.digitalocean.domain.options.CreateDropletOptions;
-import org.jclouds.digitalocean.internal.BaseDigitalOceanMockTest;
-import org.jclouds.rest.ResourceNotFoundException;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableMultimap;
-import com.squareup.okhttp.mockwebserver.MockResponse;
-import com.squareup.okhttp.mockwebserver.MockWebServer;
-
-/**
- * Mock tests for the {@link DropletApi} class.
- */
-@Test(groups = "unit", testName = "DropletApiMockTest")
-public class DropletApiMockTest extends BaseDigitalOceanMockTest {
-
- 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();
- }
- }
-
- 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();
- }
- }
-
- 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();
- }
- }
-
- public void testCreateDropletUsingSlugs() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setBody(payloadFromResource("/droplet-creation.json")));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- DropletCreation droplet = dropletApi.create("test", "img-1", "size-1", "region-1");
-
- assertRequestHasParameters(server.takeRequest(), "/droplets/new", ImmutableMultimap.of("name", "test",
- "image_slug", "img-1", "size_slug", "size-1", "region_slug", "region-1"));
-
- assertNotNull(droplet);
- assertEquals(droplet.getName(), "test");
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testCreateDropletUsingSlugsWithOptions() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setBody(payloadFromResource("/droplet-creation.json")));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- CreateDropletOptions options = CreateDropletOptions.builder().addSshKeyId(5).addSshKeyId(4)
- .privateNetworking(true).backupsEnabled(false).build();
- DropletCreation droplet = dropletApi.create("test", "img-1", "size-1", "region-1", options);
-
- ImmutableMultimap.Builder<String, String> params = ImmutableMultimap.builder();
- params.put("name", "test");
- params.put("image_slug", "img-1");
- params.put("size_slug", "size-1");
- params.put("region_slug", "region-1");
- params.put("ssh_key_ids", "5,4");
- params.put("private_networking", "true");
- params.put("backups_enabled", "false");
-
- assertRequestHasParameters(server.takeRequest(), "/droplets/new", params.build());
-
- assertNotNull(droplet);
- assertEquals(droplet.getName(), "test");
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testCreateDroplet() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setBody(payloadFromResource("/droplet-creation.json")));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- DropletCreation droplet = dropletApi.create("test", 419, 32, 1);
-
- assertRequestHasParameters(server.takeRequest(), "/droplets/new",
- ImmutableMultimap.of("name", "test", "image_id", "419", "size_id", "32", "region_id", "1"));
-
- assertNotNull(droplet);
- assertEquals(droplet.getName(), "test");
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testCreateDropletWithOptions() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setBody(payloadFromResource("/droplet-creation.json")));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- CreateDropletOptions options = CreateDropletOptions.builder().addSshKeyId(5).addSshKeyId(4)
- .privateNetworking(true).backupsEnabled(false).build();
- DropletCreation droplet = dropletApi.create("test", 419, 32, 1, options);
-
- ImmutableMultimap.Builder<String, String> params = ImmutableMultimap.builder();
- params.put("name", "test");
- params.put("image_id", "419");
- params.put("size_id", "32");
- params.put("region_id", "1");
- params.put("ssh_key_ids", "5,4");
- params.put("private_networking", "true");
- params.put("backups_enabled", "false");
-
- assertRequestHasParameters(server.takeRequest(), "/droplets/new", params.build());
-
- assertNotNull(droplet);
- assertEquals(droplet.getName(), "test");
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testRebootDroplet() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setBody(payloadFromResource("/eventid.json")));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- int event = dropletApi.reboot(1);
-
- assertRequestHasCommonFields(server.takeRequest(), "/droplets/1/reboot");
- assertTrue(event > 0);
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testRebootNonexistentDroplet() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setResponseCode(404));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- try {
- dropletApi.reboot(1);
- fail("Reboot droplet should fail on 404");
- } catch (ResourceNotFoundException ex) {
- // Expected exception
- }
-
- assertRequestHasCommonFields(server.takeRequest(), "/droplets/1/reboot");
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testPowerCycleDroplet() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setBody(payloadFromResource("/eventid.json")));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- int event = dropletApi.powerCycle(1);
-
- assertRequestHasCommonFields(server.takeRequest(), "/droplets/1/power_cycle");
- assertTrue(event > 0);
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testPowerCycleNonexistentDroplet() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setResponseCode(404));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- try {
- dropletApi.powerCycle(1);
- fail("Power cycle droplet should fail on 404");
- } catch (ResourceNotFoundException ex) {
- // Expected exception
- }
-
- assertRequestHasCommonFields(server.takeRequest(), "/droplets/1/power_cycle");
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testShutdownDroplet() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setBody(payloadFromResource("/eventid.json")));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- int event = dropletApi.shutdown(1);
-
- assertRequestHasCommonFields(server.takeRequest(), "/droplets/1/shutdown");
- assertTrue(event > 0);
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testShutdownNonexistentDroplet() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setResponseCode(404));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- try {
- dropletApi.shutdown(1);
- fail("Shutdown droplet should fail on 404");
- } catch (ResourceNotFoundException ex) {
- // Expected exception
- }
-
- assertRequestHasCommonFields(server.takeRequest(), "/droplets/1/shutdown");
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testPowerOffDroplet() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setBody(payloadFromResource("/eventid.json")));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- int event = dropletApi.powerOff(1);
-
- assertRequestHasCommonFields(server.takeRequest(), "/droplets/1/power_off");
- assertTrue(event > 0);
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testPowerOffNonexistentDroplet() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setResponseCode(404));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- try {
- dropletApi.powerOff(1);
- fail("Power off droplet should fail on 404");
- } catch (ResourceNotFoundException ex) {
- // Expected exception
- }
-
- assertRequestHasCommonFields(server.takeRequest(), "/droplets/1/power_off");
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testPowerOnDroplet() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setBody(payloadFromResource("/eventid.json")));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- int event = dropletApi.powerOn(1);
-
- assertRequestHasCommonFields(server.takeRequest(), "/droplets/1/power_on");
- assertTrue(event > 0);
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testPowerOnNonexistentDroplet() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setResponseCode(404));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- try {
- dropletApi.powerOn(1);
- fail("Power on droplet should fail on 404");
- } catch (ResourceNotFoundException ex) {
- // Expected exception
- }
-
- assertRequestHasCommonFields(server.takeRequest(), "/droplets/1/power_on");
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testResetPasswordForDroplet() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setBody(payloadFromResource("/eventid.json")));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- int event = dropletApi.resetPassword(1);
-
- assertRequestHasCommonFields(server.takeRequest(), "/droplets/1/password_reset");
- assertTrue(event > 0);
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testResetPasswordForNonexistentDroplet() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setResponseCode(404));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- try {
- dropletApi.resetPassword(1);
- fail("Reset password for droplet should fail on 404");
- } catch (ResourceNotFoundException ex) {
- // Expected exception
- }
-
- assertRequestHasCommonFields(server.takeRequest(), "/droplets/1/password_reset");
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testResizeDroplet() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setBody(payloadFromResource("/eventid.json")));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- int event = dropletApi.resize(1, 3);
-
- assertRequestHasParameters(server.takeRequest(), "/droplets/1/resize", ImmutableMultimap.of("size_id", "3"));
- assertTrue(event > 0);
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testResizeNonexistentDroplet() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setResponseCode(404));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- try {
- dropletApi.resize(1, 3);
- fail("Resize droplet should fail on 404");
- } catch (ResourceNotFoundException ex) {
- // Expected exception
- }
-
- assertRequestHasParameters(server.takeRequest(), "/droplets/1/resize", ImmutableMultimap.of("size_id", "3"));
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testSnapshotDroplet() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setBody(payloadFromResource("/eventid.json")));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- int event = dropletApi.snapshot(1);
-
- assertRequestHasCommonFields(server.takeRequest(), "/droplets/1/snapshot");
- assertTrue(event > 0);
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testSnapshotNonexistentDroplet() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setResponseCode(404));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- try {
- dropletApi.snapshot(1);
- fail("Snapshot droplet should fail on 404");
- } catch (ResourceNotFoundException ex) {
- // Expected exception
- }
-
- assertRequestHasCommonFields(server.takeRequest(), "/droplets/1/snapshot");
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testSnapshotWithNameDroplet() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setBody(payloadFromResource("/eventid.json")));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- int event = dropletApi.snapshot(1, "foo");
-
- assertRequestHasParameters(server.takeRequest(), "/droplets/1/snapshot", ImmutableMultimap.of("name", "foo"));
- assertTrue(event > 0);
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testSnapshotWithNameNonexistentDroplet() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setResponseCode(404));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- try {
- dropletApi.snapshot(1, "foo");
- fail("Snapshot droplet should fail on 404");
- } catch (ResourceNotFoundException ex) {
- // Expected exception
- }
-
- assertRequestHasParameters(server.takeRequest(), "/droplets/1/snapshot", ImmutableMultimap.of("name", "foo"));
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testRestoreDroplet() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setBody(payloadFromResource("/eventid.json")));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- int event = dropletApi.restore(1, 3);
-
- assertRequestHasParameters(server.takeRequest(), "/droplets/1/restore", ImmutableMultimap.of("image_id", "3"));
- assertTrue(event > 0);
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testRestoreNonexistentDroplet() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setResponseCode(404));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- try {
- dropletApi.restore(1, 3);
- fail("Restore droplet should fail on 404");
- } catch (ResourceNotFoundException ex) {
- // Expected exception
- }
-
- assertRequestHasParameters(server.takeRequest(), "/droplets/1/restore", ImmutableMultimap.of("image_id", "3"));
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testRebuildDroplet() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setBody(payloadFromResource("/eventid.json")));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- int event = dropletApi.rebuild(1, 3);
-
- assertRequestHasParameters(server.takeRequest(), "/droplets/1/rebuild", ImmutableMultimap.of("image_id", "3"));
- assertTrue(event > 0);
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testRebuildNonexistentDroplet() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setResponseCode(404));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- try {
- dropletApi.rebuild(1, 3);
- fail("Rebuild droplet should fail on 404");
- } catch (ResourceNotFoundException ex) {
- // Expected exception
- }
-
- assertRequestHasParameters(server.takeRequest(), "/droplets/1/rebuild", ImmutableMultimap.of("image_id", "3"));
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testRenameDroplet() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setBody(payloadFromResource("/eventid.json")));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- int event = dropletApi.rename(1, "foo");
-
- assertRequestHasParameters(server.takeRequest(), "/droplets/1/rename", ImmutableMultimap.of("name", "foo"));
- assertTrue(event > 0);
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testRenameNonexistentDroplet() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setResponseCode(404));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- try {
- dropletApi.rename(1, "foo");
- fail("Rename droplet should fail on 404");
- } catch (ResourceNotFoundException ex) {
- // Expected exception
- }
-
- assertRequestHasParameters(server.takeRequest(), "/droplets/1/rename", ImmutableMultimap.of("name", "foo"));
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testDestroyDroplet() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setBody(payloadFromResource("/eventid.json")));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- int event = dropletApi.destroy(1);
-
- assertRequestHasCommonFields(server.takeRequest(), "/droplets/1/destroy");
- assertTrue(event > 0);
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testDestroyNonexistentDroplet() 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);
- fail("Destroy droplet should fail on 404");
- } catch (ResourceNotFoundException ex) {
- // Expected exception
- }
-
- assertRequestHasCommonFields(server.takeRequest(), "/droplets/1/destroy");
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testDestroyWithOptionsDroplet() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setBody(payloadFromResource("/eventid.json")));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- DropletApi dropletApi = api.getDropletApi();
-
- try {
- int event = dropletApi.destroy(1, true);
-
- assertRequestHasParameters(server.takeRequest(), "/droplets/1/destroy",
- ImmutableMultimap.of("scrub_data", "true"));
- assertTrue(event > 0);
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- 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();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/test/java/org/jclouds/digitalocean/features/EventApiLiveTest.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/features/EventApiLiveTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/features/EventApiLiveTest.java
deleted file mode 100644
index 21785d3..0000000
--- a/digitalocean/src/test/java/org/jclouds/digitalocean/features/EventApiLiveTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean.features;
-
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertTrue;
-
-import org.jclouds.digitalocean.domain.DropletCreation;
-import org.jclouds.digitalocean.domain.Event;
-import org.jclouds.digitalocean.internal.BaseDigitalOceanLiveTest;
-import org.testng.annotations.Test;
-
-/**
- * Live tests for the {@link EventApi} class.
- */
-@Test(groups = "live", testName = "EventApiLiveTest")
-public class EventApiLiveTest extends BaseDigitalOceanLiveTest {
-
- @Override
- protected void initialize() {
- super.initialize();
- initializeImageSizeAndRegion();
- }
-
- public void testGetEvent() {
- DropletCreation droplet = null;
-
- try {
- droplet = api.getDropletApi().create("eventtest", defaultImage.getId(), defaultSize.getId(),
- defaultRegion.getId());
- Event event = api.getEventApi().get(droplet.getEventId());
- assertNotNull(event, "Droplet creation event should not be null");
- assertTrue(event.getId() > 0, "Event id should be > 0");
- } finally {
- if (droplet != null) {
- waitForEvent(droplet.getEventId());
- api.getDropletApi().destroy(droplet.getId(), true);
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/test/java/org/jclouds/digitalocean/features/EventApiMockTest.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/features/EventApiMockTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/features/EventApiMockTest.java
deleted file mode 100644
index 648030d..0000000
--- a/digitalocean/src/test/java/org/jclouds/digitalocean/features/EventApiMockTest.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean.features;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertNull;
-
-import org.jclouds.digitalocean.DigitalOceanApi;
-import org.jclouds.digitalocean.domain.Event;
-import org.jclouds.digitalocean.domain.Event.Status;
-import org.jclouds.digitalocean.internal.BaseDigitalOceanMockTest;
-import org.testng.annotations.Test;
-
-import com.squareup.okhttp.mockwebserver.MockResponse;
-import com.squareup.okhttp.mockwebserver.MockWebServer;
-
-/**
- * Mock tests for the {@link EventApi} class.
- */
-@Test(groups = "unit", testName = "EventApiMockTest")
-public class EventApiMockTest extends BaseDigitalOceanMockTest {
-
- public void testGetEvent() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setBody(payloadFromResource("/event.json")));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- EventApi eventApi = api.getEventApi();
-
- try {
- Event event = eventApi.get(7499);
-
- assertRequestHasCommonFields(server.takeRequest(), "/events/7499");
- assertNotNull(event);
- assertEquals(event.getStatus(), Status.DONE);
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testGetPendingEvent() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setBody(payloadFromResource("/event-pending.json")));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- EventApi eventApi = api.getEventApi();
-
- try {
- Event event = eventApi.get(7499);
-
- assertRequestHasCommonFields(server.takeRequest(), "/events/7499");
- assertNotNull(event);
- assertEquals(event.getStatus(), Status.PENDING);
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testGetUnexistingEvent() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setResponseCode(404));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- EventApi eventApi = api.getEventApi();
-
- try {
- Event event = eventApi.get(7499);
-
- assertRequestHasCommonFields(server.takeRequest(), "/events/7499");
- assertNull(event);
- } finally {
- api.close();
- server.shutdown();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/test/java/org/jclouds/digitalocean/features/ImageApiLiveTest.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/features/ImageApiLiveTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/features/ImageApiLiveTest.java
deleted file mode 100644
index 4027a89..0000000
--- a/digitalocean/src/test/java/org/jclouds/digitalocean/features/ImageApiLiveTest.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean.features;
-
-import static com.google.common.collect.Iterables.find;
-import static com.google.common.collect.Iterables.tryFind;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertNull;
-import static org.testng.Assert.assertTrue;
-
-import org.jclouds.digitalocean.domain.DropletCreation;
-import org.jclouds.digitalocean.domain.Image;
-import org.jclouds.digitalocean.domain.Region;
-import org.jclouds.digitalocean.internal.BaseDigitalOceanLiveTest;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Predicate;
-
-/**
- * Live tests for the {@link ImageApi} class.
- */
-@Test(groups = "live", testName = "ImageApiLiveTest")
-public class ImageApiLiveTest extends BaseDigitalOceanLiveTest {
-
- private Image snapshot;
- private Image snapshotUsingSlug;
- private DropletCreation droplet;
- private DropletCreation dropletUsingSlug;
-
- @Override
- protected void initialize() {
- super.initialize();
- initializeImageSizeAndRegion();
- }
-
- @AfterClass
- public void cleanup() {
- try {
- if (droplet != null) {
- api.getDropletApi().destroy(droplet.getId(), true);
- }
- if (dropletUsingSlug != null) {
- api.getDropletApi().destroy(dropletUsingSlug.getId(), true);
- }
- } finally {
- if (snapshot != null) {
- api.getImageApi().delete(snapshot.getId());
- assertFalse(tryFind(api.getImageApi().list(), byName(snapshot.getName())).isPresent(),
- "Snapshot should not exist after delete");
- }
- if (snapshotUsingSlug != null) {
- api.getImageApi().delete(snapshotUsingSlug.getId());
- assertFalse(tryFind(api.getImageApi().list(), byName(snapshotUsingSlug.getName())).isPresent(),
- "Snapshot should not exist after delete");
- }
- }
- }
-
- public void testGetImage() {
- assertNotNull(api.getImageApi().get(defaultImage.getId()), "The image should not be null");
- }
-
- public void testGetImageBySlug() {
- assertNotNull(api.getImageApi().get(defaultImage.getSlug()), "The image should not be null");
- }
-
- public void testGetImageNotFound() {
- assertNull(api.getImageApi().get(-1));
- }
-
- public void testTransferImage() {
- droplet = api.getDropletApi().create("imagetransferdroplet", defaultImage.getId(), defaultSize.getId(),
- defaultRegion.getId());
-
- assertTrue(droplet.getId() > 0, "Created droplet id should be > 0");
- assertTrue(droplet.getEventId() > 0, "Droplet creation event id should be > 0");
-
- waitForEvent(droplet.getEventId());
- int powerOffEvent = api.getDropletApi().powerOff(droplet.getId());
- waitForEvent(powerOffEvent);
-
- int snapshotEvent = api.getDropletApi().snapshot(droplet.getId(), "imagetransfersnapshot");
- waitForEvent(snapshotEvent);
-
- snapshot = find(api.getImageApi().list(), byName("imagetransfersnapshot"));
-
- Region newRegion = regions.get(1);
- int transferEvent = api.getImageApi().transfer(snapshot.getId(), newRegion.getId());
- assertTrue(transferEvent > 0, "Transfer event id should be > 0");
- waitForEvent(transferEvent);
- }
-
- public void testTransferImageUsingSlug() {
- dropletUsingSlug = api.getDropletApi().create("imagetransferdropletusingslug", defaultImage.getSlug(),
- defaultSize.getSlug(), defaultRegion.getSlug());
-
- assertTrue(dropletUsingSlug.getId() > 0, "Created droplet id should be > 0");
- assertTrue(dropletUsingSlug.getEventId() > 0, "Droplet creation event id should be > 0");
-
- waitForEvent(dropletUsingSlug.getEventId());
- int powerOffEvent = api.getDropletApi().powerOff(dropletUsingSlug.getId());
- waitForEvent(powerOffEvent);
-
- int snapshotEvent = api.getDropletApi().snapshot(dropletUsingSlug.getId(), "imagetransfersnapshotusingslug");
- waitForEvent(snapshotEvent);
-
- snapshotUsingSlug = find(api.getImageApi().list(), byName("imagetransfersnapshotusingslug"));
-
- Region newRegion = regions.get(1);
- int transferEvent = api.getImageApi().transfer(snapshotUsingSlug.getId(), newRegion.getId());
- assertTrue(transferEvent > 0, "Transfer event id should be > 0");
- waitForEvent(transferEvent);
- }
-
- private static Predicate<Image> byName(final String name) {
- return new Predicate<Image>() {
- @Override
- public boolean apply(Image input) {
- return input.getName().equals(name);
- }
- };
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/test/java/org/jclouds/digitalocean/features/ImageApiMockTest.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/features/ImageApiMockTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/features/ImageApiMockTest.java
deleted file mode 100644
index 2129408..0000000
--- a/digitalocean/src/test/java/org/jclouds/digitalocean/features/ImageApiMockTest.java
+++ /dev/null
@@ -1,262 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean.features;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertNull;
-import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.fail;
-
-import java.util.List;
-
-import org.jclouds.digitalocean.DigitalOceanApi;
-import org.jclouds.digitalocean.domain.Distribution;
-import org.jclouds.digitalocean.domain.Image;
-import org.jclouds.digitalocean.internal.BaseDigitalOceanMockTest;
-import org.jclouds.rest.ResourceNotFoundException;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableMultimap;
-import com.squareup.okhttp.mockwebserver.MockResponse;
-import com.squareup.okhttp.mockwebserver.MockWebServer;
-
-/**
- * Mock tests for the {@link ImageApi} class.
- */
-@Test(groups = "unit", testName = "ImageApiMockTest")
-public class ImageApiMockTest extends BaseDigitalOceanMockTest {
-
- public void testListImages() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setBody(payloadFromResource("/images.json")));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- ImageApi imageApi = api.getImageApi();
-
- try {
- List<Image> images = imageApi.list();
-
- assertRequestHasCommonFields(server.takeRequest(), "/images");
- assertEquals(images.size(), 3);
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testGetImage() throws Exception {
- MockWebServer server = mockWebServer();
- String[] imageJsons = new String[] { "/image1.json", "/image2.json", "/image3.json", "/image2.json" };
-
- for (String imageJson : imageJsons) {
- server.enqueue(new MockResponse().setBody(payloadFromResource(imageJson)));
- }
-
- DigitalOceanApi api = api(server.getUrl("/"));
- ImageApi imageApi = api.getImageApi();
-
- try {
- Image image = imageApi.get(1);
-
- assertRequestHasCommonFields(server.takeRequest(), "/images/1");
- assertNotNull(image);
- assertEquals(image.getId(), 1);
- assertEquals(image.getOs().getDistribution(), Distribution.ARCHLINUX);
- assertEquals(image.getOs().getVersion(), "2013.05");
- assertEquals(image.getOs().getArch(), "x32");
- assertEquals(image.getName(), "Arch Linux 2013.05 x32");
- assertTrue(image.isPublicImage());
- assertEquals(image.getSlug(), "arch-linux-x32");
-
- image = imageApi.get(2);
-
- assertRequestHasCommonFields(server.takeRequest(), "/images/2");
- assertNotNull(image);
- assertEquals(image.getId(), 2);
- assertEquals(image.getOs().getDistribution(), Distribution.FEDORA);
- assertEquals(image.getOs().getVersion(), "17");
- assertEquals(image.getOs().getArch(), "x64");
- assertEquals(image.getName(), "Fedora 17 x64 Desktop");
- assertTrue(image.isPublicImage());
- assertEquals(image.getSlug(), "fedora-17-x64");
-
- image = imageApi.get(3);
-
- assertRequestHasCommonFields(server.takeRequest(), "/images/3");
- assertNotNull(image);
- assertNull(image.getSlug());
- assertEquals(image.getId(), 3);
- assertEquals(image.getOs().getDistribution(), Distribution.UBUNTU);
- assertEquals(image.getOs().getVersion(), "13.04");
- assertEquals(image.getOs().getArch(), "");
- assertEquals(image.getName(), "Dokku on Ubuntu 13.04 0.2.0rc3");
- assertTrue(image.isPublicImage());
- assertNull(image.getSlug());
-
- image = imageApi.get("fedora-17-x64");
-
- assertRequestHasCommonFields(server.takeRequest(), "/images/fedora-17-x64");
- assertNotNull(image);
- assertEquals(image.getId(), 2);
- assertEquals(image.getOs().getDistribution(), Distribution.FEDORA);
- assertEquals(image.getOs().getVersion(), "17");
- assertEquals(image.getOs().getArch(), "x64");
- assertEquals(image.getName(), "Fedora 17 x64 Desktop");
- assertTrue(image.isPublicImage());
- assertEquals(image.getSlug(), "fedora-17-x64");
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testGetUnexistingImage() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setResponseCode(404));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- ImageApi imageApi = api.getImageApi();
-
- try {
- Image image = imageApi.get(15);
-
- assertRequestHasCommonFields(server.takeRequest(), "/images/15");
- assertNull(image);
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testDeleteImage() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse());
-
- DigitalOceanApi api = api(server.getUrl("/"));
- ImageApi imageApi = api.getImageApi();
-
- try {
- imageApi.delete(15);
-
- assertRequestHasCommonFields(server.takeRequest(), "/images/15/destroy");
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testDeleteImageUsingSlug() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse());
-
- DigitalOceanApi api = api(server.getUrl("/"));
- ImageApi imageApi = api.getImageApi();
-
- try {
- imageApi.delete("img-15");
-
- assertRequestHasCommonFields(server.takeRequest(), "/images/img-15/destroy");
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testDeleteUnexistingImage() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setResponseCode(404));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- ImageApi imageApi = api.getImageApi();
-
- try {
- try {
- imageApi.delete(15);
- fail("Delete image should fail on 404");
- } catch (ResourceNotFoundException ex) {
- // Expected exception
- }
-
- assertRequestHasCommonFields(server.takeRequest(), "/images/15/destroy");
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testTransferUnexistingImage() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setResponseCode(404));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- ImageApi imageApi = api.getImageApi();
-
- try {
- try {
- imageApi.transfer(47, 23);
- fail("Transfer image should fail on 404");
- } catch (ResourceNotFoundException ex) {
- // Expected exception
- }
-
- assertRequestHasParameters(server.takeRequest(), "/images/47/transfer",
- ImmutableMultimap.of("region_id", "23"));
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testTransferImage() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setBody(payloadFromResource("/eventid.json")));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- ImageApi imageApi = api.getImageApi();
-
- try {
- int eventId = imageApi.transfer(47, 23);
-
- assertRequestHasParameters(server.takeRequest(), "/images/47/transfer",
- ImmutableMultimap.of("region_id", "23"));
- assertEquals(eventId, 7499);
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testTransferImageUsingSlug() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setBody(payloadFromResource("/eventid.json")));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- ImageApi imageApi = api.getImageApi();
-
- try {
- int eventId = imageApi.transfer("img-47", 23);
-
- assertRequestHasParameters(server.takeRequest(), "/images/img-47/transfer",
- ImmutableMultimap.of("region_id", "23"));
- assertEquals(eventId, 7499);
- } finally {
- api.close();
- server.shutdown();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/test/java/org/jclouds/digitalocean/features/KeyPairApiLiveTest.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/features/KeyPairApiLiveTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/features/KeyPairApiLiveTest.java
deleted file mode 100644
index a22ce46..0000000
--- a/digitalocean/src/test/java/org/jclouds/digitalocean/features/KeyPairApiLiveTest.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean.features;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertNull;
-
-import java.io.IOException;
-import java.util.List;
-
-import org.jclouds.digitalocean.domain.SshKey;
-import org.jclouds.digitalocean.internal.BaseDigitalOceanLiveTest;
-import org.jclouds.util.Strings2;
-import org.testng.annotations.Test;
-
-/**
- * Live tests for the {@link ImageApi} class.
- */
-@Test(groups = "live", testName = "ImageApiLiveTest")
-public class KeyPairApiLiveTest extends BaseDigitalOceanLiveTest {
-
- private SshKey key;
-
- public void testCreateKey() throws IOException {
- String publicKey = Strings2.toStringAndClose(getClass().getResourceAsStream("/ssh-rsa.txt"));
- key = api.getKeyPairApi().create("foo", publicKey);
-
- assertNotNull(key);
- assertNotNull(key.getId());
- assertEquals(key.getName(), "foo");
- assertNotNull(key.getPublicKey());
- assertEquals(key.getPublicKey().getAlgorithm(), "RSA");
- }
-
- @Test(dependsOnMethods = "testCreateKey")
- public void testListKeys() {
- List<SshKey> keys = api.getKeyPairApi().list();
- assertFalse(keys.isEmpty(), "SSH key list should not be empty");
- }
-
- @Test(dependsOnMethods = "testCreateKey")
- public void testGetKey() {
- assertNotNull(api.getKeyPairApi().get(key.getId()), "The SSH key should not be null");
- }
-
- @Test(dependsOnMethods = "testCreateKey")
- public void testEditKey() throws IOException {
- String newKey = Strings2.toStringAndClose(getClass().getResourceAsStream("/ssh-dsa.txt"));
- SshKey updated = api.getKeyPairApi().edit(key.getId(), newKey);
-
- assertNotNull(updated.getPublicKey(), "The SSH key should have a public key");
- assertEquals(updated.getPublicKey().getAlgorithm(), "DSA");
- }
-
- @Test(dependsOnMethods = { "testListKeys", "testGetKey", "testEditKey" })
- public void testDeleteKey() throws IOException {
- api.getKeyPairApi().delete(key.getId());
- assertNull(api.getKeyPairApi().get(key.getId()), "The SSH key should not exist after deleting it");
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/test/java/org/jclouds/digitalocean/features/KeyPairApiMockTest.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/features/KeyPairApiMockTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/features/KeyPairApiMockTest.java
deleted file mode 100644
index 1b13765..0000000
--- a/digitalocean/src/test/java/org/jclouds/digitalocean/features/KeyPairApiMockTest.java
+++ /dev/null
@@ -1,213 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean.features;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertNull;
-import static org.testng.Assert.fail;
-
-import java.util.List;
-
-import org.jclouds.digitalocean.DigitalOceanApi;
-import org.jclouds.digitalocean.domain.SshKey;
-import org.jclouds.digitalocean.internal.BaseDigitalOceanMockTest;
-import org.jclouds.rest.ResourceNotFoundException;
-import org.jclouds.util.Strings2;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableMultimap;
-import com.squareup.okhttp.mockwebserver.MockResponse;
-import com.squareup.okhttp.mockwebserver.MockWebServer;
-
-/**
- * Mock tests for the {@link KeyPairApi} class.
- */
-@Test(groups = "unit", testName = "KeyPairApiMockTest")
-public class KeyPairApiMockTest extends BaseDigitalOceanMockTest {
-
- public void testListKeys() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setBody(payloadFromResource("/keys.json")));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- KeyPairApi keyPairApi = api.getKeyPairApi();
-
- try {
- List<SshKey> keys = keyPairApi.list();
-
- assertRequestHasCommonFields(server.takeRequest(), "/ssh_keys");
- assertEquals(keys.size(), 1);
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testGetKey() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setBody(payloadFromResource("/key.json")));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- KeyPairApi keyPairApi = api.getKeyPairApi();
-
- try {
- SshKey key = keyPairApi.get(47);
-
- assertRequestHasCommonFields(server.takeRequest(), "/ssh_keys/47");
- assertEquals(key.getId(), 47);
- assertEquals(key.getName(), "my_key");
- assertNotNull(key.getPublicKey());
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- public void testGetUnexistingKey() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setResponseCode(404));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- KeyPairApi keyPairApi = api.getKeyPairApi();
-
- try {
- SshKey key = keyPairApi.get(47);
-
- assertRequestHasCommonFields(server.takeRequest(), "/ssh_keys/47");
- assertNull(key);
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- @Test
- public void testCreateKey() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setBody(payloadFromResource("/key.json")));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- KeyPairApi keyPairApi = api.getKeyPairApi();
-
- try {
- String publicKey = Strings2.toStringAndClose(getClass().getResourceAsStream("/ssh-rsa.txt"));
- SshKey key = keyPairApi.create("my_key", publicKey);
-
- assertRequestHasParameters(server.takeRequest(), "/ssh_keys/new",
- ImmutableMultimap.of("name", "my_key", "ssh_pub_key", publicKey));
-
- assertEquals(key.getId(), 47);
- assertEquals(key.getName(), "my_key");
- assertNotNull(key.getPublicKey());
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- @Test
- public void testEditKey() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setBody(payloadFromResource("/key.json")));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- KeyPairApi keyPairApi = api.getKeyPairApi();
-
- try {
- String publicKey = Strings2.toStringAndClose(getClass().getResourceAsStream("/ssh-rsa.txt"));
- SshKey key = keyPairApi.edit(47, publicKey);
-
- assertRequestHasParameters(server.takeRequest(), "/ssh_keys/47/edit",
- ImmutableMultimap.of("ssh_pub_key", publicKey));
-
- assertEquals(key.getId(), 47);
- assertEquals(key.getName(), "my_key");
- assertNotNull(key.getPublicKey());
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- @Test
- public void testEditUnexistingKey() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setResponseCode(404));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- KeyPairApi keyPairApi = api.getKeyPairApi();
-
- try {
- String publicKey = Strings2.toStringAndClose(getClass().getResourceAsStream("/ssh-rsa.txt"));
-
- try {
- keyPairApi.edit(47, publicKey);
- fail("Edit key should fail on 404");
- } catch (ResourceNotFoundException ex) {
- // Expected exception
- }
-
- assertRequestHasParameters(server.takeRequest(), "/ssh_keys/47/edit",
- ImmutableMultimap.of("ssh_pub_key", publicKey));
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- @Test
- public void testDeleteKey() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse());
-
- DigitalOceanApi api = api(server.getUrl("/"));
- KeyPairApi keyPairApi = api.getKeyPairApi();
-
- try {
- keyPairApi.delete(47);
-
- assertRequestHasCommonFields(server.takeRequest(), "/ssh_keys/47/destroy");
- } finally {
- api.close();
- server.shutdown();
- }
- }
-
- @Test
- public void testDeleteUnexistingKey() throws Exception {
- MockWebServer server = mockWebServer();
- server.enqueue(new MockResponse().setResponseCode(404));
-
- DigitalOceanApi api = api(server.getUrl("/"));
- KeyPairApi keyPairApi = api.getKeyPairApi();
-
- try {
- try {
- keyPairApi.delete(47);
- fail("Delete key should fail on 404");
- } catch (ResourceNotFoundException ex) {
- // Expected exception
- }
-
- assertRequestHasCommonFields(server.takeRequest(), "/ssh_keys/47/destroy");
- } finally {
- api.close();
- server.shutdown();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/test/java/org/jclouds/digitalocean/features/RegionApiLiveTest.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/features/RegionApiLiveTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/features/RegionApiLiveTest.java
deleted file mode 100644
index ab32689..0000000
--- a/digitalocean/src/test/java/org/jclouds/digitalocean/features/RegionApiLiveTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean.features;
-
-import static org.testng.Assert.assertFalse;
-
-import java.util.List;
-
-import org.jclouds.digitalocean.domain.Region;
-import org.jclouds.digitalocean.internal.BaseDigitalOceanLiveTest;
-import org.testng.annotations.Test;
-
-/**
- * Live tests for the {@link RegionApi} class.
- */
-@Test(groups = "live", testName = "RegionApiLiveTest")
-public class RegionApiLiveTest extends BaseDigitalOceanLiveTest {
-
- private RegionApi regionApi;
-
- @Override
- protected void initialize() {
- super.initialize();
- regionApi = api.getRegionApi();
- }
-
- public void testListRegions() {
- List<Region> regions = regionApi.list();
-
- assertFalse(regions.isEmpty(), "Region list should not be empty");
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/test/java/org/jclouds/digitalocean/features/RegionApiMockTest.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/features/RegionApiMockTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/features/RegionApiMockTest.java
deleted file mode 100644
index 376fbef..0000000
--- a/digitalocean/src/test/java/org/jclouds/digitalocean/features/RegionApiMockTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean.features;
-
-import static org.testng.Assert.assertEquals;
-
-import java.util.List;
-
-import org.jclouds.digitalocean.DigitalOceanApi;
-import org.jclouds.digitalocean.domain.Region;
-import org.jclouds.digitalocean.internal.BaseDigitalOceanMockTest;
-import org.testng.annotations.Test;
-
-import com.squareup.okhttp.mockwebserver.MockResponse;
-import com.squareup.okhttp.mockwebserver.MockWebServer;
-
-/**
- * Mock tests for the {@link RegionApi} class.
- */
-@Test(groups = "unit", testName = "RegionApiMockTest")
-public class RegionApiMockTest extends BaseDigitalOceanMockTest {
-
- 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();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/test/java/org/jclouds/digitalocean/features/SizeApiLiveTest.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/features/SizeApiLiveTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/features/SizeApiLiveTest.java
deleted file mode 100644
index a7ba6d0..0000000
--- a/digitalocean/src/test/java/org/jclouds/digitalocean/features/SizeApiLiveTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean.features;
-
-import static org.testng.Assert.assertFalse;
-
-import java.util.List;
-
-import org.jclouds.digitalocean.domain.Size;
-import org.jclouds.digitalocean.internal.BaseDigitalOceanLiveTest;
-import org.testng.annotations.Test;
-
-/**
- * Live tests for the {@link SizesApi} class.
- */
-@Test(groups = "live", testName = "SizeApiLiveTest")
-public class SizeApiLiveTest extends BaseDigitalOceanLiveTest {
-
- private SizesApi sizesApi;
-
- @Override
- protected void initialize() {
- super.initialize();
- sizesApi = api.getSizesApi();
- }
-
- public void testListSizes() {
- List<Size> sizes = sizesApi.list();
-
- assertFalse(sizes.isEmpty(), "Size list should not be empty");
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/test/java/org/jclouds/digitalocean/features/SizesApiMockTest.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/features/SizesApiMockTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/features/SizesApiMockTest.java
deleted file mode 100644
index 4e054b6..0000000
--- a/digitalocean/src/test/java/org/jclouds/digitalocean/features/SizesApiMockTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean.features;
-
-import static org.testng.Assert.assertEquals;
-
-import java.util.List;
-
-import org.jclouds.digitalocean.DigitalOceanApi;
-import org.jclouds.digitalocean.domain.Size;
-import org.jclouds.digitalocean.internal.BaseDigitalOceanMockTest;
-import org.testng.annotations.Test;
-
-import com.squareup.okhttp.mockwebserver.MockResponse;
-import com.squareup.okhttp.mockwebserver.MockWebServer;
-
-/**
- * Mock tests for the {@link SizesApi} class.
- */
-@Test(groups = "unit", testName = "SizesApiMockTest")
-public class SizesApiMockTest extends BaseDigitalOceanMockTest {
-
- 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();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/test/java/org/jclouds/digitalocean/http/ResponseStatusFromPayloadHttpCommandExecutorServiceTest.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/http/ResponseStatusFromPayloadHttpCommandExecutorServiceTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/http/ResponseStatusFromPayloadHttpCommandExecutorServiceTest.java
deleted file mode 100644
index 6017c61..0000000
--- a/digitalocean/src/test/java/org/jclouds/digitalocean/http/ResponseStatusFromPayloadHttpCommandExecutorServiceTest.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean.http;
-
-import static org.jclouds.Constants.PROPERTY_MAX_RETRIES;
-import static org.jclouds.digitalocean.http.ResponseStatusFromPayloadHttpCommandExecutorService.ACCESS_DENIED;
-import static org.jclouds.digitalocean.http.ResponseStatusFromPayloadHttpCommandExecutorService.NOT_FOUND;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.fail;
-
-import java.util.Properties;
-
-import org.jclouds.digitalocean.DigitalOceanApi;
-import org.jclouds.digitalocean.features.ImageApi;
-import org.jclouds.digitalocean.internal.BaseDigitalOceanMockTest;
-import org.jclouds.http.HttpResponseException;
-import org.jclouds.rest.AuthorizationException;
-import org.jclouds.rest.ResourceNotFoundException;
-import org.testng.annotations.Test;
-
-import com.squareup.okhttp.mockwebserver.MockResponse;
-import com.squareup.okhttp.mockwebserver.MockWebServer;
-
-/**
- * Mock tests for the {@link ResponseStatusFromPayloadHttpCommandExecutorService} class.
- */
-@Test(groups = "unit", testName = "ResponseStatusFromPayloadHttpCommandExecutorServiceTest")
-public class ResponseStatusFromPayloadHttpCommandExecutorServiceTest extends BaseDigitalOceanMockTest {
-
- @Override
- protected Properties setupProperties() {
- Properties properties = super.setupProperties();
- properties.setProperty(PROPERTY_MAX_RETRIES, "1");
- return properties;
- }
-
- 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();
- }
- }
-
- 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();
- }
- }
-
- public void testInternalServerError() throws Exception {
- 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();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/test/java/org/jclouds/digitalocean/http/filters/AuthenticationFilterTest.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/http/filters/AuthenticationFilterTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/http/filters/AuthenticationFilterTest.java
deleted file mode 100644
index 5ce5078..0000000
--- a/digitalocean/src/test/java/org/jclouds/digitalocean/http/filters/AuthenticationFilterTest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean.http.filters;
-
-import static com.google.common.collect.Iterables.getOnlyElement;
-import static org.jclouds.digitalocean.http.filters.AuthenticationFilter.CREDENTIAL_PARAM;
-import static org.jclouds.digitalocean.http.filters.AuthenticationFilter.IDENTITY_PARAM;
-import static org.jclouds.http.utils.Queries.queryParser;
-import static org.testng.Assert.assertEquals;
-
-import org.jclouds.domain.Credentials;
-import org.jclouds.domain.LoginCredentials;
-import org.jclouds.http.HttpRequest;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Suppliers;
-import com.google.common.collect.Multimap;
-
-/**
- * Unit tests for the {@link AuthenticationFilter} class.
- */
-@Test(groups = "unit", testName = "AuthenticationFilterTest")
-public class AuthenticationFilterTest {
-
- @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "credential supplier cannot be null")
- public void testFilterWithoutCredentials() {
- new AuthenticationFilter(null);
- }
-
- public void testFilterWithCredentials() {
- HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://localhost/foo").build();
- Credentials credentials = LoginCredentials.builder().identity("foo").credential("bar").build();
- AuthenticationFilter filter = new AuthenticationFilter(Suppliers.ofInstance(credentials));
-
- HttpRequest filtered = filter.filter(request);
-
- String queryLine = filtered.getRequestLine().trim()
- .substring(filtered.getRequestLine().indexOf('?') + 1, filtered.getRequestLine().lastIndexOf(' '));
- Multimap<String, String> params = queryParser().apply(queryLine);
-
- assertEquals(getOnlyElement(params.get(IDENTITY_PARAM)), "foo");
- assertEquals(getOnlyElement(params.get(CREDENTIAL_PARAM)), "bar");
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/test/java/org/jclouds/digitalocean/internal/BaseDigitalOceanLiveTest.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/internal/BaseDigitalOceanLiveTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/internal/BaseDigitalOceanLiveTest.java
deleted file mode 100644
index 366a95b..0000000
--- a/digitalocean/src/test/java/org/jclouds/digitalocean/internal/BaseDigitalOceanLiveTest.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean.internal;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.testng.Assert.assertTrue;
-
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-
-import org.jclouds.apis.BaseApiLiveTest;
-import org.jclouds.digitalocean.DigitalOceanApi;
-import org.jclouds.digitalocean.domain.Event;
-import org.jclouds.digitalocean.domain.Image;
-import org.jclouds.digitalocean.domain.Region;
-import org.jclouds.digitalocean.domain.Size;
-import org.jclouds.util.Predicates2;
-
-import com.google.common.base.Predicate;
-import com.google.common.collect.ComparisonChain;
-import com.google.common.collect.Ordering;
-
-/**
- * Base class for the DigitalOcean live tests.
- */
-public class BaseDigitalOceanLiveTest extends BaseApiLiveTest<DigitalOceanApi> {
-
- protected static final int DEFAULT_TIMEOUT_SECONDS = 600;
- protected static final int DEFAULT_POLL_SECONDS = 1;
- protected static final String DEFAULT_IMAGE = "ubuntu-14-04-x64";
-
- protected List<Size> sizes;
- protected List<Region> regions;
-
- protected Size defaultSize;
- protected Image defaultImage;
- protected Region defaultRegion;
-
- public BaseDigitalOceanLiveTest() {
- provider = "digitalocean";
- }
-
- protected void initializeImageSizeAndRegion() {
- sizes = sortedSizes().sortedCopy(api.getSizesApi().list());
- regions = api.getRegionApi().list();
-
- assertTrue(sizes.size() > 1, "There must be at least two sizes");
- assertTrue(regions.size() > 1, "There must be at least two regions");
-
- defaultImage = api.getImageApi().get(DEFAULT_IMAGE);
- checkNotNull(defaultImage, "Image %s not found", DEFAULT_IMAGE);
-
- defaultSize = sizes.get(0);
- defaultRegion = regions.get(0);
- }
-
- protected void waitForEvent(Integer eventId) {
- Predicates2.retry(new Predicate<Integer>() {
- @Override
- public boolean apply(Integer input) {
- Event event = api.getEventApi().get(input);
- return Event.Status.DONE == event.getStatus();
- }
- }, DEFAULT_TIMEOUT_SECONDS, DEFAULT_POLL_SECONDS, TimeUnit.SECONDS).apply(eventId);
- }
-
- protected static Ordering<Size> sortedSizes() {
- return new Ordering<Size>() {
- @Override
- public int compare(Size left, Size right) {
- return ComparisonChain.start().compare(left.getCpu(), right.getCpu())
- .compare(left.getMemory(), right.getMemory()).compare(left.getDisk(), right.getDisk()).result();
- }
- };
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/test/java/org/jclouds/digitalocean/internal/BaseDigitalOceanMockTest.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/internal/BaseDigitalOceanMockTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/internal/BaseDigitalOceanMockTest.java
deleted file mode 100644
index 02022ae..0000000
--- a/digitalocean/src/test/java/org/jclouds/digitalocean/internal/BaseDigitalOceanMockTest.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jclouds.digitalocean.internal;
-
-import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor;
-import static org.jclouds.digitalocean.http.filters.AuthenticationFilter.CREDENTIAL_PARAM;
-import static org.jclouds.digitalocean.http.filters.AuthenticationFilter.IDENTITY_PARAM;
-import static org.jclouds.http.utils.Queries.encodeQueryLine;
-import static org.jclouds.util.Strings2.toStringAndClose;
-import static org.testng.Assert.assertEquals;
-
-import java.io.IOException;
-import java.net.URL;
-import java.util.Properties;
-import java.util.Set;
-
-import javax.ws.rs.core.MediaType;
-
-import org.jclouds.ContextBuilder;
-import org.jclouds.concurrent.config.ExecutorServiceModule;
-import org.jclouds.digitalocean.DigitalOceanApi;
-
-import com.google.common.base.Charsets;
-import com.google.common.base.Throwables;
-import com.google.common.collect.ImmutableMultimap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Multimap;
-import com.google.common.net.HttpHeaders;
-import com.google.inject.Module;
-import com.squareup.okhttp.mockwebserver.MockWebServer;
-import com.squareup.okhttp.mockwebserver.RecordedRequest;
-
-/**
- * Base class for all DigitalOcean mock tests.
- */
-public class BaseDigitalOceanMockTest {
- private final Set<Module> modules = ImmutableSet.<Module> of(new ExecutorServiceModule(sameThreadExecutor(),
- sameThreadExecutor()));
-
- protected String provider;
-
- public BaseDigitalOceanMockTest() {
- provider = "digitalocean";
- }
-
- public DigitalOceanApi api(URL url) {
- return ContextBuilder.newBuilder(provider)
- .credentials("clientid", "apikey")
- .endpoint(url.toString())
- .modules(modules)
- .overrides(setupProperties())
- .buildApi(DigitalOceanApi.class);
- }
-
- protected Properties setupProperties() {
- return new Properties();
- }
-
- public static MockWebServer mockWebServer() throws IOException {
- MockWebServer server = new MockWebServer();
- server.play();
- return server;
- }
-
- public byte[] payloadFromResource(String resource) {
- try {
- return toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8);
- } catch (IOException e) {
- throw Throwables.propagate(e);
- }
- }
-
- protected static void assertRequestHasCommonFields(final RecordedRequest request, final String path)
- throws InterruptedException {
- assertRequestHasParameters(request, path, ImmutableMultimap.<String, String> of());
- }
-
- protected static void assertRequestHasParameters(final RecordedRequest request, final String path,
- Multimap<String, String> parameters) throws InterruptedException {
- Multimap<String, String> allparams = ImmutableMultimap.<String, String> builder()
- .putAll(parameters)
- .put(IDENTITY_PARAM, "clientid")
- .put(CREDENTIAL_PARAM, "apikey")
- .build();
-
- assertRequestHasAcceptHeader(request);
- assertEquals(request.getRequestLine(), "GET " + path + "?" + encodeQueryLine(allparams) + " HTTP/1.1");
- }
-
- protected static void assertRequestHasAcceptHeader(final RecordedRequest request) throws InterruptedException {
- assertEquals(request.getHeader(HttpHeaders.ACCEPT), MediaType.APPLICATION_JSON);
- }
-}