[java-identity-provider] 04/05: Update Plugin tests

Rod Widdowson rdw at steadingsoftware.com
Thu Jul 30 15:33:05 UTC 2020


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch master
in repository java-identity-provider.

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=6416e64ea1a1e7a4f72ff17a272206aa615ab5a2

commit 6416e64ea1a1e7a4f72ff17a272206aa615ab5a2
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Thu Jul 30 16:12:21 2020 +0100

    Update Plugin tests
    
    1) Build our own per testrun idp-home to test with
    2) Enable the test listing test
    3) Install plugins from disribution (disabled because of bug in distribution).
---
 .../idp/installer/plugin/BasePluginTest.java       | 97 ++++++++++++++++++++++
 .../installer/plugin/impl/PluginInstallerTest.java | 33 ++++----
 2 files changed, 114 insertions(+), 16 deletions(-)

diff --git a/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/BasePluginTest.java b/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/BasePluginTest.java
new file mode 100644
index 000000000..464a3f072
--- /dev/null
+++ b/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/BasePluginTest.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.idp.installer.plugin;
+
+import java.io.IOException;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.core.io.ClassPathResource;
+import org.testng.annotations.AfterSuite;
+import org.testng.annotations.BeforeSuite;
+
+/**
+ * set up state for testing.
+ */
+ at SuppressWarnings("javadoc")
+public class BasePluginTest {
+
+    private static Logger log = LoggerFactory.getLogger(BasePluginTest.class);
+    private static Path idpHome;
+    
+    @BeforeSuite public void setupIdpHome() throws IOException {
+        idpHome = Files.createTempDirectory("PluginTests");
+        Path from = new ClassPathResource("idphome-test").getFile().toPath();
+        Files.walkFileTree(from, new SimpleFileVisitor<Path>() {
+            @Override
+            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
+                Path rel = from.relativize(dir);
+                Path to = idpHome.resolve(rel);
+                if (!Files.exists(to)) {
+                    log.trace("Creating directory {}", to);
+                    Files.createDirectory(to);
+                }
+                return FileVisitResult.CONTINUE;
+            };
+            @Override
+            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
+                Path rel = from.relativize(file);
+                Path to = idpHome.resolve(rel);
+                log.trace("Copying from {} to {}", file, to);
+                Files.copy(file,  to);
+                return FileVisitResult.CONTINUE;
+            }
+        });
+    }
+    
+    @AfterSuite public void teardownIdPHome() throws IOException {
+        
+        if (idpHome == null) {
+            return;
+        }
+        
+        Files.walkFileTree(idpHome, new SimpleFileVisitor<Path>() {
+            /** {@inheritDoc} */
+            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
+                Files.delete(file);
+                return FileVisitResult.CONTINUE;
+            }
+            
+            /** {@inheritDoc} */
+            public FileVisitResult postVisitDirectory(Path directory, IOException exc) throws IOException {
+                try {
+                    Files.delete(directory);
+                }
+                catch (final IOException foo) {
+                    log.warn("Problem cleaning up {}",directory, foo);
+                }
+                return FileVisitResult.CONTINUE;
+            }
+        });
+    }
+
+    protected Path getIdpHome() {
+        return idpHome;
+    }
+
+}
diff --git a/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerTest.java b/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerTest.java
index 264765230..9a53114ff 100644
--- a/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerTest.java
+++ b/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/PluginInstallerTest.java
@@ -19,7 +19,6 @@ package net.shibboleth.idp.installer.plugin.impl;
 
 import static org.testng.Assert.assertEquals;
 
-import java.io.File;
 import java.io.IOException;
 import java.net.URL;
 import java.nio.file.Path;
@@ -30,17 +29,17 @@ import java.util.function.Predicate;
 import org.bouncycastle.jce.provider.BouncyCastleProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.core.io.ClassPathResource;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
+import net.shibboleth.idp.installer.plugin.BasePluginTest;
 import net.shibboleth.idp.plugin.AbstractPluginDescription;
 import net.shibboleth.idp.plugin.PluginDescription;
 import net.shibboleth.utilities.java.support.collection.Pair;
 import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
 
 @SuppressWarnings("javadoc")
