Search in sources :

Example 1 with Image

use of com.spotify.docker.client.messages.Image in project linuxtools by eclipse.

the class DockerImageHierarchyViewSWTBotTest method setupData.

@Before
public void setupData() {
    // data is built as follows:
    // root_image
    // |- foo_image1
    // _|- foo_container1 (Up)
    // _|- foo_image2
    // __|- foo_container21 (Exited)
    // __|- foo_container22 (Paused)
    // |- bar_image11
    // _|- bar_container1
    final Image rootImage = MockImageFactory.id("sha256:root_image").name("root_image").build();
    final Image fooImage1 = MockImageFactory.id("sha256:foo_image1").name("foo_image1").parentId("sha256:root_image").build();
    final Image fooImage2 = MockImageFactory.id("sha256:foo_image2").name("foo_image2", "foo_image2_alias").parentId("sha256:foo_image1").build();
    final Container fooContainer1 = MockContainerFactory.id("sha256:foo_container1").name("foo_container1").imageName("foo_image1").status("Up").build();
    final Container fooContainer21 = MockContainerFactory.id("sha256:foo_container21").name("foo_container21").imageName("foo_image2").status("Exited").build();
    final Container fooContainer22 = MockContainerFactory.id("sha256:foo_container22").name("foo_container22").imageName("foo_image2_alias").status("Up (Paused)").build();
    final Image barImage1 = MockImageFactory.id("sha256:bar_image1").name("bar_image1").parentId("sha256:root_image").build();
    final Container barContainer1 = MockContainerFactory.id("sha256:bar_container1").name("bar_container1").imageName("bar_image1").build();
    final DockerClient client = MockDockerClientFactory.image(rootImage).image(fooImage1).container(fooContainer1).image(fooImage2).container(fooContainer21).container(fooContainer22).image(barImage1).container(barContainer1).build();
    this.connection = MockDockerConnectionFactory.from("Test", client).withDefaultTCPConnectionSettings();
    this.connection.getImages(true);
    this.connection.getContainers(true);
    DockerConnectionManagerUtils.configureConnectionManager(connection);
}
Also used : IDockerContainer(org.eclipse.linuxtools.docker.core.IDockerContainer) Container(com.spotify.docker.client.messages.Container) DockerClient(com.spotify.docker.client.DockerClient) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) Image(com.spotify.docker.client.messages.Image) Before(org.junit.Before)

Example 2 with Image

use of com.spotify.docker.client.messages.Image in project linuxtools by eclipse.

the class DockerImageHierarchyViewSWTBotTest method setupViews.

