[jboss-cvs] JBossAS SVN: r102062 - in projects/mc-tools: mcinspector and 28 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Mar 8 10:17:09 EST 2010


Author: kabir.khan at jboss.com
Date: 2010-03-08 10:17:07 -0500 (Mon, 08 Mar 2010)
New Revision: 102062

Added:
   projects/mc-tools/mcinspector/
   projects/mc-tools/mcinspector/trunk/
   projects/mc-tools/mcinspector/trunk/.classpath
   projects/mc-tools/mcinspector/trunk/.project
   projects/mc-tools/mcinspector/trunk/.settings/
   projects/mc-tools/mcinspector/trunk/.settings/org.eclipse.jdt.core.prefs
   projects/mc-tools/mcinspector/trunk/pom.xml
   projects/mc-tools/mcinspector/trunk/src/
   projects/mc-tools/mcinspector/trunk/src/main/
   projects/mc-tools/mcinspector/trunk/src/main/java/
   projects/mc-tools/mcinspector/trunk/src/main/java/org/
   projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/
   projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/
   projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/
   projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/bean/
   projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/bean/McInspector.java
   projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/bean/McInspectorMBean.java
   projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/
   projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/ClientCommandArguments.java
   projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/CommandArguments.java
   projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/CommandResult.java
   projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/InspectorCommand.java
   projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/InspectorCommands.java
   projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/client/
   projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/client/McInspectorClient.java
   projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/
   projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/AbstractInspectorCommand.java
   projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/AbstractInspectorCommands.java
   projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/BasicInspectorCommands.java
   projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/BeanCommand.java
   projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/ChangeCommand.java
   projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/ClientCommandArgumentsImpl.java
   projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/CommandArgumentsImpl.java
   projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/DelegatingCommandArgumentsImpl.java
   projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/HelpCommand.java
   projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/ListCommand.java
   projects/mc-tools/mcinspector/trunk/src/main/resources/
   projects/mc-tools/mcinspector/trunk/src/main/resources/META-INF/
   projects/mc-tools/mcinspector/trunk/src/main/resources/META-INF/mcinspector-jboss-beans.xml
   projects/mc-tools/mcinspector/trunk/src/main/resources/jndi.properties
   projects/mc-tools/mcinspector/trunk/src/main/resources/log4j.properties
   projects/mc-tools/mcinspector/trunk/src/main/resources/mcinspector.sh
   projects/mc-tools/mcinspector/trunk/src/test/
   projects/mc-tools/mcinspector/trunk/src/test/java/
   projects/mc-tools/mcinspector/trunk/src/test/java/org/
   projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/
   projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/
   projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/
   projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/
   projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/AbstractInspectorTest.java
   projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/AbstractInspectorTestDelegate.java
   projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/InspectorTestSuite.java
   projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/kernel/
   projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/kernel/support/
   projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/kernel/support/ErrorBean.java
   projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/kernel/support/SimpleBean.java
   projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/kernel/test/
   projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/kernel/test/BeanTestCase.java
   projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/kernel/test/ChangeTestCase.java
   projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/kernel/test/ListTestCase.java
   projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/simple/
   projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/simple/MockInspectorCommands.java
   projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/simple/support/
   projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/simple/support/MockCommandLongName.java
   projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/simple/support/MockEchoCommand.java
   projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/simple/test/
   projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/simple/test/CommandArgumentsTestCase.java
   projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/simple/test/SimpleTestCase.java
   projects/mc-tools/mcinspector/trunk/svn-commit.tmp
Log:
Add the mcinspector to svn


Added: projects/mc-tools/mcinspector/trunk/.classpath
===================================================================
--- projects/mc-tools/mcinspector/trunk/.classpath	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/.classpath	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,8 @@
+<classpath>
+  <classpathentry kind="src" path="src/test/java" output="target/test-classes" including="**/*.java"/>
+  <classpathentry kind="src" path="src/main/java" including="**/*.java"/>
+  <classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>
+  <classpathentry kind="output" path="target/classes"/>
+  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+  <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+</classpath>
\ No newline at end of file

Added: projects/mc-tools/mcinspector/trunk/.project
===================================================================
--- projects/mc-tools/mcinspector/trunk/.project	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/.project	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,17 @@
+<projectDescription>
+  <name>mcinspector</name>
+  <comment>Parent POM for JBoss projects. Provides default project build configuration.</comment>
+  <projects/>
+  <buildSpec>
+    <buildCommand>
+      <name>org.eclipse.jdt.core.javabuilder</name>
+    </buildCommand>
+    <buildCommand>
+      <name>org.maven.ide.eclipse.maven2Builder</name>
+    </buildCommand>
+  </buildSpec>
+  <natures>
+    <nature>org.eclipse.jdt.core.javanature</nature>
+    <nature>org.maven.ide.eclipse.maven2Nature</nature>
+  </natures>
+</projectDescription>
\ No newline at end of file

Added: projects/mc-tools/mcinspector/trunk/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- projects/mc-tools/mcinspector/trunk/.settings/org.eclipse.jdt.core.prefs	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/.settings/org.eclipse.jdt.core.prefs	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,5 @@
+#Thu Mar 04 22:27:14 GMT 2010
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5

Added: projects/mc-tools/mcinspector/trunk/pom.xml
===================================================================
--- projects/mc-tools/mcinspector/trunk/pom.xml	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/pom.xml	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,73 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.jboss</groupId>
+    <artifactId>jboss-parent</artifactId>
+    <version>4</version>
+  </parent>
+  <groupId>org.jboss.microcontainer</groupId>
+  <artifactId>mcinspector</artifactId>
+  <packaging>jar</packaging>
+  <version>1.0-SNAPSHOT</version>
+  <name>mcinspector</name>
+  <url>http://www.jboss.org/jbossmc/</url>
+  
+  <!-- scm>
+    <connection>scm:svn:http://anonsvn.jboss.org/repos/jbossas/projects/kernel/trunk/</connection>
+    <developerConnection>scm:svn:https://svn.jboss.org/repos/jbossas/projects/kernel/trunk/</developerConnection>
+    <url>http://viewvc.jboss.org/cgi-bin/viewvc.cgi/jbossas/projects/kernel/trunk/</url>
+  </scm -->
+
+  <properties>
+    <version.jboss.kernel>2.2.0.Alpha6</version.jboss.kernel>
+    <version.jboss.junit>3.8.1</version.jboss.junit>
+    <version.jboss.test>1.1.1.GA</version.jboss.test>
+    <version.jboss.logging.spi>2.1.1.GA</version.jboss.logging.spi>
+    <version.jboss.logging.log4j>2.1.1.GA</version.jboss.logging.log4j>
+    <version.jboss.common.core>2.2.17.GA</version.jboss.common.core>
+  </properties>
+  
+  <dependencies>
+    <dependency>
+      <groupId>org.jboss.kernel</groupId>
+      <artifactId>jboss-kernel</artifactId>
+      <version>${version.jboss.kernel}</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>${version.jboss.junit}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.test</groupId>
+      <artifactId>jboss-test</artifactId>
+      <version>${version.jboss.test}</version>
+      <scope>test</scope>
+    </dependency>    
+    <dependency>
+      <groupId>org.jboss.logging</groupId>
+      <artifactId>jboss-logging-spi</artifactId>
+      <version>${version.jboss.logging.spi}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.logging</groupId>
+      <artifactId>jboss-logging-log4j</artifactId>
+      <version>${version.jboss.logging.log4j}</version>
+      <scope>test</scope>
+      <exclusions>
+        <exclusion>
+          <groupId>org.jboss.cl</groupId>
+          <artifactId>jboss-classloading</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss</groupId>
+      <artifactId>jboss-common-core</artifactId>
+      <version>${version.jboss.common.core}</version>
+    </dependency>
+  </dependencies>
+</project>

Added: projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/bean/McInspector.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/bean/McInspector.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/bean/McInspector.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,81 @@
+/*
+* 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.microcontainer.mcinspector.bean;
+
+import org.jboss.kernel.Kernel;
+import org.jboss.microcontainer.mcinspector.command.ClientCommandArguments;
+import org.jboss.microcontainer.mcinspector.command.CommandArguments;
+import org.jboss.microcontainer.mcinspector.command.CommandResult;
+import org.jboss.microcontainer.mcinspector.command.InspectorCommands;
+import org.jboss.microcontainer.mcinspector.command.impl.BasicInspectorCommands;
+import org.jboss.microcontainer.mcinspector.command.impl.CommandArgumentsImpl;
+import org.jboss.microcontainer.mcinspector.command.impl.DelegatingCommandArgumentsImpl;
+
+/**
+ * Main entry point for in-vm clients
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class McInspector implements McInspectorMBean
+{
+   private final Kernel kernel;
+   
+   private final InspectorCommands commands;
+   
+   public McInspector(Kernel kernel)
+   {
+      this(kernel, null);
+   }
+   
+   public McInspector(Kernel kernel, InspectorCommands commands)
+   {
+      this.kernel = kernel;
+      this.commands = (commands == null) ? new BasicInspectorCommands() : commands;
+   }
+   
+   public CommandResult execute(ClientCommandArguments args)
+   {
+      if (args instanceof CommandArguments == false)
+      {
+         args = new DelegatingCommandArgumentsImpl(args);
+      }
+      return execute((CommandArguments)args);
+   }
+   
+   public String[] execute(String programName, String command)
+   {
+      return execute(new CommandArgumentsImpl(programName, command)).getLines();
+   }
+   
+   public String[] execute(String command)
+   {
+      return execute(null, command);
+   }
+   
+   private CommandResult execute(CommandArguments args)
+   {
+      args.setKernel(kernel);
+      args.setCommands(commands);
+      return commands.execute(args);
+   }
+}

Added: projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/bean/McInspectorMBean.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/bean/McInspectorMBean.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/bean/McInspectorMBean.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,60 @@
+/*
+* 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.microcontainer.mcinspector.bean;
+
+import org.jboss.microcontainer.mcinspector.command.ClientCommandArguments;
+import org.jboss.microcontainer.mcinspector.command.CommandResult;
+
+/**
+ * Main entry point for clients accessing via JMX
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface McInspectorMBean
+{
+   /**
+    * Executes a command
+    * 
+    * @param args the command arguments
+    * @return The result of the command
+    */
+   CommandResult execute(ClientCommandArguments args);
+
+   /**
+    * Executes the command-line string
+    * 
+    * @param programName the program name
+    * @param command the command
+    * @return The reply for the command, where each element is intended to be displayed on a separate line
+    */
+   String[] execute(String programName, String command);
+   
+   /**
+    * Executes the command-line string
+    * 
+    * @param command the command
+    * @return The reply for the command, where each element is intended to be displayed on a separate line
+    */
+   String[] execute(String command);
+
+}

Added: projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/ClientCommandArguments.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/ClientCommandArguments.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/ClientCommandArguments.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,110 @@
+/*
+* 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.microcontainer.mcinspector.command;
+
+import java.io.Serializable;
+
+/**
+ * Command arguments that can be sent from outside the kernel VM
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface ClientCommandArguments extends Serializable
+{
+
+   /**
+    * Gets the program name
+    * 
+    * @return the program name
+    */
+   String getProgramName();
+
+   /**
+    * Gets the command name
+    * 
+    * @returm the command name
+    */
+   String getCommand();
+
+   /**
+    * Gets the command arguments
+    * 
+    * @return the command arguments
+    */
+   String[] getCommandArguments();
+
+   /**
+    * Checks if there are any command arguments
+    * 
+    * @return the command arguments
+    */
+   boolean hasCommandArguments();
+
+   
+   /**
+    * Gets the command options
+    * 
+    * @return the command options
+    */
+   CommandOption[] getCommandOptions();
+
+   /**
+    * Checks if there are any command options
+    * 
+    * @return the command options
+    */
+   boolean hasCommandOptions();
+   
+   /**
+    * Check for a particular command option
+    * 
+    * @return the option or null if not found
+    */
+   CommandOption getCommandOption(String name);
+
+   /**
+    * Represents an option passed in to a command with '-', for example
+    * <p>
+    * <code>-v</code>, will just have the name 'v'<br>
+    * <code>-s=one</code>, will have the name 's' and one value 'one'<br>
+    * <code>-s=one,two</code>, will have the name 's' and the values 'one' and 'two'<br>
+    * 
+    * </pre>
+    * 
+    */
+   public interface CommandOption extends Serializable
+   {
+      /**
+       * Get the name of the option
+       * 
+       * @return the name
+       */
+      String getName();
+
+      /**
+       * Get the value(s) for the option
+       * 
+       * @return the values
+       */
+      String[] getValues();
+   }}
\ No newline at end of file

Added: projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/CommandArguments.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/CommandArguments.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/CommandArguments.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,64 @@
+/*
+* 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.microcontainer.mcinspector.command;
+
+import org.jboss.kernel.Kernel;
+
+/**
+ * Contains the parameters for the command and allows to set/get things in the 
+ * VM of the kernel
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface CommandArguments extends ClientCommandArguments 
+{
+   /**
+    * Get the kernel
+    * 
+    * @return the kernel
+    */
+   public Kernel getKernel();
+
+   /**
+    * Set the kernel
+    * 
+    * @param kernel the kernel to set
+    * @throws IllegalArgumentException if the kernel parameter is null
+    */
+   public void setKernel(Kernel kernel);
+
+   /**
+    * Sets the commands
+    * 
+    * @param commands the commands
+    * @throws IllegalArgumentException if the commands parameter is null
+    */
+   public void setCommands(InspectorCommands commands);
+   
+   /**
+    * Gets the commands
+    * 
+    * @return the commands
+    */
+   public InspectorCommands getCommands();   
+}

