Author: ritchiem
Date: Tue Jun 22 13:40:52 2010
New Revision: 956887

URL: http://svn.apache.org/viewvc?rev=956887&view=rev
Log:
QPID-2555 : Improvements on info plugin, using SOAP
Patch provided by Sorin Suciu

Added:
    
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/InfoService.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/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/test/InfoServiceImplTest.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

Added: 
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=956887&view=auto
==============================================================================
--- 
qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/AppInfo.java
 (added)
+++ 
qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/AppInfo.java
 Tue Jun 22 13:40:52 2010
@@ -0,0 +1,97 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.qpid.info;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+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
+ *
+ */
+public class AppInfo
+{
+
+    private static final List<String> appProps = Arrays.asList("QPID_HOME",
+            "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()
+    {
+
+        // Gather the selected app props
+        Properties sysprops = System.getProperties();
+        String propName;
+        for (Iterator<Entry<Object, Object>> it = sysprops.entrySet()
+                .iterator(); it.hasNext();)
+        {
+            Entry<Object, Object> en = it.next();
+            propName = en.getKey().toString();
+            if (appProps.indexOf(propName) >= 0)
+            {
+                appInfoMap.put(propName, en.getValue().toString());
+            }
+        }
+
+        ServerConfiguration sc;
+        try
+        {
+            sc = ApplicationRegistry.getInstance().getConfiguration();
+            if (null != sc)
+            {
+                appInfoMap.put("jmxport", sc.getJMXManagementPort() + "");
+                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());
+                appInfoMap.put("PluginDirectory", sc.getPluginDirectory());
+                appInfoMap.put("CertType", sc.getCertType());
+                appInfoMap.put("QpidWork", sc.getQpidWork());
+                appInfoMap.put("Bind", sc.getBind());
+            }
+        } catch (Exception e)
+        {
+            // 
+        }
+        return appInfoMap;
+
+    }
+
+}

Added: 
qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/InfoService.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/InfoService.java?rev=956887&view=auto
==============================================================================
--- 
qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/InfoService.java
 (added)
+++ 
qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/InfoService.java
 Tue Jun 22 13:40:52 2010
@@ -0,0 +1,30 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+    /**
+     * Interface exposing the service methods    
+     */
+    package org.apache.qpid.info;
+    
+    public interface InfoService
+    {
+        public Info<?> invoke(String action);
+    }

Added: 
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=956887&view=auto
==============================================================================
--- 
qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/InfoServiceImpl.java
 (added)
+++ 
qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/InfoServiceImpl.java
 Tue Jun 22 13:40:52 2010
@@ -0,0 +1,66 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+/**
+ * 
+ * @author sorin
+ * 
+ *  Implementation for Info service
+ */
+
+package org.apache.qpid.info;
+
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+
+public class InfoServiceImpl implements InfoService
+{
+
+    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  
+     */
+    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);
+    }  
+
+}

Added: 
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=956887&view=auto
==============================================================================
--- 
qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/SystemInfo.java
 (added)
+++ 
qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/SystemInfo.java
 Tue Jun 22 13:40:52 2010
@@ -0,0 +1,90 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.qpid.info;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.TreeMap;
+import java.util.Map.Entry;
+
+/**
+ * Collector for system specific information    
+ */
+public class SystemInfo
+{
+
+    private static Map<String, String> sysInfoMap = new TreeMap<String, 
String>();
+
+    private static final List<String> sysProps = Arrays.asList(
+            "java.class.path", "java.home", "java.vm.name", "java.vm.vendor",
+            "java.vm.version", "java.class.version", "java.runtime.version",
+            "os.arch", "os.name", "os.version", "sun.arch.data.model",
+            "user.home", "user.dir", "user.name", "user.timezone");
+
+    /**
+     * getInfo collects all the properties specified in sysprops list  
+     * @return A Map<String,String>   
+     */
+    public static Map<String, String> getInfo()
+    {
+
+        // Get the hostname
+        try
+        {
+            InetAddress addr = InetAddress.getLocalHost();
+            String hostname = addr.getHostName();
+            sysInfoMap.put("hostname", hostname);
+            sysInfoMap.put("ip", addr.getHostAddress());
+        } catch (UnknownHostException e)
+        {
+            //
+        }
+        // Get the runtime info
+        sysInfoMap.put("CPUCores", Runtime.getRuntime().availableProcessors()
+                + "");
+        sysInfoMap.put("Maximum_Memory", Runtime.getRuntime().maxMemory() + 
"");
+        sysInfoMap.put("Free_Memory", Runtime.getRuntime().freeMemory() + "");
+
+        // Gather the selected system props
+        Properties sysprops = System.getProperties();
+        String propName;
+        for (Iterator<Entry<Object, Object>> it = sysprops.entrySet()
+                .iterator(); it.hasNext();)
+        {
+            Entry<Object, Object> en = it.next();
+            propName = en.getKey().toString();
+            if (sysProps.indexOf(propName) >= 0)
+            {
+                sysInfoMap.put(propName, en.getValue().toString());
+            }
+        }
+
+        return sysInfoMap;
+
+    }
+
+}

