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");
}));
}
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;
}
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;
}
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;
}
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;
}
Aggregations