Added: projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/CommandResult.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/CommandResult.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/CommandResult.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,67 @@
+/*
+* 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.microcontainer.mcinspector.command;
+
+import java.io.PrintWriter;
+import java.io.Serializable;
+import java.util.ArrayList;
+
+/**
+ * Contains the results of the command
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class CommandResult implements Serializable
+{
+   private static final long serialVersionUID = 1L;
+   
+   private final ArrayList<String> result = new ArrayList<String>();
+   
+   public CommandResult()
+   {
+      
+   }
+   
+   public CommandResult(String...lines)
+   {
+      for (String s : lines)
+         result.add(s);
+   }
+
+   public void appendResultLine(String s)
+   {
+      result.add(s);
+   }
+   
+   public String[] getLines()
+   {
+      return result.toArray(new String[result.size()]);
+   }
+   
+   public void printResult(PrintWriter writer)
+   {
+      for (String s : result)
+         writer.println(s);
+   }
+
+}

Added: projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/InspectorCommand.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/InspectorCommand.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/InspectorCommand.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,63 @@
+/*
+* 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.microcontainer.mcinspector.command;
+
+
+/**
+ * A command plugin
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface InspectorCommand
+{
+   /**
+    * The command used to invoke the plugin. It should not contain any spaces
+    * 
+    * @return the command
+    */
+   String getName();
+   
+   /**
+    * The brief description to be displayed when the user uses the 'help' command
+    * to list all the plugins
+    * 
+    * @return the description
+    */
+   String getHelpOverview();
+   
+   /**
+    * The detailed description to be displayed when the user uses the 'help &lt;command&gt;' to
+    * get help for a particular plugin
+    * 
+    * @return the description. Each element is intended for a separate line in the output.
+    */
+   String[] getHelpDetail();
+   
+   /**
+    * Handles the command
+    * @param args the arguments
+    * 
+    * @return The result of the command
+    */
+   CommandResult execute(CommandArguments args);
+}

Added: projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/InspectorCommands.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/InspectorCommands.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/InspectorCommands.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,71 @@
+/*
+* 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.microcontainer.mcinspector.command;
+
+import java.util.Map;
+
+/**
+ * Registry and main entry point to the commands
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface InspectorCommands
+{
+   /**
+    * Adds a command
+    *
+    * @param command the command to add
+    * @throws IllegalArgumentException if the command is null, or the name is null or contains spaces 
+    */
+   void addCommand(InspectorCommand command);
+
+   /**
+    * Removes a command
+    * @return true if the command existed and thus was removed
+    */
+   boolean removeCommand(InspectorCommand command);
+
+   /**
+    * Executes the arguments using the appropriate command
+    * 
+    * @args the arguments
+    * @return the result of the command
+    */
+   CommandResult execute(CommandArguments args);
+   
+   /**
+    * Gets a command by name
+    * 
+    * @param name the name of the command
+    * @return the command or null if it does not exist 
+    */
+   InspectorCommand getCommand(String name);
+   
+   /**
+    * Gets an unmodifiable map of the commands available
+    * 
+    * @return the commands
+    */
+   Map<String, InspectorCommand> getCommands();
+
+}
\ No newline at end of file

Added: projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/client/McInspectorClient.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/client/McInspectorClient.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/client/McInspectorClient.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,97 @@
+/*
+* 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.microcontainer.mcinspector.command.client;
+
+import java.io.PrintWriter;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.jboss.microcontainer.mcinspector.command.ClientCommandArguments;
+import org.jboss.microcontainer.mcinspector.command.CommandResult;
+import org.jboss.microcontainer.mcinspector.command.impl.ClientCommandArgumentsImpl;
+
+/**
+ * Command line client that interacts with the McInspector MBean via JMX
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class McInspectorClient
+{
+   public static final String RMI_ADAPTER_NAME = "jmx/invoker/RMIAdaptor";
+
+
+   private static MBeanServerConnection createMBeanServerConnection()
+      throws NamingException
+   {
+      InitialContext ctx;
+
+      ctx = new InitialContext();
+
+      Object obj = ctx.lookup(RMI_ADAPTER_NAME);
+      ctx.close();
+
+      return (MBeanServerConnection) obj;
+   }
+
+   private static void initProtocolHandlers()
+   {
+      String handlerPkgs = System.getProperty("java.protocol.handler.pkgs");
+      if (handlerPkgs != null)
+      {
+         handlerPkgs += "|org.jboss.net.protocol";
+      }
+      else
+      {
+         handlerPkgs = "org.jboss.net.protocol";
+      }
+      System.setProperty("java.protocol.handler.pkgs", handlerPkgs);      
+   }
+      
+   public static void main(String[] args) throws Exception
+   {
+      long start = System.currentTimeMillis();
+      initProtocolHandlers();
+      MBeanServerConnection server = createMBeanServerConnection();
+
+      PrintWriter writer = new PrintWriter(System.out);
+      try
+      {
+         CommandResult result = (CommandResult)server.invoke(
+               new ObjectName("org.jboss.kernel:service=McInspector"), 
+               "execute", 
+               new Object[] {new ClientCommandArgumentsImpl("mcinspector", args)}, 
+               new String[] {ClientCommandArguments.class.getName()});
+         result.printResult(writer);
+      }
+      finally
+      {
+         writer.println("Handled in " + (System.currentTimeMillis() - start) + "ms"); 
+         writer.close();
+      }
+      
+      
+      
+   }
+}

Added: projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/AbstractInspectorCommand.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/AbstractInspectorCommand.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/AbstractInspectorCommand.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,63 @@
+/*
+* 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.microcontainer.mcinspector.command.impl;
+
+import org.jboss.logging.Logger;
+import org.jboss.microcontainer.mcinspector.command.InspectorCommand;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractInspectorCommand implements InspectorCommand
+{
+   protected final Logger log = Logger.getLogger(this.getClass());
+   
+   private final String command;
+   
+   private final String helpOverview;
+   
+   private final String[] helpDetail;
+   
+   public AbstractInspectorCommand(String command, String helpOverview, String...helpDetail)
+   {
+      this.command = command;
+      this.helpOverview = helpOverview;
+      this.helpDetail = helpDetail;
+   }
+   
+   public String getName()
+   {
+      return command;
+   }
+
+   public String getHelpOverview()
+   {
+      return helpOverview;
+   }
+
+   public String[] getHelpDetail()
+   {
+      return helpDetail;
+   }
+}

Added: projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/AbstractInspectorCommands.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/AbstractInspectorCommands.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/AbstractInspectorCommands.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,96 @@
+/*
+* 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.microcontainer.mcinspector.command.impl;
+
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.jboss.logging.Logger;
+import org.jboss.microcontainer.mcinspector.command.CommandArguments;
+import org.jboss.microcontainer.mcinspector.command.CommandResult;
+import org.jboss.microcontainer.mcinspector.command.InspectorCommand;
+import org.jboss.microcontainer.mcinspector.command.InspectorCommands;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractInspectorCommands implements InspectorCommands
+{
+   protected final Logger log = Logger.getLogger(this.getClass().getName());
+   
+   private final Map<String, InspectorCommand> commands = new LinkedHashMap<String, InspectorCommand>();
+   
+   public void addCommand(InspectorCommand command)
+   {
+      if (command == null)
+         throw new IllegalArgumentException("Null command");
+      if (command.getName() == null)
+         throw new IllegalArgumentException("Null name for " + command);
+      if (command.getName().contains(" "))
+         throw new IllegalArgumentException("The name of the command '" + command.getName() + "' contains spaces which is illegal");
+      
+      commands.put(command.getName(), command);
+      
+      log.debug("Added command handler for " + command.getName() + ": " + command);
+   }
+
+   public boolean removeCommand(InspectorCommand command)
+   {
+      if (command == null)
+         return false;
+      log.debug("Removing command handler for " + command.getName());
+      return commands.remove(command.getName()) != null;
+   }
+
+   public CommandResult execute(CommandArguments args)
+   {
+      InspectorCommand command = commands.get(args.getCommand()); 
+         
+      log.debug("Found command for '" + args.getCommand() + "' :" + (command != null));
+      if (command == null)
+         return new CommandResult("Unknown command '" + args.getCommand() + "'.",
+         		"Pass in 'help' for a list of commands.",
+         		"To see more options for a particular command pass in 'help <command>'.");
+      
+      CommandResult result = command.execute(args);
+      if (log.isDebugEnabled())
+      {
+         log.debug("Got result");
+         for (String s : result.getLines())
+            log.debug(s);
+      }
+      return result;
+   }
+
+   public Map<String, InspectorCommand> getCommands()
+   {
+      return Collections.unmodifiableMap(commands);
+   }
+   
+   public InspectorCommand getCommand(String name)
+   {
+      return commands.get(name);
+   }
+}

Added: projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/BasicInspectorCommands.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/BasicInspectorCommands.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/BasicInspectorCommands.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,31 @@
+/*
+* 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.microcontainer.mcinspector.command.impl;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class BasicInspectorCommands extends AbstractInspectorCommands
+{
+}

Added: projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/BeanCommand.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/BeanCommand.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/BeanCommand.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,140 @@
+/*
+* 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.microcontainer.mcinspector.command.impl;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.DependencyInfo;
+import org.jboss.dependency.spi.DependencyItem;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.microcontainer.mcinspector.command.CommandArguments;
+import org.jboss.microcontainer.mcinspector.command.CommandResult;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class BeanCommand extends AbstractInspectorCommand
+{
+   public BeanCommand()
+   {
+      // FIXME HelpCommand constructor
+      super("bean",
+            "Inspect a particular bean.",
+            "Gives detailed information about one or more beans.",
+            getUsage(null));
+   }
+   
+   private static String getUsage(String programName)
+   {
+      String s = programName == null ? "" : programName;
+      return "Usage:" + s + " bean <context name> [<context name>]*";
+   }
+
+   public CommandResult execute(CommandArguments args)
+   {
+      if (args.getCommandArguments().length == 0)
+         return new CommandResult(getUsage(args.getProgramName()));
+      
+      CommandResult result = new CommandResult();
+      for (String name : args.getCommandArguments())
+      {
+         outputContext(args, result, name);
+      }
+      return result;
+   }
+   
+   private void outputContext(CommandArguments args, CommandResult result, String name)
+   {
+      ControllerContext context = args.getKernel().getController().getContext(name, null);
+      
+      result.appendResultLine("Name='" + name + "'");
+      if (context == null)
+      {
+         result.appendResultLine("  ***NOT FOUND***");
+         return;
+      }
+      else
+      {
+         result.appendResultLine("  bean type=" + getType(context));
+         result.appendResultLine("  mode=" + context.getMode());
+         result.appendResultLine("  state=" + context.getState().getStateString().toUpperCase());
+         result.appendResultLine("  required state=" + context.getRequiredState().getStateString().toUpperCase());
+         result.appendResultLine("  context type=" + context.getClass().getName());
+         result.appendResultLine("  unresolved dependencies=" + countUnresolvedDependencies(context));
+      }
+      
+      if (args.getCommandOption("d") != null)
+         outputDependencies(result, context, true);
+      else if (args.getCommandOption("u") != null)
+         outputDependencies(result, context, false);
+   }
+   
+   private String getType(ControllerContext context)
+   {
+      if (context instanceof KernelControllerContext)
+         return ((KernelControllerContext)context).getBeanMetaData().getBean();
+      else
+      {
+         Object target = context.getTarget();
+         if (target == null)
+            return "???";
+         
+         return target.getClass().getName();
+      }
+   }
+   
+   private int countUnresolvedDependencies(ControllerContext context)
+   {
+      DependencyInfo info = context.getDependencyInfo();
+      if (info == null)
+         return 0;
+      return info.getUnresolvedDependencies(null).size();
+   }
+   
+   private void outputDependencies(CommandResult result, ControllerContext context, boolean all)
+   {
+      if (all)
+      {
+         result.appendResultLine("   Resolved dependencies:");
+         outputDependencyItems(result, context, true);
+      }
+      result.appendResultLine("   Unresolved dependencies:");
+      outputDependencyItems(result, context, false);
+   }
+   
+   private void outputDependencyItems(CommandResult result, ControllerContext context, boolean resolved)
+   {
+      if (context.getDependencyInfo() == null)
+         return;
+      
+      for (DependencyItem item : context.getDependencyInfo().getIDependOn(null))
+      {
+         if (item.isResolved() == resolved)
+         {
+            result.appendResultLine("      iDependOn=" + item.getIDependOn() + 
+                  "; whenRequired=" + item.getWhenRequired().getStateString().toUpperCase() + 
+                  "; dependentState=" + item.getDependentState().getStateString().toUpperCase());
+         }
+      }
+   }
+}

Added: projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/ChangeCommand.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/ChangeCommand.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/ChangeCommand.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,118 @@
+/*
+* 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.microcontainer.mcinspector.command.impl;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerMode;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.microcontainer.mcinspector.command.CommandArguments;
+import org.jboss.microcontainer.mcinspector.command.CommandResult;
+import org.jboss.microcontainer.mcinspector.command.ClientCommandArguments.CommandOption;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ChangeCommand extends AbstractInspectorCommand
+{
+   public ChangeCommand()
+   {
+      // FIXME HelpCommand constructor
+      super("change",
+            "Changes the state of the context.",
+            "Changes the state of the context if all the dependencies are satisfied.",
+            getUsage(null),
+            "" +
+            "Options:",
+            "-f  From state. If no from_state argument is used an attempt is made to move " +
+            "    the context to the target state regardless of which state it is currently in.");
+   }
+   
+   private static String getUsage(String programName)
+   {
+      String s = programName == null ? "" : programName;
+      return "Usage:" + s + " list [-f=<from_state>] <state> <context name>";
+   }
+
+   public CommandResult execute(CommandArguments args)
+   {
+      if (args.getCommandArguments().length != 2)
+         return new CommandResult(getUsage(args.getProgramName()));
+      
+      ControllerState toState = getState(args, args.getCommandArguments()[0]); 
+
+      if (toState == null)
+         return new CommandResult("'" + args.getCommandArguments()[0] + "' is not a recognized state");
+
+      ControllerState fromState = null;
+      if (args.getCommandOption("f") != null)
+      {
+         CommandOption option = args.getCommandOption("f");
+         if (option.getValues().length == 0)
+            return new CommandResult("-f option must take a value, e.g. -f=INSTALLED");
+         if (option.getValues().length > 1)
+            return new CommandResult("-f option must take a single value, e.g. -f=INSTALLED");
+            
+         fromState = getState(args, option.getValues()[0]);
+         if (fromState == null)
+            return new CommandResult("'" + option.getValues()[0] + "' is not a recognized state");
+      }
+      
+      Object name = args.getCommandArguments()[1]; 
+      ControllerContext context = args.getKernel().getController().getContext(name, fromState);
+      if (context == null || (fromState != null && !context.getState().equals(fromState)))
+      {
+         StringBuilder sb = new StringBuilder("Could not find a context called '" + name + "'");
+         if (fromState != null)
+            sb.append(" in state '" + fromState.getStateString().toUpperCase() + "'");
+         sb.append(".");
+         return new CommandResult(sb.toString());
+      }
+      
+      try
+      {
+         args.getKernel().getController().change(context, toState);
+      }
+      catch (Throwable e)
+      {
+         log.error("Error changing state of " + context + " to " + toState.getStateString(), e);
+         throw new RuntimeException(e);
+      }
+      
+      if (context.getMode() == ControllerMode.ASYNCHRONOUS)
+         return new CommandResult("Asynchronously changing '" + name + "' to " + toState.getStateString().toUpperCase());
+
+      return new CommandResult("Changed '" + name + "' to " + toState.getStateString().toUpperCase());
+   }
+   
+   private ControllerState getState(CommandArguments args, String stateString)
+   {
+      for (ControllerState state : args.getKernel().getController().getStates())
+      {
+         if (state.getStateString().equalsIgnoreCase(stateString))
+            return state;
+      }
+      return null;
+   }
+   
+}

Added: projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/ClientCommandArgumentsImpl.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/ClientCommandArgumentsImpl.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/ClientCommandArgumentsImpl.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,198 @@
+/*
+* 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.microcontainer.mcinspector.command.impl;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.microcontainer.mcinspector.command.ClientCommandArguments;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClientCommandArgumentsImpl implements ClientCommandArguments
+{
+   private static final long serialVersionUID = 1L;
+
+   private static final String[] EMPTY_STRINGS = new String[0];
+
+   private static final CommandOption[] EMPTY_OPTIONS = new CommandOption[0];
+   
+   private final String programName;
+   
+   private final SplitArguments splitArgs;
+
+   public ClientCommandArgumentsImpl(String programName, String args)
+   {
+      this(programName, parseArguments(args));
+   }
+   
+   public ClientCommandArgumentsImpl(String programName, String[] args)
+   {
+      this(programName, SplitArguments.splitArguments(args));
+   }
+   
+   private ClientCommandArgumentsImpl(String programName, SplitArguments splitArgs)
+   {
+      this.programName = programName == null ? "" : programName;
+      this.splitArgs = splitArgs;
+   }
+   
+   private static String[] parseArguments(String args)
+   {
+      String[] commandItems = args != null ? args.split(" ") : EMPTY_STRINGS;
+      ArrayList<String> list = new ArrayList<String>();
+      
+      for (String commandItem : commandItems)
+      {
+         String s = commandItem.trim();
+         if (s.length() > 0)
+            list.add(s);
+      }
+      
+      return list.toArray(new String[list.size()]);
+   }
+
+   public String getProgramName()
+   {
+      return programName;
+   }
+   
+   public String getCommand()
+   {
+      return splitArgs.command;
+   }
+
+   public String[] getCommandArguments()
+   {
+      return splitArgs.arguments;
+   }
+   
+   public boolean hasCommandArguments()
+   {
+      return getCommandArguments().length > 0;
+   }
+   
+   public CommandOption[] getCommandOptions()
+   {
+      return splitArgs.options;
+   }
+
+   public boolean hasCommandOptions()
+   {
+      return getCommandOptions().length > 0;
+   }
+   
+   public CommandOption getCommandOption(String name)
+   {
+      for (CommandOption option : getCommandOptions())
+      {
+         if (option.getName().equals(name))
+            return option;
+      }
+      return null;
+   }
+
+   public static class OptionImpl implements CommandOption
+   {
+      private static final long serialVersionUID = 1L;
+      
+      String name;
+      String[] values = EMPTY_STRINGS;
+      
+      public String getName()
+      {
+         return name;
+      }
+
+      public String[] getValues()
+      {
+         return values;
+      }
+      
+      static OptionImpl parse(String option)
+      {
+         String original = option;
+         OptionImpl opt = new OptionImpl();
+         
+         option = option.trim();
+         if (!option.startsWith("-"))
+            throw new IllegalArgumentException("Not an option " + original);
+         if (option.length() == 1)
+            throw new IllegalArgumentException("Option cannot just be '-'");
+         
+         option = option.substring(1);
+         int equals = option.indexOf("=");
+         if (equals == -1)
+         {
+            opt.name = option;
+            return opt;
+         }
+         
+         opt.name = option.substring(0, equals);
+         if (equals == option.length() - 1)
+            throw new IllegalArgumentException("'" + original + "' needs a value after the '='");
+         String value = option.substring(equals + 1);
+         opt.values = value.split(",");
+
+         return opt;
+      }
+   }
+   
+   
+   /**
+    * Splits the raw arguments into something more meaningful
+    */
+   private static class SplitArguments implements Serializable
+   {
+      private static final long serialVersionUID = 1L;
+      String command = "";
+      String[] arguments = EMPTY_STRINGS;
+      CommandOption[] options = EMPTY_OPTIONS;
+      
+      static SplitArguments splitArguments(String[] rawArguments)
+      {
+         SplitArguments args = new SplitArguments();
+         if (rawArguments == null || rawArguments.length == 0)
+            return args;
+
+         List<String> argsList = new ArrayList<String>();
+         List<CommandOption> optionsList = new ArrayList<CommandOption>();
+         
+         args.command = rawArguments[0];
+         for (int i = 1 ; i < rawArguments.length ; i++)
+         {
+            if (rawArguments[i].startsWith("-"))
+               optionsList.add(OptionImpl.parse(rawArguments[i]));
+            else
+               argsList.add(rawArguments[i]);
+         }
+         args.arguments = argsList.toArray(new String[argsList.size()]);
+         args.options = optionsList.toArray(new CommandOption[optionsList.size()]);
+         
+         return args;
+      }
+   }
+}

