|
| 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