Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/main/java/com/amihaiemil/docker/LocalDocker.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
package com.amihaiemil.docker;

import java.io.File;
import java.net.URI;

/**
* Local Docker API. Use this when you want to communicate with the local
Expand Down Expand Up @@ -57,7 +58,10 @@ public LocalDocker(final File unixSocket){
* @param version API version (e.g. v1.30).
*/
public LocalDocker(final File unixSocket, final String version){
super(new UnixHttpClient(unixSocket));
super(
new UnixHttpClient(unixSocket),
URI.create("unix://localhost:80/" + version)
);
}

}
22 changes: 16 additions & 6 deletions src/main/java/com/amihaiemil/docker/RtDocker.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@
*/
package com.amihaiemil.docker;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;

import org.apache.http.client.methods.HttpGet;
import java.io.IOException;
import java.net.URI;

/**
* Restful Docker.
Expand All @@ -36,9 +39,6 @@
* @since 0.0.1
* @todo #11:30min Implement RemoteDocker which will make the requests over
* a tcp socket and TLS if certificates are provided.
* @todo #32:30min Reimplement ping() with the new HttpClient architecture.
* It should create an HttpGet method and send it with the encapsulated
* client.
*/
abstract class RtDocker implements Docker {

Expand All @@ -47,17 +47,27 @@ abstract class RtDocker implements Docker {
*/
private final HttpClient client;

/**
* Base URI..
*/
private final URI baseUri;

/**
* Ctor.
* @param client Given HTTP Client.
* @param baseUri Base URI.
*/
RtDocker(final HttpClient client) {
RtDocker(final HttpClient client, final URI baseUri) {
this.client = client;
this.baseUri = baseUri;
}

@Override
public final boolean ping() throws IOException {
return true;
final HttpResponse response = this.client.execute(
new HttpGet(this.baseUri.toString() + "/_ping")
);
return response.getStatusLine().getStatusCode() == HttpStatus.SC_OK;
}

@Override
Expand Down
26 changes: 11 additions & 15 deletions src/test/java/com/amihaiemil/docker/LocalDockerTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,24 @@
* @author Mihai Andronache (amihaiemil@gmail.com)
* @version $Id$
* @since 0.0.1
* @todo #39:1h Implement a unix socket server so we can also unit
* test the calls made with UnixHttpClient. The user should be able
* to specify what response it expected with each request to a certain
* path.
*/
public final class LocalDockerTestCase {

/**
* LocalDocker can be instantiated with the unix:// scheme.
* LocalDocker can be instantiated.
*/
@Test
public void canInstantiateWithScheme() {
final Docker docker = new LocalDocker(
new File("/var/run/docker.sock")
public void canBeInstantiate() {
MatcherAssert.assertThat(
new LocalDocker(
new File("/var/run/docker.sock")
),
Matchers.notNullValue()
);
MatcherAssert.assertThat(docker, Matchers.notNullValue());
}

/**
* LocalDocker can be instantiated without the unix:// scheme.
*/
@Test
public void canInstantiateWithoutScheme() {
final Docker docker = new LocalDocker(
new File("/var/run/docker.sock")
);
MatcherAssert.assertThat(docker, Matchers.notNullValue());
}
}