Skip to content

Commit e5a42e4

Browse files
authored
Test component audit event row count and diff count checks for Storage actions (#2457)
- AuditLogHelper helper to get audit events for a given transactionId - AuditLogHelper to remove "Timeline" from method names and to add ContainerFilter param for cross folder checks
1 parent a4df3b6 commit e5a42e4

3 files changed

Lines changed: 57 additions & 24 deletions

File tree

src/org/labkey/test/components/ui/entities/EntityBulkUpdateDialog.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.labkey.test.BootstrapLocators;
55
import org.labkey.test.Locator;
66
import org.labkey.test.WebDriverWrapper;
7+
import org.labkey.test.WebTestHelper;
78
import org.labkey.test.components.Component;
89
import org.labkey.test.components.UpdatingComponent;
910
import org.labkey.test.components.bootstrap.ModalDialog;
@@ -262,11 +263,6 @@ public Integer getCountFromTitle()
262263

263264
// dismiss the dialog
264265

265-
public void clickEditWithGrid()
266-
{
267-
dismiss("Edit with Grid");
268-
}
269-
270266
public String clickUpdateExpectingError()
271267
{
272268
elementCache().updateButton.click();
@@ -279,7 +275,7 @@ public void clickUpdate()
279275
clickUpdate(false);
280276
}
281277

282-
public void clickUpdate(boolean skipChangeCounterCheck)
278+
public void clickUpdate(boolean skipAuditEventCheck)
283279
{
284280
Integer rowCount = getCountFromTitle();
285281

@@ -290,14 +286,14 @@ public void clickUpdate(boolean skipChangeCounterCheck)
290286
});
291287