Added: projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/CommandArgumentsImpl.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/CommandArgumentsImpl.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/CommandArgumentsImpl.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,68 @@
+/*
+* 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.microcontainer.mcinspector.command.impl;
+
+import org.jboss.kernel.Kernel;
+import org.jboss.microcontainer.mcinspector.command.CommandArguments;
+import org.jboss.microcontainer.mcinspector.command.InspectorCommands;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class CommandArgumentsImpl extends ClientCommandArgumentsImpl implements CommandArguments
+{
+   private static final long serialVersionUID = 1L;
+   
+   private volatile Kernel kernel;
+   
+   private volatile InspectorCommands commands;
+   
+   public CommandArgumentsImpl(String programName, String args)
+   {
+      super(programName, args);
+   }
+
+   public Kernel getKernel()
+   {
+      return kernel;
+   }
+
+   public void setKernel(Kernel kernel)
+   {
+      if (kernel == null)
+         throw new IllegalArgumentException("Null kernel");
+      this.kernel = kernel;
+   }
+
+   public InspectorCommands getCommands()
+   {
+      return commands;
+   }
+
+   public void setCommands(InspectorCommands commands)
+   {
+      this.commands = commands;
+   }
+
+}

Added: projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/DelegatingCommandArgumentsImpl.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/DelegatingCommandArgumentsImpl.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/DelegatingCommandArgumentsImpl.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,103 @@
+/*
+* 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.microcontainer.mcinspector.command.impl;
+
+import org.jboss.kernel.Kernel;
+import org.jboss.microcontainer.mcinspector.command.ClientCommandArguments;
+import org.jboss.microcontainer.mcinspector.command.CommandArguments;
+import org.jboss.microcontainer.mcinspector.command.InspectorCommands;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class DelegatingCommandArgumentsImpl implements CommandArguments
+{
+   private static final long serialVersionUID = 1L;
+
+   private final ClientCommandArguments delegate;
+   
+   private volatile Kernel kernel;
+   
+   private volatile InspectorCommands commands;
+
+   public DelegatingCommandArgumentsImpl(ClientCommandArguments delegate)
+   {
+      this.delegate = delegate;
+   }
+
+   public Kernel getKernel()
+   {
+      return kernel;
+   }
+
+   public void setKernel(Kernel kernel)
+   {
+      this.kernel = kernel;
+   }
+
+   public String getCommand()
+   {
+      return delegate.getCommand();
+   }
+
+   public String[] getCommandArguments()
+   {
+      return delegate.getCommandArguments();
+   }
+
+   public String getProgramName()
+   {
+      return delegate.getProgramName();
+   }
+
+   public boolean hasCommandArguments()
+   {
+      return delegate.hasCommandArguments();
+   }
+
+   public InspectorCommands getCommands()
+   {
+      return commands;
+   }
+
+   public void setCommands(InspectorCommands commands)
+   {
+      this.commands = commands;
+   }
+
+   public CommandOption[] getCommandOptions()
+   {
+      return delegate.getCommandOptions();
+   }
+
+   public boolean hasCommandOptions()
+   {
+      return delegate.hasCommandOptions();
+   }
+
+   public CommandOption getCommandOption(String name)
+   {
+      return delegate.getCommandOption(name);
+   }
+}

Added: projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/HelpCommand.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/HelpCommand.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/HelpCommand.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,100 @@
+/*
+* 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.microcontainer.mcinspector.command.impl;
+
+import java.util.Collection;
+import java.util.Map;
+
+import org.jboss.microcontainer.mcinspector.command.CommandArguments;
+import org.jboss.microcontainer.mcinspector.command.CommandResult;
+import org.jboss.microcontainer.mcinspector.command.InspectorCommand;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class HelpCommand extends AbstractInspectorCommand
+{
+   public HelpCommand()
+   {
+      // FIXME HelpCommand constructor
+      super("help",
+            "Prints the list of available commands.",
+            "Prints the list of available commands.", 
+            "For details about a particular command specify ", "help <command>");
+   }
+
+   public CommandResult execute(CommandArguments args)
+   {
+      if (args.getCommandArguments().length > 1)
+         return new CommandResult("Usage:" + args.getProgramName() + " help [command]");
+      
+      if (!args.hasCommandArguments())
+         return formatAllCommands(args);
+         
+      InspectorCommand command = args.getCommands().getCommand(args.getCommandArguments()[0]);
+      if (command == null)
+         return new CommandResult("Unknown command '" + args.getCommandArguments()[0] + "'. No help available.");
+      
+      return new CommandResult(command.getHelpDetail());
+   }
+   
+   private CommandResult formatAllCommands(CommandArguments args)
+   {
+      CommandResult result = new CommandResult("Available commands:");
+      Map<String, InspectorCommand> allCommands = args.getCommands().getCommands();
+      
+      int pad = determineMaxLength(allCommands.keySet());
+      
+      for (Map.Entry<String, InspectorCommand> entry : allCommands.entrySet())
+      {
+         result.appendResultLine(pad(entry.getKey(), pad) + entry.getValue().getHelpOverview());
+      }
+
+      result.appendResultLine("For more information about a particular command, enter 'help <command>'.");
+      
+      return result;
+   }
+   
+   private String pad(String s, int length)
+   {
+      int pad = length - s.length();
+      StringBuilder sb = new StringBuilder("   ");
+      sb.append(s);
+      sb.append("  ");
+      for (int i = 0 ; i < pad ; i++)
+         sb.append(" ");
+      return sb.toString();
+   }
+   
+   private int determineMaxLength(Collection<String> commandNames)
+   {
+      int max = 0;
+      for (String cmd : commandNames)
+      {
+         if (cmd.length() > max)
+            max = cmd.length();
+      }
+      return max;
+   }
+}

Added: projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/ListCommand.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/ListCommand.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/main/java/org/jboss/microcontainer/mcinspector/command/impl/ListCommand.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,147 @@
+/*
+* 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.microcontainer.mcinspector.command.impl;
+
+import java.util.Set;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.DependencyInfo;
+import org.jboss.microcontainer.mcinspector.command.CommandArguments;
+import org.jboss.microcontainer.mcinspector.command.CommandResult;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ListCommand extends AbstractInspectorCommand
+{
+   public ListCommand()
+   {
+      // FIXME HelpCommand constructor
+      super("list",
+            "Lists all the available contexts.",
+            "Lists all the contexts in the controller.",
+            getUsage(null),
+            "If no state arguments are passed in all states will be checked for contexts. Otherwise" +
+            "only the passed in states will be checked",
+            "Options:",
+            "-o  Overview. Show all the states in the controller with the number of contexts in each" +
+            "    Normally only states with contexts will be shown",
+            "-e  Error. Show only the contexts which are in the error state. Can not be used in combination with state arguments.",
+            "-v  Verbose. Show extra information for each context. Contexts with unresolved dependencies will" +
+            "    have a '*' after their name. Additional information is in the format (ControllerMode, Current state");
+   }
+   
+   private static String getUsage(String programName)
+   {
+      String s = programName == null ? "" : programName;
+      return "Usage:" + s + " list [-o | -v] [<state> [<state>]*]";
+   }
+
+   public CommandResult execute(CommandArguments args)
+   {
+      if (args.getCommandOption("v") != null && args.getCommandOption("o") != null)
+         throw new IllegalArgumentException("Can't use both -v and -o");
+      if (args.getCommandOption("v") != null && args.getCommandOption("e") != null)
+         throw new IllegalArgumentException("Can't use both -v and -e");
+      if (args.getCommandOption("v") != null && args.getCommandOption("o") != null)
+         throw new IllegalArgumentException("Can't use both -v and -o");
+      if (args.getCommandOption("e") != null && args.getCommandArguments().length > 0)
+         throw new IllegalArgumentException("Can not use -e in combination with passed in states");
+      CommandResult result = new CommandResult();
+      if (args.getCommandOption("e") != null)
+         getErrorContexts(args, result);
+      else
+         getContextsForStates(args, result);
+      return result;
+   }
+   
+   private void getErrorContexts(CommandArguments args, CommandResult result)
+   {
+      boolean isVerbose = args.getCommandOption("v") != null;
+      for (ControllerContext context : args.getKernel().getController().getNotInstalled())
+      {
+         if (context.getState().equals(ControllerState.ERROR))
+            outputContext(result, context, isVerbose);
+      }
+   }
+       
+   
+   private void getContextsForStates(CommandArguments args, CommandResult result)
+   {
+      String[] cmdArgs = args.getCommandArguments();
+      for (ControllerState state : args.getKernel().getController().getStates())
+      {
+         boolean useState = true;
+         if (cmdArgs.length > 0)
+         {
+            useState = false;
+            for (String cmdState : cmdArgs)
+            {
+               if (cmdState.equalsIgnoreCase(state.getStateString()))
+               {
+                  useState = true;
+                  break;
+               }
+            }
+         }
+         
+         if (useState)
+            getContextsForState(args, result, state);
+      }
+   }
+
+   private void getContextsForState(CommandArguments args, CommandResult result, ControllerState state)
+   {
+      boolean isVerbose = args.getCommandOption("v") != null;
+      Set<ControllerContext> contexts = args.getKernel().getController().getContextsByState(state);
+      if (args.getCommandOption("o") != null)
+      {
+         result.appendResultLine(state.getStateString() + ": " + contexts.size() + " contexts");
+      }
+      else if (contexts.size() > 0)
+      {
+         result.appendResultLine(state.getStateString() + ": ");
+         for (ControllerContext context : contexts)
+         {
+            outputContext(result, context, isVerbose);
+         }
+      }
+   }
+   
+   private void outputContext(CommandResult result, ControllerContext context, boolean isVerbose)
+   {
+      StringBuilder line = new StringBuilder("  " + context.getName().toString());
+      if (isVerbose)
+      {
+         String unresolved = "";
+         DependencyInfo info = context.getDependencyInfo();
+         if (info != null && info.getUnresolvedDependencies(null).size() > 0)
+            unresolved = "*";
+            
+         line.append(unresolved + " (" + context.getMode() + ", " + context.getState().getStateString().toUpperCase() + ")");
+      }
+      result.appendResultLine(line.toString());
+   }
+}

Added: projects/mc-tools/mcinspector/trunk/src/main/resources/META-INF/mcinspector-jboss-beans.xml
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/main/resources/META-INF/mcinspector-jboss-beans.xml	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/main/resources/META-INF/mcinspector-jboss-beans.xml	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,23 @@
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+   <bean name="McInspectorCommands" class="org.jboss.microcontainer.mcinspector.command.impl.BasicInspectorCommands">
+      <incallback method="addCommand"/>
+      <uncallback method="removeCommand"/>
+   </bean>
+   
+   <bean name="McInspector" class="org.jboss.microcontainer.mcinspector.bean.McInspector">
+      <constructor>
+         <parameter><inject bean="jboss.kernel:service=Kernel"/></parameter>
+         <parameter><inject bean="McInspectorCommands"/></parameter>
+      </constructor>
+      <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(exposedInterface=org.jboss.microcontainer.mcinspector.bean.McInspectorMBean.class, name="org.jboss.kernel:service=McInspector")</annotation>
+   </bean>
+   
+   <bean name="McInspectorHelpCommand" class="org.jboss.microcontainer.mcinspector.command.impl.HelpCommand"/>
+   <bean name="McInspectorListCommand" class="org.jboss.microcontainer.mcinspector.command.impl.ListCommand"/>
+   <bean name="McInspectorChangeCommand" class="org.jboss.microcontainer.mcinspector.command.impl.ChangeCommand"/>
+   <bean name="McInspectorBeanCommand" class="org.jboss.microcontainer.mcinspector.command.impl.BeanCommand"/>
+
+</deployment>
+
+

Added: projects/mc-tools/mcinspector/trunk/src/main/resources/jndi.properties
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/main/resources/jndi.properties	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/main/resources/jndi.properties	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,6 @@
+# DO NOT EDIT THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING
+#
+#jboss JNDI properties
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.provider.url=jnp://localhost:1099
+java.naming.factory.url.pkgs=org.jnp.interfaces

Added: projects/mc-tools/mcinspector/trunk/src/main/resources/log4j.properties
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/main/resources/log4j.properties	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/main/resources/log4j.properties	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,21 @@
+### ====================================================================== ###
+##                                                                          ##
+##  JBoss Bootstrap Log4j Configuration                                     ##
+##                                                                          ##
+### ====================================================================== ###
+
+### $Id: log4j.properties 20741 2004-04-26 00:35:27Z starksm $ ###
+
+log4j.rootCategory=DEBUG, CONSOLE, FILE
+
+log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
+log4j.appender.CONSOLE.Threshold=INFO
+log4j.appender.CONSOLE.Target=System.out
+log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
+log4j.appender.CONSOLE.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c{1}] %m%n
+
+log4j.appender.FILE=org.apache.log4j.FileAppender
+log4j.appender.FILE.File=twiddle.log
+log4j.appender.FILE.Append=false
+log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
+log4j.appender.FILE.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c{1}] %m%n

Added: projects/mc-tools/mcinspector/trunk/src/main/resources/mcinspector.sh
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/main/resources/mcinspector.sh	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/main/resources/mcinspector.sh	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,85 @@
+#!/bin/sh
+### ====================================================================== ###
+##                                                                          ##
+##  JBoss Shutdown Script                                                   ##
+##                                                                          ##
+### ====================================================================== ###
+
+### $Id: twiddle.sh 63457 2007-06-11 16:33:37Z anil.saldhana at jboss.com $ ###
+
+DIRNAME=`dirname $0`
+PROGNAME=`basename $0`
+GREP="grep"
+
+#
+# Helper to complain.
+#
+die() {
+    echo "${PROGNAME}: $*"
+    exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false;
+case "`uname`" in
+    CYGWIN*)
+        cygwin=true
+        ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched
+if $cygwin ; then
+    [ -n "$JBOSS_HOME" ] &&
+        JBOSS_HOME=`cygpath --unix "$JBOSS_HOME"`
+    [ -n "$JAVA_HOME" ] &&
+        JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Setup JBOSS_HOME
+if [ "x$JBOSS_HOME" = "x" ]; then
+    JBOSS_HOME=`cd $DIRNAME/..; pwd`
+fi
+export JBOSS_HOME
+
+# Setup the JVM
+if [ "x$JAVA_HOME" != "x" ]; then
+    JAVA=$JAVA_HOME/bin/java
+else
+    JAVA="java"
+fi
+
+# Setup the classpath
+#JBOSS_BOOT_CLASSPATH="$JBOSS_HOME/bin/twiddle.jar"
+JBOSS_BOOT_CLASSPATH=.
+
+if [ "x$JBOSS_CLASSPATH" = "x" ]; then
+    JBOSS_CLASSPATH="$JBOSS_BOOT_CLASSPATH"
+    JBOSS_CLASSPATH="$JBOSS_CLASSPATH:$JBOSS_HOME/client/jbossall-client.jar"
+    JBOSS_CLASSPATH="$JBOSS_CLASSPATH:$JBOSS_HOME/client/jbosssx-client.jar"
+    JBOSS_CLASSPATH="$JBOSS_CLASSPATH:$JBOSS_HOME/client/jboss-common.jar"    
+    JBOSS_CLASSPATH="$JBOSS_CLASSPATH:$JBOSS_HOME/client/getopt.jar"
+    JBOSS_CLASSPATH="$JBOSS_CLASSPATH:$JBOSS_HOME/client/log4j.jar"
+    JBOSS_CLASSPATH="$JBOSS_CLASSPATH:$JBOSS_HOME/lib/jboss-jmx.jar"
+    JBOSS_CLASSPATH="$JBOSS_CLASSPATH:$JBOSS_HOME/lib/dom4j.jar"    
+else
+    JBOSS_CLASSPATH="$JBOSS_CLASSPATH:$JBOSS_BOOT_CLASSPATH"
+fi
+
+# Setup the java endorsed dirs
+JBOSS_ENDORSED_DIRS="$JBOSS_HOME/lib/endorsed"
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin; then
+    JBOSS_HOME=`cygpath --path --windows "$JBOSS_HOME"`
+    JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
+    JBOSS_CLASSPATH=`cygpath --path --windows "$JBOSS_CLASSPATH"`
+    JBOSS_ENDORSED_DIRS=`cygpath --path --windows "$JBOSS_ENDORSED_DIRS"`    
+fi
+
+# Execute the JVM
+exec "$JAVA" \
+    $JAVA_OPTS \
+    -Djava.endorsed.dirs="$JBOSS_ENDORSED_DIRS" \
+    -Dprogram.name="$PROGNAME" \
+    -classpath $JBOSS_CLASSPATH \
+    org.jboss.microcontainer.mcinspector.command.client.McInspectorClient "$@"

Added: projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/AbstractInspectorTest.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/AbstractInspectorTest.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/AbstractInspectorTest.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,372 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.microcontainer.mcinspector;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.UUID;
+
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.kernel.spi.metadata.KernelMetaDataRepository;
+import org.jboss.microcontainer.mcinspector.bean.McInspector;
+import org.jboss.microcontainer.mcinspector.command.InspectorCommands;
+import org.jboss.microcontainer.mcinspector.command.impl.BasicInspectorCommands;
+import org.jboss.test.AbstractTestCaseWithSetup;
+import org.jboss.test.AbstractTestDelegate;
+import org.jboss.test.microcontainer.mcinspector.kernel.support.SimpleBean;
+
+/**
+ * A MicrocontainerTest.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 99939 $
+ */
+public abstract class AbstractInspectorTest extends AbstractTestCaseWithSetup
+{
+   
+   protected InspectorCommands commands;
+   protected McInspector inspector;
+   
+   Set<KernelControllerContext> deployedContexts = new HashSet<KernelControllerContext>(); 
+   
+   /**
+    * Get the test delegate
+    * 
+    * @param clazz the test class
+    * @return the delegate
+    * @throws Exception for any error
+    */
+   public static AbstractTestDelegate getDelegate(Class<?> clazz) throws Exception
+   {
+      return new AbstractInspectorTestDelegate(clazz);
+   }
+   
+   /**
+    * Create a new Microcontainer test
+    * 
+    * @param name the test name
+    */
+   public AbstractInspectorTest(String name)
+   {
+      super(name);
+   }
+   
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      commands = initializeCommands();
+      inspector = new McInspector(getKernel(), commands);
+      afterSetUp();
+   }
+   
+   protected InspectorCommands initializeCommands()
+   {
+      InspectorCommands commands = new BasicInspectorCommands();
+      setupCommands(commands);
+      return commands;
+   }
+   
+   protected abstract void setupCommands(InspectorCommands commands);
+
+   protected void afterSetUp() throws Exception
+   {
+      configureLogging();
+   }
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      super.tearDown();
+      
+      while (deployedContexts.isEmpty() == false)
+      {
+         undeploy(deployedContexts.iterator().next());
+      }
+   }
+   
+   
+
+   /**
+    * Get the test's bean name.
+    * By default it's random uuid.
+    *
+    * @return test's bean name
+    */
+   protected String createTestBeanName()
+   {
+      return UUID.randomUUID().toString();
+   }
+
+   /**
+    * Get the underlying controller.
+    *
+    * @return the controller
+    */
+   protected KernelController getController()
+   {
+      AbstractInspectorTestDelegate delegate = getInspectorDelegate();
+      Kernel kernel = delegate.kernel;
+      return kernel.getController();
+   }
+
+   protected Kernel getKernel()
+   {
+      AbstractInspectorTestDelegate delegate = getInspectorDelegate();
+      return delegate.kernel;
+   }
+
+   
+   
+   /**
+    * Get a bean
+    * 
+    * @param name the bean name
+    * @return the bean
+    * @throws IllegalStateException when the bean does not exist
+    */
+   protected Object getBean(Object name)
+   {
+      return getBean(name, ControllerState.INSTALLED);
+   }
+   
+   /**
+    * Get a bean
+    * 
+    * @param name the name of the bean
+    * @param state the state of the bean
+    * @return the bean
+    * @throws IllegalStateException when the bean does not exist at that state
+    */
+   protected Object getBean(Object name, ControllerState state)
+   {
+      return getInspectorDelegate().getBean(name, state);
+   }
+   
+   /**
+    * Get a bean
+    * 
+    * @param <T> the expected type
+    * @param name the name of the bean
+    * @param state the state of the bean
+    * @param expected the expected type
+    * @return the bean
+    * @throws IllegalStateException when the bean does not exist at that state
+    */
+   protected <T> T assertBean(Object name, ControllerState state, Class<T> expected)
+   {
+      return getInspectorDelegate().getBean(name, state, expected);
+   }
+   
+   /**
+    * Get a bean
+    * 
+    * @param <T> the expected type
+    * @param name the name of the bean
+    * @param expected the expected type
+    * @return the bean
+    * @throws IllegalStateException when the bean does not exist at that state
+    */
+   protected <T> T assertBean(Object name, Class<T> expected)
+   {
+      return assertBean(name, ControllerState.INSTALLED, expected);
+   }
+   
+   /**
+    * Assert there is no bean
+    * 
+    * @param name the name of the bean
+    * @throws IllegalStateException when the bean exists
+    */
+   protected void assertNoBean(Object name)
+   {
+      assertNoBean(name, ControllerState.INSTALLED);
+   }
+   
+   /**
+    * Assert there is no bean
+    * 
+    * @param name the name of the bean
+    * @param state the context state
+    * @throws IllegalStateException when the bean exists
+    */
+   protected void assertNoBean(Object name, ControllerState state)
+   {
+      assertNoControllerContext(name, state);
+   }
+
+   /**
+    * Get a context
+    * 
+    * @param name the bean name
+    * @return the context
+    * @throws IllegalStateException when the context does not exist 
+    */
+   protected KernelControllerContext getControllerContext(Object name)
+   {
+      return getControllerContext(name, ControllerState.INSTALLED);
+   }
+
+   /**
+    * Get a context
+    * 
+    * @param name the name of the bean
+    * @param state the state of the bean
+    * @return the context
+    * @throws IllegalStateException when the context does not exist at that state
+    */
+   protected KernelControllerContext getControllerContext(Object name, ControllerState state)
+   {
+      return getInspectorDelegate().getControllerContext(name, state);
+   }
+
+   /**
+    * Assert there is no context at the given state
+    * 
+    * @param name the name of the bean
+    * @param state the state of the bean
+    * @throws IllegalStateException when the context exists at that state
+    */
+   protected void assertNoControllerContext(Object name, ControllerState state)
+   {
+      getInspectorDelegate().assertNoControllerContext(name, state);
+   }
+
+   /**
+    * Change the context to the given state
+    * 
+    * @param context the context
+    * @param required the required state
+    * @return the actual state
+    * @throws Throwable for any error
+    */
+   public ControllerState change(KernelControllerContext context, ControllerState required) throws Throwable
+   {
+      return getInspectorDelegate().change(context, required);
+   }
+   
+   public ControllerState change(String name, ControllerState required) throws Throwable
+   {
+      for (KernelControllerContext ctx : deployedContexts)
+      {
+         if (ctx.getName().equals(name))
+            return getInspectorDelegate().change(ctx, required);
+      }
+      throw new IllegalArgumentException("No context called " + name);
+   }
+   
+   /**
+    * Deploy a bean
+    *
+    * @param beanMetaData the bean metadata
+    * @return the deployment
+    * @throws Exception for any error  
+    */
+   protected KernelControllerContext deploy(BeanMetaData beanMetaData) throws Exception
+   {
+      KernelControllerContext context = getInspectorDelegate().deploy(beanMetaData);
+      deployedContexts.add(context);
+      return context;
+   }
+   
+   /**
+    * Undeploy a bean
+    *
+    * @param context the context
+    */
+   protected void undeploy(KernelControllerContext context)
+   {
+      getInspectorDelegate().undeploy(context);
+      deployedContexts.remove(context);
+   }
+   
+   /**
+    * Get the metadata repository
+    * 
+    * @return the metadata repository
+    * @throws IllegalStateException when the bean does not exist at that state
+    */
+   protected KernelMetaDataRepository getMetaDataRepository()
+   {
+      return getInspectorDelegate().getMetaDataRepository();
+   }
+
+   /**
+    * Shutdown the controller
+    */
+   protected void shutdown()
+   {
+      getInspectorDelegate().shutdown();
+   }
+   
+   /**
+    * Get the delegate
+    * 
+    * @return the delegate
+    */
+   protected AbstractInspectorTestDelegate getInspectorDelegate()
+   {
+      return (AbstractInspectorTestDelegate) getDelegate();
+   }
+
+   protected void assertInspectorResult(String[] result, String...expected)
+   {
+      assertNotNull(result);
+      assertEquals(expected.length, result.length);
+      for (int i = 0 ; i < expected.length ; i++)
+         assertEquals(expected[i], result[i]);
+   }
+   
+   protected void deployObjectBeans(String...names) throws Throwable
+   {
+      for (int i = 0 ; i < names.length ; i++)
+      {
+         assertNoBean(names[i]);
+         deployBean(names[i], Object.class);
+         assertBean(names[i], Object.class);
+      }
+   }
+   
+   protected void deployBeanWithUnresolvedDependencies(String name, ControllerState state) throws Throwable
+   {
+      deployBeanWithDependency(name, SimpleBean.class, state, "property", "notthere");
+   }
+   
+   protected void deployBeanWithDependency(String name, Class<?> bean, ControllerState state, String property, String dependency) throws Throwable
+   {
+      assertNoBean(name);
+      BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(name, bean.getName());
+      builder.addPropertyMetaData(property, builder.createInject(dependency, null, state, ControllerState.INSTALLED));
+      deploy(builder.getBeanMetaData());
+   }
+
+   protected void deployBean(String name, Class<?> bean) throws Throwable
+   {
+      deploy(new AbstractBeanMetaData(name, bean.getName()));
+   }
+}

