Skip to content

Commit

Permalink
Merge ab0d78e into 6667347
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed Nov 4, 2018
2 parents 6667347 + ab0d78e commit 92d3b4d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main/java/com/amihaiemil/docker/Docker.java
Expand Up @@ -25,6 +25,8 @@
*/
package com.amihaiemil.docker;

import org.apache.http.client.HttpClient;

import java.io.IOException;

/**
Expand Down Expand Up @@ -79,4 +81,19 @@ public interface Docker {
* @return Swarm.
*/
Swarm swarm();

/**
* The underlying, immutable, Apache HttpClient.<br><br>
*
* Use this method to fetch the underlying HttpClient and perform your own
* HTTP requests, in case the API is missing the desired method.<br><br>
*
* Usage in any other scenario is discouraged. Try to find the desired
* method before using this. Also, if the method is missing, open an
* Issue at https://www.github.com/amihaiemil/docker-java-api, maybe
* it can be implemented and released quickly.
*
* @return The underlying HttpClient.
*/
HttpClient httpClient();
}
5 changes: 5 additions & 0 deletions src/main/java/com/amihaiemil/docker/RtDocker.java
Expand Up @@ -118,4 +118,9 @@ public final Swarm swarm() {
this
);
}

@Override
public HttpClient httpClient() {
return this.client;
}
}
16 changes: 16 additions & 0 deletions src/test/java/com/amihaiemil/docker/LocalDockerTestCase.java
Expand Up @@ -126,4 +126,20 @@ public void returnsImages() {
Matchers.notNullValue()
);
}

/**
* LocalDocker can return its HttpClient.
*/
@Test
public void returnsHttpClient() {
MatcherAssert.assertThat(
new LocalDocker(
new File("/var/run/docker.sock")
).httpClient(),
Matchers.allOf(
Matchers.notNullValue(),
Matchers.instanceOf(UnixHttpClient.class)
)
);
}
}
19 changes: 19 additions & 0 deletions src/test/java/com/amihaiemil/docker/RemoteDockerTestCase.java
Expand Up @@ -27,6 +27,7 @@

import com.amihaiemil.docker.mock.AssertRequest;
import com.amihaiemil.docker.mock.Response;

import java.net.URI;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
Expand Down Expand Up @@ -121,4 +122,22 @@ public void returnsImages() {
Matchers.notNullValue()
);
}

/**
* LocalDocker can return its HttpClient.
*/
@Test
public void returnsHttpClient() {
final HttpClient client = Mockito.mock(HttpClient.class);
MatcherAssert.assertThat(
new RemoteDocker(
client,
URI.create("http://localhost")
).httpClient(),
Matchers.allOf(
Matchers.notNullValue(),
Matchers.sameInstance(client)
)
);
}
}

0 comments on commit 92d3b4d

Please sign in to comment.