Search in sources :

Example 96 with IResource

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

the class RefreshTest method testRefreshConnection.

@Test
public void testRefreshConnection() throws InterruptedException, TimeoutException {
    IProject project1 = stubProject("test1", 1);
    IProject project2 = stubProject("test2", 1);
    IProject project2prime = stubProject("test2", 2);
    when(getConnectionMock().getResources(ResourceKind.PROJECT)).thenReturn(Collections.singletonList(project1));
    IConnectionWrapper connection = getConnection();
    getConnection().load(IExceptionHandler.NULL_HANDLER);
    UITestUtils.waitForState(connection, LoadingState.LOADED);
    assertEquals(1, connection.getResources().size());
    assertTrue(connection.getResources().stream().anyMatch(projectWrapper -> project1.equals(projectWrapper.getWrapped())));
    registry.fireConnectionChanged(getConnectionMock(), ConnectionProperties.PROPERTY_PROJECTS, null, Arrays.asList(project1, project2));
    verify(listener).elementChanged(connection);
    assertEquals(2, connection.getResources().size());
    assertTrue(connection.getResources().stream().anyMatch(projectWrapper -> project1.equals(projectWrapper.getWrapped())));
    assertTrue(connection.getResources().stream().anyMatch(projectWrapper -> project2.equals(projectWrapper.getWrapped())));
    registry.fireConnectionChanged(getConnectionMock(), ConnectionProperties.PROPERTY_PROJECTS, null, Arrays.asList(project2));
    verify(listener, times(2)).elementChanged(connection);
    assertEquals(1, connection.getResources().size());
    Optional<IResourceWrapper<?, ?>> project2Wrapper = connection.getResources().stream().filter(projectWrapper -> project2.equals(projectWrapper.getWrapped())).findFirst();
    assertTrue(project2Wrapper.isPresent());
    registry.fireConnectionChanged(getConnectionMock(), ConnectionProperties.PROPERTY_PROJECTS, null, Arrays.asList(project2prime));
    verify(listener, times(2)).elementChanged(connection);
    verify(listener).elementChanged(project2Wrapper.get());
    assertEquals(1, connection.getResources().size());
    assertTrue(connection.getResources().stream().anyMatch(projectWrapper -> {
        IResource resource = projectWrapper.getWrapped();
        String version = resource.getResourceVersion();
        return project2.equals(resource) && version.equals("2");
    }));
}
Also used : Arrays(java.util.Arrays) Proxy(java.lang.reflect.Proxy) TimeoutException(java.util.concurrent.TimeoutException) IConnectionWrapper(org.jboss.tools.openshift.internal.ui.models.IConnectionWrapper) IProject(com.openshift.restclient.model.IProject) IResourceWrapper(org.jboss.tools.openshift.internal.ui.models.IResourceWrapper) UITestUtils(org.jboss.tools.openshift.test.util.UITestUtils) ConnectionsRegistry(org.jboss.tools.openshift.common.core.connection.ConnectionsRegistry) Before(org.junit.Before) LoadingState(org.jboss.tools.openshift.internal.ui.models.LoadingState) IResource(com.openshift.restclient.model.IResource) ResourceKind(com.openshift.restclient.ResourceKind) ConnectionProperties(org.jboss.tools.openshift.core.connection.ConnectionProperties) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) OpenshiftUIModel(org.jboss.tools.openshift.internal.ui.models.OpenshiftUIModel) IExceptionHandler(org.jboss.tools.openshift.internal.ui.models.IExceptionHandler) Mockito.verify(org.mockito.Mockito.verify) IOpenShiftConnection(org.jboss.tools.openshift.core.connection.IOpenShiftConnection) Optional(java.util.Optional) IElementListener(org.jboss.tools.openshift.internal.ui.models.IElementListener) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) IResourceWrapper(org.jboss.tools.openshift.internal.ui.models.IResourceWrapper) IConnectionWrapper(org.jboss.tools.openshift.internal.ui.models.IConnectionWrapper) IProject(com.openshift.restclient.model.IProject) IResource(com.openshift.restclient.model.IResource) Test(org.junit.Test)

Example 97 with IResource

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

the class DeployImageJobTest method givenAnImageStreamTo.

private IImageStream givenAnImageStreamTo(String namespace, DockerImageURI uri) {
    IImageStream is = mock(IImageStream.class);
    when(is.getNamespaceName()).thenReturn(namespace);
    when(is.getName()).thenReturn(IMAGE_STREAM_NAME);
    when(is.getDockerImageRepository()).thenReturn(uri);
    List<IResource> streams = Arrays.asList(is);
    Connection conn = mock(Connection.class);
    when(conn.getResources(anyString(), eq(namespace))).thenReturn(streams);
    when(conn.getClusterNamespace()).thenReturn(ICommonAttributes.COMMON_NAMESPACE);
    when(parameters.getConnection()).thenReturn(conn);
    return is;
}
Also used : ResourceMocks.createConnection(org.jboss.tools.openshift.test.util.ResourceMocks.createConnection) Connection(org.jboss.tools.openshift.core.connection.Connection) IImageStream(com.openshift.restclient.model.IImageStream) IResource(com.openshift.restclient.model.IResource)