@Before
public void setupViews() {
    this.bot = new SWTWorkbenchBot();
    SWTUtils.asyncExec(() -> {
        try {
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(DockerExplorerView.VIEW_ID);
        } catch (Exception e) {
            e.printStackTrace();
            Assert.fail("Failed to open Docker Explorer view: " + e.getMessage());
        }
    });
    this.dockerExplorerViewBot = bot.viewById(DockerExplorerView.VIEW_ID);
    this.dockerExplorerView = (DockerExplorerView) (dockerExplorerViewBot.getViewReference().getView(true));
    // make sure that the Docker Image Hierarchy view is closed
    this.bot.views().stream().filter(v -> v.getReference().getId().equals(DockerImageHierarchyView.VIEW_ID)).forEach(v -> v.close());
}
Also used : IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) CloseWelcomePageRule(org.eclipse.linuxtools.internal.docker.ui.testutils.swt.CloseWelcomePageRule) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IDockerContainer(org.eclipse.linuxtools.docker.core.IDockerContainer) SWTBotMenu(org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) DockerImageHierarchyViewAssertions(org.eclipse.linuxtools.internal.docker.ui.testutils.swt.DockerImageHierarchyViewAssertions) DockerConnectionManagerUtils(org.eclipse.linuxtools.internal.docker.ui.testutils.swt.DockerConnectionManagerUtils) TabDescriptorAssertions(org.eclipse.linuxtools.internal.docker.ui.testutils.swt.TabDescriptorAssertions) DockerClient(com.spotify.docker.client.DockerClient) WidgetNotFoundException(org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException) After(org.junit.After) MockContainerFactory(org.eclipse.linuxtools.internal.docker.ui.testutils.MockContainerFactory) SWTWorkbenchBot(org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot) ClassRule(org.junit.ClassRule) SWTBotView(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView) Before(org.junit.Before) MockImageFactory(org.eclipse.linuxtools.internal.docker.ui.testutils.MockImageFactory) PlatformUI(org.eclipse.ui.PlatformUI) MockDockerConnectionFactory(org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerConnectionFactory) PropertySheet(org.eclipse.ui.views.properties.PropertySheet) Test(org.junit.Test) Collectors(java.util.stream.Collectors) MockDockerClientFactory(org.eclipse.linuxtools.internal.docker.ui.testutils.MockDockerClientFactory) TabbedPropertySheetPage(org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage) Container(com.spotify.docker.client.messages.Container) List(java.util.List) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) Rule(org.junit.Rule) Image(com.spotify.docker.client.messages.Image) MenuAssertion(org.eclipse.linuxtools.internal.docker.ui.testutils.swt.MenuAssertion) ClearConnectionManagerRule(org.eclipse.linuxtools.internal.docker.ui.testutils.swt.ClearConnectionManagerRule) IDockerImageHierarchyNode(org.eclipse.linuxtools.docker.core.IDockerImageHierarchyNode) TestLoggerRule(org.eclipse.linuxtools.internal.docker.ui.testutils.swt.TestLoggerRule) SWTUtils(org.eclipse.linuxtools.internal.docker.ui.testutils.swt.SWTUtils) Assert(org.junit.Assert) SWTWorkbenchBot(org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot) WidgetNotFoundException(org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException) Before(org.junit.Before)

Example 3 with Image

use of com.spotify.docker.client.messages.Image in project linuxtools by eclipse.

the class ImageRunSWTBotTest method shouldCreateLaunchConfigurationWhenRunningNamedContainer.

@Test
public void shouldCreateLaunchConfigurationWhenRunningNamedContainer() throws InterruptedException, DockerException, CoreException {
    // images to use
    final String imageName = "foo/bar:latest";
    final Image image = MockImageFactory.id("1a2b3c4d5e6f7g").name(imageName).build();
    final ImageInfo imageInfo = MockImageInfoFactory.volume("/foo/bar").command(Arrays.asList("the", "command")).entrypoint(Arrays.asList("the", "entrypoint")).build();
    // container to be created
    final String containerName = "foo_bar";
    final Container createdContainer = MockContainerFactory.id("MockContainer").name(containerName).imageName("1a2b3c4d5e6f7g").status("Started 1 second ago").build();
    final ContainerInfo containerInfo = MockContainerInfoFactory.build();
    final DockerClient client = MockDockerClientFactory.image(image, imageInfo).build();
    // expected response when creating the container
    final ContainerCreation containerCreation = Mockito.mock(ContainerCreation.class);
    Mockito.when(containerCreation.id()).thenReturn("MockContainer");
    Mockito.when(client.createContainer(Matchers.any(), Matchers.any())).thenReturn(containerCreation);
    final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).withDefaultTCPConnectionSettings();
    // configure the Connection Manager
    DockerConnectionManagerUtils.configureConnectionManager(dockerConnection);
    // when select images and click on run to open the wizard
    SWTUtils.getTreeItem(dockerExplorerViewBot, "Test", "Images", "foo/bar").select();
    dockerExplorerViewBot.bot().tree().contextMenu("Run...").click();
    // $NON-NLS-1$
    bot.waitUntil(Conditions.shellIsActive("Run a Docker Image"), TimeUnit.SECONDS.toMillis(1));
    // configure container
    bot.text(0).setText(containerName);
    // bot.button("Next >").click();
    // update the client to make sure the container exists once the call to "Finish" is done
    MockDockerClientFactory.addContainer(client, createdContainer, containerInfo);
    bot.button("Finish").click();
    // wait for background job to complete
    SWTUtils.waitForJobsToComplete();
    // then
    // check that the client was called
    Mockito.verify(client).createContainer(Matchers.any(), Matchers.eq(containerName));
    // check that a launch configuration was created
    final ILaunchConfiguration launchConfiguration = LaunchConfigurationUtils.getLaunchConfigurationByName(IRunDockerImageLaunchConfigurationConstants.CONFIG_TYPE_ID, "foo_bar_latest");
    assertThat(launchConfiguration).isNotNull();
}
Also used : IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) ContainerCreation(com.spotify.docker.client.messages.ContainerCreation) Container(com.spotify.docker.client.messages.Container) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) DockerClient(com.spotify.docker.client.DockerClient) ContainerInfo(com.spotify.docker.client.messages.ContainerInfo) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) Image(com.spotify.docker.client.messages.Image) ImageInfo(com.spotify.docker.client.messages.ImageInfo) Test(org.junit.Test)

