You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jd...@apache.org on 2006/05/27 00:26:02 UTC

svn commit: r409768 - in /geronimo/sandbox/gshell/trunk/gshell-core/src: main/java/org/apache/geronimo/gshell/console/ test/java/org/apache/geronimo/gshell/console/

Author: jdillon
Date: Fri May 26 15:26:01 2006
New Revision: 409768

URL: http://svn.apache.org/viewvc?rev=409768&view=rev
Log:
Improved testability of console bits

Added:
    geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/InteractiveConsoleTest.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/JLineConsoleTest.java   (with props)
    geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/SimpleConsoleTest.java   (with props)
Modified:
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/Console.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/InteractiveConsole.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/JLineConsole.java
    geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/SimpleConsole.java

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/Console.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/Console.java?rev=409768&r1=409767&r2=409768&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/Console.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/Console.java Fri May 26 15:26:01 2006
@@ -21,7 +21,7 @@
 /**
  * Abstraction of a console.
  *
- * <p>Allows pluggable implemenations (like to enable readline, etc.)
+ * <p>Allows pluggable implemenations (like to enable jline, editline, etc.)
  *
  * @version $Id$
  */

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/InteractiveConsole.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/InteractiveConsole.java?rev=409768&r1=409767&r2=409768&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/InteractiveConsole.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/InteractiveConsole.java Fri May 26 15:26:01 2006
@@ -28,14 +28,27 @@
 public class InteractiveConsole
     implements Runnable
 {
+    //
+    // TODO: Rename to *Runner, since this is not really a Console impl
+    //
+
     private static final Log log = LogFactory.getLog(InteractiveConsole.class);
 
-    private GShell gshell;
-    private Console console;
+    private final GShell gshell;
+
+    private final Console console;
 
     public InteractiveConsole(final Console console, final GShell gshell) {
-        assert console != null;
-        assert gshell != null;
+        if (console == null) {
+            throw new IllegalArgumentException("Console is null");
+        }
+        if (gshell == null) {
+            throw new IllegalArgumentException("GShell is null");
+        }
+
+        //
+        // TODO: Can probaby abstract the GShell bits to just some kind of String executor
+        //
 
         this.console = console;
         this.gshell = gshell;
@@ -44,13 +57,21 @@
     public void run() {
         log.info("Running...");
 
+        boolean debug = log.isDebugEnabled();
+
         while (true) {
             try {
+                //
+                // TODO: Need to resolve how to allow the prompt to be changed
+                //
+
                 String prompt = "> ";
                 String line;
 
                 while ((line = console.readLine(prompt)) != null) {
-                    log.debug("Read line: " + line);
+                    if (debug) {
+                        log.debug("Read line: " + line);
+                    }
 
                     // Just ignore blank lines
                     if (line.trim().equals("")) {
@@ -59,9 +80,10 @@
 
                     int result = gshell.execute(line);
 
-                    log.debug("Command result: " + result);
+                    if (debug) {
+                        log.debug("Command result: " + result);
+                    }
                 }
-
             }
             catch (Exception e) {
                 log.error("Unhandled failure", e);

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/JLineConsole.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/JLineConsole.java?rev=409768&r1=409767&r2=409768&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/JLineConsole.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/JLineConsole.java Fri May 26 15:26:01 2006
@@ -32,11 +32,13 @@
 {
     private static final Log log = LogFactory.getLog(SimpleConsole.class);
 
-    private IO io;
-    private ConsoleReader reader;
+    private final IO io;
+    private final ConsoleReader reader;
 
     public JLineConsole(final IO io) throws IOException {
-        assert io != null;
+        if (io == null) {
+            throw new IllegalArgumentException("IO is null");
+        }
 
         this.io = io;
         this.reader = new ConsoleReader(io.inputStream, io.out);

Modified: geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/SimpleConsole.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/SimpleConsole.java?rev=409768&r1=409767&r2=409768&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/SimpleConsole.java (original)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/main/java/org/apache/geronimo/gshell/console/SimpleConsole.java Fri May 26 15:26:01 2006
@@ -32,11 +32,13 @@
 {
     private static final Log log = LogFactory.getLog(SimpleConsole.class);
 
-    private IO io;
-    private BufferedReader reader;
+    private final IO io;
+    private final BufferedReader reader;
 
     public SimpleConsole(final IO io) {
-        assert io != null;
+        if (io == null) {
+            throw new IllegalArgumentException("IO is null");
+        }
 
         this.io = io;
         this.reader = new BufferedReader(io.in);

Added: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/InteractiveConsoleTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/InteractiveConsoleTest.java?rev=409768&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/InteractiveConsoleTest.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/InteractiveConsoleTest.java Fri May 26 15:26:01 2006
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed 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 org.apache.geronimo.gshell.console;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for the {@link InteractiveConsole} class.
+ *
+ * @version $Id$
+ */
+public class InteractiveConsoleTest
+    extends TestCase
+{
+    public void testConstructorArgs() throws Exception {
+        try {
+            new InteractiveConsole(null, null);
+            fail("Accepted null value");
+        }
+        catch (IllegalArgumentException expected) {
+            // ignore
+        }
+
+        try {
+            new InteractiveConsole(new SimpleConsole(new IO()), null);
+            fail("Accepted null value");
+        }
+        catch (IllegalArgumentException expected) {
+            // ignore
+        }
+
+        //
+        // TODO: Check happy day
+        //
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/InteractiveConsoleTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/InteractiveConsoleTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/InteractiveConsoleTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/JLineConsoleTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/JLineConsoleTest.java?rev=409768&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/JLineConsoleTest.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/JLineConsoleTest.java Fri May 26 15:26:01 2006
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed 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 org.apache.geronimo.gshell.console;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for the {@link JLineConsole} class.
+ *
+ * @version $Id$
+ */
+public class JLineConsoleTest
+    extends TestCase
+{
+    public void testConstructorArgs() throws Exception {
+        try {
+            new JLineConsole(null);
+            fail("Accepted null value");
+        }
+        catch (IllegalArgumentException expected) {
+            // ignore
+        }
+
+        // Happy day
+        new JLineConsole(new IO());
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/JLineConsoleTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/JLineConsoleTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/JLineConsoleTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/SimpleConsoleTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/SimpleConsoleTest.java?rev=409768&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/SimpleConsoleTest.java (added)
+++ geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/SimpleConsoleTest.java Fri May 26 15:26:01 2006
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed 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 org.apache.geronimo.gshell.console;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for the {@link SimpleConsole} class.
+ *
+ * @version $Id$
+ */
+public class SimpleConsoleTest
+    extends TestCase
+{
+    public void testConstructorArgs() throws Exception {
+        try {
+            new SimpleConsole(null);
+            fail("Accepted null value");
+        }
+        catch (IllegalArgumentException expected) {
+            // ignore
+        }
+
+        // Happy day
+        new SimpleConsole(new IO());
+    }
+}

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/SimpleConsoleTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/SimpleConsoleTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-core/src/test/java/org/apache/geronimo/gshell/console/SimpleConsoleTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain