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
5 changes: 3 additions & 2 deletions src/main/java/com/amihaiemil/docker/Network.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@
* @version $Id$
* @see <a href="https://docs.docker.com/engine/api/v1.35/#tag/Network">Docker API v1.35</a>
* @since 0.0.4
* @todo #210:30min Implement Network methods: inspect, remove, connect and
* @todo #225:30min Implement Network methods: inspect, remove, connect and
* disconnect like specified at:
* https://docs.docker.com/engine/api/v1.35/#tag/Network.
* https://docs.docker.com/engine/api/v1.35/#tag/Network. Then remove @Ignore
* annotaton from all network tests in RtNetworkTestCase.
*/
public interface Network extends JsonObject {

Expand Down
104 changes: 56 additions & 48 deletions src/test/java/com/amihaiemil/docker/RtNetworkTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@
import com.amihaiemil.docker.mock.AssertRequest;
import com.amihaiemil.docker.mock.Condition;
import com.amihaiemil.docker.mock.Response;

import java.io.IOException;
import java.net.URI;
import javax.json.Json;
import javax.json.JsonObject;
import org.apache.http.HttpStatus;
import org.hamcrest.MatcherAssert;
import org.hamcrest.collection.IsEmptyIterable;
import org.hamcrest.core.IsEqual;
import org.junit.Ignore;
import org.junit.Test;
Expand Down Expand Up @@ -137,66 +140,71 @@ public void removeSendsCorrectRequest() throws Exception {
}

/**
* RtNetwork throws UnsupportedOperationException for Inspect.
* @throws Exception If something else goes wrong.
*/
@Test(expected = UnsupportedOperationException.class)
public void unsupportedOperationInspect() throws Exception {
new RtNetwork(
Json.createObjectBuilder().build(),
new AssertRequest(
new Response(HttpStatus.SC_OK)
),
URI.create("http://localhost/networks/id1"),
DOCKER
).inspect();
}

/**
* RtNetwork throws UnsupportedOperationException for Remove.
* @throws Exception If something else goes wrong.
*/
@Test(expected = UnsupportedOperationException.class)
public void unsupportedOperationRemove() throws Exception {
new RtNetwork(
Json.createObjectBuilder().build(),
new AssertRequest(
new Response(HttpStatus.SC_OK)
),
URI.create("http://localhost/networks/id1"),
DOCKER
).remove();
}

/**
* RtNetwork throws UnsupportedOperationException for Connect.
* @throws Exception If something else goes wrong.
* RtNetwork.connect() must send a POST request to the correct url and
* connect the desired container to the network.
* @throws IOException If something goes wrong.
*/
@Test(expected = UnsupportedOperationException.class)
public void unsupportedOperationConnect() throws Exception {
new RtNetwork(
@Test
@Ignore
public void connectContainer() throws IOException {
final Network network = new RtNetwork(
Json.createObjectBuilder().build(),
new AssertRequest(
new Response(HttpStatus.SC_OK)
new Response(HttpStatus.SC_OK),
new Condition(
"connect() must send a POST HTTP request",
req -> "POST".equals(req.getRequestLine().getMethod())
),
new Condition(
"connect() must send the request to the network url",
req -> "http://localhost/network/id1".equals(
req.getRequestLine().getUri()
)
)
),
URI.create("http://localhost/networks/id1"),
URI.create("http://localhost/network/id1"),
DOCKER
).connect("containerId");
);
network.connect("containerId");
MatcherAssert.assertThat(
"could not create container",
network.inspect().getJsonArray("Container"),
new IsEmptyIterable<>()
);
}

/**
* RtNetwork throws UnsupportedOperationException for Disconnect.
* @throws Exception If something else goes wrong.
* RtNetwork.disconnect() must send a POST request to the correct url and
* disconnect the desired container from the network.
* @throws IOException If something goes wrong.
*/
@Test(expected = UnsupportedOperationException.class)
public void unsupportedOperationDisconnect() throws Exception {
new RtNetwork(
@Test
@Ignore
public void disconnectContainer() throws IOException {
final Network network = new RtNetwork(
Json.createObjectBuilder().build(),
new AssertRequest(
new Response(HttpStatus.SC_OK)
new Response(HttpStatus.SC_OK),
new Condition(
"connect() must send a POST HTTP request",
req -> "POST".equals(req.getRequestLine().getMethod())
),
new Condition(
"connect() must send the request to the network url",
req -> "http://localhost/network/id1".equals(
req.getRequestLine().getUri()
)
)
),
URI.create("http://localhost/networks/id1"),
URI.create("http://localhost/network/id1"),
DOCKER
).disconnect("containerId");
);
network.connect("containerId");
network.disconnect("containerId");
MatcherAssert.assertThat(
"could not create container",
network.inspect().getJsonArray("Container").size(),
new IsEqual<>(0)
);
}
}