Example 98 with IResource

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

the class EditResourceHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    ISelection currentSelection = UIUtils.getCurrentSelection(event);
    IResource resource = UIUtils.getFirstElement(currentSelection, IResource.class);
    Connection connection = null;
    Shell shell = HandlerUtil.getActiveShell(event);
    if (resource == null) {
        MessageDialog.openWarning(shell, "Nothing to edit", "This is not the resource you are looking for.");
        return null;
    }
    connection = ConnectionsRegistryUtil.safeGetConnectionFor(resource);
    if (connection != null) {
        IWorkbenchWindow win = HandlerUtil.getActiveWorkbenchWindow(event);
        try {
            openInEditor(win, connection, resource);
        } catch (PartInitException e) {
            String msg = NLS.bind("Error opening {0} : \"{1}\" in editor: {2}", new String[] { resource.getKind(), resource.getName(), e.getMessage() });
            OpenShiftUIActivator.getDefault().getLogger().logError(msg, e);
        }
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) Shell(org.eclipse.swt.widgets.Shell) ISelection(org.eclipse.jface.viewers.ISelection) Connection(org.jboss.tools.openshift.core.connection.Connection) PartInitException(org.eclipse.ui.PartInitException) IResource(com.openshift.restclient.model.IResource)

Example 99 with IResource

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

the class ManageProjectsHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    Connection connection = UIUtils.getFirstElement(selection, Connection.class);
    if (connection == null) {
        IResource resource = UIUtils.getFirstElement(selection, IResource.class);
        if (resource != null) {
            connection = ConnectionsRegistryUtil.getConnectionFor(resource);
        }
    }
    if (connection == null) {
        return OpenShiftUIActivator.statusFactory().cancelStatus("No connection selected that we can manage projects for.");
    }
    new OkButtonWizardDialog(HandlerUtil.getActiveShell(event), new ManageProjectsWizard(connection)).open();
    return null;
}
Also used : OkButtonWizardDialog(org.jboss.tools.openshift.common.ui.wizard.OkButtonWizardDialog) ISelection(org.eclipse.jface.viewers.ISelection) Connection(org.jboss.tools.openshift.core.connection.Connection) ManageProjectsWizard(org.jboss.tools.openshift.internal.ui.wizard.project.ManageProjectsWizard) IResource(com.openshift.restclient.model.IResource)

Example 100 with IResource

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

the class ScaleDeploymentHandler method getDeploymentConfig.

private IDeploymentConfig getDeploymentConfig(IResourceWrapper<?, ?> wrapper) {
    if (wrapper == null) {
        return null;
    }
    IDeploymentConfig dc = null;
    IResource wrapped = wrapper.getWrapped();
    if (wrapper instanceof IServiceWrapper) {
        // service selected
        dc = getDeploymentConfig((IServiceWrapper) wrapper);
    } else if (wrapped instanceof IPod) {
        // pod selected
        dc = getDeploymentConfig((IPod) wrapped, wrapper);
    } else if (wrapped instanceof IDeploymentConfig) {
        // deployment config selected
        // has to be tested before IReplicationController, IDeploymentConfig extends IReplicationController
        dc = (IDeploymentConfig) wrapped;
    } else if (wrapped instanceof IReplicationController) {
        // replication controller selected (deployment tab in properties)
        // has to be tested after IDeploymentConfig, IDeploymentConfig extends IReplicationController
        dc = getDeploymentConfig((IReplicationController) wrapped, wrapper);
    }
    return dc;
}
Also used : IServiceWrapper(org.jboss.tools.openshift.internal.ui.models.IServiceWrapper) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IResource(com.openshift.restclient.model.IResource) IPod(com.openshift.restclient.model.IPod) IReplicationController(com.openshift.restclient.model.IReplicationController)

Aggregations

IResource (com.openshift.restclient.model.IResource)101 Test (org.junit.Test)32 Connection (org.jboss.tools.openshift.core.connection.Connection)27 IProject (com.openshift.restclient.model.IProject)14 IStatus (org.eclipse.core.runtime.IStatus)12 Collection (java.util.Collection)10 ServerResourceViewModel (org.jboss.tools.openshift.internal.ui.server.ServerResourceViewModel)9 IReplicationController (com.openshift.restclient.model.IReplicationController)8 IService (com.openshift.restclient.model.IService)8 ArrayList (java.util.ArrayList)8 CoreException (org.eclipse.core.runtime.CoreException)8 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)7 Status (org.eclipse.core.runtime.Status)7 ISelection (org.eclipse.jface.viewers.ISelection)7 OpenShiftException (com.openshift.restclient.OpenShiftException)6 ResourceKind (com.openshift.restclient.ResourceKind)6 IPod (com.openshift.restclient.model.IPod)6 List (java.util.List)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 IBuildConfig (com.openshift.restclient.model.IBuildConfig)5