JCLOUDS-1551: Update version of OkHttp 3.14.9

This commit is contained in:
korlov42 2020-10-06 18:38:30 +03:00 committed by Andrew Gaul
parent 56ad552344
commit 44ff69d144
130 changed files with 1128 additions and 890 deletions

View File

@ -104,7 +104,7 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
<exclusions>
@ -115,6 +115,18 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp-tls</artifactId>
<scope>test</scope>
<exclusions>
<!-- Already provided by jclouds-sshj -->
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap</groupId>
<artifactId>shrinkwrap-depchain</artifactId>

View File

@ -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();
}
}

View File

@ -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");

View File

@ -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");

View File

@ -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);

View File

@ -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<String, String> options = ImmutableMap.<String, String> 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\" }");

View File

@ -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;
}

View File

@ -84,7 +84,7 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
<exclusions>

View File

@ -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("<regionName>").append(region).append("</regionName>");
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("<regionEndpoint>").append(regionEndpoint).append("</regionEndpoint>");
describeRegionsResponse.append("</item>");
}
@ -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;
}
}

View File

@ -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 {

View File

@ -72,7 +72,7 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
<exclusions>
@ -83,6 +83,18 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp-tls</artifactId>
<scope>test</scope>
<exclusions>
<!-- Already provided by jclouds-sshj -->
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>

View File

@ -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<String> 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<StandardDrive> 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);
}

View File

@ -66,7 +66,7 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
</dependency>

View File

@ -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 + "&" +

View File

@ -78,7 +78,7 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
</dependency>

View File

