Search in sources :

Example 26 with IResource

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

the class DeployImageJobTest method testStubDeploymentConfig.

@Test
public void testStubDeploymentConfig() {
    IImageStream is = givenAnImageStreamTo(project.getName(), DOCKER_TAG);
    IResource resource = job.stubDeploymentConfig(factory, RESOURCE_NAME, DOCKER_TAG, is);
    assertTrue(resource instanceof IDeploymentConfig);
    IDeploymentConfig dc = (IDeploymentConfig) resource;
    assertEquals("Exp. replicas to match incoming params", parameters.getReplicas(), dc.getReplicas());
    assertEquals("Exp. the selector key to be the resourceName", RESOURCE_NAME, dc.getReplicaSelector().get(DeployImageJob.SELECTOR_KEY));
    IContainer container = dc.getContainer(RESOURCE_NAME);
    assertNotNull("Exp. to find a container with the resource name", container);
    Collection<IDeploymentTrigger> triggers = dc.getTriggers();
    assertTrue("Exp. a config change trigger", triggers.stream().filter(t -> DeploymentTriggerType.CONFIG_CHANGE.equals(t.getType())).findFirst().isPresent());
    // assert ict matches container spec
    Optional<IDeploymentTrigger> icTrigger = triggers.stream().filter(t -> DeploymentTriggerType.IMAGE_CHANGE.equals(t.getType())).findFirst();
    assertTrue(icTrigger.isPresent());
    IDeploymentImageChangeTrigger imageChangeTrigger = (IDeploymentImageChangeTrigger) icTrigger.get();
    Collection<String> names = imageChangeTrigger.getContainerNames();
    assertEquals(1, names.size());
    assertEquals("Exp. the container and trigger names to match", container.getName(), names.iterator().next());
    assertTrue(imageChangeTrigger.isAutomatic());
    assertEquals(ResourceKind.IMAGE_STREAM_TAG, imageChangeTrigger.getKind());
    assertEquals("Exp. the trigger to point to the imagestream name", new DockerImageURI(null, null, is.getName(), DOCKER_TAG.getTag()), imageChangeTrigger.getFrom());
    assertEquals("Exp. the trigger to point to the imagestream name", is.getNamespaceName(), imageChangeTrigger.getNamespace());
}
Also used : Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger) IStatus(org.eclipse.core.runtime.IStatus) DeployImageJob(org.jboss.tools.openshift.internal.ui.job.DeployImageJob) IDeploymentTrigger(com.openshift.restclient.model.deploy.IDeploymentTrigger) Matchers.eq(org.mockito.Matchers.eq) IResourceVisitor(org.jboss.tools.openshift.test.util.ResourceMocks.IResourceVisitor) Mockito.doReturn(org.mockito.Mockito.doReturn) ResourceKind(com.openshift.restclient.ResourceKind) Collection(java.util.Collection) Status(org.eclipse.core.runtime.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) Matchers.any(org.mockito.Matchers.any) List(java.util.List) ICommonAttributes(org.jboss.tools.openshift.core.ICommonAttributes) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) ResourceMocks.createResource(org.jboss.tools.openshift.test.util.ResourceMocks.createResource) Mockito.mock(org.mockito.Mockito.mock) ResourceFactory(com.openshift.internal.restclient.ResourceFactory) Mock(org.mockito.Mock) IImageStream(com.openshift.restclient.model.IImageStream) RunWith(org.junit.runner.RunWith) Mockito.spy(org.mockito.Mockito.spy) Matchers.anyString(org.mockito.Matchers.anyString) IProject(com.openshift.restclient.model.IProject) ArrayList(java.util.ArrayList) ResourceMocks.createConnection(org.jboss.tools.openshift.test.util.ResourceMocks.createConnection) IResourceFactory(com.openshift.restclient.IResourceFactory) Before(org.junit.Before) DockerImageURI(com.openshift.restclient.images.DockerImageURI) IResource(com.openshift.restclient.model.IResource) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Connection(org.jboss.tools.openshift.core.connection.Connection) Mockito.verify(org.mockito.Mockito.verify) IDeployImageParameters(org.jboss.tools.openshift.internal.ui.wizard.deployimage.IDeployImageParameters) Assert.assertNull(org.junit.Assert.assertNull) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) IClient(com.openshift.restclient.IClient) DeploymentTriggerType(com.openshift.restclient.model.deploy.DeploymentTriggerType) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) IContainer(com.openshift.restclient.model.IContainer) DockerImageURI(com.openshift.restclient.images.DockerImageURI) IImageStream(com.openshift.restclient.model.IImageStream) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IDeploymentTrigger(com.openshift.restclient.model.deploy.IDeploymentTrigger) Matchers.anyString(org.mockito.Matchers.anyString) IContainer(com.openshift.restclient.model.IContainer) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger) IResource(com.openshift.restclient.model.IResource) Test(org.junit.Test)