Added: 
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=956887&view=auto
==============================================================================
--- 
qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/IniFileReader.java
 (added)
+++ 
qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/IniFileReader.java
 Tue Jun 22 13:40:52 2010
@@ -0,0 +1,142 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.qpid.info.util;
+
+import java.util.*;
+import java.io.*;
+
+public class IniFileReader
+{
+    private final Map<String, Properties> sections;
+
+    private final String COMMENT_SEMICOLON = ";";
+
+    private final String COMMENT_HASH = "#";
+
+    enum State
+    {
+        IN_SECTION, OFF_SECTION, GLOBAL
+    }
+
+    /*
+     * IniFileReader constructor
+     */
+    public IniFileReader()
+    {
+        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 
+     * @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
+     */
+    public void load(String fileName) throws IllegalArgumentException
+    {
+        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();
+        String sectionName = "";
+        try
+        {
+            BufferedReader in = new BufferedReader(new FileReader(fileName));
+            while ((line = in.readLine()) != null)
+            {
+                String str = cleanUp(line);
+
+                // Did we get a section header?
+                if (str.startsWith("[") && str.endsWith("]"))
+                {
+                    // We encountered a new section header
+                    if (state != State.IN_SECTION)
+                    {
+                        sections.put(sectionName, sectionProps);
+                        sectionProps = new Properties();
+                        sectionName = str.replace("[", "").replace("]", "")
+                                .trim();
+                        state = State.IN_SECTION;
+                    }
+                }
+
+                // Any other line tested separately, ignore if out of a section
+                // and add if in section
+                if (str.length() == 0)
+                {
+                    // We encountered a commented or an empty line, both cases
+                    // mean we are off the section
+                    if (state == State.IN_SECTION)
+                    {
+                        sections.put(sectionName, sectionProps);
+                        state = State.OFF_SECTION;
+                    }
+                } else
+                {
+                    // proper line, add it to the props
+                    if (state != State.OFF_SECTION)
+                    {
+                        if (str.contains("="))
+                        {
+                            int ix = str.indexOf("=");
+                            sectionProps.put(str.substring(0, ix).trim(), str
+                                    .substring(ix + 1).trim());
+                        }
+                    }
+                }
+            }
+            in.close();
+        } catch (IOException e)
+        {
+            sections.clear();
+            return;
+        }
+        if (state != State.OFF_SECTION)
+        {
+            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;
+    }
+
+    
+}

Added: 
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=956887&view=auto
==============================================================================
--- 
qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/SoapClient.java
 (added)
+++ 
qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/SoapClient.java
 Tue Jun 22 13:40:52 2010
@@ -0,0 +1,162 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+/**
+ * 
+ * @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;
+
+public class SoapClient
+{
+
+    private final StringBuffer xmlData;
+
+    private final Properties _destprops;
+
+    private final String hostname;
+
+    private final String port;
+
+    private final String urlpath;
+
+    private final String soapenvelope;
+
+    private final String soapaction;
+
+    private final StringBuffer soapMessage = new StringBuffer();
+
+    public SoapClient(HashMap<String, String> map, Properties destprops)
+    {
+        if (null == destprops)
+        {
+            _destprops = new Properties();
+        } else
+        {
+            _destprops = destprops;
+        }
+        hostname = _destprops.getProperty("soap.hostname", "null");
+        port = _destprops.getProperty("soap.port", "null");
+        urlpath = _destprops.getProperty("soap.path", "null");
+        soapenvelope = _destprops.getProperty("soap.envelope", "null");
+        soapaction = _destprops.getProperty("soap.action", "null");
+        xmlData = new StringBuffer(soapenvelope);
+        replaceVariables(map);
+    }
+
+    public StringBuffer getXMLData()
+    {
+        return xmlData;
+    }
+
+    public StringBuffer getSoapMessage()
+    {
+        return soapMessage;
+    }
+
+    public String getSoapEnvelope()
+    {
+        return soapenvelope;
+    }
+
+    public void setXMLData(StringBuilder sb)
+    {
+        xmlData.delete(0, xmlData.length() - 1);
+        xmlData.append(sb);
+    }
+
+    public void replaceVariables(HashMap<String, String> vars)
+    {
+        if (vars == null)
+            return;
+        int ix = 0;
+        for (String var : vars.keySet())
+        {
+            while ((ix = xmlData.indexOf("@" + var.toUpperCase())) >= 0)
+            {
+                xmlData.replace(ix, ix + 1 + var.length(), vars.get(var));
+            }
+        }
+    }
+
+    public void replaceVariables(Properties varProps)
+    {
+        if (varProps == null)
+            return;
+        int ix = 0;
+        for (Object var : varProps.keySet())
+        {
+            while ((ix = xmlData.indexOf("@" + var)) >= 0)
+            {
+                xmlData.replace(ix, ix + 1 + var.toString().length(), varProps
+                        .get(var).toString());
+            }
+        }
+    }
+
+    public String sendSOAPMessage()
+    {
+
+        try
+        {
+            InetAddress addr = InetAddress.getByName(hostname);
+            Socket sock = new Socket(addr, Integer.parseInt(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("Content-Type: text/xml; charset=\"utf-8\"\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);
+            }
+            String msg = soapMessage.toString();
+            // Send data
+            wr.write(msg);
+            wr.flush();
+            wr.close();
+            return msg;
+        } catch (Exception ex)
+        {
+            // Drop any exception
+            return null;
+        }
+    }
+}

Added: 
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=956887&view=auto
==============================================================================
--- 
qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoServiceImplTest.java
 (added)
+++ 
qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoServiceImplTest.java
 Tue Jun 22 13:40:52 2010
@@ -0,0 +1,63 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.qpid.info.test;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.qpid.info.Info;
+import org.apache.qpid.info.InfoServiceImpl;
+
+import junit.framework.TestCase;
+
+/*
+ * This test verifies the invoke() method for the info service making sure 
that the parameters are returned
+ */
+public class InfoServiceImplTest extends TestCase
+{
+
+    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
+                .invoke("START");
+        assertNotNull(info);
+        Properties props = info.toProps();
+        assertNotNull(props);
+        List<String> infoProps = 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");
+        for (String tag : infoProps)
+        {
+            assertNotNull("Info.toProps() does not have the property: " + tag,
+                    props.getProperty(tag));
+        }
+    }
+
+}

Added: 
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=956887&view=auto
==============================================================================
--- 
qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/IniFileReaderTest.java
 (added)
+++ 
qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/IniFileReaderTest.java
 Tue Jun 22 13:40:52 2010
@@ -0,0 +1,91 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.qpid.info.test;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.qpid.info.util.IniFileReader;
+
+import junit.framework.TestCase;
+
+public class IniFileReaderTest extends TestCase
+{
+
+    public void testLoad()
+    {
+        IniFileReader ifr = new IniFileReader();
+        File iniFile = null;
+        try
+        {
+            iniFile = File.createTempFile("temp", "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");
+            writer.write("key1=val1\n");
+            writer.write("key2=val2\n");
+            writer.write("\n");
+            writer.write("#Section2 Comment\n");
+            writer.write("[Section2]\n");
+            writer.write("key3=val3\n");
+            writer.write("key4=val4\n");
+            writer.write("key5=val5\n");
+            writer.write("\n");
+            writer.write("[Section3]\n");
+            writer.write("key6=val6\n");
+            writer.write("key7=val7\n");
+            writer.write("\n");
+            writer.close();
+        } 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);
+        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"));
+    }
+
+
+}

