[java-idp-integration-tests] 02/02: Improve readability
Tom Zeller
tzeller at dragonacea.biz
Thu Jan 5 13:54:43 UTC 2023
This is an automated email from the git hooks/post-receive script.
tzeller pushed a commit to branch main
in repository java-idp-integration-tests.
View the commit online:
http://git.shibboleth.net/view/?p=java-idp-integration-tests.git;a=commit;h=d5b5de64887ad570e1344a205ca53bd9db4cbb0f
commit d5b5de64887ad570e1344a205ca53bd9db4cbb0f
Author: Tom Zeller <tzeller at dragonacea.biz>
AuthorDate: Thu Jan 5 07:54:18 2023 -0600
Improve readability
---
.../idp/integration/tests/PluginTest.java | 115 ++++++++++++++++-----
1 file changed, 87 insertions(+), 28 deletions(-)
diff --git a/src/test/java/net/shibboleth/idp/integration/tests/PluginTest.java b/src/test/java/net/shibboleth/idp/integration/tests/PluginTest.java
index 66a4c6c..1a02417 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/PluginTest.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/PluginTest.java
@@ -65,8 +65,21 @@ public class PluginTest extends BaseIntegrationTest {
@Nonnull
final public String truststoresResource = "/net/shibboleth/idp/integration/tests/truststores/";
+ /**
+ * Set up paths to :
+ * <ul>
+ * <li>truststores directory</li>
+ * <li>IdP homea directory</li>
+ * <li>plugin CLI</li>
+ * <li>build CLI</li>
+ * </ul>
+ *
+ * @throws Exception
+ * if an error occurs
+ */
@BeforeClass
public void setUpPaths() throws Exception {
+
pathToTruststores = Paths.get(PluginTest.class.getResource(truststoresResource).getFile());
Assert.assertTrue(pathToTruststores.toAbsolutePath().toFile().exists());
@@ -91,15 +104,68 @@ public class PluginTest extends BaseIntegrationTest {
}
/**
- * Get plugins available to be installed.
+ * Assert that plugins are available to be installed.
+ *
+ * @param plugins
+ * plugins that should be available to be installed
+ * @throws IOException
+ * if an error occurs
+ * @throws SkipException
+ * if a plugin is not available to be installed
+ */
+ public void assertPluginsAreAvailable(@Nonnull final String... plugins) throws IOException, SkipException {
+ final List<String> availablePlugins = availablePlugins();
+ for (final String plugin : plugins) {
+ if (!availablePlugins.contains(plugin)) {
+ log.info("Skipping test because plugin {} is not available to be installed", plugin);
+ throw new SkipException("Plugin " + plugin + " not available");
+ }
+ }
+ }
+
+ /**
+ * Assert that plugins are installed.
+ *
+ * @param plugins
+ * plugins that should be installed
+ * @throws IOException
+ * if an error occurs
+ */
+ public void assertPluginsAreInstalled(@Nonnull final String... plugins) throws IOException {
+ final List<String> installedPlugins = installedPlugins();
+ for (final String plugin : plugins) {
+ Assert.assertTrue(installedPlugins.contains(plugin), "Plugin " + plugin + " is installed");
+ }
+ }
+
+ /**
+ * Assert that plugins are listed on the status page.
+ *
+ * @param plugins
+ * plugins that should be listed on the status page
+ * @throws Exception
+ * if an error occurs
+ */
+ public void assertPluginsAreOnStatusPage(@Nonnull final String... plugins) throws Exception {
+ final String statusPage = server.waitForStatusPage();
+ for (final String plugin : plugins) {
+ Assert.assertTrue(statusPage.contains(plugin), "Status page contains plugin " + plugin);
+ }
+ }
+
+ /**
+ * Get plugins available to be installed using the plugin CLI.
*
* @return plugins available to be installed
* @throws IOException
* if an error occurs
*/
public @Nonnull List<String> availablePlugins() throws IOException {
+
final List<String> availablePlugins = new ArrayList<>();
+
final Process process = Runtime.getRuntime().exec(pluginCLI + " -L", null, idpHome);
+
final BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";
while ((line = reader.readLine()) != null) {
@@ -121,12 +187,23 @@ public class PluginTest extends BaseIntegrationTest {
* if an error occurs
*/
public void buildWAR() throws IOException {
- logProcess(Runtime.getRuntime().exec(buildCLI + " -Didp.target.dir=" + idpHome, null, idpHome), "build:");
+
+ final String[] commands = new String[] {
+ buildCLI,
+ "-Didp.target.dir=" + idpHome };
+
+ final String logPrefix = "Build WAR :";
+
+ final Process process = Runtime.getRuntime().exec(commands, null, idpHome);
+
+ logProcess(process, logPrefix);
}
/**
* Install plugin.
*
+ * Does not rebuild WAR.
+ *
* @param plugin
* plugin to be installed
* @throws IOException
@@ -178,8 +255,11 @@ public class PluginTest extends BaseIntegrationTest {
* if an error occurs
*/
public @Nonnull List<String> installedPlugins() throws IOException {
+
final List<String> installedPlugins = new ArrayList<>();
+
final Process process = Runtime.getRuntime().exec(pluginCLI + " -l", null, idpHome);
+
final BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";
while ((line = reader.readLine()) != null) {
@@ -196,42 +276,21 @@ public class PluginTest extends BaseIntegrationTest {
@Test(dataProvider = "sauceOnDemandBrowserDataProvider")
public void testInstallingOIDC(@Nullable final BrowserData browserData) throws Exception {
- startSeleniumClient(browserData);
-
- final String[] pluginsToInstall = new String[] {
+ final String[] plugins = new String[] {
"net.shibboleth.oidc.common",
"net.shibboleth.idp.plugin.oidc.op" };
- final List<String> availablePlugins = availablePlugins();
+ assertPluginsAreAvailable(plugins);
- for (final String pluginToInstall : pluginsToInstall) {
- if (!availablePlugins.contains(pluginToInstall)) {
- log.info("Skipping test because plugin {} is not available to be installed", pluginToInstall);
- throw new SkipException("Plugin " + pluginToInstall + " not available");
- }
- }
+ installPlugins(plugins);
- installPlugins(pluginsToInstall);
-
- final List<String> installedPlugins = installedPlugins();
-
- for (final String pluginToInstall : pluginsToInstall) {
- Assert.assertTrue(installedPlugins.contains(pluginToInstall), "Plugin " + pluginToInstall + " is enabled");
- }
+ assertPluginsAreInstalled(plugins);
buildWAR();
startServer();
- driver.get(getBaseURL() + StatusTest.statusPath);
-
- final String statusPage = getPageSource();
-
- Assert.assertTrue(statusPage.startsWith(StatusTest.STARTS_WITH));
-
- for (final String pluginToInstall : pluginsToInstall) {
- Assert.assertTrue(statusPage.contains(pluginToInstall), "Status page contains plugin " + pluginToInstall);
- }
+ assertPluginsAreOnStatusPage(plugins);
}
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list