You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ri...@apache.org on 2010/06/22 15:42:41 UTC

svn commit: r956893 - in /qpid/trunk/qpid/java/broker-plugins/experimental/info/src: main/java/org/apache/qpid/info/ main/java/org/apache/qpid/info/util/ test/java/org/apache/qpid/info/systest/ test/java/org/apache/qpid/info/test/

Author: ritchiem
Date: Tue Jun 22 13:42:41 2010
New Revision: 956893

URL: http://svn.apache.org/viewvc?rev=956893&view=rev
Log:
Qpid-2555 Patch 4 provided by Sorin Suciu, based on local review comments

Modified:
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Activator.java
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/AppInfo.java
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Info.java
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/InfoServiceImpl.java
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/SystemInfo.java
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/HttpPoster.java
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/IniFileReader.java
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/SoapClient.java
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/systest/InfoPluginTest.java
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/HttpPosterTest.java
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoServiceImplTest.java
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoTest.java
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/IniFileReaderTest.java
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SoapClientTest.java
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SystemInfoTest.java
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/XMLWriterTest.java

Modified: qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Activator.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Activator.java?rev=956893&r1=956892&r2=956893&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Activator.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Activator.java Tue Jun 22 13:42:41 2010
@@ -21,70 +21,52 @@
 
 package org.apache.qpid.info;
 
-import java.io.File;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
 import org.apache.qpid.info.util.HttpPoster;
 import org.apache.qpid.info.util.IniFileReader;
 import org.apache.qpid.info.util.SoapClient;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 
-/**
- * The Activator class for the OSGI info service
- * 
- */
+import java.io.File;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+/** The Activator class for the OSGI info service */
 public class Activator implements BundleActivator
 {
 
-    private final List<String> soapPropList = Arrays.asList("soap.hostname",
-            "soap.port", "soap.path", "soap.action", "soap.envelope");
+    private final List<String> _soapPropList = Arrays.asList("soap.hostname",
+                                                             "soap.port", "soap.path", "soap.action", "soap.envelope");
 
-    private final List<String> httpPropList = Arrays.asList("http.url",
-            "http.envelope");
+    private final List<String> _httpPropList = Arrays.asList("http.url",
+                                                             "http.envelope");
 
-    InfoServiceImpl service = null;
+    InfoServiceImpl _service = null;
 
     BundleContext _ctx = null;
 
-    Map<String, Properties> infoprops = new HashMap<String, Properties>();
-
     /**
      * Start bundle method
-     * 
-     * @param ctx
-     *            the bundle context
+     *
+     * @param ctx the bundle context
      */
     public void start(BundleContext ctx) throws Exception
     {
         if (null != ctx)
         {
             _ctx = ctx;
-            service = new InfoServiceImpl();
-            ctx.registerService(InfoService.class.getName(), service, null);
+            _service = new InfoServiceImpl();
+            ctx.registerService(InfoService.class.getName(), _service, null);
             sendInfo("STARTUP");
         }
     }
 
     /**
-     * Getter for the bundle context
-     * 
-     * @return BundleContext the bundle context
-     */
-    public BundleContext getBundleContext()
-    {
-        return _ctx;
-    }
-
-    /**
      * Stop the bundle method
-     * 
-     * @param ctx
-     *            the bundle context
+     *
+     * @param ctx the bundle context
      */
     public void stop(BundleContext ctx) throws Exception
     {
@@ -93,13 +75,12 @@ public class Activator implements Bundle
 
     /**
      * Sends the information message
-     * 
-     * @param action
-     *            label that identifies if we are starting up or shutting down
+     *
+     * @param action label that identifies if we are starting up or shutting down
      */
     private void sendInfo(String action)
     {
-        if ((null == _ctx) && (null == service))
+        if ((null == _ctx) && (null == _service))
         {
             // invalid state
             return;
@@ -110,37 +91,35 @@ public class Activator implements Bundle
         {
             String QPID_HOME = System.getProperty("QPID_HOME");
             String cfgFilePath = QPID_HOME + File.separator + "etc"
-                    + File.separator + "qpidinfo.properties";
+                                 + File.separator + "qpidinfo.ini";
             ifr.load(cfgFilePath);
-        } catch (Exception ex)
+        }
+        catch (Throwable ex)
         {
-            // drop the exception
+            // drop everything to be silent
             return;
         }
 
-        // If we have no sections, something has gone really wrong, abort
-        if (ifr.getSections().size() == 0)
-            return;
-
-        Info<? extends Map<String, ?>> info = service.invoke(action);
-        String protocol = ifr.getSections().get("").getProperty("protocol");
-        sendMessages(protocol, ifr, info);
+        // Only send Messages if we have some sections.
+        if (ifr.getSections().size() != 0)
+        {
+            Info<? extends Map<String, ?>> info = _service.invoke(action);
+            String protocol = ifr.getSections().get("").getProperty("protocol");
+            sendMessages(protocol, ifr, info);
+        }
     }
 
     /**
      * Sends all the messages configured in the properties file
-     * 
-     * @param protocol
-     *            indicates what protocol to be used: http and soap implemented
-     *            for now
-     * @param ifr
-     *            an instance of IniFileReader class
-     * @param info
-     *            an instance of an Info object, encapsulating the information
-     *            we want to send
+     *
+     * @param protocol indicates what protocol to be used: http and soap implemented
+     *                 for now
+     * @param ifr      an instance of IniFileReader class
+     * @param info     an instance of an Info object, encapsulating the information
+     *                 we want to send
      */
     private void sendMessages(String protocol, IniFileReader ifr,
-            Info<? extends Map<String, ?>> info)
+                              Info<? extends Map<String, ?>> info)
     {
         if (null != protocol)
         {
@@ -152,7 +131,9 @@ public class Activator implements Bundle
                 {
                     // Skip the defaults
                     if (section.equals(""))
+                    {
                         continue;
+                    }
                     Properties props = new Properties();
                     props.putAll(defaultProps);
                     props.putAll(ifr.getSections().get(section));
@@ -162,7 +143,8 @@ public class Activator implements Bundle
                     }
                 }
 
-            } else if (protocol.toLowerCase().startsWith("soap"))
+            }
+            else if (protocol.toLowerCase().startsWith("soap"))
             {
                 for (String section : ifr.getSections().keySet())
                 {
@@ -175,38 +157,38 @@ public class Activator implements Bundle
                     }
                 }
             }
