Skip to content

Commit 564cd5f

Browse files
committed
#168 implemented Docker.execs()
1 parent d97e08a commit 564cd5f

File tree

5 files changed

+104
-17
lines changed

5 files changed

+104
-17
lines changed

src/main/java/com/amihaiemil/docker/Execs.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,19 @@
3232
* @version $Id$
3333
* @since 0.0.12
3434
*/
35-
public interface Execs extends Iterable<Exec> {
35+
public interface Execs {
36+
37+
/**
38+
* Get the Exec with the specified ID.
39+
* @param execId The ID of the searched Exec.
40+
* @return Exec.
41+
*/
42+
Exec get(final String execId);
43+
44+
/**
45+
* Return the Docker engine where these Execs came from.
46+
* @return Docker.
47+
*/
48+
Docker docker();
49+
3650
}

src/main/java/com/amihaiemil/docker/RtDocker.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ public final Volumes volumes() {
123123

124124
@Override
125125
public final Execs execs() {
126-
throw new UnsupportedOperationException(
127-
"Exec API is not yet implemented. If you can contribute please,"
128-
+ " do it here: https://www.github.com/amihaiemil/docker-java-api"
126+
return new RtExecs(
127+
URI.create(this.baseUri.toString() + "/exec"),
128+
this
129129
);
130130
}
131131

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* Copyright (c) 2018-2020, Mihai Emil Andronache
3+
* All rights reserved.
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions are met:
6+
* 1)Redistributions of source code must retain the above copyright notice,
7+
* this list of conditions and the following disclaimer.
8+
* 2)Redistributions in binary form must reproduce the above copyright notice,
9+
* this list of conditions and the following disclaimer in the documentation
10+
* and/or other materials provided with the distribution.
11+
* 3)Neither the name of docker-java-api nor the names of its
12+
* contributors may be used to endorse or promote products derived from
13+
* this software without specific prior written permission.
14+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24+
* POSSIBILITY OF SUCH DAMAGE.
25+
*/
26+
package com.amihaiemil.docker;
27+
28+
import java.net.URI;
29+
30+
/**
31+
* RESTful Execs API.
32+
* @author Mihai Andronache (amihaiemil@gmail.com)
33+
* @version $Id$
34+
* @since 0.0.12
35+
*/
36+
final class RtExecs implements Execs {
37+
38+
/**
39+
* Base URI for Images API.
40+
*/
41+
private final URI baseUri;
42+
43+
/**
44+
* Docker API.
45+
*/
46+
private final Docker docker;
47+
48+
/**
49+
* Ctor.
50+
* @param uri The URI for this Images API.
51+
* @param dkr The docker entry point.
52+
* @checkstyle ParameterNumber (10 lines)
53+
*/
54+
RtExecs(final URI uri, final Docker dkr) {
55+
this.baseUri = uri;
56+
this.docker = dkr;
57+
}
58+
59+
@Override
60+
public Exec get(final String execId) {
61+
return null;
62+
}
63+
64+
@Override
65+
public Docker docker() {
66+
return this.docker;
67+
}
68+
}

src/test/java/com/amihaiemil/docker/LocalDockerTestCase.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,16 @@ public void returnsNetworks() {
170170
}
171171

172172
/**
173-
* LocalUnixDocker throws UnsupportedOperationException for Exec.
173+
* LocalUnixDocker can return Execs.
174174
*/
175-
@Test(expected = UnsupportedOperationException.class)
176-
public void unsupportedOperationExec() {
177-
new LocalDocker(
178-
new File("/var/run/docker.sock")
179-
).execs();
175+
@Test
176+
public void returnsExecs() {
177+
MatcherAssert.assertThat(
178+
new LocalDocker(
179+
new File("/var/run/docker.sock")
180+
).execs(),
181+
Matchers.notNullValue()
182+
);
180183
}
181184

182185
/**

src/test/java/com/amihaiemil/docker/UnixDockerTestCase.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,16 @@ public void returnsNetworks() {
170170
}
171171

172172
/**
173-
* UnixDocker throws UnsupportedOperationException for Exec.
173+
* UnixDocker can return Execs.
174174
*/
175-
@Test(expected = UnsupportedOperationException.class)
176-
public void unsupportedOperationExec() {
177-
new UnixDocker(
178-
new File(
179-
"/var/run/docker.sock")
180-
).execs();
175+
@Test
176+
public void returnsExecs() {
177+
MatcherAssert.assertThat(
178+
new UnixDocker(
179+
new File("/var/run/docker.sock")
180+
).execs(),
181+
Matchers.notNullValue()
182+
);
181183
}
182184

183185
/**

0 commit comments

Comments
 (0)