@ -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<KeystoneApi> {
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<? extends Role> roles = roleAdminApi.list();
@ -78,7 +80,7 @@ public class RoleAdminApiMockTest extends BaseOpenStackMockTest<KeystoneApi> {
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<KeystoneApi> {
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<KeystoneApi> {
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<KeystoneApi> {
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");

View File

@ -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<KeystoneApi>
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<? extends Service> services = serviceAdminApi.list();
@ -80,7 +82,7 @@ public class ServiceAdminApiMockTest extends BaseOpenStackMockTest<KeystoneApi>
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<? extends Service> services = serviceAdminApi.list(new PaginationOptions());
@ -106,7 +108,7 @@ public class ServiceAdminApiMockTest extends BaseOpenStackMockTest<KeystoneApi>
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<KeystoneApi>
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<KeystoneApi>
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<KeystoneApi>
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");

View File

@ -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<KeystoneApi> {
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<KeystoneApi> {
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<KeystoneApi> {
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<KeystoneApi> {
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<KeystoneApi> {
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<KeystoneApi> {
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<KeystoneApi> {
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");

View File

@ -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<KeystoneApi> {
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<KeystoneApi> {
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<KeystoneApi> {
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<KeystoneApi> {
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<KeystoneApi> {
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");

View File

@ -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 {

View File

@ -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 {

View File

@ -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<KeystoneApi> 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) {

View File

@ -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<A extends Closeable> {
@ -85,9 +87,9 @@ public class BaseOpenStackMockTest<A extends Closeable> {
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<A extends Closeable> {
* 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<MockResponse> responseQueue = new LinkedBlockingQueue<MockResponse>();
@ -108,7 +112,7 @@ public class BaseOpenStackMockTest<A extends Closeable> {
* 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<A extends Closeable> {
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<A extends Closeable> {
* @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<A extends Closeable> {
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);
}

View File

@ -78,7 +78,7 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
</dependency>

View File

@ -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<Firewall> 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");

View File

@ -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");

View File

@ -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<LBaaSApi> 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<LBaaSApi> 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");

View File

@ -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<Extension> 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");

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -104,7 +104,7 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
<exclusions>

View File

@ -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<NovaApi> {
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");

View File

@ -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<NovaApi> {
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> hypervisorApi = novaApi.getHypervisorApi("RegionOne");
@ -72,7 +74,7 @@ public class HypervisorApiMockTest extends BaseOpenStackMockTest<NovaApi> {
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> hypervisorApi = novaApi.getHypervisorApi("RegionOne");
@ -87,7 +89,7 @@ public class HypervisorApiMockTest extends BaseOpenStackMockTest<NovaApi> {
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<? extends Hypervisor> hypervisors = novaApi.getHypervisorApi("RegionOne").get().list();
@ -106,7 +108,7 @@ public class HypervisorApiMockTest extends BaseOpenStackMockTest<NovaApi> {
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<? extends HypervisorDetails> hypervisors = novaApi.getHypervisorApi("RegionOne").get().listInDetail();

View File

@ -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<NovaApi> {
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<? extends Image> images = imageApi.listInDetail().concat();

View File

@ -95,7 +95,7 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
</dependency>

View File

@ -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<SwiftApi> {
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();
}

View File

@ -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)

View File

@ -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<SwiftApi> {
@ -40,7 +41,7 @@ public class TemporaryUrlSignerMockTest extends BaseOpenStackMockTest<SwiftApi>
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<SwiftApi>
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 {

View File

@ -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<SwiftApi> {
@ -51,7 +53,7 @@ public class AccountApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
.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<SwiftApi> {
.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<SwiftApi> {
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<SwiftApi> {
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);

View File

@ -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<SwiftApi> {
@ -53,7 +55,7 @@ public class BulkApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
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<SwiftApi> {
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();
}

View File

@ -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<SwiftApi> {
@ -53,7 +55,7 @@ public class ContainerApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
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<Container> containers = api.getContainerApi("DFW").list().toList();
assertEquals(containers, ImmutableList.of(
Container.builder()
@ -82,7 +84,7 @@ public class ContainerApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
assertNotNull(options);
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
SwiftApi api = api(server.url("/").toString(), "openstack-swift");
ImmutableList<Container> containers = api.getContainerApi("DFW").list(options).toList();
assertEquals(containers, ImmutableList.of(
Container.builder()
@ -111,7 +113,7 @@ public class ContainerApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
.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<SwiftApi> {
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<SwiftApi> {
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<SwiftApi> {
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<SwiftApi> {
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<SwiftApi> {
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<SwiftApi> {
.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<SwiftApi> {
.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<SwiftApi> {
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<SwiftApi> {
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<SwiftApi> {
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 {

View File

@ -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<SwiftApi> {
@ -48,7 +50,7 @@ public final class DynamicLargeObjectApiMockTest extends BaseOpenStackMockTest<S
server.enqueue(addCommonHeaders(new MockResponse().addHeader("X-Object-Manifest", "myContainer/myObject")));
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
SwiftApi api = api(server.url("/").toString(), "openstack-swift");
assertEquals(api.getObjectApi("DFW", containerName).put(objectName.concat("1"), Payloads.newPayload("data1")),
"89d903bc35dede724fd52c51437ff5fd");
assertEquals(api.getDynamicLargeObjectApi("DFW", containerName).putManifest(objectName,
@ -60,7 +62,7 @@ public final class DynamicLargeObjectApiMockTest extends BaseOpenStackMockTest<S
RecordedRequest uploadRequest = server.takeRequest();
assertEquals(uploadRequest.getRequestLine(),
"PUT /v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer/myObjectTest1 HTTP/1.1");
assertEquals(new String(uploadRequest.getBody()), "data1");
assertEquals(uploadRequest.getBody().readUtf8(), "data1");
RecordedRequest uploadRequestManifest = server.takeRequest();
assertRequest(uploadRequestManifest, "PUT",
@ -80,7 +82,7 @@ public final class DynamicLargeObjectApiMockTest extends BaseOpenStackMockTest<S
server.enqueue(addCommonHeaders(new MockResponse().addHeader("X-Object-Manifest", "myContainer/myObject")));
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
SwiftApi api = api(server.url("/").toString(), "openstack-swift");
assertEquals(api.getDynamicLargeObjectApi("DFW", "myContainer").putManifest("myObject",
ImmutableMap.of("MyFoo", "Bar"), ImmutableMap.of("MyFoo", "Bar")), "abcd");
@ -104,7 +106,7 @@ public final class DynamicLargeObjectApiMockTest extends BaseOpenStackMockTest<S
server.enqueue(addCommonHeaders(new MockResponse().addHeader("X-Object-Manifest", "myContainer/myObject")));
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
SwiftApi api = api(server.url("/").toString(), "openstack-swift");
assertEquals(api.getDynamicLargeObjectApi("DFW", "myContainer").putManifest("unic₪de",
ImmutableMap.of("MyFoo", "Bar"), ImmutableMap.of("MyFoo", "Bar")), "abcd");

View File

@ -16,10 +16,8 @@
*/
package org.jclouds.openstack.swift.v1.features;
import static com.google.common.base.Charsets.US_ASCII;
import static com.google.common.io.BaseEncoding.base16;
import static com.google.common.net.HttpHeaders.EXPIRES;
import static org.assertj.core.api.Assertions.assertThat;
import static org.jclouds.Constants.PROPERTY_MAX_RETRIES;
import static org.jclouds.Constants.PROPERTY_RETRY_DELAY_START;
import static org.jclouds.Constants.PROPERTY_SO_TIMEOUT;
@ -40,11 +38,15 @@ import static org.testng.Assert.fail;
import java.io.IOException;
import java.net.URI;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import okhttp3.Headers;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import org.jclouds.blobstore.KeyNotFoundException;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.http.HttpResponseException;
@ -62,9 +64,7 @@ import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.ByteSource;
import com.squareup.okhttp.mockwebserver.MockResponse;
import com.squareup.okhttp.mockwebserver.MockWebServer;
import com.squareup.okhttp.mockwebserver.RecordedRequest;
/**
* Provides mock tests for the {@link ObjectApi}.
@ -106,9 +106,9 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
.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<SwiftApi> {
.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<SwiftApi> {
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<SwiftApi> {
.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<SwiftApi> {
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<String, String> entry : metadata.entrySet()) {
assertEquals(replace.getHeader(OBJECT_METADATA_PREFIX + entry.getKey().toLowerCase()), entry.getValue());
}
@ -203,7 +203,7 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
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<SwiftApi> {
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<SwiftApi> {
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<SwiftApi> {
// 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<String, String> entry : metadata.entrySet()) {
assertEquals(replace.getHeader(OBJECT_METADATA_PREFIX + entry.getKey().toLowerCase()), entry.getValue());
}
@ -288,7 +288,7 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
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<SwiftApi> {
.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<SwiftApi> {
.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<SwiftApi> {
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<SwiftApi> {
.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<SwiftApi> {
.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<SwiftApi> {
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<SwiftApi> {
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<SwiftApi> {
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<SwiftApi> {
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<SwiftApi> {
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<SwiftApi> {
assertEquals(copyRequest.getRequestLine(),
"PUT /v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/foo/bar.txt HTTP/1.1");
List<String> 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<SwiftApi> {
.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<SwiftApi> {
.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<SwiftApi> {
assertEquals(copyRequest.getRequestLine(),
"PUT /v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/foo/bar.txt HTTP/1.1");
List<String> 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<SwiftApi> {
.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<SwiftApi> {
.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");

View File

@ -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<SwiftApi> {
@ -46,7 +48,7 @@ public class StaticLargeObjectApiMockTest extends BaseOpenStackMockTest<SwiftApi
server.enqueue(addCommonHeaders(new MockResponse().addHeader(HttpHeaders.ETAG, "\"abcd\"")));
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
SwiftApi api = api(server.url("/").toString(), "openstack-swift");
assertEquals(
api.getStaticLargeObjectApi("DFW", "myContainer").replaceManifest(
"myObject",
@ -67,7 +69,7 @@ public class StaticLargeObjectApiMockTest extends BaseOpenStackMockTest<SwiftApi
assertRequest(replaceRequest, "PUT", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer/myObject?multipart-manifest=put");
assertEquals(replaceRequest.getHeader(OBJECT_METADATA_PREFIX + "myfoo"), "Bar");
assertEquals(
new String(replaceRequest.getBody()),
replaceRequest.getBody().readUtf8(),
"[{\"path\":\"/mycontainer/objseg1\",\"etag\":\"0228c7926b8b642dfb29554cd1f00963\",\"size_bytes\":1468006}," +
"{\"path\":\"/mycontainer/pseudodir/seg-obj2\",\"etag\":\"5bfc9ea51a00b790717eeb934fb77b9b\",\"size_bytes\":1572864}," +
"{\"path\":\"/other-container/seg-final\",\"etag\":\"b9c3da507d2557c1ddc51f27c54bae51\",\"size_bytes\":256}]");
@ -82,7 +84,7 @@ public class StaticLargeObjectApiMockTest extends BaseOpenStackMockTest<SwiftApi
server.enqueue(addCommonHeaders(new MockResponse().addHeader(HttpHeaders.ETAG, "\"abcd\"")));
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
SwiftApi api = api(server.url("/").toString(), "openstack-swift");
assertEquals(
api.getStaticLargeObjectApi("DFW", "myContainer").replaceManifest(
"unic₪de",
@ -115,7 +117,7 @@ public class StaticLargeObjectApiMockTest extends BaseOpenStackMockTest<SwiftApi
assertEquals(replaceRequest.getHeader("content-length"), Long.toString(byteLength));
assertEquals(
new String(replaceRequest.getBody()),
replaceRequest.getBody().readUtf8(),
expectedManifest);
} finally {
server.shutdown();
@ -128,7 +130,7 @@ public class StaticLargeObjectApiMockTest extends BaseOpenStackMockTest<SwiftApi
server.enqueue(addCommonHeaders(new MockResponse().addHeader(HttpHeaders.ETAG, "\"abcd\"")));
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
SwiftApi api = api(server.url("/").toString(), "openstack-swift");
assertEquals(
api.getStaticLargeObjectApi("DFW", "myContainer").replaceManifest(
"myObject",
@ -158,7 +160,7 @@ public class StaticLargeObjectApiMockTest extends BaseOpenStackMockTest<SwiftApi
assertEquals(replaceRequest.getHeader("some-header1"), "some-header-value");
assertEquals(
new String(replaceRequest.getBody()),
replaceRequest.getBody().readUtf8(),
"[{\"path\":\"/mycontainer/objseg1\",\"etag\":\"0228c7926b8b642dfb29554cd1f00963\",\"size_bytes\":1468006}," +
"{\"path\":\"/mycontainer/pseudodir/seg-obj2\",\"etag\":\"5bfc9ea51a00b790717eeb934fb77b9b\",\"size_bytes\":1572864}," +
"{\"path\":\"/other-container/seg-final\",\"etag\":\"b9c3da507d2557c1ddc51f27c54bae51\",\"size_bytes\":256}]");
@ -174,7 +176,7 @@ public class StaticLargeObjectApiMockTest extends BaseOpenStackMockTest<SwiftApi
stringFromResource("/manifest_get_response.json")) ));
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
SwiftApi api = api(server.url("/").toString(), "openstack-swift");
List<Segment> manifest = api.getStaticLargeObjectApi("DFW", "myContainer").getManifest("myObject");
// Check response
@ -199,7 +201,7 @@ public class StaticLargeObjectApiMockTest extends BaseOpenStackMockTest<SwiftApi
server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(404).setBody(stringFromResource("/manifest_get_response.json")) ));
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
SwiftApi api = api(server.url("/").toString(), "openstack-swift");
List<Segment> manifest = api.getStaticLargeObjectApi("DFW", "myContainer").getManifest("myObject");
// Check response
@ -222,7 +224,7 @@ public class StaticLargeObjectApiMockTest extends BaseOpenStackMockTest<SwiftApi
.setBody("{\"Number Not Found\": 0, \"Response Status\": \"200 OK\", \"Errors\": [], \"Number Deleted\": 6, \"Response Body\": \"\"}")));
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
SwiftApi api = api(server.url("/").toString(), "openstack-swift");
DeleteStaticLargeObjectResponse response = api.getStaticLargeObjectApi("DFW", "myContainer").delete("myObject");
assertEquals(server.getRequestCount(), 2);
@ -244,7 +246,7 @@ public class StaticLargeObjectApiMockTest extends BaseOpenStackMockTest<SwiftApi
.setBody("{\"Number Not Found\": 1, \"Response Status\": \"200 OK\", \"Errors\": [], \"Number Deleted\": 0, \"Response Body\": \"\"}")));
try {
SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
SwiftApi api = api(server.url("/").toString(), "openstack-swift");
DeleteStaticLargeObjectResponse response = api.getStaticLargeObjectApi("DFW", "myContainer").delete("myObject");
assertEquals(server.getRequestCount(), 2);

View File

@ -109,7 +109,7 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
</dependency>

View File

@ -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<CloudFilesAp
server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/cdn_container_list.json"))));
try {
CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles");
CloudFilesApi api = api(server.url("/").toString(), "rackspace-cloudfiles");
CDNApi cdnApi = api.getCDNApi("DFW");
ImmutableList<CDNContainer> cdnContainers = cdnApi.list().toList();
@ -81,7 +83,7 @@ public class CloudFilesCDNApiMockTest extends BaseOpenStackMockTest<CloudFilesAp
server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(404)));
try {
CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles");
CloudFilesApi api = api(server.url("/").toString(), "rackspace-cloudfiles");
CDNApi cdnApi = api.getCDNApi("DFW");
List<CDNContainer> cdnContainers = cdnApi.list().toList();
@ -102,7 +104,7 @@ public class CloudFilesCDNApiMockTest extends BaseOpenStackMockTest<CloudFilesAp
server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/cdn_container_list_at.json"))));
try {
CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles");
CloudFilesApi api = api(server.url("/").toString(), "rackspace-cloudfiles");
ListCDNContainerOptions options = new ListCDNContainerOptions().marker("cdn-container-3");
ImmutableList<CDNContainer> containers = api.getCDNApi("DFW").list(options).toList();
@ -126,7 +128,7 @@ public class CloudFilesCDNApiMockTest extends BaseOpenStackMockTest<CloudFilesAp
server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(404)));
try {
CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles");
CloudFilesApi api = api(server.url("/").toString(), "rackspace-cloudfiles");
ListCDNContainerOptions options = ListCDNContainerOptions.Builder.marker("cdn-container-3");
FluentIterable<CDNContainer> containers = api.getCDNApi("DFW").list(options);
@ -147,7 +149,7 @@ public class CloudFilesCDNApiMockTest extends BaseOpenStackMockTest<CloudFilesAp
server.enqueue(addCommonHeaders(enabledResponse().setResponseCode(201)));
try {
CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles");
CloudFilesApi api = api(server.url("/").toString(), "rackspace-cloudfiles");
// enable a CDN Container
URI enabledContainer = api.getCDNApi("DFW").enable("container-1");
@ -167,7 +169,7 @@ public class CloudFilesCDNApiMockTest extends BaseOpenStackMockTest<CloudFilesAp
server.enqueue(addCommonHeaders(enabledResponse().setResponseCode(404)));
try {
CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles");
CloudFilesApi api = api(server.url("/").toString(), "rackspace-cloudfiles");
// enable a CDN Container
assertNull(api.getCDNApi("DFW").enable("container-1"));
@ -185,7 +187,7 @@ public class CloudFilesCDNApiMockTest extends BaseOpenStackMockTest<CloudFilesAp
server.enqueue(addCommonHeaders(enabledResponse().setResponseCode(201)));
try {
CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles");
CloudFilesApi api = api(server.url("/").toString(), "rackspace-cloudfiles");
// enable a CDN Container with a TTL
URI enabledContainer = api.getCDNApi("DFW").enable("container-1", 777777);
@ -205,7 +207,7 @@ public class CloudFilesCDNApiMockTest extends BaseOpenStackMockTest<CloudFilesAp
server.enqueue(addCommonHeaders(enabledResponse().setResponseCode(404)));
try {
CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles");
CloudFilesApi api = api(server.url("/").toString(), "rackspace-cloudfiles");
// enable a CDN Container with a TTL
URI enabledContainer = api.getCDNApi("DFW").enable("container-1", 777777);
@ -225,7 +227,7 @@ public class CloudFilesCDNApiMockTest extends BaseOpenStackMockTest<CloudFilesAp
server.enqueue(addCommonHeaders(enabledResponse().setResponseCode(201)));
try {
CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles");
CloudFilesApi api = api(server.url("/").toString(), "rackspace-cloudfiles");
// disable a CDN Container
assertTrue(api.getCDNApi("DFW").disable("container-1"));
@ -244,7 +246,7 @@ public class CloudFilesCDNApiMockTest extends BaseOpenStackMockTest<CloudFilesAp
server.enqueue(addCommonHeaders(enabledResponse().setResponseCode(404)));
try {
CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles");
CloudFilesApi api = api(server.url("/").toString(), "rackspace-cloudfiles");
// disable a CDN Container
boolean disbledContainer = api.getCDNApi("DFW").disable("container-1");
@ -264,7 +266,7 @@ public class CloudFilesCDNApiMockTest extends BaseOpenStackMockTest<CloudFilesAp
server.enqueue(addCommonHeaders(enabledResponse().setResponseCode(201)));
try {
CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles");
CloudFilesApi api = api(server.url("/").toString(), "rackspace-cloudfiles");
CDNContainer cdnContainer = api.getCDNApi("DFW").get("container-1");
assertCDNContainerNotNull(cdnContainer);
@ -284,7 +286,7 @@ public class CloudFilesCDNApiMockTest extends BaseOpenStackMockTest<CloudFilesAp
server.enqueue(addCommonHeaders(enabledResponse().setResponseCode(201)));
try {
CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles");
CloudFilesApi api = api(server.url("/").toString(), "rackspace-cloudfiles");
CDNContainer cdnContainer = api.getCDNApi("DFW").get("cdn-container with spaces");
assertCDNContainerNotNull(cdnContainer);
@ -304,7 +306,7 @@ public class CloudFilesCDNApiMockTest extends BaseOpenStackMockTest<CloudFilesAp
server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(404)));
try {
CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles");
CloudFilesApi api = api(server.url("/").toString(), "rackspace-cloudfiles");
CDNContainer cdnContainer = api.getCDNApi("DFW").get("container-1");
@ -322,7 +324,7 @@ public class CloudFilesCDNApiMockTest extends BaseOpenStackMockTest<CloudFilesAp
server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201)));
try {
CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles");
CloudFilesApi api = api(server.url("/").toString(), "rackspace-cloudfiles");
// purge the object
assertTrue(api.getCDNApi("DFW").purgeObject("myContainer", "myObject", emails));
@ -341,7 +343,7 @@ public class CloudFilesCDNApiMockTest extends BaseOpenStackMockTest<CloudFilesAp
server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(404)));
try {
CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles");
CloudFilesApi api = api(server.url("/").toString(), "rackspace-cloudfiles");
// purge the object
assertFalse(api.getCDNApi("DFW").purgeObject("myContainer", "myObject", emails));
@ -362,7 +364,7 @@ public class CloudFilesCDNApiMockTest extends BaseOpenStackMockTest<CloudFilesAp
server.enqueue(addCommonHeaders(updatedResponse().setResponseCode(200)));
try {
CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles");
CloudFilesApi api = api(server.url("/").toString(), "rackspace-cloudfiles");
CDNContainer cdnContainer = api.getCDNApi("DFW").get("container-1");
assertCDNContainerNotNull(cdnContainer);
@ -403,7 +405,7 @@ public class CloudFilesCDNApiMockTest extends BaseOpenStackMockTest<CloudFilesAp
server.enqueue(addCommonHeaders(updatedResponse().setResponseCode(404)));
try {
CloudFilesApi api = api(server.getUrl("/").toString(), "rackspace-cloudfiles");
CloudFilesApi api = api(server.url("/").toString(), "rackspace-cloudfiles");
CDNContainer cdnContainer = api.getCDNApi("DFW").get("container-1");
assertCDNContainerNotNull(cdnContainer);

View File

@ -88,7 +88,7 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
</dependency>

View File

@ -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 {
" <LastModified>2009-10-28T22:32:00</LastModified>\n" +
" <ETag>\"9b2cf535f27731c974343645a3985328\"</ETag>\n" +
" </CopyObjectResult>"));
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();
}
}

View File

@ -83,10 +83,15 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp-tls</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>

View File

@ -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) {

View File

@ -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("");

View File

@ -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();

View File

@ -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.
*/

View File

@ -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) {
}

View File

@ -49,10 +49,15 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp-tls</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-stubs</artifactId>

View File

@ -44,15 +44,20 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>${okhttp.version}</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp-tls</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -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

View File

@ -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<Request> {
private final Function<URI, Proxy> 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();

View File

@ -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);
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
// <adriancole.s3int0.s3-external-3.amazonaws.com>
client.setFollowRedirects(false);
.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();
}
}

View File

@ -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();
}
});
}

View File

@ -232,7 +232,7 @@
<guava.version>27.1-jre</guava.version>
<guice.version>4.2.3</guice.version>
<okhttp.version>2.2.0</okhttp.version>
<okhttp.version>3.14.9</okhttp.version>
<auto-factory.version>0.1-beta1</auto-factory.version>
<auto-service.version>1.0-rc3</auto-service.version>
<auto-value.version>1.4.1</auto-value.version>
@ -407,10 +407,15 @@
<version>${easymock.version}</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<version>${okhttp.version}</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp-tls</artifactId>
<version>${okhttp.version}</version>
</dependency>
<!-- Static analysis dependencies -->
<dependency>

View File

@ -97,7 +97,7 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
<exclusions>

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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("<regionName>").append(region).append("</regionName>");
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("<regionEndpoint>").append(regionEndpoint).append("</regionEndpoint>");
describeRegionsResponse.append("</item>");
}
@ -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;

View File

@ -90,7 +90,7 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
<exclusions>

View File

@ -113,7 +113,7 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
<exclusions>

View File

@ -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;

View File

@ -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));

View File

@ -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;

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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)

View File

@ -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;

View File

@ -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;

View File

@ -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 {

View File

@ -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 {

View File

@ -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<Supplier<URI>>() {
}).annotatedWith(GraphRBAC.class).toInstance(
Suppliers.ofInstance(URI.create(server.getUrl("/graphrbac").toString() + "/tenant-id")));
Suppliers.ofInstance(URI.create(server.url("/graphrbac").toString() + "/tenant-id")));
}
}
}

View File

@ -76,7 +76,7 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
</dependency>

View File

@ -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");
}
/**

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -96,7 +96,7 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
<exclusions>

View File

@ -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 {

View File

@ -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<DigitalOcean2Api> 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;
}
}

View File

@ -52,7 +52,7 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
</dependency>

View File

@ -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();

View File

@ -116,7 +116,7 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
<exclusions>

Some files were not shown because too many files have changed in this diff Show More