-        } else
-        {
-            return;
         }
     }
 
     /**
      * Checks if the properties for a specified protocol are valid
-     * 
-     * @param protocol
-     *            String representing the protocol
-     * @param props
-     *            The properties associate with the specified protocol
+     *
+     * @param protocol String representing the protocol
+     * @param props    The properties associate with the specified protocol
+     * @return boolean
      */
     private boolean isValid(String protocol, Properties props)
     {
         if (null == protocol)
+        {
             return false;
+        }
         String value = "";
         if (protocol.toLowerCase().startsWith("http"))
         {
-            for (String prop : httpPropList)
+            for (String prop : _httpPropList)
             {
                 if (null == props.get(prop))
+                {
                     return false;
+                }
             }
             return true;
         }
 
         if (protocol.toLowerCase().startsWith("soap"))
         {
-            for (String prop : soapPropList)
+            for (String prop : _soapPropList)
             {
                 value = props.getProperty(prop);
                 if (null == value)

Modified: qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/AppInfo.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/AppInfo.java?rev=956893&r1=956892&r2=956893&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/AppInfo.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/AppInfo.java Tue Jun 22 13:42:41 2010
@@ -21,34 +21,32 @@
 
 package org.apache.qpid.info;
 
+import org.apache.qpid.common.QpidProperties;
+import org.apache.qpid.server.configuration.ServerConfiguration;
+import org.apache.qpid.server.registry.ApplicationRegistry;
+
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Properties;
 import java.util.TreeMap;
-import java.util.Map.Entry;
 
-import org.apache.qpid.common.QpidProperties;
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-
-/**
- * AppInfo class is gathering application specific informations
- *
- */
+/** AppInfo class is gathering application specific information */
 public class AppInfo
 {
 
     private static final List<String> appProps = Arrays.asList("QPID_HOME",
-            "QPID_WORK");
+                                                               "QPID_WORK");
 
     private static Map<String, String> appInfoMap = new TreeMap<String, String>();
 
     /**
      * getInfo method retrieves a key-value map for specific application properties
+     *
      * @return Map<String,String>
-     */  
+     */
     public static Map<String, String> getInfo()
     {
 
@@ -76,8 +74,6 @@ public class AppInfo
                 appInfoMap.put("port", sc.getPorts().toString());
                 appInfoMap.put("version", QpidProperties.getReleaseVersion());
                 appInfoMap.put("vhosts", "standalone");
-                // brokerInfoMap.put("DefaultVirtualHost",
-                // sc.getDefaultVirtualHost());
                 appInfoMap.put("JMXPrincipalDatabase", sc
                         .getJMXPrincipalDatabase());
                 appInfoMap.put("KeystorePath", sc.getKeystorePath());
@@ -86,9 +82,10 @@ public class AppInfo
                 appInfoMap.put("QpidWork", sc.getQpidWork());
                 appInfoMap.put("Bind", sc.getBind());
             }
-        } catch (Exception e)
+        }
+        catch (Exception e)
         {
-            // 
+            // drop everything to be silent
         }
         return appInfoMap;
 

Modified: qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Info.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Info.java?rev=956893&r1=956892&r2=956893&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Info.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Info.java Tue Jun 22 13:42:41 2010
@@ -20,31 +20,32 @@
  */
 
 /**
- * 
+ *
  * @author sorin
- * 
+ *
  *  Info object
  */
 
 package org.apache.qpid.info;
 
+import org.apache.qpid.info.util.XMLWriter;
+
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Properties;
 
-import org.apache.qpid.info.util.XMLWriter;
-
 /**
- * The Info class encapsulates all the informations we are collecting
- * and it is able to render it in different data representations 
+ * The Info class encapsulates all the information we are collecting
+ * and it is able to render it in different data representations
  */
 public class Info<T extends Map<String, ?>>
 {
     private T _info;
 
     /**
-     * Constructor.   
+     * Constructor.
+     *
      * @param info instantiates the object with a Map<String,?>
      */
     public Info(T info)
@@ -65,24 +66,32 @@ public class Info<T extends Map<String, 
     }
 
     /**
-     * Renders Info map to a property object  
-     * @return A Properties object representing the Info map  
+     * Renders Info map to a property object
+     *
+     * @return A Properties object representing the Info map
      */
-    public Properties toProps() {
+    public Properties toProps()
+    {
         Properties props = new Properties();
-        if (null==_info) return null;
-        for (Iterator<String> it = _info.keySet().iterator(); it.hasNext();) {
-          String key = it.next();
-          props.put(key, _info.get(key));  
+        if (null == _info)
+        {
+            return null;
+        }
+        for (Iterator<String> it = _info.keySet().iterator(); it.hasNext();)
+        {
+            String key = it.next();
+            props.put(key, _info.get(key));
         }
         return props;
     }
-    
+
     /**
-     * Renders Info map to a StringBuffer  
-     * @return A StringBuffer object representing the Info map  
+     * Renders Info map to a StringBuffer
+     *
+     * @return A StringBuffer object representing the Info map
      */
-    public StringBuffer toStringBuffer() {
+    public StringBuffer toStringBuffer()
+    {
         StringBuffer sb = new StringBuffer();
         for (Iterator<String> it = _info.keySet().iterator(); it.hasNext();)
         {
@@ -91,37 +100,42 @@ public class Info<T extends Map<String, 
         }
         return sb;
     }
-    
+
     /**
-     * Renders Info map to a StringBuffer containing an XML string  
-     * @return A StringBuffer object containing an XML representation of the Info map  
+     * Renders Info map to a StringBuffer containing an XML string
+     *
+     * @return A StringBuffer object containing an XML representation of the Info map
      */
-    public StringBuffer toXML() 
+    public StringBuffer toXML()
     {
         XMLWriter xw = new XMLWriter(new StringBuffer());
         xw.writeXMLHeader();
         Map<String, String> attr = new HashMap<String, String>();
         xw.writeOpenTag("qpidinfo", attr);
         String key;
-        for (Iterator<String> it = _info.keySet().iterator(); it.hasNext();) {
+        for (Iterator<String> it = _info.keySet().iterator(); it.hasNext();)
+        {
             attr.clear();
             key = it.next();
-            xw.writeTag(key, attr, _info.get(key).toString());  
-          }
+            xw.writeTag(key, attr, _info.get(key).toString());
+        }
         xw.writeCloseTag("qpidinfo");
         return xw.getXML();
     }
-    
+
     /**
-     * Renders Info map to a HashMap  
-     * @return A HashMap object representing the Info map  
+     * Renders Info map to a HashMap
+     *
+     * @return A HashMap object representing the Info map
      */
-    public HashMap<String,String> toMap() {
+    public HashMap<String, String> toMap()
+    {
         String key;
-        HashMap<String,String> infoMap = new HashMap<String,String>();
-        for (Iterator<String> it = _info.keySet().iterator(); it.hasNext();) {
+        HashMap<String, String> infoMap = new HashMap<String, String>();
+        for (Iterator<String> it = _info.keySet().iterator(); it.hasNext();)
+        {
             key = it.next();
-            infoMap.put(key, _info.get(key).toString());  
+            infoMap.put(key, _info.get(key).toString());
         }
         return infoMap;
     }

Modified: qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/InfoServiceImpl.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/InfoServiceImpl.java?rev=956893&r1=956892&r2=956893&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/InfoServiceImpl.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/InfoServiceImpl.java Tue Jun 22 13:42:41 2010
@@ -20,9 +20,9 @@
  */
 
 /**
- * 
+ *
  * @author sorin
- * 
+ *
  *  Implementation for Info service
  */
 
@@ -39,28 +39,28 @@ public class InfoServiceImpl implements 
 {
 
     SortedMap<String, String> infoMap = new TreeMap<String, String>();
-    
+
     /**
-     * invoke method collects all the informations from System and Application 
-     * and encapsulates them in an Info object  
-     * @return An instance of an Info object  
+     * invoke method collects all the information from System and Application
+     * and encapsulates them in an Info object
+     * @return An instance of an Info object
      */
     public Info<? extends Map<String,?>> invoke(String action)
     {
         // Record the action (STARTUP/SHUTDOWN)
         infoMap.put("action",action);
-        
+
         // Record the current time stamp
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ");
         infoMap.put("time", sdf.format(Calendar.getInstance().getTime()));
-        
+
         // Add the system specific properties 
         infoMap.putAll(SystemInfo.getInfo());
         
         // Add the application specific properties
         infoMap.putAll(AppInfo.getInfo());
-        
+
         return new Info<SortedMap<String, String>>(infoMap);
-    }  
+    }
 
 }

Modified: qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/SystemInfo.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/SystemInfo.java?rev=956893&r1=956892&r2=956893&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/SystemInfo.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/SystemInfo.java Tue Jun 22 13:42:41 2010
@@ -32,7 +32,7 @@ import java.util.TreeMap;
 import java.util.Map.Entry;
 
 /**
- * Collector for system specific information    
+ * Collector for system specific information
  */
 public class SystemInfo
 {
@@ -46,8 +46,8 @@ public class SystemInfo
             "user.home", "user.dir", "user.name", "user.timezone");
 
     /**
-     * getInfo collects all the properties specified in sysprops list  
-     * @return A Map<String,String>   
+     * getInfo collects all the properties specified in sysprops list
+     * @return A Map<String,String>
      */
     public static Map<String, String> getInfo()
     {
@@ -59,9 +59,10 @@ public class SystemInfo
             String hostname = addr.getHostName();
             sysInfoMap.put("hostname", hostname);
             sysInfoMap.put("ip", addr.getHostAddress());
-        } catch (UnknownHostException e)
+        }
+        catch (UnknownHostException e)
         {
-            //
+            // drop everything to be silent
         }
         // Get the runtime info
         sysInfoMap.put("CPUCores", Runtime.getRuntime().availableProcessors()

Modified: qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/HttpPoster.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/HttpPoster.java?rev=956893&r1=956892&r2=956893&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/HttpPoster.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/HttpPoster.java Tue Jun 22 13:42:41 2010
@@ -40,63 +40,67 @@ import java.net.UnknownHostException;
  */
 public class HttpPoster implements Runnable
 {
-    private final String url;
+    private final String _url;
 
-    private final Hashtable<String, String> header;
+    private final Hashtable<String, String> _header;
 
-    private final List<String> response = new ArrayList<String>();
+    private final List<String> _response = new ArrayList<String>();
 
     private final StringBuffer _buf;
 
     /**
      * Constructor
-     * @param props  Properties containing the URL 
-     * @param buf    Buffer containing the message to be posted
+     *
+     * @param props Properties containing the URL
+     * @param buf   Buffer containing the message to be posted
      */
     public HttpPoster(Properties props, StringBuffer buf)
     {
         _buf = buf;
         if (null != props)
         {
-            url = props.getProperty("http.url");
-            header = new Hashtable<String, String>();
+            _url = props.getProperty("http.url");
+            _header = new Hashtable<String, String>();
             try
             {
-              String hostname = InetAddress.getLocalHost().getHostName();
-              header.put("hostname", hostname);
-            } catch (UnknownHostException e)
+                String hostname = InetAddress.getLocalHost().getHostName();
+                _header.put("hostname", hostname);
+            }
+            catch (UnknownHostException e)
             {
-               // Silently ignoring the error ;)
+                // Silently ignoring the error ;)
             }
-        } else
+        }
+        else
         {
-            url = null;
-            header = null;
+            _url = null;
+            _header = null;
         }
     }
-    /**
-     * Posts the message from the _buf StringBuffer to the http server
-     */
+
+    /** Posts the message from the _buf StringBuffer to the http server */
     public void run()
     {
-        if (null == url)
+        if (null == _url)
+        {
             return;
+        }
         String line;
         URL urlDest;
         URLConnection urlConn;
         try
         {
-            urlDest = new URL(url);
+            urlDest = new URL(_url);
             urlConn = urlDest.openConnection();
             urlConn.setDoOutput(true);
             urlConn.setUseCaches(false);
-            for (Iterator<String> it = header.keySet().iterator(); it.hasNext();)
+            for (Iterator<String> it = _header.keySet().iterator(); it.hasNext();)
             {
-                String prop = (String) it.next();
-                urlConn.setRequestProperty(prop, header.get(prop));
+                String prop = it.next();
+                urlConn.setRequestProperty(prop, _header.get(prop));
             }
-            OutputStreamWriter wr = new OutputStreamWriter(urlConn
-                    .getOutputStream());
+            OutputStreamWriter wr =
+                    new OutputStreamWriter(urlConn.getOutputStream());
             wr.write(_buf.toString());
             wr.flush();
             // Get the response
@@ -104,21 +108,23 @@ public class HttpPoster implements Runna
                     urlConn.getInputStream()));
             while ((line = rd.readLine()) != null)
             {
-                response.add(line);
+                _response.add(line);
             }
-        } catch (Exception ex)
+        }
+        catch (Exception ex)
         {
-            return;
+            // Silently ignoring the error ;)
         }
     }
-    
+
     /**
      * Retrieves the response from the http server
+     *
      * @return List<String> response received from the http server
      */
-    public List<String> getResponse()
+    public List<String> get_response()
     {
-        return response;
+        return _response;
     }
 
 }

