Skip to content

Commit

Permalink
Fix bug where exception is thrown when csv source key does not exist …
Browse files Browse the repository at this point in the history
…or is null

Signed-off-by: Taylor Gray <[email protected]>
  • Loading branch information
graytaylor0 committed Jul 23, 2023
1 parent b003b08 commit 5a0c362
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
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

0 comments on commit 5a0c362

Please sign in to comment.