292288
// check for the expected number of Data Changes in the latest audit event records
293-
AuditLogHelper auditLogHelper = new AuditLogHelper(getWrapper());
289+
AuditLogHelper auditLogHelper = new AuditLogHelper(getWrapper(), () -> WebTestHelper.getRemoteApiConnection(false));
294290
String auditEventName = auditLogHelper.getAuditEventNameFromURL();
295-
if (!skipChangeCounterCheck && auditEventName != null)
291+
if (!skipAuditEventCheck && auditEventName != null)
296292
{
297293
try
298294
{
299295
int changeCounter = auditLogHelper.isSourcesRoute() ? _changeCounter + 1 : _changeCounter; // Source updates include the name value in the diff (even when not changed)
300-
auditLogHelper.checkTimelineAuditEventDiffCountForLastTransaction(getWrapper().getCurrentContainerPath(), auditEventName, changeCounter, rowCount);
296+
auditLogHelper.checkAuditEventDiffCountForLastTransaction(getWrapper().getCurrentContainerPath(), auditEventName, changeCounter, rowCount);
301297
}
302298
catch (CommandException | IOException e)
303299
{

src/org/labkey/test/components/ui/grids/DetailTableEdit.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.labkey.test.BootstrapLocators;
66
import org.labkey.test.Locator;
77
import org.labkey.test.WebDriverWrapper;
8+
import org.labkey.test.WebTestHelper;
89
import org.labkey.test.components.Component;
910
import org.labkey.test.components.WebDriverComponent;
1011
import org.labkey.test.components.html.Checkbox;
@@ -503,7 +504,7 @@ public DetailDataPanel clickSave()
503504
return clickSave(false);
504505
}
505506

506-
public DetailDataPanel clickSave(boolean skipChangeCounterCheck)
507+
public DetailDataPanel clickSave(boolean skipAuditEventCheck)
507508
{
508509
String title = getSourceTitle();
509510
var componentEl = getComponentElement();
@@ -515,14 +516,14 @@ public DetailDataPanel clickSave(boolean skipChangeCounterCheck)
515516
.until(ExpectedConditions.stalenessOf(elementCache().saveButton));
516517

517518
// check for the expected number of Data Changes in the latest audit event records
518-
AuditLogHelper auditLogHelper = new AuditLogHelper(getWrapper());
519+
AuditLogHelper auditLogHelper = new AuditLogHelper(getWrapper(), () -> WebTestHelper.getRemoteApiConnection(false));
519520
String auditEventName = auditLogHelper.getAuditEventNameFromURL();
520-
if (!skipChangeCounterCheck && auditEventName != null)
521+
if (!skipAuditEventCheck && auditEventName != null)
521522
{
522523
try
523524
{
524525
int changeCounter = auditLogHelper.isSourcesRoute() ? _changeCounter + 1 : _changeCounter; // Source updates include the name value in the diff (even when not changed)
525-
auditLogHelper.checkTimelineAuditEventDiffCountForLastTransaction(getWrapper().getCurrentContainerPath(), auditEventName, changeCounter, 1);
526+
auditLogHelper.checkAuditEventDiffCountForLastTransaction(getWrapper().getCurrentContainerPath(), auditEventName, changeCounter, 1);
526527
}
527528
catch (CommandException | IOException e)
528529
{

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

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,40 +95,68 @@ public DataRegionTable goToAuditEventView(String eventType)
9595
* @param auditEventName Name of the audit event to filter on. Example 'SamplesWorkflowAuditEvent'.
9696
* @param columnNames The name of the columns to return.
9797
* @param filters The filters to be applied
98+
* @param maxRows The maximum number of rows to return. If null, all rows for the provided filters will be returned.
99+
* @param containerFilter The container filter to be applied. If null, default is ContainerFilter.Current.
98100
* @return A rowResponse with the query logs.
99101
* @throws IOException Can be thrown by the SelectRowsCommand.
100102
* @throws CommandException Can be thrown by the SelectRowsCommand.
101103
*/
102104
public SelectRowsResponse getAuditLogsFromLKS(String containerPath, String auditEventName, List<String> columnNames,
103-
List<Filter> filters, @Nullable Integer maxRows) throws IOException, CommandException
105+
List<Filter> filters, @Nullable Integer maxRows, @Nullable ContainerFilter containerFilter) throws IOException, CommandException
104106
{
105107
SelectRowsCommand cmd = new SelectRowsCommand("auditLog", auditEventName);
106108
cmd.setColumns(columnNames);
107109
cmd.addFilter("ProjectId/Name", _wrapper.getCurrentProject(), Filter.Operator.EQUAL);
108110
filters.forEach(cmd::addFilter);
109111
if (maxRows != null)
110112
cmd.setMaxRows(maxRows);
113+
if (containerFilter != null)
114+
cmd.setContainerFilter(containerFilter);
111115
return cmd.execute(_connectionSupplier.get(), containerPath);
112116
}
113117

118+
public List<Map<String, Object>> getAuditLogsForTransactionId(String containerPath, String auditEventName, List<String> columnNames,
119+
Integer transactionId, @Nullable ContainerFilter containerFilter) throws IOException, CommandException
120+
{
121+
List<Filter> transactionFilter = List.of(new Filter("TransactionId", transactionId, Filter.Operator.EQUAL));
122+
return getAuditLogsFromLKS(containerPath, auditEventName, columnNames, transactionFilter, null, containerFilter).getRows();
123+
}
124+
125+
public void checkAuditEventValuesForTransactionId(String containerPath, String auditEventName, Integer transactionId, int rowCount, Map<String, Object> expectedValues) throws IOException, CommandException
126+
{
127+
List<String> columnNames = expectedValues.keySet().stream().map(Object::toString).toList();
128+
List<Map<String, Object>> events = getAuditLogsForTransactionId(containerPath, auditEventName, columnNames, transactionId, ContainerFilter.CurrentAndSubfolders);
129+
assertEquals("Unexpected number of events for transactionId " + transactionId, rowCount, events.size());
130+
for (Map<String, Object> event : events)
131+
{
132+
for (String key : columnNames)
133+
assertEquals("Event value for " + key + " not as expected", expectedValues.get(key), event.get(key));
134+
}
135+
}
136+
114137
/**
115138
* Check the number of diffs in the audit event. This is a helper function to check the number of diffs in the
116139
* newRecordMap for an audit entry. If a transactionId is provided, it will check all rows for that
117140
* transactionId. If no transactionId is provided, it will check just the latest row.
118141
*/
119142
public void checkTimelineAuditEventDiffCount(String containerPath, List<Integer> expectedDiffCounts) throws IOException, CommandException
120143
{
121-
checkTimelineAuditEventDiffCount(containerPath, getAuditEventNameFromURL(), expectedDiffCounts);
144+
checkAuditEventDiffCount(containerPath, getAuditEventNameFromURL(), expectedDiffCounts);
145+
}
146+
public void checkAuditEventDiffCount(String containerPath, String auditEventName, List<Integer> expectedDiffCounts) throws IOException, CommandException
147+
{
148+
checkAuditEventDiffCount(containerPath, auditEventName, Collections.emptyList(), expectedDiffCounts);
122149
}
123-
public void checkTimelineAuditEventDiffCount(String containerPath, String auditEventName, List<Integer> expectedDiffCounts) throws IOException, CommandException
150+
public void checkAuditEventDiffCount(String containerPath, String auditEventName, List<Filter> filters, List<Integer> expectedDiffCounts) throws IOException, CommandException
124151
{
125152
Integer maxRows = expectedDiffCounts.size();
126-
List<Map<String, Object>> events = getAuditLogsFromLKS(containerPath, auditEventName, List.of("NewRecordMap"), Collections.emptyList(), maxRows).getRows();
153+
List<Map<String, Object>> events = getAuditLogsFromLKS(containerPath, auditEventName, List.of("InventoryUpdateType", "NewRecordMap"), filters, maxRows, ContainerFilter.CurrentAndSubfolders).getRows();
127154
assertEquals("Unexpected number of events", expectedDiffCounts.size(), events.size());
128155
for (int i = 0; i < expectedDiffCounts.size(); i++)
129156
{
130-
int expectedDiffCount = expectedDiffCounts.get(i);
131157
Map<String, Object> event = events.get(i);
158+
boolean isInventoryUpdateType = event.get("InventoryUpdateType") != null;
159+
int expectedDiffCount = isInventoryUpdateType ? 0 : expectedDiffCounts.get(i);
132160
String dataChangesStr = (String) event.get("NewRecordMap");
133161
String[] dataChanges = dataChangesStr != null ? dataChangesStr.split("&") : new String[0];
134162

@@ -143,20 +171,28 @@ public void checkTimelineAuditEventDiffCount(String containerPath, String auditE
143171
}
144172
}
145173

174+
public Integer getLastTransactionId(String containerPath, String auditEventName) throws IOException, CommandException
175+
{
176+
List<Map<String, Object>> events = getAuditLogsFromLKS(containerPath, auditEventName, List.of("TransactionId"), Collections.emptyList(), 1, ContainerFilter.CurrentAndSubfolders).getRows();
177+
return events.size() == 1 ? (Integer) events.get(0).get("TransactionId") : null;
178+
}
179+
146180
/**
147-
* Check for th expected number of diffs in the audit event for the last transactionId.
181+
* Check for the expected number of diffs in the audit event for the last transactionId.
148182
* If an expectedEventCount is also provided, it will check that the number of events for that transactionId matches the expectedEventCount.
183+
* @return transactionId
149184
*/
150-
public void checkTimelineAuditEventDiffCountForLastTransaction(String containerPath, String auditEventName, int expectedDiffCount, @Nullable Integer expectedEventCount) throws IOException, CommandException
185+
public Integer checkAuditEventDiffCountForLastTransaction(String containerPath, String auditEventName, int expectedDiffCount,
186+
@Nullable Integer expectedEventCount) throws IOException, CommandException
151187
{
152-
Integer transactionId = (Integer) getAuditLogsFromLKS(containerPath, auditEventName, List.of("TransactionId"), Collections.emptyList(), 1)
153-
.getRows().get(0).get("TransactionId");
188+
Integer transactionId = getLastTransactionId(containerPath, auditEventName);
154189
List<Filter> transactionFilter = List.of(new Filter("TransactionId", transactionId, Filter.Operator.EQUAL));
155-
int eventCount = getAuditLogsFromLKS(containerPath, auditEventName, List.of("NewRecordMap"), transactionFilter, null).getRows().size();
190+
int eventCount = getAuditLogsFromLKS(containerPath, auditEventName, List.of("NewRecordMap"), transactionFilter, null, ContainerFilter.CurrentAndSubfolders).getRows().size();
156191
if (expectedEventCount != null)
157192
assertEquals("Unexpected number of events for transactionId " + transactionId, expectedEventCount.intValue(), eventCount);
158193
List<Integer> expectedChangeCounts = Collections.nCopies(eventCount, expectedDiffCount);
159-
checkTimelineAuditEventDiffCount(containerPath, auditEventName, expectedChangeCounts);
194+
checkAuditEventDiffCount(containerPath, auditEventName, transactionFilter, expectedChangeCounts);
195+
return transactionId;
160196
}
161197

162198
public String getAuditEventNameFromURL()

0 commit comments

Comments
 (0)