changeset 1662:3a710779b87f

Separate plugin tests into user/system versions. Reviewed-by: omajid Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2015-March/013081.html PR2281
author Severin Gehwolf <sgehwolf@redhat.com>
date Tue, 10 Mar 2015 16:30:15 +0100
parents 1cfebde69814
children b1d484174d5a
files integration-tests/itest-run/src/test/java/com/redhat/thermostat/itest/PluginTest.java integration-tests/itest-run/src/test/java/com/redhat/thermostat/itest/SystemPluginsTest.java integration-tests/itest-run/src/test/java/com/redhat/thermostat/itest/UserPluginsTest.java integration-tests/itest-run/src/test/java/com/redhat/thermostat/itest/standalone/AllStandaloneTests.java
diffstat 4 files changed, 262 insertions(+), 128 deletions(-) [+]
line wrap: on
line diff
--- a/integration-tests/itest-run/src/test/java/com/redhat/thermostat/itest/PluginTest.java	Tue Mar 10 11:39:31 2015 -0400
+++ b/integration-tests/itest-run/src/test/java/com/redhat/thermostat/itest/PluginTest.java	Tue Mar 10 16:30:15 2015 +0100
@@ -36,102 +36,75 @@
 
 package com.redhat.thermostat.itest;
 
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
 
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import expectj.Spawn;
-
 public class PluginTest extends IntegrationTest {
 
-    private static final String PLUGIN_HOME = getSystemPluginHome();
-
-    private static NewCommandPlugin fooPlugin = new NewCommandPlugin("foo", "provides foo command", PLUGIN_HOME + File.separator + "new");
-    private static NewCommandPlugin userPlugin = new NewCommandPlugin(
-            "user",
-            "a plugin that is provided by the user",
-            getUserThermostatHome() + File.separator + "data" + File.separator + "plugins" + File.separator + "user");
-    private static UnknownExtendsPlugin unknownExtension = new UnknownExtendsPlugin(PLUGIN_HOME + File.separator + "unknown");
-
-    @BeforeClass
-    public static void setUpOnce() {
-        fooPlugin.install();
-        userPlugin.install();
-        unknownExtension.install();
-    }
-    
-    @Before
-    public void setup() {
-        createFakeSetupCompleteFile();
-    }
+    protected static final String SYSTEM_PLUGIN_HOME = getSystemPluginHome();
+    protected static final String USER_PLUGIN_HOME = getUserThermostatHome() + File.separator + "data" + File.separator + "plugins";
+    protected static final String USER_PLUGIN_INSTALL_LOCATION = USER_PLUGIN_HOME + File.separator + "user";
+    protected static final String SYSTEM_PLUGIN_INSTALL_LOCATION = SYSTEM_PLUGIN_HOME + File.separator + "new";
 
-    @AfterClass
-    public static void tearDownOnce() {
-        unknownExtension.uninstall();
-        userPlugin.uninstall();
-        fooPlugin.uninstall();
-    }
-    
-    @After
-    public void tearDown() throws IOException {
-        removeSetupCompleteStampFiles();
-    }
-
-    @Test
-    public void testHelpIsOkay() throws Exception {
-        Spawn shell = spawnThermostat("help");
-        shell.expectClose();
-
-        String stdOut = shell.getCurrentStandardOutContents();
-
-        assertTrue(stdOut.contains("list of commands"));
-        assertTrue(stdOut.contains("help"));
-        assertTrue(stdOut.contains("agent"));
-        assertTrue(stdOut.contains("gui"));
-        assertTrue(stdOut.contains("ping"));
-        assertTrue(stdOut.contains("shell"));
-
-        assertTrue(stdOut.contains(fooPlugin.command));
-        assertTrue(stdOut.contains(fooPlugin.description));
-
-        assertTrue(stdOut.contains(userPlugin.command));
-
-        assertFalse(stdOut.contains(unknownExtension.command));
-
-        // TODO assertEquals("", stdErr);
+    protected abstract static class BasicPlugin {
+        private final String command;
+        private final String pluginHome;
+        
+        protected BasicPlugin(String command, String pluginHome) {
+            this.command = command;
+            this.pluginHome = pluginHome;
+        }
+        
+        protected String getCommandName() {
+            return command;
+        }
+        
+        protected String getPluginHome() {
+            return pluginHome;
+        }
+        
+        protected void doInstall(String thermostatPluginXml) {
+            File home = new File(getPluginHome());
+            if (!home.isDirectory() && !home.mkdirs()) {
+                throw new AssertionError("could not create directory: " + getPluginHome());
+            }
+            try (FileWriter writer = new FileWriter(getPluginHome() + File.separator + "thermostat-plugin.xml")) {
+                writer.write(thermostatPluginXml);
+            } catch (IOException e) {
+                throw new AssertionError("unable to write plugin configuration", e);
+            }
+        }
+        
+        protected void uninstall() {
+            if (!new File(getPluginHome()).exists()) {
+                return;
+            }
+            if (!new File(getPluginHome(), "thermostat-plugin.xml").delete()) {
+                throw new AssertionError("Could not delete plugin file");
+            }
+            if (!new File(getPluginHome()).delete()) {
+                throw new AssertionError("Could not delete plugin directory");
+            }
+        }
+        
+        protected abstract void install();
     }
 
     /**
      * This plugin provides a new command
      */
-    private static class NewCommandPlugin {
+    protected static class NewCommandPlugin extends BasicPlugin {
 
-        private final String pluginHome;
-        private final String command;
         private final String description;
 
         public NewCommandPlugin(String command, String description, String pluginLocation) {
-            this.pluginHome = pluginLocation;
-
-            this.command = command;
+            super(command, pluginLocation);
             this.description = description;
         }
 
-        private void install() {
-            File home = new File(pluginHome);
-            if (!home.isDirectory() && !home.mkdirs()) {
-                throw new AssertionError("could not create directory: " + pluginHome);
-            }
-
+        @Override
+        protected void install() {
             String pluginContents = "" +
                     "<?xml version=\"1.0\"?>\n" +
                     "<plugin xmlns=\"http://icedtea.classpath.org/thermostat/plugins/v1.0\"\n" +
@@ -139,7 +112,7 @@
                     " xsi:schemaLocation=\"http://icedtea.classpath.org/thermostat/plugins/v1.0 thermost-plugin.xsd\">\n" +
                     "  <commands>" +
                     "    <command>" +
-                    "      <name>" + command + "</name>" +
+                    "      <name>" + getCommandName() + "</name>" +
                     "      <description>" + description + "</description>" +
                     "      <options>" +
                     "        <option>" +
@@ -160,48 +133,22 @@
                     "    </command>" +
                     "  </commands>" +
                     "</plugin>";
-
-            try (FileWriter writer = new FileWriter(pluginHome + File.separator + "thermostat-plugin.xml")) {
-                writer.write(pluginContents);
-            } catch (IOException e) {
-                throw new AssertionError("unable to write plugin configuration", e);
-            }
-
+            super.doInstall(pluginContents);
         }
 
-        private void uninstall() {
-            if (!new File(pluginHome).exists()) {
-                return;
-            }
-            if (!new File(pluginHome, "thermostat-plugin.xml").delete()) {
-                throw new AssertionError("Could not delete plugin file");
-            }
-            if (!new File(pluginHome).delete()) {
-                throw new AssertionError("Could not delete plugin directory");
-            }
-        }
     }
 
     /**
      * This plugin extends an unknown command
      */
-    private static class UnknownExtendsPlugin {
-
-        private final String pluginHome;
-        private final String command;
+    protected static class UnknownExtendsPlugin extends BasicPlugin {
 
         public UnknownExtendsPlugin(String pluginLocation) {
-            this.pluginHome = pluginLocation;
-
-            this.command = "unknown-command";
+            super("unknown-command", pluginLocation);
         }
 
-        private void install() {
-            File home = new File(pluginHome);
-            if (!home.isDirectory() && !home.mkdir()) {
-                throw new AssertionError("could not create directory: " + pluginHome);
-            }
-
+        @Override
+        protected void install() {
             String pluginContents = "" +
                     "<?xml version=\"1.0\"?>\n" +
                     "<plugin xmlns=\"http://icedtea.classpath.org/thermostat/plugins/v1.0\"\n" +
@@ -209,7 +156,7 @@
                     " xsi:schemaLocation=\"http://icedtea.classpath.org/thermostat/plugins/v1.0 thermost-plugin.xsd\">\n" +
                     "  <extensions>" +
                     "    <extension>" +
-                    "      <name>" + command + "</name>" +
+                    "      <name>" + getCommandName() + "</name>" +
                     "      <bundles>" +
                     "        <bundle>" +
                     "          <symbolic-name>bar</symbolic-name>" +
@@ -220,25 +167,9 @@
                     "  </extensions>" +
                     "</plugin>";
 
-            try (FileWriter writer = new FileWriter(pluginHome + File.separator + "thermostat-plugin.xml")) {
-                writer.write(pluginContents);
-            } catch (IOException e) {
-                throw new AssertionError("unable to write plugin configuration", e);
-            }
-
+            super.doInstall(pluginContents);
         }
 
-        private void uninstall() {
-            if (!new File(pluginHome).exists()) {
-                return;
-            }
-            if (!new File(pluginHome, "thermostat-plugin.xml").delete()) {
-                throw new AssertionError("Could not delete plugin file");
-            }
-            if (!new File(pluginHome).delete()) {
-                throw new AssertionError("Could not delete plugin directory");
-            }
-        }
     }
 
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/integration-tests/itest-run/src/test/java/com/redhat/thermostat/itest/SystemPluginsTest.java	Tue Mar 10 16:30:15 2015 +0100
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2012-2015 Red Hat, Inc.
+ *
+ * This file is part of Thermostat.
+ *
+ * Thermostat is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or (at your
+ * option) any later version.
+ *
+ * Thermostat is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Thermostat; see the file COPYING.  If not see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Linking this code with other modules is making a combined work
+ * based on this code.  Thus, the terms and conditions of the GNU
+ * General Public License cover the whole combination.
+ *
+ * As a special exception, the copyright holders of this code give
+ * you permission to link this code with independent modules to
+ * produce an executable, regardless of the license terms of these
+ * independent modules, and to copy and distribute the resulting
+ * executable under terms of your choice, provided that you also
+ * meet, for each linked independent module, the terms and conditions
+ * of the license of that module.  An independent module is a module
+ * which is not derived from or based on this code.  If you modify
+ * this code, you may extend this exception to your version of the
+ * library, but you are not obligated to do so.  If you do not wish
+ * to do so, delete this exception statement from your version.
+ */
+
+package com.redhat.thermostat.itest;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import expectj.Spawn;
+
+/**
+ * Tests plugins installing to the system location.
+ *
+ */
+public class SystemPluginsTest extends PluginTest {
+
+    private static NewCommandPlugin fooPlugin = new NewCommandPlugin("foo",
+            "provides foo command", SYSTEM_PLUGIN_INSTALL_LOCATION);
+    
+    @BeforeClass
+    public static void setUpOnce() {
+        fooPlugin.install();
+    }
+    
+    @Before
+    public void setup() {
+        createFakeSetupCompleteFile();
+    }
+
+    @AfterClass
+    public static void tearDownOnce() {
+        fooPlugin.uninstall();
+    }
+    
+    @After
+    public void tearDown() throws IOException {
+        removeSetupCompleteStampFiles();
+    }
+
+    @Test
+    public void helpOutputContainsSystemPluginName() throws Exception {
+        Spawn shell = spawnThermostat("help");
+        shell.expectClose();
+
+        String stdOut = shell.getCurrentStandardOutContents();
+
+        assertTrue(stdOut.contains("list of commands"));
+        assertTrue(stdOut.contains("help"));
+        assertTrue(stdOut.contains("agent"));
+        assertTrue(stdOut.contains("gui"));
+        assertTrue(stdOut.contains("ping"));
+        assertTrue(stdOut.contains("shell"));
+
+
+        assertTrue(stdOut.contains(fooPlugin.getCommandName()));
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/integration-tests/itest-run/src/test/java/com/redhat/thermostat/itest/UserPluginsTest.java	Tue Mar 10 16:30:15 2015 +0100
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2012-2015 Red Hat, Inc.
+ *
+ * This file is part of Thermostat.
+ *
+ * Thermostat is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or (at your
+ * option) any later version.
+ *
+ * Thermostat is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Thermostat; see the file COPYING.  If not see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Linking this code with other modules is making a combined work
+ * based on this code.  Thus, the terms and conditions of the GNU
+ * General Public License cover the whole combination.
+ *
+ * As a special exception, the copyright holders of this code give
+ * you permission to link this code with independent modules to
+ * produce an executable, regardless of the license terms of these
+ * independent modules, and to copy and distribute the resulting
+ * executable under terms of your choice, provided that you also
+ * meet, for each linked independent module, the terms and conditions
+ * of the license of that module.  An independent module is a module
+ * which is not derived from or based on this code.  If you modify
+ * this code, you may extend this exception to your version of the
+ * library, but you are not obligated to do so.  If you do not wish
+ * to do so, delete this exception statement from your version.
+ */
+
+package com.redhat.thermostat.itest;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import expectj.Spawn;
+
+/**
+ * Tests plugins installing to the system location.
+ *
+ */
+public class UserPluginsTest extends PluginTest {
+
+    private static NewCommandPlugin userPlugin = new NewCommandPlugin(
+            "user",
+            "a plugin that is provided by the user", USER_PLUGIN_INSTALL_LOCATION);
+    private static UnknownExtendsPlugin unknownExtension = new UnknownExtendsPlugin(USER_PLUGIN_HOME + File.separator + "unknown");
+
+    @BeforeClass
+    public static void setUpOnce() {
+        userPlugin.install();
+        unknownExtension.install();
+    }
+    
+    @Before
+    public void setup() {
+        createFakeSetupCompleteFile();
+    }
+
+    @AfterClass
+    public static void tearDownOnce() {
+        unknownExtension.uninstall();
+        userPlugin.uninstall();
+    }
+    
+    @After
+    public void tearDown() throws IOException {
+        removeSetupCompleteStampFiles();
+    }
+
+    @Test
+    public void testHelpIsOkay() throws Exception {
+        Spawn shell = spawnThermostat("help");
+        shell.expectClose();
+
+        String stdOut = shell.getCurrentStandardOutContents();
+
+        assertTrue(stdOut.contains("list of commands"));
+        assertTrue(stdOut.contains("help"));
+        assertTrue(stdOut.contains("agent"));
+        assertTrue(stdOut.contains("gui"));
+        assertTrue(stdOut.contains("ping"));
+        assertTrue(stdOut.contains("shell"));
+
+
+        assertTrue(stdOut.contains(userPlugin.getCommandName()));
+
+        assertFalse(stdOut.contains(unknownExtension.getCommandName()));
+    }
+}
--- a/integration-tests/itest-run/src/test/java/com/redhat/thermostat/itest/standalone/AllStandaloneTests.java	Tue Mar 10 11:39:31 2015 -0400
+++ b/integration-tests/itest-run/src/test/java/com/redhat/thermostat/itest/standalone/AllStandaloneTests.java	Tue Mar 10 16:30:15 2015 +0100
@@ -43,6 +43,7 @@
 import com.redhat.thermostat.itest.PluginTest;
 import com.redhat.thermostat.itest.StorageConnectionTest;
 import com.redhat.thermostat.itest.StorageTest;
+import com.redhat.thermostat.itest.UserPluginsTest;
 import com.redhat.thermostat.itest.VmCommandsTest;
 
 
@@ -93,7 +94,7 @@
     StorageConnectionTest.class,
     StorageTest.class,
     VmCommandsTest.class,
-    PluginTest.class,
+    UserPluginsTest.class,
 })
 public class AllStandaloneTests {
     // nothing