[java-idp-integration-tests] branch main updated: Move plugin helper methods to base test class

Tom Zeller tzeller at dragonacea.biz
Mon Feb 19 13:58:35 UTC 2024


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=bc0222f7f83f4ee6126dfbea227446b5f41c55e4

The following commit(s) were added to refs/heads/main by this push:
     new bc0222f  Move plugin helper methods to base test class
bc0222f is described below

commit bc0222f7f83f4ee6126dfbea227446b5f41c55e4
Author: Tom Zeller <tzeller at dragonacea.biz>
AuthorDate: Mon Feb 19 07:58:17 2024 -0600

    Move plugin helper methods to base test class
---
 .../idp/integration/tests/BaseIntegrationTest.java | 231 ++++++++++++++++++++
 .../integration/tests/plugins/BasePluginTest.java  | 239 ---------------------
 2 files changed, 231 insertions(+), 239 deletions(-)

diff --git a/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java b/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java
index 73475eb..95ac6ad 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/BaseIntegrationTest.java
@@ -94,6 +94,7 @@ import org.springframework.core.io.Resource;
 import org.springframework.util.FileSystemUtils;
 import org.testng.Assert;
 import org.testng.ITestResult;
+import org.testng.SkipException;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.AfterSuite;
@@ -419,6 +420,14 @@ public abstract class BaseIntegrationTest {
     /** Route 53 helper to create and delete DNS records. */
     @Nullable private Route53Helper route53;
 
+    /** Path to truststores directory */
+    @Nonnull
+    protected Path pathToTruststores;
+
+    /** Truststores directory resource */
+    @Nonnull
+    final public String truststoresResource = "/net/shibboleth/idp/integration/tests/truststores/";
+
     /** Class logger. */
     @Nonnull private final Logger log = LoggerFactory.getLogger(BaseIntegrationTest.class);
 
@@ -2839,4 +2848,226 @@ public abstract class BaseIntegrationTest {
         driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(seconds));
     }
 
