Search in sources :

Example 66 with Builder

use of okhttp3.Request.Builder in project docker-client by spotify.

the class DefaultDockerClientUnitTest method testInspectVolume.

@Test
public void testInspectVolume() throws Exception {
    final DefaultDockerClient dockerClient = new DefaultDockerClient(builder);
    server.enqueue(new MockResponse().setResponseCode(200).addHeader("Content-Type", "application/json").setBody(fixture("fixtures/1.33/inspectVolume.json")));
    final Volume volume = dockerClient.inspectVolume("my-volume");
    assertThat(volume.name(), is("tardis"));
    assertThat(volume.driver(), is("custom"));
    assertThat(volume.mountpoint(), is("/var/lib/docker/volumes/tardis"));
    assertThat(volume.status(), is(ImmutableMap.of("hello", "world")));
    assertThat(volume.labels(), is(ImmutableMap.of("com.example.some-label", "some-value", "com.example.some-other-label", "some-other-value")));
    assertThat(volume.scope(), is("local"));
    assertThat(volume.options(), is(ImmutableMap.of("foo", "bar", "baz", "qux")));
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) Volume(com.spotify.docker.client.messages.Volume) Test(org.junit.Test)

Example 67 with Builder

use of okhttp3.Request.Builder in project docker-client by spotify.

the class DefaultDockerClientUnitTest method testCapAddAndDrop.

@Test
@SuppressWarnings("unchecked")
public void testCapAddAndDrop() throws Exception {
    final DefaultDockerClient dockerClient = new DefaultDockerClient(builder);
    final HostConfig hostConfig = HostConfig.builder().capAdd(ImmutableList.of("foo", "bar")).capAdd(ImmutableList.of("baz", "qux")).build();
    final ContainerConfig containerConfig = ContainerConfig.builder().hostConfig(hostConfig).build();
    server.enqueue(new MockResponse());
    dockerClient.createContainer(containerConfig);
    final RecordedRequest recordedRequest = takeRequestImmediately();
    assertThat(recordedRequest.getMethod(), is("POST"));
    assertThat(recordedRequest.getPath(), is("/containers/create"));
    assertThat(recordedRequest.getHeader("Content-Type"), is("application/json"));
    // TODO (mbrown): use hamcrest-jackson for this, once we upgrade to Java 8
    final JsonNode requestJson = toJson(recordedRequest.getBody());
    final JsonNode capAddNode = requestJson.get("HostConfig").get("CapAdd");
    assertThat(capAddNode.isArray(), is(true));
    assertThat(childrenTextNodes((ArrayNode) capAddNode), containsInAnyOrder("baz", "qux"));
}
Also used : ContainerConfig(com.spotify.docker.client.messages.ContainerConfig) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) HostConfig(com.spotify.docker.client.messages.HostConfig) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Test(org.junit.Test)

Example 68 with Builder

use of okhttp3.Request.Builder in project docker-client by spotify.

the class DefaultDockerClientUnitTest method testInspectNodeNonManager.

@Test
public void testInspectNodeNonManager() throws Exception {
    final DefaultDockerClient dockerClient = new DefaultDockerClient(builder);
    enqueueServerApiVersion("1.27");
    server.enqueue(new MockResponse().setResponseCode(200).addHeader("Content-Type", "application/json").setBody(fixture("fixtures/1.27/nodeInfoNonManager.json")));
    NodeInfo nodeInfo = dockerClient.inspectNode("24ifsmvkjbyhk");
    assertThat(nodeInfo, notNullValue());
    assertThat(nodeInfo.id(), is("24ifsmvkjbyhk"));
    assertThat(nodeInfo.status(), notNullValue());
    assertThat(nodeInfo.status().addr(), is("172.17.0.2"));
    assertThat(nodeInfo.managerStatus(), nullValue());
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) NodeInfo(com.spotify.docker.client.messages.swarm.NodeInfo) Test(org.junit.Test)

Example 69 with Builder

use of okhttp3.Request.Builder in project docker-client by spotify.

the class DefaultDockerClientUnitTest method testInspectNonLeaderNode.

@Test
public void testInspectNonLeaderNode() throws Exception {
    final DefaultDockerClient dockerClient = new DefaultDockerClient(builder);
    enqueueServerApiVersion("1.27");
    server.enqueue(new MockResponse().setResponseCode(200).addHeader("Content-Type", "application/json").setBody(fixture("fixtures/1.27/nodeInfoNonLeader.json")));
    NodeInfo nodeInfo = dockerClient.inspectNode("24ifsmvkjbyhk");
    assertThat(nodeInfo, notNullValue());
    assertThat(nodeInfo.id(), is("24ifsmvkjbyhk"));
    assertThat(nodeInfo.status(), notNullValue());
    assertThat(nodeInfo.status().addr(), is("172.17.0.2"));
    assertThat(nodeInfo.managerStatus(), notNullValue());
    assertThat(nodeInfo.managerStatus().addr(), is("172.17.0.2:2377"));
    assertThat(nodeInfo.managerStatus().leader(), nullValue());
    assertThat(nodeInfo.managerStatus().reachability(), is("reachable"));
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) NodeInfo(com.spotify.docker.client.messages.swarm.NodeInfo) Test(org.junit.Test)

Example 70 with Builder

use of okhttp3.Request.Builder in project docker-client by spotify.

the class DefaultDockerClientUnitTest method testInspectConfig_NotFound.

@Test(expected = NotFoundException.class)
public void testInspectConfig_NotFound() throws Exception {
    final DefaultDockerClient dockerClient = new DefaultDockerClient(builder);
    enqueueServerApiVersion("1.30");
    server.enqueue(new MockResponse().setResponseCode(404).addHeader("Content-Type", "application/json"));
    dockerClient.inspectConfig("ktnbjxoalbkvbvedmg1urrz8h");
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) Test(org.junit.Test)

Aggregations

Request (okhttp3.Request)170 Response (okhttp3.Response)120 OkHttpClient (okhttp3.OkHttpClient)103 IOException (java.io.IOException)89 RequestBody (okhttp3.RequestBody)68 Test (org.junit.Test)68 File (java.io.File)36 MultipartBody (okhttp3.MultipartBody)36 HttpUrl (okhttp3.HttpUrl)34 Map (java.util.Map)31 MockResponse (okhttp3.mockwebserver.MockResponse)31 Call (okhttp3.Call)26 Interceptor (okhttp3.Interceptor)26 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)26 HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)24 Builder (okhttp3.OkHttpClient.Builder)21 Retrofit (retrofit2.Retrofit)21 Builder (okhttp3.Request.Builder)19 FormBody (okhttp3.FormBody)18 ResponseBody (okhttp3.ResponseBody)18