Skip to content

Commit

Permalink
[MISC] Add functional tests xwikisas#16
Browse files Browse the repository at this point in the history
* added tests for health check section
* started tests for instance usage section
  • Loading branch information
ChiuchiuSorin committed Nov 25, 2024
1 parent ffa9b92 commit 71ebc08
Show file tree
Hide file tree
Showing 6 changed files with 274 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> supportedServers = List.of("TOMCAT");
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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<String> 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<WebElement> 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!"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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<WebElement> getTableRows()
{
return content.findElements(By.cssSelector("table > tbody > tr"));
}
}

0 comments on commit 71ebc08

Please sign in to comment.