Skip to content

Commit 8df1458

Browse files
Update AuditLogHelper.checkAuditEventValuesForTransactionId to be a set comparison and not a list comparison. Also update it to be flexible for different fields per record.
1 parent 80861da commit 8df1458

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

src/org/labkey/test/util/AuditLogHelper.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import java.util.Map;
3232
import java.util.Objects;
3333
import java.util.Set;
34-
import java.util.stream.Collectors;
3534

3635
import static java.lang.Integer.parseInt;
3736
import static org.junit.Assert.assertEquals;
@@ -270,16 +269,21 @@ public void checkAuditEventValuesForTransactionId(String containerPath, AuditEve
270269
{
271270
List<Map<String, Object>> events = getAuditLogsForTransactionId(containerPath, auditEventName, columnNames, transactionId, ContainerFilter.CurrentAndSubfolders);
272271

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)))
272+
List<Map<String, Object>> unmatched = expectedValues.stream()
273+
.filter(expectedRow -> {
274+
Set<String> keysOfInterest = expectedRow.keySet();
275+
return events.stream().noneMatch(actualRow -> {
276+
Map<String, Object> actualFiltered = actualRow.entrySet().stream()
277+
.filter(e -> keysOfInterest.contains(e.getKey()))
278+
.collect(HashMap::new,
279+
(m, e) -> m.put(e.getKey(), e.getValue()),
280+
HashMap::putAll);
281+
return actualFiltered.equals(expectedRow);
282+
});
283+
})
278284
.toList();
279285

280-
assertEquals("Lists do not contain the same entries",
281-
new HashSet<>(actualFiltered), new HashSet<>(expectedValues));
282-
286+
assertTrue("Expected rows with no match in actual: " + unmatched, unmatched.isEmpty());
283287
}
284288

285289
public Map<String, Object> getTransactionAuditLogDetails(Integer transactionAuditId)

0 commit comments

Comments
 (0)