|
| 1 | +package com.github.dockerjava.core.command; |
| 2 | + |
| 3 | +import com.github.dockerjava.api.command.CreateContainerResponse; |
| 4 | +import com.github.dockerjava.api.exception.InternalServerErrorException; |
| 5 | +import com.github.dockerjava.api.exception.NotFoundException; |
| 6 | +import com.github.dockerjava.client.AbstractDockerClientTest; |
| 7 | +import com.github.dockerjava.utils.ContainerUtils; |
| 8 | +import org.slf4j.Logger; |
| 9 | +import org.slf4j.LoggerFactory; |
| 10 | +import org.testng.ITestResult; |
| 11 | +import org.testng.annotations.AfterMethod; |
| 12 | +import org.testng.annotations.AfterTest; |
| 13 | +import org.testng.annotations.BeforeMethod; |
| 14 | +import org.testng.annotations.BeforeTest; |
| 15 | +import org.testng.annotations.Test; |
| 16 | + |
| 17 | +import java.lang.reflect.Method; |
| 18 | + |
| 19 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 20 | +import static org.hamcrest.Matchers.isEmptyString; |
| 21 | +import static org.hamcrest.Matchers.not; |
| 22 | + |
| 23 | +@Test(groups = {"integration", "ignoreInCircleCi"}) |
| 24 | +public class UnpauseCmdImplTest extends AbstractDockerClientTest { |
| 25 | + |
| 26 | + public static final Logger LOG = LoggerFactory.getLogger(UnpauseCmdImplTest.class); |
| 27 | + |
| 28 | + @BeforeTest |
| 29 | + public void beforeTest() throws Exception { |
| 30 | + super.beforeTest(); |
| 31 | + } |
| 32 | + |
| 33 | + @AfterTest |
| 34 | + public void afterTest() { |
| 35 | + super.afterTest(); |
| 36 | + } |
| 37 | + |
| 38 | + @BeforeMethod |
| 39 | + public void beforeMethod(Method method) { |
| 40 | + super.beforeMethod(method); |
| 41 | + } |
| 42 | + |
| 43 | + @AfterMethod |
| 44 | + public void afterMethod(ITestResult result) { |
| 45 | + super.afterMethod(result); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + public void unpausePausedContainer() { |
| 50 | + |
| 51 | + CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999").exec(); |
| 52 | + LOG.info("Created container: {}", container.toString()); |
| 53 | + assertThat(container.getId(), not(isEmptyString())); |
| 54 | + |
| 55 | + ContainerUtils.startContainer(dockerClient, container); |
| 56 | + |
| 57 | + ContainerUtils.pauseContainer(dockerClient, container); |
| 58 | + |
| 59 | + ContainerUtils.unpaseContainer(dockerClient, container); |
| 60 | + } |
| 61 | + |
| 62 | + @Test(expectedExceptions = InternalServerErrorException.class) |
| 63 | + public void unpauseRunningContainer() { |
| 64 | + |
| 65 | + CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999").exec(); |
| 66 | + LOG.info("Created container: {}", container.toString()); |
| 67 | + assertThat(container.getId(), not(isEmptyString())); |
| 68 | + |
| 69 | + ContainerUtils.startContainer(dockerClient, container); |
| 70 | + |
| 71 | + dockerClient.unpauseContainerCmd(container.getId()).exec(); |
| 72 | + } |
| 73 | + |
| 74 | + @Test(expectedExceptions = InternalServerErrorException.class) |
| 75 | + public void unpauseStoppedContainer() { |
| 76 | + |
| 77 | + CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999").exec(); |
| 78 | + LOG.info("Created container: {}", container.toString()); |
| 79 | + assertThat(container.getId(), not(isEmptyString())); |
| 80 | + |
| 81 | + ContainerUtils.startContainer(dockerClient, container); |
| 82 | + |
| 83 | + ContainerUtils.stopContainer(dockerClient, container); |
| 84 | + |
| 85 | + dockerClient.unpauseContainerCmd(container.getId()).exec(); |
| 86 | + } |
| 87 | + |
| 88 | + @Test(expectedExceptions = NotFoundException.class) |
| 89 | + public void unpauseNonExistingContainer() { |
| 90 | + |
| 91 | + dockerClient.unpauseContainerCmd("non-existing").exec(); |
| 92 | + } |
| 93 | + |
| 94 | + @Test(expectedExceptions = InternalServerErrorException.class) |
| 95 | + public void unpauseCreatedContainer() { |
| 96 | + |
| 97 | + CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999").exec(); |
| 98 | + LOG.info("Created container: {}", container.toString()); |
| 99 | + assertThat(container.getId(), not(isEmptyString())); |
| 100 | + |
| 101 | + dockerClient.unpauseContainerCmd(container.getId()).exec(); |
| 102 | + } |
| 103 | + |
| 104 | + @Test(expectedExceptions = InternalServerErrorException.class) |
| 105 | + public void unpauseUnpausedContainer() { |
| 106 | + |
| 107 | + CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999").exec(); |
| 108 | + LOG.info("Created container: {}", container.toString()); |
| 109 | + assertThat(container.getId(), not(isEmptyString())); |
| 110 | + |
| 111 | + ContainerUtils.startContainer(dockerClient, container); |
| 112 | + |
| 113 | + ContainerUtils.pauseContainer(dockerClient, container); |
| 114 | + |
| 115 | + dockerClient.unpauseContainerCmd(container.getId()).exec(); |
| 116 | + dockerClient.unpauseContainerCmd(container.getId()).exec(); |
| 117 | + } |
| 118 | +} |
0 commit comments