From 7cb1ee6420557214bfe63ab626e800a13592ac7c Mon Sep 17 00:00:00 2001 From: Marius Brill <53812669+MariusBrill@users.noreply.github.com> Date: Thu, 3 Mar 2022 07:59:18 +0100 Subject: [PATCH] Closes #1319 - Add filter for inspectit.env path in autocompletion (#1339) * Add filter for inspectit.env path in autocompletion * Update tests --- .../autocompleterimpl/ModelAutoCompleter.java | 8 ++++--- .../ModelAutoCompleterTest.java | 21 ++++++++++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/ModelAutoCompleter.java b/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/ModelAutoCompleter.java index 56e17bce66..8bd3dbcdde 100644 --- a/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/ModelAutoCompleter.java +++ b/components/inspectit-ocelot-configurationserver/src/main/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/ModelAutoCompleter.java @@ -1,7 +1,5 @@ package rocks.inspectit.ocelot.autocomplete.autocompleterimpl; -import static rocks.inspectit.ocelot.autocomplete.autocompleterimpl.Constants.INSPECTIT; - import com.google.common.annotations.VisibleForTesting; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Component; @@ -18,6 +16,8 @@ import java.util.List; import java.util.stream.Collectors; +import static rocks.inspectit.ocelot.autocomplete.autocompleterimpl.Constants.INSPECTIT; + @Component public class ModelAutoCompleter implements AutoCompleter { @@ -41,7 +41,9 @@ public List getSuggestions(List path) { private List collectProperties(List propertyPath) { Type endType = PropertyPathHelper.getPathEndType(propertyPath, InspectitConfig.class); if (CollectionUtils.isEmpty(propertyPath) || ((propertyPath.size() == 1) && propertyPath.get(0).equals(""))) { - return getProperties(InspectitConfig.class); + return getProperties(InspectitConfig.class).stream() + //Filter out the path "inspectit.env" which may only be managed by the agent. + .filter(property -> !property.equals("env")).collect(Collectors.toList()); } if (endType instanceof Class && ((Class) endType).isEnum()) { return Arrays.stream(((Class) endType).getEnumConstants()) diff --git a/components/inspectit-ocelot-configurationserver/src/test/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/ModelAutoCompleterTest.java b/components/inspectit-ocelot-configurationserver/src/test/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/ModelAutoCompleterTest.java index 0c3eb59932..bedcfc19d0 100644 --- a/components/inspectit-ocelot-configurationserver/src/test/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/ModelAutoCompleterTest.java +++ b/components/inspectit-ocelot-configurationserver/src/test/java/rocks/inspectit/ocelot/autocomplete/autocompleterimpl/ModelAutoCompleterTest.java @@ -6,6 +6,7 @@ import rocks.inspectit.ocelot.config.model.InspectitConfig; import java.util.Arrays; +import java.util.Collections; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; @@ -46,7 +47,7 @@ void pastList() { List result = completer.getSuggestions(input); - assertThat(result).containsExactlyInAnyOrder("config", "env", "exporters", "instrumentation", "logging", "metrics", "plugins", "privacy", "publish-open-census-to-bootstrap", "self-monitoring", "service-name", "tags", "thread-pool-size", "tracing", "agent-commands"); + assertThat(result).containsExactlyInAnyOrder("config", "exporters", "instrumentation", "logging", "metrics", "plugins", "privacy", "publish-open-census-to-bootstrap", "self-monitoring", "service-name", "tags", "thread-pool-size", "tracing", "agent-commands"); } @Test @@ -124,6 +125,24 @@ void startsNotWithInspectit() { assertThat(result).isEmpty(); } + + @Test + void filtersInspectitEnvPath() { + List input = Collections.singletonList("inspectit"); + + List result = completer.getSuggestions(input); + + assertThat(result).doesNotContain("env"); + } + + @Test + void ignoresPastInspectitEnvPath() { + List input = Collections.singletonList("inspectit.env"); + + List result = completer.getSuggestions(input); + + assertThat(result).isEmpty(); + } } @Nested