Example 27 with IResource

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

the class CreateApplicationFromTemplateJobTest method shouldNotifyAndReturnWarningStatusWhenResourcesAlreadyExist.

/*
	 * Display failed resources and end wizard
	 */
@Test
public void shouldNotifyAndReturnWarningStatusWhenResourcesAlreadyExist() {
    IResource resource = mock(IResource.class);
    when(resource.getKind()).thenReturn(ResourceKind.IMAGE_STREAM);
    IResource status = mock(com.openshift.restclient.model.IStatus.class);
    when(status.getKind()).thenReturn(ResourceKind.STATUS);
    resources.add(resource);
    resources.add(status);
    when(capability.process(template)).thenReturn(template);
    when(capability.apply(template)).thenReturn(resources);
    IStatus result = job.runMe();
    assertEquals(IStatus.WARNING, result.getSeverity());
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IResource(com.openshift.restclient.model.IResource) Test(org.junit.Test)

Example 28 with IResource

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

the class CreateResourceJobTest method shouldReturnResourcesWhenAllResourcesCreatedWithoutErrors.

/*
	 * End wizard
	 */
@Test
public void shouldReturnResourcesWhenAllResourcesCreatedWithoutErrors() {
    IResource resource = mock(IResource.class);
    when(resource.getKind()).thenReturn(ResourceKind.IMAGE_STREAM);
    resources.add(resource);
    when(resourceFactory.create(input)).thenReturn(resource);
    when(client.create(resource, project.getNamespaceName())).thenReturn(resource);
    IStatus result = job.runMe();
    assertEquals(IStatus.OK, result.getSeverity());
    assertEquals(resources, job.getResource());
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IResource(com.openshift.restclient.model.IResource) Test(org.junit.Test)

Example 29 with IResource

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

the class ServerSettingsWizardPage method createRouteControls.

@SuppressWarnings("unchecked")
private void createRouteControls(Composite container, ServerSettingsWizardPageModel model, DataBindingContext dbc) {
    Group routeGroup = new Group(container, SWT.NONE);
    routeGroup.setText("Route");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(routeGroup);
    GridLayoutFactory.fillDefaults().applyTo(routeGroup);
    // additional nesting required because of
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=478618
    Composite routeContainer = new Composite(routeGroup, SWT.None);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(routeContainer);
    GridLayoutFactory.fillDefaults().margins(10, 10).numColumns(2).applyTo(routeContainer);
    Button promptRouteButton = new Button(routeContainer, SWT.CHECK);
    promptRouteButton.setSelection(true);
    promptRouteButton.setText("Prompt for route when multiple routes available to show in browser");
    GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).span(2, 1).applyTo(promptRouteButton);
    Label routeLabel = new Label(routeContainer, SWT.NONE);
    routeLabel.setText("Use Route: ");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(routeLabel);
    StructuredViewer routesViewer = new ComboViewer(routeContainer);
    GridDataFactory.fillDefaults().span(1, 1).align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(routesViewer.getControl());
    routesViewer.setContentProvider(new ObservableListContentProvider());
    routesViewer.setLabelProvider(new RouteLabelProvider());
    routesViewer.setInput(BeanProperties.list(ServerSettingsWizardPageModel.PROPERTY_ROUTES).observe(model));
    // routesViewer.setComparer(new IElementComparer() {
    // 
    // @Override
    // public boolean equals(Object object1, Object object2) {
    // if (object1 instanceof IRoute) {
    // if (!(object2 instanceof IRoute)) {
    // return false;
    // }
    // 
    // IRoute route1 = (IRoute) object1;
    // IRoute route2 = (IRoute) object2;
    // 
    // return Objects.equals(route1.getServiceName(), route2.getServiceName())
    // && Objects.equals(route1.getURL(), route2.getURL());
    // } else if (object2 instanceof IRoute) {
    // return false;
    // } else {
    // return Objects.equals(object1, object2);
    // }
    // }
    // 
    // @Override
    // public int hashCode(Object element) {
    // if (element instanceof IRoute) {
    // IRoute route = (IRoute) element;
    // return new HashCodeBuilder()
    // .append(route.getServiceName())
    // .append(route.getURL())
    // .toHashCode();
    // }
    // return element.hashCode();
    // }
    // });
    IObservableValue<IResource> selectedRouteObservable = ViewerProperties.singleSelection().observe(routesViewer);
    ValueBindingBuilder.bind(selectedRouteObservable).to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_ROUTE).observe(model)).in(dbc);
    final IObservableValue<Boolean> isSelectDefaultRouteObservable = WidgetProperties.selection().observe(promptRouteButton);
    final IObservableValue<Boolean> selectDefaultRouteModelObservable = BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_SELECT_DEFAULT_ROUTE).observe(model);
    ValueBindingBuilder.bind(isSelectDefaultRouteObservable).converting(new InvertingBooleanConverter()).to(selectDefaultRouteModelObservable).converting(new InvertingBooleanConverter()).in(dbc);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(routesViewer.getControl())).notUpdating(selectDefaultRouteModelObservable).in(dbc);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(routeLabel)).notUpdating(selectDefaultRouteModelObservable).in(dbc);
    RouteValidator routeValidator = new RouteValidator(isSelectDefaultRouteObservable, selectedRouteObservable);
    dbc.addValidationStatusProvider(routeValidator);
    ControlDecorationSupport.create(routeValidator, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
}
Also used : Group(org.eclipse.swt.widgets.Group) ObservableListContentProvider(org.eclipse.jface.databinding.viewers.ObservableListContentProvider) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) InvertingBooleanConverter(org.jboss.tools.common.ui.databinding.InvertingBooleanConverter) Label(org.eclipse.swt.widgets.Label) RouteLabelProvider(org.jboss.tools.openshift.internal.ui.dialog.SelectRouteDialog.RouteLabelProvider) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) Button(org.eclipse.swt.widgets.Button) ComboViewer(org.eclipse.jface.viewers.ComboViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) IResource(com.openshift.restclient.model.IResource)

Example 30 with IResource

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

the class ResourcesViewLabelProvider method update.

@Override
public void update(ViewerCell cell) {
    Object element = cell.getElement();
    if (!(element instanceof ObservableTreeItem)) {
        return;
    }
    if (!(((ObservableTreeItem) element).getModel() instanceof IResource)) {
        return;
    }
    IResource resource = (IResource) ((ObservableTreeItem) element).getModel();
    StyledString text = new StyledString();
    if (resource instanceof com.openshift.restclient.model.IProject) {
        createProjectLabel(text, (com.openshift.restclient.model.IProject) resource);
    } else if (resource instanceof IService) {
        createServiceLabel(text, (IService) resource);
    } else if (resource instanceof IReplicationController) {
        createReplicationControllerLabel(text, (IReplicationController) resource);
    }
    cell.setText(text.toString());
    cell.setStyleRanges(text.getStyleRanges());
    super.update(cell);
}
Also used : StyledString(org.eclipse.jface.viewers.StyledString) ObservableTreeItem(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem) IResource(com.openshift.restclient.model.IResource) IService(com.openshift.restclient.model.IService) 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