@Test
  public void supportedWhenAnnotationHasTemplateKey() {
    when(resource.isAnnotatedWith("template")).thenReturn(true);
    when(resource.getAnnotation("template")).thenReturn("aTemplateName");

    assertTrue(
        "Exp. the capability to be supported because it has the template annotation",
        capability.isSupported());
    assertEquals("Exp. to get the template name", "aTemplateName", capability.getTemplateName());
  }
 @Override
 public String getText(Object arg) {
   if (arg instanceof IResource) {
     IResource resource = (IResource) arg;
     if (isFailedStatus(resource)) {
       return org.apache.commons.lang.StringUtils.capitalize(((IStatus) resource).getMessage());
     }
     return NLS.bind("{0} - {1}", resource.getKind(), resource.getName());
   }
   return arg.toString();
 }
 private IStatus handleResponse(Collection<IResource> resources) {
   int severity = IStatus.OK;
   for (IResource resource : resources) {
     if (resource.getKind() == ResourceKind.STATUS) {
       severity = IStatus.WARNING;
       break;
     }
   }
   return new Status(
       severity, OpenShiftUIActivator.PLUGIN_ID, OK, "Resources created from template.", null);
 }
 @Override
 public StyledString getStyledText(Object arg) {
   if (arg instanceof IResource) {
     IResource resource = (IResource) arg;
     StyledString text = new StyledString();
     if (isFailedStatus(resource)) {
       text.append(((IStatus) resource).getMessage());
     } else {
       text.append(StringUtils.humanize(resource.getKind().toString()));
       text.append(resource.getName(), StyledString.QUALIFIER_STYLER);
     }
     return text;
   }
   return null;
 }
Ejemplo n.º 5
0
 @Override
 public void received(IResource resource, ChangeType change) {
   Trace.debug("Watch received change in {0} state\n{1}", state, resource.toJson(false));
   if (State.CONNECTED == state.get()) {
     IResource newItem = null;
     IResource oldItem = null;
     int index = resources.indexOf(resource);
     if (ChangeType.ADDED.equals(change)) {
       resources.add(resource);
       newItem = resource;
     } else if (ChangeType.DELETED.equals(change)) {
       oldItem = index > NOT_FOUND ? resources.remove(index) : resource;
     } else if (ChangeType.MODIFIED.equals(change)) {
       if (index > NOT_FOUND) {
         oldItem = resources.remove(index);
       }
       resources.add(resource);
       newItem = resource;
     }
     ConnectionsRegistrySingleton.getInstance()
         .fireConnectionChanged(conn, ConnectionProperties.PROPERTY_RESOURCE, oldItem, newItem);
   }
 }
 private boolean isFailedStatus(IResource resource) {
   return ResourceKind.STATUS.equals(resource.getKind()) && ((IStatus) resource).isFailure();
 }
 @Before
 public void setUp() {
   capability = new TemplateTraceability(resource);
   when(resource.getNamespace()).thenReturn("mynamespace");
   when(resource.getKind()).thenReturn(ResourceKind.TEMPLATE);
 }