Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ public class ContainerConfig {

@JsonIgnore
public ExposedPort[] getExposedPorts() {
return exposedPorts.getExposedPorts();
if (exposedPorts == null) {
return new ExposedPort[0];
} else {
return exposedPorts.getExposedPorts();
}
}

public boolean isNetworkDisabled() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.github.dockerjava.api.model;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.testng.annotations.Test;

import java.io.IOException;

import static junit.framework.Assert.assertEquals;

public class ContainerConfigTest {

@Test
public void missingExposedPortsReturnEmptyArray() throws IOException {
String s = "{}";
ObjectMapper objectMapper = new ObjectMapper();
ContainerConfig config = objectMapper.readValue(s, ContainerConfig.class);
assertEquals(0, config.getExposedPorts().length);
}

@Test
public void nullExposedPortsReturnEmptyArray() throws IOException {
String s = "{\"ExposedPorts\": null}";
ObjectMapper objectMapper = new ObjectMapper();
ContainerConfig config = objectMapper.readValue(s, ContainerConfig.class);
assertEquals(0, config.getExposedPorts().length);
}

@Test
public void exposedPortsReturnArray() throws IOException {
String s = "{\"ExposedPorts\": {\"22/tcp\": {}, \"80/tcp\": {}}}";
ObjectMapper objectMapper = new ObjectMapper();
ContainerConfig config = objectMapper.readValue(s, ContainerConfig.class);
ExposedPort[] ports = config.getExposedPorts();
assertEquals(2, ports.length);
ExposedPort port22tcp = ports[0];
assertEquals(22, port22tcp.getPort());
assertEquals(InternetProtocol.TCP, port22tcp.getProtocol());
ExposedPort port80tcp = ports[1];
assertEquals(80, port80tcp.getPort());
assertEquals(InternetProtocol.TCP, port80tcp.getProtocol());
}

}