Skip to content

Commit c237e1a

Browse files
EHR notification audit test (#1524)
* Add testNotificationAdminAudits
1 parent 76bc2f9 commit c237e1a

1 file changed

Lines changed: 102 additions & 1 deletion

File tree

onprc_ehr/test/src/org/labkey/test/tests/onprc_ehr/ONPRC_EHRTest.java

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.labkey.test.components.BodyWebPart;
4444
import org.labkey.test.pages.ehr.AnimalHistoryPage;
4545
import org.labkey.test.pages.ehr.EnterDataPage;
46+
import org.labkey.test.pages.ehr.NotificationAdminPage;
4647
import org.labkey.test.util.DataRegionTable;
4748
import org.labkey.test.util.Ext4Helper;
4849
import org.labkey.test.util.LogMethod;
@@ -71,6 +72,7 @@
7172
import java.util.HashMap;
7273
import java.util.List;
7374
import java.util.Map;
75+
import java.util.function.Function;
7476

7577
import static org.junit.Assert.assertEquals;
7678
import static org.junit.Assert.assertNotNull;
@@ -1975,5 +1977,104 @@ protected String getAnimalHistoryPath()
19751977
{
19761978
return ANIMAL_HISTORY_URL;
19771979
}
1978-
}
19791980

1981+
@Test
1982+
public void testNotificationAdminAudits() throws Exception
1983+
{
1984+
// Ensure notification service is configured
1985+
setupNotificationService();
1986+
1987+
// Navigate to Notification Admin page
1988+
goToEHRFolder();
1989+
waitAndClickAndWait(Locators.bodyPanel().append(Locator.tagContainingText("a", "EHR Admin Page")));
1990+
waitAndClickAndWait(Locator.tagContainingText("a", "Notification Admin"));
1991+
1992+
// Record start time for audit filtering
1993+
LocalDateTime start = LocalDateTime.now().minusMinutes(5);
1994+
1995+
// Change Notification User and Reply Email, then save
1996+
NotificationAdminPage.beginAt(this);
1997+
String replyEmail = "ehr-notify@labkey.test";
1998+
Ext4FieldRef.getForLabel(this, "Notification User").setValue(PasswordUtil.getUsername());
1999+
Ext4FieldRef.getForLabel(this, "Reply Email").setValue(replyEmail);
2000+
click(Ext4Helper.Locators.ext4Button("Save"));
2001+
waitForElement(Ext4Helper.Locators.window("Success"));
2002+
waitAndClickAndWait(Ext4Helper.Locators.ext4Button("OK"));
2003+
2004+
// Identify two notifications by extracting their keys from the Run Report links
2005+
beginAt(WebTestHelper.getBaseURL() + "/ldk/" + getContainerPath() + "/notificationAdmin.view");
2006+
Locator links = Locator.tagContainingText("a", "Run Report In Browser");
2007+
waitFor(() -> links.findElements(getDriver()).size() >= 2, "Expected at least two notifications to be available", WAIT_FOR_PAGE);
2008+
List<WebElement> runLinks = links.findElements(getDriver());
2009+
2010+
List<String> notifKeys = new ArrayList<>();
2011+
for (int i = 0; i < Math.min(2, runLinks.size()); i++)
2012+
{
2013+
String href = runLinks.get(i).getAttribute("href");
2014+
int idx = href.indexOf("key=");
2015+
Assert.assertTrue("Could not locate notification key in href: " + href, idx > -1);
2016+
String key = href.substring(idx + 4);
2017+
notifKeys.add(key);
2018+
}
2019+
2020+
// Disable the two notifications and save
2021+
for (String key : notifKeys)
2022+
{
2023+
_ext4Helper.selectComboBoxItem(Ext4Helper.Locators.formItemWithInputNamed("status_" + key), Ext4Helper.TextMatchTechnique.EXACT, "Disabled");
2024+
}
2025+
click(Ext4Helper.Locators.ext4Button("Save"));
2026+
waitForElement(Ext4Helper.Locators.window("Success"));
2027+
waitAndClickAndWait(Ext4Helper.Locators.ext4Button("OK"));
2028+
2029+
// Re-enable the two notifications and save
2030+
for (String key : notifKeys)
2031+
{
2032+
_ext4Helper.selectComboBoxItem(Ext4Helper.Locators.formItemWithInputNamed("status_" + key), Ext4Helper.TextMatchTechnique.EXACT, "Enabled");
2033+
}
2034+
click(Ext4Helper.Locators.ext4Button("Save"));
2035+
waitForElement(Ext4Helper.Locators.window("Success"));
2036+
waitAndClickAndWait(Ext4Helper.Locators.ext4Button("OK"));
2037+
2038+
// Manage subscribed users on the first notification: add two users then remove one
2039+
Locator manageLink = Locator.tagContainingText("a", "Manage Subscribed Users/Groups").index(0);
2040+
waitAndClick(manageLink);
2041+
waitForElement(Ext4Helper.Locators.window("Manage Subscribed Users"));
2042+
Ext4ComboRef combo = Ext4ComboRef.getForLabel(this, "Add User Or Group");
2043+
combo.waitForStoreLoad();
2044+
_ext4Helper.selectComboBoxItem(Locator.id(combo.getId()), Ext4Helper.TextMatchTechnique.CONTAINS, DATA_ADMIN.getEmail());
2045+
Ext4FieldRef.waitForComponent(this, "field[fieldLabel^='Add User Or Group']");
2046+
combo = Ext4ComboRef.getForLabel(this, "Add User Or Group");
2047+
_ext4Helper.selectComboBoxItem(Locator.id(combo.getId()), Ext4Helper.TextMatchTechnique.CONTAINS, BASIC_SUBMITTER.getEmail());
2048+
waitAndClick(Ext4Helper.Locators.ext4Button("Close"));
2049+
2050+
// Re-open and remove one user
2051+
waitAndClick(manageLink);
2052+
waitForElement(Ext4Helper.Locators.window("Manage Subscribed Users"));
2053+
assertElementPresent(Ext4Helper.Locators.ext4Button("Remove"));
2054+
waitAndClick(Ext4Helper.Locators.ext4Button("Remove").index(0));
2055+
waitAndClick(Ext4Helper.Locators.ext4Button("Close"));
2056+
2057+
// Verify audit log entries in audit.SiteSettings for this container
2058+
sleep(1000);
2059+
2060+
Function<String, Integer> countAudit = (commentSubstring) -> {
2061+
try
2062+
{
2063+
SelectRowsCommand cmd = new SelectRowsCommand("auditLog", "AppPropsEvent");
2064+
cmd.addFilter(new Filter("Created", Date.from(start.atZone(ZoneId.systemDefault()).toInstant()), Filter.Operator.DATE_GTE));
2065+
cmd.addFilter(new Filter("Comment", commentSubstring, Filter.Operator.CONTAINS));
2066+
SelectRowsResponse resp = cmd.execute(getApiHelper().getConnection(), getContainerPath());
2067+
return resp.getRowCount().intValue();
2068+
}
2069+
catch (Exception e)
2070+
{
2071+
throw new RuntimeException(e);
2072+
}
2073+
};
2074+
2075+
Assert.assertTrue("Expected audit entry for reply-to email update", countAudit.apply("Notification reply-to email updated.") > 0);
2076+
Assert.assertTrue("Expected audit entry for service user update", countAudit.apply("Notification service user updated.") > 0);
2077+
Assert.assertTrue("Expected audit entry for notification enabled", countAudit.apply("has been enabled.") > 0);
2078+
Assert.assertTrue("Expected audit entry for subscription updates", countAudit.apply("Updated notification subscriptions for") > 0);
2079+
}
2080+
}

0 commit comments

Comments
 (0)