Skip to content

Commit

Permalink
Add functional tests xwikisas#16
Browse files Browse the repository at this point in the history
* Modified comments
* Split AdminToolsViewPage in different classes specialized in different dashboard sections
* Modified Page object selectors
* Added test execution condition
* Modifed page objects functions and interaction
  • Loading branch information
ChiuchiuSorin committed Dec 13, 2023
1 parent c2116d0 commit 214479e
Show file tree
Hide file tree
Showing 18 changed files with 621 additions and 541 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@

import org.apache.commons.lang.exception.ExceptionUtils;
import org.xwiki.activeinstalls2.internal.data.DatabasePing;
import org.xwiki.activeinstalls2.internal.data.ServletContainerPing;
import org.xwiki.component.annotation.Component;

import com.xpn.xwiki.XWiki;
import com.xpn.xwiki.XWikiContext;
import com.xwiki.admintools.ServerIdentifier;
import com.xwiki.admintools.internal.data.identifiers.CurrentServer;
import com.xwiki.admintools.internal.PingProvider;
import com.xwiki.admintools.internal.data.identifiers.CurrentServer;

/**
* Extension of {@link AbstractDataProvider} for retrieving configuration data.
Expand Down Expand Up @@ -94,9 +95,9 @@ public Map<String, String> getDataAsJSON() throws Exception
systemInfo.put("serverPath", getCurrentServer().getServerPath());
systemInfo.put("tomcatConfPath", this.getCurrentServer().getServerCfgPath());
systemInfo.put("javaVersion", this.getJavaVersion());
Map<String, String> serverMetadata = this.currentServer.getServerMetadata();
systemInfo.put("usedServerName", serverMetadata.get(METADATA_NAME));
systemInfo.put("usedServerVersion", serverMetadata.get(METADATA_VERSION));
ServletContainerPing currentServerMetadata = this.currentServer.getServerMetadata();
systemInfo.put("usedServerName", currentServerMetadata.getName());
systemInfo.put("usedServerVersion", currentServerMetadata.getVersion());
systemInfo.put("xwikiVersion", getXWikiVersion());
systemInfo.putAll(this.getOSInfo());
return systemInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;
import javax.inject.Provider;
Expand Down Expand Up @@ -97,16 +96,13 @@ public List<String> getSupportedServers()
}

/**
* Access a JSON containing the server metadata.
* Access a {@link ServletContainerPing} containing the server metadata.
*
* @return the server metadata.
*/
public Map<String, String> getServerMetadata()
public ServletContainerPing getServerMetadata()
{
ServletContainerPing servletPing = pingProvider.getServletPing();
String serverName = servletPing.getName();
String serverVersion = servletPing.getVersion();
return Map.of(SERVER_NAME_KEY, serverName, SERVER_VERSION_KEY, serverVersion);
return pingProvider.getServletPing();
}