Added: projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/AbstractInspectorTestDelegate.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/AbstractInspectorTestDelegate.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/AbstractInspectorTestDelegate.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,270 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.microcontainer.mcinspector;
+
+import java.net.URL;
+
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.plugins.bootstrap.AbstractBootstrap;
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.kernel.spi.metadata.KernelMetaDataRepository;
+import org.jboss.test.AbstractTestDelegate;
+
+/**
+ * A MicrocontainerTestDelegate.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 99939 $
+ */
+public class AbstractInspectorTestDelegate extends AbstractTestDelegate
+{
+   /** The kernel */
+   protected Kernel kernel;
+
+   /**
+    * Create a new MicrocontainerTestDelegate.
+    * 
+    * @param clazz the test class
+    * @throws Exception for any error
+    */
+   public AbstractInspectorTestDelegate(Class<?> clazz) throws Exception
+   {
+      super(clazz);
+   }
+
+   public void setUp() throws Exception
+   {
+      super.setUp();
+      
+      try
+      {
+         // Bootstrap the kernel
+         AbstractBootstrap bootstrap = getBootstrap();
+         bootstrap.run();
+         kernel = bootstrap.getKernel();
+         
+      }
+      catch (Exception e)
+      {
+         super.tearDown();
+         throw e;
+      }
+      catch (Error e)
+      {
+         super.tearDown();
+         throw e;
+      }
+      catch (Throwable e)
+      {
+         super.tearDown();
+         throw new RuntimeException(e);
+      }
+   }
+
+   /**
+    * Get the kernel bootstrap
+    * 
+    * @return the bootstrap
+    * @throws Exception for any error
+    */
+   protected AbstractBootstrap getBootstrap() throws Exception
+   {
+      return new BasicBootstrap();
+   }
+   
+   protected Kernel getKernel() throws Exception
+   {
+      return kernel;
+   }
+   
+   /**
+    * Get a bean
+    *
+    * @param name the name of the bean
+    * @param state the state of the bean
+    * @return the bean
+    * @throws IllegalStateException when the bean does not exist at that state
+    */
+   protected Object getBean(final Object name, final ControllerState state)
+   {
+      KernelControllerContext context = getControllerContext(name, state);
+      return context.getTarget();
+   }
+   
+   /**
+    * Get a bean
+    *
+    * @param <T> the expected type
+    * @param name the name of the bean
+    * @param state the state of the bean
+    * @param expected the expected type
+    * @return the bean
+    * @throws IllegalStateException when the bean does not exist at that state
+    */
+   protected <T> T getBean(final Object name, final ControllerState state, final Class<T> expected)
+   {
+      if (expected == null)
+         throw new IllegalArgumentException("Null expected");
+      Object bean = getBean(name, state);
+      return expected.cast(bean);
+   }
+   
+   /**
+    * Get the metadata repository
+    * @return the metadata repository
+    * @throws IllegalStateException when the bean does not exist at that state
+    */
+   protected KernelMetaDataRepository getMetaDataRepository()
+   {
+      return kernel.getMetaDataRepository();
+   }
+   
+   /**
+    * Get a context
+    *
+    * @param name the name of the bean
+    * @param state the state of the bean
+    * @return the context
+    * @throws IllegalStateException when the context does not exist at that state
+    */
+   protected KernelControllerContext getControllerContext(final Object name, final ControllerState state)
+   {
+      KernelController controller = kernel.getController();
+      KernelControllerContext context = (KernelControllerContext) controller.getContext(name, state);
+      if (context == null)
+         return handleNotFoundContext(controller, name, state);
+      return context;
+   }
+   
+   /**
+    * Assert there is no context at the given state
+    * 
+    * @param name the name of the bean
+    * @param state the state of the bean
+    * @throws IllegalStateException when the context exists at that state
+    */
+   protected void assertNoControllerContext(final Object name, final ControllerState state)
+   {
+      KernelController controller = kernel.getController();
+      KernelControllerContext context = (KernelControllerContext) controller.getContext(name, state);
+      if (context != null)
+         throw new IllegalStateException("Did not expect context at state " + state + " ctx=" + context);
+   }
+
+   /**
+    * Handle not found context.
+    *
+    * @param controller the controller
+    * @param name the name of the bean
+    * @param state the state of the bean
+    * @return the context
+    * @throws IllegalStateException when the context does not exist at that state
+    */
+   protected KernelControllerContext handleNotFoundContext(Controller controller, Object name, ControllerState state)
+   {
+      throw new IllegalStateException("Bean not found " + name + " at state " + state);
+   }
+
+   /**
+    * Change the context to the given state
+    * 
+    * @param context the context
+    * @param required the required state
+    * @return the actual state
+    * @throws Throwable for any error
+    */
+   protected ControllerState change(KernelControllerContext context, ControllerState required) throws Throwable
+   {
+      Controller controller = kernel.getController();
+      controller.change(context, required);
+      return context.getState();
+   }
+
+   
+   /**
+    * Deploy a bean
+    *
+    * @param beanMetaData the bean metadata
+    * @return the deployment
+    * @throws Exception for any error  
+    */
+   protected KernelControllerContext deploy(BeanMetaData beanMetaData) throws Exception
+   {
+      KernelController controller = kernel.getController();
+      log.debugf("Deploying %1s", beanMetaData);
+      try
+      {
+         KernelControllerContext result = controller.install(beanMetaData);
+         log.debugf("Deployed %1s", result.getName());
+         return result;
+      }
+      catch (Exception e)
+      {
+         throw e;
+      }
+      catch (Error e)
+      {
+         throw e;
+      }
+      catch (Throwable t)
+      {
+         throw new RuntimeException("Error deploying bean: " + beanMetaData, t);
+      }
+   }
+   
+   /**
+    * Undeploy a bean
+    *
+    * @param context the context
+    */
+   protected void undeploy(KernelControllerContext context)
+   {
+      if (context == null)
+         throw new IllegalArgumentException("Null context");
+      log.debugf("Undeploying %1s", context.getName());
+      KernelController controller = kernel.getController();
+      controller.uninstall(context.getName());
+      log.debugf("Undeployed %1s", context.getName());
+   }
+
+   protected void shutdown()
+   {
+      kernel.getController().shutdown();
+   }
+
+   protected String getTestName()
+   {
+      String testName = clazz.getName();
+      return testName.replace('.', '/') + ".xml";
+   }
+
+   protected URL getTestResource(String testName)
+   {
+      return clazz.getClassLoader().getResource(testName);
+   }
+}

