forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPorts_addBindingsTest.java
More file actions
62 lines (47 loc) · 2.08 KB
/
Copy pathPorts_addBindingsTest.java
File metadata and controls
62 lines (47 loc) · 2.08 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
60
61
62
package com.github.dockerjava.api.model;
import static org.testng.Assert.assertEquals;
import java.util.Map;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.github.dockerjava.api.model.Ports.Binding;
/**
* As there may be several {@link Binding}s per {@link ExposedPort}, it makes a difference if you add
* {@link PortBinding}s for the same or different {@link ExposedPort}s to {@link Ports}. This test verifies that the Map
* in {@link Ports} is populated correctly in both cases.
*/
public class Ports_addBindingsTest {
private static final ExposedPort TCP_80 = ExposedPort.tcp(80);
private static final ExposedPort TCP_90 = ExposedPort.tcp(90);
private static final Binding BINDING_8080 = Ports.Binding(8080);
private static final Binding BINDING_9090 = Ports.Binding(9090);
private Ports ports;
@BeforeMethod
public void setup() {
ports = new Ports();
}
@Test
public void addTwoBindingsForDifferentExposedPorts() {
ports.add(new PortBinding(BINDING_8080, TCP_80), new PortBinding(BINDING_9090, TCP_90));
Map<ExposedPort, Binding[]> bindings = ports.getBindings();
// two keys with one value each
assertEquals(bindings.size(), 2);
assertEquals(bindings.get(TCP_80), new Binding[] { BINDING_8080 });
assertEquals(bindings.get(TCP_90), new Binding[] { BINDING_9090 });
}
@Test
public void addTwoBindingsForSameExposedPort() {
ports.add(new PortBinding(BINDING_8080, TCP_80), new PortBinding(BINDING_9090, TCP_80));
Map<ExposedPort, Binding[]> bindings = ports.getBindings();
// one key with two values
assertEquals(bindings.size(), 1);
assertEquals(bindings.get(TCP_80), new Binding[] { BINDING_8080, BINDING_9090 });
}
@Test
public void addNullBindings() {
ports.add(new PortBinding(null, TCP_80));
Map<ExposedPort, Binding[]> bindings = ports.getBindings();
// one key with two values
assertEquals(bindings.size(), 1);
assertEquals(bindings.get(TCP_80), null);
}
}