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