Search in sources :

Example 11 with IProject

use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.

the class OpenShiftExplorerLabelProviderTest method getStyledTextForAProject.

@Test
public void getStyledTextForAProject() {
    String displayName = "The Display Name";
    String namespace = "anamespace";
    IProject project = givenAResource(IProject.class, ResourceKind.PROJECT);
    when(project.getDisplayName()).thenReturn(displayName);
    when(project.getNamespaceName()).thenReturn(namespace);
    assertEquals(project.getDisplayName() + " " + project.getName(), provider.getStyledText(project).getString());
}
Also used : StyledString(org.eclipse.jface.viewers.StyledString) IProject(com.openshift.restclient.model.IProject) Test(org.junit.Test)

Example 12 with IProject

use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.

the class OpenShiftExplorerLabelProviderTest method getStyledTextForAProjectWithoutDisplayName.

@Test
public void getStyledTextForAProjectWithoutDisplayName() {
    String displayName = "The Display Name";
    String namespace = "anamespace";
    IProject project = givenAResource(IProject.class, ResourceKind.PROJECT);
    when(project.getName()).thenReturn(displayName);
    when(project.getNamespaceName()).thenReturn(namespace);
    assertEquals(project.getName(), provider.getStyledText(project).getString());
}
Also used : StyledString(org.eclipse.jface.viewers.StyledString) IProject(com.openshift.restclient.model.IProject) Test(org.junit.Test)

Example 13 with IProject

use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.

the class DeployImageWizardModelTest method loadResources_should_reset_project_if_not_contained_in_loaded_project.

@Test
public void loadResources_should_reset_project_if_not_contained_in_loaded_project() {
    // given
    IProject selectedProject = mock(IProject.class);
    model.setProject(selectedProject);
    IProject project1 = mock(IProject.class);
    IProject project2 = mock(IProject.class);
    createModelProjects(this.connection, project1, project2);
    model.setResourcesLoaded(false);
    // when
    model.loadResources();
    // then
    assertThat(model.getProject()).isNotEqualTo(selectedProject);
    assertThat(model.getProject()).isEqualTo(project1);
}
Also used : IProject(com.openshift.restclient.model.IProject) Test(org.junit.Test)

Example 14 with IProject

use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.

the class DeployImageWizardModelTest method addProject_should_not_reset_project.

@Test
public void addProject_should_not_reset_project() {
    // given
    IProject project1 = mock(IProject.class);
    // when
    model.addProject(project1);
    assertThat(model.getProject()).isEqualTo(project);
}
Also used : IProject(com.openshift.restclient.model.IProject) Test(org.junit.Test)

Example 15 with IProject

use of com.openshift.restclient.model.IProject 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)

Aggregations

IProject (com.openshift.restclient.model.IProject)49 Test (org.junit.Test)18 Connection (org.jboss.tools.openshift.core.connection.Connection)16 IResource (com.openshift.restclient.model.IResource)13 ArrayList (java.util.ArrayList)8 IConnection (org.jboss.tools.openshift.common.core.connection.IConnection)7 ResourceKind (com.openshift.restclient.ResourceKind)6 IStatus (org.eclipse.core.runtime.IStatus)6 ObservableTreeItem (org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem)6 List (java.util.List)5 ISelection (org.eclipse.jface.viewers.ISelection)5 IService (com.openshift.restclient.model.IService)4 IRoute (com.openshift.restclient.model.route.IRoute)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 OpenShiftException (com.openshift.restclient.OpenShiftException)3 IBuildConfig (com.openshift.restclient.model.IBuildConfig)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3