Search in sources :

Example 56 with IDockerConnection

use of org.eclipse.linuxtools.docker.core.IDockerConnection in project jbosstools-openshift by jbosstools.

the class CDKDockerUtilityTest method testDockerConnectionExists.

@Test
public void testDockerConnectionExists() throws Exception {
    assertFalse(util.dockerConnectionExists(null));
    assertFalse(util.dockerConnectionExists("test"));
    IDockerConnection existingConnection = mock(IDockerConnection.class);
    when(existingConnection.getUri()).thenReturn("https://10.1.2.2:2376");
    when(existingConnection.getName()).thenReturn("test");
    when(mgr.getConnections()).thenReturn(new IDockerConnection[] { existingConnection });
    assertTrue(util.dockerConnectionExists("test"));
    IDockerConnection found = util.findDockerConnection("test");
    assertEquals(found, existingConnection);
}
Also used : IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) Test(org.junit.Test)

Example 57 with IDockerConnection

use of org.eclipse.linuxtools.docker.core.IDockerConnection in project jbosstools-openshift by jbosstools.

the class DeployImageWizardModelTest method checkThatNewDockerConnectionsAreReported.

@Test
public void checkThatNewDockerConnectionsAreReported() throws DockerException {
    IDockerConnection connection = mock(IDockerConnection.class);
    int connectionsSize = model.getDockerConnections().size();
    DockerConnectionManager.getInstance().addConnection(connection);
    assertThat(model.getDockerConnections()).hasSize(connectionsSize + 1);
}
Also used : IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) Test(org.junit.Test)

Example 58 with IDockerConnection

use of org.eclipse.linuxtools.docker.core.IDockerConnection in project jbosstools-openshift by jbosstools.

the class DeployImageHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Connection connection = null;
    IProject project = null;
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    final IDockerImage image = UIUtils.getFirstElement(selection, IDockerImage.class);
    if (image == null || OpenShiftUIUtils.hasOpenShiftExplorerSelection()) {
        selection = OpenShiftUIUtils.getOpenShiftExplorerSelection();
        project = ResourceUtils.getProject(UIUtils.getFirstElement(selection, IResource.class));
        if (project != null) {
            connection = ConnectionsRegistryUtil.getConnectionFor(project);
        } else {
            connection = UIUtils.getFirstElement(selection, Connection.class);
        }
    }
    if (connection == null) {
        connection = OpenShiftUIUtils.getExplorerDefaultConnection(Connection.class);
    }
    IDockerConnection dockerConnection = null;
    if (image != null) {
        dockerConnection = image.getConnection();
    } else if (OpenShiftUIUtils.hasDockerExplorerSelection()) {
        ISelection dockerSelection = OpenShiftUIUtils.getDockerExplorerSelection();
        dockerConnection = UIUtils.getFirstElement(dockerSelection, IDockerConnection.class);
        if (dockerConnection == null) {
            // Action is originated from OpenShift Explorer, do the best to pick up Docker connection from the current selection in Docker Explorer.
            IDockerImage selectedImage = UIUtils.getFirstElement(dockerSelection, IDockerImage.class);
            if (selectedImage != null) {
                dockerConnection = selectedImage.getConnection();
            }
        }
    }
    runWizard(HandlerUtil.getActiveWorkbenchWindow(event).getShell(), dockerConnection, image, project, connection);
    return null;
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) ISelection(org.eclipse.jface.viewers.ISelection) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) IProject(com.openshift.restclient.model.IProject)

Example 59 with IDockerConnection

use of org.eclipse.linuxtools.docker.core.IDockerConnection in project linuxtools by eclipse.

the class EditDockerConnectionSWTBotTest method shouldSaveConnectionWhenNameAndTCPConnectionSettingsChanged.