Modified: qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/IniFileReader.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/IniFileReader.java?rev=956893&r1=956892&r2=956893&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/IniFileReader.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/IniFileReader.java Tue Jun 22 13:42:41 2010
@@ -21,37 +21,42 @@
 
 package org.apache.qpid.info.util;
 
-import java.util.*;
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
 
 /**
- * This class is simple implementation of an ini file reader. It expects a 
+ * This class is simple implementation of an ini file reader. It expects a
  * file with the following structure:
- * 
- * ; global values, can be overwritten in sections 
+ *
+ * ; global values, can be overwritten in sections
  * key1=value1
  * key2=value2
- * 
+ *
  * [Section1]
  * key1=value1_new  ; overwriting the global key1
  * key3=value3
  * key4=value4
- * 
+ *
  * [Section2]
  * key5=value5
  * key6=value6
  * key7=value7
- * 
+ *
  * Note: Commentaries are preceded by ; or # and are supported throughout
- *       A commentary line at the end of section is interpreted as 
- *       a section end marker
- * 
- * A structure <String,Properties> (section name, associated properties)  
- * is generated as a result of processing the ini file. 
+ * A commentary line at the end of section is interpreted as
+ * a section end marker
+ *
+ * A structure <String,Properties> (section name, associated properties)
+ * is generated as a result of processing the ini file.
  */
 public class IniFileReader
 {
-    private final Map<String, Properties> sections;
+    private final Map<String, Properties> _sections;
 
     private final String COMMENT_SEMICOLON = ";";
 
@@ -65,33 +70,45 @@ public class IniFileReader
     /*
      * IniFileReader constructor
      */
+
     public IniFileReader()
     {
-        sections = new HashMap<String, Properties>();
+        _sections = new HashMap<String, Properties>();
     }
 
     /**
      * Cleans up the after comments or the empty spaces/tabs surrounding the given string
-     * @param str   The String to be cleaned 
+     *
+     * @param str The String to be cleaned
+     *
      * @return String Cleanup Version
      */
     private String cleanUp(String str)
     {
         if (str.contains(COMMENT_SEMICOLON))
+        {
             str = str.substring(0, str.indexOf(COMMENT_SEMICOLON));
+        }
         if (str.contains(COMMENT_HASH))
+        {
             str = str.substring(0, str.indexOf(COMMENT_HASH));
+        }
         return str.trim();
     }
 
     /**
      * Loads and parses the ini file with the full path specified in the argument
-     * @param fileName  Full path to the ini file
-     * @throws IllegalArgumentException   If the file cannot be processed
+     *
+     * @param fileName Full path to the ini file
+     *
+     * @throws IllegalArgumentException If the file cannot be processed
      */
     public void load(String fileName) throws IllegalArgumentException
     {
-        if (! new File(fileName).isFile()) throw new IllegalArgumentException("File: "+fileName+ " does not exist or cannot be read.");
+        if (!new File(fileName).isFile())
+        {
+            throw new IllegalArgumentException("File: " + fileName + " does not exist or cannot be read.");
+        }
         State state = State.GLOBAL;
         String line;
         Properties sectionProps = new Properties();
@@ -104,12 +121,19 @@ public class IniFileReader
                 String str = cleanUp(line);
 
                 // Did we get a section header?
-                if (str.startsWith("[") && str.endsWith("]"))
+                if (str.startsWith("["))
                 {
+                    if (!str.endsWith("]"))
+                    {
+                        // Index of 1 to skip '['
+                        throw new IllegalArgumentException(str.substring(1)
+                                                           + " is not closed");
+                    }
+
                     // We encountered a new section header
                     if (state != State.IN_SECTION)
                     {
-                        sections.put(sectionName, sectionProps);
+                        _sections.put(sectionName, sectionProps);
                         sectionProps = new Properties();
                         sectionName = str.replace("[", "").replace("]", "")
                                 .trim();
@@ -125,10 +149,11 @@ public class IniFileReader
                     // mean we are off the section
                     if (state == State.IN_SECTION)
                     {
-                        sections.put(sectionName, sectionProps);
+                        _sections.put(sectionName, sectionProps);
                         state = State.OFF_SECTION;
                     }
-                } else
+                }
+                else
                 {
                     // proper line, add it to the props
                     if (state != State.OFF_SECTION)
@@ -143,25 +168,26 @@ public class IniFileReader
                 }
             }
             in.close();
-        } catch (IOException e)
+        }
+        catch (IOException e)
         {
-            sections.clear();
+            _sections.clear();
             return;
         }
         if (state != State.OFF_SECTION)
         {
-            sections.put(sectionName, sectionProps);
+            _sections.put(sectionName, sectionProps);
         }
     }
 
     /**
      * Getter for the Sections Map
+     *
      * @return Map<String,Properties> The parsed content of the ini file in this structure
      */
     public Map<String, Properties> getSections()
     {
-        return sections;
+        return _sections;
     }
 
-    
 }

Modified: qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/SoapClient.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/SoapClient.java?rev=956893&r1=956892&r2=956893&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/SoapClient.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/SoapClient.java Tue Jun 22 13:42:41 2010
@@ -19,19 +19,16 @@
  *
  */
 /**
- * 
+ *
  * @author sorin
- * 
+ *
  *  An simple SOAP client for qpid info service
  */
 package org.apache.qpid.info.util;
 
 import java.io.BufferedWriter;
-
 import java.io.OutputStreamWriter;
-
 import java.net.InetAddress;
-
 import java.net.Socket;
 import java.util.HashMap;
 import java.util.Properties;
