|
31 | 31 | import java.util.Map; |
32 | 32 | import java.util.Objects; |
33 | 33 | import java.util.Set; |
| 34 | +import java.util.stream.Collectors; |
34 | 35 |
|
35 | 36 | import static java.lang.Integer.parseInt; |
36 | 37 | import static org.junit.Assert.assertEquals; |
@@ -261,19 +262,24 @@ public void checkAuditEventValuesForTransactionId(String containerPath, AuditEve |
261 | 262 |
|
262 | 263 | public void checkAuditEventValuesForTransactionId(String containerPath, AuditEvent auditEventName, Integer transactionId, List<Map<String, Object>> expectedValues) throws IOException, CommandException |
263 | 264 | { |
264 | | - List<String> columnNames = expectedValues.get(0).keySet().stream().map(Object::toString).toList(); |
| 265 | + List<String> columnNames = expectedValues.getFirst().keySet().stream().map(Object::toString).toList(); |
265 | 266 | checkAuditEventValuesForTransactionId(containerPath, auditEventName, columnNames, transactionId, expectedValues); |
266 | 267 | } |
267 | 268 |
|
268 | 269 | public void checkAuditEventValuesForTransactionId(String containerPath, AuditEvent auditEventName, List<String> columnNames, Integer transactionId, List<Map<String, Object>> expectedValues) throws IOException, CommandException |
269 | 270 | { |
270 | 271 | List<Map<String, Object>> events = getAuditLogsForTransactionId(containerPath, auditEventName, columnNames, transactionId, ContainerFilter.CurrentAndSubfolders); |
271 | | - assertEquals("Unexpected number of events for transactionId " + transactionId, expectedValues.size(), events.size()); |
272 | | - for (int i = 0; i < expectedValues.size(); i++) |
273 | | - { |
274 | | - for (String key : expectedValues.get(i).keySet()) |
275 | | - assertEquals("Event " + i + " value for " + key + " not as expected", expectedValues.get(i).get(key), events.get(i).get(key)); |
276 | | - } |
| 272 | + |
| 273 | + Set<String> keysOfInterest = expectedValues.getFirst().keySet(); |
| 274 | + List<Map<String, Object>> actualFiltered = events.stream() |
| 275 | + .map(row -> row.entrySet().stream() |
| 276 | + .filter(e -> keysOfInterest.contains(e.getKey())) |
| 277 | + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))) |
| 278 | + .toList(); |
| 279 | + |
| 280 | + assertEquals("Lists do not contain the same entries", |
| 281 | + new HashSet<>(actualFiltered), new HashSet<>(expectedValues)); |
| 282 | + |
277 | 283 | } |
278 | 284 |
|
279 | 285 | public Map<String, Object> getTransactionAuditLogDetails(Integer transactionAuditId) |
|
0 commit comments