diff --git a/apis/docker/pom.xml b/apis/docker/pom.xml index 9aa51279ce..fd54a2aa6f 100644 --- a/apis/docker/pom.xml +++ b/apis/docker/pom.xml @@ -104,7 +104,7 @@ test - com.squareup.okhttp + com.squareup.okhttp3 mockwebserver test @@ -115,6 +115,18 @@ + + com.squareup.okhttp3 + okhttp-tls + test + + + + org.bouncycastle + bcprov-jdk15on + + + org.jboss.shrinkwrap shrinkwrap-depchain diff --git a/apis/docker/src/main/java/org/jclouds/docker/config/DockerOkHttpClientSupplier.java b/apis/docker/src/main/java/org/jclouds/docker/config/DockerOkHttpClientSupplier.java index f9278f0207..a77ffe9b1e 100644 --- a/apis/docker/src/main/java/org/jclouds/docker/config/DockerOkHttpClientSupplier.java +++ b/apis/docker/src/main/java/org/jclouds/docker/config/DockerOkHttpClientSupplier.java @@ -21,6 +21,10 @@ import java.io.File; import javax.inject.Inject; import javax.inject.Singleton; +import okhttp3.ConnectionSpec; +import okhttp3.OkHttpClient; +import okhttp3.TlsVersion; + import org.jclouds.docker.suppliers.DockerSSLContextSupplier; import org.jclouds.domain.Credentials; import org.jclouds.http.okhttp.OkHttpClientSupplier; @@ -28,9 +32,7 @@ import org.jclouds.location.Provider; import com.google.common.base.Supplier; import com.google.common.collect.ImmutableList; -import com.squareup.okhttp.ConnectionSpec; -import com.squareup.okhttp.OkHttpClient; -import com.squareup.okhttp.TlsVersion; + @Singleton public class DockerOkHttpClientSupplier implements OkHttpClientSupplier { @@ -46,18 +48,18 @@ public class DockerOkHttpClientSupplier implements OkHttpClientSupplier { @Override public OkHttpClient get() { - OkHttpClient client = new OkHttpClient(); + OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder(); ConnectionSpec tlsSpec = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS) .tlsVersions(TlsVersion.TLS_1_0, TlsVersion.TLS_1_1, TlsVersion.TLS_1_2) .build(); ConnectionSpec cleartextSpec = new ConnectionSpec.Builder(ConnectionSpec.CLEARTEXT) .build(); - client.setConnectionSpecs(ImmutableList.of(tlsSpec, cleartextSpec)); + clientBuilder.connectionSpecs(ImmutableList.of(tlsSpec, cleartextSpec)); // check if identity and credential are files, to set up sslContext if (new File(creds.get().identity).isFile() && new File(creds.get().credential).isFile()) { - client.setSslSocketFactory(dockerSSLContextSupplier.get().getSocketFactory()); + clientBuilder.sslSocketFactory(dockerSSLContextSupplier.get().getSocketFactory()); } - return client; + return clientBuilder.build(); } } diff --git a/apis/docker/src/test/java/org/jclouds/docker/features/ContainerApiMockTest.java b/apis/docker/src/test/java/org/jclouds/docker/features/ContainerApiMockTest.java index c2eff093f1..8f8687f468 100644 --- a/apis/docker/src/test/java/org/jclouds/docker/features/ContainerApiMockTest.java +++ b/apis/docker/src/test/java/org/jclouds/docker/features/ContainerApiMockTest.java @@ -20,6 +20,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.docker.DockerApi; import org.jclouds.docker.config.DockerParserModule; import org.jclouds.docker.domain.Config; @@ -32,8 +35,7 @@ import org.jclouds.docker.parse.ContainersParseTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; + /** * Mock tests for the {@link org.jclouds.docker.features.ContainerApi} class. @@ -43,7 +45,7 @@ public class ContainerApiMockTest extends BaseDockerMockTest { public void testListContainers() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/containers.json"))); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); + ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi(); try { assertEquals(api.listContainers(), new ContainersParseTest().expected()); assertSent(server, "GET", "/containers/json"); @@ -54,7 +56,7 @@ public class ContainerApiMockTest extends BaseDockerMockTest { public void testListNonexistentContainers() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(404)); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); + ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi(); try { assertEquals(api.listContainers(), ImmutableList.of()); assertSent(server, "GET", "/containers/json"); @@ -66,7 +68,7 @@ public class ContainerApiMockTest extends BaseDockerMockTest { @Test(timeOut = 10000L) public void testListAllContainers() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/containers.json"))); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); + ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi(); try { assertEquals(api.listContainers(ListContainerOptions.Builder.all(true)), new ContainersParseTest().expected()); assertSent(server, "GET", "/containers/json?all=true"); @@ -77,7 +79,7 @@ public class ContainerApiMockTest extends BaseDockerMockTest { public void testGetContainer() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/container.json"))); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString(), new DockerParserModule()).getContainerApi(); + ContainerApi api = api(DockerApi.class, server.url("/").toString(), new DockerParserModule()).getContainerApi(); String containerId = "e475abdf3e139a5e1e158b38b6cb290a1bec856d39d5a951f015dfb8fcba7331"; try { assertEquals(api.inspectContainer(containerId), new ContainerParseTest().expected()); @@ -89,7 +91,7 @@ public class ContainerApiMockTest extends BaseDockerMockTest { public void testCreateContainer() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/container-creation.json"))); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); + ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi(); Config containerConfig = Config.builder() .cmd(ImmutableList.of("date")) .attachStdin(false) @@ -110,7 +112,7 @@ public class ContainerApiMockTest extends BaseDockerMockTest { public void testRemoveContainer() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(204)); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); + ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi(); String containerId = "6d35806c1bd2b25cd92bba2d2c2c5169dc2156f53ab45c2b62d76e2d2fee14a9"; try { @@ -124,7 +126,7 @@ public class ContainerApiMockTest extends BaseDockerMockTest { public void testStartContainer() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(200)); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); + ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi(); try { api.startContainer("1"); assertSent(server, "POST", "/containers/1/start"); @@ -135,7 +137,7 @@ public class ContainerApiMockTest extends BaseDockerMockTest { public void testStopContainer() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(200)); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); + ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi(); try { api.stopContainer("1"); assertSent(server, "POST", "/containers/1/stop"); @@ -147,7 +149,7 @@ public class ContainerApiMockTest extends BaseDockerMockTest { public void testCommitContainer() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(201)); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); + ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi(); try { api.commit(); assertSent(server, "POST", "/commit"); @@ -158,7 +160,7 @@ public class ContainerApiMockTest extends BaseDockerMockTest { public void testPauseContainer() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(204)); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); + ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi(); try { api.pause("1"); assertSent(server, "POST", "/containers/1/pause"); @@ -169,7 +171,7 @@ public class ContainerApiMockTest extends BaseDockerMockTest { public void testUnpauseContainer() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(204)); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); + ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi(); try { api.unpause("1"); assertSent(server, "POST", "/containers/1/unpause"); @@ -180,7 +182,7 @@ public class ContainerApiMockTest extends BaseDockerMockTest { public void testAttachContainer() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(200)); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); + ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi(); try { api.attach("1"); assertSent(server, "POST", "/containers/1/attach"); @@ -191,7 +193,7 @@ public class ContainerApiMockTest extends BaseDockerMockTest { public void testWaitContainer() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(200)); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); + ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi(); try { api.wait("1"); assertSent(server, "POST", "/containers/1/wait"); @@ -202,7 +204,7 @@ public class ContainerApiMockTest extends BaseDockerMockTest { public void testRestartContainer() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(204)); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); + ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi(); try { api.restart("1"); assertSent(server, "POST", "/containers/1/restart"); @@ -213,7 +215,7 @@ public class ContainerApiMockTest extends BaseDockerMockTest { public void testKillContainer() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(204)); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); + ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi(); try { api.kill("1"); assertSent(server, "POST", "/containers/1/kill"); @@ -224,7 +226,7 @@ public class ContainerApiMockTest extends BaseDockerMockTest { public void testCopyFileFromContainer() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(204)); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); + ContainerApi api = api(DockerApi.class, server.url("/").toString()).getContainerApi(); try { api.copy("1", Resource.create("test")); assertSent(server, "POST", "/containers/1/copy"); diff --git a/apis/docker/src/test/java/org/jclouds/docker/features/ImageApiMockTest.java b/apis/docker/src/test/java/org/jclouds/docker/features/ImageApiMockTest.java index 77277ab8c2..803c6145f3 100644 --- a/apis/docker/src/test/java/org/jclouds/docker/features/ImageApiMockTest.java +++ b/apis/docker/src/test/java/org/jclouds/docker/features/ImageApiMockTest.java @@ -22,6 +22,9 @@ import static org.testng.Assert.assertTrue; import java.util.List; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.docker.DockerApi; import org.jclouds.docker.config.DockerParserModule; import org.jclouds.docker.domain.ImageHistory; @@ -33,8 +36,7 @@ import org.jclouds.docker.parse.ImagesParseTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; + /** * Mock tests for the {@link org.jclouds.docker.features.ImageApi} class. @@ -44,7 +46,7 @@ public class ImageApiMockTest extends BaseDockerMockTest { public void testCreateImage() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(200)); - ImageApi api = api(DockerApi.class, server.getUrl("/").toString()).getImageApi(); + ImageApi api = api(DockerApi.class, server.url("/").toString()).getImageApi(); try { api.createImage(CreateImageOptions.Builder.fromImage("base")); assertSent(server, "POST", "/images/create?fromImage=base"); @@ -55,7 +57,7 @@ public class ImageApiMockTest extends BaseDockerMockTest { public void testGetImage() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/image.json"))); - ImageApi api = api(DockerApi.class, server.getUrl("/").toString(), new DockerParserModule()).getImageApi(); + ImageApi api = api(DockerApi.class, server.url("/").toString(), new DockerParserModule()).getImageApi(); try { String imageId = "cbba6639a342646deed70d7ea6162fa2a0acea9300f911f4e014555fe37d3456"; assertEquals(api.inspectImage(imageId), new ImageParseTest().expected()); @@ -67,7 +69,7 @@ public class ImageApiMockTest extends BaseDockerMockTest { public void testListImages() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/images.json"))); - ImageApi api = api(DockerApi.class, server.getUrl("/").toString()).getImageApi(); + ImageApi api = api(DockerApi.class, server.url("/").toString()).getImageApi(); try { assertEquals(api.listImages(), new ImagesParseTest().expected()); assertSent(server, "GET", "/images/json"); @@ -78,7 +80,7 @@ public class ImageApiMockTest extends BaseDockerMockTest { public void testTagImage() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(201)); - ImageApi api = api(DockerApi.class, server.getUrl("/").toString()).getImageApi(); + ImageApi api = api(DockerApi.class, server.url("/").toString()).getImageApi(); try { api.tagImage("633fcd11259e8d6bccfbb59a4086b95b0d0fb44edfc3912000ef1f70e8a7bfc6", "jclouds", "testTag", true); assertSent(server, "POST", @@ -90,7 +92,7 @@ public class ImageApiMockTest extends BaseDockerMockTest { public void testDeleteImage() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(204)); - ImageApi api = api(DockerApi.class, server.getUrl("/").toString()).getImageApi(); + ImageApi api = api(DockerApi.class, server.url("/").toString()).getImageApi(); try { api.deleteImage("1"); assertSent(server, "DELETE", "/images/1"); @@ -105,7 +107,7 @@ public class ImageApiMockTest extends BaseDockerMockTest { new MockResponse().setBody(payloadFromResource("/history.json")), new MockResponse().setBody(payloadFromResource("/history-apiver22.json")), new MockResponse().setResponseCode(404)); - ImageApi api = api(DockerApi.class, server.getUrl("/").toString()).getImageApi(); + ImageApi api = api(DockerApi.class, server.url("/").toString()).getImageApi(); try { assertEquals(api.getHistory("ubuntu"), new HistoryParseTest().expected()); assertSent(server, "GET", "/images/ubuntu/history"); diff --git a/apis/docker/src/test/java/org/jclouds/docker/features/MiscApiMockTest.java b/apis/docker/src/test/java/org/jclouds/docker/features/MiscApiMockTest.java index dd5d965ac5..a3d21a194d 100644 --- a/apis/docker/src/test/java/org/jclouds/docker/features/MiscApiMockTest.java +++ b/apis/docker/src/test/java/org/jclouds/docker/features/MiscApiMockTest.java @@ -30,6 +30,10 @@ import java.nio.charset.StandardCharsets; import javax.ws.rs.core.HttpHeaders; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.docker.DockerApi; import org.jclouds.docker.config.DockerParserModule; import org.jclouds.docker.domain.Exec; @@ -47,9 +51,7 @@ import org.jclouds.io.Payloads; import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; + /** * Mock tests for the {@link org.jclouds.docker.features.MiscApi} class. @@ -59,7 +61,7 @@ public class MiscApiMockTest extends BaseDockerMockTest { public void testGetVersion() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/version.json"))); - MiscApi api = api(DockerApi.class, server.getUrl("/").toString()).getMiscApi(); + MiscApi api = api(DockerApi.class, server.url("/").toString()).getMiscApi(); try { assertEquals(api.getVersion(), new VersionParseTest().expected()); assertSent(server, "GET", "/version"); @@ -70,7 +72,7 @@ public class MiscApiMockTest extends BaseDockerMockTest { public void testGetInfo() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/info.json"))); - MiscApi api = api(DockerApi.class, server.getUrl("/").toString()).getMiscApi(); + MiscApi api = api(DockerApi.class, server.url("/").toString()).getMiscApi(); try { assertEquals(api.getInfo(), new InfoParseTest().expected()); assertSent(server, "GET", "/info"); @@ -81,7 +83,7 @@ public class MiscApiMockTest extends BaseDockerMockTest { public void testBuildContainer() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(200)); - MiscApi api = api(DockerApi.class, server.getUrl("/").toString()).getMiscApi(); + MiscApi api = api(DockerApi.class, server.url("/").toString()).getMiscApi(); try { api.build(tarredDockerfile()); RecordedRequest request = assertSent(server, "POST", "/build"); @@ -93,7 +95,7 @@ public class MiscApiMockTest extends BaseDockerMockTest { public void testBuildContainerUsingPayload() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(200)); - MiscApi api = api(DockerApi.class, server.getUrl("/").toString()).getMiscApi(); + MiscApi api = api(DockerApi.class, server.url("/").toString()).getMiscApi(); File file = File.createTempFile("docker", "tmp"); FileInputStream data = new FileInputStream(file); Payload payload = Payloads.newInputStreamPayload(data); @@ -110,7 +112,7 @@ public class MiscApiMockTest extends BaseDockerMockTest { public void testExecCreate() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/exec.json"))); - MiscApi api = api(DockerApi.class, server.getUrl("/").toString(), new DockerParserModule()).getMiscApi(); + MiscApi api = api(DockerApi.class, server.url("/").toString(), new DockerParserModule()).getMiscApi(); try { final String containerId = "a40d212a0a379de00426a1da2a8fd3fd20d5f74fd7c2dd42f6c93a6b1b0e6974"; final ExecCreateParams execParams = ExecCreateParams.builder() @@ -126,7 +128,7 @@ public class MiscApiMockTest extends BaseDockerMockTest { public void testExecStart() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/exec.start"))); - MiscApi api = api(DockerApi.class, server.getUrl("/").toString(), new DockerParserModule()).getMiscApi(); + MiscApi api = api(DockerApi.class, server.url("/").toString(), new DockerParserModule()).getMiscApi(); DockerInputStream dis = null; try { final String execId = "dbf45d296388032ebb9872edb75847f6655a72b4e9ab0d99ae1c75589c4ca957"; @@ -155,7 +157,7 @@ public class MiscApiMockTest extends BaseDockerMockTest { public void testExecInspect() throws IOException, InterruptedException { MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/execInspect.json"))); - MiscApi api = api(DockerApi.class, server.getUrl("/").toString(), new DockerParserModule()).getMiscApi(); + MiscApi api = api(DockerApi.class, server.url("/").toString(), new DockerParserModule()).getMiscApi(); final String expectedExecId = "fda1cf8064863fc0667c691c69793fdb7d0bd4a1fabb8250536abe5203e4208a"; ExecInspect execInspect = api.execInspect(expectedExecId); assertNotNull(execInspect); diff --git a/apis/docker/src/test/java/org/jclouds/docker/features/NetworkApiMockTest.java b/apis/docker/src/test/java/org/jclouds/docker/features/NetworkApiMockTest.java index f35e2572c4..a91aa691f7 100644 --- a/apis/docker/src/test/java/org/jclouds/docker/features/NetworkApiMockTest.java +++ b/apis/docker/src/test/java/org/jclouds/docker/features/NetworkApiMockTest.java @@ -21,6 +21,9 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import java.util.Map; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.docker.DockerApi; import org.jclouds.docker.config.DockerParserModule; import org.jclouds.docker.domain.Network; @@ -31,8 +34,7 @@ import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; + /** * Mock tests for the {@link NetworkApi} class. @@ -42,7 +44,7 @@ public class NetworkApiMockTest extends BaseDockerMockTest { public void testListNetworks() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/networks.json"))); - NetworkApi api = api(DockerApi.class, server.getUrl("/").toString()).getNetworkApi(); + NetworkApi api = api(DockerApi.class, server.url("/").toString()).getNetworkApi(); try { assertEquals(api.listNetworks(), new NetworksParseTest().expected()); assertSent(server, "GET", "/networks"); @@ -53,7 +55,7 @@ public class NetworkApiMockTest extends BaseDockerMockTest { public void testListNonexistentNetworks() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(404)); - NetworkApi api = api(DockerApi.class, server.getUrl("/").toString()).getNetworkApi(); + NetworkApi api = api(DockerApi.class, server.url("/").toString()).getNetworkApi(); try { assertEquals(api.listNetworks(), ImmutableList.of()); assertSent(server, "GET", "/networks"); @@ -64,7 +66,7 @@ public class NetworkApiMockTest extends BaseDockerMockTest { public void testGetNetwork() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/network.json"))); - NetworkApi api = api(DockerApi.class, server.getUrl("/").toString(), new DockerParserModule()).getNetworkApi(); + NetworkApi api = api(DockerApi.class, server.url("/").toString(), new DockerParserModule()).getNetworkApi(); String networkId = "b03d4cd15b76f8876110615cdeed15eadf77c9beb408d62f1687dcc69192cd6d"; try { assertEquals(api.inspectNetwork(networkId), new NetworkParseTest().expected()); @@ -76,7 +78,7 @@ public class NetworkApiMockTest extends BaseDockerMockTest { public void testCreateNetwork() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/network-creation.json"))); - NetworkApi api = api(DockerApi.class, server.getUrl("/").toString()).getNetworkApi(); + NetworkApi api = api(DockerApi.class, server.url("/").toString()).getNetworkApi(); Map options = ImmutableMap. builder() .put("com.docker.network.bridge.default_bridge", "true") @@ -118,7 +120,7 @@ public class NetworkApiMockTest extends BaseDockerMockTest { public void testRemoveNetwork() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(204)); - NetworkApi api = api(DockerApi.class, server.getUrl("/").toString()).getNetworkApi(); + NetworkApi api = api(DockerApi.class, server.url("/").toString()).getNetworkApi(); String networkId = "6d35806c1bd2b25cd92bba2d2c2c5169dc2156f53ab45c2b62d76e2d2fee14a9"; try { api.removeNetwork(networkId); @@ -130,7 +132,7 @@ public class NetworkApiMockTest extends BaseDockerMockTest { public void testConnectContainerToNetwork() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(200)); - NetworkApi api = api(DockerApi.class, server.getUrl("/").toString()).getNetworkApi(); + NetworkApi api = api(DockerApi.class, server.url("/").toString()).getNetworkApi(); try { api.connectContainerToNetwork("123456789", "containerName"); assertSent(server, "POST", "/networks/123456789/connect", "{ \"Container\": \"containerName\" }"); @@ -141,7 +143,7 @@ public class NetworkApiMockTest extends BaseDockerMockTest { public void testDisconnectContainerFromNetwork() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(200)); - NetworkApi api = api(DockerApi.class, server.getUrl("/").toString()).getNetworkApi(); + NetworkApi api = api(DockerApi.class, server.url("/").toString()).getNetworkApi(); try { api.disconnectContainerFromNetwork("123456789", "containerName"); assertSent(server, "POST", "/networks/123456789/disconnect", "{ \"Container\": \"containerName\" }"); diff --git a/apis/docker/src/test/java/org/jclouds/docker/internal/BaseDockerMockTest.java b/apis/docker/src/test/java/org/jclouds/docker/internal/BaseDockerMockTest.java index f04e94f035..a273ebc4b3 100644 --- a/apis/docker/src/test/java/org/jclouds/docker/internal/BaseDockerMockTest.java +++ b/apis/docker/src/test/java/org/jclouds/docker/internal/BaseDockerMockTest.java @@ -16,7 +16,6 @@ */ package org.jclouds.docker.internal; -import static com.google.common.base.Charsets.UTF_8; import static javax.ws.rs.core.MediaType.APPLICATION_JSON; import static org.assertj.core.api.Assertions.assertThat; import static org.jclouds.util.Strings2.toStringAndClose; @@ -27,15 +26,16 @@ import java.util.Properties; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.http.BaseMockWebServerTest; import org.jclouds.http.okhttp.config.OkHttpCommandExecutorServiceModule; -import com.google.common.base.Charsets; import com.google.common.base.Throwables; import com.google.gson.JsonParser; import com.google.inject.Module; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; + /** * Base class for all Docker mock tests. @@ -54,9 +54,9 @@ public class BaseDockerMockTest extends BaseMockWebServerTest { return new OkHttpCommandExecutorServiceModule(); } - public byte[] payloadFromResource(String resource) { + public String payloadFromResource(String resource) { try { - return toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8); + return toStringAndClose(getClass().getResourceAsStream(resource)); } catch (IOException e) { throw Throwables.propagate(e); } @@ -74,7 +74,7 @@ public class BaseDockerMockTest extends BaseMockWebServerTest { throws InterruptedException { RecordedRequest request = assertSent(server, method, path); assertEquals(request.getHeader("Content-Type"), APPLICATION_JSON); - assertEquals(parser.parse(new String(request.getBody(), UTF_8)), parser.parse(json)); + assertEquals(parser.parse(request.getBody().readUtf8()), parser.parse(json)); return request; } diff --git a/apis/ec2/pom.xml b/apis/ec2/pom.xml index bfd52ecbfd..fa702a18a6 100644 --- a/apis/ec2/pom.xml +++ b/apis/ec2/pom.xml @@ -84,7 +84,7 @@ test - com.squareup.okhttp + com.squareup.okhttp3 mockwebserver test diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/internal/BaseEC2ApiMockTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/internal/BaseEC2ApiMockTest.java index c89a9f3c3f..5bc811ed5f 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/internal/BaseEC2ApiMockTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/internal/BaseEC2ApiMockTest.java @@ -28,6 +28,10 @@ import java.util.Map; import java.util.Properties; import java.util.Set; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.Constants; import org.jclouds.ContextBuilder; import org.jclouds.concurrent.config.ExecutorServiceModule; @@ -36,13 +40,10 @@ import org.jclouds.ec2.EC2ApiMetadata; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; -import com.google.common.base.Charsets; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; import com.google.inject.Module; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; + /** * Tests need to run {@code singleThreaded = true) as otherwise tests will clash on the regionToServers field. @@ -66,7 +67,7 @@ public class BaseEC2ApiMockTest { MockWebServer defaultServer = regionToServers.get(DEFAULT_REGION); return ContextBuilder.newBuilder(new EC2ApiMetadata()) .credentials(ACCESS_KEY, SECRET_KEY) - .endpoint(defaultServer.getUrl("").toString()) + .endpoint(defaultServer.url("").toString()) .overrides(overrides) .modules(modules); } @@ -76,7 +77,7 @@ public class BaseEC2ApiMockTest { @BeforeMethod public void start() throws IOException { MockWebServer server = new MockWebServer(); - server.play(); + server.start(); regionToServers.put(DEFAULT_REGION, server); } @@ -99,11 +100,11 @@ public class BaseEC2ApiMockTest { describeRegionsResponse.append("").append(region).append(""); if (!regionToServers.containsKey(region)) { MockWebServer server = new MockWebServer(); - server.play(); + server.start(); regionToServers.put(region, server); } MockWebServer server = regionToServers.get(region); - String regionEndpoint = server.getUrl("").toString(); + String regionEndpoint = server.url("").toString(); describeRegionsResponse.append("").append(regionEndpoint).append(""); describeRegionsResponse.append(""); } @@ -130,7 +131,7 @@ public class BaseEC2ApiMockTest { RecordedRequest request = regionToServers.get(region).takeRequest(); assertEquals(request.getMethod(), "POST"); assertEquals(request.getPath(), "/"); - assertEquals(new String(request.getBody(), Charsets.UTF_8).replaceAll("&Signature.*", ""), postParams); + assertEquals(request.getBody().readUtf8().replaceAll("&Signature.*", ""), postParams); return request; } } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/suppliers/DescribeAvailabilityZonesInRegionMockTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/suppliers/DescribeAvailabilityZonesInRegionMockTest.java index 11702245a1..9f3c2925dc 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/suppliers/DescribeAvailabilityZonesInRegionMockTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/suppliers/DescribeAvailabilityZonesInRegionMockTest.java @@ -22,6 +22,8 @@ import static org.testng.Assert.fail; import java.util.Map; import java.util.Set; +import okhttp3.mockwebserver.MockResponse; + import org.jclouds.ec2.internal.BaseEC2ApiMockTest; import org.jclouds.rest.AuthorizationException; import org.testng.annotations.Test; @@ -29,7 +31,7 @@ import org.testng.annotations.Test; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableSet; -import com.squareup.okhttp.mockwebserver.MockResponse; + @Test(groups = "unit", testName = "DescribeAvailabilityZonesInRegionMockTest", singleThreaded = true) public class DescribeAvailabilityZonesInRegionMockTest extends BaseEC2ApiMockTest { diff --git a/apis/elasticstack/pom.xml b/apis/elasticstack/pom.xml index 86026dcef8..183e731c11 100644 --- a/apis/elasticstack/pom.xml +++ b/apis/elasticstack/pom.xml @@ -72,7 +72,7 @@ test - com.squareup.okhttp + com.squareup.okhttp3 mockwebserver test @@ -83,6 +83,18 @@ + + com.squareup.okhttp3 + okhttp-tls + test + + + + org.bouncycastle + bcprov-jdk15on + + + com.google.auto.service auto-service diff --git a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackMockTest.java b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackMockTest.java index e74ca85042..f0bee408b2 100644 --- a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackMockTest.java +++ b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackMockTest.java @@ -27,17 +27,18 @@ import java.util.Set; import javax.ws.rs.core.HttpHeaders; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.elasticstack.domain.StandardDrive; import org.jclouds.http.BaseMockWebServerTest; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.testng.annotations.Test; -import com.google.common.base.Charsets; import com.google.common.base.Throwables; import com.google.inject.Module; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; + /** * Mock tests for the {@link ElasticStackApi} class. @@ -48,7 +49,7 @@ public class ElasticStackMockTest extends BaseMockWebServerTest { public void testListStandardDrives() throws IOException, InterruptedException { MockWebServer server = mockWebServer(new MockResponse() .setBody(payloadFromResource("/standard_drives_uuids.txt"))); - ElasticStackApi api = api(ElasticStackApi.class, server.getUrl("/").toString()); + ElasticStackApi api = api(ElasticStackApi.class, server.url("/").toString()); try { Set standardDrives = api.listStandardDrives(); @@ -65,7 +66,7 @@ public class ElasticStackMockTest extends BaseMockWebServerTest { public void testListStandardDriveInfo() throws IOException, InterruptedException { MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/standard_drives.txt"))); - ElasticStackApi api = api(ElasticStackApi.class, server.getUrl("/").toString()); + ElasticStackApi api = api(ElasticStackApi.class, server.url("/").toString()); try { Set standardDrives = api.listStandardDriveInfo(); @@ -84,9 +85,9 @@ public class ElasticStackMockTest extends BaseMockWebServerTest { assertEquals(request.getHeader(HttpHeaders.AUTHORIZATION), "Basic dXVpZDphcGlrZXk="); } - private byte[] payloadFromResource(String resource) { + private String payloadFromResource(String resource) { try { - return toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8); + return toStringAndClose(getClass().getResourceAsStream(resource)); } catch (IOException e) { throw Throwables.propagate(e); } diff --git a/apis/oauth/pom.xml b/apis/oauth/pom.xml index 320357dc42..ccd5661ac0 100644 --- a/apis/oauth/pom.xml +++ b/apis/oauth/pom.xml @@ -66,7 +66,7 @@ test - com.squareup.okhttp + com.squareup.okhttp3 mockwebserver test diff --git a/apis/oauth/src/test/java/org/jclouds/oauth/v2/AuthorizationApiMockTest.java b/apis/oauth/src/test/java/org/jclouds/oauth/v2/AuthorizationApiMockTest.java index 792f8bb4c9..f75585228c 100644 --- a/apis/oauth/src/test/java/org/jclouds/oauth/v2/AuthorizationApiMockTest.java +++ b/apis/oauth/src/test/java/org/jclouds/oauth/v2/AuthorizationApiMockTest.java @@ -37,6 +37,10 @@ import java.io.IOException; import java.net.URL; import java.util.Properties; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.ContextBuilder; import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.oauth.v2.config.CredentialType; @@ -55,9 +59,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.io.BaseEncoding; import com.google.inject.Binder; import com.google.inject.Module; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; + @Test(groups = "unit", testName = "OAuthApiMockTest") public class AuthorizationApiMockTest { @@ -101,9 +103,9 @@ public class AuthorizationApiMockTest { server.enqueue(new MockResponse().setBody("{\n" + " \"access_token\" : \"1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M\",\n" + " \"token_type\" : \"Bearer\",\n" + " \"expires_in\" : 3600\n" + "}")); - server.play(); + server.start(); - AuthorizationApi api = api(server.getUrl("/"), P12_PRIVATE_KEY_CREDENTIALS); + AuthorizationApi api = api(server.url("/").url(), P12_PRIVATE_KEY_CREDENTIALS); assertEquals(api.authorize(CLAIMS), TOKEN); @@ -113,7 +115,7 @@ public class AuthorizationApiMockTest { assertEquals(request.getHeader("Content-Type"), "application/x-www-form-urlencoded"); assertEquals( - new String(request.getBody(), UTF_8), // + request.getBody().readUtf8(), // "grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&" + // Base64 Encoded Header @@ -134,9 +136,9 @@ public class AuthorizationApiMockTest { MockWebServer server = new MockWebServer(); try { server.enqueue(new MockResponse().setResponseCode(400)); - server.play(); + server.start(); - AuthorizationApi api = api(server.getUrl("/"), P12_PRIVATE_KEY_CREDENTIALS); + AuthorizationApi api = api(server.url("/").url(), P12_PRIVATE_KEY_CREDENTIALS); api.authorize(CLAIMS); fail("An AuthorizationException should have been raised"); } catch (AuthorizationException ex) { @@ -158,9 +160,9 @@ public class AuthorizationApiMockTest { server.enqueue(new MockResponse().setBody("{\n" + " \"access_token\" : \"1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M\",\n" + " \"token_type\" : \"Bearer\",\n" + " \"expires_in\" : 3600\n" + "}")); - server.play(); + server.start(); - AuthorizationApi api = api(server.getUrl("/"), CLIENT_CREDENTIALS_SECRET); + AuthorizationApi api = api(server.url("/").url(), CLIENT_CREDENTIALS_SECRET); assertEquals(api.authorizeClientSecret(identity, credential, resource, null), TOKEN); @@ -170,7 +172,7 @@ public class AuthorizationApiMockTest { assertEquals(request.getHeader("Content-Type"), "application/x-www-form-urlencoded"); assertEquals( - new String(request.getBody(), UTF_8), // + request.getBody().readUtf8(), // "grant_type=client_credentials&client_id=" + identity + "&client_secret=" + credential + "&resource=" + encoded_resource); @@ -190,9 +192,9 @@ public class AuthorizationApiMockTest { server.enqueue(new MockResponse().setBody("{\n" + " \"access_token\" : \"1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M\",\n" + " \"token_type\" : \"Bearer\",\n" + " \"expires_in\" : 3600\n" + "}")); - server.play(); + server.start(); - AuthorizationApi api = api(server.getUrl("/"), CLIENT_CREDENTIALS_P12_AND_CERTIFICATE); + AuthorizationApi api = api(server.url("/").url(), CLIENT_CREDENTIALS_P12_AND_CERTIFICATE); assertEquals(api.authorize(identity, CLIENT_CREDENTIALS_CLAIMS, resource, null), TOKEN); RecordedRequest request = server.takeRequest(); @@ -201,7 +203,7 @@ public class AuthorizationApiMockTest { assertEquals(request.getHeader("Content-Type"), "application/x-www-form-urlencoded"); assertEquals( - new String(request.getBody(), UTF_8), + request.getBody().readUtf8(), "grant_type=client_credentials&" + "client_assertion_type=urn%3Aietf%3Aparams%3Aoauth%3Aclient-assertion-type%3Ajwt-bearer&" + "client_id=" + identity + "&" + diff --git a/apis/openstack-keystone/pom.xml b/apis/openstack-keystone/pom.xml index 9e8b37edef..385b2aaf08 100644 --- a/apis/openstack-keystone/pom.xml +++ b/apis/openstack-keystone/pom.xml @@ -78,7 +78,7 @@ test - com.squareup.okhttp + com.squareup.okhttp3 mockwebserver test diff --git a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/extensions/RoleAdminApiMockTest.java b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/extensions/RoleAdminApiMockTest.java index e50cc2ef10..0b33b939cc 100644 --- a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/extensions/RoleAdminApiMockTest.java +++ b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/extensions/RoleAdminApiMockTest.java @@ -22,6 +22,10 @@ import static org.testng.Assert.assertTrue; import java.util.Set; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.openstack.keystone.v2_0.KeystoneApi; import org.jclouds.openstack.keystone.v2_0.domain.Role; import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest; @@ -29,9 +33,7 @@ import org.testng.annotations.Test; import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableSet; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; + /** * Tests RoleApi Guice wiring and parsing @@ -52,7 +54,7 @@ public class RoleAdminApiMockTest extends BaseOpenStackMockTest { stringFromResource("/role_list_response.json")))); try { - KeystoneApi keystoneApi = api(server.getUrl("/").toString(), "openstack-keystone"); + KeystoneApi keystoneApi = api(server.url("/").toString(), "openstack-keystone"); RoleAdminApi roleAdminApi = keystoneApi.getRoleAdminApi().get(); FluentIterable roles = roleAdminApi.list(); @@ -78,7 +80,7 @@ public class RoleAdminApiMockTest extends BaseOpenStackMockTest { stringFromResource("/role_create_response.json")))); try { - KeystoneApi keystoneApi = api(server.getUrl("/").toString(), "openstack-keystone"); + KeystoneApi keystoneApi = api(server.url("/").toString(), "openstack-keystone"); RoleAdminApi roleAdminApi = keystoneApi.getRoleAdminApi().get(); Role testRole = roleAdminApi.create("jclouds-role"); @@ -90,7 +92,7 @@ public class RoleAdminApiMockTest extends BaseOpenStackMockTest { assertExtensions(server); RecordedRequest createRoleRequest = server.takeRequest(); assertEquals(createRoleRequest.getRequestLine(), "POST /OS-KSADM/roles HTTP/1.1"); - assertEquals(new String(createRoleRequest.getBody()), "{\"role\":{\"name\":\"jclouds-role\"}}"); + assertEquals(createRoleRequest.getBody().readUtf8(), "{\"role\":{\"name\":\"jclouds-role\"}}"); } finally { server.shutdown(); } @@ -104,7 +106,7 @@ public class RoleAdminApiMockTest extends BaseOpenStackMockTest { stringFromResource("/role_create_response.json")))); try { - KeystoneApi keystoneApi = api(server.getUrl("/").toString(), "openstack-keystone"); + KeystoneApi keystoneApi = api(server.url("/").toString(), "openstack-keystone"); RoleAdminApi roleAdminApi = keystoneApi.getRoleAdminApi().get(); Role role = roleAdminApi.get("r1000"); @@ -131,7 +133,7 @@ public class RoleAdminApiMockTest extends BaseOpenStackMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(204))); try { - KeystoneApi keystoneApi = api(server.getUrl("/").toString(), "openstack-keystone"); + KeystoneApi keystoneApi = api(server.url("/").toString(), "openstack-keystone"); RoleAdminApi roleAdminApi = keystoneApi.getRoleAdminApi().get(); boolean success = roleAdminApi.delete("r1000"); diff --git a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/extensions/ServiceAdminApiMockTest.java b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/extensions/ServiceAdminApiMockTest.java index b68f8eb339..aa2206902c 100644 --- a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/extensions/ServiceAdminApiMockTest.java +++ b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/extensions/ServiceAdminApiMockTest.java @@ -21,6 +21,10 @@ import static org.testng.Assert.assertNotNull; import java.util.Set; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.collect.PagedIterable; import org.jclouds.openstack.keystone.v2_0.KeystoneApi; import org.jclouds.openstack.keystone.v2_0.domain.Service; @@ -30,9 +34,7 @@ import org.jclouds.openstack.v2_0.options.PaginationOptions; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; + /** * Tests ServiceApi Guice wiring and parsing @@ -54,7 +56,7 @@ public class ServiceAdminApiMockTest extends BaseOpenStackMockTest stringFromResource("/service_list_response.json")))); try { - KeystoneApi keystoneApi = api(server.getUrl("/").toString(), "openstack-keystone"); + KeystoneApi keystoneApi = api(server.url("/").toString(), "openstack-keystone"); ServiceAdminApi serviceAdminApi = keystoneApi.getServiceAdminApi().get(); PagedIterable services = serviceAdminApi.list(); @@ -80,7 +82,7 @@ public class ServiceAdminApiMockTest extends BaseOpenStackMockTest stringFromResource("/service_list_response.json")))); try { - KeystoneApi keystoneApi = api(server.getUrl("/").toString(), "openstack-keystone"); + KeystoneApi keystoneApi = api(server.url("/").toString(), "openstack-keystone"); ServiceAdminApi serviceAdminApi = keystoneApi.getServiceAdminApi().get(); PaginatedCollection services = serviceAdminApi.list(new PaginationOptions()); @@ -106,7 +108,7 @@ public class ServiceAdminApiMockTest extends BaseOpenStackMockTest stringFromResource("/service_create_response.json")))); try { - KeystoneApi keystoneApi = api(server.getUrl("/").toString(), "openstack-keystone"); + KeystoneApi keystoneApi = api(server.url("/").toString(), "openstack-keystone"); ServiceAdminApi serviceAdminApi = keystoneApi.getServiceAdminApi().get(); Service testService = serviceAdminApi.create("jclouds-service-test", "jclouds-service-type", "jclouds-service-description"); @@ -119,7 +121,7 @@ public class ServiceAdminApiMockTest extends BaseOpenStackMockTest assertExtensions(server); RecordedRequest createServiceRequest = server.takeRequest(); assertEquals(createServiceRequest.getRequestLine(), "POST /OS-KSADM/services HTTP/1.1"); - String bodyRequest = new String(createServiceRequest.getBody()); + String bodyRequest = createServiceRequest.getBody().readUtf8(); assertEquals( bodyRequest, "{\"OS-KSADM:service\":{\"name\":\"jclouds-service-test\",\"type\":\"jclouds-service-type\",\"description\":\"jclouds-service-description\"}}"); @@ -136,7 +138,7 @@ public class ServiceAdminApiMockTest extends BaseOpenStackMockTest stringFromResource("/service_create_response.json")))); try { - KeystoneApi keystoneApi = api(server.getUrl("/").toString(), "openstack-keystone"); + KeystoneApi keystoneApi = api(server.url("/").toString(), "openstack-keystone"); ServiceAdminApi serviceAdminApi = keystoneApi.getServiceAdminApi().get(); Service service = serviceAdminApi.get("s1000"); @@ -163,7 +165,7 @@ public class ServiceAdminApiMockTest extends BaseOpenStackMockTest server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(204))); try { - KeystoneApi keystoneApi = api(server.getUrl("/").toString(), "openstack-keystone"); + KeystoneApi keystoneApi = api(server.url("/").toString(), "openstack-keystone"); ServiceAdminApi serviceAdminApi = keystoneApi.getServiceAdminApi().get(); serviceAdminApi.delete("s1000"); diff --git a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/extensions/TenantAdminApiMockTest.java b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/extensions/TenantAdminApiMockTest.java index 4a052fd3a0..a626076fa8 100644 --- a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/extensions/TenantAdminApiMockTest.java +++ b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/extensions/TenantAdminApiMockTest.java @@ -19,6 +19,10 @@ package org.jclouds.openstack.keystone.v2_0.extensions; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.openstack.keystone.v2_0.KeystoneApi; import org.jclouds.openstack.keystone.v2_0.domain.Tenant; import org.jclouds.openstack.keystone.v2_0.options.CreateTenantOptions; @@ -26,9 +30,6 @@ import org.jclouds.openstack.keystone.v2_0.options.UpdateTenantOptions; import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest; import org.testng.annotations.Test; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; /** * Tests TenantApi Guice wiring and parsing @@ -44,7 +45,7 @@ public class TenantAdminApiMockTest extends BaseOpenStackMockTest { stringFromResource("/tenant_create_response.json")))); try { - KeystoneApi keystoneApi = api(server.getUrl("/").toString(), "openstack-keystone"); + KeystoneApi keystoneApi = api(server.url("/").toString(), "openstack-keystone"); TenantAdminApi tenantAdminApi = keystoneApi.getTenantAdminApi().get(); CreateTenantOptions createTenantOptions = CreateTenantOptions.Builder.description("jclouds-description") .enabled(true); @@ -58,7 +59,7 @@ public class TenantAdminApiMockTest extends BaseOpenStackMockTest { assertExtensions(server); RecordedRequest createTenantRequest = server.takeRequest(); assertEquals(createTenantRequest.getRequestLine(), "POST /tenants HTTP/1.1"); - assertEquals(new String(createTenantRequest.getBody()), + assertEquals(createTenantRequest.getBody().readUtf8(), "{\"tenant\":{\"name\":\"jclouds-tenant\",\"description\":\"jclouds-description\",\"enabled\":true}}"); } finally { server.shutdown(); @@ -73,7 +74,7 @@ public class TenantAdminApiMockTest extends BaseOpenStackMockTest { stringFromResource("/tenant_update_response.json")))); try { - KeystoneApi keystoneApi = api(server.getUrl("/").toString(), "openstack-keystone"); + KeystoneApi keystoneApi = api(server.url("/").toString(), "openstack-keystone"); TenantAdminApi tenantAdminApi = keystoneApi.getTenantAdminApi().get(); UpdateTenantOptions updateTenantOptions = UpdateTenantOptions.Builder .description("jclouds-description-modified").enabled(false).name("jclouds-tenant-modified"); @@ -88,7 +89,7 @@ public class TenantAdminApiMockTest extends BaseOpenStackMockTest { RecordedRequest updateTenantRequest = server.takeRequest(); assertEquals(updateTenantRequest.getRequestLine(), "PUT /tenants/t1000 HTTP/1.1"); assertEquals( - new String(updateTenantRequest.getBody()), + updateTenantRequest.getBody().readUtf8(), "{\"tenant\":{\"name\":\"jclouds-tenant-modified\",\"description\":\"jclouds-description-modified\",\"enabled\":false}}"); } finally { server.shutdown(); @@ -102,7 +103,7 @@ public class TenantAdminApiMockTest extends BaseOpenStackMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(204))); try { - KeystoneApi keystoneApi = api(server.getUrl("/").toString(), "openstack-keystone"); + KeystoneApi keystoneApi = api(server.url("/").toString(), "openstack-keystone"); TenantAdminApi tenantAdminApi = keystoneApi.getTenantAdminApi().get(); tenantAdminApi.delete("t1000"); @@ -123,7 +124,7 @@ public class TenantAdminApiMockTest extends BaseOpenStackMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201))); try { - KeystoneApi keystoneApi = api(server.getUrl("/").toString(), "openstack-keystone"); + KeystoneApi keystoneApi = api(server.url("/").toString(), "openstack-keystone"); TenantAdminApi tenantAdminApi = keystoneApi.getTenantAdminApi().get(); tenantAdminApi.addRoleOnTenant("u1000", "t1000", "r1000"); @@ -145,7 +146,7 @@ public class TenantAdminApiMockTest extends BaseOpenStackMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(204))); try { - KeystoneApi keystoneApi = api(server.getUrl("/").toString(), "openstack-keystone"); + KeystoneApi keystoneApi = api(server.url("/").toString(), "openstack-keystone"); TenantAdminApi tenantAdminApi = keystoneApi.getTenantAdminApi().get(); tenantAdminApi.deleteRoleOnTenant("t1000", "u1000", "r1000"); diff --git a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/extensions/UserAdminApiMockTest.java b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/extensions/UserAdminApiMockTest.java index 3b269c08f3..7672e71e53 100644 --- a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/extensions/UserAdminApiMockTest.java +++ b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v2_0/extensions/UserAdminApiMockTest.java @@ -19,6 +19,10 @@ package org.jclouds.openstack.keystone.v2_0.extensions; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.openstack.keystone.v2_0.KeystoneApi; import org.jclouds.openstack.keystone.v2_0.domain.User; import org.jclouds.openstack.keystone.v2_0.options.CreateUserOptions; @@ -26,9 +30,6 @@ import org.jclouds.openstack.keystone.v2_0.options.UpdateUserOptions; import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest; import org.testng.annotations.Test; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; /** * Tests UserApi Guice wiring and parsing @@ -44,7 +45,7 @@ public class UserAdminApiMockTest extends BaseOpenStackMockTest { stringFromResource("/user_create_response.json")))); try { - KeystoneApi keystoneApi = api(server.getUrl("/").toString(), "openstack-keystone"); + KeystoneApi keystoneApi = api(server.url("/").toString(), "openstack-keystone"); UserAdminApi userAdminApi = keystoneApi.getUserAdminApi().get(); CreateUserOptions createUserOptions = CreateUserOptions.Builder.email("john.smith@example.org").enabled(true) .tenant("12345"); @@ -59,7 +60,7 @@ public class UserAdminApiMockTest extends BaseOpenStackMockTest { RecordedRequest createUserRequest = server.takeRequest(); assertEquals(createUserRequest.getRequestLine(), "POST /users HTTP/1.1"); assertEquals( - new String(createUserRequest.getBody()), + createUserRequest.getBody().readUtf8(), "{\"user\":{\"name\":\"jqsmith\",\"tenantId\":\"12345\",\"password\":\"jclouds-password\",\"email\":\"john.smith@example.org\",\"enabled\":true}}"); } finally { server.shutdown(); @@ -74,7 +75,7 @@ public class UserAdminApiMockTest extends BaseOpenStackMockTest { stringFromResource("/user_update_response.json")))); try { - KeystoneApi keystoneApi = api(server.getUrl("/").toString(), "openstack-keystone"); + KeystoneApi keystoneApi = api(server.url("/").toString(), "openstack-keystone"); UserAdminApi userAdminApi = keystoneApi.getUserAdminApi().get(); UpdateUserOptions updateUserOptions = UpdateUserOptions.Builder.email("john.smith.renamed@example.org") .enabled(false).name("jqsmith-renamed").password("jclouds-password"); @@ -89,7 +90,7 @@ public class UserAdminApiMockTest extends BaseOpenStackMockTest { RecordedRequest updateUserRequest = server.takeRequest(); assertEquals(updateUserRequest.getRequestLine(), "PUT /users/u1000 HTTP/1.1"); assertEquals( - new String(updateUserRequest.getBody()), + updateUserRequest.getBody().readUtf8(), "{\"user\":{\"name\":\"jqsmith-renamed\",\"email\":\"john.smith.renamed@example.org\",\"password\":\"jclouds-password\",\"enabled\":false}}"); } finally { server.shutdown(); @@ -103,7 +104,7 @@ public class UserAdminApiMockTest extends BaseOpenStackMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(204))); try { - KeystoneApi keystoneApi = api(server.getUrl("/").toString(), "openstack-keystone"); + KeystoneApi keystoneApi = api(server.url("/").toString(), "openstack-keystone"); UserAdminApi userAdminApi = keystoneApi.getUserAdminApi().get(); userAdminApi.delete("u1000"); diff --git a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v3/features/AuthApiMockTest.java b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v3/features/AuthApiMockTest.java index a156fad845..482738f2e3 100644 --- a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v3/features/AuthApiMockTest.java +++ b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v3/features/AuthApiMockTest.java @@ -21,12 +21,13 @@ import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.openstack.keystone.v3.domain.Token; import org.jclouds.openstack.keystone.v3.domain.User; import org.jclouds.openstack.keystone.v3.internal.BaseV3KeystoneApiMockTest; import org.testng.annotations.Test; -import com.squareup.okhttp.mockwebserver.RecordedRequest; @Test(groups = "unit", testName = "AuthApiMockTest", singleThreaded = true) public class AuthApiMockTest extends BaseV3KeystoneApiMockTest { diff --git a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v3/features/ProjectApiMockTest.java b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v3/features/ProjectApiMockTest.java index b8a45425b2..a585936733 100644 --- a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v3/features/ProjectApiMockTest.java +++ b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v3/features/ProjectApiMockTest.java @@ -25,12 +25,14 @@ import static org.testng.Assert.assertTrue; import java.util.List; import java.util.Set; +import okhttp3.mockwebserver.MockResponse; + import org.jclouds.openstack.keystone.v3.domain.Project; import org.jclouds.openstack.keystone.v3.internal.BaseV3KeystoneApiMockTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; -import com.squareup.okhttp.mockwebserver.MockResponse; + @Test(groups = "unit", testName = "ProjectApiMockTest", singleThreaded = true) public class ProjectApiMockTest extends BaseV3KeystoneApiMockTest { diff --git a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v3/internal/BaseV3KeystoneApiMockTest.java b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v3/internal/BaseV3KeystoneApiMockTest.java index ec3f7ba509..ac023fad6f 100644 --- a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v3/internal/BaseV3KeystoneApiMockTest.java +++ b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/keystone/v3/internal/BaseV3KeystoneApiMockTest.java @@ -27,6 +27,10 @@ import java.util.Properties; import java.util.Set; import java.util.UUID; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.ContextBuilder; import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.http.okhttp.config.OkHttpCommandExecutorServiceModule; @@ -48,9 +52,7 @@ import com.google.common.io.Resources; import com.google.common.reflect.TypeToken; import com.google.gson.JsonParser; import com.google.inject.Module; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; + public class BaseV3KeystoneApiMockTest { @@ -68,7 +70,7 @@ public class BaseV3KeystoneApiMockTest { @BeforeMethod public void start() throws IOException { server = new MockWebServer(); - server.play(); + server.start(); ApiContext ctx = ContextBuilder.newBuilder("openstack-keystone-3") .credentials("domain:identity", "credential") @@ -103,7 +105,7 @@ public class BaseV3KeystoneApiMockTest { } protected String url(String path) { - return server.getUrl(path).toString(); + return server.url(path).toString(); } protected void enqueueAuthentication(MockWebServer server) { @@ -178,7 +180,7 @@ public class BaseV3KeystoneApiMockTest { private void assertBody(RecordedRequest request, String body) { assertEquals(request.getHeader("Content-Type"), "application/json"); - assertEquals(parser.parse(new String(request.getBody(), Charsets.UTF_8)), parser.parse(body)); + assertEquals(parser.parse(request.getBody().readUtf8()), parser.parse(body)); } protected Token tokenFromResource(String resource) { diff --git a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/v2_0/internal/BaseOpenStackMockTest.java b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/v2_0/internal/BaseOpenStackMockTest.java index a67a038193..cce52387e6 100644 --- a/apis/openstack-keystone/src/test/java/org/jclouds/openstack/v2_0/internal/BaseOpenStackMockTest.java +++ b/apis/openstack-keystone/src/test/java/org/jclouds/openstack/v2_0/internal/BaseOpenStackMockTest.java @@ -30,11 +30,16 @@ import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; import java.util.regex.Pattern; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.QueueDispatcher; +import okhttp3.mockwebserver.RecordedRequest; +import okhttp3.mockwebserver.SocketPolicy; + import org.jclouds.ContextBuilder; import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.util.Strings2; -import com.google.common.base.Charsets; import com.google.common.base.Throwables; import com.google.common.collect.ImmutableSet; import com.google.common.net.HttpHeaders; @@ -43,10 +48,7 @@ import com.google.common.reflect.TypeToken; import com.google.gson.JsonElement; import com.google.gson.JsonParser; import com.google.inject.Module; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.QueueDispatcher; -import com.squareup.okhttp.mockwebserver.RecordedRequest; + public class BaseOpenStackMockTest { @@ -85,9 +87,9 @@ public class BaseOpenStackMockTest { public static MockWebServer mockOpenStackServer() throws IOException { MockWebServer server = new MockWebServer(); - server.play(); - URL url = server.getUrl(""); - server.setDispatcher(getURLReplacingQueueDispatcher(url)); + server.start(); + URL url = server.url("").url(); + server.setDispatcher(getURLReplacingQueueDispatcher(url.toString())); return server; } @@ -95,7 +97,9 @@ public class BaseOpenStackMockTest { * there's no built-in way to defer evaluation of a response header, hence * this method, which allows us to send back links to the mock server. */ - public static QueueDispatcher getURLReplacingQueueDispatcher(final URL url) { + public static QueueDispatcher getURLReplacingQueueDispatcher(final String url) { + final String strippedUrl = url.endsWith("/") ? url.substring(0, url.length() - 1) : url; + final QueueDispatcher dispatcher = new QueueDispatcher() { protected final BlockingQueue responseQueue = new LinkedBlockingQueue(); @@ -108,7 +112,7 @@ public class BaseOpenStackMockTest { * access.json or accessRackspace.json) for the declared service * endpoints. */ - String newBody = urlTokenPattern.matcher(new String(response.getBody().readByteArray())).replaceAll(": \"" + url.toString()); + String newBody = urlTokenPattern.matcher(new String(response.getBody().readByteArray())).replaceAll(": \"" + strippedUrl); response = response.setBody(newBody); } @@ -119,6 +123,11 @@ public class BaseOpenStackMockTest { public void enqueueResponse(MockResponse response) { responseQueue.add(response); } + + @Override + public MockResponse peek() { + return super.peek().setSocketPolicy(SocketPolicy.EXPECT_CONTINUE); + } }; return dispatcher; @@ -187,7 +196,7 @@ public class BaseOpenStackMockTest { * @see RecordedRequest */ private void assertContentTypeIsJSON(RecordedRequest request) { - assertTrue(request.getHeaders().contains("Content-Type: application/json")); + assertTrue(request.getHeaders().values("Content-Type").contains("application/json")); } /** @@ -224,7 +233,7 @@ public class BaseOpenStackMockTest { JsonElement requestJson = null; // to be compared JsonElement resourceJson; // to be compared try { - requestJson = parser.parse(new String(request.getBody(), Charsets.UTF_8)); + requestJson = parser.parse(request.getBody().readUtf8()); } catch (Exception e) { Throwables.propagate(e); } diff --git a/apis/openstack-neutron/pom.xml b/apis/openstack-neutron/pom.xml index e81c7d1cc6..3416ea6a3d 100644 --- a/apis/openstack-neutron/pom.xml +++ b/apis/openstack-neutron/pom.xml @@ -78,7 +78,7 @@ test - com.squareup.okhttp + com.squareup.okhttp3 mockwebserver test diff --git a/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/extensions/FWaaSApiMockTest.java b/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/extensions/FWaaSApiMockTest.java index 595b22fdff..e61504fdff 100644 --- a/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/extensions/FWaaSApiMockTest.java +++ b/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/extensions/FWaaSApiMockTest.java @@ -25,6 +25,9 @@ import java.io.IOException; import java.net.URISyntaxException; import java.util.List; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.openstack.neutron.v2.NeutronApi; import org.jclouds.openstack.neutron.v2.domain.CreateFirewall; import org.jclouds.openstack.neutron.v2.domain.CreateFirewallPolicy; @@ -44,8 +47,6 @@ import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; /** * Tests Floating Api Guice wiring and parsing @@ -62,7 +63,7 @@ public class FWaaSApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201).setBody(stringFromResource("/firewall_create_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); FWaaSApi api = neutronApi.getFWaaSApi("RegionOne").get(); CreateFirewall firewallRequest = CreateFirewall.builder() @@ -103,7 +104,7 @@ public class FWaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/firewall_list_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); FWaaSApi api = neutronApi.getFWaaSApi("RegionOne").get(); PaginatedCollection firewalls = api.list(PaginationOptions.Builder.limit(2).marker("abcdefg")); @@ -135,7 +136,7 @@ public class FWaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/floatingip_list_response_paged2.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); FloatingIPApi api = neutronApi.getFloatingIPApi("RegionOne"); // Note: Lazy! Have to actually look at the collection. @@ -169,7 +170,7 @@ public class FWaaSApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201).setBody(stringFromResource("/firewall_get_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); FWaaSApi api = neutronApi.getFWaaSApi("RegionOne").get(); Firewall firewall = api.get("12345"); @@ -206,7 +207,7 @@ public class FWaaSApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201).setBody(stringFromResource("/firewall_update_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); FWaaSApi api = neutronApi.getFWaaSApi("RegionOne").get(); UpdateFirewall updateFirewall = UpdateFirewall.builder() @@ -242,7 +243,7 @@ public class FWaaSApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); FWaaSApi api = neutronApi.getFWaaSApi("RegionOne").get(); boolean result = api.delete("12345"); @@ -272,7 +273,7 @@ public class FWaaSApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201).setBody(stringFromResource("/firewall_policy_create_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); FWaaSApi api = neutronApi.getFWaaSApi("RegionOne").get(); CreateFirewallPolicy firewallPolicyRequest = CreateFirewallPolicy.builder() @@ -313,7 +314,7 @@ public class FWaaSApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201).setBody(stringFromResource("/firewall_policy_get_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); FWaaSApi api = neutronApi.getFWaaSApi("RegionOne").get(); FirewallPolicy firewallPolicy = api.getFirewallPolicy("12345"); @@ -350,7 +351,7 @@ public class FWaaSApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201).setBody(stringFromResource("/firewall_policy_get_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); FWaaSApi api = neutronApi.getFWaaSApi("RegionOne").get(); UpdateFirewallPolicy updateFirewallPolicy = UpdateFirewallPolicy.builder() @@ -391,7 +392,7 @@ public class FWaaSApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201).setBody(stringFromResource("/firewall_policy_insert_rule_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); FWaaSApi api = neutronApi.getFWaaSApi("RegionOne").get(); FirewallPolicy updatedFirewallPolicy = api.insertFirewallRuleToPolicy("12345", "59585143-e819-48c9-944d-f03e0f049dba"); @@ -422,7 +423,7 @@ public class FWaaSApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201).setBody(stringFromResource("/firewall_rule_create_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); FWaaSApi api = neutronApi.getFWaaSApi("RegionOne").get(); CreateFirewallRule firewallRuleRequest = CreateFirewallRule.builder() @@ -469,7 +470,7 @@ public class FWaaSApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201).setBody(stringFromResource("/firewall_rule_get_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); FWaaSApi api = neutronApi.getFWaaSApi("RegionOne").get(); FirewallRule firewallRule = api.getFirewallRule("12345"); @@ -508,7 +509,7 @@ public class FWaaSApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201).setBody(stringFromResource("/firewall_rule_update_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); FWaaSApi api = neutronApi.getFWaaSApi("RegionOne").get(); UpdateFirewallRule updateFirewallRule = UpdateFirewallRule.builder() @@ -542,7 +543,7 @@ public class FWaaSApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); FWaaSApi api = neutronApi.getFWaaSApi("RegionOne").get(); boolean result = api.deleteFirewallRule("12345"); diff --git a/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/extensions/RouterApiMockTest.java b/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/extensions/RouterApiMockTest.java index 16859f4cc2..3dbb0a4573 100644 --- a/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/extensions/RouterApiMockTest.java +++ b/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/extensions/RouterApiMockTest.java @@ -24,6 +24,9 @@ import java.io.IOException; import java.net.URISyntaxException; import java.util.List; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.openstack.neutron.v2.NeutronApi; import org.jclouds.openstack.neutron.v2.domain.ExternalGatewayInfo; import org.jclouds.openstack.neutron.v2.domain.NetworkStatus; @@ -34,8 +37,6 @@ import org.jclouds.openstack.neutron.v2.internal.BaseNeutronApiMockTest; import org.jclouds.openstack.v2_0.options.PaginationOptions; import org.testng.annotations.Test; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; /** * Tests NetworkApi Guice wiring and parsing @@ -52,7 +53,7 @@ public class RouterApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201).setBody(stringFromResource("/router_create_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); RouterApi api = neutronApi.getRouterApi("RegionOne").get(); Router.CreateRouter createRouter = Router.createBuilder().name("another_router").adminStateUp(Boolean.TRUE) @@ -95,7 +96,7 @@ public class RouterApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/router_list_response_paged1.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); RouterApi api = neutronApi.getRouterApi("RegionOne").get(); Routers routers = api.list(PaginationOptions.Builder.limit(2).marker("abcdefg")); @@ -127,7 +128,7 @@ public class RouterApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/router_list_response_paged2.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); RouterApi api = neutronApi.getRouterApi("RegionOne").get(); // Note: Lazy! Have to actually look at the collection. @@ -162,7 +163,7 @@ public class RouterApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201).setBody(stringFromResource("/router_get_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); RouterApi api = neutronApi.getRouterApi("RegionOne").get(); Router router = api.get("12345"); @@ -198,7 +199,7 @@ public class RouterApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201).setBody(stringFromResource("/router_update_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); RouterApi api = neutronApi.getRouterApi("RegionOne").get(); Router.UpdateRouter updateRouter = Router.updateBuilder() @@ -239,7 +240,7 @@ public class RouterApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); RouterApi api = neutronApi.getRouterApi("RegionOne").get(); boolean result = api.delete("12345"); @@ -269,7 +270,7 @@ public class RouterApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201).setBody(stringFromResource("/router_add_interface_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); RouterApi api = neutronApi.getRouterApi("RegionOne").get(); RouterInterface routerInterface = api.addInterfaceForSubnet("12345", "a2f1f29d-571b-4533-907f-5803ab96ead1"); @@ -300,7 +301,7 @@ public class RouterApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201).setBody(stringFromResource("/router_add_interface_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); RouterApi api = neutronApi.getRouterApi("RegionOne").get(); RouterInterface routerInterface = api.addInterfaceForPort("12345", "portid"); @@ -332,7 +333,7 @@ public class RouterApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); RouterApi api = neutronApi.getRouterApi("RegionOne").get(); boolean result = api.removeInterfaceForSubnet("12345", "a2f1f29d-571b-4533-907f-5803ab96ead1"); @@ -362,7 +363,7 @@ public class RouterApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); RouterApi api = neutronApi.getRouterApi("RegionOne").get(); boolean result = api.removeInterfaceForPort("12345", "portid"); diff --git a/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/extensions/lbaas/v1/LBaaSApiMockTest.java b/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/extensions/lbaas/v1/LBaaSApiMockTest.java index ce5dc66d45..e500e47720 100644 --- a/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/extensions/lbaas/v1/LBaaSApiMockTest.java +++ b/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/extensions/lbaas/v1/LBaaSApiMockTest.java @@ -24,6 +24,9 @@ import static org.testng.Assert.assertTrue; import java.io.IOException; import java.util.List; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.openstack.neutron.v2.NeutronApi; import org.jclouds.openstack.neutron.v2.domain.lbaas.v1.HealthMonitor; import org.jclouds.openstack.neutron.v2.domain.lbaas.v1.HealthMonitors; @@ -44,8 +47,7 @@ import org.testng.annotations.Test; import com.google.common.base.Optional; import com.google.common.collect.ImmutableSet; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; + @Test public class LBaaSApiMockTest extends BaseNeutronApiMockTest { @@ -56,7 +58,7 @@ public class LBaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/extension_list_with_lbaas_v1_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); Optional lbaasApiExtension = neutronApi.getLBaaSApi("RegionOne"); assertAuthentication(server); @@ -77,7 +79,7 @@ public class LBaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/extension_list_without_lbaas_v1_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); Optional lbaasApiExtension = neutronApi.getLBaaSApi("RegionOne"); assertAuthentication(server); @@ -99,7 +101,7 @@ public class LBaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201).setBody(stringFromResource("/lbaas/v1/pool_create_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); LBaaSApi lbaasApi = neutronApi.getLBaaSApi("RegionOne").get(); Pool.CreatePool createPool = Pool.createBuilder("8032909d-47a1-4715-90af-5153ffe39861", Protocol.TCP, Pool.ROUND_ROBIN) @@ -148,7 +150,7 @@ public class LBaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201).setBody(stringFromResource("/lbaas/v1/pool_list_response_paged1.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); LBaaSApi lbaasApi = neutronApi.getLBaaSApi("RegionOne").get(); Pools pools = lbaasApi.listPools(PaginationOptions.Builder.limit(2).marker("abcdefg")); @@ -179,7 +181,7 @@ public class LBaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/lbaas/v1/pool_list_response_paged2.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); LBaaSApi lbaasApi = neutronApi.getLBaaSApi("RegionOne").get(); // Note: Lazy! Have to actually look at the collection. @@ -213,7 +215,7 @@ public class LBaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201).setBody(stringFromResource("/lbaas/v1/pool_get_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); LBaaSApi lbaasApi = neutronApi.getLBaaSApi("RegionOne").get(); Pool pool = lbaasApi.getPool("72741b06-df4d-4715-b142-276b6bce75ab"); @@ -259,7 +261,7 @@ public class LBaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201).setBody(stringFromResource("/lbaas/v1/pool_update_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); LBaaSApi lbaasApi = neutronApi.getLBaaSApi("RegionOne").get(); Pool.UpdatePool updatePool = Pool.updateBuilder().name("new_name").description("new description").lbMethod("NEW_LB_METHOD") @@ -310,7 +312,7 @@ public class LBaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(204))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); LBaaSApi lbaasApi = neutronApi.getLBaaSApi("RegionOne").get(); boolean result = lbaasApi.deletePool("72741b06-df4d-4715-b142-276b6bce75ab"); @@ -338,7 +340,7 @@ public class LBaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201).setBody(stringFromResource("/lbaas/v1/member_create_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); LBaaSApi lbaasApi = neutronApi.getLBaaSApi("RegionOne").get(); Member.CreateMember createMember = Member.createBuilder("72741b06-df4d-4715-b142-276b6bce75ab", null, 80) @@ -378,7 +380,7 @@ public class LBaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201).setBody(stringFromResource("/lbaas/v1/member_list_response_paged1.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); LBaaSApi lbaasApi = neutronApi.getLBaaSApi("RegionOne").get(); Members members = lbaasApi.listMembers(PaginationOptions.Builder.limit(2).marker("abcdefg")); @@ -409,7 +411,7 @@ public class LBaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/lbaas/v1/member_list_response_paged2.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); LBaaSApi lbaasApi = neutronApi.getLBaaSApi("RegionOne").get(); // Note: Lazy! Have to actually look at the collection. @@ -443,7 +445,7 @@ public class LBaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201).setBody(stringFromResource("/lbaas/v1/member_get_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); LBaaSApi lbaasApi = neutronApi.getLBaaSApi("RegionOne").get(); Member member = lbaasApi.getMember("48a471ea-64f1-4eb6-9be7-dae6bbe40a0f"); @@ -480,7 +482,7 @@ public class LBaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201).setBody(stringFromResource("/lbaas/v1/member_update_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); LBaaSApi lbaasApi = neutronApi.getLBaaSApi("RegionOne").get(); Member.UpdateMember updateMember = Member.updateBuilder().poolId("new_pool_id").weight(2) @@ -520,7 +522,7 @@ public class LBaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(204))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); LBaaSApi lbaasApi = neutronApi.getLBaaSApi("RegionOne").get(); boolean result = lbaasApi.deleteMember("48a471ea-64f1-4eb6-9be7-dae6bbe40a0f"); @@ -548,7 +550,7 @@ public class LBaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201).setBody(stringFromResource("/lbaas/v1/vip_create_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); LBaaSApi lbaasApi = neutronApi.getLBaaSApi("RegionOne").get(); VIP.CreateVIP createVIP = VIP.createBuilder("8032909d-47a1-4715-90af-5153ffe39861", Protocol.HTTP, 80, "61b1f87a-7a21-4ad3-9dda-7f81d249944f") @@ -594,7 +596,7 @@ public class LBaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201).setBody(stringFromResource("/lbaas/v1/vip_list_response_paged1.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); LBaaSApi lbaasApi = neutronApi.getLBaaSApi("RegionOne").get(); VIPs vips = lbaasApi.listVIPs(PaginationOptions.Builder.limit(2).marker("abcdefg")); @@ -625,7 +627,7 @@ public class LBaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/lbaas/v1/vip_list_response_paged2.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); LBaaSApi lbaasApi = neutronApi.getLBaaSApi("RegionOne").get(); // Note: Lazy! Have to actually look at the collection. @@ -659,7 +661,7 @@ public class LBaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201).setBody(stringFromResource("/lbaas/v1/vip_get_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); LBaaSApi lbaasApi = neutronApi.getLBaaSApi("RegionOne").get(); VIP vip = lbaasApi.getVIP("4ec89087-d057-4e2c-911f-60a3b47ee304"); @@ -703,7 +705,7 @@ public class LBaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201).setBody(stringFromResource("/lbaas/v1/vip_update_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); LBaaSApi lbaasApi = neutronApi.getLBaaSApi("RegionOne").get(); SessionPersistence sessionPersistence = SessionPersistence.builder().type(SessionPersistence.Type.APP_COOKIE).cookieName("MyNewAppCookie").build(); @@ -750,7 +752,7 @@ public class LBaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(204))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); LBaaSApi lbaasApi = neutronApi.getLBaaSApi("RegionOne").get(); boolean result = lbaasApi.deleteVIP("c987d2be-9a3c-4ac9-a046-e8716b1350e2"); @@ -778,7 +780,7 @@ public class LBaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201).setBody(stringFromResource("/lbaas/v1/health_monitor_create_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); LBaaSApi lbaasApi = neutronApi.getLBaaSApi("RegionOne").get(); HealthMonitor.CreateHealthMonitor createHealthMonitor = HealthMonitor.createBuilder(ProbeType.HTTP, Integer.valueOf(1), Integer.valueOf(1), Integer.valueOf(1)) @@ -823,7 +825,7 @@ public class LBaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201).setBody(stringFromResource("/lbaas/v1/health_monitor_list_response_paged1.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); LBaaSApi lbaasApi = neutronApi.getLBaaSApi("RegionOne").get(); HealthMonitors healthMonitors = lbaasApi.listHealthMonitors(PaginationOptions.Builder.limit(2).marker("abcdefg")); @@ -854,7 +856,7 @@ public class LBaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/lbaas/v1/health_monitor_list_response_paged2.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); LBaaSApi lbaasApi = neutronApi.getLBaaSApi("RegionOne").get(); // Note: Lazy! Have to actually look at the collection. @@ -888,7 +890,7 @@ public class LBaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201).setBody(stringFromResource("/lbaas/v1/health_monitor_get_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); LBaaSApi lbaasApi = neutronApi.getLBaaSApi("RegionOne").get(); HealthMonitor healthMonitor = lbaasApi.getHealthMonitor("5d4b5228-33b0-4e60-b225-9b727c1a20e7"); @@ -930,7 +932,7 @@ public class LBaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201).setBody(stringFromResource("/lbaas/v1/health_monitor_update_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); LBaaSApi lbaasApi = neutronApi.getLBaaSApi("RegionOne").get(); HealthMonitor.UpdateHealthMonitor updateHealthMonitor = HealthMonitor.updateBuilder().delay(Integer.valueOf(1)).timeout(Integer.valueOf(1)).maxRetries(Integer.valueOf(1)) @@ -975,7 +977,7 @@ public class LBaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(204))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); LBaaSApi lbaasApi = neutronApi.getLBaaSApi("RegionOne").get(); boolean result = lbaasApi.deleteHealthMonitor("466c8345-28d8-4f84-a246-e04380b0461d"); @@ -1003,7 +1005,7 @@ public class LBaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201).setBody(stringFromResource("/lbaas/v1/pool_associate_health_monitor_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); LBaaSApi lbaasApi = neutronApi.getLBaaSApi("RegionOne").get(); HealthMonitor healthMonitor = lbaasApi.associateHealthMonitor("72741b06-df4d-4715-b142-276b6bce75ab", "5d4b5228-33b0-4e60-b225-9b727c1a20e7"); @@ -1031,7 +1033,7 @@ public class LBaaSApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(204))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); LBaaSApi lbaasApi = neutronApi.getLBaaSApi("RegionOne").get(); boolean result = lbaasApi.disassociateHealthMonitor("72741b06-df4d-4715-b142-276b6bce75ab", "5d4b5228-33b0-4e60-b225-9b727c1a20e7"); diff --git a/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/features/ExtensionApiMockTest.java b/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/features/ExtensionApiMockTest.java index a92988177b..a8695e0335 100644 --- a/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/features/ExtensionApiMockTest.java +++ b/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/features/ExtensionApiMockTest.java @@ -21,14 +21,15 @@ import static org.testng.Assert.assertNotNull; import java.util.Set; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.openstack.neutron.v2.NeutronApi; import org.jclouds.openstack.neutron.v2.internal.BaseNeutronApiMockTest; import org.jclouds.openstack.v2_0.domain.Extension; import org.jclouds.openstack.v2_0.features.ExtensionApi; import org.testng.annotations.Test; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; /** * Tests annotation parsing of {@code ExtensionApi} @@ -43,7 +44,7 @@ public class ExtensionApiMockTest extends BaseNeutronApiMockTest { .setResponseCode(200).setBody(stringFromResource("/extension_list.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); ExtensionApi api = neutronApi.getExtensionApi("RegionOne"); Set extensions = api.list(); @@ -72,7 +73,7 @@ public class ExtensionApiMockTest extends BaseNeutronApiMockTest { .setResponseCode(200).setBody(stringFromResource("/extension_details.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); Extension routerExtension = neutronApi.getExtensionApi("RegionOne").get("router"); diff --git a/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/features/FloatingIPApiMockTest.java b/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/features/FloatingIPApiMockTest.java index b34d8ab7cf..c83ee6f57e 100644 --- a/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/features/FloatingIPApiMockTest.java +++ b/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/features/FloatingIPApiMockTest.java @@ -25,6 +25,9 @@ import java.io.IOException; import java.net.URISyntaxException; import java.util.List; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.openstack.neutron.v2.NeutronApi; import org.jclouds.openstack.neutron.v2.domain.FloatingIP; import org.jclouds.openstack.neutron.v2.domain.FloatingIPs; @@ -32,8 +35,6 @@ import org.jclouds.openstack.neutron.v2.internal.BaseNeutronApiMockTest; import org.jclouds.openstack.v2_0.options.PaginationOptions; import org.testng.annotations.Test; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; /** * Tests Floating Api Guice wiring and parsing @@ -49,7 +50,7 @@ public class FloatingIPApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201).setBody(stringFromResource("/floatingip_create_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); FloatingIPApi api = neutronApi.getFloatingIPApi("RegionOne"); FloatingIP.CreateFloatingIP createFip = FloatingIP.createBuilder("376da547-b977-4cfe-9cba-275c80debf57") @@ -88,7 +89,7 @@ public class FloatingIPApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/floatingip_list_response_paged1.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); FloatingIPApi api = neutronApi.getFloatingIPApi("RegionOne"); FloatingIPs floatingIPs = api.list(PaginationOptions.Builder.limit(2).marker("abcdefg")); @@ -119,7 +120,7 @@ public class FloatingIPApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/floatingip_list_response_paged2.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); FloatingIPApi api = neutronApi.getFloatingIPApi("RegionOne"); // Note: Lazy! Have to actually look at the collection. @@ -152,7 +153,7 @@ public class FloatingIPApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201).setBody(stringFromResource("/floatingip_get_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); FloatingIPApi api = neutronApi.getFloatingIPApi("RegionOne"); FloatingIP floatingIP = api.get("12345"); @@ -188,7 +189,7 @@ public class FloatingIPApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201).setBody(stringFromResource("/floatingip_update_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); FloatingIPApi api = neutronApi.getFloatingIPApi("RegionOne"); FloatingIP.UpdateFloatingIP updateFloatingIP = FloatingIP.updateBuilder() @@ -222,7 +223,7 @@ public class FloatingIPApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201).setBody(stringFromResource("/floatingip_update_dissociate_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); FloatingIPApi api = neutronApi.getFloatingIPApi("RegionOne"); FloatingIP.UpdateFloatingIP updateFloatingIP = FloatingIP.updateBuilder().build(); @@ -254,7 +255,7 @@ public class FloatingIPApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); FloatingIPApi api = neutronApi.getFloatingIPApi("RegionOne"); boolean result = api.delete("12345"); diff --git a/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/features/NetworkApiMockTest.java b/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/features/NetworkApiMockTest.java index 95e3f4c6bc..1c95a97fc3 100644 --- a/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/features/NetworkApiMockTest.java +++ b/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/features/NetworkApiMockTest.java @@ -18,8 +18,9 @@ package org.jclouds.openstack.neutron.v2.features; import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableList; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; + +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; import org.jclouds.openstack.neutron.v2.NeutronApi; import org.jclouds.openstack.neutron.v2.domain.Network; @@ -51,7 +52,7 @@ public class NetworkApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201).setBody(stringFromResource("/network_create_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); NetworkApi api = neutronApi.getNetworkApi("RegionOne"); Network.CreateNetwork createNetwork = Network.createBuilder("jclouds-wibble") @@ -86,7 +87,7 @@ public class NetworkApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/network_list_response_paged1.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); NetworkApi api = neutronApi.getNetworkApi("RegionOne"); Networks networks = api.list(PaginationOptions.Builder.limit(2).marker("abcdefg")); @@ -114,7 +115,7 @@ public class NetworkApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(404).setBody(stringFromResource("/network_list_response_paged1.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); NetworkApi api = neutronApi.getNetworkApi("RegionOne"); Networks networks = api.list(PaginationOptions.Builder.limit(2).marker("abcdefg")); @@ -141,7 +142,7 @@ public class NetworkApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/network_list_response_paged2.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); NetworkApi api = neutronApi.getNetworkApi("RegionOne"); // Note: Lazy! Have to actually look at the collection. @@ -175,7 +176,7 @@ public class NetworkApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/network_get_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); NetworkApi api = neutronApi.getNetworkApi("RegionOne"); Network network = api.get("12345"); @@ -204,7 +205,7 @@ public class NetworkApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201).setBody(stringFromResource("/network_bulk_create_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); NetworkApi api = neutronApi.getNetworkApi("RegionOne"); Network.CreateNetwork createNetwork1 = Network.createBuilder("jclouds-wibble") @@ -250,7 +251,7 @@ public class NetworkApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201).setBody(stringFromResource("/network_update_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); NetworkApi api = neutronApi.getNetworkApi("RegionOne"); Network.UpdateNetwork updateNetwork = Network.updateBuilder() @@ -283,7 +284,7 @@ public class NetworkApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); NetworkApi api = neutronApi.getNetworkApi("RegionOne"); boolean result = api.delete("123456"); diff --git a/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/features/PortApiMockTest.java b/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/features/PortApiMockTest.java index a8932c7c48..6991555f7a 100644 --- a/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/features/PortApiMockTest.java +++ b/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/features/PortApiMockTest.java @@ -25,6 +25,9 @@ import java.net.URISyntaxException; import java.util.List; import java.util.Map; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.openstack.neutron.v2.NeutronApi; import org.jclouds.openstack.neutron.v2.domain.AddressPair; import org.jclouds.openstack.neutron.v2.domain.NetworkStatus; @@ -39,8 +42,7 @@ import org.testng.annotations.Test; import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; + /** * Tests NetworkApi Guice wiring and parsing @@ -56,7 +58,7 @@ public class PortApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201).setBody(stringFromResource("/port_create_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); PortApi api = neutronApi.getPortApi("RegionOne"); Port.CreatePort createPort = Port.createBuilder("6aeaf34a-c482-4bd3-9dc3-7faf36412f12") @@ -101,7 +103,7 @@ public class PortApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/port_list_response_paged1.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); PortApi api = neutronApi.getPortApi("RegionOne"); Ports ports = api.list(PaginationOptions.Builder.limit(2).marker("abcdefg")); @@ -130,7 +132,7 @@ public class PortApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/port_list_response_paged2.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); PortApi api = neutronApi.getPortApi("RegionOne"); // Note: Lazy! Have to actually look at the collection. @@ -163,7 +165,7 @@ public class PortApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201).setBody(stringFromResource("/port_create_bulk_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); PortApi api = neutronApi.getPortApi("RegionOne"); Port.CreatePort createPort1 = Port.createBuilder("64239a54-dcc4-4b39-920b-b37c2144effa") @@ -207,7 +209,7 @@ public class PortApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201).setBody(stringFromResource("/port_get_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); PortApi api = neutronApi.getPortApi("RegionOne"); Port port = api.get("12345"); @@ -243,7 +245,7 @@ public class PortApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201).setBody(stringFromResource("/port_update_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); PortApi api = neutronApi.getPortApi("RegionOne"); Port.UpdatePort updatePort = Port.updateBuilder() @@ -275,7 +277,7 @@ public class PortApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); PortApi api = neutronApi.getPortApi("RegionOne"); boolean result = api.delete("12345"); diff --git a/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/features/SecurityGroupApiMockTest.java b/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/features/SecurityGroupApiMockTest.java index 39bb8c59d3..69ccda6531 100644 --- a/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/features/SecurityGroupApiMockTest.java +++ b/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/features/SecurityGroupApiMockTest.java @@ -25,6 +25,9 @@ import java.io.IOException; import java.net.URISyntaxException; import java.util.List; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.openstack.neutron.v2.NeutronApi; import org.jclouds.openstack.neutron.v2.domain.Rule; import org.jclouds.openstack.neutron.v2.domain.RuleDirection; @@ -37,8 +40,6 @@ import org.jclouds.openstack.neutron.v2.internal.BaseNeutronApiMockTest; import org.jclouds.openstack.v2_0.options.PaginationOptions; import org.testng.annotations.Test; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; /** * Tests SecurityGroupApi Guice wiring and parsing @@ -54,7 +55,7 @@ public class SecurityGroupApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201).setBody(stringFromResource("/security_group_create_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); SecurityGroupApi api = neutronApi.getSecurityGroupApi("RegionOne"); SecurityGroup.CreateSecurityGroup createSecurityGroup = SecurityGroup.createBuilder().name("new-webservers") @@ -96,7 +97,7 @@ public class SecurityGroupApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201).setBody(stringFromResource("/security_group_rule_create_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); SecurityGroupApi api = neutronApi.getSecurityGroupApi("RegionOne"); Rule.CreateRule createSecurityGroupRule = Rule.createBuilder( @@ -142,7 +143,7 @@ public class SecurityGroupApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/security_group_list_response_paged1.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); SecurityGroupApi api = neutronApi.getSecurityGroupApi("RegionOne"); SecurityGroups securityGroups = api.listSecurityGroups(PaginationOptions.Builder.limit(2).marker("abcdefg")); @@ -173,7 +174,7 @@ public class SecurityGroupApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/security_group_rule_list_response_paged1.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); SecurityGroupApi api = neutronApi.getSecurityGroupApi("RegionOne"); Rules rules = api.listRules(PaginationOptions.Builder.limit(2).marker("abcdefg")); @@ -205,7 +206,7 @@ public class SecurityGroupApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/security_group_list_response_paged2.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); SecurityGroupApi api = neutronApi.getSecurityGroupApi("RegionOne"); // Note: Lazy! Have to actually look at the collection. @@ -240,7 +241,7 @@ public class SecurityGroupApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/security_group_rule_list_response_paged2.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); SecurityGroupApi api = neutronApi.getSecurityGroupApi("RegionOne"); // Note: Lazy! Have to actually look at the collection. @@ -275,7 +276,7 @@ public class SecurityGroupApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201).setBody(stringFromResource("/security_group_get_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); SecurityGroupApi api = neutronApi.getSecurityGroupApi("RegionOne"); SecurityGroup securityGroup = api.getSecurityGroup("12345"); @@ -309,7 +310,7 @@ public class SecurityGroupApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201).setBody(stringFromResource("/security_group_rule_get_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); SecurityGroupApi api = neutronApi.getSecurityGroupApi("RegionOne"); Rule rule = api.get("12345"); @@ -343,7 +344,7 @@ public class SecurityGroupApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); SecurityGroupApi api = neutronApi.getSecurityGroupApi("RegionOne"); boolean result = api.deleteSecurityGroup("12345"); @@ -371,7 +372,7 @@ public class SecurityGroupApiMockTest extends BaseNeutronApiMockTest { new MockResponse().setResponseCode(201))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); SecurityGroupApi api = neutronApi.getSecurityGroupApi("RegionOne"); boolean result = api.deleteRule("12345"); diff --git a/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/features/SubnetApiMockTest.java b/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/features/SubnetApiMockTest.java index 036bad783c..54da407ec6 100644 --- a/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/features/SubnetApiMockTest.java +++ b/apis/openstack-neutron/src/test/java/org/jclouds/openstack/neutron/v2/features/SubnetApiMockTest.java @@ -24,6 +24,9 @@ import java.io.IOException; import java.net.URISyntaxException; import java.util.List; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.openstack.neutron.v2.NeutronApi; import org.jclouds.openstack.neutron.v2.domain.IPv6DHCPMode; import org.jclouds.openstack.neutron.v2.domain.Subnet; @@ -34,8 +37,7 @@ import org.testng.annotations.Test; import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableList; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; + /** * Tests NetworkApi Guice wiring and parsing @@ -50,7 +52,7 @@ public class SubnetApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201).setBody(stringFromResource("/subnet_create_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); SubnetApi api = neutronApi.getSubnetApi("RegionOne"); Subnet.CreateSubnet createSubnet = Subnet.createBuilder("1234567890", "10.0.3.0/24") @@ -86,7 +88,7 @@ public class SubnetApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/subnet_list_response_pages1.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); SubnetApi api = neutronApi.getSubnetApi("RegionOne"); Subnets subnets = api.list(PaginationOptions.Builder.limit(2).marker("abcdefg")); @@ -114,7 +116,7 @@ public class SubnetApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/subnet_list_response_pages2.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); SubnetApi api = neutronApi.getSubnetApi("RegionOne"); // Note: Lazy! Have to actually look at the collection. @@ -146,7 +148,7 @@ public class SubnetApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/subnet_get_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); SubnetApi api = neutronApi.getSubnetApi("RegionOne"); Subnet subnet = api.get("12345"); @@ -177,7 +179,7 @@ public class SubnetApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201).setBody(stringFromResource("/subnet_bulk_create_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); SubnetApi api = neutronApi.getSubnetApi("RegionOne"); Subnet.CreateSubnet createSubnet1 = Subnet.createBuilder("e6031bc2-901a-4c66-82da-f4c32ed89406", @@ -225,7 +227,7 @@ public class SubnetApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200).setBody(stringFromResource("/subnet_update_response.json")))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); SubnetApi api = neutronApi.getSubnetApi("RegionOne"); Subnet.UpdateSubnet updateSubnet = Subnet.updateBuilder() @@ -260,7 +262,7 @@ public class SubnetApiMockTest extends BaseNeutronApiMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(200))); try { - NeutronApi neutronApi = api(server.getUrl("/").toString(), "openstack-neutron", overrides); + NeutronApi neutronApi = api(server.url("/").toString(), "openstack-neutron", overrides); SubnetApi api = neutronApi.getSubnetApi("RegionOne"); boolean result = api.delete("12345"); diff --git a/apis/openstack-nova/pom.xml b/apis/openstack-nova/pom.xml index a78b57699b..bdc7b3b4e0 100644 --- a/apis/openstack-nova/pom.xml +++ b/apis/openstack-nova/pom.xml @@ -104,7 +104,7 @@ test - com.squareup.okhttp + com.squareup.okhttp3 mockwebserver test diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/ConsolesApiMockTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/ConsolesApiMockTest.java index 838ebfe08d..21f21fafd2 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/ConsolesApiMockTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/ConsolesApiMockTest.java @@ -20,6 +20,9 @@ import static com.google.common.collect.Iterables.getFirst; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.openstack.nova.v2_0.NovaApi; import org.jclouds.openstack.nova.v2_0.domain.Console; import org.jclouds.openstack.nova.v2_0.parse.ParseNOVNCConsoleTest; @@ -29,8 +32,6 @@ import org.jclouds.openstack.nova.v2_0.parse.ParseXVPVNCConsoleTest; import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest; import org.testng.annotations.Test; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; /** * Tests ConsolesApi Guice wiring and parsing @@ -71,7 +72,7 @@ public class ConsolesApiMockTest extends BaseOpenStackMockTest { server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource(responseResource)))); try { - NovaApi novaApi = api(server.getUrl("/").toString(), "openstack-nova"); + NovaApi novaApi = api(server.url("/").toString(), "openstack-nova"); String regionId = getFirst(novaApi.getConfiguredRegions(), "RegionTwo"); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HypervisorApiMockTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HypervisorApiMockTest.java index 07acabc1ca..0e858ce399 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HypervisorApiMockTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HypervisorApiMockTest.java @@ -19,8 +19,10 @@ package org.jclouds.openstack.nova.v2_0.extensions; import com.google.common.base.Optional; import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableSet; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; + +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.openstack.nova.v2_0.NovaApi; import org.jclouds.openstack.nova.v2_0.domain.regionscoped.Hypervisor; import org.jclouds.openstack.nova.v2_0.domain.regionscoped.HypervisorDetails; @@ -58,7 +60,7 @@ public class HypervisorApiMockTest extends BaseOpenStackMockTest { MockWebServer server = servers.get(method.getName()); server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/extension_list_full.json")))); - NovaApi novaApi = api(server.getUrl("/").toString(), "openstack-nova"); + NovaApi novaApi = api(server.url("/").toString(), "openstack-nova"); assertEquals(novaApi.getConfiguredRegions(), ImmutableSet.of("RegionOne", "RegionTwo", "RegionThree")); Optional hypervisorApi = novaApi.getHypervisorApi("RegionOne"); @@ -72,7 +74,7 @@ public class HypervisorApiMockTest extends BaseOpenStackMockTest { MockWebServer server = servers.get(method.getName()); server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/extension_list.json")))); - NovaApi novaApi = api(server.getUrl("/").toString(), "openstack-nova"); + NovaApi novaApi = api(server.url("/").toString(), "openstack-nova"); assertEquals(novaApi.getConfiguredRegions(), ImmutableSet.of("RegionOne", "RegionTwo", "RegionThree")); Optional hypervisorApi = novaApi.getHypervisorApi("RegionOne"); @@ -87,7 +89,7 @@ public class HypervisorApiMockTest extends BaseOpenStackMockTest { server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/extension_list_full.json")))); server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/hypervisor_list.json")))); - NovaApi novaApi = api(server.getUrl("/").toString(), "openstack-nova"); + NovaApi novaApi = api(server.url("/").toString(), "openstack-nova"); assertEquals(novaApi.getConfiguredRegions(), ImmutableSet.of("RegionOne", "RegionTwo", "RegionThree")); FluentIterable hypervisors = novaApi.getHypervisorApi("RegionOne").get().list(); @@ -106,7 +108,7 @@ public class HypervisorApiMockTest extends BaseOpenStackMockTest { server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/extension_list_full.json")))); server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/hypervisor_details.json")))); - NovaApi novaApi = api(server.getUrl("/").toString(), "openstack-nova"); + NovaApi novaApi = api(server.url("/").toString(), "openstack-nova"); assertEquals(novaApi.getConfiguredRegions(), ImmutableSet.of("RegionOne", "RegionTwo", "RegionThree")); FluentIterable hypervisors = novaApi.getHypervisorApi("RegionOne").get().listInDetail(); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiMockTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiMockTest.java index af81b8b385..367d3a47aa 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiMockTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/features/ImageApiMockTest.java @@ -17,8 +17,10 @@ package org.jclouds.openstack.nova.v2_0.features; import com.google.common.collect.FluentIterable; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; + +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.openstack.nova.v2_0.NovaApi; import org.jclouds.openstack.nova.v2_0.domain.BlockDeviceMapping; import org.jclouds.openstack.nova.v2_0.domain.Image; @@ -36,7 +38,7 @@ public class ImageApiMockTest extends BaseOpenStackMockTest { server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/image_list_with_block_device_mapping.json")))); try { - NovaApi novaApi = api(server.getUrl("/").toString(), "openstack-nova"); + NovaApi novaApi = api(server.url("/").toString(), "openstack-nova"); ImageApi imageApi = novaApi.getImageApiForZone("RegionOne"); FluentIterable images = imageApi.listInDetail().concat(); diff --git a/apis/openstack-swift/pom.xml b/apis/openstack-swift/pom.xml index a18c40f230..820646e049 100644 --- a/apis/openstack-swift/pom.xml +++ b/apis/openstack-swift/pom.xml @@ -95,7 +95,7 @@ test - com.squareup.okhttp + com.squareup.okhttp3 mockwebserver test diff --git a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/AuthenticationMockTest.java b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/AuthenticationMockTest.java index 8b5e89510a..2f17d1efdb 100644 --- a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/AuthenticationMockTest.java +++ b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/AuthenticationMockTest.java @@ -16,19 +16,19 @@ */ package org.jclouds.openstack.swift.v1; -import static com.google.common.base.Charsets.UTF_8; import static org.jclouds.openstack.swift.v1.features.AccountApiMockTest.accountResponse; import static org.testng.Assert.assertEquals; import java.util.Properties; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; /** * @see KeystoneProperties#CREDENTIAL_TYPE @@ -56,14 +56,14 @@ public class AuthenticationMockTest extends BaseOpenStackMockTest { Properties overrides = new Properties(); overrides.setProperty("jclouds.keystone.credential-type", credentialType); - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift", overrides); + SwiftApi api = api(server.url("/").toString(), "openstack-swift", overrides); api.getAccountApi("DFW").get(); assertEquals(server.getRequestCount(), 2); RecordedRequest authRequest = server.takeRequest(); assertEquals(authRequest.getRequestLine(), "POST /tokens HTTP/1.1"); - assertEquals(new String(authRequest.getBody(), UTF_8), expectedPost); + assertEquals(authRequest.getBody().readUtf8(), expectedPost); } finally { server.shutdown(); } diff --git a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/TempAuthMockTest.java b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/TempAuthMockTest.java index 5e36a6833d..e639772534 100644 --- a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/TempAuthMockTest.java +++ b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/TempAuthMockTest.java @@ -26,6 +26,10 @@ import static org.testng.Assert.assertTrue; import java.io.IOException; import java.util.Properties; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.ContextBuilder; import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.openstack.swift.v1.reference.TempAuthHeaders; @@ -34,9 +38,7 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; + @Test(groups = "unit", testName = "TempAuthMockTest", singleThreaded = true) public class TempAuthMockTest { @@ -63,11 +65,11 @@ public class TempAuthMockTest { private void test(Properties overrides, String identityHeaderName, String identityHeaderPass) throws Exception{ tempAuthServer.enqueue(new MockResponse().setResponseCode(204) .addHeader("X-Auth-Token", "token") - .addHeader("X-Storage-Url", swiftServer.getUrl("").toString())); + .addHeader("X-Storage-Url", swiftServer.url("").toString())); swiftServer.enqueue(new MockResponse().setBody("[{\"name\":\"test_container_1\",\"count\":2,\"bytes\":78}]")); - SwiftApi api = api(tempAuthServer.getUrl("").toString(), overrides); + SwiftApi api = api(tempAuthServer.url("").toString(), overrides); // Region name is derived from the swift server host. assertEquals(api.getConfiguredRegions(), ImmutableSet.of(tempAuthServer.getHostName())); @@ -100,10 +102,10 @@ public class TempAuthMockTest { @BeforeMethod public void start() throws IOException { tempAuthServer = new MockWebServer(); - tempAuthServer.play(); + tempAuthServer.start(); swiftServer = new MockWebServer(); - swiftServer.play(); + swiftServer.start(); } @AfterMethod(alwaysRun = true) diff --git a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/TemporaryUrlSignerMockTest.java b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/TemporaryUrlSignerMockTest.java index a9ab9a2364..853f6ad1de 100644 --- a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/TemporaryUrlSignerMockTest.java +++ b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/TemporaryUrlSignerMockTest.java @@ -20,11 +20,12 @@ import static org.jclouds.openstack.swift.v1.features.AccountApiMockTest.account import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.ACCOUNT_TEMPORARY_URL_KEY; import static org.testng.Assert.assertEquals; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest; import org.testng.annotations.Test; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; @Test(groups = "unit", testName = "TemporaryUrlSignerMockTest") public class TemporaryUrlSignerMockTest extends BaseOpenStackMockTest { @@ -40,7 +41,7 @@ public class TemporaryUrlSignerMockTest extends BaseOpenStackMockTest server.enqueue(addCommonHeaders(accountResponse().addHeader(ACCOUNT_TEMPORARY_URL_KEY, "mykey"))); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); String signature = TemporaryUrlSigner.checkApiEvery(api.getAccountApi("DFW"), 10000) .sign("GET", "/v1/AUTH_account/container/object", 1323479485L); @@ -62,7 +63,7 @@ public class TemporaryUrlSignerMockTest extends BaseOpenStackMockTest server.enqueue(addCommonHeaders(accountResponse())); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); TemporaryUrlSigner.checkApiEvery(api.getAccountApi("DFW"), 10000) .sign("GET", "/v1/AUTH_account/container/object", 1323479485L); } finally { diff --git a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/AccountApiMockTest.java b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/AccountApiMockTest.java index 72d3a1e129..c5671aa428 100644 --- a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/AccountApiMockTest.java +++ b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/AccountApiMockTest.java @@ -28,15 +28,17 @@ import static org.testng.Assert.assertTrue; import java.util.Map; import java.util.Map.Entry; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.openstack.swift.v1.SwiftApi; import org.jclouds.openstack.swift.v1.domain.Account; import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; + @Test(groups = "unit", testName = "AccountApiMockTest") public class AccountApiMockTest extends BaseOpenStackMockTest { @@ -51,7 +53,7 @@ public class AccountApiMockTest extends BaseOpenStackMockTest { .addHeader(ACCOUNT_METADATA_PREFIX + "Apiversion", "v1.1"))); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); Account account = api.getAccountApi("DFW").get(); assertEquals(account.getContainerCount(), 3L); assertEquals(account.getObjectCount(), 42L); @@ -76,7 +78,7 @@ public class AccountApiMockTest extends BaseOpenStackMockTest { .addHeader(ACCOUNT_METADATA_PREFIX + "ApiVersion", "v1.1"))); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); api.getAccountApi("DFW").updateMetadata(metadata); assertEquals(server.getRequestCount(), 2); @@ -98,7 +100,7 @@ public class AccountApiMockTest extends BaseOpenStackMockTest { server.enqueue(addCommonHeaders(accountResponse())); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); api.getAccountApi("DFW").updateTemporaryUrlKey("foobar"); assertEquals(server.getRequestCount(), 2); @@ -118,7 +120,7 @@ public class AccountApiMockTest extends BaseOpenStackMockTest { server.enqueue(addCommonHeaders(accountResponse())); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); assertTrue(api.getAccountApi("DFW").deleteMetadata(metadata)); assertEquals(server.getRequestCount(), 2); diff --git a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/BulkApiMockTest.java b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/BulkApiMockTest.java index 3136b52161..ae1212157c 100644 --- a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/BulkApiMockTest.java +++ b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/BulkApiMockTest.java @@ -19,6 +19,10 @@ package org.jclouds.openstack.swift.v1.features; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + import org.jboss.shrinkwrap.api.GenericArchive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; @@ -32,9 +36,7 @@ import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest; import org.testng.annotations.Test; import com.google.common.io.ByteSource; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; + @Test(groups = "unit", testName = "BulkApiMockTest") public class BulkApiMockTest extends BaseOpenStackMockTest { @@ -53,7 +55,7 @@ public class BulkApiMockTest extends BaseOpenStackMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201).setBody("{\"Number Files Created\": 10, \"Errors\": []}"))); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); Payload payload = Payloads.newByteSourcePayload(ByteSource.wrap(tarGz)); ExtractArchiveResponse response = api.getBulkApi("DFW").extractArchive("myContainer", payload, "tar.gz"); @@ -64,7 +66,7 @@ public class BulkApiMockTest extends BaseOpenStackMockTest { assertAuthentication(server); RecordedRequest extractRequest = server.takeRequest(); assertRequest(extractRequest, "PUT", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer?extract-archive=tar.gz"); - assertEquals(extractRequest.getBody(), tarGz); + assertEquals(extractRequest.getBody().readByteArray(), tarGz); } finally { server.shutdown(); } diff --git a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiMockTest.java b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiMockTest.java index 618ec9a172..d345f60429 100644 --- a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiMockTest.java +++ b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiMockTest.java @@ -31,6 +31,10 @@ import static org.testng.Assert.assertTrue; import java.util.Map; import java.util.Map.Entry; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.blobstore.ContainerNotFoundException; import org.jclouds.openstack.swift.v1.SwiftApi; import org.jclouds.openstack.swift.v1.domain.Container; @@ -40,9 +44,7 @@ import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; + @Test(groups = "unit", testName = "ContainerApiMockTest") public class ContainerApiMockTest extends BaseOpenStackMockTest { @@ -53,7 +55,7 @@ public class ContainerApiMockTest extends BaseOpenStackMockTest { server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/container_list.json")))); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); ImmutableList containers = api.getContainerApi("DFW").list().toList(); assertEquals(containers, ImmutableList.of( Container.builder() @@ -82,7 +84,7 @@ public class ContainerApiMockTest extends BaseOpenStackMockTest { assertNotNull(options); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); ImmutableList containers = api.getContainerApi("DFW").list(options).toList(); assertEquals(containers, ImmutableList.of( Container.builder() @@ -111,7 +113,7 @@ public class ContainerApiMockTest extends BaseOpenStackMockTest { .addHeader(CONTAINER_METADATA_PREFIX + "ApiVersion", "v1.1"))); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); assertTrue(api.getContainerApi("DFW").create("myContainer", anybodyRead().metadata(metadata))); Container container = api.getContainerApi("DFW").get("myContainer"); @@ -137,7 +139,7 @@ public class ContainerApiMockTest extends BaseOpenStackMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(404))); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); assertTrue(api.getContainerApi("DFW").create("myContainer", anybodyRead().metadata(metadata))); // the head call will throw the ContainerNotFoundException @@ -153,7 +155,7 @@ public class ContainerApiMockTest extends BaseOpenStackMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201))); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); assertTrue(api.getContainerApi("DFW").create("myContainer")); assertEquals(server.getRequestCount(), 2); @@ -170,7 +172,7 @@ public class ContainerApiMockTest extends BaseOpenStackMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201))); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); assertTrue(api.getContainerApi("DFW").create("myContainer", anybodyRead().metadata(metadata))); assertEquals(server.getRequestCount(), 2); @@ -195,7 +197,7 @@ public class ContainerApiMockTest extends BaseOpenStackMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201))); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); assertTrue(api.getContainerApi("DFW").create("container # ! special")); assertEquals(server.getRequestCount(), 2); @@ -212,7 +214,7 @@ public class ContainerApiMockTest extends BaseOpenStackMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(202))); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); assertFalse(api.getContainerApi("DFW").create("myContainer")); assertEquals(server.getRequestCount(), 2); @@ -233,7 +235,7 @@ public class ContainerApiMockTest extends BaseOpenStackMockTest { .addHeader(CONTAINER_METADATA_PREFIX + "Apiversion", "v1.1"))); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); Container container = api.getContainerApi("DFW").get("myContainer"); assertEquals(container.getName(), "myContainer"); assertEquals(container.getObjectCount(), Long.valueOf(42L)); @@ -258,7 +260,7 @@ public class ContainerApiMockTest extends BaseOpenStackMockTest { .addHeader(CONTAINER_METADATA_PREFIX + "ApiVersion", "v1.1"))); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); api.getContainerApi("DFW").updateMetadata("myContainer", metadata); assertEquals(server.getRequestCount(), 2); @@ -280,7 +282,7 @@ public class ContainerApiMockTest extends BaseOpenStackMockTest { server.enqueue(addCommonHeaders(containerResponse())); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); assertTrue(api.getContainerApi("DFW").deleteMetadata("myContainer", metadata)); assertEquals(server.getRequestCount(), 2); @@ -302,7 +304,7 @@ public class ContainerApiMockTest extends BaseOpenStackMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(204))); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); assertTrue(api.getContainerApi("DFW").deleteIfEmpty("myContainer")); assertEquals(server.getRequestCount(), 2); @@ -321,7 +323,7 @@ public class ContainerApiMockTest extends BaseOpenStackMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(409))); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); assertFalse(api.getContainerApi("DFW").deleteIfEmpty("myContainer")); } finally { diff --git a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/DynamicLargeObjectApiMockTest.java b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/DynamicLargeObjectApiMockTest.java index c0420ee648..6f6ed0c10b 100644 --- a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/DynamicLargeObjectApiMockTest.java +++ b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/DynamicLargeObjectApiMockTest.java @@ -21,6 +21,10 @@ import static com.google.common.net.HttpHeaders.ETAG; import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.OBJECT_METADATA_PREFIX; import static org.testng.Assert.assertEquals; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.io.Payloads; import org.jclouds.openstack.swift.v1.SwiftApi; import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest; @@ -28,9 +32,7 @@ import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; import com.google.common.net.HttpHeaders; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; + @Test(groups = "unit", testName = "DynamicLargeObjectApiMockTest") public final class DynamicLargeObjectApiMockTest extends BaseOpenStackMockTest { @@ -48,7 +50,7 @@ public final class DynamicLargeObjectApiMockTest extends BaseOpenStackMockTest { .setBody(stringFromResource("/object_list.json")))); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); ObjectList objects = api.getObjectApi("DFW", "myContainer").list(); - assertEquals(objects, parsedObjectsForUrl(server.getUrl("/").toString())); + assertEquals(objects, parsedObjectsForUrl(server.url("/").toString())); assertEquals(objects.getContainer().getName(), "myContainer"); assertTrue(objects.getContainer().getAnybodyRead().get()); @@ -133,9 +133,9 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest { .setBody(stringFromResource("/object_list.json")))); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); ObjectList objects = api.getObjectApi("DFW", "myContainer").list(new ListContainerOptions()); - assertEquals(objects, parsedObjectsForUrl(server.getUrl("/").toString())); + assertEquals(objects, parsedObjectsForUrl(server.url("/").toString())); assertEquals(objects.getContainer().getName(), "myContainer"); assertTrue(objects.getContainer().getAnybodyRead().get()); @@ -153,9 +153,9 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest { server.enqueue(addCommonHeaders(containerResponse().setBody(stringFromResource("/object_list.json")))); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); ObjectList objects = api.getObjectApi("DFW", "myContainer").list(marker("test")); - assertEquals(objects, parsedObjectsForUrl(server.getUrl("/").toString())); + assertEquals(objects, parsedObjectsForUrl(server.url("/").toString())); assertEquals(server.getRequestCount(), 2); assertAuthentication(server); @@ -174,7 +174,7 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest { .addHeader("Expires", "1406243553")); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); assertEquals( api.getObjectApi("DFW", "myContainer").put("myObject", PAYLOAD, metadata(metadata)), "d9f5eb4bba4e2f2f046e54611bc8196b"); @@ -184,7 +184,7 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest { RecordedRequest replace = server.takeRequest(); assertRequest(replace, "PUT", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer/myObject"); - assertEquals(new String(replace.getBody()), "swifty"); + assertEquals(replace.getBody().readUtf8(), "swifty"); for (Entry entry : metadata.entrySet()) { assertEquals(replace.getHeader(OBJECT_METADATA_PREFIX + entry.getKey().toLowerCase()), entry.getValue()); } @@ -203,7 +203,7 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest { final String objectName = "object # ! special"; try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); assertEquals( api.getObjectApi("DFW", containerName).put(objectName, PAYLOAD, metadata(metadata)), "d9f5eb4bba4e2f2f046e54611bc8196b"); @@ -213,7 +213,7 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest { RecordedRequest replace = server.takeRequest(); assertRequest(replace, "PUT", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/container%20%23%20%21%20special/object%20%23%20%21%20special"); - assertEquals(new String(replace.getBody()), "swifty"); + assertEquals(replace.getBody().readUtf8(), "swifty"); } finally { server.shutdown(); } @@ -235,7 +235,7 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest { Properties overrides = new Properties(); overrides.setProperty(PROPERTY_MAX_RETRIES, 5 + ""); - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift", overrides); + SwiftApi api = api(server.url("/").toString(), "openstack-swift", overrides); assertEquals( api.getObjectApi("DFW", "myContainer").put("myObject", PAYLOAD, metadata(metadata)), "d9f5eb4bba4e2f2f046e54611bc8196b"); @@ -246,7 +246,7 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest { // This should take a while. assertRequest(replace, "PUT", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer/myObject"); - assertEquals(new String(replace.getBody()), "swifty"); + assertEquals(replace.getBody().readUtf8(), "swifty"); for (Entry entry : metadata.entrySet()) { assertEquals(replace.getHeader(OBJECT_METADATA_PREFIX + entry.getKey().toLowerCase()), entry.getValue()); } @@ -288,7 +288,7 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest { Properties overrides = new Properties(); overrides.setProperty(PROPERTY_MAX_RETRIES, 5 + ""); - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift", overrides); + SwiftApi api = api(server.url("/").toString(), "openstack-swift", overrides); assertEquals( api.getObjectApi("DFW", "myContainer").put("myObject1", PAYLOAD, metadata(metadata)), "d9f5eb4bba4e2f2f046e54611bc8196b"); @@ -336,7 +336,7 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest { .addHeader(OBJECT_METADATA_PREFIX + "Apiversion", "v1.1"))); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); SwiftObject object = api.getObjectApi("DFW", "myContainer").getWithoutBody("myObject"); assertEquals(object.getName(), "myObject"); assertEquals(object.getETag(), "8a964ee2a5e88be344f36c22562a6486"); @@ -370,7 +370,7 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest { .addHeader(OBJECT_METADATA_PREFIX + "Apiversion", "v1.1"))); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); SwiftObject object = api.getObjectApi("DFW", "myContainer").get("myObject", tail(1)); assertEquals(object.getName(), "myObject"); assertEquals(object.getETag(), "8a964ee2a5e88be344f36c22562a6486"); @@ -409,7 +409,7 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest { overrides.setProperty(PROPERTY_MAX_RETRIES, 0 + ""); // 0 retries == 1 try. Semantics. overrides.setProperty(PROPERTY_RETRY_DELAY_START, 0 + ""); // exponential backoff already working for this call. This is the delay BETWEEN attempts. - final SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift", overrides); + final SwiftApi api = api(server.url("/").toString(), "openstack-swift", overrides); api.getObjectApi("DFW", "myContainer").put("myObject", new ByteSourcePayload(ByteSource.wrap("swifty".getBytes())), metadata(metadata)); @@ -434,7 +434,7 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest { .addHeader(OBJECT_METADATA_PREFIX + "ApiVersion", "v1.1"))); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); api.getObjectApi("DFW", "myContainer").updateMetadata("myObject", metadata); assertEquals(server.getRequestCount(), 2); @@ -458,14 +458,14 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest { .addHeader(OBJECT_METADATA_PREFIX + "ApiVersion", "v1.1"))); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); api.getObjectApi("DFW", "myContainer").updateMetadata("myObject", metadata); assertEquals(server.getRequestCount(), 2); assertEquals(server.takeRequest().getRequestLine(), "POST /tokens HTTP/1.1"); RecordedRequest replaceRequest = server.takeRequest(); - assertEquals(replaceRequest.getHeaders("Content-Type").get(0), "", "updateMetadata should send an empty content-type header, but sent " - + replaceRequest.getHeaders("Content-Type").get(0).toString()); + assertEquals(replaceRequest.getHeader("Content-Type"), "", "updateMetadata should send an empty content-type header, but sent " + + replaceRequest.getHeader("Content-Type")); assertEquals(replaceRequest.getRequestLine(), "POST /v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer/myObject HTTP/1.1"); @@ -483,7 +483,7 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest { server.enqueue(addCommonHeaders(objectResponse())); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); assertTrue(api.getObjectApi("DFW", "myContainer").deleteMetadata("myObject", metadata)); assertEquals(server.getRequestCount(), 2); @@ -505,7 +505,7 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(204))); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); api.getObjectApi("DFW", "myContainer").delete("myObject"); assertEquals(server.getRequestCount(), 2); @@ -524,7 +524,7 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(404))); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); api.getObjectApi("DFW", "myContainer").delete("myObject"); assertEquals(server.getRequestCount(), 2); @@ -543,7 +543,7 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201) .addHeader(SwiftHeaders.OBJECT_COPY_FROM, "/bar/foo.txt"))); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); api.getObjectApi("DFW", "foo").copy("bar.txt", "bar", "foo.txt"); assertEquals(server.getRequestCount(), 2); @@ -563,7 +563,7 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest { server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201) .addHeader(SwiftHeaders.OBJECT_COPY_FROM, "/bar/foo.txt"))); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); api.getObjectApi("DFW", "foo").copy("bar.txt", "bar", "foo.txt", new CopyOptions().ifMatch("fakeetag")); assertEquals(server.getRequestCount(), 2); @@ -573,9 +573,9 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest { assertEquals(copyRequest.getRequestLine(), "PUT /v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/foo/bar.txt HTTP/1.1"); - List requestHeaders = copyRequest.getHeaders(); - assertThat(requestHeaders).contains("If-Match: fakeetag"); - assertThat(requestHeaders).contains(SwiftHeaders.OBJECT_COPY_FROM + ": /bar/foo.txt"); + Headers requestHeaders = copyRequest.getHeaders(); + assertEquals(requestHeaders.get("If-Match"), "fakeetag"); + assertEquals(requestHeaders.get(SwiftHeaders.OBJECT_COPY_FROM), "/bar/foo.txt"); } finally { server.shutdown(); } @@ -589,7 +589,7 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest { .addHeader(SwiftHeaders.OBJECT_COPY_FROM, "/bogus/foo.txt"))); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); // the following line will throw the KeyNotFoundException api.getObjectApi("DFW", "foo").copy("bar.txt", "bogus", "foo.txt"); } finally { @@ -604,7 +604,7 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest { .addHeader(SwiftHeaders.OBJECT_COPY_FROM, "/bar/foo.txt"))); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); api.getObjectApi("DFW", "foo") .copy("bar.txt", "bar", "foo.txt", ImmutableMap.of("someUserHeader", "someUserMetadataValue"), ImmutableMap.of("Content-Disposition", "attachment; filename=\"fname.ext\"")); @@ -616,10 +616,10 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest { assertEquals(copyRequest.getRequestLine(), "PUT /v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/foo/bar.txt HTTP/1.1"); - List requestHeaders = copyRequest.getHeaders(); - assertTrue(requestHeaders.contains("X-Object-Meta-someuserheader: someUserMetadataValue")); - assertTrue(requestHeaders.contains("Content-Disposition: attachment; filename=\"fname.ext\"")); - assertTrue(requestHeaders.contains(SwiftHeaders.OBJECT_COPY_FROM + ": /bar/foo.txt")); + Headers requestHeaders = copyRequest.getHeaders(); + assertEquals(requestHeaders.get("X-Object-Meta-someuserheader"), "someUserMetadataValue"); + assertEquals(requestHeaders.get("Content-Disposition"), "attachment; filename=\"fname.ext\""); + assertEquals(requestHeaders.get(SwiftHeaders.OBJECT_COPY_FROM), "/bar/foo.txt"); } finally { server.shutdown(); } @@ -633,7 +633,7 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest { .addHeader(SwiftHeaders.OBJECT_COPY_FROM, "/bar/foo.txt"))); try { - SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift"); + SwiftApi api = api(server.url("/").toString(), "openstack-swift"); api.getObjectApi("DFW", "foo") .copy("bar.txt", "bar", "foo.txt", ImmutableMap.of("someUserHeader", "someUserMetadataValue"), ImmutableMap.of("Content-Disposition", "attachment; filename=\"fname.ext\"")); @@ -650,7 +650,7 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest { .addHeader("ETag", "8a964ee2a5e88be344f36c22562a6486") // TODO: MWS doesn't allow you to return content length w/o content // on HEAD! - .setBody("ABCD".getBytes(US_ASCII)) + .setBody("ABCD") .addHeader("Content-Length", "4") .addHeader("Content-Type", "text/plain; charset=UTF-8") .addHeader(EXPIRES, "Wed, 23 Jul 2014 14:00:00 GMT"); diff --git a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiMockTest.java b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiMockTest.java index 5389023588..0043a8771b 100644 --- a/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiMockTest.java +++ b/apis/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/StaticLargeObjectApiMockTest.java @@ -23,19 +23,21 @@ import static org.testng.Assert.assertNotEquals; import java.util.List; -import com.google.common.base.Charsets; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.openstack.swift.v1.SwiftApi; import org.jclouds.openstack.swift.v1.domain.DeleteStaticLargeObjectResponse; import org.jclouds.openstack.swift.v1.domain.Segment; import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest; import org.testng.annotations.Test; +import com.google.common.base.Charsets; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.net.HttpHeaders; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; + @Test(groups = "unit", testName = "StaticLargeObjectApiMockTest") public class StaticLargeObjectApiMockTest extends BaseOpenStackMockTest { @@ -46,7 +48,7 @@ public class StaticLargeObjectApiMockTest extends BaseOpenStackMockTest manifest = api.getStaticLargeObjectApi("DFW", "myContainer").getManifest("myObject"); // Check response @@ -199,7 +201,7 @@ public class StaticLargeObjectApiMockTest extends BaseOpenStackMockTest manifest = api.getStaticLargeObjectApi("DFW", "myContainer").getManifest("myObject"); // Check response @@ -222,7 +224,7 @@ public class StaticLargeObjectApiMockTest extends BaseOpenStackMockTesttest - com.squareup.okhttp + com.squareup.okhttp3 mockwebserver test diff --git a/apis/rackspace-cloudfiles/src/test/java/org/jclouds/rackspace/cloudfiles/v1/features/CloudFilesCDNApiMockTest.java b/apis/rackspace-cloudfiles/src/test/java/org/jclouds/rackspace/cloudfiles/v1/features/CloudFilesCDNApiMockTest.java index a3fa13c858..673422cc8d 100644 --- a/apis/rackspace-cloudfiles/src/test/java/org/jclouds/rackspace/cloudfiles/v1/features/CloudFilesCDNApiMockTest.java +++ b/apis/rackspace-cloudfiles/src/test/java/org/jclouds/rackspace/cloudfiles/v1/features/CloudFilesCDNApiMockTest.java @@ -35,6 +35,9 @@ import static org.testng.Assert.assertTrue; import java.net.URI; import java.util.List; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest; import org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi; import org.jclouds.rackspace.cloudfiles.v1.domain.CDNContainer; @@ -43,8 +46,7 @@ import org.testng.annotations.Test; import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableList; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; + /** * Tests the behavior of the {@link CloudFilesCDNApi}. @@ -60,7 +62,7 @@ public class CloudFilesCDNApiMockTest extends BaseOpenStackMockTest cdnContainers = cdnApi.list().toList(); @@ -81,7 +83,7 @@ public class CloudFilesCDNApiMockTest extends BaseOpenStackMockTest cdnContainers = cdnApi.list().toList(); @@ -102,7 +104,7 @@ public class CloudFilesCDNApiMockTest extends BaseOpenStackMockTest containers = api.getCDNApi("DFW").list(options).toList(); @@ -126,7 +128,7 @@ public class CloudFilesCDNApiMockTest extends BaseOpenStackMockTest containers = api.getCDNApi("DFW").list(options); @@ -147,7 +149,7 @@ public class CloudFilesCDNApiMockTest extends BaseOpenStackMockTesttest - com.squareup.okhttp + com.squareup.okhttp3 mockwebserver test diff --git a/apis/s3/src/test/java/org/jclouds/s3/S3ClientMockTest.java b/apis/s3/src/test/java/org/jclouds/s3/S3ClientMockTest.java index e8b49a7c27..34f69fe61e 100644 --- a/apis/s3/src/test/java/org/jclouds/s3/S3ClientMockTest.java +++ b/apis/s3/src/test/java/org/jclouds/s3/S3ClientMockTest.java @@ -29,6 +29,11 @@ import java.net.URL; import java.util.Properties; import java.util.Set; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; +import okhttp3.mockwebserver.SocketPolicy; + import org.jclouds.ContextBuilder; import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.http.okhttp.config.OkHttpCommandExecutorServiceModule; @@ -39,9 +44,7 @@ import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.inject.Module; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; + @Test(singleThreaded = true) public class S3ClientMockTest { @@ -63,9 +66,9 @@ public class S3ClientMockTest { public void testZeroLengthPutHasContentLengthHeader() throws IOException, InterruptedException { MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse().addHeader(ETAG, "ABCDEF")); - server.play(); + server.start(); - S3Client client = getS3Client(server.getUrl("/")); + S3Client client = getS3Client(server.url("/").url()); S3Object nada = client.newS3Object(); nada.getMetadata().setKey("object"); nada.setPayload(new byte[] {}); @@ -74,17 +77,17 @@ public class S3ClientMockTest { RecordedRequest request = server.takeRequest(); assertEquals(request.getRequestLine(), "PUT /bucket/object HTTP/1.1"); - assertEquals(request.getHeaders(CONTENT_LENGTH), ImmutableList.of("0")); - assertThat(request.getHeaders(EXPECT)).isEmpty(); + assertEquals(request.getHeaders().values(CONTENT_LENGTH), ImmutableList.of("0")); + assertThat(request.getHeader(EXPECT)).isNull(); server.shutdown(); } public void testDirectorySeparator() throws IOException, InterruptedException { MockWebServer server = new MockWebServer(); - server.enqueue(new MockResponse().setBody("").addHeader(ETAG, "ABCDEF")); - server.play(); + server.enqueue(new MockResponse().setBody("").addHeader(ETAG, "ABCDEF").setSocketPolicy(SocketPolicy.EXPECT_CONTINUE)); + server.start(); - S3Client client = getS3Client(server.getUrl("/")); + S3Client client = getS3Client(server.url("/").url()); S3Object fileInDir = client.newS3Object(); fileInDir.getMetadata().setKey("someDir/fileName"); fileInDir.setPayload(new byte[] { 1, 2, 3, 4 }); @@ -93,7 +96,7 @@ public class S3ClientMockTest { RecordedRequest request = server.takeRequest(); assertEquals(request.getRequestLine(), "PUT /bucket/someDir/fileName HTTP/1.1"); - assertEquals(request.getHeaders(EXPECT), ImmutableList.of("100-continue")); + assertEquals(request.getHeaders().values(EXPECT), ImmutableList.of("100-continue")); server.shutdown(); } @@ -104,11 +107,11 @@ public class S3ClientMockTest { " 2009-10-28T22:32:00\n" + " \"9b2cf535f27731c974343645a3985328\"\n" + " ")); - server.play(); - S3Client client = getS3Client(server.getUrl("/")); + server.start(); + S3Client client = getS3Client(server.url("/").url()); client.copyObject("sourceBucket", "apples#?:$&'\"<>čॐ", "destinationBucket", "destinationObject", CopyObjectOptions.NONE); RecordedRequest request = server.takeRequest(); - assertEquals(request.getHeaders("x-amz-copy-source"), ImmutableList.of("/sourceBucket/apples%23%3F%3A%24%26%27%22%3C%3E%C4%8D%E0%A5%90")); + assertEquals(request.getHeaders().values("x-amz-copy-source"), ImmutableList.of("/sourceBucket/apples%23%3F%3A%24%26%27%22%3C%3E%C4%8D%E0%A5%90")); server.shutdown(); } } diff --git a/core/pom.xml b/core/pom.xml index fa29452178..abd34ce94b 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -83,10 +83,15 @@ test - com.squareup.okhttp + com.squareup.okhttp3 mockwebserver test + + com.squareup.okhttp3 + okhttp-tls + test + com.google.auto.value auto-value diff --git a/core/src/main/java/org/jclouds/http/config/SSLModule.java b/core/src/main/java/org/jclouds/http/config/SSLModule.java index 6f03171f30..19b85de7ec 100644 --- a/core/src/main/java/org/jclouds/http/config/SSLModule.java +++ b/core/src/main/java/org/jclouds/http/config/SSLModule.java @@ -101,7 +101,7 @@ public class SSLModule extends AbstractModule { @Singleton public static class TrustAllCerts implements X509TrustManager { public X509Certificate[] getAcceptedIssuers() { - return null; + return new X509Certificate[0]; } public void checkClientTrusted(X509Certificate[] certs, String authType) { diff --git a/core/src/test/java/org/jclouds/http/BackoffLimitedRetryJavaTest.java b/core/src/test/java/org/jclouds/http/BackoffLimitedRetryJavaTest.java index e7ec6949f8..34222fd2bd 100644 --- a/core/src/test/java/org/jclouds/http/BackoffLimitedRetryJavaTest.java +++ b/core/src/test/java/org/jclouds/http/BackoffLimitedRetryJavaTest.java @@ -23,12 +23,14 @@ import static org.testng.Assert.fail; import java.util.Properties; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.testng.annotations.Test; import com.google.inject.Module; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; + /** * Tests the retry behavior of the default {@link RetryHandler} implementation @@ -57,7 +59,7 @@ public class BackoffLimitedRetryJavaTest extends BaseMockWebServerTest { @Test public void testNoRetriesSuccessful() throws Exception { MockWebServer server = mockWebServer(new MockResponse()); - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); try { client.download(""); assertEquals(server.getRequestCount(), 1); @@ -70,7 +72,7 @@ public class BackoffLimitedRetryJavaTest extends BaseMockWebServerTest { @Test public void testSingleRetrySuccessful() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(500), new MockResponse()); - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); try { client.download(""); assertEquals(server.getRequestCount(), 2); @@ -88,7 +90,7 @@ public class BackoffLimitedRetryJavaTest extends BaseMockWebServerTest { } server.enqueue(new MockResponse()); - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); try { client.download(""); assertEquals(server.getRequestCount(), maxRetries); @@ -105,7 +107,7 @@ public class BackoffLimitedRetryJavaTest extends BaseMockWebServerTest { server.enqueue(new MockResponse().setResponseCode(500)); } - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); try { client.download(""); @@ -126,7 +128,7 @@ public class BackoffLimitedRetryJavaTest extends BaseMockWebServerTest { server.enqueue(new MockResponse().setResponseCode(500)); } - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); try { client.download(""); client.download(""); diff --git a/core/src/test/java/org/jclouds/http/BaseHttpCommandExecutorServiceIntegrationTest.java b/core/src/test/java/org/jclouds/http/BaseHttpCommandExecutorServiceIntegrationTest.java index ace24277b9..7a19459912 100644 --- a/core/src/test/java/org/jclouds/http/BaseHttpCommandExecutorServiceIntegrationTest.java +++ b/core/src/test/java/org/jclouds/http/BaseHttpCommandExecutorServiceIntegrationTest.java @@ -34,6 +34,13 @@ import java.net.URLDecoder; import java.util.Random; import java.util.concurrent.TimeUnit; +import okhttp3.mockwebserver.Dispatcher; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + +import okio.Buffer; + import org.jclouds.io.ByteStreams2; import org.jclouds.io.Payload; import org.jclouds.util.Strings2; @@ -42,16 +49,12 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; -import com.google.common.base.Charsets; import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; import com.google.common.collect.Multimap; import com.google.common.io.ByteSource; import com.google.common.io.Files; -import com.squareup.okhttp.mockwebserver.Dispatcher; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; + /** * Tests for functionality all {@link HttpCommandExecutorService} http executor @@ -76,7 +79,7 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base @Test public void testRequestFilter() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody("test")); - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); try { String result = client.downloadFilter("", "filterme"); @@ -93,7 +96,7 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base @Test public void testGetStringWithHeader() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody("test")); - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); try { String result = client.download("", "test"); @@ -109,7 +112,7 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base @Test public void testGetString() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody(XML)); - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); try { assertEquals(client.download(""), XML); } finally { @@ -121,7 +124,7 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base @Test public void testGetStringIsRetriedOnFailure() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(500), new MockResponse().setBody(XML)); - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); try { String result = client.download(""); assertEquals(server.getRequestCount(), 2); @@ -135,10 +138,10 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base @Test public void testGetStringViaRequest() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody(XML)); - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); try { HttpResponse getStringResponse = client.invoke(HttpRequest.builder().method("GET") - .endpoint(server.getUrl("/objects").toString()).build()); + .endpoint(server.url("/objects").toString()).build()); assertEquals(Strings2.toStringAndClose(getStringResponse.getPayload().openStream()).trim(), XML); } finally { closeQuietly(client); @@ -154,7 +157,7 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base @Test(dataProvider = "gets") public void testGetStringSynch(String uri) throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody(XML)); - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); try { String result = client.synch(uri); RecordedRequest request = server.takeRequest(); @@ -169,7 +172,7 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base @Test public void testGetException() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(404)); - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); try { String result = client.downloadException("", tail(1)); assertEquals(result, "foo"); @@ -182,7 +185,7 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base @Test public void testGetSynchException() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(404)); - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); try { String result = client.synchException("", ""); assertEquals(result, "foo"); @@ -195,10 +198,10 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base @Test public void testGetStringRedirect() throws Exception { MockWebServer redirectTarget = mockWebServer(new MockResponse().setBody(XML2)); - redirectTarget.useHttps(sslContext.getSocketFactory(), false); + redirectTarget.useHttps(sslSocketFactory(), false); MockWebServer server = mockWebServer(new MockResponse().setResponseCode(302).setHeader("Location", - redirectTarget.getUrl("/").toString())); - IntegrationTestClient client = client(server.getUrl("/").toString()); + redirectTarget.url("/").toString())); + IntegrationTestClient client = client(server.url("/").toString()); try { String result = client.download("redirect"); assertEquals(result, XML2); @@ -216,10 +219,10 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base String constitutionsMd5 = base64().encode(oneHundredOneConstitutions.hash(md5()).asBytes()); MockResponse response = new MockResponse().addHeader("Content-MD5", constitutionsMd5) .addHeader("Content-type", "text/plain") - .setBody(oneHundredOneConstitutions.openStream(), oneHundredOneConstitutions.size()); + .setBody(new Buffer().readFrom(oneHundredOneConstitutions.openStream(), oneHundredOneConstitutions.size())); MockWebServer server = mockWebServer(response, response); - InputStream input = server.getUrl("/101constitutions").openStream(); + InputStream input = server.url("/101constitutions").url().openStream(); try { assertValidMd5(input, constitutionsMd5); @@ -240,7 +243,7 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base try { MockResponse response = new MockResponse(); String expectedMd5 = request.getHeader("Content-MD5"); - ByteSource body = ByteSource.wrap(request.getBody()); + ByteSource body = ByteSource.wrap(request.getBody().readByteArray()); String realMd5FromRequest = base64().encode(body.hash(md5()).asBytes()); boolean matched = expectedMd5.equals(realMd5FromRequest); if (matched) { @@ -259,7 +262,7 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base @Test public void testUploadBigFile() throws Exception { MockWebServer server = mockWebServer(new MD5CheckDispatcher()); - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); File f = null; Payload payload = null; @@ -295,12 +298,12 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base @Test public void testPost() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody("fooPOST")); - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); try { String result = client.post("", "foo"); // Verify that the body is properly populated RecordedRequest request = server.takeRequest(); - assertEquals(new String(request.getBody(), Charsets.UTF_8), "foo"); + assertEquals(request.getBody().readUtf8(), "foo"); assertEquals(result, "fooPOST"); } finally { closeQuietly(client); @@ -311,12 +314,12 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base @Test public void testZeroLengthPost() throws Exception { MockWebServer server = mockWebServer(new MockResponse()); - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); try { client.postNothing(""); assertEquals(server.getRequestCount(), 1); RecordedRequest request = server.takeRequest(); - assertEquals(new String(request.getBody(), Charsets.UTF_8), ""); + assertEquals(request.getBody().readUtf8(), ""); } finally { closeQuietly(client); server.shutdown(); @@ -327,16 +330,16 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base public void testPostIsRetriedOnFailure() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(500), new MockResponse().setBody("fooPOST")); - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); try { String result = client.post("", "foo"); assertEquals(server.getRequestCount(), 2); assertEquals(result, "fooPOST"); // Verify that the body was properly sent in the two requests RecordedRequest request = server.takeRequest(); - assertEquals(new String(request.getBody(), Charsets.UTF_8), "foo"); + assertEquals(request.getBody().readUtf8(), "foo"); request = server.takeRequest(); - assertEquals(new String(request.getBody(), Charsets.UTF_8), "foo"); + assertEquals(request.getBody().readUtf8(), "foo"); } finally { closeQuietly(client); server.shutdown(); @@ -346,10 +349,10 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base @Test public void testPostRedirect() throws Exception { MockWebServer redirectTarget = mockWebServer(new MockResponse().setBody("fooPOSTREDIRECT")); - redirectTarget.useHttps(sslContext.getSocketFactory(), false); + redirectTarget.useHttps(sslSocketFactory(), false); MockWebServer server = mockWebServer(new MockResponse().setResponseCode(302).setHeader("Location", - redirectTarget.getUrl("/").toString())); - IntegrationTestClient client = client(server.getUrl("/").toString()); + redirectTarget.url("/").toString())); + IntegrationTestClient client = client(server.url("/").toString()); try { String result = client.post("redirect", "foo"); assertEquals(result, "fooPOSTREDIRECT"); @@ -357,9 +360,9 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base assertEquals(redirectTarget.getRequestCount(), 1); // Verify that the body was populated after the redirect RecordedRequest request = server.takeRequest(); - assertEquals(new String(request.getBody(), Charsets.UTF_8), "foo"); + assertEquals(request.getBody().readUtf8(), "foo"); request = redirectTarget.takeRequest(); - assertEquals(new String(request.getBody(), Charsets.UTF_8), "foo"); + assertEquals(request.getBody().readUtf8(), "foo"); } finally { closeQuietly(client); redirectTarget.shutdown(); @@ -370,12 +373,12 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base @Test public void testPostAsInputStream() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody("fooPOST")); - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); try { String result = client.postAsInputStream("", "foo"); // Verify that the body is properly populated RecordedRequest request = server.takeRequest(); - assertEquals(new String(request.getBody(), Charsets.UTF_8), "foo"); + assertEquals(request.getBody().readUtf8(), "foo"); assertEquals(result, "fooPOST"); } finally { closeQuietly(client); @@ -386,7 +389,7 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base @Test public void testPostAsInputStreamDoesNotRetryOnFailure() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(500), new MockResponse()); - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); try { client.postAsInputStream("", "foo"); fail("Request should have thrown an exception after a server error"); @@ -401,12 +404,12 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base @Test public void testPostBinder() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody("fooPOSTJSON")); - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); try { String result = client.postJson("", "foo"); // Verify that the body is properly populated RecordedRequest request = server.takeRequest(); - assertEquals(new String(request.getBody(), Charsets.UTF_8), "{\"key\":\"foo\"}"); + assertEquals(request.getBody().readUtf8(), "{\"key\":\"foo\"}"); assertEquals(result, "fooPOSTJSON"); } finally { closeQuietly(client); @@ -418,7 +421,7 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base public void testPostContentDisposition() throws Exception { MockWebServer server = mockWebServer(new MockResponse().addHeader("x-Content-Disposition", "attachment; filename=photo.jpg")); - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); Payload payload = null; try { ByteSource body = ByteSource.wrap("foo".getBytes()); @@ -441,7 +444,7 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base @Test public void testPostContentEncoding() throws Exception { MockWebServer server = mockWebServer(new MockResponse().addHeader("x-Content-Encoding", "gzip")); - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); Payload payload = null; try { ByteSource body = ByteSource.wrap("foo".getBytes()); @@ -464,7 +467,7 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base @Test public void testPostContentLanguage() throws Exception { MockWebServer server = mockWebServer(new MockResponse().addHeader("x-Content-Language", "mi, en")); - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); Payload payload = null; try { ByteSource body = ByteSource.wrap("foo".getBytes()); @@ -487,12 +490,12 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base @Test public void testPut() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody("fooPUT")); - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); try { String result = client.upload("", "foo"); // Verify that the body is properly populated RecordedRequest request = server.takeRequest(); - assertEquals(new String(request.getBody(), Charsets.UTF_8), "foo"); + assertEquals(request.getBody().readUtf8(), "foo"); assertEquals(result, "fooPUT"); } finally { closeQuietly(client); @@ -503,10 +506,10 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base @Test public void testPutRedirect() throws Exception { MockWebServer redirectTarget = mockWebServer(new MockResponse().setBody("fooPUTREDIRECT")); - redirectTarget.useHttps(sslContext.getSocketFactory(), false); + redirectTarget.useHttps(sslSocketFactory(), false); MockWebServer server = mockWebServer(new MockResponse().setResponseCode(302).setHeader("Location", - redirectTarget.getUrl("/").toString())); - IntegrationTestClient client = client(server.getUrl("/").toString()); + redirectTarget.url("/").toString())); + IntegrationTestClient client = client(server.url("/").toString()); try { String result = client.upload("redirect", "foo"); assertEquals(result, "fooPUTREDIRECT"); @@ -514,9 +517,9 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base assertEquals(redirectTarget.getRequestCount(), 1); // Verify that the body was populated after the redirect RecordedRequest request = server.takeRequest(); - assertEquals(new String(request.getBody(), Charsets.UTF_8), "foo"); + assertEquals(request.getBody().readUtf8(), "foo"); request = redirectTarget.takeRequest(); - assertEquals(new String(request.getBody(), Charsets.UTF_8), "foo"); + assertEquals(request.getBody().readUtf8(), "foo"); } finally { closeQuietly(client); redirectTarget.shutdown(); @@ -527,12 +530,12 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base @Test public void testZeroLengthPut() throws Exception { MockWebServer server = mockWebServer(new MockResponse()); - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); try { client.putNothing(""); assertEquals(server.getRequestCount(), 1); RecordedRequest request = server.takeRequest(); - assertEquals(new String(request.getBody(), Charsets.UTF_8), ""); + assertEquals(request.getBody().readUtf8(), ""); } finally { closeQuietly(client); server.shutdown(); @@ -543,16 +546,16 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base public void testPutIsRetriedOnFailure() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(500), new MockResponse().setBody("fooPUT")); - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); try { String result = client.upload("", "foo"); assertEquals(server.getRequestCount(), 2); assertEquals(result, "fooPUT"); // Verify that the body was properly sent in the two requests RecordedRequest request = server.takeRequest(); - assertEquals(new String(request.getBody(), Charsets.UTF_8), "foo"); + assertEquals(request.getBody().readUtf8(), "foo"); request = server.takeRequest(); - assertEquals(new String(request.getBody(), Charsets.UTF_8), "foo"); + assertEquals(request.getBody().readUtf8(), "foo"); } finally { closeQuietly(client); server.shutdown(); @@ -562,7 +565,7 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base @Test public void testHead() throws Exception { MockWebServer server = mockWebServer(new MockResponse()); - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); try { assertTrue(client.exists("")); } finally { @@ -574,7 +577,7 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base @Test public void testHeadIsRetriedOnServerError() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(500), new MockResponse()); - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); try { assertTrue(client.exists("")); assertEquals(server.getRequestCount(), 2); @@ -587,7 +590,7 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base @Test public void testHeadFailure() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(404)); - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); try { assertFalse(client.exists("")); } finally { @@ -599,7 +602,7 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base @Test public void testGetAndParseSax() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody(XML)); - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); try { String result = client.downloadAndParse(""); assertEquals(result, "whoppers"); @@ -613,11 +616,11 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base public void testInterruptThrottledGet() throws Exception { long timeoutMillis = 10 * 1000; MockWebServer server = mockWebServer(new MockResponse().setBody(XML).throttleBody(XML.length() / 2, timeoutMillis, TimeUnit.MILLISECONDS)); - IntegrationTestClient client = client(server.getUrl("/").toString()); + IntegrationTestClient client = client(server.url("/").toString()); try { HttpResponse response = client.invoke(HttpRequest.builder() .method("GET") - .endpoint(server.getUrl("/").toURI()) + .endpoint(server.url("/").uri()) .build()); InputStream is = response.getPayload().openStream(); long now = System.currentTimeMillis(); diff --git a/core/src/test/java/org/jclouds/http/BaseMockWebServerTest.java b/core/src/test/java/org/jclouds/http/BaseMockWebServerTest.java index b3434ae362..2d298380da 100644 --- a/core/src/test/java/org/jclouds/http/BaseMockWebServerTest.java +++ b/core/src/test/java/org/jclouds/http/BaseMockWebServerTest.java @@ -23,10 +23,15 @@ import java.io.Closeable; import java.io.IOException; import java.net.InetAddress; import java.net.UnknownHostException; -import java.security.GeneralSecurityException; import java.util.Properties; -import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSocketFactory; + +import okhttp3.mockwebserver.Dispatcher; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.tls.HandshakeCertificates; +import okhttp3.tls.HeldCertificate; import org.jclouds.ContextBuilder; import org.jclouds.providers.AnonymousProviderMetadata; @@ -34,10 +39,7 @@ import org.testng.annotations.BeforeClass; import com.google.common.collect.ImmutableSet; import com.google.inject.Module; -import com.squareup.okhttp.internal.SslContextBuilder; -import com.squareup.okhttp.mockwebserver.Dispatcher; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; + /** * Base class for integration tests that use {@link MockWebServer} to verify the @@ -45,14 +47,19 @@ import com.squareup.okhttp.mockwebserver.MockWebServer; */ public abstract class BaseMockWebServerTest { - protected SSLContext sslContext; + protected HandshakeCertificates serverCertificates; @BeforeClass(groups = "integration") protected void setupSSL() { try { - sslContext = new SslContextBuilder(InetAddress.getLocalHost().getHostName()).build(); - } catch (GeneralSecurityException ex) { - throw new RuntimeException(ex); + String localhost = InetAddress.getLocalHost().getHostName(); + HeldCertificate localhostCertificate = new HeldCertificate.Builder() + .addSubjectAlternativeName(localhost) + .build(); + + serverCertificates = new HandshakeCertificates.Builder() + .heldCertificate(localhostCertificate) + .build(); } catch (UnknownHostException ex) { throw new RuntimeException(ex); } @@ -64,7 +71,7 @@ public abstract class BaseMockWebServerTest { */ protected static MockWebServer mockWebServer(MockResponse... responses) throws IOException { MockWebServer server = new MockWebServer(); - server.play(); + server.start(); for (MockResponse response : responses) { server.enqueue(response); } @@ -76,7 +83,7 @@ public abstract class BaseMockWebServerTest { */ protected static MockWebServer mockWebServer(Dispatcher dispatcher) throws IOException { MockWebServer server = new MockWebServer(); - server.play(); + server.start(); server.setDispatcher(dispatcher); return server; } @@ -100,6 +107,10 @@ public abstract class BaseMockWebServerTest { .modules(ImmutableSet.copyOf(connectionModules)).overrides(properties).buildApi(apiClass); } + protected SSLSocketFactory sslSocketFactory() { + return serverCertificates.sslSocketFactory(); + } + /** * Add the connection properties used to configure the tests. */ diff --git a/core/src/test/java/org/jclouds/http/JavaUrlHttpCommandExecutorServiceIntegrationTest.java b/core/src/test/java/org/jclouds/http/JavaUrlHttpCommandExecutorServiceIntegrationTest.java index e911b0ef32..9149989a90 100644 --- a/core/src/test/java/org/jclouds/http/JavaUrlHttpCommandExecutorServiceIntegrationTest.java +++ b/core/src/test/java/org/jclouds/http/JavaUrlHttpCommandExecutorServiceIntegrationTest.java @@ -26,6 +26,11 @@ import static org.testng.Assert.fail; import java.util.Properties; +import okhttp3.mockwebserver.Dispatcher; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.io.Payload; import org.jclouds.io.payloads.StringPayload; @@ -34,10 +39,7 @@ import org.jclouds.utils.TestUtils; import org.testng.annotations.Test; import com.google.inject.Module; -import com.squareup.okhttp.mockwebserver.Dispatcher; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; + @Test(groups = "integration") public class JavaUrlHttpCommandExecutorServiceIntegrationTest extends BaseHttpCommandExecutorServiceIntegrationTest { @@ -62,9 +64,9 @@ public class JavaUrlHttpCommandExecutorServiceIntegrationTest extends BaseHttpCo return new MockResponse(); } }); - server.play(); + server.start(); - HttpClient client = api(HttpClient.class, server.getUrl("/").toString()); + HttpClient client = api(HttpClient.class, server.url("/").toString()); // Make a fake payload that has no data, but says there's a lot! Payload fakePayload = new StringPayload(""); @@ -72,7 +74,7 @@ public class JavaUrlHttpCommandExecutorServiceIntegrationTest extends BaseHttpCo try { try { - client.post(server.getUrl("/").toURI(), fakePayload); + client.post(server.url("/").uri(), fakePayload); fail("Should have errored since we didn't sent that much data!"); } catch (HttpResponseException expected) { } diff --git a/drivers/gae/pom.xml b/drivers/gae/pom.xml index a4228707b3..a55625626e 100644 --- a/drivers/gae/pom.xml +++ b/drivers/gae/pom.xml @@ -49,10 +49,15 @@ test - com.squareup.okhttp + com.squareup.okhttp3 mockwebserver test + + com.squareup.okhttp3 + okhttp-tls + test + com.google.appengine appengine-api-stubs diff --git a/drivers/okhttp/pom.xml b/drivers/okhttp/pom.xml index 3f43551bc8..4fe0534017 100644 --- a/drivers/okhttp/pom.xml +++ b/drivers/okhttp/pom.xml @@ -44,15 +44,20 @@ test - com.squareup.okhttp + com.squareup.okhttp3 okhttp ${okhttp.version} - com.squareup.okhttp + com.squareup.okhttp3 mockwebserver test + + com.squareup.okhttp3 + okhttp-tls + test + diff --git a/drivers/okhttp/src/main/java/org/jclouds/http/okhttp/OkHttpClientSupplier.java b/drivers/okhttp/src/main/java/org/jclouds/http/okhttp/OkHttpClientSupplier.java index 9254ec5f02..3c5be76749 100644 --- a/drivers/okhttp/src/main/java/org/jclouds/http/okhttp/OkHttpClientSupplier.java +++ b/drivers/okhttp/src/main/java/org/jclouds/http/okhttp/OkHttpClientSupplier.java @@ -16,12 +16,14 @@ */ package org.jclouds.http.okhttp; +import okhttp3.OkHttpClient; + import org.jclouds.http.okhttp.OkHttpClientSupplier.NewOkHttpClient; import com.google.common.annotations.Beta; import com.google.common.base.Supplier; import com.google.inject.ImplementedBy; -import com.squareup.okhttp.OkHttpClient; + /** * Provides the OkHttp client used for all requests. This could be used to diff --git a/drivers/okhttp/src/main/java/org/jclouds/http/okhttp/OkHttpCommandExecutorService.java b/drivers/okhttp/src/main/java/org/jclouds/http/okhttp/OkHttpCommandExecutorService.java index ddf62c1451..750d78820e 100644 --- a/drivers/okhttp/src/main/java/org/jclouds/http/okhttp/OkHttpCommandExecutorService.java +++ b/drivers/okhttp/src/main/java/org/jclouds/http/okhttp/OkHttpCommandExecutorService.java @@ -29,8 +29,17 @@ import java.net.Proxy; import java.net.URI; import java.util.Map; +import javax.annotation.Nullable; import javax.inject.Named; +import okhttp3.internal.http.HttpMethod; +import okhttp3.Headers; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + import okio.BufferedSink; import okio.Okio; import okio.Source; @@ -51,12 +60,7 @@ import com.google.common.base.Function; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableMultimap.Builder; import com.google.inject.Inject; -import com.squareup.okhttp.Headers; -import com.squareup.okhttp.MediaType; -import com.squareup.okhttp.OkHttpClient; -import com.squareup.okhttp.Request; -import com.squareup.okhttp.RequestBody; -import com.squareup.okhttp.Response; + public final class OkHttpCommandExecutorService extends BaseHttpCommandExecutorService { private final Function proxyForURI; @@ -92,6 +96,11 @@ public final class OkHttpCommandExecutorService extends BaseHttpCommandExecutorS } } + // OkHttp requires body (at least empty one) for some type of the requests, so let's generate it + if (body == null && HttpMethod.requiresRequestBody(request.getMethod())) { + body = generateEmptyRequestBody(payload); + } + builder.method(request.getMethod(), body); return builder.build(); @@ -117,6 +126,22 @@ public final class OkHttpCommandExecutorService extends BaseHttpCommandExecutorS } } + private RequestBody generateEmptyRequestBody(final Payload payload) { + return new RequestBody() { + @Nullable @Override public MediaType contentType() { + return payload != null ? MediaType.parse(payload.getContentMetadata().getContentType()) : null; + } + + @Override public void writeTo(BufferedSink sink) throws IOException { + // nothing to do + } + + @Override public long contentLength() throws IOException { + return 0; + } + }; + } + protected RequestBody generateRequestBody(final HttpRequest request, final Payload payload) { checkNotNull(payload.getContentMetadata().getContentType(), "payload.getContentType"); return new RequestBody() { @@ -147,8 +172,9 @@ public final class OkHttpCommandExecutorService extends BaseHttpCommandExecutorS @Override protected HttpResponse invoke(Request nativeRequest) throws IOException, InterruptedException { - OkHttpClient requestScopedClient = globalClient.clone(); - requestScopedClient.setProxy(proxyForURI.apply(nativeRequest.uri())); + OkHttpClient requestScopedClient = globalClient.newBuilder() + .proxy(proxyForURI.apply(nativeRequest.url().uri())) + .build(); Response response = requestScopedClient.newCall(nativeRequest).execute(); diff --git a/drivers/okhttp/src/main/java/org/jclouds/http/okhttp/config/OkHttpCommandExecutorServiceModule.java b/drivers/okhttp/src/main/java/org/jclouds/http/okhttp/config/OkHttpCommandExecutorServiceModule.java index 9c47d811ca..1958e66eab 100644 --- a/drivers/okhttp/src/main/java/org/jclouds/http/okhttp/config/OkHttpCommandExecutorServiceModule.java +++ b/drivers/okhttp/src/main/java/org/jclouds/http/okhttp/config/OkHttpCommandExecutorServiceModule.java @@ -22,6 +22,8 @@ import javax.inject.Named; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLContext; +import okhttp3.OkHttpClient; + import org.jclouds.http.HttpCommandExecutorService; import org.jclouds.http.HttpUtils; import org.jclouds.http.config.ConfiguresHttpCommandExecutorService; @@ -34,7 +36,7 @@ import com.google.inject.AbstractModule; import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.Scopes; -import com.squareup.okhttp.OkHttpClient; + /** * Configures the {@link OkHttpCommandExecutorService}. @@ -68,22 +70,22 @@ public class OkHttpCommandExecutorServiceModule extends AbstractModule { @Override public OkHttpClient get() { - OkHttpClient client = clientSupplier.get(); - client.setConnectTimeout(utils.getConnectionTimeout(), TimeUnit.MILLISECONDS); - client.setReadTimeout(utils.getSocketOpenTimeout(), TimeUnit.MILLISECONDS); - // do not follow redirects since https redirects don't work properly - // ex. Caused by: java.io.IOException: HTTPS hostname wrong: should be - // - client.setFollowRedirects(false); + OkHttpClient.Builder clientBuilder = clientSupplier.get().newBuilder() + .connectTimeout(utils.getConnectionTimeout(), TimeUnit.MILLISECONDS) + .readTimeout(utils.getSocketOpenTimeout(), TimeUnit.MILLISECONDS) + // do not follow redirects since https redirects don't work properly + // ex. Caused by: java.io.IOException: HTTPS hostname wrong: should be + // + .followRedirects(false); if (utils.relaxHostname()) { - client.setHostnameVerifier(verifier); + clientBuilder.hostnameVerifier(verifier); } if (utils.trustAllCerts()) { - client.setSslSocketFactory(untrustedSSLContextProvider.get().getSocketFactory()); + clientBuilder.sslSocketFactory(untrustedSSLContextProvider.get().getSocketFactory()); } - return client; + return clientBuilder.build(); } } diff --git a/drivers/okhttp/src/test/java/org/jclouds/http/okhttp/OkHttpCommandExecutorServiceTest.java b/drivers/okhttp/src/test/java/org/jclouds/http/okhttp/OkHttpCommandExecutorServiceTest.java index 6a485ce47c..877cf88fd7 100644 --- a/drivers/okhttp/src/test/java/org/jclouds/http/okhttp/OkHttpCommandExecutorServiceTest.java +++ b/drivers/okhttp/src/test/java/org/jclouds/http/okhttp/OkHttpCommandExecutorServiceTest.java @@ -31,6 +31,13 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import okhttp3.ConnectionSpec; +import okhttp3.OkHttpClient; +import okhttp3.TlsVersion; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.http.BaseHttpCommandExecutorServiceIntegrationTest; import org.jclouds.http.HttpResponseException; import org.jclouds.http.config.ConfiguresHttpCommandExecutorService; @@ -40,16 +47,10 @@ import org.jclouds.rest.annotations.PATCH; import org.jclouds.rest.binders.BindToStringPayload; import org.testng.annotations.Test; -import com.google.common.base.Charsets; import com.google.common.collect.ImmutableList; import com.google.inject.AbstractModule; import com.google.inject.Module; -import com.squareup.okhttp.ConnectionSpec; -import com.squareup.okhttp.OkHttpClient; -import com.squareup.okhttp.TlsVersion; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; + /** * Tests the functionality of the {@link OkHttpCommandExecutorService} @@ -83,13 +84,13 @@ public class OkHttpCommandExecutorServiceTest extends BaseHttpCommandExecutorSer @Test public void testPatch() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody("fooPATCH")); - PatchApi api = api(PatchApi.class, server.getUrl("/").toString()); + PatchApi api = api(PatchApi.class, server.url("/").toString()); try { String result = api.patch("", "foo"); // Verify that the body is properly populated RecordedRequest request = server.takeRequest(); assertEquals(request.getMethod(), "PATCH"); - assertEquals(new String(request.getBody(), Charsets.UTF_8), "foo"); + assertEquals(request.getBody().readUtf8(), "foo"); assertEquals(result, "fooPATCH"); // Verify content headers are sent assertNotNull(request.getHeader("Content-Type")); @@ -106,7 +107,7 @@ public class OkHttpCommandExecutorServiceTest extends BaseHttpCommandExecutorSer public void testPatchIsRetriedOnFailure() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(500), new MockResponse().setBody("fooPATCH")); - PatchApi api = api(PatchApi.class, server.getUrl("/").toString()); + PatchApi api = api(PatchApi.class, server.url("/").toString()); try { String result = api.patch("", "foo"); assertEquals(server.getRequestCount(), 2); @@ -114,10 +115,10 @@ public class OkHttpCommandExecutorServiceTest extends BaseHttpCommandExecutorSer // Verify that the body was properly sent in the two requests RecordedRequest request = server.takeRequest(); assertEquals(request.getMethod(), "PATCH"); - assertEquals(new String(request.getBody(), Charsets.UTF_8), "foo"); + assertEquals(request.getBody().readUtf8(), "foo"); request = server.takeRequest(); assertEquals(request.getMethod(), "PATCH"); - assertEquals(new String(request.getBody(), Charsets.UTF_8), "foo"); + assertEquals(request.getBody().readUtf8(), "foo"); } finally { closeQuietly(api); server.shutdown(); @@ -127,10 +128,10 @@ public class OkHttpCommandExecutorServiceTest extends BaseHttpCommandExecutorSer @Test public void testPatchRedirect() throws Exception { MockWebServer redirectTarget = mockWebServer(new MockResponse().setBody("fooPATCHREDIRECT")); - redirectTarget.useHttps(sslContext.getSocketFactory(), false); + redirectTarget.useHttps(sslSocketFactory(), false); MockWebServer server = mockWebServer(new MockResponse().setResponseCode(302).setHeader("Location", - redirectTarget.getUrl("/").toString())); - PatchApi api = api(PatchApi.class, server.getUrl("/").toString()); + redirectTarget.url("/").toString())); + PatchApi api = api(PatchApi.class, server.url("/").toString()); try { String result = api.patch("", "foo"); assertEquals(result, "fooPATCHREDIRECT"); @@ -139,10 +140,10 @@ public class OkHttpCommandExecutorServiceTest extends BaseHttpCommandExecutorSer // Verify that the body was populated after the redirect RecordedRequest request = server.takeRequest(); assertEquals(request.getMethod(), "PATCH"); - assertEquals(new String(request.getBody(), Charsets.UTF_8), "foo"); + assertEquals(request.getBody().readUtf8(), "foo"); request = redirectTarget.takeRequest(); assertEquals(request.getMethod(), "PATCH"); - assertEquals(new String(request.getBody(), Charsets.UTF_8), "foo"); + assertEquals(request.getBody().readUtf8(), "foo"); } finally { closeQuietly(api); redirectTarget.shutdown(); @@ -153,25 +154,25 @@ public class OkHttpCommandExecutorServiceTest extends BaseHttpCommandExecutorSer @Test public void testZeroLengthPatch() throws Exception { MockWebServer server = mockWebServer(new MockResponse()); - PatchApi api = api(PatchApi.class, server.getUrl("/").toString()); + PatchApi api = api(PatchApi.class, server.url("/").toString()); try { api.patchNothing(""); assertEquals(server.getRequestCount(), 1); RecordedRequest request = server.takeRequest(); assertEquals(request.getMethod(), "PATCH"); - assertEquals(new String(request.getBody(), Charsets.UTF_8), ""); + assertEquals(request.getBody().readUtf8(), ""); } finally { closeQuietly(api); server.shutdown(); } } - @Test(expectedExceptions = HttpResponseException.class, expectedExceptionsMessageRegExp = ".*exhausted connection specs.*") + @Test(expectedExceptions = HttpResponseException.class, expectedExceptionsMessageRegExp = "Failed to connect to.*") public void testSSLConnectionFailsIfOnlyHttpConfigured() throws Exception { MockWebServer server = mockWebServer(new MockResponse()); - server.useHttps(sslContext.getSocketFactory(), false); + server.useHttps(sslSocketFactory(), false); Module httpConfigModule = new ConnectionSpecModule(ConnectionSpec.CLEARTEXT); - PatchApi api = api(PatchApi.class, server.getUrl("/").toString(), httpConfigModule); + PatchApi api = api(PatchApi.class, server.url("/").toString(), httpConfigModule); try { api.patchNothing(""); } finally { @@ -180,11 +181,11 @@ public class OkHttpCommandExecutorServiceTest extends BaseHttpCommandExecutorSer } } - @Test(expectedExceptions = HttpResponseException.class, expectedExceptionsMessageRegExp = ".*exhausted connection specs.*") + @Test(expectedExceptions = HttpResponseException.class, expectedExceptionsMessageRegExp = "CLEARTEXT communication not enabled for client.*") public void testHTTPConnectionFailsIfOnlySSLConfigured() throws Exception { MockWebServer server = mockWebServer(new MockResponse()); Module httpConfigModule = new ConnectionSpecModule(ConnectionSpec.MODERN_TLS); - PatchApi api = api(PatchApi.class, server.getUrl("/").toString(), httpConfigModule); + PatchApi api = api(PatchApi.class, server.url("/").toString(), httpConfigModule); try { api.patchNothing(""); } finally { @@ -197,10 +198,10 @@ public class OkHttpCommandExecutorServiceTest extends BaseHttpCommandExecutorSer public void testBothProtocolsSucceedIfSSLAndHTTPConfigured() throws Exception { MockWebServer redirectTarget = mockWebServer(new MockResponse()); MockWebServer server = mockWebServer(new MockResponse().setResponseCode(302).setHeader("Location", - redirectTarget.getUrl("/").toString())); - server.useHttps(sslContext.getSocketFactory(), false); + redirectTarget.url("/").toString())); + server.useHttps(sslSocketFactory(), false); Module httpConfigModule = new ConnectionSpecModule(ConnectionSpec.CLEARTEXT, ConnectionSpec.MODERN_TLS); - PatchApi api = api(PatchApi.class, server.getUrl("/").toString(), httpConfigModule); + PatchApi api = api(PatchApi.class, server.url("/").toString(), httpConfigModule); try { api.patchNothing(""); assertEquals(server.getRequestCount(), 1); @@ -215,15 +216,15 @@ public class OkHttpCommandExecutorServiceTest extends BaseHttpCommandExecutorSer @Test public void testRestrictedSSLProtocols() throws Exception { MockWebServer server = mockWebServer(new MockResponse()); - server.useHttps(sslContext.getSocketFactory(), false); + server.useHttps(sslSocketFactory(), false); ConnectionSpec spec = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS).tlsVersions(TlsVersion.TLS_1_2) .build(); - PatchApi api = api(PatchApi.class, server.getUrl("/").toString(), new ConnectionSpecModule(spec)); + PatchApi api = api(PatchApi.class, server.url("/").toString(), new ConnectionSpecModule(spec)); try { api.patchNothing(""); assertEquals(server.getRequestCount(), 1); RecordedRequest request = server.takeRequest(); - assertEquals(request.getSslProtocol(), "TLSv1.2"); + assertEquals(request.getTlsVersion().javaName(), "TLSv1.2"); } finally { closeQuietly(api); server.shutdown(); @@ -244,9 +245,9 @@ public class OkHttpCommandExecutorServiceTest extends BaseHttpCommandExecutorSer bind(OkHttpClientSupplier.class).toInstance(new OkHttpClientSupplier() { @Override public OkHttpClient get() { - OkHttpClient client = new OkHttpClient(); - client.setConnectionSpecs(connectionSpecs); - return client; + return new OkHttpClient.Builder() + .connectionSpecs(connectionSpecs) + .build(); } }); } diff --git a/project/pom.xml b/project/pom.xml index 564f984412..9720a7f8f3 100644 --- a/project/pom.xml +++ b/project/pom.xml @@ -232,7 +232,7 @@ 27.1-jre 4.2.3 - 2.2.0 + 3.14.9 0.1-beta1 1.0-rc3 1.4.1 @@ -407,10 +407,15 @@ ${easymock.version} - com.squareup.okhttp + com.squareup.okhttp3 mockwebserver ${okhttp.version} + + com.squareup.okhttp3 + okhttp-tls + ${okhttp.version} + diff --git a/providers/aws-ec2/pom.xml b/providers/aws-ec2/pom.xml index 729b4ec957..8f24e91c65 100644 --- a/providers/aws-ec2/pom.xml +++ b/providers/aws-ec2/pom.xml @@ -97,7 +97,7 @@ test - com.squareup.okhttp + com.squareup.okhttp3 mockwebserver test diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceApiMockTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceApiMockTest.java index e11a1dd36a..292bc20a39 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceApiMockTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/AWSEC2ComputeServiceApiMockTest.java @@ -19,6 +19,8 @@ package org.jclouds.aws.ec2.compute; import static org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions.Builder.blockUntilRunning; import static org.testng.Assert.assertEquals; +import okhttp3.mockwebserver.MockResponse; + import org.jclouds.aws.ec2.internal.BaseAWSEC2ApiMockTest; import org.jclouds.aws.ec2.options.Tenancy; import org.jclouds.compute.ComputeService; @@ -28,7 +30,6 @@ import org.jclouds.compute.predicates.NodePredicates; import org.testng.annotations.Test; import com.google.common.collect.Iterables; -import com.squareup.okhttp.mockwebserver.MockResponse; @Test(groups = "unit", testName = "AWSEC2ComputeServiceMockTest", singleThreaded = true) public class AWSEC2ComputeServiceApiMockTest extends BaseAWSEC2ApiMockTest { diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/AWSAMIApiMockTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/AWSAMIApiMockTest.java index 283ea2d1bf..28f779d9b4 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/AWSAMIApiMockTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/AWSAMIApiMockTest.java @@ -25,6 +25,8 @@ import static org.testng.Assert.assertTrue; import java.util.Map; import java.util.Set; +import okhttp3.mockwebserver.MockResponse; + import org.jclouds.aws.ec2.internal.BaseAWSEC2ApiMockTest; import org.jclouds.ec2.domain.Image; import org.jclouds.ec2.domain.Permission; @@ -34,7 +36,6 @@ import org.jclouds.ec2.options.RegisterImageOptions; import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; -import com.squareup.okhttp.mockwebserver.MockResponse; @Test(groups = "unit", testName = "AWSAMIApiMockTest", singleThreaded = true) public class AWSAMIApiMockTest extends BaseAWSEC2ApiMockTest { diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/AWSSecurityGroupApiMockTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/AWSSecurityGroupApiMockTest.java index 4d6b3822e2..b937e5dcd3 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/AWSSecurityGroupApiMockTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/AWSSecurityGroupApiMockTest.java @@ -20,6 +20,8 @@ import static org.testng.Assert.assertEquals; import java.util.Set; +import okhttp3.mockwebserver.MockResponse; + import org.jclouds.aws.ec2.internal.BaseAWSEC2ApiMockTest; import org.jclouds.aws.ec2.options.CreateSecurityGroupOptions; import org.jclouds.ec2.domain.SecurityGroup; @@ -32,7 +34,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; -import com.squareup.okhttp.mockwebserver.MockResponse; @Test(groups = "unit", testName = "AWSSecurityGroupApiMockTest", singleThreaded = true) public class AWSSecurityGroupApiMockTest extends BaseAWSEC2ApiMockTest { diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/AWSSubnetApiMockTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/AWSSubnetApiMockTest.java index 191a51b456..1bfc826dfb 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/AWSSubnetApiMockTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/AWSSubnetApiMockTest.java @@ -20,6 +20,8 @@ import static org.jclouds.aws.ec2.options.ModifySubnetAttributeOptions.Builder.m import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; +import okhttp3.mockwebserver.MockResponse; + import org.jclouds.aws.ec2.internal.BaseAWSEC2ApiMockTest; import org.jclouds.aws.ec2.options.CreateSubnetOptions; import org.jclouds.ec2.domain.Subnet; @@ -28,7 +30,6 @@ import org.testng.annotations.Test; import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Iterables; -import com.squareup.okhttp.mockwebserver.MockResponse; @Test(groups = "unit", testName = "AWSSubnetApiMockTest", singleThreaded = true) public class AWSSubnetApiMockTest extends BaseAWSEC2ApiMockTest { diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/InternetGatewayApiMockTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/InternetGatewayApiMockTest.java index ef39e93d79..4733fb3ac1 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/InternetGatewayApiMockTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/InternetGatewayApiMockTest.java @@ -25,6 +25,8 @@ import static org.testng.Assert.assertTrue; import java.util.List; +import okhttp3.mockwebserver.MockResponse; + import org.jclouds.aws.AWSResponseException; import org.jclouds.aws.ec2.domain.InternetGateway; import org.jclouds.aws.ec2.domain.InternetGatewayAttachment; @@ -37,7 +39,6 @@ import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; -import com.squareup.okhttp.mockwebserver.MockResponse; @Test(groups = "unit", testName = "InternetGatewayApiMockTest", singleThreaded = true) public class InternetGatewayApiMockTest extends BaseAWSEC2ApiMockTest { diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/PlacementGroupApiMockTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/PlacementGroupApiMockTest.java index b94c6c39f8..233b526284 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/PlacementGroupApiMockTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/PlacementGroupApiMockTest.java @@ -19,13 +19,14 @@ package org.jclouds.aws.ec2.features; import static com.google.common.collect.Iterables.getOnlyElement; import static org.testng.Assert.assertEquals; +import okhttp3.mockwebserver.MockResponse; + import org.jclouds.aws.ec2.domain.PlacementGroup; import org.jclouds.aws.ec2.internal.BaseAWSEC2ApiMockTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableSet; -import com.squareup.okhttp.mockwebserver.MockResponse; @Test(groups = "unit", testName = "PlacementGroupApiMockTest", singleThreaded = true) public class PlacementGroupApiMockTest extends BaseAWSEC2ApiMockTest { diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/RouteTableApiMockTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/RouteTableApiMockTest.java index 2541a93b7c..e8eb5db093 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/RouteTableApiMockTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/RouteTableApiMockTest.java @@ -26,6 +26,8 @@ import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; +import okhttp3.mockwebserver.MockResponse; + import org.jclouds.aws.AWSResponseException; import org.jclouds.aws.ec2.domain.Route; import org.jclouds.aws.ec2.domain.RouteTable; @@ -34,7 +36,6 @@ import org.testng.Assert; import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; -import com.squareup.okhttp.mockwebserver.MockResponse; @Test(groups = "unit", testName = "RouteTableApiMockTest", singleThreaded = true) public class RouteTableApiMockTest extends BaseAWSEC2ApiMockTest { diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/SpotInstanceApiMockTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/SpotInstanceApiMockTest.java index b2d02df601..53613bfa41 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/SpotInstanceApiMockTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/SpotInstanceApiMockTest.java @@ -24,6 +24,8 @@ import static org.testng.Assert.assertTrue; import java.util.Date; import java.util.Set; +import okhttp3.mockwebserver.MockResponse; + import org.jclouds.aws.ec2.domain.Spot; import org.jclouds.aws.ec2.domain.SpotInstanceRequest; import org.jclouds.aws.ec2.internal.BaseAWSEC2ApiMockTest; @@ -31,7 +33,6 @@ import org.testng.annotations.Test; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableSet; -import com.squareup.okhttp.mockwebserver.MockResponse; @Test(groups = "unit", testName = "SpotInstanceApiMockTest", singleThreaded = true) public class SpotInstanceApiMockTest extends BaseAWSEC2ApiMockTest { diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/VPCApiMockTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/VPCApiMockTest.java index c13520757c..2857dc33fb 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/VPCApiMockTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/VPCApiMockTest.java @@ -21,6 +21,8 @@ import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; +import okhttp3.mockwebserver.MockResponse; + import org.jclouds.aws.ec2.domain.VPC; import org.jclouds.aws.ec2.internal.BaseAWSEC2ApiMockTest; import org.jclouds.aws.ec2.options.CreateVpcOptions; @@ -28,7 +30,6 @@ import org.testng.annotations.Test; import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableSet; -import com.squareup.okhttp.mockwebserver.MockResponse; @Test(groups = "unit", testName = "VPCApiMockTest", singleThreaded = true) public class VPCApiMockTest extends BaseAWSEC2ApiMockTest { diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/internal/BaseAWSEC2ApiMockTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/internal/BaseAWSEC2ApiMockTest.java index fab1f50576..b84235eb91 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/internal/BaseAWSEC2ApiMockTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/internal/BaseAWSEC2ApiMockTest.java @@ -33,6 +33,10 @@ import java.util.Set; import javax.ws.rs.core.Response; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.Constants; import org.jclouds.ContextBuilder; import org.jclouds.aws.ec2.AWSEC2Api; @@ -48,14 +52,10 @@ import org.jclouds.rest.ConfiguresHttpApi; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; -import com.google.common.base.Charsets; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; import com.google.inject.Module; import com.google.inject.Provides; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; /** * Tests need to run {@code singleThreaded = true} as otherwise tests will clash on the regionToServers field. @@ -84,7 +84,7 @@ public class BaseAWSEC2ApiMockTest { overrides.setProperty(ComputeServiceProperties.TIMEOUT_CLEANUP_INCIDENTAL_RESOURCES, "0"); return ContextBuilder.newBuilder(new AWSEC2ProviderMetadata()) .credentials(ACCESS_KEY, SECRET_KEY) - .endpoint(defaultServer.getUrl("").toString()) + .endpoint(defaultServer.url("").toString()) .overrides(overrides) .modules(modules); } @@ -122,7 +122,7 @@ public class BaseAWSEC2ApiMockTest { @BeforeMethod(alwaysRun = true) public void start() throws IOException { MockWebServer server = new MockWebServer(); - server.play(); + server.start(); regionToServers.put(DEFAULT_REGION, server); } @@ -145,11 +145,11 @@ public class BaseAWSEC2ApiMockTest { describeRegionsResponse.append("").append(region).append(""); if (!regionToServers.containsKey(region)) { MockWebServer server = new MockWebServer(); - server.play(); + server.start(); regionToServers.put(region, server); } MockWebServer server = regionToServers.get(region); - String regionEndpoint = server.getUrl("").toString(); + String regionEndpoint = server.url("").toString(); describeRegionsResponse.append("").append(regionEndpoint).append(""); describeRegionsResponse.append(""); } @@ -196,7 +196,7 @@ public class BaseAWSEC2ApiMockTest { assertThat( request.getHeader(AUTHORIZATION)).startsWith("AWS4-HMAC-SHA256 Credential=AKIAIOSFODNN7EXAMPLE/20120416/" + region + "/ec2/aws4_request, SignedHeaders=content-type;host;x-amz-date, Signature="); - String body = new String(request.getBody(), Charsets.UTF_8); + String body = request.getBody().readUtf8(); assertThat(body).contains("&Version=" + apiVersion); assertEquals(body.replace("&Version=" + apiVersion, ""), postParams); return request; diff --git a/providers/aws-s3/pom.xml b/providers/aws-s3/pom.xml index 690edf9f45..bd4fbedecc 100644 --- a/providers/aws-s3/pom.xml +++ b/providers/aws-s3/pom.xml @@ -90,7 +90,7 @@ test - com.squareup.okhttp + com.squareup.okhttp3 mockwebserver test diff --git a/providers/azurecompute-arm/pom.xml b/providers/azurecompute-arm/pom.xml index df00c7c074..5632468abc 100644 --- a/providers/azurecompute-arm/pom.xml +++ b/providers/azurecompute-arm/pom.xml @@ -113,7 +113,7 @@ test - com.squareup.okhttp + com.squareup.okhttp3 mockwebserver test diff --git a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/DeploymentApiMockTest.java b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/DeploymentApiMockTest.java index 89d6acaba7..da12e90948 100644 --- a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/DeploymentApiMockTest.java +++ b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/DeploymentApiMockTest.java @@ -16,9 +16,10 @@ */ package org.jclouds.azurecompute.arm.features; +import okhttp3.mockwebserver.MockResponse; + import org.jclouds.azurecompute.arm.domain.Deployment; import org.jclouds.azurecompute.arm.domain.Deployment.ProvisioningState; -import com.squareup.okhttp.mockwebserver.MockResponse; import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiMockTest; import org.testng.annotations.Test; diff --git a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/JobApiMockTest.java b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/JobApiMockTest.java index 736414596e..6a9474e6d3 100644 --- a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/JobApiMockTest.java +++ b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/JobApiMockTest.java @@ -54,7 +54,7 @@ public class JobApiMockTest extends BaseAzureComputeApiMockTest { } public void testGetJobStatusNoContent() throws InterruptedException { - server.enqueue(jsonResponse("/resourcegroup.json").setStatus("HTTP/1.1 204 No Content")); + server.enqueue(response204()); JobStatus status = api.getJobApi().jobStatus(URI.create(requestUrl)); diff --git a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LocationApiMockTest.java b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LocationApiMockTest.java index 50ecbe722f..7babccf609 100644 --- a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LocationApiMockTest.java +++ b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/LocationApiMockTest.java @@ -17,7 +17,9 @@ package org.jclouds.azurecompute.arm.features; import com.google.common.collect.ImmutableList; -import com.squareup.okhttp.mockwebserver.MockResponse; + +import okhttp3.mockwebserver.MockResponse; + import org.jclouds.azurecompute.arm.domain.Location; import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiMockTest; import org.testng.annotations.Test; diff --git a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/MetricDefinitionsApiMockTest.java b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/MetricDefinitionsApiMockTest.java index 8fd06b8d6f..5fe82c1ed8 100644 --- a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/MetricDefinitionsApiMockTest.java +++ b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/MetricDefinitionsApiMockTest.java @@ -19,13 +19,14 @@ package org.jclouds.azurecompute.arm.features; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; +import okhttp3.mockwebserver.MockResponse; + import org.jclouds.azurecompute.arm.domain.MetricDefinition; import org.jclouds.azurecompute.arm.domain.MetricName; import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiMockTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; -import com.squareup.okhttp.mockwebserver.MockResponse; @Test(groups = "unit", testName = "MetricDefinitionsApiMockTest", singleThreaded = true) public class MetricDefinitionsApiMockTest extends BaseAzureComputeApiMockTest { diff --git a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/MetricsApiMockTest.java b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/MetricsApiMockTest.java index 2001d193e1..069015aad1 100644 --- a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/MetricsApiMockTest.java +++ b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/MetricsApiMockTest.java @@ -21,6 +21,8 @@ import static org.testng.Assert.assertTrue; import java.util.Date; +import okhttp3.mockwebserver.MockResponse; + import org.jclouds.azurecompute.arm.domain.Metric; import org.jclouds.azurecompute.arm.domain.MetricData; import org.jclouds.azurecompute.arm.domain.MetricName; @@ -28,7 +30,6 @@ import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiMockTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; -import com.squareup.okhttp.mockwebserver.MockResponse; @Test(groups = "unit", testName = "MetricsApiMockTest", singleThreaded = true) public class MetricsApiMockTest extends BaseAzureComputeApiMockTest { diff --git a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/NetworkInterfaceCardApiMockTest.java b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/NetworkInterfaceCardApiMockTest.java index c00fad68c9..44acabc7ee 100644 --- a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/NetworkInterfaceCardApiMockTest.java +++ b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/NetworkInterfaceCardApiMockTest.java @@ -26,6 +26,8 @@ import java.util.Arrays; import java.util.List; import java.util.Map; +import okhttp3.mockwebserver.MockResponse; + import org.jclouds.azurecompute.arm.domain.IdReference; import org.jclouds.azurecompute.arm.domain.IpConfiguration; import org.jclouds.azurecompute.arm.domain.IpConfigurationProperties; @@ -35,7 +37,6 @@ import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiMockTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; -import com.squareup.okhttp.mockwebserver.MockResponse; @Test(groups = "unit", testName = "NetworkInterfaceCardApiMockTest", singleThreaded = true) public class NetworkInterfaceCardApiMockTest extends BaseAzureComputeApiMockTest { diff --git a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/PublicIPAddressApiMockTest.java b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/PublicIPAddressApiMockTest.java index 882b9d6dfd..17cbb5fe08 100644 --- a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/PublicIPAddressApiMockTest.java +++ b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/PublicIPAddressApiMockTest.java @@ -27,6 +27,8 @@ import static org.testng.Assert.assertTrue; import java.util.List; import java.util.Map; +import okhttp3.mockwebserver.MockResponse; + import org.jclouds.azurecompute.arm.AzureComputeProviderMetadata; import org.jclouds.azurecompute.arm.domain.DnsSettings; import org.jclouds.azurecompute.arm.domain.publicipaddress.PublicIPAddress; @@ -36,7 +38,6 @@ import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiMockTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; -import com.squareup.okhttp.mockwebserver.MockResponse; @Test(groups = "unit", testName = "PublicIPAddressApiMockTest", singleThreaded = true) diff --git a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/StorageAccountApiMockTest.java b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/StorageAccountApiMockTest.java index e3fdf6d56b..87e1da979b 100644 --- a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/StorageAccountApiMockTest.java +++ b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/StorageAccountApiMockTest.java @@ -19,11 +19,12 @@ package org.jclouds.azurecompute.arm.features; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import okhttp3.mockwebserver.MockResponse; + import org.jclouds.azurecompute.arm.domain.StorageService; import org.jclouds.azurecompute.arm.domain.Availability; import org.jclouds.azurecompute.arm.domain.StorageServiceKeys; import org.jclouds.azurecompute.arm.domain.StorageServiceUpdateParams; -import com.squareup.okhttp.mockwebserver.MockResponse; import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiMockTest; import org.jclouds.date.DateService; import org.jclouds.date.internal.SimpleDateFormatDateService; diff --git a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VMSizeApiMockTest.java b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VMSizeApiMockTest.java index 6717e8bbfd..f26aebac57 100644 --- a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VMSizeApiMockTest.java +++ b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VMSizeApiMockTest.java @@ -16,7 +16,8 @@ */ package org.jclouds.azurecompute.arm.features; -import com.squareup.okhttp.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockResponse; + import org.jclouds.azurecompute.arm.domain.VMSize; import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiMockTest; import org.testng.annotations.Test; diff --git a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VaultApiMockTest.java b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VaultApiMockTest.java index be3ae74c7e..161640f82a 100644 --- a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VaultApiMockTest.java +++ b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VaultApiMockTest.java @@ -128,7 +128,7 @@ public class VaultApiMockTest extends BaseAzureComputeApiMockTest { @BeforeMethod public void start() throws IOException, URISyntaxException { super.start(); - vaultUri = server.getUrl("").toURI(); + vaultUri = server.url("").uri(); } public void createVault() throws InterruptedException { diff --git a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VirtualMachineApiMockTest.java b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VirtualMachineApiMockTest.java index e96d540299..543282da33 100644 --- a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VirtualMachineApiMockTest.java +++ b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VirtualMachineApiMockTest.java @@ -29,6 +29,8 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import okhttp3.mockwebserver.MockResponse; + import org.jclouds.azurecompute.arm.domain.DataDisk; import org.jclouds.azurecompute.arm.domain.DiagnosticsProfile; import org.jclouds.azurecompute.arm.domain.HardwareProfile; @@ -58,7 +60,6 @@ import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.squareup.okhttp.mockwebserver.MockResponse; @Test(groups = "unit", testName = "VirtualMachineApiMockTest", singleThreaded = true) public class VirtualMachineApiMockTest extends BaseAzureComputeApiMockTest { diff --git a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/internal/BaseAzureComputeApiMockTest.java b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/internal/BaseAzureComputeApiMockTest.java index 20a1ab7af5..5932919e06 100644 --- a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/internal/BaseAzureComputeApiMockTest.java +++ b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/internal/BaseAzureComputeApiMockTest.java @@ -30,6 +30,10 @@ import java.net.URISyntaxException; import java.util.Properties; import java.util.Set; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.ContextBuilder; import org.jclouds.azurecompute.arm.AzureComputeApi; import org.jclouds.azurecompute.arm.AzureComputeProviderMetadata; @@ -54,9 +58,7 @@ import com.google.common.io.Resources; import com.google.gson.JsonParser; import com.google.inject.Module; import com.google.inject.TypeLiteral; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; + public class BaseAzureComputeApiMockTest { @@ -74,11 +76,11 @@ public class BaseAzureComputeApiMockTest { @BeforeMethod public void start() throws IOException, URISyntaxException { server = new MockWebServer(); - server.play(); + server.start(); context = ContextBuilder.newBuilder(testProviderMetadata()) .credentials("mock", MOCK_BEARER_TOKEN) - .endpoint(server.getUrl("/").toString() + "subscriptions/SUBSCRIPTIONID") + .endpoint(server.url("/").toString() + "subscriptions/SUBSCRIPTIONID") .modules(setupModules()) .overrides(setupProperties()) .build(); @@ -118,7 +120,7 @@ public class BaseAzureComputeApiMockTest { } protected String url(String path) { - return server.getUrl(path).toString(); + return server.url(path).toString(); } protected MockResponse jsonResponse(String resource) { @@ -180,7 +182,7 @@ public class BaseAzureComputeApiMockTest { throws InterruptedException { RecordedRequest request = assertSent(server, method, path); assertEquals(request.getHeader("Content-Type"), "application/json"); - assertEquals(parser.parse(new String(request.getBody(), Charsets.UTF_8)), parser.parse(json)); + assertEquals(parser.parse(request.getBody().readUtf8()), parser.parse(json)); return request; } @@ -197,7 +199,7 @@ public class BaseAzureComputeApiMockTest { // Override the hardcoded service URIs to allow mocking service endpoints bind(new TypeLiteral>() { }).annotatedWith(GraphRBAC.class).toInstance( - Suppliers.ofInstance(URI.create(server.getUrl("/graphrbac").toString() + "/tenant-id"))); + Suppliers.ofInstance(URI.create(server.url("/graphrbac").toString() + "/tenant-id"))); } } } diff --git a/providers/b2/pom.xml b/providers/b2/pom.xml index 314b422679..7293047512 100644 --- a/providers/b2/pom.xml +++ b/providers/b2/pom.xml @@ -76,7 +76,7 @@ provided - com.squareup.okhttp + com.squareup.okhttp3 mockwebserver test diff --git a/providers/b2/src/test/java/org/jclouds/b2/features/B2TestUtils.java b/providers/b2/src/test/java/org/jclouds/b2/features/B2TestUtils.java index 50b387e753..391a82e9d9 100644 --- a/providers/b2/src/test/java/org/jclouds/b2/features/B2TestUtils.java +++ b/providers/b2/src/test/java/org/jclouds/b2/features/B2TestUtils.java @@ -23,20 +23,21 @@ import java.net.URL; import java.util.Set; import java.util.Properties; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.ContextBuilder; import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.b2.B2Api; import org.jclouds.util.Strings2; -import com.google.common.base.Charsets; import com.google.common.base.Throwables; import com.google.common.collect.ImmutableSet; import com.google.common.util.concurrent.MoreExecutors; import com.google.gson.JsonElement; import com.google.gson.JsonParser; import com.google.inject.Module; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; + final class B2TestUtils { static B2Api api(String uri, String provider, Properties overrides) { @@ -57,8 +58,8 @@ final class B2TestUtils { static MockWebServer createMockWebServer() throws IOException { MockWebServer server = new MockWebServer(); - server.play(); - URL url = server.getUrl(""); + server.start(); + URL url = server.url("").url(); return server; } @@ -104,7 +105,7 @@ final class B2TestUtils { JsonParser parser = new JsonParser(); JsonElement requestJson; try { - requestJson = parser.parse(new String(request.getBody(), Charsets.UTF_8)); + requestJson = parser.parse(request.getBody().readUtf8()); } catch (Exception e) { throw Throwables.propagate(e); } @@ -119,7 +120,7 @@ final class B2TestUtils { * @see RecordedRequest */ private static void assertContentTypeIsJson(RecordedRequest request) { - assertThat(request.getHeaders()).contains("Content-Type: application/json"); + assertThat(request.getHeaders().values("Content-Type")).contains("application/json"); } /** diff --git a/providers/b2/src/test/java/org/jclouds/b2/features/BucketApiMockTest.java b/providers/b2/src/test/java/org/jclouds/b2/features/BucketApiMockTest.java index 38fde65c67..98b50a2287 100644 --- a/providers/b2/src/test/java/org/jclouds/b2/features/BucketApiMockTest.java +++ b/providers/b2/src/test/java/org/jclouds/b2/features/BucketApiMockTest.java @@ -23,13 +23,14 @@ import static org.jclouds.b2.features.B2TestUtils.assertRequest; import static org.jclouds.b2.features.B2TestUtils.createMockWebServer; import static org.jclouds.b2.features.B2TestUtils.stringFromResource; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.b2.domain.Bucket; import org.jclouds.b2.domain.BucketList; import org.jclouds.b2.domain.BucketType; import org.testng.annotations.Test; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; @Test(groups = "unit", testName = "BucketApiMockTest") public final class BucketApiMockTest { @@ -39,7 +40,7 @@ public final class BucketApiMockTest { server.enqueue(new MockResponse().setBody(stringFromResource("/bucket.json"))); try { - BucketApi api = api(server.getUrl("/").toString(), "b2").getBucketApi(); + BucketApi api = api(server.url("/").toString(), "b2").getBucketApi(); Bucket response = api.createBucket("any_name_you_pick", BucketType.ALL_PRIVATE); assertThat(response.bucketId()).isEqualTo("4a48fe8875c6214145260818"); assertThat(response.bucketName()).isEqualTo("any_name_you_pick"); @@ -59,7 +60,7 @@ public final class BucketApiMockTest { server.enqueue(new MockResponse().setBody(stringFromResource("/bucket.json"))); try { - BucketApi api = api(server.getUrl("/").toString(), "b2").getBucketApi(); + BucketApi api = api(server.url("/").toString(), "b2").getBucketApi(); Bucket response = api.deleteBucket("4a48fe8875c6214145260818"); assertThat(response.bucketId()).isEqualTo("4a48fe8875c6214145260818"); assertThat(response.bucketName()).isEqualTo("any_name_you_pick"); @@ -79,7 +80,7 @@ public final class BucketApiMockTest { server.enqueue(new MockResponse().setResponseCode(400).setBody(stringFromResource("/delete_bucket_already_deleted_response.json"))); try { - BucketApi api = api(server.getUrl("/").toString(), "b2").getBucketApi(); + BucketApi api = api(server.url("/").toString(), "b2").getBucketApi(); Bucket response = api.deleteBucket("4a48fe8875c6214145260818"); assertThat(response).isNull(); @@ -97,7 +98,7 @@ public final class BucketApiMockTest { server.enqueue(new MockResponse().setBody(stringFromResource("/bucket.json"))); try { - BucketApi api = api(server.getUrl("/").toString(), "b2").getBucketApi(); + BucketApi api = api(server.url("/").toString(), "b2").getBucketApi(); Bucket response = api.updateBucket("4a48fe8875c6214145260818", BucketType.ALL_PRIVATE); assertThat(response.bucketId()).isEqualTo("4a48fe8875c6214145260818"); assertThat(response.bucketName()).isEqualTo("any_name_you_pick"); @@ -117,7 +118,7 @@ public final class BucketApiMockTest { server.enqueue(new MockResponse().setBody(stringFromResource("/list_buckets_response.json"))); try { - BucketApi api = api(server.getUrl("/").toString(), "b2").getBucketApi(); + BucketApi api = api(server.url("/").toString(), "b2").getBucketApi(); BucketList response = api.listBuckets(); assertThat(response.buckets()).hasSize(3); diff --git a/providers/b2/src/test/java/org/jclouds/b2/features/MultipartApiMockTest.java b/providers/b2/src/test/java/org/jclouds/b2/features/MultipartApiMockTest.java index 7fc8af62ac..b646a9f1c6 100644 --- a/providers/b2/src/test/java/org/jclouds/b2/features/MultipartApiMockTest.java +++ b/providers/b2/src/test/java/org/jclouds/b2/features/MultipartApiMockTest.java @@ -28,6 +28,9 @@ import java.util.Collection; import java.util.Date; import java.util.Map; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.io.Payload; import org.jclouds.io.Payloads; import org.jclouds.b2.domain.Action; @@ -42,8 +45,7 @@ import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; + @Test(groups = "unit", testName = "MultipartApiMockTest") public final class MultipartApiMockTest { @@ -64,7 +66,7 @@ public final class MultipartApiMockTest { server.enqueue(new MockResponse().setBody(stringFromResource("/start_large_file_response.json"))); try { - MultipartApi api = api(server.getUrl("/").toString(), "b2").getMultipartApi(); + MultipartApi api = api(server.url("/").toString(), "b2").getMultipartApi(); MultipartUploadResponse response = api.startLargeFile(BUCKET_ID, FILE_NAME, CONTENT_TYPE, FILE_INFO); assertThat(response.accountId()).isEqualTo(ACCOUNT_ID); assertThat(response.bucketId()).isEqualTo(BUCKET_ID); @@ -88,7 +90,7 @@ public final class MultipartApiMockTest { server.enqueue(new MockResponse().setBody(stringFromResource("/cancel_large_file_response.json"))); try { - MultipartApi api = api(server.getUrl("/").toString(), "b2").getMultipartApi(); + MultipartApi api = api(server.url("/").toString(), "b2").getMultipartApi(); B2Object response = api.cancelLargeFile(FILE_ID); assertThat(response.accountId()).isEqualTo(ACCOUNT_ID); assertThat(response.bucketId()).isEqualTo(BUCKET_ID); @@ -112,7 +114,7 @@ public final class MultipartApiMockTest { "ffffffffffffffffffffffffffffffffffffffff"); try { - MultipartApi api = api(server.getUrl("/").toString(), "b2").getMultipartApi(); + MultipartApi api = api(server.url("/").toString(), "b2").getMultipartApi(); B2Object response = api.finishLargeFile(FILE_ID, sha1); assertThat(response.accountId()).isEqualTo(ACCOUNT_ID); assertThat(response.action()).isEqualTo(Action.UPLOAD); @@ -139,7 +141,7 @@ public final class MultipartApiMockTest { server.enqueue(new MockResponse().setBody(stringFromResource("/get_upload_part_url_response.json"))); try { - MultipartApi api = api(server.getUrl("/").toString(), "b2").getMultipartApi(); + MultipartApi api = api(server.url("/").toString(), "b2").getMultipartApi(); GetUploadPartResponse response = api.getUploadPartUrl(FILE_ID); assertThat(response.authorizationToken()).isEqualTo(AUTHORIZATION_TOKEN); assertThat(response.fileId()).isEqualTo(FILE_ID); @@ -158,8 +160,8 @@ public final class MultipartApiMockTest { server.enqueue(new MockResponse().setBody(stringFromResource("/upload_part_response.json"))); try { - MultipartApi api = api(server.getUrl("/").toString(), "b2").getMultipartApi(); - GetUploadPartResponse uploadPart = GetUploadPartResponse.create(FILE_ID, server.getUrl("/b2api/v2/b2_upload_part/4a48fe8875c6214145260818/c001_v0001007_t0042").toURI(), AUTHORIZATION_TOKEN); + MultipartApi api = api(server.url("/").toString(), "b2").getMultipartApi(); + GetUploadPartResponse uploadPart = GetUploadPartResponse.create(FILE_ID, server.url("/b2api/v2/b2_upload_part/4a48fe8875c6214145260818/c001_v0001007_t0042").uri(), AUTHORIZATION_TOKEN); long contentLength = 100 * 1000 * 1000; Payload payload = Payloads.newByteSourcePayload(TestUtils.randomByteSource().slice(0, contentLength)); payload.getContentMetadata().setContentLength(contentLength); @@ -182,7 +184,7 @@ public final class MultipartApiMockTest { server.enqueue(new MockResponse().setBody(stringFromResource("/list_parts_response.json"))); try { - MultipartApi api = api(server.getUrl("/").toString(), "b2").getMultipartApi(); + MultipartApi api = api(server.url("/").toString(), "b2").getMultipartApi(); ListPartsResponse response = api.listParts(FILE_ID, 1, 1000); assertThat(response.nextPartNumber()).isNull(); assertThat(response.parts()).hasSize(3); @@ -222,7 +224,7 @@ public final class MultipartApiMockTest { server.enqueue(new MockResponse().setBody(stringFromResource("/list_unfinished_large_files_response.json"))); try { - MultipartApi api = api(server.getUrl("/").toString(), "b2").getMultipartApi(); + MultipartApi api = api(server.url("/").toString(), "b2").getMultipartApi(); ListUnfinishedLargeFilesResponse response = api.listUnfinishedLargeFiles(BUCKET_ID, FILE_ID, 1000); assertThat(response.nextFileId()).isNull(); assertThat(response.files()).hasSize(1); diff --git a/providers/b2/src/test/java/org/jclouds/b2/features/ObjectApiMockTest.java b/providers/b2/src/test/java/org/jclouds/b2/features/ObjectApiMockTest.java index 5b86dc1372..29778f9886 100644 --- a/providers/b2/src/test/java/org/jclouds/b2/features/ObjectApiMockTest.java +++ b/providers/b2/src/test/java/org/jclouds/b2/features/ObjectApiMockTest.java @@ -28,6 +28,10 @@ import java.net.URI; import java.util.Date; import java.util.Map; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.blobstore.ContainerNotFoundException; import org.jclouds.blobstore.KeyNotFoundException; import org.jclouds.http.options.GetOptions; @@ -45,9 +49,7 @@ import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; import com.google.common.net.HttpHeaders; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; + @Test(groups = "unit", testName = "ObjectApiMockTest") public final class ObjectApiMockTest { @@ -66,7 +68,7 @@ public final class ObjectApiMockTest { server.enqueue(new MockResponse().setBody(stringFromResource("/get_upload_url_response.json"))); try { - ObjectApi api = api(server.getUrl("/").toString(), "b2").getObjectApi(); + ObjectApi api = api(server.url("/").toString(), "b2").getObjectApi(); UploadUrlResponse response = api.getUploadUrl(BUCKET_ID); assertThat(response.bucketId()).isEqualTo(BUCKET_ID); assertThat(response.uploadUrl()).isEqualTo(URI.create("https://pod-000-1005-03.backblaze.com/b2api/v2/b2_upload_file?cvt=c001_v0001005_t0027&bucket=4a48fe8875c6214145260818")); @@ -86,7 +88,7 @@ public final class ObjectApiMockTest { server.enqueue(new MockResponse().setResponseCode(400).setBody(stringFromResource("/get_upload_url_deleted_bucket_response.json"))); try { - ObjectApi api = api(server.getUrl("/").toString(), "b2").getObjectApi(); + ObjectApi api = api(server.url("/").toString(), "b2").getObjectApi(); try { api.getUploadUrl(BUCKET_ID); failBecauseExceptionWasNotThrown(ContainerNotFoundException.class); @@ -107,10 +109,10 @@ public final class ObjectApiMockTest { server.enqueue(new MockResponse().setBody(stringFromResource("/upload_file_response.json"))); try { - ObjectApi api = api(server.getUrl("/").toString(), "b2").getObjectApi(); + ObjectApi api = api(server.url("/").toString(), "b2").getObjectApi(); String accountId = "d522aa47a10f"; - UploadUrlResponse uploadUrl = UploadUrlResponse.create(BUCKET_ID, server.getUrl("/b2api/v2/b2_upload_file/4a48fe8875c6214145260818/c001_v0001007_t0042").toURI(), "FAKE-AUTHORIZATION-TOKEN"); + UploadUrlResponse uploadUrl = UploadUrlResponse.create(BUCKET_ID, server.url("/b2api/v2/b2_upload_file/4a48fe8875c6214145260818/c001_v0001007_t0042").uri(), "FAKE-AUTHORIZATION-TOKEN"); Payload payload = Payloads.newStringPayload(PAYLOAD); payload.getContentMetadata().setContentType(CONTENT_TYPE); UploadFileResponse response = api.uploadFile(uploadUrl, FILE_NAME, SHA1, FILE_INFO, payload); @@ -137,7 +139,7 @@ public final class ObjectApiMockTest { server.enqueue(new MockResponse().setBody(stringFromResource("/delete_object_response.json"))); try { - ObjectApi api = api(server.getUrl("/").toString(), "b2").getObjectApi(); + ObjectApi api = api(server.url("/").toString(), "b2").getObjectApi(); DeleteFileResponse response = api.deleteFileVersion(FILE_NAME, FILE_ID); assertThat(response.fileName()).isEqualTo(FILE_NAME); assertThat(response.fileId()).isEqualTo(FILE_ID); @@ -156,7 +158,7 @@ public final class ObjectApiMockTest { server.enqueue(new MockResponse().setResponseCode(400).setBody(stringFromResource("/delete_file_version_already_deleted_response.json"))); try { - ObjectApi api = api(server.getUrl("/").toString(), "b2").getObjectApi(); + ObjectApi api = api(server.url("/").toString(), "b2").getObjectApi(); try { api.deleteFileVersion(FILE_NAME, FILE_ID); failBecauseExceptionWasNotThrown(KeyNotFoundException.class); @@ -178,7 +180,7 @@ public final class ObjectApiMockTest { server.enqueue(new MockResponse().setBody(stringFromResource("/get_file_info_response.json"))); try { - ObjectApi api = api(server.getUrl("/").toString(), "b2").getObjectApi(); + ObjectApi api = api(server.url("/").toString(), "b2").getObjectApi(); B2Object b2Object = api.getFileInfo("4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001"); assertThat(b2Object.fileId()).isEqualTo("4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001"); assertThat(b2Object.fileName()).isEqualTo("akitty.jpg"); @@ -206,7 +208,7 @@ public final class ObjectApiMockTest { server.enqueue(new MockResponse().setResponseCode(404).setBody(stringFromResource("/get_file_info_deleted_file_response.json"))); try { - ObjectApi api = api(server.getUrl("/").toString(), "b2").getObjectApi(); + ObjectApi api = api(server.url("/").toString(), "b2").getObjectApi(); B2Object b2Object = api.getFileInfo("4_ze73ede9c9c8412db49f60715_f100b4e93fbae6252_d20150824_m224353_c900_v8881000_t0001"); assertThat(b2Object).isNull(); @@ -232,7 +234,7 @@ public final class ObjectApiMockTest { .setBody(PAYLOAD)); try { - ObjectApi api = api(server.getUrl("/").toString(), "b2").getObjectApi(); + ObjectApi api = api(server.url("/").toString(), "b2").getObjectApi(); B2Object b2Object = api.downloadFileById(FILE_ID); @@ -272,7 +274,7 @@ public final class ObjectApiMockTest { .setBody(PAYLOAD)); try { - ObjectApi api = api(server.getUrl("/").toString(), "b2").getObjectApi(); + ObjectApi api = api(server.url("/").toString(), "b2").getObjectApi(); B2Object b2Object = api.downloadFileById(FILE_ID, new GetOptions().range(42, 69)); @@ -285,7 +287,7 @@ public final class ObjectApiMockTest { request = server.takeRequest(); assertThat(request.getMethod()).isEqualTo("GET"); assertThat(request.getPath()).isEqualTo("/b2api/v2/b2_download_file_by_id?fileId=4_h4a48fe8875c6214145260818_f000000000000472a_d20140104_m032022_c001_v0000123_t0104"); - assertThat(request.getHeaders()).contains("Range: bytes=42-69"); + assertThat(request.getHeaders().values("Range")).contains("bytes=42-69"); } finally { server.shutdown(); } @@ -305,7 +307,7 @@ public final class ObjectApiMockTest { .setBody(PAYLOAD)); try { - ObjectApi api = api(server.getUrl("/").toString(), "b2").getObjectApi(); + ObjectApi api = api(server.url("/").toString(), "b2").getObjectApi(); B2Object b2Object = api.downloadFileByName(BUCKET_NAME, FILE_NAME); @@ -337,7 +339,7 @@ public final class ObjectApiMockTest { server.enqueue(new MockResponse().setBody(stringFromResource("/list_file_names_response.json"))); try { - ObjectApi api = api(server.getUrl("/").toString(), "b2").getObjectApi(); + ObjectApi api = api(server.url("/").toString(), "b2").getObjectApi(); String accountId = "d522aa47a10f"; B2ObjectList list = api.listFileNames(BUCKET_ID, null, null, null, null); @@ -373,7 +375,7 @@ public final class ObjectApiMockTest { server.enqueue(new MockResponse().setBody(stringFromResource("/list_file_versions_response.json"))); try { - ObjectApi api = api(server.getUrl("/").toString(), "b2").getObjectApi(); + ObjectApi api = api(server.url("/").toString(), "b2").getObjectApi(); String accountId = "d522aa47a10f"; B2ObjectList list = api.listFileVersions(BUCKET_ID, null, null, null, null, null); @@ -417,7 +419,7 @@ public final class ObjectApiMockTest { server.enqueue(new MockResponse().setBody(stringFromResource("/hide_file_response.json"))); try { - ObjectApi api = api(server.getUrl("/").toString(), "b2").getObjectApi(); + ObjectApi api = api(server.url("/").toString(), "b2").getObjectApi(); String accountId = "d522aa47a10f"; HideFileResponse response = api.hideFile(BUCKET_ID, FILE_NAME); diff --git a/providers/digitalocean2/pom.xml b/providers/digitalocean2/pom.xml index cb1446bc94..0254f303bf 100644 --- a/providers/digitalocean2/pom.xml +++ b/providers/digitalocean2/pom.xml @@ -96,7 +96,7 @@ test - com.squareup.okhttp + com.squareup.okhttp3 mockwebserver test diff --git a/providers/digitalocean2/src/test/java/org/jclouds/digitalocean2/exceptions/RateLimitExceptionMockTest.java b/providers/digitalocean2/src/test/java/org/jclouds/digitalocean2/exceptions/RateLimitExceptionMockTest.java index 6b90626d20..d27b9e58bf 100644 --- a/providers/digitalocean2/src/test/java/org/jclouds/digitalocean2/exceptions/RateLimitExceptionMockTest.java +++ b/providers/digitalocean2/src/test/java/org/jclouds/digitalocean2/exceptions/RateLimitExceptionMockTest.java @@ -24,10 +24,11 @@ import static org.testng.Assert.fail; import java.util.Properties; +import okhttp3.mockwebserver.MockResponse; + import org.jclouds.digitalocean2.internal.BaseDigitalOcean2ApiMockTest; import org.testng.annotations.Test; -import com.squareup.okhttp.mockwebserver.MockResponse; @Test(groups = "unit", testName = "RateLimitExceptionMockTest", singleThreaded = true) public class RateLimitExceptionMockTest extends BaseDigitalOcean2ApiMockTest { diff --git a/providers/digitalocean2/src/test/java/org/jclouds/digitalocean2/internal/BaseDigitalOcean2ApiMockTest.java b/providers/digitalocean2/src/test/java/org/jclouds/digitalocean2/internal/BaseDigitalOcean2ApiMockTest.java index 16f92c6975..80667ea8e6 100644 --- a/providers/digitalocean2/src/test/java/org/jclouds/digitalocean2/internal/BaseDigitalOcean2ApiMockTest.java +++ b/providers/digitalocean2/src/test/java/org/jclouds/digitalocean2/internal/BaseDigitalOcean2ApiMockTest.java @@ -26,6 +26,10 @@ import java.util.Map; import java.util.Properties; import java.util.Set; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.ContextBuilder; import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.digitalocean2.DigitalOcean2Api; @@ -42,9 +46,7 @@ import com.google.common.io.Resources; import com.google.common.reflect.TypeToken; import com.google.gson.JsonParser; import com.google.inject.Module; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; + public class BaseDigitalOcean2ApiMockTest { @@ -63,7 +65,7 @@ public class BaseDigitalOcean2ApiMockTest { @BeforeMethod public void start() throws IOException { server = new MockWebServer(); - server.play(); + server.start(); ApiContext ctx = ContextBuilder.newBuilder("digitalocean2") .credentials("", MOCK_BEARER_TOKEN) .endpoint(url("")) @@ -85,7 +87,7 @@ public class BaseDigitalOcean2ApiMockTest { } protected String url(String path) { - return server.getUrl(path).toString(); + return server.url(path).toString(); } protected MockResponse jsonResponse(String resource) { @@ -136,7 +138,7 @@ public class BaseDigitalOcean2ApiMockTest { throws InterruptedException { RecordedRequest request = assertSent(server, method, path); assertEquals(request.getHeader("Content-Type"), "application/json"); - assertEquals(parser.parse(new String(request.getBody(), Charsets.UTF_8)), parser.parse(json)); + assertEquals(parser.parse(request.getBody().readUtf8()), parser.parse(json)); return request; } } diff --git a/providers/dynect/pom.xml b/providers/dynect/pom.xml index 9a5ebe46d3..9019028b9d 100644 --- a/providers/dynect/pom.xml +++ b/providers/dynect/pom.xml @@ -52,7 +52,7 @@ test - com.squareup.okhttp + com.squareup.okhttp3 mockwebserver test diff --git a/providers/dynect/src/test/java/org/jclouds/dynect/v3/DynectApiMockTest.java b/providers/dynect/src/test/java/org/jclouds/dynect/v3/DynectApiMockTest.java index c5bd5b379e..a5672cd84f 100644 --- a/providers/dynect/src/test/java/org/jclouds/dynect/v3/DynectApiMockTest.java +++ b/providers/dynect/src/test/java/org/jclouds/dynect/v3/DynectApiMockTest.java @@ -24,6 +24,9 @@ import java.io.IOException; import java.util.Properties; import java.util.Set; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.ContextBuilder; import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.dynect.v3.DynECTExceptions.JobStillRunningException; @@ -32,8 +35,7 @@ import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; import com.google.inject.Module; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; + @Test(singleThreaded = true) public class DynectApiMockTest { @@ -61,9 +63,9 @@ public class DynectApiMockTest { MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse().setResponseCode(OK.getStatusCode()).setBody(session)); server.enqueue(new MockResponse().setResponseCode(OK.getStatusCode()).setBody(running)); - server.play(); + server.start(); - DynECTApi api = mockDynectApi(server.getUrl("/").toString()); + DynECTApi api = mockDynectApi(server.url("/").toString()); try { api.getZoneApi().list(); @@ -80,9 +82,9 @@ public class DynectApiMockTest { MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse().setResponseCode(OK.getStatusCode()).setBody(session)); server.enqueue(new MockResponse().setResponseCode(OK.getStatusCode()).setBody(taskBlocking)); - server.play(); + server.start(); - DynECTApi api = mockDynectApi(server.getUrl("/").toString()); + DynECTApi api = mockDynectApi(server.url("/").toString()); try { api.getZoneApi().list(); @@ -98,9 +100,9 @@ public class DynectApiMockTest { MockWebServer server = new MockWebServer(); server.enqueue(new MockResponse().setResponseCode(OK.getStatusCode()).setBody(session)); server.enqueue(new MockResponse().setResponseCode(OK.getStatusCode()).setBody(targetExists)); - server.play(); + server.start(); - DynECTApi api = mockDynectApi(server.getUrl("/").toString()); + DynECTApi api = mockDynectApi(server.url("/").toString()); try { api.getZoneApi().list(); diff --git a/providers/google-cloud-storage/pom.xml b/providers/google-cloud-storage/pom.xml index 6be1ef8a40..7c0b4da864 100644 --- a/providers/google-cloud-storage/pom.xml +++ b/providers/google-cloud-storage/pom.xml @@ -116,7 +116,7 @@ test - com.squareup.okhttp + com.squareup.okhttp3 mockwebserver test diff --git a/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiMockTest.java b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiMockTest.java index 863581b614..a371af6a07 100644 --- a/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiMockTest.java +++ b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiMockTest.java @@ -20,9 +20,11 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertFalse; -import static com.google.common.base.Charsets.UTF_8; import static javax.ws.rs.core.MediaType.APPLICATION_JSON; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.googlecloudstorage.domain.DomainResourceReferences.DestinationPredefinedAcl; import org.jclouds.googlecloudstorage.domain.DomainResourceReferences.PredefinedAcl; import org.jclouds.googlecloudstorage.domain.DomainResourceReferences.Projection; @@ -44,8 +46,7 @@ import org.jclouds.util.Strings2; import org.testng.annotations.Test; import com.google.common.net.MediaType; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.RecordedRequest; + @Test(groups = "unit", testName = "ObjectApiMockTest", singleThreaded = true) public class ObjectApiMockTest extends BaseGoogleCloudStorageApiMockTest { @@ -117,7 +118,7 @@ public class ObjectApiMockTest extends BaseGoogleCloudStorageApiMockTest { RecordedRequest request = assertSent(server, "POST", "/upload/storage/v1/b/bucket_name/o" + "?uploadType=media&name=new_object&predefinedAcl=publicReadWrite", null); assertEquals(request.getHeader("Content-Type"), "text/plain"); - assertEquals(new String(request.getBody(), UTF_8), testPayload); + assertEquals(request.getBody().readUtf8(), testPayload); } public void delete() throws Exception { @@ -271,9 +272,8 @@ public class ObjectApiMockTest extends BaseGoogleCloudStorageApiMockTest { new ParseGoogleCloudStorageObject().expected()); RecordedRequest request = assertSent(server, "POST", "/upload/storage/v1/b/bucket_name/o?uploadType=multipart", null); - assertTrue(new String(request.getBody(), UTF_8).contains(testPayload)); + assertTrue(request.getBody().readUtf8().contains(testPayload)); - assertTrue(new String(request.getBody(), UTF_8).contains(testPayload)); //TODO: this should be a more robust assertion about the formatting of the payload } diff --git a/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/internal/BaseGoogleCloudStorageApiMockTest.java b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/internal/BaseGoogleCloudStorageApiMockTest.java index 80db201220..f9e953c696 100644 --- a/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/internal/BaseGoogleCloudStorageApiMockTest.java +++ b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/internal/BaseGoogleCloudStorageApiMockTest.java @@ -16,7 +16,6 @@ */ package org.jclouds.googlecloudstorage.internal; -import static com.google.common.base.Charsets.UTF_8; import static com.google.common.base.Throwables.propagate; import static com.google.common.util.concurrent.MoreExecutors.newDirectExecutorService; import static javax.ws.rs.core.MediaType.APPLICATION_JSON; @@ -31,6 +30,10 @@ import java.util.Properties; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.ContextBuilder; import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.googlecloudstorage.GoogleCloudStorageApi; @@ -42,9 +45,7 @@ import org.testng.annotations.BeforeMethod; import com.google.common.collect.ImmutableSet; import com.google.gson.JsonParser; import com.google.inject.AbstractModule; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; + /** * Tests need to run {@code singleThreaded = true} as otherwise tests will clash on the server field. @@ -83,11 +84,11 @@ public class BaseGoogleCloudStorageApiMockTest { public void start() throws IOException { suffix.set(0); server = new MockWebServer(); - server.play(); + server.start(); } protected String url(String path) { - return server.getUrl(path).toString(); + return server.url(path).toString(); } @AfterMethod(alwaysRun = true) @@ -129,7 +130,7 @@ public class BaseGoogleCloudStorageApiMockTest { throws InterruptedException { RecordedRequest request = assertSent(server, method, path, type); assertEquals(request.getHeader("Content-Type"), APPLICATION_JSON); - assertEquals(parser.parse(new String(request.getBody(), UTF_8)), parser.parse(json)); + assertEquals(parser.parse(request.getBody().readUtf8()), parser.parse(json)); return request; } diff --git a/providers/google-compute-engine/pom.xml b/providers/google-compute-engine/pom.xml index 7780c31c06..ee79fe03ad 100644 --- a/providers/google-compute-engine/pom.xml +++ b/providers/google-compute-engine/pom.xml @@ -128,7 +128,7 @@ test - com.squareup.okhttp + com.squareup.okhttp3 mockwebserver test diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceMockTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceMockTest.java index 6e1c11b834..49ec53cfbe 100644 --- a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceMockTest.java +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceMockTest.java @@ -25,6 +25,8 @@ import static org.testng.Assert.assertTrue; import java.io.IOException; import java.util.Set; +import okhttp3.mockwebserver.MockResponse; + import org.jclouds.compute.ComputeService; import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.Hardware; @@ -38,7 +40,7 @@ import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiMockTe import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; -import com.squareup.okhttp.mockwebserver.MockResponse; + @Test(groups = "unit", testName = "GoogleComputeEngineServiceMockTest", singleThreaded = true) public class GoogleComputeEngineServiceMockTest extends BaseGoogleComputeEngineApiMockTest { diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/ResourcesMockTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/ResourcesMockTest.java index 3ace7f2d59..c41d3f6dc8 100644 --- a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/ResourcesMockTest.java +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/ResourcesMockTest.java @@ -40,7 +40,7 @@ public class ResourcesMockTest extends BaseGoogleComputeEngineApiMockTest { public void testInstance() throws Exception { server.enqueue(jsonResponse("/instance_get.json")); - Instance instance = resourceApi().instance(server.getUrl("/foo/bar").toURI()); + Instance instance = resourceApi().instance(server.url("/foo/bar").uri()); assertEquals(instance, new ParseInstanceTest().expected(url("/projects"))); assertSent(server, "GET", "/foo/bar"); } @@ -48,7 +48,7 @@ public class ResourcesMockTest extends BaseGoogleComputeEngineApiMockTest { public void testInstanceReturns404() throws Exception { server.enqueue(response404()); - Instance instance = resourceApi().instance(server.getUrl("/foo/bar").toURI()); + Instance instance = resourceApi().instance(server.url("/foo/bar").uri()); assertNull(instance); assertSent(server, "GET", "/foo/bar"); } @@ -56,7 +56,7 @@ public class ResourcesMockTest extends BaseGoogleComputeEngineApiMockTest { public void testNetwork() throws Exception { server.enqueue(jsonResponse("/network_get.json")); - Network network = resourceApi().network(server.getUrl("/foo/bar").toURI()); + Network network = resourceApi().network(server.url("/foo/bar").uri()); assertEquals(network, new ParseNetworkTest().expected(url("/projects"))); assertSent(server, "GET", "/foo/bar"); } @@ -64,7 +64,7 @@ public class ResourcesMockTest extends BaseGoogleComputeEngineApiMockTest { public void testNetworkReturns404() throws Exception { server.enqueue(response404()); - Network network = resourceApi().network(server.getUrl("/foo/bar").toURI()); + Network network = resourceApi().network(server.url("/foo/bar").uri()); assertNull(network); assertSent(server, "GET", "/foo/bar"); } @@ -72,7 +72,7 @@ public class ResourcesMockTest extends BaseGoogleComputeEngineApiMockTest { public void testDisk() throws Exception { server.enqueue(jsonResponse("/disk_get.json")); - Disk disk = resourceApi().disk(server.getUrl("/foo/bar").toURI()); + Disk disk = resourceApi().disk(server.url("/foo/bar").uri()); assertEquals(disk, new ParseDiskTest().expected(url("/projects"))); assertSent(server, "GET", "/foo/bar"); } @@ -80,7 +80,7 @@ public class ResourcesMockTest extends BaseGoogleComputeEngineApiMockTest { public void testDiskReturns404() throws Exception { server.enqueue(response404()); - Disk disk = resourceApi().disk(server.getUrl("/foo/bar").toURI()); + Disk disk = resourceApi().disk(server.url("/foo/bar").uri()); assertNull(disk); assertSent(server, "GET", "/foo/bar"); } @@ -88,7 +88,7 @@ public class ResourcesMockTest extends BaseGoogleComputeEngineApiMockTest { public void testImage() throws Exception { server.enqueue(jsonResponse("/image_get.json")); - Image image = resourceApi().image(server.getUrl("/foo/bar").toURI()); + Image image = resourceApi().image(server.url("/foo/bar").uri()); assertEquals(image, new ParseImageTest().expected(url("/projects"))); assertSent(server, "GET", "/foo/bar"); } @@ -96,7 +96,7 @@ public class ResourcesMockTest extends BaseGoogleComputeEngineApiMockTest { public void testImageReturns404() throws Exception { server.enqueue(response404()); - Image image = resourceApi().image(server.getUrl("/foo/bar").toURI()); + Image image = resourceApi().image(server.url("/foo/bar").uri()); assertNull(image); assertSent(server, "GET", "/foo/bar"); } @@ -104,7 +104,7 @@ public class ResourcesMockTest extends BaseGoogleComputeEngineApiMockTest { public void testOperation() throws Exception { server.enqueue(jsonResponse("/operation.json")); - Operation operation = resourceApi().operation(server.getUrl("/foo/bar").toURI()); + Operation operation = resourceApi().operation(server.url("/foo/bar").uri()); assertEquals(operation, new ParseOperationTest().expected(url("/projects"))); assertSent(server, "GET", "/foo/bar"); } @@ -112,7 +112,7 @@ public class ResourcesMockTest extends BaseGoogleComputeEngineApiMockTest { public void testOperationReturns404() throws Exception { server.enqueue(response404()); - Operation operation = resourceApi().operation(server.getUrl("/foo/bar").toURI()); + Operation operation = resourceApi().operation(server.url("/foo/bar").uri()); assertNull(operation); assertSent(server, "GET", "/foo/bar"); } @@ -120,7 +120,7 @@ public class ResourcesMockTest extends BaseGoogleComputeEngineApiMockTest { public void testDelete() throws Exception { server.enqueue(jsonResponse("/operation.json")); - Operation operation = resourceApi().delete(server.getUrl("/foo/bar").toURI()); + Operation operation = resourceApi().delete(server.url("/foo/bar").uri()); assertEquals(operation, new ParseOperationTest().expected(url("/projects"))); assertSent(server, "DELETE", "/foo/bar"); } @@ -128,7 +128,7 @@ public class ResourcesMockTest extends BaseGoogleComputeEngineApiMockTest { public void testDeleteReturns404() throws Exception { server.enqueue(response404()); - Operation operation = resourceApi().delete(server.getUrl("/foo/bar").toURI()); + Operation operation = resourceApi().delete(server.url("/foo/bar").uri()); assertNull(operation); assertSent(server, "DELETE", "/foo/bar"); } @@ -136,7 +136,7 @@ public class ResourcesMockTest extends BaseGoogleComputeEngineApiMockTest { public void testResetInstance() throws Exception { server.enqueue(jsonResponse("/operation.json")); - Operation operation = resourceApi().resetInstance(server.getUrl("/foo/bar").toURI()); + Operation operation = resourceApi().resetInstance(server.url("/foo/bar").uri()); assertEquals(operation, new ParseOperationTest().expected(url("/projects"))); assertSent(server, "POST", "/foo/bar/reset"); } @@ -144,7 +144,7 @@ public class ResourcesMockTest extends BaseGoogleComputeEngineApiMockTest { public void testStopInstance() throws Exception { server.enqueue(jsonResponse("/operation.json")); - Operation operation = resourceApi().stopInstance(server.getUrl("/foo/bar").toURI()); + Operation operation = resourceApi().stopInstance(server.url("/foo/bar").uri()); assertEquals(operation, new ParseOperationTest().expected(url("/projects"))); assertSent(server, "POST", "/foo/bar/stop"); } @@ -152,7 +152,7 @@ public class ResourcesMockTest extends BaseGoogleComputeEngineApiMockTest { public void testStartInstance() throws Exception { server.enqueue(jsonResponse("/operation.json")); - Operation operation = resourceApi().startInstance(server.getUrl("/foo/bar").toURI()); + Operation operation = resourceApi().startInstance(server.url("/foo/bar").uri()); assertEquals(operation, new ParseOperationTest().expected(url("/projects"))); assertSent(server, "POST", "/foo/bar/start"); } @@ -160,7 +160,7 @@ public class ResourcesMockTest extends BaseGoogleComputeEngineApiMockTest { public void testSubnetwork() throws Exception { server.enqueue(jsonResponse("/subnetwork_get.json")); - Subnetwork subnet = resourceApi().subnetwork(server.getUrl("/foo/bar").toURI()); + Subnetwork subnet = resourceApi().subnetwork(server.url("/foo/bar").uri()); assertEquals(subnet, new ParseSubnetworkTest().expected(url("/projects"))); assertSent(server, "GET", "/foo/bar"); } @@ -168,7 +168,7 @@ public class ResourcesMockTest extends BaseGoogleComputeEngineApiMockTest { public void testSubnetworkReturns404() throws Exception { server.enqueue(response404()); - Subnetwork subnet = resourceApi().subnetwork(server.getUrl("/foo/bar").toURI()); + Subnetwork subnet = resourceApi().subnetwork(server.url("/foo/bar").uri()); assertNull(subnet); assertSent(server, "GET", "/foo/bar"); } diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/OperationApiMockTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/OperationApiMockTest.java index 3c4caa8690..7470729a78 100644 --- a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/OperationApiMockTest.java +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/OperationApiMockTest.java @@ -23,6 +23,8 @@ import static org.testng.Assert.assertNull; import java.net.URI; +import okhttp3.mockwebserver.MockResponse; + import org.jclouds.googlecloud.domain.ForwardingListPage; import org.jclouds.googlecloud.domain.ListPage; import org.jclouds.googlecomputeengine.domain.Operation; @@ -34,7 +36,7 @@ import org.jclouds.googlecomputeengine.parse.ParseZoneOperationTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; -import com.squareup.okhttp.mockwebserver.MockResponse; + @Test(groups = "unit", testName = "OperationApiMockTest", singleThreaded = true) public class OperationApiMockTest extends BaseGoogleComputeEngineApiMockTest { diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiMockTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiMockTest.java index d45a6ea18d..f5d82538d3 100644 --- a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiMockTest.java +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiMockTest.java @@ -16,7 +16,6 @@ */ package org.jclouds.googlecomputeengine.internal; -import static com.google.common.base.Charsets.UTF_8; import static com.google.common.base.Throwables.propagate; import static com.google.common.util.concurrent.MoreExecutors.newDirectExecutorService; import static javax.ws.rs.core.MediaType.APPLICATION_JSON; @@ -33,6 +32,10 @@ import java.util.Properties; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.ContextBuilder; import org.jclouds.compute.ComputeService; import org.jclouds.compute.ComputeServiceContext; @@ -46,9 +49,7 @@ import org.testng.annotations.BeforeMethod; import com.google.common.collect.ImmutableSet; import com.google.gson.JsonParser; import com.google.inject.Module; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; + /** * Tests need to run {@code singleThreaded = true} as otherwise tests will clash on the server field. @@ -91,11 +92,17 @@ public class BaseGoogleComputeEngineApiMockTest { public void start() throws IOException { suffix.set(0); server = new MockWebServer(); - server.play(); + server.start(); } protected String url(String path) { - return server.getUrl(path).toString(); + if ("".equals(path)) { + final String serverUrl = server.url("").toString(); + + return serverUrl.substring(0, serverUrl.length() - 1); + } + + return server.url(path).toString(); } @AfterMethod(alwaysRun = true) @@ -138,7 +145,7 @@ public class BaseGoogleComputeEngineApiMockTest { throws InterruptedException { RecordedRequest request = assertSent(server, method, path); assertEquals(request.getHeader("Content-Type"), APPLICATION_JSON); - assertEquals(parser.parse(new String(request.getBody(), UTF_8)), parser.parse(json)); + assertEquals(parser.parse(request.getBody().readUtf8()), parser.parse(json)); return request; } diff --git a/providers/packet/pom.xml b/providers/packet/pom.xml index c471bf204f..2fb22944f0 100644 --- a/providers/packet/pom.xml +++ b/providers/packet/pom.xml @@ -94,7 +94,7 @@ test - com.squareup.okhttp + com.squareup.okhttp3 mockwebserver test diff --git a/providers/packet/src/test/java/org/jclouds/packet/compute/internal/BasePacketApiMockTest.java b/providers/packet/src/test/java/org/jclouds/packet/compute/internal/BasePacketApiMockTest.java index 18aaf5fb85..86f8027fec 100644 --- a/providers/packet/src/test/java/org/jclouds/packet/compute/internal/BasePacketApiMockTest.java +++ b/providers/packet/src/test/java/org/jclouds/packet/compute/internal/BasePacketApiMockTest.java @@ -21,6 +21,10 @@ import java.util.Map; import java.util.Properties; import java.util.Set; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.ContextBuilder; import org.jclouds.concurrent.config.ExecutorServiceModule; import org.jclouds.json.Json; @@ -37,9 +41,6 @@ import com.google.common.io.Resources; import com.google.common.reflect.TypeToken; import com.google.gson.JsonParser; import com.google.inject.Module; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.collect.Iterables.getOnlyElement; @@ -65,7 +66,7 @@ public class BasePacketApiMockTest { @BeforeMethod public void start() throws IOException { server = new MockWebServer(); - server.play(); + server.start(); ctx = ContextBuilder.newBuilder("packet") .credentials("", X_AUTHORIZATION_TOKEN) .endpoint(url("")) @@ -89,7 +90,7 @@ public class BasePacketApiMockTest { } protected String url(String path) { - return server.getUrl(path).toString(); + return server.url(path).toString(); } protected MockResponse jsonResponse(String resource) { @@ -140,7 +141,7 @@ public class BasePacketApiMockTest { throws InterruptedException { RecordedRequest request = assertSent(server, method, path); assertEquals(request.getHeader("Content-Type"), "application/json"); - assertEquals(parser.parse(new String(request.getBody(), Charsets.UTF_8)), parser.parse(json)); + assertEquals(parser.parse(request.getBody().readUtf8()), parser.parse(json)); return request; } } diff --git a/providers/profitbricks/pom.xml b/providers/profitbricks/pom.xml index c01691be78..e3cf54ccfe 100644 --- a/providers/profitbricks/pom.xml +++ b/providers/profitbricks/pom.xml @@ -82,7 +82,7 @@ test - com.squareup.okhttp + com.squareup.okhttp3 mockwebserver test diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/compute/config/StatusPredicateTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/compute/config/StatusPredicateTest.java index b2f4607b46..b4fe251282 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/compute/config/StatusPredicateTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/compute/config/StatusPredicateTest.java @@ -16,11 +16,13 @@ */ package org.jclouds.profitbricks.compute.config; -import static org.jclouds.profitbricks.internal.BaseProfitBricksMockTest.mockWebServer; import static org.testng.Assert.assertEquals; import java.util.concurrent.TimeUnit; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.profitbricks.ProfitBricksApi; import org.jclouds.profitbricks.compute.config.ProfitBricksComputeServiceContextModule.DataCenterProvisioningStatePredicate; import org.jclouds.profitbricks.compute.config.ProfitBricksComputeServiceContextModule.ServerStatusPredicate; @@ -33,8 +35,6 @@ import org.jclouds.util.Predicates2; import org.testng.annotations.Test; import com.google.common.base.Predicate; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; /** @@ -47,8 +47,8 @@ public class StatusPredicateTest extends BaseProfitBricksMockTest { public void testDataCenterPredicate() throws Exception { MockWebServer server = mockWebServer(); - byte[] payloadInProcess = payloadFromResource("/datacenter/datacenter-state-inprocess.xml"); - byte[] payloadAvailable = payloadFromResource("/datacenter/datacenter-state.xml"); + String payloadInProcess = payloadFromResource("/datacenter/datacenter-state-inprocess.xml"); + String payloadAvailable = payloadFromResource("/datacenter/datacenter-state.xml"); // wait 3 times server.enqueue(new MockResponse().setBody(payloadInProcess)); @@ -58,7 +58,7 @@ public class StatusPredicateTest extends BaseProfitBricksMockTest { server.enqueue(new MockResponse().setBody(payloadAvailable)); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); Predicate waitUntilAvailable = Predicates2.retry( new DataCenterProvisioningStatePredicate(pbApi, ProvisioningState.AVAILABLE), @@ -80,8 +80,8 @@ public class StatusPredicateTest extends BaseProfitBricksMockTest { public void testServerPredicate() throws Exception { MockWebServer server = mockWebServer(); - byte[] payloadInProcess = payloadFromResource("/server/server-state-inprocess.xml"); - byte[] payloadAvailable = payloadFromResource("/server/server.xml"); + String payloadInProcess = payloadFromResource("/server/server-state-inprocess.xml"); + String payloadAvailable = payloadFromResource("/server/server.xml"); // wait 3 times server.enqueue(new MockResponse().setBody(payloadInProcess)); @@ -91,7 +91,7 @@ public class StatusPredicateTest extends BaseProfitBricksMockTest { server.enqueue(new MockResponse().setBody(payloadAvailable)); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); Predicate waitUntilAvailable = Predicates2.retry( new ServerStatusPredicate(pbApi, Server.Status.RUNNING), @@ -113,8 +113,8 @@ public class StatusPredicateTest extends BaseProfitBricksMockTest { public void testSnapshotPredicate() throws Exception { MockWebServer server = mockWebServer(); - byte[] payloadInProcess = payloadFromResource("/snapshot/snapshot-state-inprocess.xml"); - byte[] payloadAvailable = payloadFromResource("/snapshot/snapshot.xml"); + String payloadInProcess = payloadFromResource("/snapshot/snapshot-state-inprocess.xml"); + String payloadAvailable = payloadFromResource("/snapshot/snapshot.xml"); // wait 3 times server.enqueue(new MockResponse().setBody(payloadInProcess)); @@ -124,7 +124,7 @@ public class StatusPredicateTest extends BaseProfitBricksMockTest { server.enqueue(new MockResponse().setBody(payloadAvailable)); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); Predicate waitUntilAvailable = Predicates2.retry( new SnapshotProvisioningStatePredicate(pbApi, ProvisioningState.AVAILABLE), diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/DataCenterApiMockTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/DataCenterApiMockTest.java index 262d34a3bd..f375576cde 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/DataCenterApiMockTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/DataCenterApiMockTest.java @@ -25,6 +25,9 @@ import static org.testng.Assert.fail; import java.util.List; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.profitbricks.ProfitBricksApi; import org.jclouds.profitbricks.domain.DataCenter; import org.jclouds.profitbricks.domain.Location; @@ -32,8 +35,6 @@ import org.jclouds.profitbricks.domain.ProvisioningState; import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest; import org.testng.annotations.Test; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; /** * Mock tests for the {@link org.jclouds.profitbricks.features.DataCenterApi} class @@ -46,7 +47,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/datacenter/datacenters.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); DataCenterApi api = pbApi.dataCenterApi(); try { @@ -65,7 +66,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setResponseCode(404)); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); DataCenterApi api = pbApi.dataCenterApi(); try { @@ -83,7 +84,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/datacenter/datacenter.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); DataCenterApi api = pbApi.dataCenterApi(); String id = "12345678-abcd-efgh-ijkl-987654321000"; @@ -104,7 +105,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setResponseCode(404)); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); DataCenterApi api = pbApi.dataCenterApi(); String id = "random-non-existing-id"; @@ -123,7 +124,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/datacenter/datacenter-state.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); DataCenterApi api = pbApi.dataCenterApi(); String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; @@ -144,7 +145,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/datacenter/datacenter-created.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); DataCenterApi api = pbApi.dataCenterApi(); String content = "" @@ -182,7 +183,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/datacenter/datacenter-updated.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); DataCenterApi api = pbApi.dataCenterApi(); String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; @@ -211,7 +212,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/datacenter/datacenter-cleared.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); DataCenterApi api = pbApi.dataCenterApi(); String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; @@ -235,7 +236,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/datacenter/datacenter-deleted.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); DataCenterApi api = pbApi.dataCenterApi(); String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; @@ -256,7 +257,7 @@ public class DataCenterApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setResponseCode(404)); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); DataCenterApi api = pbApi.dataCenterApi(); try { diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/DrivesApiMockTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/DrivesApiMockTest.java index 38cdcf018b..0a87efbbe6 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/DrivesApiMockTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/DrivesApiMockTest.java @@ -16,13 +16,14 @@ */ package org.jclouds.profitbricks.features; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; +import static org.testng.Assert.assertNotNull; + +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.profitbricks.ProfitBricksApi; import org.jclouds.profitbricks.domain.Drive; import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest; -import static org.jclouds.profitbricks.internal.BaseProfitBricksMockTest.mockWebServer; -import static org.testng.Assert.assertNotNull; import org.testng.annotations.Test; @Test(groups = "unit", testName = "DrivesApiMockTest") @@ -33,7 +34,7 @@ public class DrivesApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/drives/drives-add.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); DrivesApi api = pbApi.drivesApi(); String content = "" @@ -62,7 +63,7 @@ public class DrivesApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/drives/drives-remove.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); DrivesApi api = pbApi.drivesApi(); String content = "" diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/FirewallApiMockTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/FirewallApiMockTest.java index d9531cb4ce..5f009b0929 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/FirewallApiMockTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/FirewallApiMockTest.java @@ -16,18 +16,17 @@ */ package org.jclouds.profitbricks.features; -import static org.jclouds.profitbricks.internal.BaseProfitBricksMockTest.mockWebServer; 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 static org.testng.Assert.assertTrue; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; - import java.util.List; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.profitbricks.ProfitBricksApi; import org.jclouds.profitbricks.domain.Firewall; import org.jclouds.profitbricks.domain.Firewall.Protocol; @@ -45,7 +44,7 @@ public class FirewallApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/firewall/firewalls.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); FirewallApi api = pbApi.firewallApi(); @@ -65,7 +64,7 @@ public class FirewallApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/firewall/firewall.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); FirewallApi api = pbApi.firewallApi(); @@ -92,7 +91,7 @@ public class FirewallApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setResponseCode(404)); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); FirewallApi api = pbApi.firewallApi(); String id = "firewall-id"; @@ -112,7 +111,7 @@ public class FirewallApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/firewall/firewall-addtonic.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); FirewallApi api = pbApi.firewallApi(); String content = "" @@ -155,7 +154,7 @@ public class FirewallApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/firewall/firewall-remove.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); FirewallApi api = pbApi.firewallApi(); String firewallId = "12345"; @@ -178,7 +177,7 @@ public class FirewallApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setResponseCode(404)); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); FirewallApi api = pbApi.firewallApi(); String firewallRuleId = "12345"; @@ -198,7 +197,7 @@ public class FirewallApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/firewall/firewall-activate.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); FirewallApi api = pbApi.firewallApi(); String firewallId = "12345"; @@ -221,7 +220,7 @@ public class FirewallApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setResponseCode(404)); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); FirewallApi api = pbApi.firewallApi(); String firewallId = "12345"; @@ -241,7 +240,7 @@ public class FirewallApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/firewall/firewall-deactivate.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); FirewallApi api = pbApi.firewallApi(); String firewallId = "12345"; @@ -264,7 +263,7 @@ public class FirewallApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setResponseCode(404)); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); FirewallApi api = pbApi.firewallApi(); String firewallId = "12345"; @@ -284,7 +283,7 @@ public class FirewallApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/firewall/firewall-delete.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); FirewallApi api = pbApi.firewallApi(); String firewallId = "12345"; @@ -307,7 +306,7 @@ public class FirewallApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setResponseCode(404)); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); FirewallApi api = pbApi.firewallApi(); String firewallId = "12345"; diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/IpBlockApiMockTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/IpBlockApiMockTest.java index 234f163bb8..022d5114f6 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/IpBlockApiMockTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/IpBlockApiMockTest.java @@ -16,17 +16,21 @@ */ package org.jclouds.profitbricks.features; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import java.util.List; -import org.jclouds.profitbricks.ProfitBricksApi; -import org.jclouds.profitbricks.domain.IpBlock; -import org.jclouds.profitbricks.domain.Location; -import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest; 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 java.util.List; + +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + +import org.jclouds.profitbricks.ProfitBricksApi; +import org.jclouds.profitbricks.domain.IpBlock; +import org.jclouds.profitbricks.domain.Location; +import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest; + import org.testng.annotations.Test; @Test(groups = "unit", testName = "IpBlockApiMockTest") @@ -37,7 +41,7 @@ public class IpBlockApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/ipblock/ipblock.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); IpBlockApi api = pbApi.ipBlockApi(); String id = "qwertyui-qwer-qwer-qwer-qwertyyuiiop"; @@ -60,7 +64,7 @@ public class IpBlockApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setResponseCode(404)); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); IpBlockApi api = pbApi.ipBlockApi(); String id = "qwertyui-qwer-qwer-qwer-qwertyyuiiop"; @@ -80,7 +84,7 @@ public class IpBlockApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/ipblock/ipblocks.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); IpBlockApi api = pbApi.ipBlockApi(); try { @@ -98,7 +102,7 @@ public class IpBlockApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setResponseCode(404)); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); IpBlockApi api = pbApi.ipBlockApi(); try { @@ -116,7 +120,7 @@ public class IpBlockApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/ipblock/ipblock-reserve.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); IpBlockApi api = pbApi.ipBlockApi(); int blockSize = 2; @@ -138,7 +142,7 @@ public class IpBlockApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/ipblock/ipblock-addtonic.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); IpBlockApi api = pbApi.ipBlockApi(); String ip = "2"; @@ -160,7 +164,7 @@ public class IpBlockApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/ipblock/ipblock-removefromnic.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); IpBlockApi api = pbApi.ipBlockApi(); String ip = "2"; @@ -182,7 +186,7 @@ public class IpBlockApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/ipblock/ipblock-release.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); IpBlockApi api = pbApi.ipBlockApi(); String blockid = "2"; diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/LoadBalancerApiMockTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/LoadBalancerApiMockTest.java index e4e8fd7ed6..315b619bdd 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/LoadBalancerApiMockTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/LoadBalancerApiMockTest.java @@ -25,8 +25,9 @@ import java.util.List; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; + +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; import org.jclouds.profitbricks.ProfitBricksApi; import org.jclouds.profitbricks.domain.LoadBalancer; @@ -42,7 +43,7 @@ public class LoadBalancerApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/loadbalancer/loadbalancers.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); LoadBalancerApi api = pbApi.loadBalancerApi(); try { @@ -63,7 +64,7 @@ public class LoadBalancerApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setResponseCode(404)); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); LoadBalancerApi api = pbApi.loadBalancerApi(); try { @@ -83,7 +84,7 @@ public class LoadBalancerApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/loadbalancer/loadbalancer.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); LoadBalancerApi api = pbApi.loadBalancerApi(); String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; @@ -106,7 +107,7 @@ public class LoadBalancerApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setResponseCode(404)); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); LoadBalancerApi api = pbApi.loadBalancerApi(); String id = "random-non-existing-id"; @@ -127,7 +128,7 @@ public class LoadBalancerApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/loadbalancer/loadbalancer-create.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); LoadBalancerApi api = pbApi.loadBalancerApi(); String content = "" @@ -166,7 +167,7 @@ public class LoadBalancerApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/loadbalancer/loadbalancer-update.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); LoadBalancerApi api = pbApi.loadBalancerApi(); String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; @@ -205,7 +206,7 @@ public class LoadBalancerApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/loadbalancer/loadbalancer-register.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); LoadBalancerApi api = pbApi.loadBalancerApi(); String content = "" @@ -237,7 +238,7 @@ public class LoadBalancerApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/loadbalancer/loadbalancer-deregister.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); LoadBalancerApi api = pbApi.loadBalancerApi(); String content = "" @@ -265,7 +266,7 @@ public class LoadBalancerApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/loadbalancer/loadbalancer-delete.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); LoadBalancerApi api = pbApi.loadBalancerApi(); String loadBalancerId = "qwertyui-qwer-qwer-qwer-qwertyyuiiop"; diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/NicApiMockTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/NicApiMockTest.java index 940efa71de..72146579d9 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/NicApiMockTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/NicApiMockTest.java @@ -24,8 +24,8 @@ import static org.testng.Assert.assertTrue; import java.util.List; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; import org.jclouds.profitbricks.ProfitBricksApi; import org.jclouds.profitbricks.domain.Nic; @@ -41,7 +41,7 @@ public class NicApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/nic/nic.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); NicApi api = pbApi.nicApi(); String id = "12345678-abcd-efgh-ijkl-987654321000"; @@ -63,7 +63,7 @@ public class NicApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setResponseCode(404)); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); NicApi api = pbApi.nicApi(); String id = "nonexisting-nic-id"; @@ -83,7 +83,7 @@ public class NicApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/nic/nics.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); NicApi api = pbApi.nicApi(); try { List nics = api.getAllNics(); @@ -100,7 +100,7 @@ public class NicApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/nic/nic-create.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); NicApi api = pbApi.nicApi(); String content = "" @@ -137,7 +137,7 @@ public class NicApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/nic/nic-update.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); NicApi api = pbApi.nicApi(); String content = "" @@ -170,7 +170,7 @@ public class NicApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/nic/nic-internetaccess.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); NicApi api = pbApi.nicApi(); String content = "" @@ -197,7 +197,7 @@ public class NicApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/nic/nic-delete.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); NicApi api = pbApi.nicApi(); String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; @@ -219,7 +219,7 @@ public class NicApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setResponseCode(404)); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); NicApi api = pbApi.nicApi(); String id = "nonexisting-nic-id"; diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ServerApiMockTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ServerApiMockTest.java index 47738b81bc..d354ba8369 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ServerApiMockTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/ServerApiMockTest.java @@ -16,13 +16,11 @@ */ package org.jclouds.profitbricks.features; -import static org.jclouds.profitbricks.internal.BaseProfitBricksMockTest.mockWebServer; - -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; - import java.util.List; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.profitbricks.ProfitBricksApi; import org.jclouds.profitbricks.domain.AvailabilityZone; import org.jclouds.profitbricks.domain.OsType; @@ -47,7 +45,7 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/server/servers.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); ServerApi api = pbApi.serverApi(); try { @@ -66,7 +64,7 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setResponseCode(404)); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); ServerApi api = pbApi.serverApi(); try { @@ -84,7 +82,7 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/server/server.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); ServerApi api = pbApi.serverApi(); String id = "qwertyui-qwer-qwer-qwer-qwertyyuiiop"; @@ -106,7 +104,7 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setResponseCode(404)); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); ServerApi api = pbApi.serverApi(); String id = "random-non-existing-id"; @@ -126,7 +124,7 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/server/server-start.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); ServerApi api = pbApi.serverApi(); String id = "qwertyui-qwer-qwer-qwer-qwertyyuiiop"; @@ -147,7 +145,7 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setResponseCode(500).setBody(payloadFromResource("/fault-404.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); ServerApi api = pbApi.serverApi(); String id = "random-non-existing-id"; @@ -168,7 +166,7 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/server/server-stop.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); ServerApi api = pbApi.serverApi(); String id = "qwertyui-qwer-qwer-qwer-qwertyyuiiop"; @@ -189,7 +187,7 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/server/server-reset.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); ServerApi api = pbApi.serverApi(); String id = "qwertyui-qwer-qwer-qwer-qwertyyuiiop"; @@ -210,7 +208,7 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/server/server-create.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); ServerApi api = pbApi.serverApi(); String dataCenterId = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; @@ -270,7 +268,7 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/server/server-update.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); ServerApi api = pbApi.serverApi(); String serverId = "qwertyui-qwer-qwer-qwer-qwertyyuiiop"; @@ -325,7 +323,7 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/server/server-delete.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); ServerApi api = pbApi.serverApi(); String serverId = "qwertyui-qwer-qwer-qwer-qwertyyuiiop"; @@ -347,7 +345,7 @@ public class ServerApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setResponseCode(404)); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); ServerApi api = pbApi.serverApi(); String id = "random-non-existing-id"; diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/SnapshotApiMockTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/SnapshotApiMockTest.java index 9574e76255..9c688e172e 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/SnapshotApiMockTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/SnapshotApiMockTest.java @@ -16,8 +16,9 @@ */ package org.jclouds.profitbricks.features; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.profitbricks.ProfitBricksApi; import org.jclouds.profitbricks.domain.OsType; import org.jclouds.profitbricks.domain.Snapshot; @@ -25,7 +26,6 @@ import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest; import org.testng.annotations.Test; import java.util.List; -import static org.jclouds.profitbricks.internal.BaseProfitBricksMockTest.mockWebServer; import org.testng.Assert; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; @@ -43,7 +43,7 @@ public class SnapshotApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/snapshot/snapshots.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); SnapshotApi api = pbApi.snapshotApi(); try { @@ -62,7 +62,7 @@ public class SnapshotApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setResponseCode(404)); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); SnapshotApi api = pbApi.snapshotApi(); try { @@ -80,7 +80,7 @@ public class SnapshotApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/snapshot/snapshot.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); SnapshotApi api = pbApi.snapshotApi(); String id = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh"; @@ -103,7 +103,7 @@ public class SnapshotApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setResponseCode(404)); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); SnapshotApi api = pbApi.snapshotApi(); String id = "random-non-existing-id"; @@ -122,7 +122,7 @@ public class SnapshotApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/snapshot/snapshot-create.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); SnapshotApi api = pbApi.snapshotApi(); String storageId = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; @@ -157,7 +157,7 @@ public class SnapshotApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/snapshot/snapshot-update.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); SnapshotApi api = pbApi.snapshotApi(); String snapshotId = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; @@ -209,7 +209,7 @@ public class SnapshotApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/snapshot/snapshot-delete.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); SnapshotApi api = pbApi.snapshotApi(); String snapshotId = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh"; @@ -230,7 +230,7 @@ public class SnapshotApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setResponseCode(404)); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); SnapshotApi api = pbApi.snapshotApi(); String id = "random-non-existing-id"; @@ -249,7 +249,7 @@ public class SnapshotApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/snapshot/snapshot-rollback.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); SnapshotApi api = pbApi.snapshotApi(); String snapshotId = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh"; diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/StorageApiMockTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/StorageApiMockTest.java index 10a4a491b9..03532d7884 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/StorageApiMockTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/features/StorageApiMockTest.java @@ -24,13 +24,14 @@ import static org.testng.Assert.assertTrue; import java.util.List; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.profitbricks.ProfitBricksApi; import org.jclouds.profitbricks.domain.Storage; import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest; import org.testng.annotations.Test; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; @Test(groups = "unit", testName = "StorageApiMockTest") public class StorageApiMockTest extends BaseProfitBricksMockTest { @@ -40,7 +41,7 @@ public class StorageApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/storage/storages.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); StorageApi api = pbApi.storageApi(); try { @@ -59,7 +60,7 @@ public class StorageApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setResponseCode(404)); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); StorageApi api = pbApi.storageApi(); try { @@ -77,7 +78,7 @@ public class StorageApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/storage/storage.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); StorageApi api = pbApi.storageApi(); String id = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh"; @@ -99,7 +100,7 @@ public class StorageApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setResponseCode(404)); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); StorageApi api = pbApi.storageApi(); String id = "random-non-existing-id"; @@ -118,7 +119,7 @@ public class StorageApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/storage/storage-connect.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); StorageApi api = pbApi.storageApi(); String storageId = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh"; @@ -152,7 +153,7 @@ public class StorageApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/storage/storage-disconnect.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); StorageApi api = pbApi.storageApi(); String storageId = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh"; @@ -178,7 +179,7 @@ public class StorageApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/storage/storage-create.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); StorageApi api = pbApi.storageApi(); String dataCenterId = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; @@ -213,7 +214,7 @@ public class StorageApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/storage/storage-update.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); StorageApi api = pbApi.storageApi(); String storageId = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh"; @@ -247,7 +248,7 @@ public class StorageApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setBody(payloadFromResource("/storage/storage-delete.xml"))); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); StorageApi api = pbApi.storageApi(); String storageId = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh"; @@ -269,7 +270,7 @@ public class StorageApiMockTest extends BaseProfitBricksMockTest { MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setResponseCode(404)); - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); + ProfitBricksApi pbApi = api(server.url(rootUrl).url()); StorageApi api = pbApi.storageApi(); String id = "random-non-existing-id"; diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/ResponseStatusFromPayloadHttpCommandExecutorServiceTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/ResponseStatusFromPayloadHttpCommandExecutorServiceTest.java index 166cbb904c..584622bd44 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/ResponseStatusFromPayloadHttpCommandExecutorServiceTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/http/ResponseStatusFromPayloadHttpCommandExecutorServiceTest.java @@ -16,10 +16,12 @@ */ package org.jclouds.profitbricks.http; -import static org.jclouds.profitbricks.internal.BaseProfitBricksMockTest.mockWebServer; import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.http.HttpResponseException; import org.jclouds.profitbricks.ProfitBricksApi; import org.jclouds.profitbricks.domain.DataCenter; @@ -33,8 +35,6 @@ import org.jclouds.rest.InsufficientResourcesException; 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. @@ -49,7 +49,7 @@ public class ResponseStatusFromPayloadHttpCommandExecutorServiceTest extends Bas MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setResponseCode(500).setBody(payloadFromResource("/fault-404.xml"))); - ProfitBricksApi pbApi = api(server.getUrl("/")); + ProfitBricksApi pbApi = api(server.url("/").url()); DataCenterApi api = pbApi.dataCenterApi(); String id = "random-non-existing-id"; @@ -69,7 +69,7 @@ public class ResponseStatusFromPayloadHttpCommandExecutorServiceTest extends Bas MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setResponseCode(500).setBody(payloadFromResource("/fault-400.xml"))); - ProfitBricksApi pbApi = api(server.getUrl("/")); + ProfitBricksApi pbApi = api(server.url("/").url()); DataCenterApi api = pbApi.dataCenterApi(); try { @@ -88,7 +88,7 @@ public class ResponseStatusFromPayloadHttpCommandExecutorServiceTest extends Bas MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setResponseCode(401).setBody(payloadFromResource("/html/fault-401.html"))); - ProfitBricksApi pbApi = api(server.getUrl("/")); + ProfitBricksApi pbApi = api(server.url("/").url()); DataCenterApi api = pbApi.dataCenterApi(); try { @@ -107,7 +107,7 @@ public class ResponseStatusFromPayloadHttpCommandExecutorServiceTest extends Bas MockWebServer server = mockWebServer(); server.enqueue(new MockResponse().setResponseCode(503).setBody(payloadFromResource("/fault-413.xml"))); - ProfitBricksApi pbApi = api(server.getUrl("/")); + ProfitBricksApi pbApi = api(server.url("/").url()); ServerApi api = pbApi.serverApi(); try { @@ -131,9 +131,9 @@ public class ResponseStatusFromPayloadHttpCommandExecutorServiceTest extends Bas public void testServiceUnderMaintenance() throws Exception { MockWebServer server = mockWebServer(); for (int i = 0; i <= MAX_RETRIES; i++) // jclouds retries 5 times - server.enqueue(new MockResponse().setResponseCode(503).setBody(payloadFromResource("/html/maintenance-503.html"))); + server.enqueue(new MockResponse().setStatus(statusLine503ok()).setBody(payloadFromResource("/html/maintenance-503.html"))); - ProfitBricksApi pbApi = api(server.getUrl("/")); + ProfitBricksApi pbApi = api(server.url("/").url()); DataCenterApi api = pbApi.dataCenterApi(); try { @@ -146,4 +146,8 @@ public class ResponseStatusFromPayloadHttpCommandExecutorServiceTest extends Bas server.shutdown(); } } + + public String statusLine503ok() { + return "HTTP/1.1 503 OK"; + } } diff --git a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/internal/BaseProfitBricksMockTest.java b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/internal/BaseProfitBricksMockTest.java index d5883a61f6..aaea69acb1 100644 --- a/providers/profitbricks/src/test/java/org/jclouds/profitbricks/internal/BaseProfitBricksMockTest.java +++ b/providers/profitbricks/src/test/java/org/jclouds/profitbricks/internal/BaseProfitBricksMockTest.java @@ -27,16 +27,17 @@ import java.util.Set; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.ContextBuilder; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.profitbricks.ProfitBricksApi; -import com.google.common.base.Charsets; import com.google.common.base.Throwables; import com.google.common.collect.ImmutableSet; import com.google.inject.Module; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; + /** * Base class for all ProfitBricks mock test @@ -74,13 +75,13 @@ public class BaseProfitBricksMockTest { public static MockWebServer mockWebServer() throws IOException { MockWebServer server = new MockWebServer(); - server.play(); + server.start(); return server; } - public byte[] payloadFromResource(String resource) { + public String payloadFromResource(String resource) { try { - return toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8); + return toStringAndClose(getClass().getResourceAsStream(resource)); } catch (IOException e) { throw Throwables.propagate(e); } @@ -98,7 +99,7 @@ public class BaseProfitBricksMockTest { } protected static void assertRequestHasCommonProperties(final RecordedRequest request, String content) { - assertEquals(new String(request.getBody()), payloadSoapWithBody(content)); + assertEquals(request.getBody().readUtf8(), payloadSoapWithBody(content)); assertRequestHasCommonProperties(request); } } diff --git a/providers/softlayer/pom.xml b/providers/softlayer/pom.xml index 8f536174bb..3e139bc8f3 100644 --- a/providers/softlayer/pom.xml +++ b/providers/softlayer/pom.xml @@ -81,7 +81,7 @@ test - com.squareup.okhttp + com.squareup.okhttp3 mockwebserver test @@ -92,6 +92,18 @@ + + com.squareup.okhttp3 + okhttp-tls + test + + + + org.bouncycastle + bcprov-jdk15on + + + com.google.auto.service auto-service diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountApiMockTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountApiMockTest.java index 6c6d8670f3..d2e29e5129 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountApiMockTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountApiMockTest.java @@ -19,6 +19,9 @@ package org.jclouds.softlayer.features; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.softlayer.SoftLayerApi; import org.jclouds.softlayer.config.SoftLayerParserModule; @@ -27,8 +30,6 @@ import org.jclouds.softlayer.parse.VirtualGuestBlockDeviceTemplateGroupsParseTes import org.jclouds.softlayer.parse.VirtualGuestsParseTest; import org.testng.annotations.Test; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; /** * Mock tests for the {@link org.jclouds.softlayer.features.AccountApi} class. @@ -60,7 +61,7 @@ public class AccountApiMockTest extends BaseSoftLayerMockTest { public void testGetBlockDeviceTemplateGroups() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/account_get_block_devices_template_groups.json"))); - AccountApi api = api(SoftLayerApi.class, server.getUrl("/").toString()).getAccountApi(); + AccountApi api = api(SoftLayerApi.class, server.url("/").toString()).getAccountApi(); try { assertEquals(api.getBlockDeviceTemplateGroups(), new VirtualGuestBlockDeviceTemplateGroupsParseTest().expected()); assertSent(server, "GET", "/SoftLayer_Account/getBlockDeviceTemplateGroups?objectMask=children.blockDevices.diskImage.softwareReferences.softwareDescription"); @@ -81,7 +82,7 @@ public class AccountApiMockTest extends BaseSoftLayerMockTest { } private AccountApi getAccountApi(MockWebServer server) { - return api(SoftLayerApi.class, server.getUrl("/").toString(), new + return api(SoftLayerApi.class, server.url("/").toString(), new JavaUrlHttpCommandExecutorServiceModule(), new SoftLayerParserModule()).getAccountApi(); } diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterApiMockTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterApiMockTest.java index 321bb8746f..f5478736b9 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterApiMockTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterApiMockTest.java @@ -20,14 +20,15 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.softlayer.SoftLayerApi; import org.jclouds.softlayer.internal.BaseSoftLayerMockTest; import org.jclouds.softlayer.parse.DatacenterParseTest; import org.jclouds.softlayer.parse.DatacentersParseTest; import org.testng.annotations.Test; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; /** * Mock tests for the {@link org.jclouds.softlayer.features.DatacenterApi} class. @@ -81,6 +82,6 @@ public class DatacenterApiMockTest extends BaseSoftLayerMockTest { } private DatacenterApi getDatacenterApi(MockWebServer server) { - return api(SoftLayerApi.class, server.getUrl("/").toString()).getDatacenterApi(); + return api(SoftLayerApi.class, server.url("/").toString()).getDatacenterApi(); } } diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/NetworkApiMockTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/NetworkApiMockTest.java index 5cf3e26871..00008b87c5 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/NetworkApiMockTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/NetworkApiMockTest.java @@ -17,8 +17,10 @@ package org.jclouds.softlayer.features; import com.google.common.collect.ImmutableList; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; + +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.softlayer.SoftLayerApi; import org.jclouds.softlayer.config.SoftLayerParserModule; @@ -364,7 +366,7 @@ public class NetworkApiMockTest extends BaseSoftLayerMockTest { } private NetworkApi getNetworkApi(MockWebServer server) { - return api(SoftLayerApi.class, server.getUrl("/").toString(), new + return api(SoftLayerApi.class, server.url("/").toString(), new JavaUrlHttpCommandExecutorServiceModule(), new SoftLayerParserModule()).getNetworkApi(); } } diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/SoftwareDescriptionApiMockTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/SoftwareDescriptionApiMockTest.java index fe306e51d5..3f26aeb479 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/SoftwareDescriptionApiMockTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/SoftwareDescriptionApiMockTest.java @@ -18,13 +18,14 @@ package org.jclouds.softlayer.features; import static org.testng.Assert.assertEquals; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.softlayer.SoftLayerApi; import org.jclouds.softlayer.internal.BaseSoftLayerMockTest; import org.jclouds.softlayer.parse.SoftwareDescriptionsParseTest; import org.testng.annotations.Test; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; /** * Mock tests for the {@link org.jclouds.softlayer.features.SoftwareDescriptionApi} class. @@ -35,7 +36,7 @@ public class SoftwareDescriptionApiMockTest extends BaseSoftLayerMockTest { public void testGetAllObjects() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/software_description_list.json"))); - SoftwareDescriptionApi api = api(SoftLayerApi.class, server.getUrl("/").toString()).getSoftwareDescriptionApi(); + SoftwareDescriptionApi api = api(SoftLayerApi.class, server.url("/").toString()).getSoftwareDescriptionApi(); try { assertEquals(api.getAllObjects(), new SoftwareDescriptionsParseTest().expected()); diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiMockTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiMockTest.java index c8280b241e..9e6bf68639 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiMockTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiMockTest.java @@ -21,6 +21,9 @@ import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.softlayer.SoftLayerApi; import org.jclouds.softlayer.config.SoftLayerParserModule; @@ -33,9 +36,6 @@ import org.jclouds.softlayer.parse.VirtualGuestFilteredParseTest; import org.jclouds.softlayer.parse.VirtualGuestParseTest; import org.testng.annotations.Test; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; - import com.google.common.collect.ImmutableSet; /** @@ -93,7 +93,7 @@ public class VirtualGuestApiMockTest extends BaseSoftLayerMockTest { public void testDeleteVirtualGuest() throws Exception { MockWebServer server = mockWebServer(new MockResponse()); - VirtualGuestApi api = api(SoftLayerApi.class, server.getUrl("/").toString()).getVirtualGuestApi(); + VirtualGuestApi api = api(SoftLayerApi.class, server.url("/").toString()).getVirtualGuestApi(); try { assertTrue(api.deleteVirtualGuest(1301396)); assertSent(server, "GET", "/SoftLayer_Virtual_Guest/1301396/deleteObject"); @@ -104,7 +104,7 @@ public class VirtualGuestApiMockTest extends BaseSoftLayerMockTest { public void testDeleteNonExistingVirtualGuest() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(404)); - VirtualGuestApi api = api(SoftLayerApi.class, server.getUrl("/").toString()).getVirtualGuestApi(); + VirtualGuestApi api = api(SoftLayerApi.class, server.url("/").toString()).getVirtualGuestApi(); try { assertFalse(api.deleteVirtualGuest(1301396)); assertSent(server, "GET", "/SoftLayer_Virtual_Guest/1301396/deleteObject"); @@ -126,7 +126,7 @@ public class VirtualGuestApiMockTest extends BaseSoftLayerMockTest { public void testGetNullCreateObjectOptions() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(404)); - VirtualGuestApi api = api(SoftLayerApi.class, server.getUrl("/").toString()).getVirtualGuestApi(); + VirtualGuestApi api = api(SoftLayerApi.class, server.url("/").toString()).getVirtualGuestApi(); try { assertNull(api.getCreateObjectOptions()); assertSent(server, "GET", "/SoftLayer_Virtual_Guest/getCreateObjectOptions"); @@ -137,7 +137,7 @@ public class VirtualGuestApiMockTest extends BaseSoftLayerMockTest { public void testRebootHardVirtualGuest() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/datacenter_get.json"))); - VirtualGuestApi api = api(SoftLayerApi.class, server.getUrl("/").toString()).getVirtualGuestApi(); + VirtualGuestApi api = api(SoftLayerApi.class, server.url("/").toString()).getVirtualGuestApi(); try { api.rebootHardVirtualGuest(1301396); assertSent(server, "GET", "/SoftLayer_Virtual_Guest/1301396/rebootHard.json"); @@ -148,7 +148,7 @@ public class VirtualGuestApiMockTest extends BaseSoftLayerMockTest { public void testRebootNonExistingVirtualGuest() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(404)); - VirtualGuestApi api = api(SoftLayerApi.class, server.getUrl("/").toString()).getVirtualGuestApi(); + VirtualGuestApi api = api(SoftLayerApi.class, server.url("/").toString()).getVirtualGuestApi(); try { api.rebootHardVirtualGuest(1301396); assertSent(server, "GET", "/SoftLayer_Virtual_Guest/1301396/rebootHard.json"); @@ -159,7 +159,7 @@ public class VirtualGuestApiMockTest extends BaseSoftLayerMockTest { public void testPauseVirtualGuest() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/datacenter_get.json"))); - VirtualGuestApi api = api(SoftLayerApi.class, server.getUrl("/").toString()).getVirtualGuestApi(); + VirtualGuestApi api = api(SoftLayerApi.class, server.url("/").toString()).getVirtualGuestApi(); try { api.pauseVirtualGuest(1301396); assertSent(server, "GET", "/SoftLayer_Virtual_Guest/1301396/pause.json"); @@ -170,7 +170,7 @@ public class VirtualGuestApiMockTest extends BaseSoftLayerMockTest { public void testPauseNonExistingVirtualGuest() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(404)); - VirtualGuestApi api = api(SoftLayerApi.class, server.getUrl("/").toString()).getVirtualGuestApi(); + VirtualGuestApi api = api(SoftLayerApi.class, server.url("/").toString()).getVirtualGuestApi(); try { api.pauseVirtualGuest(1301396); assertSent(server, "GET", "/SoftLayer_Virtual_Guest/1301396/pause.json"); @@ -181,7 +181,7 @@ public class VirtualGuestApiMockTest extends BaseSoftLayerMockTest { public void testResumeVirtualGuest() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/datacenter_get.json"))); - VirtualGuestApi api = api(SoftLayerApi.class, server.getUrl("/").toString()).getVirtualGuestApi(); + VirtualGuestApi api = api(SoftLayerApi.class, server.url("/").toString()).getVirtualGuestApi(); try { api.resumeVirtualGuest(1301396); assertSent(server, "GET", "/SoftLayer_Virtual_Guest/1301396/resume.json"); @@ -192,7 +192,7 @@ public class VirtualGuestApiMockTest extends BaseSoftLayerMockTest { public void testResumeNonExistingVirtualGuest() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(404)); - VirtualGuestApi api = api(SoftLayerApi.class, server.getUrl("/").toString()).getVirtualGuestApi(); + VirtualGuestApi api = api(SoftLayerApi.class, server.url("/").toString()).getVirtualGuestApi(); try { api.resumeVirtualGuest(1301396); assertSent(server, "GET", "/SoftLayer_Virtual_Guest/1301396/resume.json"); @@ -203,7 +203,7 @@ public class VirtualGuestApiMockTest extends BaseSoftLayerMockTest { public void testSetTagsOnVirtualGuest() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/virtual_guest_set_tags_response.json"))); - VirtualGuestApi api = api(SoftLayerApi.class, server.getUrl("/").toString()).getVirtualGuestApi(); + VirtualGuestApi api = api(SoftLayerApi.class, server.url("/").toString()).getVirtualGuestApi(); VirtualGuest virtualGuest = createVirtualGuest(); try { assertTrue(api.setTags(virtualGuest.getId(), ImmutableSet.of("test1", "test2", "test3"))); @@ -215,7 +215,7 @@ public class VirtualGuestApiMockTest extends BaseSoftLayerMockTest { public void testSetTagsOnNonExistingVirtualGuest() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(404)); - VirtualGuestApi api = api(SoftLayerApi.class, server.getUrl("/").toString()).getVirtualGuestApi(); + VirtualGuestApi api = api(SoftLayerApi.class, server.url("/").toString()).getVirtualGuestApi(); VirtualGuest virtualGuest = createVirtualGuest(); try { assertFalse(api.setTags(virtualGuest.getId(), ImmutableSet.of("test1", "test2", "test3"))); @@ -241,7 +241,7 @@ public class VirtualGuestApiMockTest extends BaseSoftLayerMockTest { } private VirtualGuestApi getVirtualGuestApi(MockWebServer server) { - return api(SoftLayerApi.class, server.getUrl("/").toString(), new + return api(SoftLayerApi.class, server.url("/").toString(), new JavaUrlHttpCommandExecutorServiceModule(), new SoftLayerParserModule()).getVirtualGuestApi(); } diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestBlockDeviceTemplateGroupApiMockTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestBlockDeviceTemplateGroupApiMockTest.java index 3b6002e848..ce8a544fb4 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestBlockDeviceTemplateGroupApiMockTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestBlockDeviceTemplateGroupApiMockTest.java @@ -20,14 +20,15 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; + import org.jclouds.softlayer.SoftLayerApi; import org.jclouds.softlayer.internal.BaseSoftLayerMockTest; import org.jclouds.softlayer.parse.PublicImagesParseTest; import org.jclouds.softlayer.parse.VirtualGuestBlockDeviceTemplateGroupParseTest; import org.testng.annotations.Test; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; /** * Mock tests for the {@link VirtualGuestBlockDeviceTemplateGroupApi} class. @@ -80,7 +81,7 @@ public class VirtualGuestBlockDeviceTemplateGroupApiMockTest extends BaseSoftLay } private VirtualGuestBlockDeviceTemplateGroupApi getVirtualGuestBlockDeviceTemplateGroupApi(MockWebServer server) { - return api(SoftLayerApi.class, server.getUrl("/").toString()).getVirtualGuestBlockDeviceTemplateGroupApi(); + return api(SoftLayerApi.class, server.url("/").toString()).getVirtualGuestBlockDeviceTemplateGroupApi(); } } diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/internal/BaseSoftLayerMockTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/internal/BaseSoftLayerMockTest.java index 739a12de3d..0eecb0a6df 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/internal/BaseSoftLayerMockTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/internal/BaseSoftLayerMockTest.java @@ -27,15 +27,16 @@ import java.util.Properties; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; + import org.jclouds.http.BaseMockWebServerTest; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.softlayer.SoftLayerApiMetadata; -import com.google.common.base.Charsets; import com.google.common.base.Throwables; import com.google.inject.Module; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; + /** * Base class for all SoftLayer mock tests. @@ -54,9 +55,9 @@ public class BaseSoftLayerMockTest extends BaseMockWebServerTest { return new JavaUrlHttpCommandExecutorServiceModule(); } - public byte[] payloadFromResource(String resource) { + public String payloadFromResource(String resource) { try { - return toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8); + return toStringAndClose(getClass().getResourceAsStream(resource)); } catch (IOException e) { throw Throwables.propagate(e); }