@@ -39,52 +36,56 @@ import java.util.Properties;
 public class SoapClient
 {
 
-    private final StringBuffer xmlData;
+    private final StringBuffer _xmlData;
 
     private final Properties _destprops;
 
-    private final String hostname;
+    private final String _hostname;
 
-    private final int port;
+    private final int _port;
 
-    private final String urlpath;
+    private final String _urlpath;
 
-    private final String soapenvelope;
+    private final String _soapenvelope;
     
-    private final String soapaction;
+    private final String _soapaction;
     
-    private final StringBuffer soapMessage = new StringBuffer();
+    private final StringBuffer _soapMessage = new StringBuffer();
     
 
     public SoapClient(HashMap<String, String> map, Properties destprops)
     {
         _destprops = destprops;
-        hostname = (String) _destprops.get("soap.hostname");
-        port = Integer.parseInt((String) _destprops.get("soap.port"));
-        urlpath = (String) destprops.get("soap.path");
-        soapenvelope = (String) destprops.get("soap.envelope");
-        soapaction = (String) destprops.get("soap.action");
-        xmlData = new StringBuffer(soapenvelope);
+        _hostname = (String) _destprops.get("soap.hostname");
+        _port = Integer.parseInt((String) _destprops.get("soap.port"));
+        _urlpath = (String) destprops.get("soap.path");
+        _soapenvelope = (String) destprops.get("soap.envelope");
+        _soapaction = (String) destprops.get("soap.action");
+        _xmlData = new StringBuffer(_soapenvelope);
         replaceVariables(map);
     }
 
     public StringBuffer getXMLData()
     {
-        return xmlData;
+        return _xmlData;
     }
 
     public StringBuffer getSoapMessage() {
-        return soapMessage;
+        return _soapMessage;
     }
    
     public String getSoapEnvelope() {
-        return soapenvelope;
+        return _soapenvelope;
     }
-  
+
+    /**
+     * Clears and sets new XML data
+     * @param sb the new data to set
+     */
     public void setXMLData(StringBuffer sb)
     {
-        xmlData.delete(0, xmlData.length());
-        xmlData.append(sb);
+        _xmlData.delete(0, _xmlData.length());
+        _xmlData.append(sb);
     }
     
 
@@ -93,9 +94,9 @@ public class SoapClient
         int ix = 0;
         for (String var : vars.keySet())
         {
-            while ((ix = xmlData.indexOf("@" + var.toUpperCase())) >= 0)
+            while ((ix = _xmlData.indexOf("@" + var.toUpperCase())) >= 0)
             {
-                xmlData.replace(ix, ix + 1 + var.length(), vars.get(var));
+                _xmlData.replace(ix, ix + 1 + var.length(), vars.get(var));
             }
         }
     }
@@ -103,13 +104,15 @@ public class SoapClient
     public void replaceVariables(Properties varProps)
     {
         if (varProps == null)
+        {
             return;
+        }
         int ix = 0;
         for (Object var : varProps.keySet())
         {
-            while ((ix = xmlData.indexOf("@" + var)) >= 0)
+            while ((ix = _xmlData.indexOf("@" + var)) >= 0)
             {
-                xmlData.replace(ix, ix + 1 + var.toString().length(), varProps
+                _xmlData.replace(ix, ix + 1 + var.toString().length(), varProps
                         .get(var).toString());
             }
         }
@@ -121,34 +124,32 @@ public class SoapClient
 
         try
         {
-            InetAddress addr = InetAddress.getByName(hostname);
-            Socket sock = new Socket(addr, port);
+            InetAddress addr = InetAddress.getByName(_hostname);
+            Socket sock = new Socket(addr, _port);
             StringBuffer sb = new StringBuffer();
-            sb.append("POST " + urlpath + " HTTP/1.1\r\n");
-            sb.append("Host: " + hostname + ":" + port + "\r\n");
-            sb.append("Content-Length: " + xmlData.length() + "\r\n");
+            sb.append("POST " + _urlpath + " HTTP/1.1\r\n");
+            sb.append("Host: " + _hostname + ":" + _port + "\r\n");
+            sb.append("Content-Length: " + _xmlData.length() + "\r\n");
             sb.append("Content-Type: text/xml; charset=\"utf-8\"\r\n");
-            sb.append("SOAPAction: \"urn:"+soapaction+"\"\r\n");
+            sb.append("SOAPAction: \"urn:"+ _soapaction +"\"\r\n");
             sb.append("User-Agent: Axis2\r\n");
             sb.append("\r\n");
             // Send header
             BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(sock
                     .getOutputStream(), "UTF-8"));
-            synchronized(soapMessage) {
-                soapMessage.setLength(0);
-                soapMessage.append(sb);
-                soapMessage.append(xmlData);
+            synchronized(_soapMessage) {
+                _soapMessage.setLength(0);
+                _soapMessage.append(sb);
+                _soapMessage.append(_xmlData);
             }
-            System.out.println(soapMessage.toString());
-         // Send data
-            wr.write(soapMessage.toString());           
+            // Send data
+            wr.write(_soapMessage.toString());
             wr.flush();
             wr.close();
             
         } catch (Exception ex)
         {
             // Drop any exception
-            System.out.println("*** INFO Exception at sending SOAP msg: "+ex.getMessage());
         }
     }
 }

Modified: qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/systest/InfoPluginTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/systest/InfoPluginTest.java?rev=956893&r1=956892&r2=956893&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/systest/InfoPluginTest.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/systest/InfoPluginTest.java Tue Jun 22 13:42:41 2010
@@ -1,5 +1,7 @@
 package org.apache.qpid.info.systest;
 
+import org.apache.qpid.test.utils.QpidBrokerTestCase;
+
 import java.io.BufferedReader;
 import java.io.BufferedWriter;
 import java.io.File;
@@ -13,37 +15,35 @@ import java.util.List;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
-import org.apache.qpid.test.utils.QpidBrokerTestCase;
-
 public class InfoPluginTest extends QpidBrokerTestCase
 {
     private String QPID_HOME = null;
 
-    private ServerSocket server = null;
+    private ServerSocket _server = null;
 
-    private final int port = 9000;
+    private int _port;
 
     private static final String CR = System.getProperty("line.separator");
 
     private static final String FS = File.separator;
 
-    private final String cfgRelPath = "etc" + FS + "qpidinfo.properties";
+    private final String _cfgRelPath = "etc" + FS + "qpidinfo.ini";
 
-    private File tmpCfgFile;
+    private File _tmpCfgFile;
 
-    private final String soapEnvelopeHead = "<?xml version=\"1.0\"?><soap:Envelope xmlns:soap=\"http://www.w3.org/2001/12/soap-envelope\" soap:encodingStyle=\"http://www.w3.org/2001/12/soap-encoding\">";
+    private final String _soapEnvelopeHead = "<?xml version=\"1.0\"?><soap:Envelope xmlns:soap=\"http://www.w3.org/2001/12/soap-envelope\" soap:encodingStyle=\"http://www.w3.org/2001/12/soap-encoding\">";
 
-    private final String soapEnvelopeTail = "</soap:Envelope>";
+    private final String _soapEnvelopeTail = "</soap:Envelope>";
 
-    private String soapMessage1 = "@ACTION" + "-" + "@VERSION";
+    private String _soapMessage1 = "@ACTION" + "-" + "@VERSION";
 
-    private String soapMessage2 = "@VERSION" + "-" + "@ACTION";
+    private String _soapMessage2 = "@VERSION" + "-" + "@ACTION";
 
-    private CountDownLatch latch = new CountDownLatch(2);
+    private CountDownLatch _latch = new CountDownLatch(2);
 
-    final List<List<String>> recv = new ArrayList<List<String>>();
+    final List<List<String>> _recv = new ArrayList<List<String>>();
 
-    Thread socketAcceptor;
+    Thread _socketAcceptor;
 
     public void setUp() throws Exception
     {
@@ -51,19 +51,27 @@ public class InfoPluginTest extends Qpid
         if (QPID_HOME != null)
         {
             System.out.println("QPID_HOME=" + QPID_HOME);
-        } else
+        }
+        else
         {
             fail("QPID_HOME not set");
         }
+
+        startSoapServer();
+        // Must start the server first to identify a free port.
         createConfigFile();
-        startSoapServer(port);
     }
 
     public void tearDown() throws Exception
     {
+        System.out.println("*** Stopping socket server...");
+        _socketAcceptor.join(2000);
+
         System.out.println("*** Deleting the config file...");
-        if (tmpCfgFile.isFile())
-            tmpCfgFile.delete();
+        if (_tmpCfgFile.isFile())
+        {
+            _tmpCfgFile.delete();
+        }
         super.tearDown();
     }
 
