forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPortsSerializingTest.java
More file actions
59 lines (46 loc) · 2.33 KB
/
Copy pathPortsSerializingTest.java
File metadata and controls
59 lines (46 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.github.dockerjava.api.model;
import com.github.dockerjava.api.model.Ports.Binding;
import com.github.dockerjava.test.serdes.JSONTestHelper;
import org.junit.Test;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
public class PortsSerializingTest {
private final String jsonWithDoubleBindingForOnePort = "{\"80/tcp\":[{\"HostIp\":\"10.0.0.1\",\"HostPort\":\"80\"},{\"HostIp\":\"10.0.0.2\",\"HostPort\":\"80\"}]}";
private final String jsonWithNullBindingForOnePort = "{\"80/tcp\":null}";
@Test
public void deserializingPortWithMultipleBindings() throws Exception {
Ports ports = JSONTestHelper.getMapper().readValue(jsonWithDoubleBindingForOnePort, Ports.class);
Map<ExposedPort, Binding[]> map = ports.getBindings();
assertEquals(map.size(), 1);
Binding[] bindings = map.get(ExposedPort.tcp(80));
assertEquals(bindings.length, 2);
assertEquals(bindings[0], new Binding("10.0.0.1", "80"));
assertEquals(bindings[1], new Binding("10.0.0.2", "80"));
}
@Test
public void serializingPortWithMultipleBindings() throws Exception {
Ports ports = new Ports();
ports.bind(ExposedPort.tcp(80), new Binding("10.0.0.1", "80"));
ports.bind(ExposedPort.tcp(80), new Binding("10.0.0.2", "80"));
assertEquals(JSONTestHelper.getMapper().writeValueAsString(ports), jsonWithDoubleBindingForOnePort);
}
@Test
public void serializingEmptyBinding() throws Exception {
Ports ports = new Ports(ExposedPort.tcp(80), new Binding(null, null));
assertEquals(JSONTestHelper.getMapper().writeValueAsString(ports), "{\"80/tcp\":[{\"HostIp\":\"\",\"HostPort\":\"\"}]}");
}
@Test
public void deserializingPortWithNullBindings() throws Exception {
Ports ports = JSONTestHelper.getMapper().readValue(jsonWithNullBindingForOnePort, Ports.class);
Map<ExposedPort, Binding[]> map = ports.getBindings();
assertEquals(map.size(), 1);
assertNull(map.get(ExposedPort.tcp(80)));
}
@Test
public void serializingWithNullBindings() throws Exception {
Ports ports = new Ports();
ports.bind(ExposedPort.tcp(80), null);
assertEquals(JSONTestHelper.getMapper().writeValueAsString(ports), jsonWithNullBindingForOnePort);
}
}