Skip to content

Commit a221a94

Browse files
committed
Direct unit tests for docker-java#211
1 parent bdbdd75 commit a221a94

File tree

4 files changed

+364
-0
lines changed

4 files changed

+364
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2015 CloudBees Inc., Oleg Nenashev.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.github.dockerjava.api.command;
17+
18+
import com.fasterxml.jackson.databind.ObjectMapper;
19+
import com.github.dockerjava.test.serdes.AbstractJSONResourceRef;
20+
import com.github.dockerjava.test.serdes.JSONResourceRef;
21+
import java.io.IOException;
22+
import java.io.InputStream;
23+
import org.apache.commons.io.IOUtils;
24+
import static org.testng.Assert.assertEquals;
25+
import static org.testng.Assert.assertNotNull;
26+
27+
/**
28+
* References test resources and provides basic tests functionality.
29+
* @author Oleg Nenashev
30+
*/
31+
public enum CommandJSONSamples implements JSONResourceRef {
32+
33+
inspectContainerResponse_full,
34+
inspectContainerResponse_empty;
35+
36+
@Override
37+
public String getFileName() {
38+
return this + ".json";
39+
}
40+
41+
@Override
42+
public Class<?> getResourceClass() {
43+
return CommandJSONSamples.class;
44+
}
45+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2015 CloudBees Inc., Oleg Nenashev.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.github.dockerjava.api.command;
17+
18+
import static com.github.dockerjava.test.serdes.JSONTestHelper.testRoundTrip;
19+
import java.io.IOException;
20+
import static org.testng.Assert.*;
21+
import org.testng.annotations.Test;
22+
23+
/**
24+
* Tests for {@link InspectContainerResponse}.
25+
* @author Oleg Nenashev
26+
*/
27+
public class InspectContainerResponseTest {
28+
29+
@Test
30+
public void roundTrip_full() throws IOException {
31+
InspectContainerResponse[] responses = testRoundTrip(
32+
CommandJSONSamples.inspectContainerResponse_full,
33+
InspectContainerResponse[].class);
34+
assertEquals(1, responses.length);
35+
final InspectContainerResponse response = responses[0];
36+
37+
// Check volumes: https://github.com/docker-java/docker-java/issues/211
38+
assertEquals(response.getVolumes().length, 2);
39+
assertEquals(response.getVolumesRW().length, 2);
40+
assertEquals(response.getVolumes()[1].getContainerPath(), "/bar/foo/myvol2");
41+
assertEquals(response.getVolumes()[1].getHostPath(), "/path2");
42+
assertEquals(response.getVolumesRW()[1].getVolume().getPath(), "/bar/foo/myvol2");
43+
assertFalse(response.getVolumesRW()[1].getAccessMode().toBoolean());
44+
assertTrue(response.getVolumesRW()[0].getAccessMode().toBoolean());
45+
}
46+
47+
@Test
48+
public void roundTrip_empty() throws IOException {
49+
testRoundTrip(CommandJSONSamples.inspectContainerResponse_empty, InspectContainerResponse[].class);
50+
}
51+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
[{
2+
"AppArmorProfile": "",
3+
"Args": [ ],
4+
"Config": {
5+
"AttachStderr": true,
6+
"AttachStdin": true,
7+
"AttachStdout": true,
8+
"Cmd": [ ],
9+
"CpuShares": 0,
10+
"Cpuset": "",
11+
"Domainname": "",
12+
"Entrypoint": null,
13+
"Env": [ ],
14+
"ExposedPorts": { },
15+
"Hostname": "469e5edd8d5b",
16+
"Image": "jenkinsci/workflow-demo",
17+
"Labels": {},
18+
"MacAddress": "",
19+
"Memory": 0,
20+
"MemorySwap": 0,
21+
"NetworkDisabled": false,
22+
"OnBuild": null,
23+
"OpenStdin": true,
24+
"PortSpecs": null,
25+
"StdinOnce": true,
26+
"Tty": true,
27+
"User": "",
28+
"Volumes": null,
29+
"WorkingDir": "/var/lib/jenkins/workflow-plugin-pipeline-demo"
30+
},
31+
"Created": "2015-04-29T11:55:42.968262967Z",
32+
"Driver": "aufs",
33+
"ExecDriver": "native-0.2",
34+
"ExecIDs": null,
35+
"HostConfig": {
36+
"Binds": null,
37+
"CapAdd": null,
38+
"CapDrop": null,
39+
"CgroupParent": "",
40+
"ContainerIDFile": "",
41+
"CpuShares": 0,
42+
"CpusetCpus": "",
43+
"Devices": [],
44+
"Dns": null,
45+
"DnsSearch": null,
46+
"ExtraHosts": null,
47+
"IpcMode": "",
48+
"Links": null,
49+
"LogConfig": {
50+
"Config": null,
51+
"Type": "json-file"
52+
},
53+
"LxcConf": [],
54+
"Memory": 0,
55+
"MemorySwap": 0,
56+
"NetworkMode": "bridge",
57+
"PidMode": "",
58+
"PortBindings": {
59+
"8080/tcp": [ ]
60+
},
61+
"Privileged": false,
62+
"PublishAllPorts": false,
63+
"ReadonlyRootfs": false,
64+
"RestartPolicy": {
65+
"MaximumRetryCount": 0,
66+
"Name": ""
67+
},
68+
"SecurityOpt": null,
69+
"Ulimits": null,
70+
"VolumesFrom": null
71+
},
72+
"HostnamePath": "/mnt/sda1/var/lib/docker/containers/469e5edd8d5b33e3c905a7ffc97360ec6ee211d6782815fbcd144568045819e1/hostname",
73+
"HostsPath": "/mnt/sda1/var/lib/docker/containers/469e5edd8d5b33e3c905a7ffc97360ec6ee211d6782815fbcd144568045819e1/hosts",
74+
"Id": "469e5edd8d5b33e3c905a7ffc97360ec6ee211d6782815fbcd144568045819e1",
75+
"Image": "4300417211ebb75b48b06ed5640d641778f312072d24b37978682345cbb362b1",
76+
"LogPath": "/mnt/sda1/var/lib/docker/containers/469e5edd8d5b33e3c905a7ffc97360ec6ee211d6782815fbcd144568045819e1/469e5edd8d5b33e3c905a7ffc97360ec6ee211d6782815fbcd144568045819e1-json.log",
77+
"MountLabel": "",
78+
"Name": "/desperate_babbage",
79+
"NetworkSettings": {
80+
"Bridge": "docker0",
81+
"Gateway": "172.17.42.1",
82+
"GlobalIPv6Address": "",
83+
"GlobalIPv6PrefixLen": 0,
84+
"IPAddress": "172.17.0.2",
85+
"IPPrefixLen": 16,
86+
"IPv6Gateway": "",
87+
"LinkLocalIPv6Address": "fe80::42:acff:fe11:2",
88+
"LinkLocalIPv6PrefixLen": 64,
89+
"MacAddress": "02:42:ac:11:00:02",
90+
"PortMapping": null,
91+
"Ports": {
92+
"22/tcp": null,
93+
"8080/tcp": [ ]
94+
}
95+
},
96+
"Path": "/bin/sh",
97+
"ProcessLabel": "",
98+
"ResolvConfPath": "/mnt/sda1/var/lib/docker/containers/469e5edd8d5b33e3c905a7ffc97360ec6ee211d6782815fbcd144568045819e1/resolv.conf",
99+
"RestartCount": 0,
100+
"State": {
101+
"Dead": false,
102+
"Error": "",
103+
"ExitCode": 0,
104+
"FinishedAt": "0001-01-01T00:00:00Z",
105+
"OOMKilled": false,
106+
"Paused": false,
107+
"Pid": 898,
108+
"Restarting": false,
109+
"Running": true,
110+
"StartedAt": "2015-04-29T11:55:43.464717907Z"
111+
},
112+
"Volumes": {},
113+
"VolumesRW": {}
114+
}
115+
]
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
[{
2+
"AppArmorProfile": "",
3+
"Args": [
4+
"-c",
5+
"/var/lib/jenkins/run.sh"
6+
],
7+
"Config": {
8+
"AttachStderr": true,
9+
"AttachStdin": true,
10+
"AttachStdout": true,
11+
"Cmd": [
12+
"/bin/sh",
13+
"-c",
14+
"/var/lib/jenkins/run.sh"
15+
],
16+
"CpuShares": 0,
17+
"Cpuset": "",
18+
"Domainname": "",
19+
"Entrypoint": null,
20+
"Env": [
21+
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
22+
"MAVEN_VERSION=3.3.1",
23+
"JETTY_VERSION=9.2.9.v20150224",
24+
"REV=107ea141f5c7581056c6eb53d2ccd222cdf0d58c"
25+
],
26+
"ExposedPorts": {
27+
"22/tcp": {},
28+
"8080/tcp": {},
29+
"8081/tcp": {}
30+
},
31+
"Hostname": "469e5edd8d5b",
32+
"Image": "jenkinsci/workflow-demo",
33+
"Labels": {},
34+
"MacAddress": "",
35+
"Memory": 0,
36+
"MemorySwap": 0,
37+
"NetworkDisabled": false,
38+
"OnBuild": null,
39+
"OpenStdin": true,
40+
"PortSpecs": null,
41+
"StdinOnce": true,
42+
"Tty": true,
43+
"User": "",
44+
"Volumes": null,
45+
"WorkingDir": "/var/lib/jenkins/workflow-plugin-pipeline-demo"
46+
},
47+
"Created": "2015-04-29T11:55:42.968262967Z",
48+
"Driver": "aufs",
49+
"ExecDriver": "native-0.2",
50+
"ExecIDs": null,
51+
"HostConfig": {
52+
"Binds": null,
53+
"CapAdd": null,
54+
"CapDrop": null,
55+
"CgroupParent": "",
56+
"ContainerIDFile": "",
57+
"CpuShares": 0,
58+
"CpusetCpus": "",
59+
"Devices": [],
60+
"Dns": null,
61+
"DnsSearch": null,
62+
"ExtraHosts": null,
63+
"IpcMode": "",
64+
"Links": null,
65+
"LogConfig": {
66+
"Config": null,
67+
"Type": "json-file"
68+
},
69+
"LxcConf": [],
70+
"Memory": 0,
71+
"MemorySwap": 0,
72+
"NetworkMode": "bridge",
73+
"PidMode": "",
74+
"PortBindings": {
75+
"8080/tcp": [
76+
{
77+
"HostIp": "",
78+
"HostPort": "8080"
79+
}
80+
],
81+
"8081/tcp": [
82+
{
83+
"HostIp": "",
84+
"HostPort": "8081"
85+
}
86+
]
87+
},
88+
"Privileged": false,
89+
"PublishAllPorts": false,
90+
"ReadonlyRootfs": false,
91+
"RestartPolicy": {
92+
"MaximumRetryCount": 0,
93+
"Name": ""
94+
},
95+
"SecurityOpt": null,
96+
"Ulimits": null,
97+
"VolumesFrom": null
98+
},
99+
"HostnamePath": "/mnt/sda1/var/lib/docker/containers/469e5edd8d5b33e3c905a7ffc97360ec6ee211d6782815fbcd144568045819e1/hostname",
100+
"HostsPath": "/mnt/sda1/var/lib/docker/containers/469e5edd8d5b33e3c905a7ffc97360ec6ee211d6782815fbcd144568045819e1/hosts",
101+
"Id": "469e5edd8d5b33e3c905a7ffc97360ec6ee211d6782815fbcd144568045819e1",
102+
"Image": "4300417211ebb75b48b06ed5640d641778f312072d24b37978682345cbb362b1",
103+
"LogPath": "/mnt/sda1/var/lib/docker/containers/469e5edd8d5b33e3c905a7ffc97360ec6ee211d6782815fbcd144568045819e1/469e5edd8d5b33e3c905a7ffc97360ec6ee211d6782815fbcd144568045819e1-json.log",
104+
"MountLabel": "",
105+
"Name": "/desperate_babbage",
106+
"NetworkSettings": {
107+
"Bridge": "docker0",
108+
"Gateway": "172.17.42.1",
109+
"GlobalIPv6Address": "",
110+
"GlobalIPv6PrefixLen": 0,
111+
"IPAddress": "172.17.0.2",
112+
"IPPrefixLen": 16,
113+
"IPv6Gateway": "",
114+
"LinkLocalIPv6Address": "fe80::42:acff:fe11:2",
115+
"LinkLocalIPv6PrefixLen": 64,
116+
"MacAddress": "02:42:ac:11:00:02",
117+
"PortMapping": null,
118+
"Ports": {
119+
"22/tcp": null,
120+
"8080/tcp": [
121+
{
122+
"HostIp": "0.0.0.0",
123+
"HostPort": "8080"
124+
}
125+
],
126+
"8081/tcp": [
127+
{
128+
"HostIp": "0.0.0.0",
129+
"HostPort": "8081"
130+
}
131+
]
132+
}
133+
},
134+
"Path": "/bin/sh",
135+
"ProcessLabel": "",
136+
"ResolvConfPath": "/mnt/sda1/var/lib/docker/containers/469e5edd8d5b33e3c905a7ffc97360ec6ee211d6782815fbcd144568045819e1/resolv.conf",
137+
"RestartCount": 0,
138+
"State": {
139+
"Dead": false,
140+
"Error": "",
141+
"ExitCode": 0,
142+
"FinishedAt": "0001-01-01T00:00:00Z",
143+
"OOMKilled": false,
144+
"Paused": false,
145+
"Pid": 898,
146+
"Restarting": false,
147+
"Running": true,
148+
"StartedAt": "2015-04-29T11:55:43.464717907Z"
149+
},
150+
"Volumes": { "/foo/bar/myvol":"/path1", "/bar/foo/myvol2":"/path2" },
151+
"VolumesRW": { "/foo/bar/myvol": true, "/bar/foo/myvol2": false }
152+
}
153+
]

0 commit comments

Comments
 (0)