Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Kat Shen <[email protected]>
  • Loading branch information
shenkw1 committed Jul 4, 2023
1 parent e7918bd commit a89d64a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion data-prepper-plugins/key-value-processor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ When run, the processor will parse the message into the following output:
* Cannot be an empty string
* Example: `delete_value_regex` is `"\s"`. `{"key1=value1 "}` will parse into `{"key1": "value1"}`
* `transform_key` - Change keys to lowercase, uppercase, or all capitals.
* Default is an empty string
* Default is an empty string (no transformation)
* Example: `transform_key` is `lowercase`. `{"Key1=value1"}` will parse into `{"key1": "value1"}`
* Example: `transform_key` is `uppercase`. `{"key1=value1"}` will parse into `{"Key1": "value1"}`
* Example: `transform_key` is `capitalize`. `{"key1=value1"}` will parse into `{"KEY1": "value1"}`
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -36,7 +35,7 @@ public class KeyValueProcessor extends AbstractProcessor<Record<Event>, Record<E
private final Pattern fieldDelimiterPattern;
private final Pattern keyValueDelimiterPattern;
private final Set<String> includeKeysSet = new HashSet<String>();
private final Set<String> validTransformOptionSet = new HashSet<>(Arrays.asList("lowercase", "uppercase", "capitalize"));
private final Set<String> validTransformOptionSet = Set.of("", "lowercase", "uppercase", "capitalize");

@DataPrepperPluginConstructor
public KeyValueProcessor(final PluginMetrics pluginMetrics, final KeyValueProcessorConfig keyValueProcessorConfig) {
Expand Down Expand Up @@ -97,11 +96,8 @@ public KeyValueProcessor(final PluginMetrics pluginMetrics, final KeyValueProces
includeKeysSet.addAll(keyValueProcessorConfig.getIncludeKeys());
}

if(keyValueProcessorConfig.getTransformKey() != null
&& !keyValueProcessorConfig.getTransformKey().isEmpty()) {
if(!validTransformOptionSet.contains(keyValueProcessorConfig.getTransformKey())) {
throw new IllegalArgumentException("transform_key is not a valid option");
}
if(!validTransformOptionSet.contains(keyValueProcessorConfig.getTransformKey())) {
throw new IllegalArgumentException(String.format("The transform_key value: %s is not a valid option", keyValueProcessorConfig.getTransformKey()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ void testDeleteValueAndKeyRegexKvProcessor() {

@Test
void testLowercaseTransformKvProcessor() {
when(mockConfig.getTransformKey()).thenReturn("lowercase");

final Record<Event> record = getMessage("Key1=value1");
final List<Record<Event>> editedRecords = (List<Record<Event>>) keyValueProcessor.doExecute(Collections.singletonList(record));
final LinkedHashMap<String, Object> parsed_message = getLinkedHashMap(editedRecords);
Expand All @@ -384,6 +386,8 @@ void testLowercaseTransformKvProcessor() {

@Test
void testUppercaseTransformKvProcessor() {
when(mockConfig.getTransformKey()).thenReturn("uppercase");

final Record<Event> record = getMessage("key1=value1");
final List<Record<Event>> editedRecords = (List<Record<Event>>) keyValueProcessor.doExecute(Collections.singletonList(record));
final LinkedHashMap<String, Object> parsed_message = getLinkedHashMap(editedRecords);
Expand All @@ -394,6 +398,8 @@ void testUppercaseTransformKvProcessor() {

@Test
void testCapitalizeTransformKvProcessor() {
when(mockConfig.getTransformKey()).thenReturn("capitalize");

final Record<Event> record = getMessage("key1=value1");
final List<Record<Event>> editedRecords = (List<Record<Event>>) keyValueProcessor.doExecute(Collections.singletonList(record));
final LinkedHashMap<String, Object> parsed_message = getLinkedHashMap(editedRecords);
Expand Down

0 comments on commit a89d64a

Please sign in to comment.