@@ -71,18 +79,21 @@ public class InfoPluginTest extends Qpid
     {
         try
         {
-            tmpCfgFile = new File(QPID_HOME + FS + cfgRelPath);
-            if (tmpCfgFile.isFile())
-                tmpCfgFile.delete();
-            tmpCfgFile.createNewFile();
-            assertTrue(tmpCfgFile.isFile());
-            FileWriter fwriter = new FileWriter(tmpCfgFile);
+            _tmpCfgFile = new File(QPID_HOME + FS + _cfgRelPath);
+            _tmpCfgFile.deleteOnExit();
+            if (_tmpCfgFile.isFile())
+            {
+                _tmpCfgFile.delete();
+            }
+            assertTrue("Unable to create file.", _tmpCfgFile.createNewFile());
+            assertTrue(_tmpCfgFile.isFile());
+            FileWriter fwriter = new FileWriter(_tmpCfgFile);
             BufferedWriter writer = new BufferedWriter(fwriter);
             writer.write("protocol=soap");
             writer.write(CR);
             writer.write("soap.hostname=localhost");
             writer.write(CR);
-            writer.write("soap.port=" + port);
+            writer.write("soap.port=" + _port);
             writer.write(CR);
             writer.write(CR);
             writer.write("[MSG1]");
@@ -91,8 +102,8 @@ public class InfoPluginTest extends Qpid
             writer.write(CR);
             writer.write("soap.action=submitinfo1");
             writer.write(CR);
-            writer.write("soap.envelope=" + soapEnvelopeHead + soapMessage1
-                    + soapEnvelopeTail);
+            writer.write("soap.envelope=" + _soapEnvelopeHead + _soapMessage1
+                         + _soapEnvelopeTail);
             writer.write(CR);
             writer.write(CR);
             writer.write("[MSG2]");
@@ -101,34 +112,36 @@ public class InfoPluginTest extends Qpid
             writer.write(CR);
             writer.write("soap.action=submitinfo2");
             writer.write(CR);
-            writer.write("soap.envelope=" + soapEnvelopeHead + soapMessage2
-                    + soapEnvelopeTail);
+            writer.write("soap.envelope=" + _soapEnvelopeHead + _soapMessage2
+                         + _soapEnvelopeTail);
             writer.write(CR);
             writer.write(CR);
             writer.close();
-            assertTrue("Config file size is zero", tmpCfgFile.length() > 0);
-        } catch (IOException e)
+            assertTrue("Config file size is zero", _tmpCfgFile.length() > 0);
+        }
+        catch (IOException e)
         {
             fail("Unable to create the qpidinfo.properties due to: "
-                    + e.getMessage());
+                 + e.getMessage());
         }
     }
 
-    private void startSoapServer(int port) throws Exception
+    private void startSoapServer() throws Exception
     {
-        assertTrue("Port a negative number", port > 0);
-        assertTrue("Port higher than 65535", port < 65535);
-
         try
         {
-            server = new ServerSocket(port);
-            assertNotNull("SocketServer is null", server);
-        } catch (Exception ex)
+            _server = new ServerSocket(0);
+            _port = _server.getLocalPort();
+            assertTrue("Server not yet bound.", _port != -1);
+
+            assertNotNull("SocketServer is null", _server);
+        }
+        catch (Exception ex)
         {
             fail("Unable to start the socket server due to: " + ex.getMessage());
         }
 
-        socketAcceptor = new Thread()
+        _socketAcceptor = new Thread()
         {
             public void run()
             {
@@ -136,26 +149,27 @@ public class InfoPluginTest extends Qpid
                 {
                     try
                     {
-                        Socket socket = server.accept();
+                        Socket socket = _server.accept();
                         new ConnectionHandler(socket);
-                    } catch (IOException e)
+                    }
+                    catch (IOException e)
                     {
                         fail("Error opening the socket in accept mode");
                     }
                 }
             }
         };
-        socketAcceptor.start();
+        _socketAcceptor.start();
         System.out.println("*** Socket server started...");
     }
 
     class ConnectionHandler implements Runnable
     {
-        private Socket socket;
+        private Socket _socket;
 
         public ConnectionHandler(Socket socket)
         {
-            this.socket = socket;
+            _socket = socket;
             Thread t = new Thread(this);
             t.start();
         }
@@ -168,7 +182,7 @@ public class InfoPluginTest extends Qpid
             try
             {
                 BufferedReader br = new BufferedReader(new InputStreamReader(
-                        socket.getInputStream()));
+                        _socket.getInputStream()));
                 assertNotNull(br);
                 while ((line = br.readLine()) != null)
                 {
@@ -177,12 +191,13 @@ public class InfoPluginTest extends Qpid
                 br.close();
                 System.out.println("*** Received buffer: " + buf);
                 System.out.println("*** Latch countdown");
-                latch.countDown();
-                synchronized (recv)
+                _latch.countDown();
+                synchronized (_recv)
                 {
-                    recv.add(buf);
+                    _recv.add(buf);
                 }
-            } catch (Exception ex)
+            }
+            catch (Exception ex)
             {
                 ex.printStackTrace();
                 fail("Exception while reading from the socket");
@@ -194,56 +209,48 @@ public class InfoPluginTest extends Qpid
 
     public void testInfoPlugin() throws Exception
     {
+        //Start the broker
         super.setUp();
-        if (!latch.await(10, TimeUnit.SECONDS))
+        if (!_latch.await(10, TimeUnit.SECONDS))
         {
             fail("Timeout awaiting for the latch, upon startup");
         }
 
-        assertTrue("Received less than 2 messages", recv.size() > 1);
-        //Message 1
-        assertTrue("Message has 0 size", recv.get(0).size()>0);
-        assertEquals("Message does not have 8 fields", recv.get(0).size(), 8);
-        assertTrue("Message does not contain Host: localhost:9000",recv.get(0).contains("Host: localhost:9000"));
-        assertTrue("Message does not contain: User-Agent: Axis2 ", recv.get(0).contains("User-Agent: Axis2"));
-        assertTrue("Message does not contain: SOAPAction: \"urn:submitinfo\"", recv.get(0).get(4).startsWith("SOAPAction: \"urn:submitinfo"));
-        assertTrue("Message does not contain STARTUP in the soap envelope", recv.get(0).get(7).contains("STARTUP"));
-        
-        //Message 2
-        assertTrue("Message has 0 size", recv.get(1).size()>0);
-        assertEquals("Message does not have 8 fields", recv.get(1).size(), 8);
-        assertTrue("Message does not contain Host: localhost:9000",recv.get(1).contains("Host: localhost:9000"));
-        assertTrue("Message does not contain: User-Agent: Axis2 ", recv.get(1).contains("User-Agent: Axis2"));
-        assertTrue("Message does not contain: SOAPAction: \"urn:submitinfo\"", recv.get(1).get(4).startsWith("SOAPAction: \"urn:submitinfo"));
-        assertTrue("Message does not contain STARTUP in the soap envelope", recv.get(0).get(7).contains("STARTUP"));
-        
-        recv.clear();
-        latch = new CountDownLatch(2);
-   
+        validateResponses("STARTUP");
+
+        _recv.clear();
+        _latch = new CountDownLatch(2);
+
         stopBroker();
-        
-        if (!latch.await(10, TimeUnit.SECONDS))
+
+        if (!_latch.await(10, TimeUnit.SECONDS))
         {
             fail("Timeout awaiting for the latch, upon shutdown");
         }
-        
-        
-        assertTrue("Received less than 2 messages", recv.size() > 1);
-        
-         // Message 1
-        assertTrue("Message does not contain Host: localhost:9000",recv.get(0).contains("Host: localhost:9000"));
-        assertTrue("Message does not contain: User-Agent: Axis2 ", recv.get(0).contains("User-Agent: Axis2"));
-        assertTrue("Message does not contain: SOAPAction: \"urn:submitinfo\"", recv.get(0).get(4).startsWith("SOAPAction: \"urn:submitinfo"));
-        assertTrue("Message does not contain SHUTDOWN in the soap envelope", recv.get(0).get(7).contains("SHUTDOWN"));
-        
+
+        validateResponses("SHUTDOWN");
+
+    }
+
+    /**
+     * Check the responses from the server to ensure they contain the required messages.
+     * @param action String to match for the SHUTDOWN or STARTUP action.
+     */
+    private void validateResponses(String action)
+    {
+        assertTrue("Received less than 2 messages", _recv.size() > 1);
+
+        // Message 1
+        assertTrue("Message does not contain Host: localhost:" + _port + "\n" + _recv.get(0), _recv.get(0).contains("Host: localhost:" + _port));
+        assertTrue("Message does not contain: User-Agent: Axis2 " + "\n" + _recv.get(0), _recv.get(0).contains("User-Agent: Axis2"));
+        assertTrue("Message does not contain: SOAPAction: \"urn:submitinfo\"" + "\n" + _recv.get(0).get(4), _recv.get(0).get(4).startsWith("SOAPAction: \"urn:submitinfo"));
+        assertTrue("Message does not contain '" + action + "' in the soap envelope" + "\n" + _recv.get(0).get(7), _recv.get(0).get(7).contains(action));
+
         // Message 2
-        assertTrue("Message does not contain Host: localhost:9000",recv.get(1).contains("Host: localhost:9000"));
-        assertTrue("Message does not contain: User-Agent: Axis2 ", recv.get(1).contains("User-Agent: Axis2"));
-        assertTrue("Message does not contain: SOAPAction: \"urn:submitinfo\"", recv.get(1).get(4).startsWith("SOAPAction: \"urn:submitinfo"));
-        assertTrue("Message does not contain SHUTDOWN in the soap envelope", recv.get(0).get(7).contains("SHUTDOWN"));
-        
-        System.out.println("*** Stopping socket server...");
-        socketAcceptor.join(2000);
+        assertTrue("Message does not contain Host: localhost:" + _port + "\n" + _recv.get(1), _recv.get(1).contains("Host: localhost:" + _port));
+        assertTrue("Message does not contain: User-Agent: Axis2 " + "\n" + _recv.get(1), _recv.get(1).contains("User-Agent: Axis2"));
+        assertTrue("Message does not contain: SOAPAction: \"urn:submitinfo\"" + "\n" + _recv.get(1).get(4), _recv.get(1).get(4).startsWith("SOAPAction: \"urn:submitinfo"));
+        assertTrue("Message does not contain '" + action + "' in the soap envelope" + "\n" + _recv.get(1).get(7), _recv.get(1).get(7).contains(action));
     }
 
 }

