From 2044fbea977a91bb336aefe82a3f1a488d369a01 Mon Sep 17 00:00:00 2001 From: Marty Pradere Date: Fri, 24 Oct 2025 05:37:20 -0700 Subject: [PATCH 1/3] EHR notif audit test --- .../test/tests/onprc_ehr/ONPRC_EHRTest.java | 102 +++++++++++++++++- 1 file changed, 101 insertions(+), 1 deletion(-) diff --git a/onprc_ehr/test/src/org/labkey/test/tests/onprc_ehr/ONPRC_EHRTest.java b/onprc_ehr/test/src/org/labkey/test/tests/onprc_ehr/ONPRC_EHRTest.java index c155344ab..f2a795ac4 100644 --- a/onprc_ehr/test/src/org/labkey/test/tests/onprc_ehr/ONPRC_EHRTest.java +++ b/onprc_ehr/test/src/org/labkey/test/tests/onprc_ehr/ONPRC_EHRTest.java @@ -43,6 +43,7 @@ import org.labkey.test.components.BodyWebPart; import org.labkey.test.pages.ehr.AnimalHistoryPage; import org.labkey.test.pages.ehr.EnterDataPage; +import org.labkey.test.pages.ehr.NotificationAdminPage; import org.labkey.test.util.DataRegionTable; import org.labkey.test.util.Ext4Helper; import org.labkey.test.util.LogMethod; @@ -71,6 +72,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Function; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -1975,5 +1977,103 @@ protected String getAnimalHistoryPath() { return ANIMAL_HISTORY_URL; } -} + @Test + public void testNotificationAdminAudits() throws Exception + { + // Ensure notification service is configured + setupNotificationService(); + + // Navigate to Notification Admin page + goToEHRFolder(); + waitAndClickAndWait(Locators.bodyPanel().append(Locator.tagContainingText("a", "EHR Admin Page"))); + waitAndClickAndWait(Locator.tagContainingText("a", "Notification Admin")); + + // Record start time for audit filtering + LocalDateTime start = LocalDateTime.now().minusMinutes(5); + + // Change Notification User and Reply Email, then save + NotificationAdminPage.beginAt(this); + String replyEmail = "ehr-notify@labkey.test"; + Ext4FieldRef.getForLabel(this, "Notification User").setValue(PasswordUtil.getUsername()); + Ext4FieldRef.getForLabel(this, "Reply Email").setValue(replyEmail); + click(Ext4Helper.Locators.ext4Button("Save")); + waitForElement(Ext4Helper.Locators.window("Success")); + waitAndClickAndWait(Ext4Helper.Locators.ext4Button("OK")); + + // Identify two notifications by extracting their keys from the Run Report links + beginAt(WebTestHelper.getBaseURL() + "/ldk/" + getContainerPath() + "/notificationAdmin.view"); + List runLinks = Locator.tagContainingText("a", "Run Report In Browser").findElements(getDriver()); + Assert.assertTrue("Expected at least two notifications to be available", runLinks.size() >= 2); + + List notifKeys = new ArrayList<>(); + for (int i = 0; i < Math.min(2, runLinks.size()); i++) + { + String href = runLinks.get(i).getAttribute("href"); + int idx = href.indexOf("key="); + Assert.assertTrue("Could not locate notification key in href: " + href, idx > -1); + String key = href.substring(idx + 4); + notifKeys.add(key); + } + + // Disable the two notifications and save + for (String key : notifKeys) + { + _ext4Helper.selectComboBoxItem(Ext4Helper.Locators.formItemWithInputNamed("status_" + key), Ext4Helper.TextMatchTechnique.EXACT, "Disabled"); + } + click(Ext4Helper.Locators.ext4Button("Save")); + waitForElement(Ext4Helper.Locators.window("Success")); + waitAndClickAndWait(Ext4Helper.Locators.ext4Button("OK")); + + // Re-enable the two notifications and save + for (String key : notifKeys) + { + _ext4Helper.selectComboBoxItem(Ext4Helper.Locators.formItemWithInputNamed("status_" + key), Ext4Helper.TextMatchTechnique.EXACT, "Enabled"); + } + click(Ext4Helper.Locators.ext4Button("Save")); + waitForElement(Ext4Helper.Locators.window("Success")); + waitAndClickAndWait(Ext4Helper.Locators.ext4Button("OK")); + + // Manage subscribed users on the first notification: add two users then remove one + Locator manageLink = Locator.tagContainingText("a", "Manage Subscribed Users/Groups").index(0); + waitAndClick(manageLink); + waitForElement(Ext4Helper.Locators.window("Manage Subscribed Users")); + Ext4ComboRef combo = Ext4ComboRef.getForLabel(this, "Add User Or Group"); + combo.waitForStoreLoad(); + _ext4Helper.selectComboBoxItem(Locator.id(combo.getId()), Ext4Helper.TextMatchTechnique.CONTAINS, DATA_ADMIN.getEmail()); + Ext4FieldRef.waitForComponent(this, "field[fieldLabel^='Add User Or Group']"); + combo = Ext4ComboRef.getForLabel(this, "Add User Or Group"); + _ext4Helper.selectComboBoxItem(Locator.id(combo.getId()), Ext4Helper.TextMatchTechnique.CONTAINS, BASIC_SUBMITTER.getEmail()); + waitAndClick(Ext4Helper.Locators.ext4Button("Close")); + + // Re-open and remove one user + waitAndClick(manageLink); + waitForElement(Ext4Helper.Locators.window("Manage Subscribed Users")); + assertElementPresent(Ext4Helper.Locators.ext4Button("Remove")); + waitAndClick(Ext4Helper.Locators.ext4Button("Remove").index(0)); + waitAndClick(Ext4Helper.Locators.ext4Button("Close")); + + // Verify audit log entries in audit.SiteSettings for this container + sleep(1000); + + Function countAudit = (commentSubstring) -> { + try + { + SelectRowsCommand cmd = new SelectRowsCommand("auditLog", "AppPropsEvent"); + cmd.addFilter(new Filter("Created", Date.from(start.atZone(ZoneId.systemDefault()).toInstant()), Filter.Operator.DATE_GTE)); + cmd.addFilter(new Filter("Comment", commentSubstring, Filter.Operator.CONTAINS)); + SelectRowsResponse resp = cmd.execute(getApiHelper().getConnection(), getContainerPath()); + return resp.getRowCount().intValue(); + } + catch (Exception e) + { + throw new RuntimeException(e); + } + }; + + Assert.assertTrue("Expected audit entry for reply-to email update", countAudit.apply("Notification reply-to email updated.") > 0); + Assert.assertTrue("Expected audit entry for service user update", countAudit.apply("Notification service user updated.") > 0); + Assert.assertTrue("Expected audit entry for notification enabled", countAudit.apply("has been enabled.") > 0); + Assert.assertTrue("Expected audit entry for subscription updates", countAudit.apply("Updated notification subscriptions for") > 0); + } +} From 87679f81fb0eb3547af000d5fd97612ab6e72b7b Mon Sep 17 00:00:00 2001 From: Marty Pradere Date: Tue, 28 Oct 2025 13:45:22 -0700 Subject: [PATCH 2/3] fix flaky test --- .../test/src/org/labkey/test/tests/onprc_ehr/ONPRC_EHRTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onprc_ehr/test/src/org/labkey/test/tests/onprc_ehr/ONPRC_EHRTest.java b/onprc_ehr/test/src/org/labkey/test/tests/onprc_ehr/ONPRC_EHRTest.java index f2a795ac4..6e01335f9 100644 --- a/onprc_ehr/test/src/org/labkey/test/tests/onprc_ehr/ONPRC_EHRTest.java +++ b/onprc_ehr/test/src/org/labkey/test/tests/onprc_ehr/ONPRC_EHRTest.java @@ -2004,7 +2004,7 @@ public void testNotificationAdminAudits() throws Exception // Identify two notifications by extracting their keys from the Run Report links beginAt(WebTestHelper.getBaseURL() + "/ldk/" + getContainerPath() + "/notificationAdmin.view"); List runLinks = Locator.tagContainingText("a", "Run Report In Browser").findElements(getDriver()); - Assert.assertTrue("Expected at least two notifications to be available", runLinks.size() >= 2); + waitFor(() -> runLinks.size() >= 2, "Expected at least two notifications to be available", WAIT_FOR_PAGE); List notifKeys = new ArrayList<>(); for (int i = 0; i < Math.min(2, runLinks.size()); i++) From 7acdb32bc5429b416ef56c516c500e913ed961bc Mon Sep 17 00:00:00 2001 From: Marty Pradere Date: Wed, 29 Oct 2025 05:24:40 -0700 Subject: [PATCH 3/3] flaky test --- .../src/org/labkey/test/tests/onprc_ehr/ONPRC_EHRTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/onprc_ehr/test/src/org/labkey/test/tests/onprc_ehr/ONPRC_EHRTest.java b/onprc_ehr/test/src/org/labkey/test/tests/onprc_ehr/ONPRC_EHRTest.java index 6e01335f9..e1313a66f 100644 --- a/onprc_ehr/test/src/org/labkey/test/tests/onprc_ehr/ONPRC_EHRTest.java +++ b/onprc_ehr/test/src/org/labkey/test/tests/onprc_ehr/ONPRC_EHRTest.java @@ -2003,8 +2003,9 @@ public void testNotificationAdminAudits() throws Exception // Identify two notifications by extracting their keys from the Run Report links beginAt(WebTestHelper.getBaseURL() + "/ldk/" + getContainerPath() + "/notificationAdmin.view"); - List runLinks = Locator.tagContainingText("a", "Run Report In Browser").findElements(getDriver()); - waitFor(() -> runLinks.size() >= 2, "Expected at least two notifications to be available", WAIT_FOR_PAGE); + Locator links = Locator.tagContainingText("a", "Run Report In Browser"); + waitFor(() -> links.findElements(getDriver()).size() >= 2, "Expected at least two notifications to be available", WAIT_FOR_PAGE); + List runLinks = links.findElements(getDriver()); List notifKeys = new ArrayList<>(); for (int i = 0; i < Math.min(2, runLinks.size()); i++)