Skip to content

Commit 54fd9ba

Browse files
authored
Test component audit event row count and diff count checks for Jobs and Picklists (#2533)
- Add AuditLogHelper checkAuditEventDiffCount support for checking event "Metadata" in addition to "NewRecordMap" - WebDriverWrapper helper for getUserId - AuditLogHelper.checkAuditEventDiffCount should set maxRows when no filters provided
1 parent abecd65 commit 54fd9ba

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

src/org/labkey/test/WebDriverWrapper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,11 @@ public String getDisplayName()
13581358
return whoAmI().getDisplayName();
13591359
}
13601360

1361+
public int getCurrentUserId()
1362+
{
1363+
return whoAmI().getUserId().intValue();
1364+
}
1365+
13611366
public String getCurrentDateTimeFormatString()
13621367
{
13631368
return (String)executeScript("return LABKEY.container.formats.dateTimeFormat");

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,24 +171,29 @@ public void checkAuditEventDiffCount(String containerPath, AuditEvent auditEvent
171171
}
172172
public void checkAuditEventDiffCount(String containerPath, AuditEvent auditEventName, List<Filter> filters, List<Integer> expectedDiffCounts) throws IOException, CommandException
173173
{
174-
Integer maxRows = expectedDiffCounts.size();
175-
List<Map<String, Object>> events = getAuditLogsFromLKS(containerPath, auditEventName, List.of("InventoryUpdateType", "NewRecordMap"), filters, maxRows, ContainerFilter.CurrentAndSubfolders).getRows();
174+
checkAuditEventDiffCount(containerPath, auditEventName, "NewRecordMap", filters, expectedDiffCounts);
175+
}
176+
177+
public void checkAuditEventDiffCount(String containerPath, AuditEvent auditEventName, String eventDiffFieldName, List<Filter> filters, List<Integer> expectedDiffCounts) throws IOException, CommandException
178+
{
179+
Integer maxRows = filters == null || filters.isEmpty() ? expectedDiffCounts.size() : null;
180+
List<Map<String, Object>> events = getAuditLogsFromLKS(containerPath, auditEventName, List.of("InventoryUpdateType", eventDiffFieldName), filters, maxRows, ContainerFilter.CurrentAndSubfolders).getRows();
176181
assertEquals("Unexpected number of events", expectedDiffCounts.size(), events.size());
177182
for (int i = 0; i < expectedDiffCounts.size(); i++)
178183
{
179184
Map<String, Object> event = events.get(i);
180185
boolean isInventoryUpdateType = event.get("InventoryUpdateType") != null;
181186
int expectedDiffCount = isInventoryUpdateType ? 0 : expectedDiffCounts.get(i);
182-
String dataChangesStr = (String) event.get("NewRecordMap");
187+
String dataChangesStr = (String) event.get(eventDiffFieldName);
183188
String[] dataChanges = dataChangesStr != null ? dataChangesStr.split("&") : new String[0];
184189

185190
// filter out SampleStateLabel as that is not a change, it is added for display purposes
186191
dataChanges = Stream.of(dataChanges).filter(s -> !s.toLowerCase().startsWith("samplestatelabel=")).toArray(String[]::new);
187192
// filter out RowId as that is not a change, it is added for display purposes
188193
dataChanges = Stream.of(dataChanges).filter(s -> !s.toLowerCase().startsWith("rowid=")).toArray(String[]::new);
189194

190-
TestLogger.log("Audit record data changes diff count check: " + dataChangesStr);
191-
assertEquals("Audit record data changes did not include the expected number of diffs, expected " + expectedDiffCount + " but was " + dataChanges.length + ": " + dataChangesStr,
195+
TestLogger.log("Audit record data changes diff count check (" + eventDiffFieldName + "): " + dataChangesStr);
196+
assertEquals("Audit record data changes did not include the expected number of diffs in " + eventDiffFieldName + ", expected " + expectedDiffCount + " but was " + dataChanges.length + ": " + dataChangesStr,
192197
expectedDiffCount, dataChanges.length);
193198
}
194199
}

0 commit comments

Comments
 (0)