Skip to content
Open
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
20 changes: 13 additions & 7 deletions src/org/labkey/test/util/AuditLogHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

import static java.lang.Integer.parseInt;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -261,19 +262,24 @@ public void checkAuditEventValuesForTransactionId(String containerPath, AuditEve

public void checkAuditEventValuesForTransactionId(String containerPath, AuditEvent auditEventName, Integer transactionId, List<Map<String, Object>> expectedValues) throws IOException, CommandException
{
List<String> columnNames = expectedValues.get(0).keySet().stream().map(Object::toString).toList();
List<String> columnNames = expectedValues.getFirst().keySet().stream().map(Object::toString).toList();
checkAuditEventValuesForTransactionId(containerPath, auditEventName, columnNames, transactionId, expectedValues);
}

public void checkAuditEventValuesForTransactionId(String containerPath, AuditEvent auditEventName, List<String> columnNames, Integer transactionId, List<Map<String, Object>> expectedValues) throws IOException, CommandException
{
List<Map<String, Object>> events = getAuditLogsForTransactionId(containerPath, auditEventName, columnNames, transactionId, ContainerFilter.CurrentAndSubfolders);
assertEquals("Unexpected number of events for transactionId " + transactionId, expectedValues.size(), events.size());
for (int i = 0; i < expectedValues.size(); i++)
{
for (String key : expectedValues.get(i).keySet())
assertEquals("Event " + i + " value for " + key + " not as expected", expectedValues.get(i).get(key), events.get(i).get(key));
}

Set<String> keysOfInterest = expectedValues.getFirst().keySet();
List<Map<String, Object>> actualFiltered = events.stream()
.map(row -> row.entrySet().stream()
.filter(e -> keysOfInterest.contains(e.getKey()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)))
.toList();

assertEquals("Lists do not contain the same entries",
new HashSet<>(actualFiltered), new HashSet<>(expectedValues));

}

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