+    /**
+     * 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 + " should be installed");
+        }
+    }
+
+    /**
+     * Assert that plugins are not installed.
+     * 
+     * @param plugins
+     *            plugins that should be not installed
+     * @throws IOException
+     *             if an error occurs
+     */
+    public void assertPluginsAreNotInstalled(@Nonnull final String... plugins) throws IOException {
+        final List<String> installedPlugins = installedPlugins();
+        for (final String plugin : plugins) {
+            Assert.assertFalse(installedPlugins.contains(plugin), "Plugin " + plugin + " should not be 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 should contain plugin " + plugin);
+        }
+    }
+
+    /**
+     * Assert that plugins are not listed on the status page.
+     * 
+     * @param plugins
+     *            plugins that should be listed on the status page
+     * @throws Exception
+     *             if an error occurs
+     */
+    public void assertPluginsAreNotOnStatusPage(@Nonnull final String... plugins) throws Exception {
+        final String statusPage = server.waitForStatusPage();
+        for (final String plugin : plugins) {
+            Assert.assertFalse(statusPage.contains(plugin), "Status page should not contain 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) {
+            // line should be something like :
+            // Plugin net.shibboleth.idp.plugin.oidc.op: version 3.3.0 available for install
+            log.trace("Available plugins : {}", line);
+            final String[] strings = line.split("\\s+");
+
+            // TODO line.matches(available for install)
+            if (strings.length == 7 && strings[4].matches(".*available.*")) {
+                final String pluginName = strings[1].replaceAll(":$", "");
+                availablePlugins.add(pluginName);
+            }
+        }
+        return availablePlugins;
+    }
+
+    /**
+     * Set up path to plugin truststores directory.
+     */
+    @BeforeClass
+    public void setUpPathToPluginTruststores() {
+        pathToTruststores = new File(getClass().getResource(truststoresResource).getFile()).toPath();
+        Assert.assertTrue(pathToTruststores.toAbsolutePath().toFile().exists());
+    }
+
+    /**
+     * Install plugin.
+     * 
+     * Does not rebuild WAR.
+     * 
+     * @param plugin
+     *            plugin to be installed
+     * @throws IOException
+     *             if an error occurs
+     */
+    public void installPlugin(@Nonnull final String plugin) throws IOException {
+
+        final Path pathToTruststore = pathToTruststores.resolve(plugin).resolve("truststore.asc").toAbsolutePath();
+
+        assert pathToTruststore.toFile().exists() : "Path to truststore " + pathToTruststore + "should exist";
+
+        final String truststore = pathToTruststore.toString();
+
+        final String[] commands = new String[] { //
+                pluginCLI, //
+                "--noRebuild", //
+                "--noPrompt", //
+                "-I", plugin, //
+                "--truststore", truststore };
+
+        log.debug("Install plugin '{}'", plugin);
+
+        final Process process = new ProcessBuilder() //
+                .command(commands)
+                .directory(idpHome)
+                .start();
+
+        logProcess(process, "Install plugin :");
+    }
+
+    /**
+     * Install plugins.
+     * 
+     * @param plugins
+     *            plugins to be installed
+     * @throws IOException
+     *             if an error occurs
+     */
+    public void installPlugins(@Nonnull final String... plugins) throws IOException {
+        for (final String plugin : plugins) {
+            installPlugin(plugin);
+        }
+    }
+
+    /**
+     * Get installed plugins using plugin CLI.
+     * 
+     * @return installed plugins
+     * @throws IOException
+     *             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) {
+            // line should be something like :
+            // Plugin: net.shibboleth.idp.plugin.rhino Current Version: 1.0.0
+            log.trace("Installed plugins : {}", line);
+            final String[] strings = line.split("\\s+");
+            if (strings.length == 5) {
+                installedPlugins.add(strings[1]);
+            }
+        }
+        return installedPlugins;
+    }
+
+    /**
+     * Remove plugin.
+     * 
+     * Does not rebuild WAR.
+     * 
+     * @param plugin
+     *            plugin to be installed
+     * @throws IOException
+     *             if an error occurs
+     */
+    public void removePlugin(@Nonnull final String plugin) throws IOException {
+
+        final String[] commands = new String[] { pluginCLI, //
+                "--noRebuild", //
+                "--noPrompt", //
+                "-r", plugin };
+
+        log.debug("Remove plugin '{}'", plugin);
+
+        final Process process = new ProcessBuilder() //
+                .command(commands)
+                .directory(idpHome)
+                .start();
+
+        logProcess(process, "Remove plugin :");
+    }
+
 }
diff --git a/src/test/java/net/shibboleth/idp/integration/tests/plugins/BasePluginTest.java b/src/test/java/net/shibboleth/idp/integration/tests/plugins/BasePluginTest.java
index 0fec929..45ed31b 100644
--- a/src/test/java/net/shibboleth/idp/integration/tests/plugins/BasePluginTest.java
+++ b/src/test/java/net/shibboleth/idp/integration/tests/plugins/BasePluginTest.java
@@ -17,20 +17,10 @@
 
 package net.shibboleth.idp.integration.tests.plugins;
 
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.List;
-
 import javax.annotation.Nonnull;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.testng.Assert;
-import org.testng.SkipException;
 import org.testng.annotations.BeforeClass;
 
 import net.shibboleth.idp.integration.tests.BaseIntegrationTest;
