Skip to content

Commit bbe940f

Browse files
committed
added test case for ContainerConfig.getExposedPorts
1 parent edfa297 commit bbe940f

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.github.dockerjava.api.model;
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import org.testng.annotations.Test;
5+
6+
import java.io.IOException;
7+
8+
import static junit.framework.Assert.assertEquals;
9+
10+
public class ContainerConfigTest {
11+
12+
@Test
13+
public void missingExposedPortsReturnEmptyArray() throws IOException {
14+
String s = "{}";
15+
ObjectMapper objectMapper = new ObjectMapper();
16+
ContainerConfig config = objectMapper.readValue(s, ContainerConfig.class);
17+
assertEquals(0, config.getExposedPorts().length);
18+
}
19+
20+
@Test
21+
public void nullExposedPortsReturnEmptyArray() throws IOException {
22+
String s = "{\"ExposedPorts\": null}";
23+
ObjectMapper objectMapper = new ObjectMapper();
24+
ContainerConfig config = objectMapper.readValue(s, ContainerConfig.class);
25+
assertEquals(0, config.getExposedPorts().length);
26+
}
27+
28+
@Test
29+
public void exposedPortsReturnArray() throws IOException {
30+
String s = "{\"ExposedPorts\": {\"22/tcp\": {}, \"80/tcp\": {}}}";
31+
ObjectMapper objectMapper = new ObjectMapper();
32+
ContainerConfig config = objectMapper.readValue(s, ContainerConfig.class);
33+
ExposedPort[] ports = config.getExposedPorts();
34+
assertEquals(2, ports.length);
35+
ExposedPort port22tcp = ports[0];
36+
assertEquals(22, port22tcp.getPort());
37+
assertEquals(InternetProtocol.TCP, port22tcp.getProtocol());
38+
ExposedPort port80tcp = ports[1];
39+
assertEquals(80, port80tcp.getPort());
40+
assertEquals(InternetProtocol.TCP, port80tcp.getProtocol());
41+
}
42+
43+
}

0 commit comments

Comments
 (0)