Search in sources :

Example 1 with KeyValueFilter

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

the class KeyValueFilterFactoryTest method shouldCreateFilterThatMatchesSubstrings.

@Test
public void shouldCreateFilterThatMatchesSubstrings() {
    // given
    // when
    List<KeyValueFilter> filters = KeyValueFilterFactory.create("smurfs=blue");
    // then
    assertThat(filters).isNotEmpty();
    KeyValueFilter filter = filters.get(0);
    assertThat(filter.matchesKey("all the smurfs")).isTrue();
    assertThat(filter.matchesValue("are very much blue")).isTrue();
}
Also used : KeyValueFilter(org.jboss.tools.openshift.internal.common.core.util.KeyValueFilterFactory.KeyValueFilter) Test(org.junit.Test)

Example 2 with KeyValueFilter

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

the class KeyValueFilterFactoryTest method shouldIgnoreSpaceAfterColon.

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

Example 3 with KeyValueFilter

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

the class KeyValueFilterFactoryTest method shouldReportEmptyRangeForKeyIfFilteringOnValueOnly.

@Test
public void shouldReportEmptyRangeForKeyIfFilteringOnValueOnly() {
    // given
    // when
    List<KeyValueFilter> filters = KeyValueFilterFactory.create("blue");
    // then
    assertThat(filters).isNotEmpty();
    KeyValueFilter filter = filters.get(0);
    Range range = filter.getMatchingRangeForKey("smurfs=blue");
    assertThat(range).isNull();
}
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 4 with KeyValueFilter

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

the class KeyValueFilterFactoryTest method shouldCreateValueOnlyFilterIfExpressionhasNoEquals.

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

Example 5 with KeyValueFilter

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

the class KeyValueFilterFactoryTest method shouldReportMatchRangesForKey.

@Test
public void shouldReportMatchRangesForKey() {
    // given
    String filterExpr = "smurfs";
    String filteredText = "all the smurfs";
    int matchStart = filteredText.indexOf(filterExpr);
    int matchLength = filterExpr.length();
    // when
    List<KeyValueFilter> filters = KeyValueFilterFactory.create(filterExpr + "=anyvallue");
    // then
    assertThat(filters).isNotEmpty();
    KeyValueFilter filter = filters.get(0);
    Range range = filter.getMatchingRangeForKey(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