@SuppressWarnings("unchecked")
@Test
public void shouldSaveConnectionWhenNameAndTCPConnectionSettingsChanged() {
    // given
    final IDockerConnection connection = configureTCPConnection("Test");
    final IDockerConnectionStorageManager connectionStorageManager = MockDockerConnectionStorageManagerFactory.providing(connection);
    DockerConnectionManagerUtils.configureConnectionManager(connectionStorageManager);
    final SWTBotTreeItem connectionTreeItem = SWTUtils.getTreeItem(dockerExplorer.bot(), "Test");
    assertThat(connectionTreeItem).isNotNull();
    // let's ignore the connection savings that may have occurred when
    // adding elements from the extension points
    Mockito.reset(connectionStorageManager);
    // when
    openConnectionEditionWizard("Test");
    bot.text(0).setText("foo");
    bot.text(2).setText("https://foo.bar:1234");
    getFinishButton().click();
    // then
    final IDockerConnection foundConnection = DockerConnectionManager.getInstance().findConnection("foo");
    assertThat(foundConnection).isNotNull();
    assertThat(foundConnection.getSettings()).isNotNull().isEqualTo(new TCPConnectionSettings("https://foo.bar:1234", PATH_TO_CERTS));
    Mockito.verify(connectionStorageManager).saveConnections(Matchers.anyList());
}
Also used : IDockerConnectionStorageManager(org.eclipse.linuxtools.docker.core.IDockerConnectionStorageManager) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) TCPConnectionSettings(org.eclipse.linuxtools.internal.docker.core.TCPConnectionSettings) Test(org.junit.Test)

Example 60 with IDockerConnection

use of org.eclipse.linuxtools.docker.core.IDockerConnection in project linuxtools by eclipse.

the class EditDockerConnectionSWTBotTest method shouldRefreshDockerExplorerViewWhenTCPConnectionSettingsChanged.

@Test
public void shouldRefreshDockerExplorerViewWhenTCPConnectionSettingsChanged() {
    // given
    dockerContainers.close();
    dockerImages.close();
    final IDockerConnection connection = configureTCPConnection("Test");
    final SWTBotTreeItem connectionTreeItem = SWTUtils.getTreeItem(dockerExplorer.bot(), "Test");
    assertThat(connectionTreeItem).isNotNull();
    // when
    openConnectionEditionWizard("Test");
    bot.text(2).setText("https://foo.bar:1234");
    getFinishButton().click();
    SWTUtils.wait(2, TimeUnit.SECONDS);
    // then
    final SWTBotTreeItem updatedConnectionTreeItem = SWTUtils.getTreeItem(dockerExplorer.bot(), "Test");
    assertThat(updatedConnectionTreeItem).isNotNull();
    assertThat(updatedConnectionTreeItem.getText()).contains("https://foo.bar:1234");
    // list of containers and images should have been refreshed
    Mockito.verify(connection, Mockito.times(0)).getContainers(true);
    Mockito.verify(connection, Mockito.times(0)).getImages(true);
}
Also used : SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) Test(org.junit.Test)

Aggregations

IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)90 DockerException (org.eclipse.linuxtools.docker.core.DockerException)24 DockerConnection (org.eclipse.linuxtools.internal.docker.core.DockerConnection)20 Job (org.eclipse.core.runtime.jobs.Job)17 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)16 IDockerImage (org.eclipse.linuxtools.docker.core.IDockerImage)15 Test (org.junit.Test)15 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)12 SWTBotTreeItem (org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem)9 File (java.io.File)8 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 IDockerContainer (org.eclipse.linuxtools.docker.core.IDockerContainer)8 IPath (org.eclipse.core.runtime.IPath)7 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)7 List (java.util.List)5 IDockerConnectionStorageManager (org.eclipse.linuxtools.docker.core.IDockerConnectionStorageManager)5 RunConsole (org.eclipse.linuxtools.internal.docker.ui.consoles.RunConsole)5 DockerClient (com.spotify.docker.client.DockerClient)4 HashMap (java.util.HashMap)4