[jboss-cvs] JBossAS SVN: r61868 - branches/Branch_4_2/testsuite/src/main/org/jboss/test/util/test.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Mar 29 17:50:08 EDT 2007


Author: stan.silvert at jboss.com
Date: 2007-03-29 17:50:08 -0400 (Thu, 29 Mar 2007)
New Revision: 61868

Added:
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/util/test/TwiddleUnitTestCase.java
Removed:
   branches/Branch_4_2/testsuite/src/main/org/jboss/test/util/test/TwiddleTestCase.java
Log:
JBAS-3726


Deleted: branches/Branch_4_2/testsuite/src/main/org/jboss/test/util/test/TwiddleTestCase.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/util/test/TwiddleTestCase.java	2007-03-29 21:35:18 UTC (rev 61867)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/util/test/TwiddleTestCase.java	2007-03-29 21:50:08 UTC (rev 61868)
@@ -1,156 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.util.test;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.jboss.test.JBossTestCase;
-
-/**
- * Unit tests for the Twiddle command line utility.
- *
- * @author  <a href="mailto:stan at jboss.org">Stan Silvert</a>
- */
-public class TwiddleTestCase extends JBossTestCase
-{
-   public TwiddleTestCase(String name)
-   {
-      super(name);
-   }
-
-   public static Test suite() throws Exception
-   {
-      TestSuite suite = new TestSuite();
-      suite.addTest(new TestSuite(TwiddleTestCase.class));
-      return suite;
-   }
-
-   /**
-    * This really just tests that twiddle can be invoked.
-    */
-   public void testHelp() throws Exception
-   {
-      if (!isWindows()) return;  // TODO: fix so it runs on unix
-
-      String result = runTwiddle("-h");
-      assertTrue(result.contains("usage: twiddle [options] <command> [command_arguments]"));
-   }
-
-   /**
-    *  Test getting an attribute value from an MBean.
-    */
-   public void testGet() throws Exception
-   {
-      if (!isWindows()) return;  // TODO: fix so it runs on unix
-
-      String result = runTwiddle("get", "\"jboss.system:type=Server\"", "Started");
-      assertTrue(result.startsWith("Started=true"));
-   }
-
-   /**
-    * Run twiddle with the given arguments. This method relies on finding the twiddle
-    * bat or sh file using the jboss.dist system property. It will automatically pass
-    * in the -s parameter for the host of the server being used for testing.
-    *
-    * @param args The arguments passed to twiddle.  These should not include the -s
-    *             argument.
-    */ 
-   protected String runTwiddle(String... args) throws IOException, InterruptedException
-   {
-      List<String> command = new ArrayList<String>();
-
-      if (isWindows())
-      {
-         command.add("cmd");
-         command.add("/C");
-         command.add("twiddle");
-      }
-      else
-      {
-         command.add("/bin/sh");
-         command.add("-c");
-         command.add("twiddle.sh");
-      }
-
-      command.add("-s");
-      command.add(getServerHost());
-
-      command.addAll(Arrays.asList(args));
-
-      ProcessBuilder builder = new ProcessBuilder(command);
-      builder.directory(getTwiddleWorkingDir());
-      Process proc = builder.start();
-      InputStream in = proc.getInputStream();
-      int readByte = 0;
-      StringBuilder buffer = new StringBuilder();
-      while (readByte != -1)
-      {
-        readByte = in.read();
-        if (readByte != -1)
-        {
-           buffer.append((char)readByte);
-        }
-      }
-
-      if (log.isDebugEnabled()) debugTwiddle(builder, buffer);
-
-      return buffer.toString();
-   }
-
-   protected void debugTwiddle(ProcessBuilder builder, StringBuilder buffer)
-   {
-      String command = "";
-      for (String param: builder.command() )
-      {
-         command += param;
-         command += " ";
-      }
-
-      log.debug("executed: " + command);
-      log.debug("returned: " + buffer.toString());
-   }
-
-   protected boolean isWindows()
-   {
-      return System.getProperty("os.name").toLowerCase().startsWith("windows");
-   }
-
-   protected File getTwiddleWorkingDir()
-   {
-      // usually, the jboss.dist system property is set in the ant <junit> task using
-      // <sysproperty key="jboss.dist" value="${jboss.dist}"/>
-      String jbossDist = System.getProperty("jboss.dist");
-      if (jbossDist == null) throw new IllegalStateException("jboss.dist System property is not set");
-      String jbossBin = jbossDist + "/bin";
-      return new File(jbossBin);
-   }
-}