@@ -44,23 +34,6 @@ public abstract class BasePluginTest extends BaseIntegrationTest {
     @Nonnull
     protected final Logger log = LoggerFactory.getLogger(BasePluginTest.class);
 
-    /** Path to truststores directory */
-    @Nonnull
-    protected Path pathToTruststores;
-
-    /** Truststores directory resource */
-    @Nonnull
-    final public String truststoresResource = "/net/shibboleth/idp/integration/tests/truststores/";
-
-    /**
-     * Set up path to truststores directory.
-     */
-    @BeforeClass
-    public void setUpPaths() {
-        pathToTruststores = new File(getClass().getResource(truststoresResource).getFile()).toPath();
-        Assert.assertTrue(pathToTruststores.toAbsolutePath().toFile().exists());
-    }
-
     /**
      * Enable all IdP modules.
      * 
@@ -74,216 +47,4 @@ public abstract class BasePluginTest extends BaseIntegrationTest {
         assertModulesAreEnabled(modulesToEnable);
     }
 
-    /**
-     * 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 + " should be installed");
-        }
-    }
-
-    /**
-     * Assert that plugins are not installed.
-     * 
-     * @param plugins
-     *            plugins that should be not installed
-     * @throws IOException
-     *             if an error occurs
-     */
-    public void assertPluginsAreNotInstalled(@Nonnull final String... plugins) throws IOException {
-        final List<String> installedPlugins = installedPlugins();
-        for (final String plugin : plugins) {
-            Assert.assertFalse(installedPlugins.contains(plugin), "Plugin " + plugin + " should not be 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 should contain plugin " + plugin);
-        }
-    }
-
-    /**
-     * Assert that plugins are not listed on the status page.
-     * 
-     * @param plugins
-     *            plugins that should be listed on the status page
-     * @throws Exception
-     *             if an error occurs
-     */
-    public void assertPluginsAreNotOnStatusPage(@Nonnull final String... plugins) throws Exception {
-        final String statusPage = server.waitForStatusPage();
-        for (final String plugin : plugins) {
-            Assert.assertFalse(statusPage.contains(plugin), "Status page should not contain 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) {
-            // line should be something like :
-            // Plugin net.shibboleth.idp.plugin.oidc.op: version 3.3.0 available for install
-            log.trace("Available plugins : {}", line);
-            final String[] strings = line.split("\\s+");
-
-            // TODO line.matches(available for install)
-            if (strings.length == 7 && strings[4].matches(".*available.*")) {
-                final String pluginName = strings[1].replaceAll(":$", "");
-                availablePlugins.add(pluginName);
-            }
-        }
-        return availablePlugins;
-    }
-
-    /**
-     * Install plugin.
-     * 
-     * Does not rebuild WAR.
-     * 
-     * @param plugin
-     *            plugin to be installed
-     * @throws IOException
-     *             if an error occurs
-     */
-    public void installPlugin(@Nonnull final String plugin) throws IOException {
-
-        final Path pathToTruststore = pathToTruststores.resolve(plugin).resolve("truststore.asc").toAbsolutePath();
-
-        assert pathToTruststore.toFile().exists() : "Path to truststore " + pathToTruststore + "should exist";
-
-        final String truststore = pathToTruststore.toString();
-
-        final String[] commands = new String[] { //
-                pluginCLI, //
-                "--noRebuild", //
-                "--noPrompt", //
-                "-I", plugin, //
-                "--truststore", truststore };
-
-        log.debug("Install plugin '{}'", plugin);
-
-        final Process process = new ProcessBuilder() //
-                .command(commands)
-                .directory(idpHome)
-                .start();
-
-        logProcess(process, "Install plugin :");
-    }
-
-    /**
-     * Install plugins.
-     * 
-     * @param plugins
-     *            plugins to be installed
-     * @throws IOException
-     *             if an error occurs
-     */
-    public void installPlugins(@Nonnull final String... plugins) throws IOException {
-        for (final String plugin : plugins) {
-            installPlugin(plugin);
-        }
-    }
-
-    /**
-     * Get installed plugins using plugin CLI.
-     * 
-     * @return installed plugins
-     * @throws IOException
-     *             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) {
-            // line should be something like :
-            // Plugin: net.shibboleth.idp.plugin.rhino Current Version: 1.0.0
-            log.trace("Installed plugins : {}", line);
-            final String[] strings = line.split("\\s+");
-            if (strings.length == 5) {
-                installedPlugins.add(strings[1]);
-            }
-        }
-        return installedPlugins;
-    }
-
-    /**
-     * Remove plugin.
-     * 
-     * Does not rebuild WAR.
-     * 
-     * @param plugin
-     *            plugin to be installed
-     * @throws IOException
-     *             if an error occurs
-     */
-    public void removePlugin(@Nonnull final String plugin) throws IOException {
-
-        final String[] commands = new String[] { pluginCLI, //
-                "--noRebuild", //
-                "--noPrompt", //
-                "-r", plugin };
-
-        log.debug("Remove plugin '{}'", plugin);
-
-        final Process process = new ProcessBuilder() //
-                .command(commands)
-                .directory(idpHome)
-                .start();
-
-        logProcess(process, "Remove plugin :");
-    }
 }
\ 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