Skip to content

Commit 80861da

Browse files
Modify AuditLogHelper.checkAuditEventValuesForTransactionId to do a set comparison and not a list comparison.
1 parent 8c09218 commit 80861da

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

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

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

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

262263
public void checkAuditEventValuesForTransactionId(String containerPath, AuditEvent auditEventName, Integer transactionId, List<Map<String, Object>> expectedValues) throws IOException, CommandException
263264
{
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();
265266
checkAuditEventValuesForTransactionId(containerPath, auditEventName, columnNames, transactionId, expectedValues);
266267
}
267268

268269
public void checkAuditEventValuesForTransactionId(String containerPath, AuditEvent auditEventName, List<String> columnNames, Integer transactionId, List<Map<String, Object>> expectedValues) throws IOException, CommandException
269270
{
270271
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+
277283
}
278284

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

0 commit comments

Comments
 (0)