/**
Expand All @@ -117,7 +113,7 @@ public void updateCurrentServer()
this.currentServerIdentifier = null;
for (ServerIdentifier serverIdentifier : this.supportedServers.get()) {
boolean matchingHint =
getServerMetadata().get(SERVER_NAME_KEY).toLowerCase().contains(serverIdentifier.getComponentHint());
getServerMetadata().getName().toLowerCase().contains(serverIdentifier.getComponentHint());
if (matchingHint && serverIdentifier.foundServerPath()) {
this.currentServerIdentifier = serverIdentifier;
this.currentServerIdentifier.updatePossiblePaths();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import javax.inject.Named;
import javax.inject.Singleton;

import org.apache.commons.lang.StringUtils;
import org.xwiki.component.annotation.Component;

import com.xwiki.admintools.ServerIdentifier;
Expand Down Expand Up @@ -86,14 +87,14 @@ public boolean foundServerPath()
{
this.serverPath = null;
String providedConfigServerPath = this.adminToolsConfig.getServerPath();
if (providedConfigServerPath != null && !providedConfigServerPath.isEmpty()) {
if (!StringUtils.isEmpty(providedConfigServerPath)) {
return checkAndSetServerPath(providedConfigServerPath);
} else {
String catalinaBase = System.getProperty("catalina.base");
String catalinaHome = System.getenv("CATALINA_HOME");
if (catalinaBase != null && !catalinaBase.isEmpty()) {
if (!StringUtils.isEmpty(catalinaBase)) {
return checkAndSetServerPath(catalinaBase);
} else if (catalinaHome != null && !catalinaHome.isEmpty()) {
} else if (!StringUtils.isEmpty(catalinaHome)) {
return checkAndSetServerPath(catalinaHome);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
#includeMacros("AdminTools.Code.Macros")
#viewLastNLinesMoldal("configuration")
#if ($configuration['serverFound'] == 'true')
<div id="adminToolsBackendSection" class="adminToolsDashboardItem">
<div class="admin-tools-dashboard-item backend-section">
<h2>$services.icon.renderHTML('world')
$escapetool.xml($services.localization.render('adminTools.dashboard.section.backend.title'))</h2>
<p>$escapetool.xml($services.localization.render('adminTools.dashboard.section.backend.description'))</p>
<hr/>
<ul>
<li>
$escapetool.xml($services.localization.render('adminTools.dashboard.section.backend.xwiki.version')):
$configuration['xwikiVersion']
$escapetool.xml($services.localization.render('adminTools.dashboard.section.backend.xwiki.version',
[$configuration.xwikiVersion]))
</li>
<ul>
<li>
Expand All @@ -40,54 +40,46 @@
</li>
</ul>
<li>
$escapetool.xml($services.localization.render('adminTools.dashboard.section.backend.java')):
$configuration['javaVersion']
$escapetool.xml($services.localization.render('adminTools.dashboard.section.backend.java',
[$configuration.javaVersion]))
</li>
<li>
$escapetool.xml($services.localization.render('adminTools.dashboard.section.backend.usedServer'))
$configuration['usedServerName'] - $configuration['usedServerVersion']
$escapetool.xml($services.localization.render('adminTools.dashboard.section.backend.usedServer',
[$configuration.usedServerName, $configuration.usedServerVersion]))
</li>
<li>$escapetool.xml($services.localization.render('adminTools.dashboard.section.backend.os.legend'))
<ul>
<li>$escapetool.xml($services.localization.render('adminTools.dashboard.section.backend.os.name')):
$configuration['osName']</li>
<li>$escapetool.xml($services.localization.render('adminTools.dashboard.section.backend.os.version')):
$configuration['osVersion']</li>
<li>$escapetool.xml($services.localization.render('adminTools.dashboard.section.backend.os.architecture')):
$configuration['osArch']</li>
<li>$escapetool.xml($services.localization.render('adminTools.dashboard.section.backend.os.name',
$configuration.osName))</li>
<li>$escapetool.xml($services.localization.render('adminTools.dashboard.section.backend.os.version',
$configuration.osVersion))</li>
<li>$escapetool.xml($services.localization.render('adminTools.dashboard.section.backend.os.architecture',
$configuration.osArch))</li>
</ul>
</li>
#set($databaseName = $configuration['databaseName'])
#if ($databaseName != $null)
<li>$escapetool.xml($services.localization.render('adminTools.dashboard.section.backend.usedDB'))
$databaseName - $configuration['databaseVersion']</li>
#set ($supportedDatabases = $services.admintools.getSupportedDatabases())
#set($databaseName = $configuration.databaseName)
#if ("$databaseName" != '')
<li>$escapetool.xml($services.localization.render('adminTools.dashboard.section.backend.usedDB',
[$databaseName, $configuration.databaseVersion]))</li>
#set ($isSupported = false)
#databaseIsSupported($databaseName $supportedDatabases $isSupported)
#databaseIsSupported($databaseName $isSupported)
#if (!$isSupported)
#set($warningDatabaseMessage = $escapetool.xml(
$services.localization.render('adminTools.dashboard.section.backend.supportedDB.error')) + ':')
#set($warningDatabaseMessage = $warningDatabaseMessage +
$stringtool.join($supportedDatabases, ', '))
#warning($warningDatabaseMessage)
#set($warningDatabaseMessage = $escapetool.xml($services.localization.render(
'adminTools.dashboard.section.backend.supportedDB.error', [$stringtool.join($supportedDatabases, ', ')]
)))
#warning($warningDatabaseMessage)
#end
#else
#set($warningDatabaseMessage = $escapetool.xml(
$services.localization.render('adminTools.dashboard.section.backend.supportedDB.error')) + ':')
#set($warningDatabaseMessage = $warningDatabaseMessage +
$stringtool.join($services.admintools.getSupportedDatabases(), ', '))
<li>$escapetool.xml(
$services.localization.render('adminTools.dashboard.section.backend.usedDB')) #warning($warningDatabaseMessage)
</li>
#set($warningDatabaseMessage = $escapetool.xml($services.localization.render(
'adminTools.dashboard.section.backend.supportedDB.error', [$stringtool.join($supportedDatabases, ', ')])))
#warning($warningDatabaseMessage)
#end
</ul>
</div>
#else
#set($warningMessage =
$escapetool.xml($services.localization.render('adminTools.dashboard.section.backend.configuration.error'))+ '<br>')
#set($warningMessage = $warningMessage +
$escapetool.xml($services.localization.render('adminTools.dashboard.section.backend.supportedServers.error')) + ':'
+ $stringtool.join($services.admintools.getSupportedServers(), ', '))
$escapetool.xml($services.localization.render('adminTools.dashboard.section.backend.configuration.error',
[$stringtool.join($services.admintools.getSupportedServers(), ', ')])))
#warning($warningMessage)
#end
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#includeMacros("AdminTools.Code.Macros")
#set($adminToolsFilesPath = "$request.getContextPath()/rest/admintools/files")
#if ($found)
<div id="adminToolsFilesSection" class="adminToolsDashboardItem">
<div class="admin-tools-dashboard-item files-section">
<h2>$services.icon.renderHTML('download')
$escapetool.xml($services.localization.render('adminTools.dashboard.section.download.title'))</h2>
<p>$escapetool.xml($services.localization.render('adminTools.dashboard.section.download.description'))</p>
Expand Down
Loading

0 comments on commit 214479e

Please sign in to comment.