|
31 | 31 | import static org.hamcrest.CoreMatchers.equalTo; |
32 | 32 | import static org.hamcrest.CoreMatchers.is; |
33 | 33 | import static org.hamcrest.MatcherAssert.assertThat; |
| 34 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
34 | 35 | import static org.junit.jupiter.api.Assertions.assertThrows; |
35 | 36 | import static org.mockito.ArgumentMatchers.any; |
36 | 37 | import static org.mockito.ArgumentMatchers.eq; |
@@ -64,6 +65,39 @@ void invalid_add_when_throws_InvalidPluginConfigurationException() { |
64 | 65 | assertThrows(InvalidPluginConfigurationException.class, this::createObjectUnderTest); |
65 | 66 | } |
66 | 67 |
|
| 68 | + @Test |
| 69 | + public void test_add_empty_array_followed_by_list_of_map_to_the_same_key() { |
| 70 | + when(mockConfig.getEntries()).thenReturn(createListOfEntries( |
| 71 | + createEntry("actor/user/groups", null, new ArrayList<>(), null, null, false, false, null, null, true, null), |
| 72 | + createEntry("actor/user/groups", null, List.of(Map.of("name", "")), null, null, false, true, null, null, true, null))); |
| 73 | + |
| 74 | + final AddEntryProcessor processor = createObjectUnderTest(); |
| 75 | + final List<Map<String, Object>> mapList = List.of(Map.of("testKey", "testValue")); |
| 76 | + final Map<String, Object> data = Map.of("message", mapList); |
| 77 | + final Record<Event> record = getEvent(mapList); |
| 78 | + |
| 79 | + final List<Record<Event>> editedRecords = (List<Record<Event>>) processor.doExecute(Collections.singletonList(record)); |
| 80 | + assertEquals("{\"message\":[{\"testKey\":\"testValue\"}],\"actor\":{\"user\":{\"groups\":[[{\"name\":\"\"}]]}}}", |
| 81 | + editedRecords.get(0).getData().toJsonString()); |
| 82 | + } |
| 83 | + |
| 84 | + @Test |
| 85 | + public void test_add_list_of_map_followed_by_empty_array_to_the_same_key() { |
| 86 | + when(mockConfig.getEntries()).thenReturn(createListOfEntries( |
| 87 | + createEntry("actor/user/groups", null, List.of(Map.of("name", "")), null, null, false, true, null, null, true, null), |
| 88 | + createEntry("actor/user/groups", null, new ArrayList<>(), null, null, false, false, null, null, true, null), |
| 89 | + createEntry("actor/user/groups", null, List.of(Map.of("second", "slistval")), null, null, false, true, null, null, true, null))); |
| 90 | + |
| 91 | + final AddEntryProcessor processor = createObjectUnderTest(); |
| 92 | + final List<Map<String, Object>> mapList = List.of(Map.of("testKey", "testValue")); |
| 93 | + final Map<String, Object> data = Map.of("message", mapList); |
| 94 | + final Record<Event> record = getEvent(mapList); |
| 95 | + |
| 96 | + final List<Record<Event>> editedRecords = (List<Record<Event>>) processor.doExecute(Collections.singletonList(record)); |
| 97 | + assertEquals("{\"message\":[{\"testKey\":\"testValue\"}],\"actor\":{\"user\":{\"groups\":[{\"name\":\"\"},[{\"second\":\"slistval\"}]]}}}", |
| 98 | + editedRecords.get(0).getData().toJsonString()); |
| 99 | + } |
| 100 | + |
67 | 101 | @Test |
68 | 102 | public void testSingleAddProcessorTests() { |
69 | 103 | when(mockConfig.getEntries()).thenReturn(createListOfEntries(createEntry("newMessage", null, 3, null, null, false, false,null, null, true, null))); |
@@ -359,7 +393,7 @@ public void testListMergeOptimization() { |
359 | 393 | final Record<Event> record = getEvent(currentList); |
360 | 394 | final List<Record<Event>> editedRecords = (List<Record<Event>>) processor.doExecute(Collections.singletonList(record)); |
361 | 395 |
|
362 | | - assertThat(editedRecords.get(0).getData().get("message", List.class), equalTo(Arrays.asList(1, 2, 3, 4, 5))); |
| 396 | + assertThat(editedRecords.get(0).getData().get("message", List.class), equalTo(Arrays.asList(1, 2, 3, Arrays.asList(4, 5)))); |
363 | 397 | } |
364 | 398 |
|
365 | 399 | @Test |
|
0 commit comments