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