diff options
| author | Martin Ritchie <ritchiem@apache.org> | 2010-06-22 13:40:52 +0000 |
|---|---|---|
| committer | Martin Ritchie <ritchiem@apache.org> | 2010-06-22 13:40:52 +0000 |
| commit | 571c08285a95a1fb810309f19ceca2107054f12d (patch) | |
| tree | cc41a290d3f6afe40bfd306906aa9f735c4dbe7e /java/broker-plugins/experimental/info/src/test | |
| parent | a49decc7d56bdb704a5d1580058c0da57e9a9353 (diff) | |
| download | qpid-python-571c08285a95a1fb810309f19ceca2107054f12d.tar.gz | |
QPID-2555 : Improvements on info plugin, using SOAP
Patch provided by Sorin Suciu
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@956887 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/broker-plugins/experimental/info/src/test')
4 files changed, 362 insertions, 0 deletions
diff --git a/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoServiceImplTest.java b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoServiceImplTest.java new file mode 100644 index 0000000000..2de3f4841b --- /dev/null +++ b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoServiceImplTest.java @@ -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)); + } + } + +} diff --git a/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/IniFileReaderTest.java b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/IniFileReaderTest.java new file mode 100644 index 0000000000..626102c68d --- /dev/null +++ b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/IniFileReaderTest.java @@ -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")); + } + + +} diff --git a/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SoapClientTest.java b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SoapClientTest.java new file mode 100644 index 0000000000..5c7276456c --- /dev/null +++ b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SoapClientTest.java @@ -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()); + } + +} diff --git a/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SystemInfoTest.java b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SystemInfoTest.java new file mode 100644 index 0000000000..092ea630eb --- /dev/null +++ b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SystemInfoTest.java @@ -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)); + } + } + +} |
