[java-identity-provider] branch master updated: IDP-1595 Test Framework for PluginCLI

Rod Widdowson rdw at steadingsoftware.com
Fri Jul 31 10:25:49 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=9ec8b3ec5660dcc73ff9c8f0428d93954eb00413

The following commit(s) were added to refs/heads/master by this push:
       new  9ec8b3ec5 IDP-1595 Test Framework for PluginCLI
9ec8b3ec5 is described below

commit 9ec8b3ec5660dcc73ff9c8f0428d93954eb00413
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Thu Jul 30 17:30:46 2020 +0100

    IDP-1595 Test Framework for PluginCLI
    
    https://issues.shibboleth.net/jira/browse/IDP-1595
---
 idp-installer/pom.xml                              | 20 ++++++---
 .../idp/installer/plugin/PluginInstallerCLI.java   | 29 ++++++++----
 .../idp/installer/plugin/BasePluginTest.java       |  7 ++-
 .../idp/installer/plugin/PluginCLITest.java        | 51 ++++++++++++++++++++++
 .../test/resources/idphome-test/conf/admin/gitkeep |  0
 5 files changed, 89 insertions(+), 18 deletions(-)

diff --git a/idp-installer/pom.xml b/idp-installer/pom.xml
index aa9f96420..cb0e5da29 100644
--- a/idp-installer/pom.xml
+++ b/idp-installer/pom.xml
@@ -106,10 +106,10 @@
             <artifactId>spring-core</artifactId>
         </dependency>
         
-	<dependency>
-	    <groupId>org.apache.httpcomponents</groupId>
-	    <artifactId>httpclient</artifactId>
-	</dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+        </dependency>
 
         <dependency>
             <groupId>org.bouncycastle</groupId>
@@ -122,12 +122,12 @@
             <artifactId>bcprov-jdk15on</artifactId>
         </dependency>
 
-	<dependency>
+        <dependency>
             <groupId>com.google.code.findbugs</groupId>
             <artifactId>jsr305</artifactId>
-	</dependency>
+	   </dependency>
 
-	<dependency>
+       <dependency>
             <groupId>com.google.guava</groupId>
             <artifactId>guava</artifactId>
         </dependency>
@@ -137,6 +137,12 @@
         <!-- Runtime Dependencies -->
 
         <!-- Test Dependencies -->
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>idp-conf</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>${opensaml.groupId}</groupId>
             <artifactId>opensaml-core</artifactId>
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerCLI.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerCLI.java
index 23383e4f0..3e944b1e7 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerCLI.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/PluginInstallerCLI.java
@@ -109,7 +109,6 @@ public final class PluginInstallerCLI extends AbstractCommandLine<PluginInstalle
     
     /** {@inheritDoc} */
     protected int doRun(final PluginInstallerArguments args) {
-        getLogger().warn("Starting");
         final int ret = super.doRun(args);
         if (ret != RC_OK) {
             return ret;
@@ -122,7 +121,8 @@ public final class PluginInstallerCLI extends AbstractCommandLine<PluginInstalle
                     return FileVisitResult.CONTINUE;
                 }
                 @Override 
-                public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttributes attrs) throws IOException {
+                public FileVisitResult preVisitDirectory(final Path dir,
+                        final BasicFileAttributes attrs) throws IOException {
                     getLogger().warn("Dire {}",dir);
                     return FileVisitResult.CONTINUE;
                 }
@@ -133,19 +133,30 @@ public final class PluginInstallerCLI extends AbstractCommandLine<PluginInstalle
         } 
         return ret;
     }
-    
-    /**
-     * CLI entry point.
+
+    /** Shim for CLI entry point: Allows the code to be run from a test.
+     *
+     * @return one of the predefines {@link AbstractCommandLine#RC_INIT},
+     * {@link AbstractCommandLine#RC_IO}, {@link AbstractCommandLine#RC_OK}
+     * or {@link AbstractCommandLine#RC_UNKNOWN}
+     *
      * @param args arguments
      */
-    public static void main(@Nonnull final String[] args) {
+    public static int runMain(@Nonnull final String[] args) {
         final PluginInstallerCLI cli = new PluginInstallerCLI();
         cli.setIdpHome(StringSupport.trimOrNull(System.getProperty("net.shibboleth.idp.cli.idp.home")));
         if (cli.getIdpHome() == null) {
-            System.exit(RC_INIT);
+            return RC_INIT;
         } else {
-            System.exit(cli.run(args));
+            return cli.run(args);
         }
     }
-
+    
+    /**
+     * CLI entry point.
+     * @param args arguments
+     */
+    public static void main(@Nonnull final String[] args) {
+        System.exit(runMain(args));
+    }
 }
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
index 464a3f072..c8524fd23 100644
--- 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
@@ -71,16 +71,19 @@ public class BasePluginTest {
         }
         
         Files.walkFileTree(idpHome, new SimpleFileVisitor<Path>() {
-            /** {@inheritDoc} */
+            @Override
             public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                 Files.delete(file);
+                log.trace("Deleted {}", file);
                 return FileVisitResult.CONTINUE;
             }
             
-            /** {@inheritDoc} */
+            @Override
             public FileVisitResult postVisitDirectory(Path directory, IOException exc) throws IOException {
                 try {
+                    log.trace("Deleting {}", directory);
                     Files.delete(directory);
+                    log.trace("Deleted {}", directory);
                 }
                 catch (final IOException foo) {
                     log.warn("Problem cleaning up {}",directory, foo);
diff --git a/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/PluginCLITest.java b/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/PluginCLITest.java
new file mode 100644
index 000000000..1f567f3ab
--- /dev/null
+++ b/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/PluginCLITest.java
@@ -0,0 +1,51 @@
+/*
+ * 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 static org.testng.Assert.assertEquals;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+import org.testng.annotations.Test;
+
+import net.shibboleth.ext.spring.cli.AbstractCommandLine;
+
+ at SuppressWarnings("javadoc")
+public class PluginCLITest extends BasePluginTest {
+    
+    @Test(enabled = true) public void TestCli() throws IOException {
+        System.setProperty("net.shibboleth.idp.cli.idp.home",getIdpHome().toString());
+        final Resource pluginInstaller = new ClassPathResource("conf/admin/plugin-installer.xml");
+        final File plugin = getIdpHome().resolve("conf").resolve("admin").resolve("plugin-installer.xml").toFile();
+        plugin.createNewFile();
+        
+        try (final InputStream is = pluginInstaller.getInputStream();
+             final BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(plugin))) {
+            is.transferTo(os);
+        }
+    
+        assertEquals(PluginInstallerCLI.runMain(new String[] { plugin.getAbsolutePath(), "--verbose"}), 
+                AbstractCommandLine.RC_OK);	
+    }
+}
diff --git a/idp-installer/src/test/resources/idphome-test/conf/admin/gitkeep b/idp-installer/src/test/resources/idphome-test/conf/admin/gitkeep
new file mode 100644
index 000000000..e69de29bb

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


More information about the commits mailing list