http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/39cd6698/docker/src/test/java/org/jclouds/docker/config/DockerParserModuleTest.java ---------------------------------------------------------------------- diff --git a/docker/src/test/java/org/jclouds/docker/config/DockerParserModuleTest.java b/docker/src/test/java/org/jclouds/docker/config/DockerParserModuleTest.java deleted file mode 100644 index 33564ea..0000000 --- a/docker/src/test/java/org/jclouds/docker/config/DockerParserModuleTest.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.docker.config; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; - -import java.util.List; -import java.util.Map; - -import org.jclouds.docker.domain.Container; -import org.jclouds.docker.domain.NetworkSettings; -import org.jclouds.docker.domain.Port; -import org.jclouds.json.Json; -import org.jclouds.json.config.GsonModule; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; -import com.google.inject.Guice; - -/** - * Unit tests for the {@link org.jclouds.docker.config.DockerParserModule} class. - */ -@Test(groups = "unit", testName = "DockerParserModuleTest") -public class DockerParserModuleTest { - - private Json json = Guice.createInjector(new GsonModule(), new DockerParserModule()).getInstance(Json.class); - - public void testContainerWithVolumesNull() { - Container container = json.fromJson("{ \"Id\": \"foo\", \"Volumes\": null }", Container.class); - assertNotNull(container); - assertEquals(container.id(), "foo"); - assertEquals(container.volumes(), ImmutableMap.of()); - } - - public void port() { - // Note IP, not Ip - String text = "{\"IP\":\"0.0.0.0\",\"PrivatePort\":4567,\"PublicPort\":49155,\"Type\":\"tcp\"}"; - Port port = Port.create("0.0.0.0", 4567, 49155, "tcp"); - assertEquals(json.fromJson(text, Port.class), port); - assertEquals(json.toJson(port), text); - } - - public void networkSettings() { - String text = "{" + - "\"Bridge\":\"\"," + - "\"SandboxID\":\"3ef128b055eb9ef62a6a2c281d97a2dfde5f47947d490f1dd2a81612611d961f\"," + - "\"HairpinMode\":false," + - "\"LinkLocalIPv6Address\":\"\"," + - "\"LinkLocalIPv6PrefixLen\":0," + - "\"Ports\":{}," + - "\"SandboxKey\":\"/var/run/docker/netns/3ef128b055eb\"," + - "\"SecondaryIPAddresses\":[]," + - "\"SecondaryIPv6Addresses\":[]," + - "\"EndpointID\":\"9e8dcc0c8288938a923018fee0728cee8e6de7c01a5150738ee6e51c1caf8cf6\"," + - "\"Gateway\":\"172.17.0.1\"," + - "\"GlobalIPv6Address\":\"\"," + - "\"GlobalIPv6PrefixLen\":0," + - "\"IPAddress\":\"172.17.0.2\"," + - "\"IPPrefixLen\":16," + - "\"IPv6Gateway\":\"\"," + - "\"MacAddress\":\"02:42:ac:11:00:02\"," + - "\"Networks\":{" + - "\"bridge\":{" + - "\"EndpointID\":\"9e8dcc0c8288938a923018fee0728cee8e6de7c01a5150738ee6e51c1caf8cf6\"," + - "\"Gateway\":\"172.17.0.1\"," + - "\"IPAddress\":\"172.17.0.2\"," + - "\"IPPrefixLen\":16," + - "\"IPv6Gateway\":\"\"," + - "\"GlobalIPv6Address\":\"\"," + - "\"GlobalIPv6PrefixLen\":0," + - "\"MacAddress\":\"02:42:ac:11:00:02\"" + - "}" + - "}" + - "}"; - NetworkSettings settings = NetworkSettings.create( - "", // Bridge - "3ef128b055eb9ef62a6a2c281d97a2dfde5f47947d490f1dd2a81612611d961f", // SandboxID - false, // HairpinMode - "", // LinkLocalIPv6Address - 0, // LinkLocalIPv6PrefixLen - ImmutableMap.<String, List<Map<String, String>>> of(), // Ports - "/var/run/docker/netns/3ef128b055eb", // SandboxKey - null, // SecondaryIPAddresses - null, // SecondaryIPv6Addresses - "9e8dcc0c8288938a923018fee0728cee8e6de7c01a5150738ee6e51c1caf8cf6", // EndpointID - "172.17.0.1", // Gateway - "", // GlobalIPv6Address - 0, // GlobalIPv6PrefixLen - "172.17.0.2", // IPAddress - 16, // IPPrefixLen - "", // IPv6Gateway - "02:42:ac:11:00:02", // MacAddress - ImmutableMap.of( - "bridge", NetworkSettings.Details.create( - "9e8dcc0c8288938a923018fee0728cee8e6de7c01a5150738ee6e51c1caf8cf6", // EndpointID - "172.17.0.1", // Gateway - "172.17.0.2", // IPAddress - 16, // IPPrefixLen - "", // IPv6Gateway - "", // GlobalIPv6Address - 0, // GlobalIPv6PrefixLen - "02:42:ac:11:00:02" // MacAddress - ) - ), - null // PortMapping - ); - - assertEquals(json.fromJson(text, NetworkSettings.class), settings); - assertEquals(json.toJson(settings), text); - } -}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/39cd6698/docker/src/test/java/org/jclouds/docker/domain/ConfigTest.java ---------------------------------------------------------------------- diff --git a/docker/src/test/java/org/jclouds/docker/domain/ConfigTest.java b/docker/src/test/java/org/jclouds/docker/domain/ConfigTest.java deleted file mode 100644 index 6ba9ac5..0000000 --- a/docker/src/test/java/org/jclouds/docker/domain/ConfigTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.docker.domain; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - -@Test(groups = "unit", testName = "ConfigTest") -public class ConfigTest { - - @Test - public void testFromConfig() { - Config origConfig = Config.builder() - .hostname("6c9932f478bd") - .env(ImmutableList.of("PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin")) - .image("57e570db16baba1e8c0d6f3c15868ddb400f64ff76ec948e65c3ca3f15fb3587") - .domainname("") - .user("") - .cmd(ImmutableList.of("-name", "7a:63:a2:39:7b:0f")) - .entrypoint(ImmutableList.of("/home/weave/weaver", "-iface", "ethwe", "-wait", "5")) - .image("zettio/weave") - .workingDir("/home/weave") - .exposedPorts(ImmutableMap.of("6783/tcp", ImmutableMap.of(), "6783/udp", ImmutableMap.of())) - .build(); - Config newConfig = Config.builder().fromConfig(origConfig).build(); - assertThat(origConfig).isEqualTo(newConfig); - } - - - @Test - public void testNullValuesPropagation() { - Config config = Config.builder() - .image("zettio/weave") - .build(); - - assertThat(config.cmd()).isNull(); - assertThat(config.entrypoint()).isNull(); - assertThat(config.env()).isNull(); - assertThat(config.hostname()).isNull(); - assertThat(config.domainname()).isNull(); - assertThat(config.workingDir()).isNull(); - assertThat(config.hostConfig()).isNull(); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/39cd6698/docker/src/test/java/org/jclouds/docker/domain/ContainerTest.java ---------------------------------------------------------------------- diff --git a/docker/src/test/java/org/jclouds/docker/domain/ContainerTest.java b/docker/src/test/java/org/jclouds/docker/domain/ContainerTest.java deleted file mode 100644 index 7be6e3c..0000000 --- a/docker/src/test/java/org/jclouds/docker/domain/ContainerTest.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.docker.domain; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.testng.annotations.Test; - -@Test(groups = "unit", testName = "ContainerTest") -public class ContainerTest { - - @Test - public void testFromContainer() { - Container testContainer = Container.builder() - .id("testcontainer") - .build(); - - - Container newTestContainer = testContainer.toBuilder().build(); - assertThat(newTestContainer).isEqualTo(testContainer); - } -} - http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/39cd6698/docker/src/test/java/org/jclouds/docker/features/ContainerApiLiveTest.java ---------------------------------------------------------------------- diff --git a/docker/src/test/java/org/jclouds/docker/features/ContainerApiLiveTest.java b/docker/src/test/java/org/jclouds/docker/features/ContainerApiLiveTest.java deleted file mode 100644 index 6c024d6..0000000 --- a/docker/src/test/java/org/jclouds/docker/features/ContainerApiLiveTest.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.docker.features; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; - -import java.io.IOException; -import java.io.InputStream; -import java.util.List; - -import org.jclouds.docker.compute.BaseDockerApiLiveTest; -import org.jclouds.docker.domain.Config; -import org.jclouds.docker.domain.Container; -import org.jclouds.docker.domain.ContainerSummary; -import org.jclouds.docker.domain.Image; -import org.jclouds.docker.domain.Resource; -import org.jclouds.docker.options.AttachOptions; -import org.jclouds.docker.options.CreateImageOptions; -import org.jclouds.docker.options.ListContainerOptions; -import org.jclouds.docker.options.RemoveContainerOptions; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; - -@Test(groups = "live", testName = "RemoteApiLiveTest", singleThreaded = true) -public class ContainerApiLiveTest extends BaseDockerApiLiveTest { - - private Container container = null; - protected Image image = null; - - @BeforeClass - protected void init() { - if (api.getImageApi().inspectImage(ALPINE_IMAGE_TAG) == null) { - CreateImageOptions options = CreateImageOptions.Builder.fromImage(ALPINE_IMAGE_TAG); - InputStream createImageStream = api.getImageApi().createImage(options); - consumeStream(createImageStream); - } - image = api.getImageApi().inspectImage(ALPINE_IMAGE_TAG); - assertNotNull(image); - } - - @AfterClass - protected void tearDown() { - if (container != null) { - if (api.getContainerApi().inspectContainer(container.id()) != null) { - api.getContainerApi().removeContainer(container.id(), RemoveContainerOptions.Builder.force(true)); - } - } - } - - public void testCreateContainer() throws IOException, InterruptedException { - Config containerConfig = Config.builder().image(image.id()) - .cmd(ImmutableList.of("/bin/sh", "-c", "touch hello; while true; do echo hello world; sleep 1; done")) - .build(); - container = api().createContainer("testCreateContainer", containerConfig); - assertNotNull(container); - assertNotNull(container.id()); - } - - @Test(dependsOnMethods = "testCreateContainer") - public void testStartContainer() throws IOException, InterruptedException { - api().startContainer(container.id()); - assertTrue(api().inspectContainer(container.id()).state().running()); - } - - @Test(dependsOnMethods = "testStartContainer") - public void testAttachContainer() throws InterruptedException { - // wait 2 seconds - give a container chance to echo the string - Thread.sleep(2000L); - - InputStream attachStream = api().attach(container.id(), AttachOptions.Builder.logs(true).stream(false).stdout(true)); - String stream = consumeStream(attachStream); - assertThat(stream.trim()).contains("hello world"); - } - - @Test(dependsOnMethods = "testAttachContainer") - public void testCopyFileFromContainer() { - InputStream tarredStream = api().copy(container.id(), Resource.create("hello")); - assertNotNull(consumeStream(tarredStream)); - } - - @Test(dependsOnMethods = "testCopyFileFromContainer") - public void testPauseContainer() { - api().pause(container.id()); - assertTrue(api().inspectContainer(container.id()).state().paused()); - } - - @Test(dependsOnMethods = "testPauseContainer") - public void testUnpauseContainer() { - api().unpause(container.id()); - assertFalse(api().inspectContainer(container.id()).state().paused()); - } - - @Test(dependsOnMethods = "testUnpauseContainer") - public void testStopContainer() { - api().stopContainer(container.id()); - assertFalse(api().inspectContainer(container.id()).state().running()); - } - - @Test(dependsOnMethods = "testStopContainer") - public void testRestartContainer() { - api().restart(container.id()); - assertTrue(api().inspectContainer(container.id()).state().running()); - } - - @Test(dependsOnMethods = "testRestartContainer") - public void testWaitContainer() { - api().stopContainer(container.id(), 1); - assertEquals(api().wait(container.id()).statusCode(), 137); - } - - @Test(dependsOnMethods = "testWaitContainer") - public void testRemoveContainer() { - api().removeContainer(container.id()); - assertNull(api().inspectContainer(container.id())); - } - - @Test - public void testListContainers() { - List<ContainerSummary> containerSummaries = api().listContainers(ListContainerOptions.Builder.all(true)); - for (ContainerSummary containerSummary : containerSummaries) { - assertNotNull(containerSummary.id()); - assertNotNull(containerSummary.image()); - assertFalse(containerSummary.names().isEmpty()); - } - } - - private ContainerApi api() { - return api.getContainerApi(); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/39cd6698/docker/src/test/java/org/jclouds/docker/features/ContainerApiMockTest.java ---------------------------------------------------------------------- diff --git a/docker/src/test/java/org/jclouds/docker/features/ContainerApiMockTest.java b/docker/src/test/java/org/jclouds/docker/features/ContainerApiMockTest.java deleted file mode 100644 index a9d32b5..0000000 --- a/docker/src/test/java/org/jclouds/docker/features/ContainerApiMockTest.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.docker.features; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; - -import org.jclouds.docker.DockerApi; -import org.jclouds.docker.config.DockerParserModule; -import org.jclouds.docker.domain.Config; -import org.jclouds.docker.domain.Container; -import org.jclouds.docker.domain.Resource; -import org.jclouds.docker.internal.BaseDockerMockTest; -import org.jclouds.docker.options.ListContainerOptions; -import org.jclouds.docker.parse.ContainerParseTest; -import org.jclouds.docker.parse.ContainersParseTest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; - -/** - * Mock tests for the {@link org.jclouds.docker.features.ContainerApi} class. - */ -@Test(groups = "unit", testName = "ContainerApiMockTest") -public class ContainerApiMockTest extends BaseDockerMockTest { - - public void testListContainers() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/containers.json"))); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); - try { - assertEquals(api.listContainers(), new ContainersParseTest().expected()); - assertSent(server, "GET", "/containers/json"); - } finally { - server.shutdown(); - } - } - - public void testListNonexistentContainers() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setResponseCode(404)); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); - try { - assertEquals(api.listContainers(), ImmutableList.of()); - assertSent(server, "GET", "/containers/json"); - } finally { - server.shutdown(); - } - } - - @Test(timeOut = 10000l) - public void testListAllContainers() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/containers.json"))); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); - try { - assertEquals(api.listContainers(ListContainerOptions.Builder.all(true)), new ContainersParseTest().expected()); - assertSent(server, "GET", "/containers/json?all=true"); - } finally { - server.shutdown(); - } - } - - public void testGetContainer() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/container.json"))); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString(), new DockerParserModule()).getContainerApi(); - String containerId = "e475abdf3e139a5e1e158b38b6cb290a1bec856d39d5a951f015dfb8fcba7331"; - try { - assertEquals(api.inspectContainer(containerId), new ContainerParseTest().expected()); - assertSent(server, "GET", "/containers/" + containerId + "/json"); - } finally { - server.shutdown(); - } - } - - public void testCreateContainer() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/container-creation.json"))); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); - Config containerConfig = Config.builder() - .cmd(ImmutableList.of("date")) - .attachStdin(false) - .attachStderr(true) - .attachStdout(true) - .tty(false) - .image("base") - .build(); - try { - Container container = api.createContainer("test", containerConfig); - assertSent(server, "POST", "/containers/create?name=test"); - assertNotNull(container); - assertThat(container.id()).isEqualTo("c6c74153ae4b1d1633d68890a68d89c40aa5e284a1ea016cbc6ef0e634ee37b2"); - } finally { - server.shutdown(); - } - } - - public void testRemoveContainer() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setResponseCode(204)); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); - String containerId = "6d35806c1bd2b25cd92bba2d2c2c5169dc2156f53ab45c2b62d76e2d2fee14a9"; - - try { - api.removeContainer(containerId); - assertSent(server, "DELETE", "/containers/" + containerId); - - } finally { - server.shutdown(); - } - } - - public void testStartContainer() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setResponseCode(200)); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); - try { - api.startContainer("1"); - assertSent(server, "POST", "/containers/1/start"); - } finally { - server.shutdown(); - } - } - - public void testStopContainer() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setResponseCode(200)); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); - try { - api.stopContainer("1"); - assertSent(server, "POST", "/containers/1/stop"); - } finally { - server.shutdown(); - } - } - - - public void testCommitContainer() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setResponseCode(201)); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); - try { - api.commit(); - assertSent(server, "POST", "/commit"); - } finally { - server.shutdown(); - } - } - - public void testPauseContainer() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setResponseCode(204)); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); - try { - api.pause("1"); - assertSent(server, "POST", "/containers/1/pause"); - } finally { - server.shutdown(); - } - } - - public void testUnpauseContainer() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setResponseCode(204)); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); - try { - api.unpause("1"); - assertSent(server, "POST", "/containers/1/unpause"); - } finally { - server.shutdown(); - } - } - - public void testAttachContainer() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setResponseCode(200)); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); - try { - api.attach("1"); - assertSent(server, "POST", "/containers/1/attach"); - } finally { - server.shutdown(); - } - } - - public void testWaitContainer() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setResponseCode(200)); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); - try { - api.wait("1"); - assertSent(server, "POST", "/containers/1/wait"); - } finally { - server.shutdown(); - } - } - - public void testRestartContainer() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setResponseCode(204)); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); - try { - api.restart("1"); - assertSent(server, "POST", "/containers/1/restart"); - } finally { - server.shutdown(); - } - } - - public void testKillContainer() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setResponseCode(204)); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); - try { - api.kill("1"); - assertSent(server, "POST", "/containers/1/kill"); - } finally { - server.shutdown(); - } - } - - public void testCopyFileFromContainer() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setResponseCode(204)); - ContainerApi api = api(DockerApi.class, server.getUrl("/").toString()).getContainerApi(); - try { - api.copy("1", Resource.create("test")); - assertSent(server, "POST", "/containers/1/copy"); - } finally { - server.shutdown(); - } - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/39cd6698/docker/src/test/java/org/jclouds/docker/features/ImageApiLiveTest.java ---------------------------------------------------------------------- diff --git a/docker/src/test/java/org/jclouds/docker/features/ImageApiLiveTest.java b/docker/src/test/java/org/jclouds/docker/features/ImageApiLiveTest.java deleted file mode 100644 index 051ea01..0000000 --- a/docker/src/test/java/org/jclouds/docker/features/ImageApiLiveTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.docker.features; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; - -import java.io.InputStream; -import java.util.List; - -import org.jclouds.docker.compute.BaseDockerApiLiveTest; -import org.jclouds.docker.domain.Image; -import org.jclouds.docker.domain.ImageSummary; -import org.jclouds.docker.options.CreateImageOptions; -import org.testng.annotations.Test; - -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; - -@Test(groups = "live", testName = "ImageApiLiveTest", singleThreaded = true) -public class ImageApiLiveTest extends BaseDockerApiLiveTest { - - private Image image; - - @Test - public void testCreateImage() { - InputStream createImageStream = api().createImage(CreateImageOptions.Builder.fromImage(DEFAULT_IMAGE).tag(DEFAULT_TAG)); - consumeStream(createImageStream); - } - - @Test(dependsOnMethods = "testCreateImage") - public void testInspectImage() { - image = api.getImageApi().inspectImage(String.format("%s:%s", DEFAULT_IMAGE, DEFAULT_TAG)); - assertNotNull(image); - } - - @Test(dependsOnMethods = "testInspectImage") - public void testTagImage() { - api.getImageApi().tagImage(image.id(), "jclouds", "testTag", true); - Image taggedImage = api.getImageApi().inspectImage("jclouds:testTag"); - assertEquals(taggedImage.id(), image.id(), "Newly added image tag should point to the same image ID."); - } - - @Test(dependsOnMethods = "testTagImage") - public void testListImages() { - List<ImageSummary> listImages = api().listImages(); - assertNotNull(listImages); - - Iterables.find(listImages, new Predicate<ImageSummary>() { - @Override - public boolean apply(ImageSummary input) { - return input.repoTags().contains("jclouds:testTag"); - } - }); - } - - @Test(dependsOnMethods = "testListImages", alwaysRun = true) - public void testDeleteImage() { - consumeStream(api().deleteImage(String.format("%s:%s", DEFAULT_IMAGE, DEFAULT_TAG))); - assertNull(api().inspectImage(String.format("%s:%s", DEFAULT_IMAGE, DEFAULT_TAG))); - - assertNotNull(api().inspectImage(image.id()), "Image should should still exist after removing original tag. There is a newly added tag referencing it."); - consumeStream(api().deleteImage("jclouds:testTag")); - assertNull(api().inspectImage("jclouds:testTag")); - } - - private ImageApi api() { - return api.getImageApi(); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/39cd6698/docker/src/test/java/org/jclouds/docker/features/ImageApiMockTest.java ---------------------------------------------------------------------- diff --git a/docker/src/test/java/org/jclouds/docker/features/ImageApiMockTest.java b/docker/src/test/java/org/jclouds/docker/features/ImageApiMockTest.java deleted file mode 100644 index 77277ab..0000000 --- a/docker/src/test/java/org/jclouds/docker/features/ImageApiMockTest.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.docker.features; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; - -import java.util.List; - -import org.jclouds.docker.DockerApi; -import org.jclouds.docker.config.DockerParserModule; -import org.jclouds.docker.domain.ImageHistory; -import org.jclouds.docker.internal.BaseDockerMockTest; -import org.jclouds.docker.options.CreateImageOptions; -import org.jclouds.docker.parse.HistoryParseTest; -import org.jclouds.docker.parse.ImageParseTest; -import org.jclouds.docker.parse.ImagesParseTest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; - -/** - * Mock tests for the {@link org.jclouds.docker.features.ImageApi} class. - */ -@Test(groups = "unit", testName = "ImageApiMockTest") -public class ImageApiMockTest extends BaseDockerMockTest { - - public void testCreateImage() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setResponseCode(200)); - ImageApi api = api(DockerApi.class, server.getUrl("/").toString()).getImageApi(); - try { - api.createImage(CreateImageOptions.Builder.fromImage("base")); - assertSent(server, "POST", "/images/create?fromImage=base"); - } finally { - server.shutdown(); - } - } - - public void testGetImage() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/image.json"))); - ImageApi api = api(DockerApi.class, server.getUrl("/").toString(), new DockerParserModule()).getImageApi(); - try { - String imageId = "cbba6639a342646deed70d7ea6162fa2a0acea9300f911f4e014555fe37d3456"; - assertEquals(api.inspectImage(imageId), new ImageParseTest().expected()); - assertSent(server, "GET", "/images/" + imageId + "/json"); - } finally { - server.shutdown(); - } - } - - public void testListImages() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/images.json"))); - ImageApi api = api(DockerApi.class, server.getUrl("/").toString()).getImageApi(); - try { - assertEquals(api.listImages(), new ImagesParseTest().expected()); - assertSent(server, "GET", "/images/json"); - } finally { - server.shutdown(); - } - } - - public void testTagImage() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setResponseCode(201)); - ImageApi api = api(DockerApi.class, server.getUrl("/").toString()).getImageApi(); - try { - api.tagImage("633fcd11259e8d6bccfbb59a4086b95b0d0fb44edfc3912000ef1f70e8a7bfc6", "jclouds", "testTag", true); - assertSent(server, "POST", - "/images/633fcd11259e8d6bccfbb59a4086b95b0d0fb44edfc3912000ef1f70e8a7bfc6/tag?repo=jclouds&tag=testTag&force=true"); - } finally { - server.shutdown(); - } - } - - public void testDeleteImage() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setResponseCode(204)); - ImageApi api = api(DockerApi.class, server.getUrl("/").toString()).getImageApi(); - try { - api.deleteImage("1"); - assertSent(server, "DELETE", "/images/1"); - - } finally { - server.shutdown(); - } - } - - public void testGetHistory() throws Exception { - MockWebServer server = mockWebServer( - new MockResponse().setBody(payloadFromResource("/history.json")), - new MockResponse().setBody(payloadFromResource("/history-apiver22.json")), - new MockResponse().setResponseCode(404)); - ImageApi api = api(DockerApi.class, server.getUrl("/").toString()).getImageApi(); - try { - assertEquals(api.getHistory("ubuntu"), new HistoryParseTest().expected()); - assertSent(server, "GET", "/images/ubuntu/history"); - - // Docker Engine 1.10 (REST API ver 22) doesn't return parent layer IDs - assertEquals(api.getHistory("fcf9d588ee9ab46c5a888e67f892fac66e6396eb195a743e50c0c5f9a4710e66"), - ImmutableList.of( - ImageHistory.create("sha256:fcf9d588ee9ab46c5a888e67f892fac66e6396eb195a743e50c0c5f9a4710e66", - 1456304238, - "", - ImmutableList.of("registry.acme.com:8888/jboss-eap-test/eap-test:1.0-3"), - 188605160, - ""), - ImageHistory.create("<missing>", - 1455838658, - "", - null, - 195019519, - ""), - ImageHistory.create("<missing>", - 1455812978, - "", - null, - 203250948, - "Imported from -") - )); - assertSent(server, "GET", "/images/fcf9d588ee9ab46c5a888e67f892fac66e6396eb195a743e50c0c5f9a4710e66/history"); - - // check also if empty list is returned if the image is not found - List<ImageHistory> historyList = api.getHistory("missing-image"); - assertNotNull(historyList); - assertTrue(historyList.isEmpty()); - } finally { - server.shutdown(); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/39cd6698/docker/src/test/java/org/jclouds/docker/features/MiscApiLiveTest.java ---------------------------------------------------------------------- diff --git a/docker/src/test/java/org/jclouds/docker/features/MiscApiLiveTest.java b/docker/src/test/java/org/jclouds/docker/features/MiscApiLiveTest.java deleted file mode 100644 index c9c69dc..0000000 --- a/docker/src/test/java/org/jclouds/docker/features/MiscApiLiveTest.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.docker.features; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URISyntaxException; - -import org.assertj.core.api.Fail; -import org.jclouds.docker.compute.BaseDockerApiLiveTest; -import org.jclouds.docker.domain.Config; -import org.jclouds.docker.domain.Container; -import org.jclouds.docker.domain.Exec; -import org.jclouds.docker.domain.ExecCreateParams; -import org.jclouds.docker.domain.ExecInspect; -import org.jclouds.docker.domain.ExecStartParams; -import org.jclouds.docker.domain.Image; -import org.jclouds.docker.options.BuildOptions; -import org.jclouds.docker.options.CreateImageOptions; -import org.jclouds.docker.options.RemoveContainerOptions; -import org.jclouds.docker.util.DockerInputStream; -import org.jclouds.docker.util.StdStreamData; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; - -@Test(groups = "live", testName = "MiscApiLiveTest", singleThreaded = true) -public class MiscApiLiveTest extends BaseDockerApiLiveTest { - - private static final String IMAGE_TEST_TAG = "jclouds-test-test-build-image"; - - private static String imageId; - - private Container container = null; - private Image image = null; - private Exec exec = null; - - @BeforeClass - protected void init() { - if (api.getImageApi().inspectImage(ALPINE_IMAGE_TAG) == null) { - CreateImageOptions options = CreateImageOptions.Builder.fromImage(ALPINE_IMAGE_TAG); - InputStream createImageStream = api.getImageApi().createImage(options); - consumeStream(createImageStream); - } - image = api.getImageApi().inspectImage(ALPINE_IMAGE_TAG); - assertNotNull(image); - Config containerConfig = Config.builder().image(image.id()) - .cmd(ImmutableList.of("/bin/sh", "-c", "touch hello; while true; do echo hello world; sleep 1; done")) - .build(); - container = api.getContainerApi().createContainer("miscApiTest", containerConfig); - assertNotNull(container); - api.getContainerApi().startContainer(container.id()); - assertTrue(api.getContainerApi().inspectContainer(container.id()).state().running()); - } - - @AfterClass - protected void tearDown() { - if (container != null) { - if (api.getContainerApi().inspectContainer(container.id()) != null) { - api.getContainerApi().removeContainer(container.id(), RemoveContainerOptions.Builder.force(true)); - } - } - if (image != null) { - api.getImageApi().deleteImage(ALPINE_IMAGE_TAG); - } - } - - @Test - public void testVersion() { - assertNotNull(api().getVersion().apiVersion()); - assertNotNull(api().getVersion().version()); - assertNotNull(api().getVersion().gitCommit()); - assertNotNull(api().getVersion().goVersion()); - assertNotNull(api().getVersion().kernelVersion()); - assertNotNull(api().getVersion().arch()); - assertNotNull(api().getVersion().os()); - } - - @Test - public void testInfo() { - assertNotNull(api().getInfo()); - } - - @Test - public void testBuildImageFromDockerfile() throws IOException, InterruptedException, URISyntaxException { - removeImageIfExists(IMAGE_TEST_TAG); - BuildOptions options = BuildOptions.Builder.tag(IMAGE_TEST_TAG).verbose(false).nocache(true); - InputStream buildImageStream = api().build(tarredDockerfile(), options); - String buildStream = consumeStream(buildImageStream); - try { - Iterable<String> splitted = Splitter.on("\n").split(buildStream.replace("\r", "").trim()); - String lastStreamedLine = Iterables.getLast(splitted).trim(); - String rawImageId = Iterables.getLast(Splitter.on("Successfully built ").split(lastStreamedLine)); - imageId = rawImageId.substring(0, 11); - assertNotNull(imageId); - } finally { - removeImageIfExists(IMAGE_TEST_TAG); - } - } - - @Test - public void testExecCreate() { - exec = api().execCreate(container.id(), - ExecCreateParams.builder() - .cmd(ImmutableList.<String> of("/bin/sh", "-c", - "echo -n Standard >&1 && echo -n Error >&2 && exit 2")) - .attachStderr(true).attachStdout(true).build()); - assertNotNull(exec); - assertNotNull(exec.id()); - } - - @Test(dependsOnMethods = "testExecCreate") - public void testExecStart() throws IOException { - final ExecStartParams startParams = ExecStartParams.builder().detach(false).build(); - DockerInputStream inputStream = null; - try { - inputStream = new DockerInputStream(api().execStart(exec.id(), startParams)); - assertNotNull(inputStream); - ByteArrayOutputStream baosOut = new ByteArrayOutputStream(); - ByteArrayOutputStream baosErr = new ByteArrayOutputStream(); - StdStreamData data = null; - while (null != (data = inputStream.readStdStreamData())) { - assertFalse(data.isTruncated()); - switch (data.getType()) { - case OUT: - baosOut.write(data.getPayload()); - break; - case ERR: - baosErr.write(data.getPayload()); - break; - default: - Fail.fail("Unexpected Stream type"); - break; - } - } - assertEquals(baosOut.toString(), "Standard"); - assertEquals(baosErr.toString(), "Error"); - } finally { - if (inputStream != null) { - inputStream.close(); - } - } - } - - @Test(dependsOnMethods = "testExecStart") - public void testExecInspect() throws IOException { - ExecInspect execInspect = api().execInspect(exec.id()); - assertNotNull(execInspect); - assertEquals(execInspect.id(), exec.id()); - assertEquals(execInspect.running(), false); - assertEquals(execInspect.exitCode(), 2); - } - - private MiscApi api() { - return api.getMiscApi(); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/39cd6698/docker/src/test/java/org/jclouds/docker/features/MiscApiMockTest.java ---------------------------------------------------------------------- diff --git a/docker/src/test/java/org/jclouds/docker/features/MiscApiMockTest.java b/docker/src/test/java/org/jclouds/docker/features/MiscApiMockTest.java deleted file mode 100644 index dd5d965..0000000 --- a/docker/src/test/java/org/jclouds/docker/features/MiscApiMockTest.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.docker.features; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.jclouds.docker.compute.BaseDockerApiLiveTest.tarredDockerfile; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.nio.charset.StandardCharsets; - -import javax.ws.rs.core.HttpHeaders; - -import org.jclouds.docker.DockerApi; -import org.jclouds.docker.config.DockerParserModule; -import org.jclouds.docker.domain.Exec; -import org.jclouds.docker.domain.ExecCreateParams; -import org.jclouds.docker.domain.ExecInspect; -import org.jclouds.docker.domain.ExecStartParams; -import org.jclouds.docker.internal.BaseDockerMockTest; -import org.jclouds.docker.parse.InfoParseTest; -import org.jclouds.docker.parse.VersionParseTest; -import org.jclouds.docker.util.DockerInputStream; -import org.jclouds.docker.util.StdStreamData; -import org.jclouds.docker.util.StdStreamData.StdStreamType; -import org.jclouds.io.Payload; -import org.jclouds.io.Payloads; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; - -/** - * Mock tests for the {@link org.jclouds.docker.features.MiscApi} class. - */ -@Test(groups = "unit", testName = "MiscApiMockTest") -public class MiscApiMockTest extends BaseDockerMockTest { - - public void testGetVersion() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/version.json"))); - MiscApi api = api(DockerApi.class, server.getUrl("/").toString()).getMiscApi(); - try { - assertEquals(api.getVersion(), new VersionParseTest().expected()); - assertSent(server, "GET", "/version"); - } finally { - server.shutdown(); - } - } - - public void testGetInfo() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/info.json"))); - MiscApi api = api(DockerApi.class, server.getUrl("/").toString()).getMiscApi(); - try { - assertEquals(api.getInfo(), new InfoParseTest().expected()); - assertSent(server, "GET", "/info"); - } finally { - server.shutdown(); - } - } - - public void testBuildContainer() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setResponseCode(200)); - MiscApi api = api(DockerApi.class, server.getUrl("/").toString()).getMiscApi(); - try { - api.build(tarredDockerfile()); - RecordedRequest request = assertSent(server, "POST", "/build"); - assertDockerBuildHttpHeaders(request); - } finally { - server.shutdown(); - } - } - - public void testBuildContainerUsingPayload() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setResponseCode(200)); - MiscApi api = api(DockerApi.class, server.getUrl("/").toString()).getMiscApi(); - File file = File.createTempFile("docker", "tmp"); - FileInputStream data = new FileInputStream(file); - Payload payload = Payloads.newInputStreamPayload(data); - payload.getContentMetadata().setContentLength(file.length()); - try { - api.build(payload); - RecordedRequest request = assertSent(server, "POST", "/build"); - assertDockerBuildHttpHeaders(request); - } finally { - server.shutdown(); - } - } - - - public void testExecCreate() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/exec.json"))); - MiscApi api = api(DockerApi.class, server.getUrl("/").toString(), new DockerParserModule()).getMiscApi(); - try { - final String containerId = "a40d212a0a379de00426a1da2a8fd3fd20d5f74fd7c2dd42f6c93a6b1b0e6974"; - final ExecCreateParams execParams = ExecCreateParams.builder() - .cmd(ImmutableList.<String> of("/bin/sh", "-c", "echo -n Standard >&1 && echo -n Error >&2")) - .attachStderr(true).attachStdout(true).build(); - final Exec expectedExec = Exec.create("dbf45d296388032ebb9872edb75847f6655a72b4e9ab0d99ae1c75589c4ca957"); - assertEquals(api.execCreate(containerId, execParams), expectedExec); - assertSent(server, "POST", "/containers/" + containerId + "/exec"); - } finally { - server.shutdown(); - } - } - - public void testExecStart() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/exec.start"))); - MiscApi api = api(DockerApi.class, server.getUrl("/").toString(), new DockerParserModule()).getMiscApi(); - DockerInputStream dis = null; - try { - final String execId = "dbf45d296388032ebb9872edb75847f6655a72b4e9ab0d99ae1c75589c4ca957"; - final ExecStartParams startParams = ExecStartParams.builder().detach(false).build(); - dis = new DockerInputStream(api.execStart(execId, startParams)); - - final StdStreamData msg1 = dis.readStdStreamData(); - assertFalse(msg1.isTruncated()); - assertEquals(msg1.getPayload(), "Standard".getBytes(StandardCharsets.UTF_8)); - assertEquals(msg1.getType(), StdStreamType.OUT); - - final StdStreamData msg2 = dis.readStdStreamData(); - assertFalse(msg2.isTruncated()); - assertEquals(msg2.getPayload(), "Error".getBytes(StandardCharsets.UTF_8)); - assertEquals(msg2.getType(), StdStreamType.ERR); - - assertNull(dis.readStdStreamData()); - assertSent(server, "POST", "/exec/" + execId + "/start"); - } finally { - if (dis != null) { - dis.close(); - } - server.shutdown(); - } - } - - public void testExecInspect() throws IOException, InterruptedException { - MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/execInspect.json"))); - MiscApi api = api(DockerApi.class, server.getUrl("/").toString(), new DockerParserModule()).getMiscApi(); - final String expectedExecId = "fda1cf8064863fc0667c691c69793fdb7d0bd4a1fabb8250536abe5203e4208a"; - ExecInspect execInspect = api.execInspect(expectedExecId); - assertNotNull(execInspect); - assertEquals(execInspect.id(), expectedExecId); - assertEquals(execInspect.running(), false); - assertEquals(execInspect.exitCode(), 2); - assertSent(server, "GET", "/exec/" + expectedExecId + "/json"); - } - - /** - * Asserts that correct values of HTTP headers are used in Docker build REST - * API calls. - * - * @param request - */ - private void assertDockerBuildHttpHeaders(RecordedRequest request) { - assertThat(request.getHeader("Connection")).isEqualTo("close"); - assertThat(request.getHeader(HttpHeaders.CONTENT_TYPE)).isEqualTo("application/tar"); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/39cd6698/docker/src/test/java/org/jclouds/docker/features/NetworkApiLiveTest.java ---------------------------------------------------------------------- diff --git a/docker/src/test/java/org/jclouds/docker/features/NetworkApiLiveTest.java b/docker/src/test/java/org/jclouds/docker/features/NetworkApiLiveTest.java deleted file mode 100644 index 8edafa3..0000000 --- a/docker/src/test/java/org/jclouds/docker/features/NetworkApiLiveTest.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.docker.features; - -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; -import java.io.IOException; -import java.io.InputStream; -import java.util.List; - -import org.jclouds.docker.compute.BaseDockerApiLiveTest; -import org.jclouds.docker.domain.Config; -import org.jclouds.docker.domain.Container; -import org.jclouds.docker.domain.Image; -import org.jclouds.docker.domain.Network; -import org.jclouds.docker.options.CreateImageOptions; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.google.common.base.Predicates; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Iterables; - -@Test(groups = "live", testName = "NetworkApiLiveTest", singleThreaded = true) -public class NetworkApiLiveTest extends BaseDockerApiLiveTest { - - private static final String NETWORK_NAME = "JCLOUDS_NETWORK"; - - private Network network = null; - protected Image image = null; - private Container container; - - @BeforeClass - protected void init() { - - if (api.getImageApi().inspectImage(ALPINE_IMAGE_TAG) == null) { - CreateImageOptions options = CreateImageOptions.Builder.fromImage(ALPINE_IMAGE_TAG); - InputStream createImageStream = api.getImageApi().createImage(options); - consumeStream(createImageStream); - } - image = api.getImageApi().inspectImage(ALPINE_IMAGE_TAG); - assertNotNull(image); - - Config containerConfig = Config.builder().image(image.id()) - .cmd(ImmutableList.of("sh", "-c", "touch hello; while true; do echo hello world; sleep 1; done")) - .build(); - container = api.getContainerApi().createContainer("jclouds-test-network", containerConfig); - api.getContainerApi().startContainer(container.id()); - container = api.getContainerApi().inspectContainer(container.id()); - } - - @AfterClass(alwaysRun = true) - protected void tearDown() { - if (container != null) { - api.getContainerApi().stopContainer(container.id()); - api.getContainerApi().removeContainer(container.id()); - } - if (network != null) { - api().removeNetwork(network.id()); - } - } - - public void testCreateNetwork() throws IOException, InterruptedException { - network = api().createNetwork(Network.create(NETWORK_NAME, null, null, null, null, ImmutableMap.<String, Network.Details> of(), ImmutableMap.<String, String> of())); - assertNotNull(network); - assertNotNull(network.id()); - } - - @Test(dependsOnMethods = "testCreateNetwork") - public void testGetNetwork() { - network = api().inspectNetwork(network.id()); - assertNotNull(network); - } - - @Test(dependsOnMethods = "testGetNetwork") - public void testAttachContainerToNetwork() { - api().connectContainerToNetwork(network.id(), container.id()); - container = api.getContainerApi().inspectContainer(container.id()); - assertTrue(Iterables.any(container.networkSettings().networks().keySet(), Predicates.equalTo(network.name()))); - } - - @Test(dependsOnMethods = "testAttachContainerToNetwork") - public void testDisconnectContainerFromNetwork() { - api().disconnectContainerFromNetwork(network.id(), container.id()); - container = api.getContainerApi().inspectContainer(container.id()); - assertFalse(Iterables.any(container.networkSettings().networks().keySet(), Predicates.equalTo(network.name()))); - } - - @Test(dependsOnMethods = "testCreateNetwork") - public void testListNetworks() { - List<Network> networks = api().listNetworks(); - for (Network network : networks) { - assertNotNull(network.id()); - } - } - - @Test(dependsOnMethods = "testDisconnectContainerFromNetwork") - public void testRemoveNetwork() { - api().removeNetwork(network.id()); - assertNull(api().inspectNetwork(network.id())); - network = null; - } - - private NetworkApi api() { - return api.getNetworkApi(); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/39cd6698/docker/src/test/java/org/jclouds/docker/features/NetworkApiMockTest.java ---------------------------------------------------------------------- diff --git a/docker/src/test/java/org/jclouds/docker/features/NetworkApiMockTest.java b/docker/src/test/java/org/jclouds/docker/features/NetworkApiMockTest.java deleted file mode 100644 index f35e257..0000000 --- a/docker/src/test/java/org/jclouds/docker/features/NetworkApiMockTest.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.docker.features; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import java.util.Map; - -import org.jclouds.docker.DockerApi; -import org.jclouds.docker.config.DockerParserModule; -import org.jclouds.docker.domain.Network; -import org.jclouds.docker.internal.BaseDockerMockTest; -import org.jclouds.docker.parse.NetworkParseTest; -import org.jclouds.docker.parse.NetworksParseTest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; - -/** - * Mock tests for the {@link NetworkApi} class. - */ -@Test(groups = "unit", testName = "NetworkApiMockTest") -public class NetworkApiMockTest extends BaseDockerMockTest { - - public void testListNetworks() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/networks.json"))); - NetworkApi api = api(DockerApi.class, server.getUrl("/").toString()).getNetworkApi(); - try { - assertEquals(api.listNetworks(), new NetworksParseTest().expected()); - assertSent(server, "GET", "/networks"); - } finally { - server.shutdown(); - } - } - - public void testListNonexistentNetworks() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setResponseCode(404)); - NetworkApi api = api(DockerApi.class, server.getUrl("/").toString()).getNetworkApi(); - try { - assertEquals(api.listNetworks(), ImmutableList.of()); - assertSent(server, "GET", "/networks"); - } finally { - server.shutdown(); - } - } - - public void testGetNetwork() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/network.json"))); - NetworkApi api = api(DockerApi.class, server.getUrl("/").toString(), new DockerParserModule()).getNetworkApi(); - String networkId = "b03d4cd15b76f8876110615cdeed15eadf77c9beb408d62f1687dcc69192cd6d"; - try { - assertEquals(api.inspectNetwork(networkId), new NetworkParseTest().expected()); - assertSent(server, "GET", "/networks/" + networkId); - } finally { - server.shutdown(); - } - } - - public void testCreateNetwork() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/network-creation.json"))); - NetworkApi api = api(DockerApi.class, server.getUrl("/").toString()).getNetworkApi(); - - Map<String, String> options = ImmutableMap.<String, String> builder() - .put("com.docker.network.bridge.default_bridge", "true") - .put("com.docker.network.bridge.enable_icc", "true") - .put("com.docker.network.bridge.enable_ip_masquerade", "true") - .put("com.docker.network.bridge.host_binding_ipv4", "0.0.0.0") - .put("com.docker.network.bridge.name", "docker0") - .put("com.docker.network.driver.mtu", "1500") - .build(); - - Network network = Network.create( - "isolated_nw", // Name - null, // Id - "bridge", // Driver - null, // Scope - Network.IPAM.create( - "default", // driver - ImmutableList.of(Network.IPAM.Config.create("172.17.0.0/16", null, null)) // config - ), - ImmutableMap.of("39b69226f9d79f5634485fb236a23b2fe4e96a0a94128390a7fbbcc167065867", - Network.Details.create( - "ed2419a97c1d9954d05b46e462e7002ea552f216e9b136b80a7db8d98b442eda", //endpointId - "02:42:ac:11:00:02", // MAC - "172.17.0.2/16", // ipv4address - "" // ipv6address - ) - ), - options); - - try { - Network created = api.createNetwork(network); - assertNotNull(created); - assertThat(created.id()).isEqualTo("22be93d5babb089c5aab8dbc369042fad48ff791584ca2da2100db837a1c7c30"); - assertSent(server, "POST", "/networks/create", "{\"Name\":\"isolated_nw\",\"Scope\":\"bridge\",\"IPAM\":{\"Driver\":\"default\",\"Config\":[{\"Subnet\":\"172.17.0.0/16\"}]},\"Containers\":{\"39b69226f9d79f5634485fb236a23b2fe4e96a0a94128390a7fbbcc167065867\":{\"EndpointID\":\"ed2419a97c1d9954d05b46e462e7002ea552f216e9b136b80a7db8d98b442eda\",\"MacAddress\":\"02:42:ac:11:00:02\",\"IPv4Address\":\"172.17.0.2/16\",\"IPv6Address\":\"\"}},\"Options\":{\"com.docker.network.bridge.default_bridge\":\"true\",\"com.docker.network.bridge.enable_icc\":\"true\",\"com.docker.network.bridge.enable_ip_masquerade\":\"true\",\"com.docker.network.bridge.host_binding_ipv4\":\"0.0.0.0\",\"com.docker.network.bridge.name\":\"docker0\",\"com.docker.network.driver.mtu\":\"1500\"}}"); - } finally { - server.shutdown(); - } - } - - public void testRemoveNetwork() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setResponseCode(204)); - NetworkApi api = api(DockerApi.class, server.getUrl("/").toString()).getNetworkApi(); - String networkId = "6d35806c1bd2b25cd92bba2d2c2c5169dc2156f53ab45c2b62d76e2d2fee14a9"; - try { - api.removeNetwork(networkId); - assertSent(server, "DELETE", "/networks/" + networkId); - } finally { - server.shutdown(); - } - } - - public void testConnectContainerToNetwork() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setResponseCode(200)); - NetworkApi api = api(DockerApi.class, server.getUrl("/").toString()).getNetworkApi(); - try { - api.connectContainerToNetwork("123456789", "containerName"); - assertSent(server, "POST", "/networks/123456789/connect", "{ \"Container\": \"containerName\" }"); - } finally { - server.shutdown(); - } - } - - public void testDisconnectContainerFromNetwork() throws Exception { - MockWebServer server = mockWebServer(new MockResponse().setResponseCode(200)); - NetworkApi api = api(DockerApi.class, server.getUrl("/").toString()).getNetworkApi(); - try { - api.disconnectContainerFromNetwork("123456789", "containerName"); - assertSent(server, "POST", "/networks/123456789/disconnect", "{ \"Container\": \"containerName\" }"); - } finally { - server.shutdown(); - } - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/39cd6698/docker/src/test/java/org/jclouds/docker/internal/BaseDockerMockTest.java ---------------------------------------------------------------------- diff --git a/docker/src/test/java/org/jclouds/docker/internal/BaseDockerMockTest.java b/docker/src/test/java/org/jclouds/docker/internal/BaseDockerMockTest.java deleted file mode 100644 index f04e94f..0000000 --- a/docker/src/test/java/org/jclouds/docker/internal/BaseDockerMockTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.docker.internal; - -import static com.google.common.base.Charsets.UTF_8; -import static javax.ws.rs.core.MediaType.APPLICATION_JSON; -import static org.assertj.core.api.Assertions.assertThat; -import static org.jclouds.util.Strings2.toStringAndClose; -import static org.testng.Assert.assertEquals; -import java.io.IOException; -import java.util.Properties; - -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; - -import org.jclouds.http.BaseMockWebServerTest; -import org.jclouds.http.okhttp.config.OkHttpCommandExecutorServiceModule; - -import com.google.common.base.Charsets; -import com.google.common.base.Throwables; -import com.google.gson.JsonParser; -import com.google.inject.Module; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import com.squareup.okhttp.mockwebserver.RecordedRequest; - -/** - * Base class for all Docker mock tests. - */ -public class BaseDockerMockTest extends BaseMockWebServerTest { - - protected static final String API_VERSION = "1.15"; - - @Override - protected void addOverrideProperties(Properties properties) { - properties.setProperty("jclouds.api-version", API_VERSION); - } - - @Override - protected Module createConnectionModule() { - return new OkHttpCommandExecutorServiceModule(); - } - - public byte[] payloadFromResource(String resource) { - try { - return toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8); - } catch (IOException e) { - throw Throwables.propagate(e); - } - } - - protected RecordedRequest assertSent(MockWebServer server, String method, String path) throws InterruptedException { - RecordedRequest request = server.takeRequest(); - assertThat(request.getMethod()).isEqualTo(method); - assertThat(request.getPath()).isEqualTo("/v" + API_VERSION + path); - assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo(MediaType.APPLICATION_JSON); - return request; - } - - protected RecordedRequest assertSent(MockWebServer server, String method, String path, String json) - throws InterruptedException { - RecordedRequest request = assertSent(server, method, path); - assertEquals(request.getHeader("Content-Type"), APPLICATION_JSON); - assertEquals(parser.parse(new String(request.getBody(), UTF_8)), parser.parse(json)); - return request; - } - - /** So that we can ignore formatting. */ - private final JsonParser parser = new JsonParser(); - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/39cd6698/docker/src/test/java/org/jclouds/docker/internal/BaseDockerParseTest.java ---------------------------------------------------------------------- diff --git a/docker/src/test/java/org/jclouds/docker/internal/BaseDockerParseTest.java b/docker/src/test/java/org/jclouds/docker/internal/BaseDockerParseTest.java deleted file mode 100644 index 5227ff8..0000000 --- a/docker/src/test/java/org/jclouds/docker/internal/BaseDockerParseTest.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.docker.internal; - -import org.jclouds.docker.config.DockerParserModule; -import org.jclouds.json.BaseItemParserTest; -import org.jclouds.json.config.GsonModule; - -import com.google.inject.Guice; -import com.google.inject.Injector; - -public abstract class BaseDockerParseTest<T> extends BaseItemParserTest<T> { - - @Override - protected Injector injector() { - return Guice.createInjector(new GsonModule(), new DockerParserModule()); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/39cd6698/docker/src/test/java/org/jclouds/docker/internal/DockerTestUtils.java ---------------------------------------------------------------------- diff --git a/docker/src/test/java/org/jclouds/docker/internal/DockerTestUtils.java b/docker/src/test/java/org/jclouds/docker/internal/DockerTestUtils.java deleted file mode 100644 index aa136d7..0000000 --- a/docker/src/test/java/org/jclouds/docker/internal/DockerTestUtils.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.docker.internal; - -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.logging.Level; - -import org.jclouds.docker.DockerApi; -import org.jclouds.docker.features.ImageApi; -import org.jclouds.docker.options.DeleteImageOptions; - -import com.google.common.base.Preconditions; - -/** - * Utility methods shared by Docker tests. - */ -public class DockerTestUtils { - - /** - * Read all data from given {@link InputStream} and throw away all the bits. - * If an {@link IOException} occurs, it's not propagated to user. The given InputStream is closed after the read. - * - * @param is InputStream instance (may be null) - */ - public static void consumeStreamSilently(InputStream is) { - if (is == null) { - return; - } - char[] tmpBuff = new char[8 * 1024]; - // throw everything away - InputStreamReader isr = new InputStreamReader(is); - try { - try { - while (isr.read(tmpBuff) > -1) { - // empty - } - } finally { - isr.close(); - } - } catch (IOException e) { - java.util.logging.Logger.getAnonymousLogger().log(Level.WARNING, "Error ocured during reading InputStream.", e); - } - } - - /** - * Removes Docker image if it's present on the Docker host. Docker Image API - * is used to inspect and remove image (({@link ImageApi#deleteImage(String)} - * method). - * - * @param dockerApi - * DockerApi instance (must be not-<code>null</code>) - * @param imageName - * image to be deleted (must be not-<code>null</code>) - */ - public static void removeImageIfExists(DockerApi dockerApi, String imageName) { - Preconditions.checkNotNull(dockerApi, "DockerApi instance has to be provided"); - Preconditions.checkNotNull(imageName, "Docker image name has to be provided"); - final ImageApi imageApi = dockerApi.getImageApi(); - if (null != imageApi.inspectImage(imageName)) { - consumeStreamSilently(imageApi.deleteImage(imageName, DeleteImageOptions.Builder.force(true))); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/39cd6698/docker/src/test/java/org/jclouds/docker/parse/ContainerParseTest.java ---------------------------------------------------------------------- diff --git a/docker/src/test/java/org/jclouds/docker/parse/ContainerParseTest.java b/docker/src/test/java/org/jclouds/docker/parse/ContainerParseTest.java deleted file mode 100644 index 291fa13..0000000 --- a/docker/src/test/java/org/jclouds/docker/parse/ContainerParseTest.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.docker.parse; - -import java.util.List; -import java.util.Map; - -import javax.ws.rs.Consumes; -import javax.ws.rs.core.MediaType; - -import org.jclouds.date.internal.SimpleDateFormatDateService; -import org.jclouds.docker.domain.Config; -import org.jclouds.docker.domain.Container; -import org.jclouds.docker.domain.HostConfig; -import org.jclouds.docker.domain.NetworkSettings; -import org.jclouds.docker.domain.Node; -import org.jclouds.docker.domain.State; -import org.jclouds.docker.internal.BaseDockerParseTest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - -@Test(groups = "unit") -public class ContainerParseTest extends BaseDockerParseTest<Container> { - - @Override - public String resource() { - return "/container.json"; - } - - @Override - @Consumes(MediaType.APPLICATION_JSON) - public Container expected() { - return Container.builder() - .id("6c9932f478bd761f32ddb54ed28ab42ab6fac6f2a279f561ea31503ee9d39524") - .created(new SimpleDateFormatDateService().iso8601DateParse("2014-10-31T17:00:21.544197943Z")) - .path("/home/weave/weaver") - .name("/weave") - .args(ImmutableList.of("-iface", "ethwe", "-wait", "5", "-name", "7a:63:a2:39:7b:0f")) - .config(Config.builder() - .hostname("6c9932f478bd") - .env(ImmutableList.of("PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin")) - .image("zettio/weave") - .domainname("") - .user("") - .cmd(ImmutableList.of("-name", "7a:63:a2:39:7b:0f")) - .entrypoint(ImmutableList.of("/home/weave/weaver", "-iface", "ethwe", "-wait", "5")) - .workingDir("/home/weave") - .exposedPorts(ImmutableMap.of("6783/tcp", ImmutableMap.of(), "6783/udp", ImmutableMap.of())) - .build()) - .state(State.create(10357, true, 0, "2015-11-10T09:33:21.68146124Z", "0001-01-01T00:00:00Z", false, false, "running", false, false, "")) - .image("57e570db16baba1e8c0d6f3c15868ddb400f64ff76ec948e65c3ca3f15fb3587") - .networkSettings(NetworkSettings.builder() - .sandboxId("3ef128b055eb9ef62a6a2c281d97a2dfde5f47947d490f1dd2a81612611d961f") - .hairpinMode(false) - .linkLocalIPv6Address("") - .linkLocalIPv6PrefixLen(0) - .globalIPv6Address("") - .globalIPv6PrefixLen(0) - .ipv6Gateway("") - .sandboxKey("/var/run/docker/netns/3ef128b055eb") - .endpointId("9e8dcc0c8288938a923018fee0728cee8e6de7c01a5150738ee6e51c1caf8cf6") - .ipAddress("172.17.0.2") - .ipPrefixLen(16) - .gateway("172.17.0.1") - .bridge("") - .ports(ImmutableMap.<String, List<Map<String, String>>>of()) - .macAddress("02:42:ac:11:00:02") - .networks(ImmutableMap.of( - "JCLOUDS_NETWORK", NetworkSettings.Details.create( - "04268fbb4dc368b5a53bb1c3f89294a4f0c72095deb944db3c4efc6d6a439304", - "172.19.0.1", - "172.19.0.2", - 16, - "", - "", - 0, - "02:42:ac:13:00:02" - ), - "bridge", NetworkSettings.Details.create( - "9e8dcc0c8288938a923018fee0728cee8e6de7c01a5150738ee6e51c1caf8cf6", - "172.17.0.1", - "172.17.0.2", - 16, - "", - "", - 0, - "02:42:ac:11:00:02" - ) - )) - .build()) - .resolvConfPath("/var/lib/docker/containers/6c9932f478bd761f32ddb54ed28ab42ab6fac6f2a279f561ea31503ee9d39524/resolv.conf") - .hostConfig(HostConfig.builder() - .containerIDFile("") - .portBindings(ImmutableMap.<String, List<Map<String, String>>>of( - "6783/tcp", ImmutableList.<Map<String, String>>of(ImmutableMap.of("HostIp", "", "HostPort", "6783")), - "6783/udp", ImmutableList.<Map<String, String>>of(ImmutableMap.of("HostIp", "", "HostPort", "6783"))) - ) - .capAdd(ImmutableList.of("NET_ADMIN")) - .capDrop(ImmutableList.of("MKNOD")) - .dns(ImmutableList.of("8.8.8.8", "8.8.4.4")) - .extraHosts(ImmutableList.<String>of("extra:169.254.0.1")) - .privileged(true) - .networkMode("bridge") - .restartPolicy(ImmutableMap.<String, String> of("MaximumRetryCount", "0", "Name", "")) - .build()) - .driver("aufs") - .execDriver("native-0.2") - .hostnamePath("/var/lib/docker/containers/6c9932f478bd761f32ddb54ed28ab42ab6fac6f2a279f561ea31503ee9d39524/hostname") - .hostsPath("/var/lib/docker/containers/6c9932f478bd761f32ddb54ed28ab42ab6fac6f2a279f561ea31503ee9d39524/hosts") - .mountLabel("") - .processLabel("") - .node(Node.builder(). - ip("10.10.10.10").build()) - .build(); - } -}