-public class PluginInstallerTest {
+public class PluginInstallerTest extends BasePluginTest {
 
     private final Logger log = LoggerFactory.getLogger(PluginInstallerTest.class);
     
@@ -64,10 +63,10 @@ public class PluginInstallerTest {
         }
     }
 
-    @Test(enabled = false) public void testListing() throws ComponentInitializationException, IOException {
+    @Test(enabled = true) public void testListing() throws ComponentInitializationException, IOException {
         
         try (final PluginInstaller inst = new PluginInstaller()) {
-            inst.setIdpHome(new ClassPathResource("idphome-test").getFile().toPath());
+            inst.setIdpHome(getIdpHome());
             inst.initialize();
             List<PluginDescription> plugins = inst.getInstalledPlugins();
             assertEquals(plugins.get(0).getPluginId(), "org.example.Plugin");
@@ -76,37 +75,39 @@ public class PluginInstallerTest {
     
     @Test(enabled = false) public void testUnpackZip() throws ComponentInitializationException, IOException {
         try (final PluginInstaller inst = new PluginInstaller()) {
-            inst.setIdpHome(new ClassPathResource("idphome-test").getFile().toPath());
+            inst.setIdpHome(getIdpHome());
             inst.setAcceptCert(loggingAcceptCert);
             inst.setAcceptDownload(loggingAcceptDownLoad);
             inst.initialize();
-            final File f = new File("H:\\Perforce\\Juno\\New\\plugins\\java-idp-plugin-scripting\\rhino-dist\\target");
-            inst.installPlugin(f.toPath(),"shibboleth-idp-plugin-rhino-0.0.1-SNAPSHOT.zip");
+            final URL where = new URL("https://build.shibboleth.net/nexus/service/local/repositories/releases/content/net/shibboleth/idp/plugin/scripting/idp-plugin-nashorn-dist/0.1.0/");
+            inst.installPlugin(where,"idp-plugin-nashorn-dist-0.1.0.zip");
         }
     }
     
-    @Test(enabled = false) public void testUnpackTgz() throws ComponentInitializationException, IOException {
+    @Test(enabled = false) public void testUnpackZipFile() throws ComponentInitializationException, IOException {
         try (final PluginInstaller inst = new PluginInstaller()) {
-            inst.setIdpHome(new ClassPathResource("idphome-test").getFile().toPath());
+            inst.setIdpHome(getIdpHome());
             inst.setAcceptCert(loggingAcceptCert);
             inst.setAcceptDownload(loggingAcceptDownLoad);
             inst.initialize();
-            final File f = new File("H:\\Perforce\\Juno\\New\\plugins\\java-idp-plugin-scripting\\nashorn-dist\\target");
-            inst.installPlugin(f.toPath(),"shibboleth-idp-plugin-nashorn-0.0.1-SNAPSHOT.tar.gz");
+            final Path dir = Path.of("H:\\Perforce\\Juno\\New\\plugins\\java-idp-plugin-scripting\\rhino-dist\\target");
+            inst.installPlugin(dir,"shibboleth-idp-plugin-rhino-0.1.0-SNAPSHOT.zip");
         }
     }
 
-    @Test(enabled = false) public void testDownload() throws ComponentInitializationException, IOException {
+    
+    @Test(enabled = false) public void testUnpackTgz() throws ComponentInitializationException, IOException {
         try (final PluginInstaller inst = new PluginInstaller()) {
-            inst.setIdpHome(new ClassPathResource("idphome-test").getFile().toPath());
+            inst.setIdpHome(getIdpHome());
             inst.setAcceptCert(loggingAcceptCert);
             inst.setAcceptDownload(loggingAcceptDownLoad);
             inst.initialize();
-            final URL url = new URL("http://iis.steadingsoftware.net/plugins/");
-            inst.installPlugin(url,"shibboleth-idp-plugin-nashorn-0.0.1-SNAPSHOT.tar.gz");
+            final URL where = new URL("https://build.shibboleth.net/nexus/service/local/repositories/releases/content/net/shibboleth/idp/plugin/scripting/idp-plugin-rhino-dist/0.1.0/");
+            inst.installPlugin(where,"idp-plugin-rhino-dist-0.1.0.zip");
         }
     }
 
+
     public static class Wibble extends AbstractPluginDescription {
 
         /** {@inheritDoc} */

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list