Search in sources :

Example 41 with Builder

use of okhttp3.HttpUrl.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 42 with Builder

use of okhttp3.HttpUrl.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 43 with Builder

use of okhttp3.HttpUrl.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 44 with Builder

use of okhttp3.HttpUrl.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 45 with Builder

use of okhttp3.HttpUrl.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)204 Response (okhttp3.Response)146 OkHttpClient (okhttp3.OkHttpClient)141 IOException (java.io.IOException)111 RequestBody (okhttp3.RequestBody)81 Test (org.junit.Test)75 HttpUrl (okhttp3.HttpUrl)47 File (java.io.File)42 MultipartBody (okhttp3.MultipartBody)40 MockResponse (okhttp3.mockwebserver.MockResponse)40 Map (java.util.Map)39 HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)31 Call (okhttp3.Call)29 Interceptor (okhttp3.Interceptor)29 Retrofit (retrofit2.Retrofit)29 Builder (okhttp3.OkHttpClient.Builder)26 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)25 ResponseBody (okhttp3.ResponseBody)24 HashMap (java.util.HashMap)22 FormBody (okhttp3.FormBody)21