Example 4 with Image

use of com.spotify.docker.client.messages.Image in project linuxtools by eclipse.

the class DockerConnectionTest method shouldLoadImages.

@Test
public void shouldLoadImages() throws DockerException {
    // given
    final Image fooImage = MockImageFactory.id("foo").build();
    final Image barImage = MockImageFactory.id("bar").build();
    final DockerClient client = MockDockerClientFactory.image(fooImage).image(barImage).build();
    final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).withDefaultTCPConnectionSettings();
    dockerConnection.open(false);
    // when
    final List<IDockerImage> images = dockerConnection.getImages();
    // then
    assertThat(images).hasSize(2);
}
Also used : DockerClient(com.spotify.docker.client.DockerClient) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) Image(com.spotify.docker.client.messages.Image) Test(org.junit.Test)

Example 5 with Image

use of com.spotify.docker.client.messages.Image in project linuxtools by eclipse.

the class DockerConnectionTest method hasImageTest.

@Test
public void hasImageTest() throws DockerException {
    // given
    final Image fooImage = MockImageFactory.id("foo").name("foo", "foo:latest", "foo:1.0", "org/foo", "org/foo:1.0", "org/foo:latest").build();
    final DockerClient client = MockDockerClientFactory.image(fooImage).build();
    final DockerConnection dockerConnection = MockDockerConnectionFactory.from("Test", client).withDefaultTCPConnectionSettings();
    // when
    dockerConnection.open(false);
    // then
    assertTrue(dockerConnection.hasImage("foo", null));
    assertTrue(dockerConnection.hasImage("foo", "latest"));
    assertTrue(dockerConnection.hasImage("foo", "1.0"));
    assertTrue(dockerConnection.hasImage("org/foo", null));
    assertTrue(dockerConnection.hasImage("org/foo", "latest"));
    assertTrue(dockerConnection.hasImage("org/foo", "1.0"));
}
Also used : DockerClient(com.spotify.docker.client.DockerClient) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) Image(com.spotify.docker.client.messages.Image) Test(org.junit.Test)

Aggregations

Image (com.spotify.docker.client.messages.Image)14 DockerClient (com.spotify.docker.client.DockerClient)7 Test (org.junit.Test)7 IDockerImage (org.eclipse.linuxtools.docker.core.IDockerImage)6 Container (com.spotify.docker.client.messages.Container)4 DockerException (com.spotify.docker.client.exceptions.DockerException)3 RemovedImage (com.spotify.docker.client.messages.RemovedImage)3 Long.toHexString (java.lang.Long.toHexString)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)3 ContainerCreation (com.spotify.docker.client.messages.ContainerCreation)2 ContainerInfo (com.spotify.docker.client.messages.ContainerInfo)2 ImageInfo (com.spotify.docker.client.messages.ImageInfo)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 IDockerContainer (org.eclipse.linuxtools.docker.core.IDockerContainer)2 DockerConnection (org.eclipse.linuxtools.internal.docker.core.DockerConnection)2 Before (org.junit.Before)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1