-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
345 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* Copyright (c) 2018, Mihai Emil Andronache | ||
* All rights reserved. | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* 1)Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* 2)Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* 3)Neither the name of docker-java-api nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package com.amihaiemil.docker; | ||
|
||
import java.net.URI; | ||
import org.apache.http.client.HttpClient; | ||
|
||
/** | ||
* Use this to communicate with a remote Docker API. | ||
* | ||
* @author George Aristy (george.aristy@gmail.com) | ||
* @version $Id$ | ||
* @since 0.0.1 | ||
*/ | ||
public final class RemoteDocker extends RtDocker { | ||
/** | ||
* Remote Docker engine. | ||
* @param uri Remote Docker URI. | ||
*/ | ||
public RemoteDocker(final URI uri) { | ||
this(new SslHttpClient(), uri); | ||
} | ||
|
||
/** | ||
* Remote Docker engine. | ||
* @param client The http client to use. | ||
* @param uri Remote Docker URI. | ||
*/ | ||
public RemoteDocker(final HttpClient client, final URI uri) { | ||
this(client, uri, "v1.35"); | ||
} | ||
|
||
/** | ||
* Remote Docker engine. | ||
* @param client The http client to use. | ||
* @param uri Remote Docker URI. | ||
* @param version API version (eg. v1.35). | ||
*/ | ||
public RemoteDocker(final HttpClient client, final URI uri, | ||
final String version) { | ||
super(client, uri); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/** | ||
* Copyright (c) 2018, Mihai Emil Andronache | ||
* All rights reserved. | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* 1)Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* 2)Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* 3)Neither the name of docker-java-api nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package com.amihaiemil.docker; | ||
|
||
import java.io.IOException; | ||
import org.apache.http.HttpHost; | ||
import org.apache.http.HttpRequest; | ||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.ClientProtocolException; | ||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.client.ResponseHandler; | ||
import org.apache.http.client.methods.HttpUriRequest; | ||
import org.apache.http.conn.ClientConnectionManager; | ||
import org.apache.http.impl.client.HttpClients; | ||
import org.apache.http.params.HttpParams; | ||
import org.apache.http.protocol.HttpContext; | ||
|
||
/** | ||
* An HttpClient that works over a normal network socket. | ||
* | ||
* @author George Aristy (george.aristy@gmail.com) | ||
* @version $Id$ | ||
* @since 0.0.1 | ||
* @checkstyle ParameterNumber (150 lines) | ||
* @todo #23:30min Add path for certificates as a parameter and, with those | ||
* certificates, register the http/https protocols, similar to how "unix" is | ||
* registered in UnixHttpClient. | ||
*/ | ||
final class SslHttpClient implements HttpClient { | ||
/** | ||
* Decorated HttpClient. | ||
*/ | ||
private final HttpClient origin; | ||
|
||
/** | ||
* Ctor. | ||
*/ | ||
SslHttpClient() { | ||
this( | ||
HttpClients.custom() | ||
.setMaxConnPerRoute(10) | ||
.setMaxConnTotal(10) | ||
.build() | ||
); | ||
} | ||
|
||
/** | ||
* Ctor. | ||
* @param client Decorated HttpClient. | ||
*/ | ||
SslHttpClient(final HttpClient client) { | ||
this.origin = client; | ||
} | ||
|
||
@Override | ||
public HttpParams getParams() { | ||
throw new UnsupportedOperationException("Not supported yet."); | ||
} | ||
|
||
@Override | ||
public ClientConnectionManager getConnectionManager() { | ||
throw new UnsupportedOperationException("Not supported yet."); | ||
} | ||
|
||
@Override | ||
public HttpResponse execute(final HttpUriRequest request) | ||
throws IOException, ClientProtocolException { | ||
return this.origin.execute(request); | ||
} | ||
|
||
@Override | ||
public HttpResponse execute(final HttpUriRequest request, | ||
final HttpContext context) | ||
throws IOException, ClientProtocolException { | ||
throw new UnsupportedOperationException("Not supported yet."); | ||
} | ||
|
||
@Override | ||
public HttpResponse execute(final HttpHost target, | ||
final HttpRequest request) | ||
throws IOException, ClientProtocolException { | ||
throw new UnsupportedOperationException("Not supported yet."); | ||
} | ||
|
||
@Override | ||
public HttpResponse execute(final HttpHost target, | ||
final HttpRequest request, final HttpContext context) | ||
throws IOException, ClientProtocolException { | ||
throw new UnsupportedOperationException("Not supported yet."); | ||
} | ||
|
||
@Override | ||
public <T> T execute(final HttpUriRequest request, | ||
final ResponseHandler<? extends T> responseHandler) | ||
throws IOException, ClientProtocolException { | ||
throw new UnsupportedOperationException("Not supported yet."); | ||
} | ||
|
||
@Override | ||
public <T> T execute(final HttpUriRequest request, | ||
final ResponseHandler<? extends T> responseHandler, | ||
final HttpContext context) throws IOException, ClientProtocolException { | ||
throw new UnsupportedOperationException("Not supported yet."); | ||
} | ||
|
||
@Override | ||
public <T> T execute(final HttpHost target, final HttpRequest request, | ||
final ResponseHandler<? extends T> responseHandler) | ||
throws IOException, ClientProtocolException { | ||
throw new UnsupportedOperationException("Not supported yet."); | ||
} | ||
|
||
@Override | ||
public <T> T execute(final HttpHost target, final HttpRequest request, | ||
final ResponseHandler<? extends T> responseHandler, | ||
final HttpContext context) throws IOException, ClientProtocolException { | ||
throw new UnsupportedOperationException("Not supported yet."); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
src/test/java/com/amihaiemil/docker/RemoteDockerTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* Copyright (c) 2018, Mihai Emil Andronache | ||
* All rights reserved. | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* 1)Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* 2)Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* 3)Neither the name of docker-java-api nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package com.amihaiemil.docker; | ||
|
||
import com.amihaiemil.docker.mock.AssertRequest; | ||
import com.amihaiemil.docker.mock.Response; | ||
import java.net.URI; | ||
import org.apache.http.HttpStatus; | ||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Unit tests for {@link RemoteDocker}. | ||
* @author George Aristy (george.aristy@gmail.com) | ||
* @version $Id$ | ||
* @since 0.0.1 | ||
* @checkstyle MethodName (500 lines) | ||
* @todo #23:30min RemoteDocker: implement the rest of the test cases | ||
* (including integration tests) for RemoteDocker. | ||
*/ | ||
public final class RemoteDockerTestCase { | ||
/** | ||
* Ping must be TRUE if response is OK. | ||
* @throws Exception If an error occurs. | ||
*/ | ||
@Test | ||
public void pingTrueIfResponseIsOk() throws Exception { | ||
MatcherAssert.assertThat( | ||
new RemoteDocker( | ||
new AssertRequest( | ||
new Response(HttpStatus.SC_OK, "") | ||
), | ||
URI.create("http://remotedocker") | ||
).ping(), | ||
Matchers.is(true) | ||
); | ||
} | ||
|
||
/** | ||
* Ping must be False if response is not OK. | ||
* @throws Exception If an error occurs. | ||
*/ | ||
@Test | ||
public void pingFalseIfResponseIsNotOk() throws Exception { | ||
MatcherAssert.assertThat( | ||
new RemoteDocker( | ||
new AssertRequest( | ||
new Response(HttpStatus.SC_NOT_FOUND, "") | ||
), | ||
URI.create("http://remotedocker") | ||
).ping(), | ||
Matchers.is(false) | ||
); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/test/java/com/amihaiemil/docker/SslHttpClientTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Copyright (c) 2018, Mihai Emil Andronache | ||
* All rights reserved. | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* 1)Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* 2)Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* 3)Neither the name of docker-java-api nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package com.amihaiemil.docker; | ||
|
||
import com.amihaiemil.docker.mock.AssertRequest; | ||
import com.amihaiemil.docker.mock.Response; | ||
import org.apache.http.HttpStatus; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Unit tests for {@link SslHttpClient}. | ||
* @author George Aristy (george.aristy@gmail.com) | ||
* @version $Id$ | ||
* @since 0.0.1 | ||
* @checkstyle MethodName (500 lines) | ||
*/ | ||
public final class SslHttpClientTestCase { | ||
/** | ||
* DefaultHttpClient can execute the request and return the response. | ||
* @throws Exception If an error occurs. | ||
*/ | ||
@Test | ||
public void executesRequestAndReturnsResponse() throws Exception { | ||
final Response response = new Response(HttpStatus.SC_OK, ""); | ||
MatcherAssert.assertThat( | ||
new SslHttpClient( | ||
new AssertRequest(response) | ||
).execute(new HttpGet()), | ||
Matchers.is(response) | ||
); | ||
} | ||
} |
7995bd6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
11-6dd03fe4
disappeared fromsrc/main/java/com/amihaiemil/docker/RtDocker.java
, that's why I closed #23. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.7995bd6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
23-d9c71050
discovered insrc/main/java/com/amihaiemil/docker/SslHttpClient.java
and submitted as #67. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.7995bd6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
23-6815c522
discovered insrc/test/java/com/amihaiemil/docker/RemoteDockerTestCase.java
and submitted as #68. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.