Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where exception is thrown when csv source key does not exist … #3053

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public Collection<Record<Event>> doExecute(final Collection<Record<Event>> recor
final Event event = record.getData();

final String message = event.get(config.getSource(), String.class);

if (Objects.isNull(message)) {
continue;
}

final boolean userDidSpecifyHeaderEventKey = Objects.nonNull(config.getColumnNamesSourceKey());
final boolean thisEventHasHeaderSource = userDidSpecifyHeaderEventKey && event.containsKey(config.getColumnNamesSourceKey());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -59,6 +60,18 @@ private CsvProcessor createObjectUnderTest() {
return new CsvProcessor(pluginMetrics, processorConfig);
}

@Test
void do_nothing_when_source_is_null_value_or_does_not_exist_in_the_Event() {
final Record<Event> eventUnderTest = createMessageEvent("");
when(processorConfig.getSource()).thenReturn(UUID.randomUUID().toString());


final List<Record<Event>> editedEvents = (List<Record<Event>>) csvProcessor.doExecute(Collections.singletonList(eventUnderTest));
final Event parsedEvent = getSingleEvent(editedEvents);

assertThat(parsedEvent, equalTo(eventUnderTest.getData()));
}

@Test
void test_when_messageIsEmpty_then_notParsed() {
final Record<Event> eventUnderTest = createMessageEvent("");
Expand Down
Loading