Added: 
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=956887&view=auto
==============================================================================
--- 
qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SoapClientTest.java
 (added)
+++ 
qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SoapClientTest.java
 Tue Jun 22 13:40:52 2010
@@ -0,0 +1,159 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.qpid.info.test;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.util.ArrayList;
+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 = 9000;
+
+    private final String hostName = "localhost";
+
+    private final String urlPath = "/testSoap";
+
+    private ServerSocket server = null;
+
+    Thread socketAcceptor;
+
+    /*
+     * Generate a soap client from a custom URL, hostname, port and soap 
context
+     * path to be derived
+     */
+    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.envelope", "<ip>@IP</ip>");
+        destprops.setProperty("soap.action", "send");
+        HashMap<String, String> soapmap = new HashMap<String, String>();
+        soapmap.put("IP", "127.0.0.1");
+        return new SoapClient(soapmap, destprops);
+    }
+
+    /*
+     * A connection handler class that verifies the correct message is received
+     * 
+     */
+    class ConnectionHandler implements Runnable
+    {
+        private Socket socket;
+
+        public ConnectionHandler(Socket socket)
+        {
+            this.socket = socket;
+            Thread t = new Thread(this);
+            t.start();
+        }
+
+        public void run()
+        {
+            String line;
+            final List<String> response = new ArrayList<String>();
+            try
+            {
+                BufferedReader br = new BufferedReader(new InputStreamReader(
+                        socket.getInputStream()));
+                assertNotNull(br);
+                while ((line = br.readLine()) != null)
+                {
+                    response.add(line);
+                }
+                br.close();
+            } catch (Exception ex)
+            {
+                ex.printStackTrace();
+                fail("Exception while reading from the socket");
+            }
+            assertTrue(response.contains("<ip>127.0.0.1</ip>"));
+            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("User-Agent: Axis2"));
+        }
+
+    }
+
+    /*
+     * Test that the SOAP client sends the expected data to the socket We mock 
a
+     * simple SOAP envelope: <ip>127.0.0.1</ip>
+     */
+    public void testSoapClient() throws Exception
+    {
+        //
+        try
+        {
+            server = new ServerSocket(port);
+            assertNotNull(server);
+        } catch (Exception ex)
+        {
+            ex.printStackTrace();
+            fail("Unable to start the socket server");
+        }
+
+        socketAcceptor = new Thread()
+        {
+            public void run()
+            {
+                try
+                {
+                    Socket socket = server.accept();
+                    new ConnectionHandler(socket);
+                } catch (IOException e)
+                {
+                    e.printStackTrace();
+                }
+            }
+        };
+        socketAcceptor.start();
+        // Sleep for 1 second to allow the ServerSocket readiness
+        Thread.sleep(1000);
+        SoapClient sc = getSoapClient();
+        assertNotNull(sc);
+        sc.sendSOAPMessage();
+        socketAcceptor.join(2000);
+    }
+
+    public void testSoapClientFailure() throws Exception
+    {
+        SoapClient sc = new SoapClient(null, null);
+        assertNull("No response expected for the failure test", sc
+                .sendSOAPMessage());
+    }
+
+}

Added: 
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=956887&view=auto
==============================================================================
--- 
qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SystemInfoTest.java
 (added)
+++ 
qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SystemInfoTest.java
 Tue Jun 22 13:40:52 2010
@@ -0,0 +1,49 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.qpid.info.test;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.info.SystemInfo;
+
+public class SystemInfoTest extends TestCase
+{
+
+    public void testGetInfo()
+    {
+        Map<String, String> sysInfoMap = SystemInfo.getInfo();
+        assertNotNull("SystemInfo.getInfo() returned null", sysInfoMap);
+        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");
+        for (String tag : sysInfoProps)
+        {
+            assertNotNull("Map does not contain the tag: "+tag, 
sysInfoMap.get(tag));
+        }
+    }
+
+}



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

Reply via email to