Skip to content

Commit

Permalink
clean up illegal argument statements, parameterize tests
Browse files Browse the repository at this point in the history
Signed-off-by: Kat Shen <[email protected]>
  • Loading branch information
shenkw1 committed Aug 7, 2023
1 parent fa8d2f2 commit b2c772c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ private void validateKeySets(final Set<String> includeSet, final Set<String> exc

includeIntersectionSet.retainAll(excludeSet);
if (!includeIntersectionSet.isEmpty()) {
throw new IllegalArgumentException("Include keys and exclude keys set cannot have any overlap", null);
throw new IllegalArgumentException("Include keys and exclude keys set cannot have any overlap");
}

defaultIntersectionSet.retainAll(excludeSet);
if (!defaultIntersectionSet.isEmpty()) {
throw new IllegalArgumentException("Cannot exclude a default key!", null);
throw new IllegalArgumentException("Cannot exclude a default key!");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

Expand Down Expand Up @@ -317,7 +319,7 @@ void testIncludeExcludeKeysOverlapKeyValueProcessor() {
}

@Test
void testDefaultKeysKeyValueProcessor() {
void testDefaultKeysNoOverlapsBetweenEventKvProcessor() {
final Map<String, Object> defaultMap = Map.of("dKey", "dValue");
when(mockConfig.getDefaultValues()).thenReturn(defaultMap);
keyValueProcessor = new KeyValueProcessor(pluginMetrics, mockConfig);
Expand All @@ -331,10 +333,12 @@ void testDefaultKeysKeyValueProcessor() {
assertThatKeyEquals(parsed_message, "dKey", "dValue");
}

@Test
void testDefaultKeysAlreadyInMessageKeyValueProcessor() {
@ParameterizedTest
@ValueSource(booleans = {true, false})
void testDefaultKeysAlreadyInMessageKvProcessor(boolean skipDuplicateValues) {
final Map<String, Object> defaultMap = Map.of("dKey", "dValue");
when(mockConfig.getDefaultValues()).thenReturn(defaultMap);
when(mockConfig.getSkipDuplicateValues()).thenReturn(skipDuplicateValues);
keyValueProcessor = new KeyValueProcessor(pluginMetrics, mockConfig);

final Record<Event> record = getMessage("key1=value1&dKey=abc");
Expand All @@ -346,12 +350,14 @@ void testDefaultKeysAlreadyInMessageKeyValueProcessor() {
assertThatKeyEquals(parsed_message, "dKey", "abc");
}

@Test
void testDefaultIncludeKeysOverlapKeyValueProcessor() {
@ParameterizedTest
@ValueSource(booleans = {true, false})
void testDefaultIncludeKeysOverlapKvProcessor(boolean skipDuplicateValues) {
final Map<String, Object> defaultMap = Map.of("key1", "abc");
final List<String> includeKeys = List.of("key1");
when(mockConfig.getDefaultValues()).thenReturn(defaultMap);
when(mockConfig.getIncludeKeys()).thenReturn(includeKeys);
when(mockConfig.getSkipDuplicateValues()).thenReturn(skipDuplicateValues);
keyValueProcessor = new KeyValueProcessor(pluginMetrics, mockConfig);

final Record<Event> record = getMessage("key1=value1&key2=value2");
Expand All @@ -362,12 +368,14 @@ void testDefaultIncludeKeysOverlapKeyValueProcessor() {
assertThatKeyEquals(parsed_message, "key1", "value1");
}

@Test
void testDefaultPrioritizeIncludeKeysKeyValueProcessor() {
@ParameterizedTest
@ValueSource(booleans = {true, false})
void testDefaultPrioritizeIncludeKeysKvProcessor(boolean skipDuplicateValues) {
final Map<String, Object> defaultMap = Map.of("key2", "value2");
final List<String> includeKeys = List.of("key1");
when(mockConfig.getDefaultValues()).thenReturn(defaultMap);
when(mockConfig.getIncludeKeys()).thenReturn(includeKeys);
when(mockConfig.getSkipDuplicateValues()).thenReturn(skipDuplicateValues);
keyValueProcessor = new KeyValueProcessor(pluginMetrics, mockConfig);

final Record<Event> record = getMessage("key1=value1&key2=abc");
Expand All @@ -379,12 +387,14 @@ void testDefaultPrioritizeIncludeKeysKeyValueProcessor() {
assertThatKeyEquals(parsed_message, "key2", "value2");
}

@Test
void testIncludeKeysNotInRecordMessageKeyValueProcessor() {
@ParameterizedTest
@ValueSource(booleans = {true, false})
void testIncludeKeysNotInRecordMessageKvProcessor(boolean skipDuplicateValues) {
final Map<String, Object> defaultMap = Map.of("key2", "value2");
final List<String> includeKeys = List.of("key1");
when(mockConfig.getDefaultValues()).thenReturn(defaultMap);
when(mockConfig.getIncludeKeys()).thenReturn(includeKeys);
when(mockConfig.getSkipDuplicateValues()).thenReturn(skipDuplicateValues);
keyValueProcessor = new KeyValueProcessor(pluginMetrics, mockConfig);

final Record<Event> record = getMessage("key2=abc");
Expand Down Expand Up @@ -534,10 +544,10 @@ void testCapitalizeTransformKvProcessor() {

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);
final LinkedHashMap<String, Object> parsedMessage = getLinkedHashMap(editedRecords);

assertThat(parsed_message.size(), equalTo(1));
assertThatKeyEquals(parsed_message, "KEY1", "value1");
assertThat(parsedMessage.size(), equalTo(1));
assertThatKeyEquals(parsedMessage, "KEY1", "value1");
}

@Test
Expand Down

0 comments on commit b2c772c

Please sign in to comment.