Added: branches/Branch_4_2/testsuite/src/main/org/jboss/test/util/test/TwiddleUnitTestCase.java
===================================================================
--- branches/Branch_4_2/testsuite/src/main/org/jboss/test/util/test/TwiddleUnitTestCase.java	                        (rev 0)
+++ branches/Branch_4_2/testsuite/src/main/org/jboss/test/util/test/TwiddleUnitTestCase.java	2007-03-29 21:50:08 UTC (rev 61868)
@@ -0,0 +1,166 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.util.test;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.test.JBossTestCase;
+
+/**
+ * Unit tests for the Twiddle command line utility.
+ *
+ * @author  <a href="mailto:stan at jboss.org">Stan Silvert</a>
+ */
+public class TwiddleUnitTestCase extends JBossTestCase
+{
+  public TwiddleUnitTestCase(String name)
+  {
+     super(name);
+  }
+
+  public static Test suite() throws Exception
+  {
+     TestSuite suite = new TestSuite();
+     suite.addTest(new TestSuite(TwiddleTestCase.class));
+     return suite;
+  }
+
+  /**
+   * This really just tests that twiddle can be invoked.
+   */
+  public void testHelp() throws Exception
+  {
+     String result = runTwiddle("-h");
+     assertTrue(result.contains("usage: twiddle"));
+     assertTrue(result.contains("[options] <command> [command_arguments]"));
+  }
+
+  /**
+   *  Test getting an attribute value from an MBean.
+   */
+  public void testGet() throws Exception
+  {
+     String result = runTwiddle("get", "\"jboss.system:type=Server\"", "Started");
+     assertTrue(result.startsWith("Started=true"));
+  }
+
+  /**
+   * Run twiddle with the given arguments. This method relies on finding the twiddle
+   * bat or sh file using the jboss.dist system property. It will automatically pass
+   * in the -s parameter for the host of the server being used for testing.
+   *
+   * @param args The arguments passed to twiddle.  These should not include the -s
+   *             argument.
+   */
+  protected String runTwiddle(String... args) throws IOException, InterruptedException
+  {
+     List<String> command = new ArrayList<String>();
+
+     if (isWindows())
+     {
+        command.add("cmd");
+        command.add("/C");
+        command.add("twiddle");
+        command.add("-s");
+        command.add(getServerHost());
+        command.addAll(Arrays.asList(args));
+     }
+     else
+     {
+        command.add("/bin/sh");
+        command.add("-c");
+        String twiddleCmd = "./twiddle.sh ";
+        twiddleCmd += "-s ";
+        twiddleCmd += getServerHost();
+        twiddleCmd += makeTwiddleArgs(args);
+        command.add(twiddleCmd);
+     }
+
+     ProcessBuilder builder = new ProcessBuilder(command);
+     builder.directory(getTwiddleWorkingDir());
+     Process proc = builder.start();
+     InputStream in = proc.getInputStream();
+     int readByte = 0;
+     StringBuilder buffer = new StringBuilder();
+     while (readByte != -1)
+     {
+       readByte = in.read();
+       if (readByte != -1)
+       {
+          buffer.append((char)readByte);
+       }
+     }
+
+     if (log.isDebugEnabled()) debugTwiddle(builder, buffer);
+
+     return buffer.toString();
+  }
+
+  protected String makeTwiddleArgs(String[] args)
+  {
+     String result = "";
+     for (int i=0; i < args.length; i++)
+     {
+        result += " ";
+        result += args[i];
+     }
+     return result;
+  }
+
+  protected void debugTwiddle(ProcessBuilder builder, StringBuilder buffer)
+  {
+     String command = "";
+     for (String param: builder.command() )
+     {
+        command += param;
+        command += " ";
+     }
+
+     log.debug("executed: " + command);
+     log.debug("returned: " + buffer.toString());
+  }
+
+  protected boolean isWindows()
+  {
+     return System.getProperty("os.name").toLowerCase().startsWith("windows");
+  }
+
+  protected File getTwiddleWorkingDir()
+  {
+     // usually, the jboss.dist system property is set in the ant <junit> task using
+     // <sysproperty key="jboss.dist" value="${jboss.dist}"/>
+     String jbossDist = System.getProperty("jboss.dist");
+     if (jbossDist == null) throw new IllegalStateException("jboss.dist System property is not set");
+     String jbossBin = jbossDist + "/bin";
+     return new File(jbossBin);
+  }
+}




More information about the jboss-cvs-commits mailing list