Added: projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/InspectorTestSuite.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/InspectorTestSuite.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/InspectorTestSuite.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,58 @@
+/*
+* 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.microcontainer.mcinspector;
+
+import org.jboss.test.microcontainer.mcinspector.kernel.test.BeanTestCase;
+import org.jboss.test.microcontainer.mcinspector.kernel.test.ChangeTestCase;
+import org.jboss.test.microcontainer.mcinspector.kernel.test.ListTestCase;
+import org.jboss.test.microcontainer.mcinspector.simple.test.CommandArgumentsTestCase;
+import org.jboss.test.microcontainer.mcinspector.simple.test.SimpleTestCase;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class InspectorTestSuite extends TestSuite
+{
+   public static void main(String[] args)
+   {
+      TestRunner.run(suite());
+   }
+
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite("Inspector Tests");
+
+      suite.addTest(CommandArgumentsTestCase.suite());
+      suite.addTest(SimpleTestCase.suite());
+      suite.addTest(ListTestCase.suite());
+      suite.addTest(ChangeTestCase.suite());
+      suite.addTest(BeanTestCase.suite());
+      
+      return suite;
+   }  
+}
\ No newline at end of file

Added: projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/kernel/support/ErrorBean.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/kernel/support/ErrorBean.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/kernel/support/ErrorBean.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,35 @@
+/*
+* 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.microcontainer.mcinspector.kernel.support;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ErrorBean
+{
+   public ErrorBean()
+   {
+      throw new RuntimeException("An error");
+   }
+}

Added: projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/kernel/support/SimpleBean.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/kernel/support/SimpleBean.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/kernel/support/SimpleBean.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,56 @@
+/*
+* 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.microcontainer.mcinspector.kernel.support;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class SimpleBean
+{
+   Object property;
+   Object property2;
+
+   public Object getProperty()
+   {
+      return property;
+   }
+
+   public void setProperty(Object property)
+   {
+      this.property = property;
+   }
+
+   public Object getProperty2()
+   {
+      return property2;
+   }
+
+   public void setProperty2(Object property2)
+   {
+      this.property2 = property2;
+   }
+   
+   
+   
+}

Added: projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/kernel/test/BeanTestCase.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/kernel/test/BeanTestCase.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/kernel/test/BeanTestCase.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,258 @@
+/*
+* 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.microcontainer.mcinspector.kernel.test;
+
+import junit.framework.Test;
+
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.kernel.plugins.dependency.AbstractKernelControllerContext;
+import org.jboss.microcontainer.mcinspector.command.InspectorCommands;
+import org.jboss.microcontainer.mcinspector.command.impl.BeanCommand;
+import org.jboss.test.microcontainer.mcinspector.AbstractInspectorTest;
+import org.jboss.test.microcontainer.mcinspector.kernel.support.ErrorBean;
+import org.jboss.test.microcontainer.mcinspector.kernel.support.SimpleBean;
+
+/**
+ * Tests the bean command
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class BeanTestCase extends AbstractInspectorTest
+{
+
+   public BeanTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(BeanTestCase.class);
+   }
+
+   @Override
+   protected void setupCommands(InspectorCommands commands)
+   {
+      commands.addCommand(new BeanCommand());
+   }
+   
+   public void testNoBean()
+   {
+      String[] result = inspector.execute("bean");
+      assertEquals(1, result.length);
+      assertTrue(result[0].startsWith("Usage"));
+   }
+   
+   public void testBeanNoContext() throws Throwable
+   {
+      deployObjectBeans("Test1");
+      String[] result = inspector.execute("bean Test2");
+      assertEquals(2, result.length);
+      assertTrue(result[0].equals("Name='Test2'"));
+      assertTrue(result[1].contains("***NOT FOUND***"));
+   }
+   
+   public void testBeanSummaryNoUnresolvedDependencies() throws Throwable
+   {
+      deployObjectBeans("Test1");
+      String[] result = inspector.execute("bean Test1");
+      assertEquals(7, result.length);
+      checkBeanSummary(result, "Test1", Object.class, "INSTALLED", 0, 0);
+   }
+   
+   public void testBeanSummariesNoUnresolvedDependencies() throws Throwable
+   {
+      deployObjectBeans("Test1", "Test2");
+      String[] result = inspector.execute("bean Test1 Test2");
+      assertEquals(14, result.length);
+      checkBeanSummary(result, "Test1", Object.class, "INSTALLED", 0, 0);
+      checkBeanSummary(result, "Test2", Object.class, "INSTALLED", 0, 7);
+   }
+   
+   public void testBeanSummaryWithUnresolvedDependencies() throws Throwable
+   {
+      deployBeanWithUnresolvedDependencies("Test1", ControllerState.CONFIGURED);
+      String[] result = inspector.execute("bean Test1");
+      assertEquals(7, result.length);
+      checkBeanSummary(result, "Test1", SimpleBean.class, "INSTANTIATED", 1, 0);
+   }
+   
+   public void testBeanSummariesWithUnresolvedDependencies() throws Throwable
+   {
+      deployBeanWithUnresolvedDependencies("Test1", ControllerState.CONFIGURED);
+      deployBeanWithUnresolvedDependencies("Test2", ControllerState.INSTANTIATED);
+      String[] result = inspector.execute("bean Test1 Test2");
+      assertEquals(14, result.length);
+      checkBeanSummary(result, "Test1", SimpleBean.class, "INSTANTIATED", 1, 0);
+      checkBeanSummary(result, "Test2", SimpleBean.class, "DESCRIBED", 1, 7);
+   }
+   
+   public void testErrorContext() throws Throwable
+   {
+      deployBean("Test1", ErrorBean.class);
+      String[] result = inspector.execute("bean Test1");
+      assertEquals(7, result.length);
+      checkBeanSummary(result, "Test1", ErrorBean.class, "**ERROR**", 0, 0);
+   }
+   
+   private void checkBeanSummary(String[] result, String name, Class<?> beanType, String state, int unresolved, int offset)
+   {
+      assertTrue(result[0 + offset].equals("Name='" + name + "'"));
+      assertTrue(result[1 + offset].contains("bean type=" + beanType.getName()));
+      assertTrue(result[2 + offset].contains("mode=AUTOMATIC"));
+      assertTrue(result[3 + offset].contains("state=" + state));
+      assertTrue(result[4 + offset].contains("required state=INSTALLED"));
+      assertTrue(result[5 + offset].contains("context type=" + AbstractKernelControllerContext.class.getName()));
+      assertTrue(result[6 + offset].contains("unresolved dependencies=" + unresolved));
+   }
+   
+   public void testAllDependenciesViewAllDependenciesResolved() throws Throwable
+   {
+      deployObjectBeans("Test1");
+      deployBeanWithDependency("Test2", SimpleBean.class, ControllerState.CONFIGURED, "property", "Test1");
+      assertBean("Test2", SimpleBean.class);
+      
+      String[] result = inspector.execute("bean -d Test2");
+      int resolved = findStringIndex(result, "Resolved dependencies");
+      int unresolved = findStringIndex(result, "Unresolved dependencies");
+      assertEquals(2, unresolved - resolved);
+      assertEquals(result.length - 1, unresolved);
+      assertTrue(result[resolved + 1].contains("iDependOn=Test1"));
+      assertTrue(result[resolved + 1].contains("whenRequired=CONFIGURED"));
+      assertTrue(result[resolved + 1].contains("dependentState=INSTALLED"));
+   }
+   
+   public void testUnresolvedDependenciesViewAllDependenciesResolved() throws Throwable
+   {
+      deployObjectBeans("Test1");
+      deployBeanWithDependency("Test2", SimpleBean.class, ControllerState.CONFIGURED, "property", "Test1");
+      assertBean("Test2", SimpleBean.class);
+      
+      String[] result = inspector.execute("bean -u Test2");
+      
+      assertEquals(-1, findStringIndex(result, "Resolved dependencies"));
+      int unresolved = findStringIndex(result, "Unresolved dependencies");
+      assertEquals(result.length - 1, unresolved);
+   }
+   
+   public void testAllDependenciesViewSomeDependenciesResolved() throws Throwable
+   {
+      deployObjectBeans("Test1");
+      deployBeanWithTwoDependencies("Test2");
+
+      String[] result = inspector.execute("bean -d Test2");
+      assertTrue(-1 < findStringIndex(result, "state=INSTANTIATED"));
+      int resolved = findStringIndex(result, "Resolved dependencies");
+      int unresolved = findStringIndex(result, "Unresolved dependencies");
+      assertEquals(2, unresolved - resolved);
+      assertEquals(result.length - 2, unresolved);
+      assertTrue(result[resolved + 1].contains("iDependOn=Test1"));
+      assertTrue(result[resolved + 1].contains("whenRequired=CONFIGURED"));
+      assertTrue(result[resolved + 1].contains("dependentState=INSTALLED"));
+      assertTrue(result[unresolved + 1].contains("iDependOn=not_there"));
+      assertTrue(result[unresolved + 1].contains("whenRequired=CONFIGURED"));
+      assertTrue(result[unresolved + 1].contains("dependentState=INSTALLED"));
+   }
+   
+   public void testUnresolvedDependenciesViewSomeDependenciesResolved() throws Throwable
+   {
+      deployObjectBeans("Test1");
+      deployBeanWithTwoDependencies("Test2");
+
+      String[] result = inspector.execute("bean -u Test2");
+      assertTrue(-1 < findStringIndex(result, "state=INSTANTIATED"));
+      assertEquals(-1, findStringIndex(result, "Resolved dependencies"));
+      int unresolved = findStringIndex(result, "Unresolved dependencies");
+      assertEquals(result.length - 2, unresolved);
+      assertTrue(result[unresolved + 1].contains("iDependOn=not_there"));
+      assertTrue(result[unresolved + 1].contains("whenRequired=CONFIGURED"));
+      assertTrue(result[unresolved + 1].contains("dependentState=INSTALLED"));
+   }
+   
+   public void testAllDependenciesViewNoDependenciesResolved() throws Throwable
+   {
+      deployBeanWithTwoDependencies("Test2");
+      String[] result = inspector.execute("bean -d Test2");
+      assertTrue(-1 < findStringIndex(result, "state=INSTANTIATED"));
+      int resolved = findStringIndex(result, "Resolved dependencies");
+      int unresolved = findStringIndex(result, "Unresolved dependencies");
+      assertEquals(1, unresolved - resolved);
+      assertEquals(result.length - 3, unresolved);
+      int i = findStringIndex(result, "Test1");
+      assertTrue(-1 < i);
+      assertTrue(result[i].contains("iDependOn=Test1"));
+      assertTrue(result[i].contains("whenRequired=CONFIGURED"));
+      assertTrue(result[i].contains("dependentState=INSTALLED"));
+      
+      i = findStringIndex(result, "not_there");
+      assertTrue(-1 < i);
+      assertTrue(result[i].contains("iDependOn=not_there"));
+      assertTrue(result[i].contains("whenRequired=CONFIGURED"));
+      assertTrue(result[i].contains("dependentState=INSTALLED"));
+   }
+   
+   public void testUnresolvedDependenciesViewNoDependenciesResolved() throws Throwable
+   {
+      deployBeanWithTwoDependencies("Test2");
+      String[] result = inspector.execute("bean -u Test2");
+      assertTrue(-1 < findStringIndex(result, "state=INSTANTIATED"));
+      assertEquals(-1, findStringIndex(result, "Resolved dependencies"));
+      int unresolved = findStringIndex(result, "Unresolved dependencies");
+      assertEquals(result.length - 3, unresolved);
+      int i = findStringIndex(result, "Test1");
+      assertTrue(-1 < i);
+      assertTrue(result[i].contains("iDependOn=Test1"));
+      assertTrue(result[i].contains("whenRequired=CONFIGURED"));
+      assertTrue(result[i].contains("dependentState=INSTALLED"));
+      
+      i = findStringIndex(result, "not_there");
+      assertTrue(-1 < i);
+      assertTrue(result[i].contains("iDependOn=not_there"));
+      assertTrue(result[i].contains("whenRequired=CONFIGURED"));
+      assertTrue(result[i].contains("dependentState=INSTALLED"));
+   }
+   
+   private int findStringIndex(String[] result, String search)
+   {
+      for (int i = 0 ; i < result.length ; i++)
+      {
+         if (result[i].trim().contains(search))
+            return i;
+      }
+      return -1;
+   }
+   
+   protected void deployBeanWithTwoDependencies(String name) throws Throwable
+   {
+      assertNoBean(name);
+      BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(name, SimpleBean.class.getName());
+      
+      builder.addPropertyMetaData("property", builder.createInject("Test1", null, ControllerState.CONFIGURED, ControllerState.INSTALLED));
+      builder.addPropertyMetaData("property1", builder.createInject("not_there", null, ControllerState.CONFIGURED, ControllerState.INSTALLED));
+
+      deploy(builder.getBeanMetaData());
+   }
+
+
+}

Added: projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/kernel/test/ChangeTestCase.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/kernel/test/ChangeTestCase.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/kernel/test/ChangeTestCase.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,142 @@
+/*
+* 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.microcontainer.mcinspector.kernel.test;
+
+import junit.framework.Test;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.microcontainer.mcinspector.command.InspectorCommands;
+import org.jboss.microcontainer.mcinspector.command.impl.ChangeCommand;
+import org.jboss.test.microcontainer.mcinspector.AbstractInspectorTest;
+
+/**
+ * Tests the change command
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ChangeTestCase extends AbstractInspectorTest
+{
+
+   public ChangeTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(ChangeTestCase.class);
+   }
+
+   @Override
+   protected void setupCommands(InspectorCommands commands)
+   {
+      commands.addCommand(new ChangeCommand());
+   }
+   
+   public void testInvalidChangeCommands() throws Throwable
+   {
+      String[] result = inspector.execute("change");
+      assertEquals(1, result.length);
+      assertTrue(result[0].startsWith("Usage"));
+
+      result = inspector.execute("change a b c");
+      assertEquals(1, result.length);
+      assertTrue(result[0].startsWith("Usage"));
+   }
+   
+   public void testInvalidStateChange() throws Throwable
+   {
+      String[] result = inspector.execute("change NO_SUCH_STATE Test1");
+      assertEquals(1, result.length);
+      assertTrue(result[0].contains("NO_SUCH_STATE"));
+   }
+   
+   public void testEmptyFromState() throws Throwable
+   {
+      String[] result = inspector.execute("change -f INSTALLED Test1");
+      assertEquals(1, result.length);
+      assertTrue(result[0].contains("must take a value"));
+   }
+   
+   public void testArrayFromState() throws Throwable
+   {
+      String[] result = inspector.execute("change -f=DESCRIBED,INSTANTIATED,CREATE INSTALLED Test1");
+      assertEquals(1, result.length);
+      assertTrue(result[0].contains("must take a single value"));
+   }
+   
+   public void testBadFromState() throws Throwable
+   {
+      String[] result = inspector.execute("change -f=NO_SUCH_STATE INSTALLED Test1");
+      assertEquals(1, result.length);
+      assertTrue(result[0].contains("NO_SUCH_STATE"));
+   }
+ 
+   public void testNoContext() throws Throwable
+   {
+      String[] result = inspector.execute("change INSTALLED Test1");
+      assertEquals(1, result.length);
+      assertTrue(result[0].contains("Could not find"));
+   }
+   
+   public void testChange() throws Throwable
+   {
+      deployObjectBeans("Test1");
+      
+      assertBean("Test1", Object.class);
+      String[] result = inspector.execute("change START Test1");
+      assertEquals(1, result.length);
+      assertTrue(result[0].contains("Changed"));
+      
+      ControllerContext ctx = getControllerContext("Test1", ControllerState.START);
+      assertNotNull(ctx);
+      assertEquals(ControllerState.START, ctx.getState());
+   }
+   
+   public void testChangeWithFromState() throws Throwable
+   {
+      deployObjectBeans("Test1");
+      
+      assertBean("Test1", Object.class);
+      String[] result = inspector.execute("change -f=INSTALLED START Test1");
+      assertEquals(1, result.length);
+      assertTrue(result[0].contains("Changed"));
+      
+      ControllerContext ctx = getControllerContext("Test1", ControllerState.START);
+      assertNotNull(ctx);
+      assertEquals(ControllerState.START, ctx.getState());
+   }
+   
+   public void testChangeWithContextNotInFromState() throws Throwable
+   {
+      deployObjectBeans("Test1");
+      
+      assertBean("Test1", Object.class);
+      String[] result = inspector.execute("change -f=CREATE START Test1");
+      assertEquals(1, result.length);
+      assertTrue(result[0].contains("Could not find"));
+      assertTrue(result[0].contains("'Test1'"));
+      assertTrue(result[0].contains("CREATE"));
+   }
+}

Added: projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/kernel/test/ListTestCase.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/kernel/test/ListTestCase.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/kernel/test/ListTestCase.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,255 @@
+/*
+* 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.microcontainer.mcinspector.kernel.test;
+
+import junit.framework.Test;
+
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.microcontainer.mcinspector.command.InspectorCommands;
+import org.jboss.microcontainer.mcinspector.command.impl.ListCommand;
+import org.jboss.test.microcontainer.mcinspector.AbstractInspectorTest;
+import org.jboss.test.microcontainer.mcinspector.kernel.support.ErrorBean;
+
+/**
+ * Test the 'list' command
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ListTestCase extends AbstractInspectorTest
+{
+
+   public ListTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(ListTestCase.class);
+   }
+
+   @Override
+   protected void setupCommands(InspectorCommands commands)
+   {
+      commands.addCommand(new ListCommand());
+   }
+   
+   public void testPlainList() throws Throwable
+   {
+      deployObjectBeans("Test1", "Test2");
+      
+      String[] result = inspector.execute("list");
+      
+      assertEquals(3, result.length);
+      assertTrue(result[0].toUpperCase().contains("INSTALLED:"));
+      assertEquals("Test1", result[1].trim());
+      assertEquals("Test2", result[2].trim());
+      
+      change("Test1", ControllerState.DESCRIBED);
+      
+      result = inspector.execute("list");
+      
+      assertEquals(4, result.length);
+      assertTrue(result[0].toUpperCase().contains("DESCRIBED:"));
+      assertEquals("Test1", result[1].trim());
+      assertTrue(result[2].toUpperCase().contains("INSTALLED:"));
+      assertEquals("Test2", result[3].trim());
+   }
+   
+   public void testStatesList() throws Throwable
+   {
+      deployObjectBeans("Test1", "Test2");
+      
+      String[] result = inspector.execute("list DeSCrIbED CONfIGuRED");
+      
+      assertEquals(0, result.length);
+      
+      result = inspector.execute("list DESCrIBED INSTaLLED");
+
+      assertEquals(3, result.length);
+      assertTrue(result[0].toUpperCase().contains("INSTALLED:"));
+      assertEquals("Test1", result[1].trim());
+      assertEquals("Test2", result[2].trim());
+
+      change("Test2", ControllerState.DESCRIBED);
+
+      result = inspector.execute("list DeSCRIBED INSTaLLED");
+
+      assertEquals(4, result.length);
+      assertTrue(result[0].toUpperCase().contains("DESCRIBED:"));
+      assertEquals("Test2", result[1].trim());
+      assertTrue(result[2].toUpperCase().contains("INSTALLED:"));
+      assertEquals("Test1", result[3].trim());
+   }
+   
+   public void testOverviewList() throws Throwable
+   {
+      deployObjectBeans("Test1", "Test2");
+      
+      String[] result = inspector.execute("list -o");
+      
+      assertEquals(8, result.length);
+      assertTrue(result[0].toUpperCase().contains("NOT INSTALLED"));
+      assertTrue(result[1].toUpperCase().contains("PREINSTALL"));
+      assertTrue(result[2].toUpperCase().contains("DESCRIBED"));
+      assertTrue(result[3].toUpperCase().contains("INSTANTIATED"));
+      assertTrue(result[4].toUpperCase().contains("CONFIGURED"));
+      assertTrue(result[5].toUpperCase().contains("CREATE"));
+      assertTrue(result[6].toUpperCase().contains("START"));
+      assertTrue(result[7].toUpperCase().contains("INSTALLED"));
+      
+      assertTrue(result[0].contains("0"));
+      assertTrue(result[1].contains("0"));
+      assertTrue(result[2].contains("0"));
+      assertTrue(result[3].contains("0"));
+      assertTrue(result[4].contains("0"));
+      assertTrue(result[5].contains("0"));
+      assertTrue(result[6].contains("0"));
+      assertTrue(result[7].contains("2"));
+   }
+
+   public void testOverviewAndVerboseError() throws Throwable
+   {
+      try
+      {
+         deployObjectBeans("Test1", "Test2");
+         inspector.execute("list -o -v");
+         fail("Can't have verbose and overview");
+      }
+      catch(Exception expected)
+      {
+      }
+      
+   }
+   
+   public void testVerboseListNoUnresolvedDependencies() throws Throwable
+   {
+      deployObjectBeans("Test1", "Test2");
+      
+      String[] result = inspector.execute("list -v");
+      assertEquals(3, result.length);
+      assertTrue(result[0].toUpperCase().contains("INSTALLED:"));
+      assertTrue(result[1].trim().startsWith("Test1"));
+      assertTrue(result[2].trim().startsWith("Test2"));
+      
+      assertTrue(result[1].contains("(AUTOMATIC, INSTALLED)"));
+      assertTrue(result[2].contains("(AUTOMATIC, INSTALLED)"));
+   
+      change("Test1", ControllerState.DESCRIBED);
+
+      result = inspector.execute("list -v");
+      assertEquals(4, result.length);
+      assertTrue(result[0].toUpperCase().contains("DESCRIBED:"));
+      assertTrue(result[1].trim().startsWith("Test1"));
+      assertTrue(result[2].toUpperCase().contains("INSTALLED:"));
+      assertTrue(result[3].trim().startsWith("Test2"));
+
+      assertTrue(result[1].contains("(AUTOMATIC, DESCRIBED)"));
+      assertTrue(result[3].contains("(AUTOMATIC, INSTALLED)"));
+}
+   
+   public void testVerboseListStatesNoUnresolvedDependencies() throws Throwable
+   {
+      deployObjectBeans("Test1", "Test2");
+      
+      String[] result = inspector.execute("list -v INSTALLED DESCRIBED");
+      assertEquals(3, result.length);
+      assertTrue(result[0].toUpperCase().contains("INSTALLED:"));
+      assertTrue(result[1].trim().startsWith("Test1"));
+      assertTrue(result[2].trim().startsWith("Test2"));
+      
+      assertTrue(result[1].contains("(AUTOMATIC, INSTALLED)"));
+      assertTrue(result[2].contains("(AUTOMATIC, INSTALLED)"));
+   
+      change("Test1", ControllerState.DESCRIBED);
+
+      result = inspector.execute("list -v INSTALLED DESCRIBED");
+      assertEquals(4, result.length);
+      assertTrue(result[0].toUpperCase().contains("DESCRIBED:"));
+      assertTrue(result[1].trim().startsWith("Test1"));
+      assertTrue(result[2].toUpperCase().contains("INSTALLED:"));
+      assertTrue(result[3].trim().startsWith("Test2"));
+
+      assertTrue(result[1].contains("(AUTOMATIC, DESCRIBED)"));
+      assertTrue(result[3].contains("(AUTOMATIC, INSTALLED)"));
+      
+      change("Test1", ControllerState.CONFIGURED);
+
+      result = inspector.execute("list -v INSTALLED DESCRIBED");
+      assertEquals(2, result.length);
+      assertTrue(result[0].toUpperCase().contains("INSTALLED:"));
+      assertTrue(result[1].trim().startsWith("Test2"));
+      
+      result = inspector.execute("list -v DESCRIBED");
+      assertEquals(0, result.length);
+   }
+   
+   public void testVerboseListUnresolvedDependencies() throws Throwable
+   {
+      deployBeanWithUnresolvedDependencies("Test1", ControllerState.CONFIGURED);
+      deployBeanWithUnresolvedDependencies("Test2", ControllerState.INSTANTIATED);
+      
+      String[] result = inspector.execute("list -v");
+         
+      assertEquals(4, result.length);
+      assertTrue(result[0].toUpperCase().contains("DESCRIBED:"));
+      assertTrue(result[1].trim().startsWith("Test2*"));
+      assertTrue(result[1].toUpperCase().contains("(AUTOMATIC, DESCRIBED)"));
+      assertTrue(result[2].toUpperCase().contains("INSTANTIATED:"));
+      assertTrue(result[3].trim().startsWith("Test1"));
+      assertTrue(result[3].contains("(AUTOMATIC, INSTANTIATED)"));
+      
+   }
+   
+   public void testVerboseListStatesUnresolvedDependencies() throws Throwable
+   {
+      deployBeanWithUnresolvedDependencies("Test1", ControllerState.CONFIGURED);
+      deployBeanWithUnresolvedDependencies("Test2", ControllerState.INSTANTIATED);
+      
+      String[] result = inspector.execute("list -v INSTALLED");
+      assertEquals(0, result.length);
+         
+      result = inspector.execute("list -v DESCRIBED STARTED");
+      assertEquals(2, result.length);
+      assertTrue(result[0].toUpperCase().contains("DESCRIBED:"));
+      assertTrue(result[1].trim().startsWith("Test2*"));
+      assertTrue(result[1].contains("(AUTOMATIC, DESCRIBED)"));
+
+      result = inspector.execute("list -v DESCRIBED INSTANTIATED");
+      assertEquals(4, result.length);
+      assertTrue(result[0].toUpperCase().contains("DESCRIBED:"));
+      assertTrue(result[1].trim().startsWith("Test2*"));
+      assertTrue(result[1].toUpperCase().contains("(AUTOMATIC, DESCRIBED)"));
+      assertTrue(result[2].toUpperCase().contains("INSTANTIATED:"));
+      assertTrue(result[3].trim().startsWith("Test1"));
+      assertTrue(result[3].contains("(AUTOMATIC, INSTANTIATED)"));
+   }
+   
+   public void testErrorContexts() throws Throwable
+   {
+      deployBean("Test1", ErrorBean.class);
+      String[] result = inspector.execute("list -e");
+      assertEquals(1, result.length);
+      assertTrue(result[0].contains("Test1"));
+   }
+}

Added: projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/simple/MockInspectorCommands.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/simple/MockInspectorCommands.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/simple/MockInspectorCommands.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,60 @@
+/*
+* 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.microcontainer.mcinspector.simple;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.kernel.Kernel;
+import org.jboss.microcontainer.mcinspector.command.InspectorCommand;
+import org.jboss.microcontainer.mcinspector.command.impl.AbstractInspectorCommands;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class MockInspectorCommands extends AbstractInspectorCommands
+{
+   Map<String, InspectorCommand> commands = Collections.synchronizedMap(new HashMap<String, InspectorCommand>());
+   
+   public void addCommand(InspectorCommand command)
+   {
+      commands.put(command.getName(), command);
+   }
+
+   public boolean removeCommand(InspectorCommand command)
+   {
+      return commands.remove(command.getName()) != null;
+   }
+
+   public String[] execute(Kernel kernel, String[] commandItems)
+   {
+      String command = (commandItems == null || commandItems.length == 0) ? "" : commandItems[0]; 
+      if (commands.get(command) == null)
+         return null;
+      return null;
+   }
+
+
+}

Added: projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/simple/support/MockCommandLongName.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/simple/support/MockCommandLongName.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/simple/support/MockCommandLongName.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,44 @@
+/*
+* 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.microcontainer.mcinspector.simple.support;
+
+import org.jboss.microcontainer.mcinspector.command.CommandArguments;
+import org.jboss.microcontainer.mcinspector.command.CommandResult;
+import org.jboss.microcontainer.mcinspector.command.impl.AbstractInspectorCommand;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class MockCommandLongName extends AbstractInspectorCommand
+{
+   public MockCommandLongName()
+   {
+      super("LongLongLongLongLongLongName", "A command with a long name", "Who cares :-)");
+   }
+
+   public CommandResult execute(CommandArguments args)
+   {
+      return new CommandResult(args.getCommandArguments());
+   }
+}

Added: projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/simple/support/MockEchoCommand.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/simple/support/MockEchoCommand.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/simple/support/MockEchoCommand.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,44 @@
+/*
+* 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.microcontainer.mcinspector.simple.support;
+
+import org.jboss.microcontainer.mcinspector.command.CommandArguments;
+import org.jboss.microcontainer.mcinspector.command.CommandResult;
+import org.jboss.microcontainer.mcinspector.command.impl.AbstractInspectorCommand;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class MockEchoCommand extends AbstractInspectorCommand
+{
+   public MockEchoCommand()
+   {
+      super("echo", "An echo command", "An echo command.", "Usage: echo [param [,param]*]");
+   }
+
+   public CommandResult execute(CommandArguments args)
+   {
+      return new CommandResult(args.getCommandArguments());
+   }
+}

Added: projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/simple/test/CommandArgumentsTestCase.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/simple/test/CommandArgumentsTestCase.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/simple/test/CommandArgumentsTestCase.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,263 @@
+/*
+* 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.microcontainer.mcinspector.simple.test;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.jboss.microcontainer.mcinspector.command.ClientCommandArguments;
+import org.jboss.microcontainer.mcinspector.command.ClientCommandArguments.CommandOption;
+import org.jboss.microcontainer.mcinspector.command.impl.ClientCommandArgumentsImpl;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class CommandArgumentsTestCase extends TestCase
+{
+   public CommandArgumentsTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return new TestSuite(CommandArgumentsTestCase.class);
+   }
+
+   public void testEmptyNoProgramName()
+   {
+      ClientCommandArguments args = new ClientCommandArgumentsImpl(null, "");
+      assertEquals("", args.getProgramName());
+      assertEmpty(args.getCommandArguments());
+      assertEmpty(args.getCommandOptions());
+      assertEquals("", args.getCommand());
+   }
+
+   public void testEmptyWithProgramName()
+   {
+      ClientCommandArguments args = new ClientCommandArgumentsImpl("x", "");
+      assertEquals("x", args.getProgramName());
+      assertEquals("", args.getCommand());
+      assertEmpty(args.getCommandArguments());
+      assertEmpty(args.getCommandOptions());
+   }
+   
+   public void testCommandOnly()
+   {
+      ClientCommandArguments args = new ClientCommandArgumentsImpl("x", "test");
+      assertEquals("test", args.getCommand());
+      assertEmpty(args.getCommandArguments());
+      assertEmpty(args.getCommandOptions());
+   }
+
+   public void testCommandOnlySpacesTrimmed()
+   {
+      ClientCommandArguments args = new ClientCommandArgumentsImpl("x", "    test     ");
+      assertEquals("test", args.getCommand());
+      assertEmpty(args.getCommandArguments());
+      assertEmpty(args.getCommandOptions());
+   }
+   
+   public void testCommandAndArg()
+   {
+      ClientCommandArguments args = new ClientCommandArgumentsImpl("x", "test one");
+      assertEquals("test", args.getCommand());
+      assertEqualArrays(args.getCommandArguments(), "one");
+      assertEmpty(args.getCommandOptions());
+   }
+   
+   public void testCommandAndArgSpacesTrimmed()
+   {
+      ClientCommandArguments args = new ClientCommandArgumentsImpl("x", "   test    one   ");
+      assertEquals("test", args.getCommand());
+      assertEqualArrays(args.getCommandArguments(), "one");
+      assertEmpty(args.getCommandOptions());
+   }
+   
+   public void testCommandAndArgs()
+   {
+      ClientCommandArguments args = new ClientCommandArgumentsImpl("x", "test one two");
+      assertEquals("test", args.getCommand());
+      assertEqualArrays(args.getCommandArguments(), "one", "two");
+      assertEmpty(args.getCommandOptions());
+   }
+   
+   public void testCommandAndArgsSpacesTrimmed()
+   {
+      ClientCommandArguments args = new ClientCommandArgumentsImpl("x", "   test    one   two    ");
+      assertEquals("test", args.getCommand());
+      assertEqualArrays(args.getCommandArguments(), "one", "two");
+      assertEmpty(args.getCommandOptions());
+   }
+   
+   public void testCommandAndBadOption()
+   {
+      try
+      {
+         ClientCommandArguments args = new ClientCommandArgumentsImpl("x", "test -");
+         args.getCommandOptions();
+         fail("Bad option");
+      }
+      catch(RuntimeException expected)
+      {
+      }
+   }
+
+   public void testCommandAndSimpleOption()
+   {
+      ClientCommandArguments args = new ClientCommandArgumentsImpl("x", "test -v");
+      assertEquals("test", args.getCommand());
+      assertEmpty(args.getCommandArguments());
+      
+      CommandOption[] options = args.getCommandOptions(); 
+      assertEquals(1, options.length);
+      assertEquals("v", options[0].getName());
+      assertEmpty(options[0].getValues());
+   }
+
+   public void testCommandAndSimpleOptionSpacesTrimmed()
+   {
+      ClientCommandArguments args = new ClientCommandArgumentsImpl("x", " test   -v  ");
+      assertEquals("test", args.getCommand());
+      assertEmpty(args.getCommandArguments());
+      
+      CommandOption[] options = args.getCommandOptions(); 
+      assertEquals(1, options.length);
+      assertEquals("v", options[0].getName());
+      assertEmpty(options[0].getValues());
+   }
+
+   public void testCommandAndTwoSimpleOptions()
+   {
+      ClientCommandArguments args = new ClientCommandArgumentsImpl("x", "test -v -x");
+      assertEquals("test", args.getCommand());
+      assertEmpty(args.getCommandArguments());
+      
+      CommandOption[] options = args.getCommandOptions(); 
+      assertEquals(2, options.length);
+      assertEquals("v", options[0].getName());
+      assertEmpty(options[0].getValues());
+
+      assertEquals("x", options[1].getName());
+      assertEmpty(options[1].getValues());
+   }
+
+   public void testCommandAndTwoSimpleOptionsSpacesTrimmed()
+   {
+      ClientCommandArguments args = new ClientCommandArgumentsImpl("x", " test    -v    -x ");
+      assertEquals("test", args.getCommand());
+      assertEmpty(args.getCommandArguments());
+      
+      CommandOption[] options = args.getCommandOptions(); 
+      assertEquals(2, options.length);
+      assertEquals("v", options[0].getName());
+      assertEmpty(options[0].getValues());
+
+      assertEquals("x", options[1].getName());
+      assertEmpty(options[1].getValues());
+   }
+
+   public void testCommandAndNoOptionValue()
+   {
+      try
+      {
+         ClientCommandArguments args = new ClientCommandArgumentsImpl("x", "test -v=");
+         args.getCommandOptions();
+         fail("Bad option");
+      }
+      catch(RuntimeException expected)
+      {
+      }
+   }
+
+   public void testCommandAndNoOptionValueSpacesTrimmed()
+   {
+      try
+      {
+         ClientCommandArguments args = new ClientCommandArgumentsImpl("x", "   test    -v=       ");
+         args.getCommandOptions();
+         fail("Bad option");
+      }
+      catch(RuntimeException expected)
+      {
+      }
+   }
+
+   public void testCommandAndSingleValueOption()
+   {
+      ClientCommandArguments args = new ClientCommandArgumentsImpl("x", "test -v=hello");
+      assertEquals("test", args.getCommand());
+      assertEmpty(args.getCommandArguments());
+      
+      CommandOption[] options = args.getCommandOptions(); 
+      assertEquals(1, options.length);
+      assertEquals("v", options[0].getName());
+      assertEqualArrays(options[0].getValues(), "hello");
+   }
+
+   public void testCommandAndTwoValueOption()
+   {
+      ClientCommandArguments args = new ClientCommandArgumentsImpl("x", "test -v=one,two");
+      assertEquals("test", args.getCommand());
+      assertEmpty(args.getCommandArguments());
+      
+      CommandOption[] options = args.getCommandOptions(); 
+      assertEquals(1, options.length);
+      assertEquals("v", options[0].getName());
+      assertEqualArrays(options[0].getValues(), "one", "two");
+   }
+
+   public void testCommandWithArgumentsAndOptions()
+   {
+      ClientCommandArguments args = new ClientCommandArgumentsImpl("x", "test -v one -w=1 two -y=1,2,3");
+      assertEquals("test", args.getCommand());
+      assertEqualArrays(args.getCommandArguments(), "one", "two");
+
+      CommandOption[] options = args.getCommandOptions(); 
+      assertEquals(3, options.length);
+      assertEquals("v", options[0].getName());
+      assertEmpty(options[0].getValues());
+      
+      assertEquals("w", options[1].getName());
+      assertEqualArrays(options[1].getValues(), "1");
+      
+      assertEquals("y", options[2].getName());
+      assertEqualArrays(options[2].getValues(), "1", "2", "3");
+      
+      
+   }
+
+   private void assertEmpty(Object[] array)
+   {
+      assertEquals(0, array.length);
+   }
+   
+   private void assertEqualArrays(Object[] actual, Object...expected)
+   {
+      assertEquals(expected.length, actual.length);
+      for (int i = 0 ; i < actual.length ; i++)
+         assertEquals(expected[i], actual[i]);
+   }
+}

Added: projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/simple/test/SimpleTestCase.java
===================================================================
--- projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/simple/test/SimpleTestCase.java	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/src/test/java/org/jboss/test/microcontainer/mcinspector/simple/test/SimpleTestCase.java	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,171 @@
+/*
+* 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.microcontainer.mcinspector.simple.test;
+
+import junit.framework.Test;
+
+import org.jboss.microcontainer.mcinspector.command.InspectorCommands;
+import org.jboss.microcontainer.mcinspector.command.impl.HelpCommand;
+import org.jboss.test.microcontainer.mcinspector.AbstractInspectorTest;
+import org.jboss.test.microcontainer.mcinspector.simple.support.MockCommandLongName;
+import org.jboss.test.microcontainer.mcinspector.simple.support.MockEchoCommand;
+
+/**
+ * Tests that the basic command and parsing system works
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class SimpleTestCase extends AbstractInspectorTest
+{
+   public SimpleTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(SimpleTestCase.class);
+   }
+
+   @Override
+   protected void setupCommands(InspectorCommands commands)
+   {
+      commands.addCommand(new MockEchoCommand());
+   }
+
+   public void testNullCommand()
+   {
+      checkUnknownCommand(null);
+   }
+   
+   public void testEmptyCommand()
+   {
+      checkUnknownCommand("");
+   }
+   
+   public void testUnknownCommand()
+   {
+      checkUnknownCommand("unknown");
+   }
+   
+   private void checkUnknownCommand(String cmd)
+   {
+      String[] result = inspector.execute(cmd);
+      String expectedCmd = cmd == null ? "" : cmd;
+      assertInspectorResult(
+            result, 
+            "Unknown command '" + expectedCmd + "'.",
+            "Pass in 'help' for a list of commands.",
+            "To see more options for a particular command pass in 'help <command>'.");
+   }
+   
+   public void testEchoCommandNoParameters()
+   {
+      String[] result = inspector.execute("echo");
+      assertInspectorResult(result);
+   }
+   
+   public void testEchoCommandNoParametersSurroundedBySpaces()
+   {
+      String[] result = inspector.execute("    echo       ");
+      assertInspectorResult(result);
+   }
+   
+   public void testEchoCommandOneParameter()
+   {
+      String[] result = inspector.execute("echo one");
+      assertInspectorResult(result, "one");
+   }
+   
+   public void testEchoCommandOneParameterManySpaces()
+   {
+      String[] result = inspector.execute("echo      one");
+      assertInspectorResult(result, "one");
+   }
+   
+   public void testEchoCommandTwoParameters()
+   {
+      String[] result = inspector.execute("echo one two");
+      assertInspectorResult(result, "one", "two");
+   }
+   
+   public void testEchoCommandThreeParametersSeveralSpaces()
+   {
+      String[] result = inspector.execute("            echo      one        two                three");
+      assertInspectorResult(result, "one", "two", "three");
+   }
+   
+   public void testHelpCommandFormatting()
+   {
+      commands.addCommand(new HelpCommand());
+      
+      String[] result = inspector.execute("help");
+      
+      assertInspectorResult(result, 
+            "Available commands:",      
+            "   echo  An echo command",
+            "   help  Prints the list of available commands.",
+            "For more information about a particular command, enter 'help <command>'.");
+   }
+   
+   public void testHelpCommandFormattingWithLongNames()
+   {
+      commands.addCommand(new HelpCommand());
+      commands.addCommand(new MockCommandLongName());
+      
+      String[] result = inspector.execute("help");
+      
+      assertInspectorResult(result, 
+            "Available commands:",      
+            "   echo                          An echo command",
+            "   help                          Prints the list of available commands.",
+            "   LongLongLongLongLongLongName  A command with a long name",
+            "For more information about a particular command, enter 'help <command>'.");
+   }
+   
+   public void testHelpTooManyParameters()
+   {
+      commands.addCommand(new HelpCommand());
+      String[] result = inspector.execute("help one two");
+      assertInspectorResult(result, 
+            "Usage: help [command]");      
+      
+   }
+   
+   public void testHelpNonExistantCommand()
+   {
+      commands.addCommand(new HelpCommand());
+      String[] result = inspector.execute("help notThere");
+      assertInspectorResult(result, 
+            "Unknown command 'notThere'. No help available.");      
+   }
+   
+   public void testHelpEchoCommand()
+   {
+      commands.addCommand(new HelpCommand());
+      String[] result = inspector.execute("help echo");
+      assertInspectorResult(result, 
+            "An echo command.",
+            "Usage: echo [param [,param]*]");      
+   }
+}

Added: projects/mc-tools/mcinspector/trunk/svn-commit.tmp
===================================================================
--- projects/mc-tools/mcinspector/trunk/svn-commit.tmp	                        (rev 0)
+++ projects/mc-tools/mcinspector/trunk/svn-commit.tmp	2010-03-08 15:17:07 UTC (rev 102062)
@@ -0,0 +1,4 @@
+Add the mcinspector to svn
+--This line, and those below, will be ignored--
+
+A    .




More information about the jboss-cvs-commits mailing list