From 71ebc0881078f36a218291e8bf17e41abec1dc02 Mon Sep 17 00:00:00 2001 From: ChiuchiuSorin Date: Mon, 25 Nov 2024 17:57:11 +0200 Subject: [PATCH] [MISC] Add functional tests #16 * added tests for health check section * started tests for instance usage section --- .../admintools/test/ui/AdminToolsIT.java | 67 +++++++++++++++++-- .../test/po/AdminToolsHomePage.java | 12 ++++ .../test/po/DashboardHealthSectionView.java | 65 ++++++++++++++++++ .../test/po/DashboardUsageSectionView.java | 40 +++++++++++ .../test/po/FlushCacheModalView.java | 46 +++++++++++++ .../test/po/WikisSizeModalView.java | 48 +++++++++++++ 6 files changed, 274 insertions(+), 4 deletions(-) create mode 100644 application-admintools-test/application-admintools-test-pageobjects/src/main/java/com/xwiki/admintools/test/po/DashboardHealthSectionView.java create mode 100644 application-admintools-test/application-admintools-test-pageobjects/src/main/java/com/xwiki/admintools/test/po/DashboardUsageSectionView.java create mode 100644 application-admintools-test/application-admintools-test-pageobjects/src/main/java/com/xwiki/admintools/test/po/FlushCacheModalView.java create mode 100644 application-admintools-test/application-admintools-test-pageobjects/src/main/java/com/xwiki/admintools/test/po/WikisSizeModalView.java diff --git a/application-admintools-test/application-admintools-test-docker/src/test/it/com/xwiki/admintools/test/ui/AdminToolsIT.java b/application-admintools-test/application-admintools-test-docker/src/test/it/com/xwiki/admintools/test/ui/AdminToolsIT.java index 8447610..a78afe6 100644 --- a/application-admintools-test/application-admintools-test-docker/src/test/it/com/xwiki/admintools/test/ui/AdminToolsIT.java +++ b/application-admintools-test/application-admintools-test-docker/src/test/it/com/xwiki/admintools/test/ui/AdminToolsIT.java @@ -21,6 +21,7 @@ import java.util.Arrays; import java.util.List; +import java.util.Objects; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -29,25 +30,31 @@ import org.junit.jupiter.api.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; import org.xwiki.model.reference.DocumentReference; import org.xwiki.panels.test.po.ApplicationsPanel; import org.xwiki.test.docker.junit5.TestConfiguration; import org.xwiki.test.docker.junit5.UITest; +import org.xwiki.test.docker.junit5.servletengine.ServletEngine; import org.xwiki.test.ui.TestUtils; import org.xwiki.test.ui.po.ViewPage; import com.xwiki.admintools.test.po.AdminToolsHomePage; import com.xwiki.admintools.test.po.DashboardConfigurationSectionView; import com.xwiki.admintools.test.po.DashboardFilesSectionView; +import com.xwiki.admintools.test.po.DashboardHealthSectionView; +import com.xwiki.admintools.test.po.DashboardUsageSectionView; import com.xwiki.admintools.test.po.DownloadArchiveModalView; +import com.xwiki.admintools.test.po.FlushCacheModalView; import com.xwiki.admintools.test.po.LastNLinesModalView; +import com.xwiki.admintools.test.po.WikisSizeModalView; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -@UITest +@UITest(servletEngine = ServletEngine.TOMCAT, servletEngineTag = "8") class AdminToolsIT { private static final List supportedServers = List.of("TOMCAT"); @@ -78,7 +85,7 @@ static void setUp(TestUtils setup) // have given that Admin user the admin right directly but the solution we chose is closer to the XS // distribution. setup.loginAsSuperAdmin(); - setup.setGlobalRights("XWiki.XWikiAdminGroup", "", "admin", true); + setup.setGlobalRights("XWiki.XWikiAdminGroup", "", "admin,programming", true); setup.createAdminUser(); setup.loginAsAdmin(); } @@ -180,13 +187,65 @@ void adminToolDownloadArchiveModal() @Test @Order(6) + void adminToolsHealthSection(TestUtils testUtils) + { + DashboardHealthSectionView healthSectionView = AdminToolsHomePage.getHealthSection(); + + WebElement healthJobButton = healthSectionView.getHealthJobStartButton(); + healthJobButton.click(); + assertFalse(healthJobButton.isEnabled()); + testUtils.getDriver().waitUntilElementIsEnabled(healthJobButton); + AdminToolsHomePage.gotoPage(); + + // Because the health check result is inserted at runtime by a velocity script, the testUtils fails to select + // the result message element. Therefore, it's necessary to select the text from the entire content. + WebElement healthCheckResult = healthSectionView.getHealthContent(); + List messages = List.of("Critical issues were found, please consult the results below!", + "Some issues have been found, for more details please see the results below.", "No issue found!"); + + boolean rightResult = messages.stream().anyMatch(healthCheckResult.getText()::contains); + assertTrue(rightResult); + + WebElement logs = healthSectionView.getLogs(); + assertFalse(logs.isDisplayed()); + healthSectionView.clickResultsToggle(); + assertTrue(logs.isDisplayed()); + + FlushCacheModalView flushCacheModalView = healthSectionView.clickFlushCacheHyperlink(); + assertTrue(flushCacheModalView.isDisplayed()); + flushCacheModalView.clickConfirmButton(); + testUtils.getDriver() + .waitUntilCondition(ExpectedConditions.visibilityOfElementLocated(By.className("xnotification-container"))); + WebElement alert = testUtils.getDriver().findElement(By.className("xnotification-container")); + assertEquals("Cache flushed successfully.", alert.getText()); + assertFalse(flushCacheModalView.isDisplayed()); + + flushCacheModalView = healthSectionView.clickFlushCacheHyperlink(); + flushCacheModalView.clickCancelButton(); + assertFalse(flushCacheModalView.isDisplayed()); + } + + @Test + @Order(7) + void adminToolsUsageSection(TestUtils testUtils) + { + DashboardUsageSectionView usageSectionView = AdminToolsHomePage.getInstanceUsageSection(); + WikisSizeModalView sizeModalView = usageSectionView.getWikisSizeModal(); + assertTrue(sizeModalView.isDisplayed()); + List sizeRows = sizeModalView.getTableRows(); + for (WebElement row : sizeRows) { + assertFalse(row.getText().contains("null")); + } + } + + @Test + @Order(8) void adminToolsHomePageFilesNotAdmin(TestUtils testUtils) { testUtils.login(USER_NAME, PASSWORD); WebElement filesSectionNonAdminView = AdminToolsHomePage.gotoPage().getNonAdminUserView(); - assertTrue(filesSectionNonAdminView.getText().contains( - "Access denied due to missing admin rights!")); + assertTrue(filesSectionNonAdminView.getText().contains("Access denied due to missing admin rights!")); } /** diff --git a/application-admintools-test/application-admintools-test-pageobjects/src/main/java/com/xwiki/admintools/test/po/AdminToolsHomePage.java b/application-admintools-test/application-admintools-test-pageobjects/src/main/java/com/xwiki/admintools/test/po/AdminToolsHomePage.java index b7898b4..9ff930e 100644 --- a/application-admintools-test/application-admintools-test-pageobjects/src/main/java/com/xwiki/admintools/test/po/AdminToolsHomePage.java +++ b/application-admintools-test/application-admintools-test-pageobjects/src/main/java/com/xwiki/admintools/test/po/AdminToolsHomePage.java @@ -61,6 +61,18 @@ public static DashboardFilesSectionView getFilesSection() return new DashboardFilesSectionView(); } + public static DashboardHealthSectionView getHealthSection() + { + gotoPage(); + return new DashboardHealthSectionView(); + } + + public static DashboardUsageSectionView getInstanceUsageSection() + { + gotoPage(); + return new DashboardUsageSectionView(); + } + /** * Check if the page is the same as Admin Tools WebHome. */ diff --git a/application-admintools-test/application-admintools-test-pageobjects/src/main/java/com/xwiki/admintools/test/po/DashboardHealthSectionView.java b/application-admintools-test/application-admintools-test-pageobjects/src/main/java/com/xwiki/admintools/test/po/DashboardHealthSectionView.java new file mode 100644 index 0000000..754d94c --- /dev/null +++ b/application-admintools-test/application-admintools-test-pageobjects/src/main/java/com/xwiki/admintools/test/po/DashboardHealthSectionView.java @@ -0,0 +1,65 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package com.xwiki.admintools.test.po; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.xwiki.test.ui.po.ViewPage; + +public class DashboardHealthSectionView extends ViewPage +{ + @FindBy(css = "#healthCheck") + private WebElement healthContent; + + @FindBy(css = "a[href='#confirmCacheFlushModal']") + private WebElement flushCacheModalHyperlink; + + public WebElement getHealthJobStartButton() + { + return healthContent.findElement(By.id("healthCheckJobStart")); + } + + public WebElement getResult() + { + return healthContent.findElement(By.className("health-check-result-message")); + } + + public WebElement getHealthContent() + { + return healthContent; + } + + public void clickResultsToggle() + { + healthContent.findElement(By.className("collapse-toggle")).click(); + } + + public WebElement getLogs() + { + return healthContent.findElement(By.className("log")); + } + + public FlushCacheModalView clickFlushCacheHyperlink() + { + flushCacheModalHyperlink.click(); + return new FlushCacheModalView(By.id("confirmCacheFlushModal")); + } +} diff --git a/application-admintools-test/application-admintools-test-pageobjects/src/main/java/com/xwiki/admintools/test/po/DashboardUsageSectionView.java b/application-admintools-test/application-admintools-test-pageobjects/src/main/java/com/xwiki/admintools/test/po/DashboardUsageSectionView.java new file mode 100644 index 0000000..a7e9256 --- /dev/null +++ b/application-admintools-test/application-admintools-test-pageobjects/src/main/java/com/xwiki/admintools/test/po/DashboardUsageSectionView.java @@ -0,0 +1,40 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package com.xwiki.admintools.test.po; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.xwiki.test.ui.po.ViewPage; + +public class DashboardUsageSectionView extends ViewPage +{ + @FindBy(css = ".wiki-size-section") + private WebElement instanceUsageContent; + + @FindBy(css = "a[href='#viewWikisSizeModal']") + private WebElement wikiSizeModalHyperlink; + + public WikisSizeModalView getWikisSizeModal() + { + wikiSizeModalHyperlink.click(); + return new WikisSizeModalView(By.id("viewWikisSizeModal")); + } +} diff --git a/application-admintools-test/application-admintools-test-pageobjects/src/main/java/com/xwiki/admintools/test/po/FlushCacheModalView.java b/application-admintools-test/application-admintools-test-pageobjects/src/main/java/com/xwiki/admintools/test/po/FlushCacheModalView.java new file mode 100644 index 0000000..3793362 --- /dev/null +++ b/application-admintools-test/application-admintools-test-pageobjects/src/main/java/com/xwiki/admintools/test/po/FlushCacheModalView.java @@ -0,0 +1,46 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package com.xwiki.admintools.test.po; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.xwiki.test.ui.po.BaseModal; + +public class FlushCacheModalView extends BaseModal +{ + @FindBy(css = "div#confirmCacheFlushModal") + public WebElement content; + + public FlushCacheModalView(By selector) + { + super(selector); + } + + public void clickConfirmButton() + { + content.findElement(By.cssSelector("#confirmCacheFlushModal .btn-primary")).click(); + } + + public void clickCancelButton() + { + content.findElement(By.cssSelector("#confirmCacheFlushModal .btn-default")).click(); + } +} diff --git a/application-admintools-test/application-admintools-test-pageobjects/src/main/java/com/xwiki/admintools/test/po/WikisSizeModalView.java b/application-admintools-test/application-admintools-test-pageobjects/src/main/java/com/xwiki/admintools/test/po/WikisSizeModalView.java new file mode 100644 index 0000000..35147af --- /dev/null +++ b/application-admintools-test/application-admintools-test-pageobjects/src/main/java/com/xwiki/admintools/test/po/WikisSizeModalView.java @@ -0,0 +1,48 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package com.xwiki.admintools.test.po; + +import java.util.List; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.xwiki.test.ui.po.BaseModal; + +public class WikisSizeModalView extends BaseModal +{ + @FindBy(css = "div#viewWikisSizeModal") + public WebElement content; + + public WikisSizeModalView(By selector) + { + super(selector); + } + + public void clickCancelButton() + { + content.findElement(By.cssSelector("#viewWikisSizeModal .btn-default")).click(); + } + + public List getTableRows() + { + return content.findElements(By.cssSelector("table > tbody > tr")); + } +} \ No newline at end of file