Skip to content

Commit 2f12588

Browse files
committed
Change serialization of RestartPolicy.noRestart()
The Docker CLI uses "" as the name for the --restart no policy.
1 parent 34bdbd9 commit 2f12588

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/main/java/com/github/dockerjava/api/model/RestartPolicy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class RestartPolicy {
2323
private int maximumRetryCount = 0;
2424

2525
@JsonProperty("Name")
26-
private String name = "no";
26+
private String name = "";
2727

2828
public RestartPolicy() {
2929
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.github.dockerjava.api.model;
2+
3+
import static org.testng.Assert.assertEquals;
4+
5+
import org.testng.annotations.Test;
6+
7+
import com.fasterxml.jackson.databind.ObjectMapper;
8+
9+
/**
10+
* Compares serialization results of various {@link RestartPolicy}s with
11+
* what Docker (as of 1.3.3) actually sends when executing
12+
* <code>docker run --restart xxx</code>.
13+
*/
14+
public class RestartPolicy_SerializingTest {
15+
private final ObjectMapper objectMapper = new ObjectMapper();
16+
17+
@Test // --restart no
18+
public void noRestart() throws Exception {
19+
String json = objectMapper.writeValueAsString(RestartPolicy.noRestart());
20+
assertEquals(json, "{\"MaximumRetryCount\":0,\"Name\":\"\"}");
21+
}
22+
23+
@Test // --restart always
24+
public void alwaysRestart() throws Exception {
25+
String json = objectMapper.writeValueAsString(RestartPolicy.alwaysRestart());
26+
assertEquals(json, "{\"MaximumRetryCount\":0,\"Name\":\"always\"}");
27+
}
28+
29+
@Test // --restart on-failure
30+
public void onFailureRestart() throws Exception {
31+
String json = objectMapper.writeValueAsString(RestartPolicy.onFailureRestart(0));
32+
assertEquals(json, "{\"MaximumRetryCount\":0,\"Name\":\"on-failure\"}");
33+
}
34+
35+
@Test // --restart on-failure:2
36+
public void onFailureRestartWithCount() throws Exception {
37+
String json = objectMapper.writeValueAsString(RestartPolicy.onFailureRestart(2));
38+
assertEquals(json, "{\"MaximumRetryCount\":2,\"Name\":\"on-failure\"}");
39+
}
40+
41+
}

0 commit comments

Comments
 (0)