diff --git a/pom.xml b/pom.xml
index c4a83f562..975a088ec 100644
--- a/pom.xml
+++ b/pom.xml
@@ -241,6 +241,13 @@
com.spotify
hamcrest-jackson
1.1.3
+ test
+
+
+ com.spotify
+ hamcrest-pojo
+ 1.1.3
+ test
diff --git a/src/test/java/com/spotify/docker/client/DefaultDockerClientTest.java b/src/test/java/com/spotify/docker/client/DefaultDockerClientTest.java
index 078b60772..9fa4ff405 100644
--- a/src/test/java/com/spotify/docker/client/DefaultDockerClientTest.java
+++ b/src/test/java/com/spotify/docker/client/DefaultDockerClientTest.java
@@ -5429,69 +5429,6 @@ public void testRemoveService() throws Exception {
assertThat(sut.listServices(), is(empty()));
}
- @Test
- public void testInspectTask() throws Exception {
- requireDockerApiVersionAtLeast("1.24", "swarm support");
- final Set priorTasks = new HashSet<>(sut.listTasks());
-
- final Date start = new Date();
-
- final ServiceSpec serviceSpec = createServiceSpec(randomName());
- final int initialNumTasks = sut.listTasks().size();
- final ServiceCreateResponse serviceCreateResponse = sut.createService(serviceSpec);
- await().until(numberOfTasks(sut), is(greaterThan(initialNumTasks)));
-
- final Set tasks = new HashSet<>(sut.listTasks());
-
- final Set newTasks = Sets.difference(tasks, priorTasks);
- final Task someTask = newTasks.iterator().next();
-
- final Task inspectedTask = sut.inspectTask(someTask.id());
- final Date now = new Date();
- assertThat(inspectedTask.id(), notNullValue());
- assertThat(inspectedTask.version().index(), allOf(notNullValue(), greaterThan(0L)));
- assertThat(inspectedTask.createdAt(),
- allOf(notNullValue(), greaterThanOrEqualTo(start), lessThanOrEqualTo(now)));
- assertThat(inspectedTask.updatedAt(),
- allOf(notNullValue(), greaterThanOrEqualTo(start), lessThanOrEqualTo(now)));
- assertThat(inspectedTask.slot(), allOf(notNullValue(), greaterThan(0)));
- assertThat(inspectedTask.status(), notNullValue());
- assertThat(inspectedTask.name(), nullValue());
- assertEquals(serviceCreateResponse.id(), inspectedTask.serviceId());
- if (serviceSpec.labels() == null || serviceSpec.labels().isEmpty()) {
- // Hamcrest has generally bad support for "is null or empty",
- // and no support at all for empty maps
- assertTrue(inspectedTask.labels() == null || inspectedTask.labels().isEmpty());
- } else {
- assertEquals(serviceSpec.labels(), inspectedTask.labels());
- }
- assertThat(inspectedTask.desiredState(), is(anything()));
- assertThat(inspectedTask.networkAttachments(), is(anything()));
-
- final TaskSpec taskSpecTemplate = serviceSpec.taskTemplate();
- final TaskSpec taskSpecActual = inspectedTask.spec();
- assertEquals(taskSpecTemplate.resources(), taskSpecActual.resources());
- assertEquals(taskSpecTemplate.restartPolicy(), taskSpecActual.restartPolicy());
- assertEquals(taskSpecTemplate.placement(), taskSpecActual.placement());
- assertEquals(taskSpecTemplate.networks(), taskSpecActual.networks());
- assertEquals(taskSpecTemplate.logDriver(), taskSpecActual.logDriver());
-
- final ContainerSpec containerSpecTemplate = taskSpecTemplate.containerSpec();
- final ContainerSpec containerSpecActual = taskSpecActual.containerSpec();
- assertThat(containerSpecActual.image(),
- latestImageNameMatcher(containerSpecTemplate.image()));
- assertEquals(containerSpecTemplate.labels(), containerSpecActual.labels());
- assertEquals(containerSpecTemplate.command(), containerSpecActual.command());
- assertEquals(containerSpecTemplate.args(), containerSpecActual.args());
- assertEquals(containerSpecTemplate.env(), containerSpecActual.env());
- assertEquals(containerSpecTemplate.dir(), containerSpecActual.dir());
- assertEquals(containerSpecTemplate.user(), containerSpecActual.user());
- assertEquals(containerSpecTemplate.groups(), containerSpecActual.groups());
- assertEquals(containerSpecTemplate.tty(), containerSpecActual.tty());
- assertEquals(containerSpecTemplate.mounts(), containerSpecActual.mounts());
- assertEquals(containerSpecTemplate.stopGracePeriod(), containerSpecActual.stopGracePeriod());
- }
-
@Test
public void testListTasks() throws Exception {
requireDockerApiVersionAtLeast("1.24", "swarm support");
diff --git a/src/test/java/com/spotify/docker/client/DefaultDockerClientUnitTest.java b/src/test/java/com/spotify/docker/client/DefaultDockerClientUnitTest.java
index 608b67175..dabec7c4a 100644
--- a/src/test/java/com/spotify/docker/client/DefaultDockerClientUnitTest.java
+++ b/src/test/java/com/spotify/docker/client/DefaultDockerClientUnitTest.java
@@ -24,6 +24,7 @@
import static com.spotify.hamcrest.jackson.JsonMatchers.jsonArray;
import static com.spotify.hamcrest.jackson.JsonMatchers.jsonObject;
import static com.spotify.hamcrest.jackson.JsonMatchers.jsonText;
+import static com.spotify.hamcrest.pojo.IsPojo.pojo;
import static java.util.Collections.singletonList;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.contains;
@@ -79,14 +80,19 @@
import com.spotify.docker.client.messages.swarm.NodeSpec;
import com.spotify.docker.client.messages.swarm.Placement;
import com.spotify.docker.client.messages.swarm.Preference;
+import com.spotify.docker.client.messages.swarm.ResourceRequirements;
import com.spotify.docker.client.messages.swarm.Service;
import com.spotify.docker.client.messages.swarm.ServiceSpec;
import com.spotify.docker.client.messages.swarm.Spread;
import com.spotify.docker.client.messages.swarm.SwarmJoin;
+import com.spotify.docker.client.messages.swarm.Task;
import com.spotify.docker.client.messages.swarm.TaskSpec;
+import com.spotify.docker.client.messages.swarm.Version;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.sql.Date;
+import java.time.Instant;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -1241,6 +1247,36 @@ public void testGetDistribution() throws Exception {
)));
}
+ @Test
+ public void testInspectTask() throws Exception {
+ final DefaultDockerClient dockerClient = new DefaultDockerClient(builder);
+
+ enqueueServerApiVersion("1.24");
+ enqueueServerApiResponse(200, "fixtures/1.24/task.json");
+
+ final Task task = dockerClient.inspectTask("0kzzo1i0y4jz6027t0k7aezc7");
+
+ assertThat(task, is(pojo(Task.class)
+ .where("id", is("0kzzo1i0y4jz6027t0k7aezc7"))
+ .where("version", is(pojo(Version.class)
+ .where("index", is(71L))
+ ))
+ .where("createdAt", is(Date.from(Instant.parse("2016-06-07T21:07:31.171892745Z"))))
+ .where("updatedAt", is(Date.from(Instant.parse("2016-06-07T21:07:31.376370513Z"))))
+ .where("spec", is(pojo(TaskSpec.class)
+ .where("containerSpec", is(pojo(ContainerSpec.class)
+ .where("image", is("redis"))
+ ))
+ .where("resources", is(pojo(ResourceRequirements.class)
+ .where("limits",
+ is(pojo(com.spotify.docker.client.messages.swarm.Resources.class)))
+ .where("reservations",
+ is(pojo(com.spotify.docker.client.messages.swarm.Resources.class)))
+ ))
+ ))
+ ));
+ }
+
private void enqueueServerApiResponse(final int statusCode, final String fileName)
throws IOException {
server.enqueue(new MockResponse()
diff --git a/src/test/resources/fixtures/1.24/task.json b/src/test/resources/fixtures/1.24/task.json
new file mode 100644
index 000000000..0b787bbc9
--- /dev/null
+++ b/src/test/resources/fixtures/1.24/task.json
@@ -0,0 +1,83 @@
+{
+ "ID": "0kzzo1i0y4jz6027t0k7aezc7",
+ "Version": {
+ "Index": 71
+ },
+ "CreatedAt": "2016-06-07T21:07:31.171892745Z",
+ "UpdatedAt": "2016-06-07T21:07:31.376370513Z",
+ "Spec": {
+ "ContainerSpec": {
+ "Image": "redis"
+ },
+ "Resources": {
+ "Limits": {},
+ "Reservations": {}
+ },
+ "RestartPolicy": {
+ "Condition": "any",
+ "MaxAttempts": 0
+ },
+ "Placement": {}
+ },
+ "ServiceID": "9mnpnzenvg8p8tdbtq4wvbkcz",
+ "Slot": 1,
+ "NodeID": "60gvrl6tm78dmak4yl7srz94v",
+ "Status": {
+ "Timestamp": "2016-06-07T21:07:31.290032978Z",
+ "State": "running",
+ "Message": "started",
+ "ContainerStatus": {
+ "ContainerID": "e5d62702a1b48d01c3e02ca1e0212a250801fa8d67caca0b6f35919ebc12f035",
+ "PID": 677
+ }
+ },
+ "DesiredState": "running",
+ "NetworksAttachments": [
+ {
+ "Network": {
+ "ID": "4qvuz4ko70xaltuqbt8956gd1",
+ "Version": {
+ "Index": 18
+ },
+ "CreatedAt": "2016-06-07T20:31:11.912919752Z",
+ "UpdatedAt": "2016-06-07T21:07:29.955277358Z",
+ "Spec": {
+ "Name": "ingress",
+ "Labels": {
+ "com.docker.swarm.internal": "true"
+ },
+ "DriverConfiguration": {},
+ "IPAMOptions": {
+ "Driver": {},
+ "Configs": [
+ {
+ "Subnet": "10.255.0.0/16",
+ "Gateway": "10.255.0.1"
+ }
+ ]
+ }
+ },
+ "DriverState": {
+ "Name": "overlay",
+ "Options": {
+ "com.docker.network.driver.overlay.vxlanid_list": "256"
+ }
+ },
+ "IPAMOptions": {
+ "Driver": {
+ "Name": "default"
+ },
+ "Configs": [
+ {
+ "Subnet": "10.255.0.0/16",
+ "Gateway": "10.255.0.1"
+ }
+ ]
+ }
+ },
+ "Addresses": [
+ "10.255.0.10/16"
+ ]
+ }
+ ]
+}