if (onBaseComponents != null) {
filter.setOnBaseResourceChildren(Boolean.valueOf(onBaseComponents));
}
- filter.setResourceName((String) properties.get("nameSearch"));
+ filter.setResourceName(toString(properties.get("nameSearch")));
filter.setResourceKey((String) properties.get("keySearch"));
String onFavourites = (String) properties.get("onFavourites");
if (onFavourites != null) {
return null;
}
+ @CheckForNull
+ public static String toString(@Nullable Object o) {
+ if (o != null) {
+ if (o instanceof List) {
+ return Joiner.on(",").join((List) o);
+ } else if (o instanceof String[]) {
+ // assume that it contains only strings
+ return Joiner.on(",").join((String[]) o);
+ } else {
+ return o.toString();
+ }
+ }
+ return null;
+ }
+
}
import java.util.List;
import java.util.Map;
+import static com.google.common.collect.Lists.newArrayList;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
assertThat(conditions.get(0).period()).isNull();
}
+ @Test
+ public void name_conditions() {
+ MeasureFilterFactory factory = new MeasureFilterFactory(newMetricFinder(), system);
+ Map<String, Object> props = ImmutableMap.<String, Object>of(
+ "nameSearch", "SonarQube"
+ );
+ MeasureFilter filter = factory.create(props);
+
+ assertThat(filter.getResourceName()).isEqualTo("SonarQube");
+ }
+
+ @Test
+ public void not_fail_when_name_conditions_contains_array() {
+ MeasureFilterFactory factory = new MeasureFilterFactory(newMetricFinder(), system);
+ Map<String, Object> props = ImmutableMap.<String, Object>of(
+ "nameSearch", new String[]{"sonar", "qube"}
+ );
+ MeasureFilter filter = factory.create(props);
+
+ assertThat(filter.getResourceName()).isEqualTo("sonar,qube");
+ }
+
+ @Test
+ public void not_fail_when_name_conditions_contains_list() {
+ MeasureFilterFactory factory = new MeasureFilterFactory(newMetricFinder(), system);
+ Map<String, Object> props = ImmutableMap.<String, Object>of(
+ "nameSearch", newArrayList("sonar", "qube")
+ );
+ MeasureFilter filter = factory.create(props);
+
+ assertThat(filter.getResourceName()).isEqualTo("sonar,qube");
+ }
+
@Test
public void ignore_partial_measure_condition() {
MeasureFilterFactory factory = new MeasureFilterFactory(newMetricFinder(), system);
@criteria = self.data.split(CRITERIA_SEPARATOR).inject(HashWithIndifferentAccess.new) do |h, s|
k, v=s.split('=')
if k && v
- # Empty values are removed
- v=v.split(CRITERIA_KEY_VALUE_SEPARATOR).select{|v| !v.empty?} if v.include?(CRITERIA_KEY_VALUE_SEPARATOR)
+ # nameSearch can contains comma, in this case we should not split the value
+ if k != 'nameSearch'
+ # Empty values are removed
+ v=v.split(CRITERIA_KEY_VALUE_SEPARATOR).select{|v| !v.empty?} if v.include?(CRITERIA_KEY_VALUE_SEPARATOR)
+ end
h[k]=v
end
h