Modified: qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/HttpPosterTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/HttpPosterTest.java?rev=956893&r1=956892&r2=956893&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/HttpPosterTest.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/HttpPosterTest.java Tue Jun 22 13:42:41 2010
@@ -92,14 +92,14 @@ public class HttpPosterTest extends Test
         HttpPoster hp = getHttpPoster(baseURL + contextPath);
         assertNotNull(hp);
         hp.run();
-        List<String> response = hp.getResponse();
+        List<String> response = hp.get_response();
         assertTrue(response.size() > 0);
         assertEquals("OK <br>", response.get(0).toString());
 
         // Failure Test
         hp = getHttpPoster("http://localhost/nonexistent");
         hp.run();
-        response = hp.getResponse();
+        response = hp.get_response();
         assertTrue(response.size() == 0);
 
     }

Modified: qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoServiceImplTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoServiceImplTest.java?rev=956893&r1=956892&r2=956893&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoServiceImplTest.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoServiceImplTest.java Tue Jun 22 13:42:41 2010
@@ -37,14 +37,14 @@ import junit.framework.TestCase;
 public class InfoServiceImplTest extends TestCase
 {
 
-    InfoServiceImpl isi = null;
+    InfoServiceImpl _isi = null;
 
     @SuppressWarnings("unchecked")
     public void testInvoke()
     {
-        isi = new InfoServiceImpl();
-        assertNotNull(isi);
-        Info<? extends Map<String, String>> info = (Info<? extends Map<String, String>>) isi
+        _isi = new InfoServiceImpl();
+        assertNotNull(_isi);
+        Info<? extends Map<String, String>> info = (Info<? extends Map<String, String>>) _isi
                 .invoke("START");
         assertNotNull(info);
         Properties props = info.toProps();

Modified: qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoTest.java?rev=956893&r1=956892&r2=956893&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoTest.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoTest.java Tue Jun 22 13:42:41 2010
@@ -32,23 +32,16 @@ import org.apache.qpid.info.Info;
  */
 public class InfoTest extends TestCase
 {
-    private HashMap<String, String> infoPayLoad = null;
+    private HashMap<String, String> _infoPayLoad = null;
 
-    private Info<HashMap<String, String>> info = null;
+    private Info<HashMap<String, String>> _info = null;
 
     protected void setUp() throws Exception
     {
         super.setUp();
-        infoPayLoad = new HashMap<String, String>();
-        infoPayLoad.put("test", "Test");
-        info = new Info<HashMap<String, String>>(infoPayLoad);
-    }
-
-    protected void tearDown() throws Exception
-    {
-        super.tearDown();
-        info = null;
-        infoPayLoad = null;
+        _infoPayLoad = new HashMap<String, String>();
+        _infoPayLoad.put("test", "Test");
+        _info = new Info<HashMap<String, String>>(_infoPayLoad);
     }
 
     /*
@@ -56,9 +49,9 @@ public class InfoTest extends TestCase
      */
     public void testToString()
     {
-        assertNotNull("toString() returned null", info.toString());
+        assertNotNull("toString() returned null", _info.toString());
         assertEquals("toString() did not return the proper string",
-                "test=Test\n", info.toString());
+                "test=Test\n", _info.toString());
     }
 
     /*
@@ -68,8 +61,8 @@ public class InfoTest extends TestCase
     {
         Properties props = new Properties();
         props.put("test", "Test");
-        assertNotNull("toProperties() returned null", info.toProps());
-        assertEquals("toProperties not returned the proper object", props, info
+        assertNotNull("toProperties() returned null", _info.toProps());
+        assertEquals("toProperties not returned the proper object", props, _info
                 .toProps());
     }
 
@@ -79,8 +72,8 @@ public class InfoTest extends TestCase
     public void testToStringBuffer()
     {
         StringBuffer sb = new StringBuffer("test=Test\n");
-        assertNotNull(info.toStringBuffer());
-        assertEquals(sb.toString(), info.toStringBuffer().toString());
+        assertNotNull(_info.toStringBuffer());
+        assertEquals(sb.toString(), _info.toStringBuffer().toString());
     }
 
     /*
@@ -88,15 +81,15 @@ public class InfoTest extends TestCase
      */
     public void testToXML()
     {
-        String INDEND = "    ";
+        String INDENT = "    ";
         StringBuffer sb = new StringBuffer();
         sb.append("<?xml version=\"1.0\"?>\n");
         sb.append("<qpidinfo>\n");
         sb.append("<test>\n");
-        sb.append(INDEND + "Test\n");
+        sb.append(INDENT + "Test\n");
         sb.append("</test>\n");
         sb.append("</qpidinfo>\n");
-        assertEquals("toString() does not return the proper string", info
+        assertEquals("toString() does not return the proper string", _info
                 .toXML().toString(), sb.toString());
     }
 
@@ -105,7 +98,7 @@ public class InfoTest extends TestCase
      */
     public void testToMap()
     {
-        HashMap<String, String> thm = info.toMap();
+        HashMap<String, String> thm = _info.toMap();
         assertFalse("toMap() returned empty map", thm.isEmpty());
         assertEquals("testToMap did not returned 1", 1, thm.size());
         assertTrue("toMap() returned a map not containing expected key: test",

Modified: qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/IniFileReaderTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/IniFileReaderTest.java?rev=956893&r1=956892&r2=956893&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/IniFileReaderTest.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/IniFileReaderTest.java Tue Jun 22 13:42:41 2010
@@ -21,6 +21,9 @@
 
 package org.apache.qpid.info.test;
 
+import junit.framework.TestCase;
+import org.apache.qpid.info.util.IniFileReader;
+
 import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileWriter;
@@ -28,10 +31,10 @@ import java.io.IOException;
 import java.util.Map;
 import java.util.Properties;
 
-import org.apache.qpid.info.util.IniFileReader;
-
-import junit.framework.TestCase;
-
+/**
+ * Test the Loading of the ini file reader by first writing
+ * out a correct ini file.
+ */
 public class IniFileReaderTest extends TestCase
 {
 
@@ -48,8 +51,8 @@ public class IniFileReaderTest extends T
             writer.write("globalprop1=globalval1\n");
             writer.write("globalprop2=globalval2\n");
             writer.write("\n");
-            writer.write("[Section1]\n");
-            writer.write("key1=val1\n");
+            writer.write("[Section1] # Comment on Section\n");
+            writer.write("key1=val1 # Comment on Value\n");
             writer.write("key2=val2\n");
             writer.write("\n");
             writer.write("#Section2 Comment\n");
@@ -63,29 +66,71 @@ public class IniFileReaderTest extends T
             writer.write("key7=val7\n");
             writer.write("\n");
             writer.close();
-        } catch (IOException e)
+        }
+        catch (IOException e)
         {
             e.printStackTrace();
             fail("Unable to create temporary File");
         }
         ifr.load(iniFile.getAbsolutePath());
-        Map<String,Properties> sections = ifr.getSections();
-        assertNotNull("Sections not null",sections);
+        Map<String, Properties> sections = ifr.getSections();
+        assertNotNull("Sections not null", sections);
         assertEquals("Have 4 sections", sections.keySet().size(), 4);
         assertTrue("Get globalprop1", sections.get("").getProperty("globalprop1").equals("globalval1"));
         assertTrue("Get globalprop2", sections.get("").getProperty("globalprop2").equals("globalval2"));
         assertNotNull("Section1 not null", sections.get("Section1"));
-        assertEquals("Section1 has 2 properties",sections.get("Section1").size(),2);
-        assertTrue("Section1 key1 has val1",sections.get("Section1").getProperty("key1").equals("val1"));
-        assertTrue("Section1 key2 has val2",sections.get("Section1").getProperty("key2").equals("val2"));
-        assertEquals("Section2 has 3 properties",sections.get("Section2").size(),3);
-        assertTrue("Section2 key3 has val3",sections.get("Section2").getProperty("key3").equals("val3"));
-        assertTrue("Section2 key4 has val4",sections.get("Section2").getProperty("key4").equals("val4"));
-        assertTrue("Section2 key5 has val5",sections.get("Section2").getProperty("key5").equals("val5"));
-        assertEquals("Section3 has 2 properties",sections.get("Section3").size(),2);
-        assertTrue("Section3 key6 has val6",sections.get("Section3").getProperty("key6").equals("val6"));
-        assertTrue("Section3 key7 has val7",sections.get("Section3").getProperty("key7").equals("val7"));
+        assertEquals("Section1 has 2 properties", sections.get("Section1").size(), 2);
+        assertTrue("Section1 key1 has val1", sections.get("Section1").getProperty("key1").equals("val1"));
+        assertTrue("Section1 key2 has val2", sections.get("Section1").getProperty("key2").equals("val2"));
+        assertEquals("Section2 has 3 properties", sections.get("Section2").size(), 3);
+        assertTrue("Section2 key3 has val3", sections.get("Section2").getProperty("key3").equals("val3"));
+        assertTrue("Section2 key4 has val4", sections.get("Section2").getProperty("key4").equals("val4"));
+        assertTrue("Section2 key5 has val5", sections.get("Section2").getProperty("key5").equals("val5"));
+        assertEquals("Section3 has 2 properties", sections.get("Section3").size(), 2);
+        assertTrue("Section3 key6 has val6", sections.get("Section3").getProperty("key6").equals("val6"));
+        assertTrue("Section3 key7 has val7", sections.get("Section3").getProperty("key7").equals("val7"));
     }
 
+    /**
+     * Test to ensure that the loading of a file with an unclosed section header
+     * fails to parse.
+     *
+     * Section needs to be fully enclosed in square brackets '[<name>]'
+     */
+    public void testIncompleteSection1Load()
+    {
+        IniFileReader ifr = new IniFileReader();
+        File iniFile = null;
+        try
+        {
+            iniFile = File.createTempFile(getName(), "ini");
+            iniFile.deleteOnExit();
+            BufferedWriter writer = new BufferedWriter(new FileWriter(iniFile));
+            writer.write("# Global Comment1\n");
+            writer.write("globalprop1=globalval1\n");
+            writer.write("globalprop2=globalval2\n");
+            writer.write("\n");
+            writer.write("[Section1\n");  // Note '[Section1' not complete
+            writer.write("key1=val1\n");
+            writer.write("key2=val2\n");
+            writer.write("\n");
+            writer.close();            
+        }
+        catch (IOException e)
+        {
+            e.printStackTrace();
+            fail("Unable to create temporary File");
+        }
+        try
+        {
+            ifr.load(iniFile.getAbsolutePath());
+            fail("File should fail to parse");
+        }
+        catch (IllegalArgumentException iae)
+        {
+            assertEquals("Incorrect Exception", "Section1 is not closed", iae.getMessage());
+        }
+
+    }
 
 }

Modified: qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SoapClientTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SoapClientTest.java?rev=956893&r1=956892&r2=956893&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SoapClientTest.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SoapClientTest.java Tue Jun 22 13:42:41 2010
@@ -21,6 +21,9 @@
 
 package org.apache.qpid.info.test;
 
+import junit.framework.TestCase;
+import org.apache.qpid.info.util.SoapClient;
+
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
@@ -31,22 +34,16 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Properties;
 
-import junit.framework.TestCase;
-
-import org.apache.qpid.info.util.SoapClient;
-
 public class SoapClientTest extends TestCase
 {
 
-    private final int port = 9100;
-
-    private final String hostName = "localhost";
+    private int _port;
 
-    private final String urlPath = "/testSoap";
+    private final String _hostName = "localhost";
 
-    private ServerSocket server = null;
+    private final String _urlPath = "/testSoap";
 
-    Thread socketAcceptor;
+    private ServerSocket _server = null;
 
     /*
      * Generate a soap client from a custom URL, hostname, port and soap context
@@ -55,9 +52,9 @@ public class SoapClientTest extends Test
     private SoapClient getSoapClient()
     {
         Properties destprops = new Properties();
-        destprops.setProperty("soap.hostname", hostName);
-        destprops.setProperty("soap.port", port + "");
-        destprops.setProperty("soap.urlpath", urlPath);
+        destprops.setProperty("soap.hostname", _hostName);
+        destprops.setProperty("soap.port", _port + "");
+        destprops.setProperty("soap.urlpath", _urlPath);
         destprops.setProperty("soap.envelope", "<ip>@IP</ip>");
         destprops.setProperty("soap.action", "send");
         HashMap<String, String> soapmap = new HashMap<String, String>();
@@ -94,7 +91,8 @@ public class SoapClientTest extends Test
                     response.add(line);
                 }
                 br.close();
-            } catch (Exception ex)
+            }
+            catch (Exception ex)
             {
                 ex.printStackTrace();
                 fail("Exception while reading from the socket");
@@ -103,7 +101,7 @@ public class SoapClientTest extends Test
             assertTrue(response.contains("SOAPAction: \"urn:send\""));
             assertTrue(response
                     .contains("Content-Type: text/xml; charset=\"utf-8\""));
-            assertTrue(response.contains("Host: localhost:9000"));
+            assertTrue(response.contains("Host: localhost" + _port));
             assertTrue(response.contains("User-Agent: Axis2"));
         }
 
@@ -118,59 +116,93 @@ public class SoapClientTest extends Test
         //
         try
         {
-            server = new ServerSocket(port);
-            assertNotNull(server);
-        } catch (Exception ex)
+            _server = new ServerSocket(0);
+            _port = _server.getLocalPort();
+            assertTrue("Server is not yet bound to a port", _port != -1);
+            assertNotNull(_server);
+        }
+        catch (Exception ex)
         {
             ex.printStackTrace();
             fail("Unable to start the socket server");
         }
 
-        socketAcceptor = new Thread()
+        Thread _socketAcceptor = new Thread()
         {
             public void run()
             {
                 try
                 {
-                    Socket socket = server.accept();
+                    Socket socket = _server.accept();
                     new ConnectionHandler(socket);
-                } catch (IOException e)
+                }
+                catch (IOException e)
                 {
                     e.printStackTrace();
                 }
             }
         };
-        socketAcceptor.start();
+        _socketAcceptor.start();
         // Sleep for 1 second to allow the ServerSocket readiness
         Thread.sleep(1000);
         SoapClient sc = getSoapClient();
         assertNotNull(sc);
         sc.sendSOAPMessage();
-        socketAcceptor.join(2000);
+
+        _socketAcceptor.join(2000);
+
+        assertFalse("Socket Acceptor not stopped.", _socketAcceptor.isAlive());
     }
-    
-    public void testSoapClientXMLData() {
+
+    /**
+     * Test SoapClient correctly clears previously set values
+     */
+    public void testSoapClientXMLData()
+    {
         SoapClient sc = getSoapClient();
+
+        StringBuffer initial = new StringBuffer("Initial Value");
+
+        sc.setXMLData(initial);
+
+        assertEquals("getXMLData is not set with initial value",
+                     initial.toString(), sc.getXMLData().toString());
+
+
         StringBuffer sb = new StringBuffer("<?xml version=\"1.0\"?><ip...@PORT>");
         sc.setXMLData(sb);
-        assertEquals(sc.getXMLData().length(),sb.length());
-        assertEquals("getXMLData does not return the same StringBuffer set by setXMLData",sb.toString(),sc.getXMLData().toString());
+        assertEquals(sc.getXMLData().length(), sb.length());
+        assertEquals("getXMLData does not return the same StringBuffer set by setXMLData",
+                     sb.toString(), sc.getXMLData().toString());
     }
-    
-    public void testReplaceVariablesMap() {
-        Properties props = new Properties();        
-        props.setProperty("soap.hostname", hostName);
-        props.setProperty("soap.port", port + "");
-        props.setProperty("soap.urlpath", urlPath);     
+
+    /**
+     * Test that variable replacement is performed on the soap.envelope.
+     * Create dummy soap message and validate that the variable have been replaced.
+     */
+    public void testReplaceVariablesMap()
+    {
+        Properties props = new Properties();
+        // Add dummy values as required to create a soap message
+        props.setProperty("soap.hostname", _hostName);
+        props.setProperty("soap.port", "0");
+        props.setProperty("soap.urlpath", _urlPath);
         props.setProperty("soap.action", "send");
+
+        /// The envelope is what we care about
         props.setProperty("soap.envelope", "<addr>@IP:@PORT</addr>");
         HashMap<String, String> soapmap = new HashMap<String, String>();
-        soapmap.put("IP", "127.0.0.1");
-        soapmap.put("PORT","8080");     
-        SoapClient sc = new SoapClient(soapmap,props);
-        assertNotNull("SoapClient is null",sc);
-        assertTrue("Replace variables did not work as expected","<addr>127.0.0.1:8080</addr>".equals(sc.getXMLData().toString()));
+
+        /// Variables that should be replaced.
+        final String ip = "127.0.0.1";
+        soapmap.put("IP", ip);
+        final String port = "8080";
+        soapmap.put("PORT", port);
+
+        SoapClient sc = new SoapClient(soapmap, props);
+        assertNotNull("SoapClient is null", sc);
+
+        assertTrue("Replace variables did not work as expected", ("<addr>" + ip + ":" + port + "</addr>").equals(sc.getXMLData().toString()));
     }
-    
 
 }

Modified: qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SystemInfoTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SystemInfoTest.java?rev=956893&r1=956892&r2=956893&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SystemInfoTest.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SystemInfoTest.java Tue Jun 22 13:42:41 2010
@@ -21,29 +21,36 @@
 
 package org.apache.qpid.info.test;
 
+import junit.framework.TestCase;
+import org.apache.qpid.info.SystemInfo;
+
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
-import junit.framework.TestCase;
-
-import org.apache.qpid.info.SystemInfo;
-
+/** Test the SystemInfo component */
 public class SystemInfoTest extends TestCase
 {
 
+    /**
+     * Ensure the list of required properties are returned by the
+     * SystemInfo.getInfo call
+     */
     public void testGetInfo()
     {
         Map<String, String> sysInfoMap = SystemInfo.getInfo();
         assertNotNull("SystemInfo.getInfo() returned null", sysInfoMap);
-        List<String> sysInfoProps = Arrays.asList("java.class.path",
+        List<String> sysInfoProps = Arrays.asList(
+                "java.class.path",
                 "java.vm.name", "java.class.version", "os.arch", "os.name",
                 "os.version", "sun.arch.data.model", "user.dir", "user.name",
-                "user.timezone");
+                "user.timezone", "hostname", "ip", "CPUCores", "Maximum_Memory",
+                "Free_Memory");
+
         for (String tag : sysInfoProps)
         {
-            assertNotNull("Map does not contain the tag: "+tag, sysInfoMap.get(tag));
+            assertNotNull("Map does not contain the tag: " + tag, sysInfoMap.get(tag));
         }
     }
 
-}
+}
\ No newline at end of file

Modified: qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/XMLWriterTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/XMLWriterTest.java?rev=956893&r1=956892&r2=956893&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/XMLWriterTest.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/XMLWriterTest.java Tue Jun 22 13:42:41 2010
@@ -21,57 +21,106 @@
 
 package org.apache.qpid.info.test;
 
-import java.util.HashMap;
-
+import junit.framework.TestCase;
 import org.apache.qpid.info.util.XMLWriter;
 
-import junit.framework.TestCase;
+import java.util.HashMap;
 
 /*
  * This test verifies the XML writer custom class operations
  */
+
 public class XMLWriterTest extends TestCase
 {
 
     private XMLWriter xw = null;
 
+    /** Test constructor arg is returned via getXML() */
     public void testXMLWriter()
     {
-        xw = new XMLWriter(new StringBuffer("Test"));
+        StringBuffer input = new StringBuffer("Test");
+        xw = new XMLWriter(input);
         assertNotNull("XMLWriter could not instantiate", xw);
-        assertEquals("XMLWriter.toString() failed","Test", xw.getXML().toString());
+        assertEquals("XMLWriter.getXML() failed", input, xw.getXML());
     }
 
+    /** Test header generation */
     public void testWriteXMLHeader()
     {
         xw = new XMLWriter(new StringBuffer());
         assertNotNull(xw);
         xw.writeXMLHeader();
-        assertEquals("XMLWriter.writeXMLHeader(...) failed","<?xml version=\"1.0\"?>\n", xw.getXML().toString());
+        assertEquals("XMLWriter.writeXMLHeader(...) failed", "<?xml version=\"1.0\"?>\n", xw.getXML().toString());
     }
 
+    /** Test tag created and written correctly */
     public void testWriteTag()
     {
-        String INDEND = "    ";
+        String INDENT = "    ";
         xw = new XMLWriter(new StringBuffer());
         assertNotNull("XMLWriter could not instantiate", xw);
         xw.writeTag("test", new HashMap<String, String>(), "TEST");
-        assertEquals("XMLWriter.writeTag(...) failed","<test>\n" + INDEND + "TEST\n" + "</test>\n", xw.getXML()
+        assertEquals("XMLWriter.writeTag(...) failed", "<test>\n" + INDENT + "TEST\n" + "</test>\n", xw.getXML()
                 .toString());
     }
 
+    /** Test tag created and written correctly */
+    public void testWriteTagWithNullAttribute()
+    {
+        String INDENT = "    ";
+        xw = new XMLWriter(new StringBuffer());
+        assertNotNull("XMLWriter could not instantiate", xw);
+        xw.writeTag("test", null, "TEST");
+        assertEquals("XMLWriter.writeTag(...) failed", "<test>\n" + INDENT + "TEST\n" + "</test>\n", xw.getXML()
+                .toString());
+    }
+
+    /** Test tag created and written correctly with attribute */
+    public void testWriteTagWithAttribute()
+    {
+        String INDENT = "    ";
+        xw = new XMLWriter(new StringBuffer());
+        assertNotNull("XMLWriter could not instantiate", xw);
+        HashMap<String, String> attr = new HashMap<String, String>();
+        attr.put("id", "1");
+
+        xw.writeTag("test", attr, "TEST");
+        assertEquals("XMLWriter.writeTag(...) failed", "<test id=\"1\">\n" + INDENT + "TEST\n" + "</test>\n", xw.getXML()
+                .toString());
+    }
+
+    /** Test open tag with an empty attribute map. Just creates an open tag */
     public void testWriteOpenTag()
     {
         xw = new XMLWriter(new StringBuffer());
         assertNotNull(xw);
         HashMap<String, String> attr = new HashMap<String, String>();
         xw.writeOpenTag("test", attr);
-        assertEquals("XMLWriter.writeOpenTag(...) failed","<test>\n", xw.getXML().toString());
+        assertEquals("XMLWriter.writeOpenTag(...) failed", "<test>\n", xw.getXML().toString());
+    }
+
+    /** Test open tag with a null attribute map. Just creates an open tag */
+    public void testNullAtrributeOnTag()
+    {
+        xw = new XMLWriter(new StringBuffer());
+        assertNotNull(xw);
+        xw.writeOpenTag("test", null);
+        assertEquals("XMLWriter.writeOpenTag(...) failed", "<test>\n", xw.getXML().toString());
+    }
+
+    /** Test that setting an attribute value on the tag is correctly outputted. */
+    public void testAtrributeOnTag()
+    {
+        xw = new XMLWriter(new StringBuffer());
+        assertNotNull(xw);
+        HashMap<String, String> attr = new HashMap<String, String>();
+
         attr.put("id", "1");
         xw.writeOpenTag("test1", attr);
-        assertEquals("XMLWriter.writeOpenTag(...) failed","<test>\n" + "<test1 id=\"1\">\n", xw.getXML().toString());
+        assertEquals("XMLWriter.writeOpenTag(...) failed", "<test1 id=\"1\">\n", xw.getXML().toString());
     }
 
+    /** Test Close Tag is correctly written */
     public void testWriteCloseTag()
     {
         xw = new XMLWriter(new StringBuffer());



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org