Search in sources :

Example 6 with ResourceProperty

use of org.jboss.tools.openshift.internal.ui.wizard.newapp.ResourceDetailsContentProvider.ResourceProperty in project jbosstools-openshift by jbosstools.

the class ResourceDetailsLabelProviderTest method getStyledTextWithUnkownParameterInMap.

@Test
public void getStyledTextWithUnkownParameterInMap() {
    ResourceProperty resourceProperty = mock(ResourceProperty.class);
    when(resourceProperty.getProperty()).thenReturn("Prop");
    Map<String, String> params = new TreeMap<>();
    params.put("${name}", "is name");
    params.put("surname", "${surname}");
    params.put("gender", "${gender}");
    when(resourceProperty.getValue()).thenReturn(params);
    assertEquals("Prop: Dmitrii=is name,gender=(Unknown parameter gender),surname=Bocharov", labelsProvider.getStyledText(resourceProperty).toString());
}
Also used : ResourceProperty(org.jboss.tools.openshift.internal.ui.wizard.newapp.ResourceDetailsContentProvider.ResourceProperty) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 7 with ResourceProperty

use of org.jboss.tools.openshift.internal.ui.wizard.newapp.ResourceDetailsContentProvider.ResourceProperty in project jbosstools-openshift by jbosstools.

the class ResourceDetailsContentProviderTest method shouldReturnUnknownResourcePropertyGivenBuildConfigBuildStrategyIsNull.

@Test
public void shouldReturnUnknownResourcePropertyGivenBuildConfigBuildStrategyIsNull() {
    // given
    IBuildConfig bc = ResourceMocks.createBuildConfig("42", null, null, null, null, null, null, null);
    // when
    Object[] children = contentProvider.getChildren(bc);
    // then
    ResourceProperty property = getResourceProperty(ResourceDetailsContentProvider.LABEL_STRATEGY, children);
    assertThat(property).isNotNull();
    assertThat(property.isUnknownValue()).isTrue();
}
Also used : ResourceProperty(org.jboss.tools.openshift.internal.ui.wizard.newapp.ResourceDetailsContentProvider.ResourceProperty) IBuildConfig(com.openshift.restclient.model.IBuildConfig) Test(org.junit.Test)

Example 8 with ResourceProperty

use of org.jboss.tools.openshift.internal.ui.wizard.newapp.ResourceDetailsContentProvider.ResourceProperty in project jbosstools-openshift by jbosstools.

the class ResourceDetailsLabelProvider method getStyledText.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public StyledString getStyledText(Object element) {
    if (element instanceof IResource) {
        IResource resource = (IResource) element;
        StyledString text = new StyledString(StringUtils.capitalize(resource.getKind()));
        text.append(" ").append(replaceParameters(resource.getName()), StyledString.QUALIFIER_STYLER);
        return text;
    }
    if (element instanceof ResourceProperty) {
        ResourceProperty property = (ResourceProperty) element;
        StyledString text = new StyledString(StringUtils.capitalize(property.getProperty()));
        text.append(": ");
        String value = null;
        if (property.getValue() instanceof Map) {
            value = org.jboss.tools.openshift.common.core.utils.StringUtils.serialize((Map) property.getValue());
        } else if (property.getValue() instanceof Collection) {
            value = StringUtils.join((Collection) property.getValue(), ", ");
        } else {
            value = property.getValue() != null ? property.getValue().toString() : "";
        }
        if (StringUtils.isBlank(value)) {
            if (property.isUnknownValue()) {
                value = LABEL_UNKNOWN;
            } else {
                value = LABEL_NOT_PROVIDED;
            }
        }
        text.append(replaceParameters(value), StyledString.QUALIFIER_STYLER);
        return text;
    }
    return null;
}
Also used : ResourceProperty(org.jboss.tools.openshift.internal.ui.wizard.newapp.ResourceDetailsContentProvider.ResourceProperty) Collection(java.util.Collection) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) Map(java.util.Map) IResource(com.openshift.restclient.model.IResource)

Example 9 with ResourceProperty

use of org.jboss.tools.openshift.internal.ui.wizard.newapp.ResourceDetailsContentProvider.ResourceProperty in project jbosstools-openshift by jbosstools.

the class ResourceDetailsLabelProviderTest method getStyledTextWithUnknownLabel.

@Test
public void getStyledTextWithUnknownLabel() {
    ResourceProperty resourceProperty = mock(ResourceProperty.class);
    when(resourceProperty.getProperty()).thenReturn("prop1");
    when(resourceProperty.isUnknownValue()).thenReturn(true);
    when(resourceProperty.getValue()).thenReturn("");
    assertEquals("Prop1: (Unknown)", labelsProvider.getStyledText(resourceProperty).toString());
}
Also used : ResourceProperty(org.jboss.tools.openshift.internal.ui.wizard.newapp.ResourceDetailsContentProvider.ResourceProperty) Test(org.junit.Test)

Aggregations

ResourceProperty (org.jboss.tools.openshift.internal.ui.wizard.newapp.ResourceDetailsContentProvider.ResourceProperty)9 Test (org.junit.Test)8 IBuildConfig (com.openshift.restclient.model.IBuildConfig)2 IResource (com.openshift.restclient.model.IResource)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 StyledString (org.eclipse.jface.viewers.StyledString)1