Search in sources :

Example 6 with KeyValueFilter

use of org.jboss.tools.openshift.internal.common.core.util.KeyValueFilterFactory.KeyValueFilter in project jbosstools-openshift by jbosstools.

the class ResourceUtilsIsMatchingLabelsTest method filterWithoutKeyNorValueExpressionShouldBeEmpty.

@Test
public void filterWithoutKeyNorValueExpressionShouldBeEmpty() {
    // given
    KeyValueFilter filter = new KeyValueFilter();
    // when
    boolean empty = filter.isEmpty();
    // then
    assertThat(empty).isTrue();
}
Also used : KeyValueFilter(org.jboss.tools.openshift.internal.common.core.util.KeyValueFilterFactory.KeyValueFilter) Test(org.junit.Test)

Example 7 with KeyValueFilter

use of org.jboss.tools.openshift.internal.common.core.util.KeyValueFilterFactory.KeyValueFilter in project jbosstools-openshift by jbosstools.

the class ResourceUtilsIsMatchingLabelsTest method emptyLabelResourceHasMatchingLabelsIfFilterIsEmptyNull.

@Test
public void emptyLabelResourceHasMatchingLabelsIfFilterIsEmptyNull() {
    // given
    IService service = ResourceMocks.createResource(IService.class, ResourceKind.SERVICE, resource -> {
        doReturn(new HashMap<String, String>()).when(resource).getLabels();
    });
    assertThat(hasMatchingLabels(new KeyValueFilter(), service)).isTrue();
}
Also used : KeyValueFilter(org.jboss.tools.openshift.internal.common.core.util.KeyValueFilterFactory.KeyValueFilter) IService(com.openshift.restclient.model.IService) Test(org.junit.Test)

Example 8 with KeyValueFilter

use of org.jboss.tools.openshift.internal.common.core.util.KeyValueFilterFactory.KeyValueFilter in project jbosstools-openshift by jbosstools.

the class KeyValueFilterFactoryTest method shouldReportMatchRangesForKeyAndValue.

@Test
public void shouldReportMatchRangesForKeyAndValue() {
    // given
    String keyExpr = "smurfs";
    String keyText = "all the smurfs";
    int keyMatchStart = keyText.indexOf(keyExpr);
    int keyMatchLength = keyExpr.length();
    String valueExpr = "blue";
    String valueText = "very much blue in the face";
    int valueMatchStart = valueText.indexOf(valueExpr);
    int valueMatchLength = valueExpr.length();
    // when
    List<KeyValueFilter> filters = KeyValueFilterFactory.create(keyExpr + "=" + valueExpr);
    // then
    assertThat(filters).isNotEmpty();
    KeyValueFilter filter = filters.get(0);
    Range keyRange = filter.getMatchingRangeForKey(keyText);
    assertThat(keyRange).isNotNull();
    assertThat(keyRange.start).isEqualTo(keyMatchStart);
    assertThat(keyRange.length).isEqualTo(keyMatchLength);
    Range valueRange = filter.getMatchingRangeForValue(valueText);
    assertThat(valueRange).isNotNull();
    assertThat(valueRange.start).isEqualTo(valueMatchStart);
    assertThat(valueRange.length).isEqualTo(valueMatchLength);
}
Also used : KeyValueFilter(org.jboss.tools.openshift.internal.common.core.util.KeyValueFilterFactory.KeyValueFilter) Range(org.jboss.tools.openshift.internal.common.core.util.KeyValueFilterFactory.KeyValueFilter.Range) Test(org.junit.Test)

Example 9 with KeyValueFilter

use of org.jboss.tools.openshift.internal.common.core.util.KeyValueFilterFactory.KeyValueFilter in project jbosstools-openshift by jbosstools.

the class KeyValueFilterFactoryTest method shouldAcceptKeyAndValueWithSpaces.

@Test
public void shouldAcceptKeyAndValueWithSpaces() {
    // given
    // when
    List<KeyValueFilter> filters = KeyValueFilterFactory.create("fo o= bar tender");
    // then
    assertThat(filters).isNotEmpty();
    KeyValueFilter filter = filters.get(0);
    assertThat(filter.matchesKey("fo o")).isTrue();
    assertThat(filter.matchesValue("bar tender")).isTrue();
}
Also used : KeyValueFilter(org.jboss.tools.openshift.internal.common.core.util.KeyValueFilterFactory.KeyValueFilter) Test(org.junit.Test)

Example 10 with KeyValueFilter

use of org.jboss.tools.openshift.internal.common.core.util.KeyValueFilterFactory.KeyValueFilter in project jbosstools-openshift by jbosstools.

the class KeyValueFilterFactoryTest method shouldReportMatchRangesForValue.

@Test
public void shouldReportMatchRangesForValue() {
    // given
    String filterExpr = "blue";
    String filteredText = "very much blue in the face";
    int matchStart = filteredText.indexOf(filterExpr);
    int matchLength = filterExpr.length();
    // when
    List<KeyValueFilter> filters = KeyValueFilterFactory.create("smurfs=" + filterExpr);
    // then
    assertThat(filters).isNotEmpty();
    KeyValueFilter filter = filters.get(0);
    Range range = filter.getMatchingRangeForValue(filteredText);
    assertThat(range).isNotNull();
    assertThat(range.start).isEqualTo(matchStart);
    assertThat(range.length).isEqualTo(matchLength);
}
Also used : KeyValueFilter(org.jboss.tools.openshift.internal.common.core.util.KeyValueFilterFactory.KeyValueFilter) Range(org.jboss.tools.openshift.internal.common.core.util.KeyValueFilterFactory.KeyValueFilter.Range) Test(org.junit.Test)

Aggregations

KeyValueFilter (org.jboss.tools.openshift.internal.common.core.util.KeyValueFilterFactory.KeyValueFilter)10 Test (org.junit.Test)10 Range (org.jboss.tools.openshift.internal.common.core.util.KeyValueFilterFactory.KeyValueFilter.Range)4 IService (com.openshift.restclient.model.IService)1