diff options
Diffstat (limited to 'qpid/java/broker-plugins/experimental/info/src/test/java/org/apache')
9 files changed, 0 insertions, 1148 deletions
diff --git a/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/systest/InfoPluginTest.java b/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/systest/InfoPluginTest.java deleted file mode 100644 index 348e860d5f..0000000000 --- a/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/systest/InfoPluginTest.java +++ /dev/null @@ -1,277 +0,0 @@ -/* - * - * 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.systest; - -import org.apache.qpid.test.utils.QpidBrokerTestCase; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.ServerSocket; -import java.net.Socket; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -public class InfoPluginTest extends QpidBrokerTestCase -{ - private String QPID_HOME = null; - - private ServerSocket _server = null; - - 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.ini"; - - 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 _soapEnvelopeTail = "</soap:Envelope>"; - - private String _soapMessage1 = "@ACTION" + "-" + "@VERSION"; - - private String _soapMessage2 = "@VERSION" + "-" + "@ACTION"; - - private CountDownLatch _latch = new CountDownLatch(2); - - final List<List<String>> _recv = new ArrayList<List<String>>(); - - Thread _socketAcceptor; - - public void setUp() throws Exception - { - QPID_HOME = System.getProperty("QPID_HOME"); - if (QPID_HOME != null) - { - System.out.println("QPID_HOME=" + QPID_HOME); - } - else - { - fail("QPID_HOME not set"); - } - - startSoapServer(); - // Must start the server first to identify a free port. - createConfigFile(); - } - - 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(); - } - super.tearDown(); - } - - private void createConfigFile() - { - try - { - _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(CR); - writer.write(CR); - writer.write("[MSG1]"); - writer.write(CR); - writer.write("soap.path=/info1"); - writer.write(CR); - writer.write("soap.action=submitinfo1"); - writer.write(CR); - writer.write("soap.envelope=" + _soapEnvelopeHead + _soapMessage1 - + _soapEnvelopeTail); - writer.write(CR); - writer.write(CR); - writer.write("[MSG2]"); - writer.write(CR); - writer.write("soap.path=/info2"); - writer.write(CR); - writer.write("soap.action=submitinfo2"); - writer.write(CR); - 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) - { - fail("Unable to create the qpidinfo.properties due to: " - + e.getMessage()); - } - } - - private void startSoapServer() throws Exception - { - try - { - _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() - { - public void run() - { - while (true) - { - try - { - Socket socket = _server.accept(); - new ConnectionHandler(socket); - } - catch (IOException e) - { - fail("Error opening the socket in accept mode"); - } - } - } - }; - _socketAcceptor.start(); - System.out.println("*** Socket server started..."); - } - - class ConnectionHandler implements Runnable - { - private Socket _socket; - - public ConnectionHandler(Socket socket) - { - _socket = socket; - Thread t = new Thread(this); - t.start(); - } - - public void run() - { - System.out.println("*** Connection handler running..."); - List<String> buf = new ArrayList<String>(); - String line; - try - { - BufferedReader br = new BufferedReader(new InputStreamReader( - _socket.getInputStream())); - assertNotNull(br); - while ((line = br.readLine()) != null) - { - buf.add(line); - } - br.close(); - System.out.println("*** Received buffer: " + buf); - synchronized (_recv) - { - _recv.add(buf); - } - - System.out.println("*** Latch countdown"); - _latch.countDown(); - } - catch (Exception ex) - { - ex.printStackTrace(); - fail("Exception while reading from the socket"); - } - - } - - } - - public void testInfoPlugin() throws Exception - { - //Start the broker - super.setUp(); - if (!_latch.await(10, TimeUnit.SECONDS)) - { - fail("Timeout awaiting for the latch, upon startup"); - } - - validateResponses("STARTUP"); - - _recv.clear(); - _latch = new CountDownLatch(2); - - stopBroker(); - - if (!_latch.await(10, TimeUnit.SECONDS)) - { - fail("Timeout awaiting for the latch, upon 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:" + _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)); - } - -} diff --git a/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/HttpPosterTest.java b/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/HttpPosterTest.java deleted file mode 100644 index 4f76fea8ef..0000000000 --- a/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/HttpPosterTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * - * 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.List; -import java.util.Properties; - -import org.apache.qpid.info.util.HttpPoster; -import org.mortbay.jetty.testing.ServletTester; - -import junit.framework.TestCase; - -/* - * This test verifies that the plugin posts correctly to a webserver - * We use an embedded jetty container to mimic the webserver - */ -public class HttpPosterTest extends TestCase -{ - - private ServletTester tester; - - private String baseURL; - - private final String contextPath = "/info"; - - /* - * This method generates a dummy HttpPoster with a dummy body containing a - * single line. The url we are posting to can be controlled by the parameter - * url - * - * @param url - */ - private HttpPoster getHttpPoster(String url) - { - StringBuffer sb = new StringBuffer("test=TEST"); - Properties props = new Properties(); - props.put("http.url", url); - return new HttpPoster(props, sb); - } - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception - { - tester = new ServletTester(); - tester.setContextPath("/"); - tester.addServlet(InfoServlet.class, contextPath); - baseURL = tester.createSocketConnector(true); - tester.start(); - } - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#tearDown() - */ - protected void tearDown() throws Exception - { - super.tearDown(); - tester.stop(); - } - - /* - * This test is posting a string to an embedded Jetty Servlet and captures - * the response message. If the servlet receives the message ok, it will - * print Ok. A failure test is following where we post to a non-existent URL - */ - public void testHttpPoster() throws Exception - { - // Test HttpPoster posts correctly to the servlet - HttpPoster hp = getHttpPoster(baseURL + contextPath); - assertNotNull(hp); - hp.run(); - 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.get_response(); - assertTrue(response.size() == 0); - - } - -} diff --git a/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoServiceImplTest.java b/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoServiceImplTest.java deleted file mode 100644 index 9f359582a5..0000000000 --- a/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoServiceImplTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * - * 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/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoServlet.java b/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoServlet.java deleted file mode 100644 index 6b12a2d80c..0000000000 --- a/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoServlet.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * - * 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.PrintWriter; -import javax.servlet.GenericServlet; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; - -/* - * This is a servlet used by the embedded Jetty to be able to receive http post - * from the info plugin - */ - -public class InfoServlet extends GenericServlet -{ - private static final long serialVersionUID = 1L; - - @Override - public void service(ServletRequest request, ServletResponse response) - throws ServletException, IOException - { - String line; - BufferedReader in = request.getReader(); - while ((line = in.readLine()) != null) - { - System.out.println(line); - } - response.setContentType("text/html"); - PrintWriter out = response.getWriter(); - out.println("OK <br>\n"); - System.out.println("ServletResponse: OK"); - } - -}
\ No newline at end of file diff --git a/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoTest.java b/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoTest.java deleted file mode 100644 index bb4965ef1e..0000000000 --- a/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoTest.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * - * 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.HashMap; -import java.util.Properties; -import junit.framework.TestCase; -import org.apache.qpid.info.Info; - -/* - * This test verifies the toString(), toProps(), toXML() and toStringBuffer() methods of the Info object - * - */ -public class InfoTest extends TestCase -{ - private HashMap<String, String> _infoPayLoad = 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); - } - - /* - * Test the conversion toString() of the Info object - */ - public void testToString() - { - assertNotNull("toString() returned null", _info.toString()); - assertEquals("toString() did not return the proper string", - "test=Test\n", _info.toString()); - } - - /* - * Test the conversion toProps() of the Info object - */ - public void testToProps() - { - Properties props = new Properties(); - props.put("test", "Test"); - assertNotNull("toProperties() returned null", _info.toProps()); - assertEquals("toProperties not returned the proper object", props, _info - .toProps()); - } - - /* - * Test the conversion toStringBuffer() of the Info object - */ - public void testToStringBuffer() - { - StringBuffer sb = new StringBuffer("test=Test\n"); - assertNotNull(_info.toStringBuffer()); - assertEquals(sb.toString(), _info.toStringBuffer().toString()); - } - - /* - * Test conversion toXML() of the info object - */ - public void testToXML() - { - String INDENT = " "; - StringBuffer sb = new StringBuffer(); - sb.append("<?xml version=\"1.0\"?>\n"); - sb.append("<qpidinfo>\n"); - sb.append("<test>\n"); - sb.append(INDENT + "Test\n"); - sb.append("</test>\n"); - sb.append("</qpidinfo>\n"); - assertEquals("toString() does not return the proper string", _info - .toXML().toString(), sb.toString()); - } - - /* - * Test the conversion toMap() of the Info object - */ - public void testToMap() - { - 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", - thm.containsKey("test")); - assertTrue( - "toMap() returned a map not containing the value for key test: Test", - thm.containsValue("Test")); - - } - -} diff --git a/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/IniFileReaderTest.java b/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/IniFileReaderTest.java deleted file mode 100644 index 77ecaa2176..0000000000 --- a/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/IniFileReaderTest.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * - * 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 junit.framework.TestCase; -import org.apache.qpid.info.util.IniFileReader; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.util.Map; -import java.util.Properties; - -/** - * Test the Loading of the ini file reader by first writing - * out a correct ini file. - */ -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] # 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"); - 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")); - } - - /** - * 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()); - } - - } - -} diff --git a/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SoapClientTest.java b/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SoapClientTest.java deleted file mode 100644 index a3d993a39f..0000000000 --- a/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SoapClientTest.java +++ /dev/null @@ -1,208 +0,0 @@ -/* - * - * 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 junit.framework.TestCase; -import org.apache.qpid.info.util.SoapClient; - -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; - -public class SoapClientTest extends TestCase -{ - - private int _port; - - private final String _hostName = "localhost"; - - private final String _urlPath = "/testSoap"; - - private ServerSocket _server = null; - - /* - * 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" + _port)); - 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(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"); - } - - Thread _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); - - assertFalse("Socket Acceptor not stopped.", _socketAcceptor.isAlive()); - } - - /** - * 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=@IP><port=@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()); - } - - /** - * 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>(); - - /// 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())); - } - -} diff --git a/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SystemInfoTest.java b/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SystemInfoTest.java deleted file mode 100644 index 6cb8e3a90a..0000000000 --- a/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SystemInfoTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * - * 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 junit.framework.TestCase; -import org.apache.qpid.info.SystemInfo; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -/** 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", - "java.vm.name", "java.class.version", "os.arch", "os.name", - "os.version", "sun.arch.data.model", "user.dir", "user.name", - "user.timezone", "hostname", "ip", "CPUCores", "Maximum_Memory", - "Free_Memory"); - - for (String tag : sysInfoProps) - { - assertNotNull("Map does not contain the tag: " + tag, sysInfoMap.get(tag)); - } - } - -}
\ No newline at end of file diff --git a/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/XMLWriterTest.java b/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/XMLWriterTest.java deleted file mode 100644 index f352226361..0000000000 --- a/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/XMLWriterTest.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * - * 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 junit.framework.TestCase; -import org.apache.qpid.info.util.XMLWriter; - -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() - { - StringBuffer input = new StringBuffer("Test"); - xw = new XMLWriter(input); - assertNotNull("XMLWriter could not instantiate", xw); - 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()); - } - - /** Test tag created and written correctly */ - public void testWriteTag() - { - 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" + 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()); - } - - /** 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", "<test1 id=\"1\">\n", xw.getXML().toString()); - } - - /** Test Close Tag is correctly written */ - public void testWriteCloseTag() - { - xw = new XMLWriter(new StringBuffer()); - assertNotNull(xw); - xw.writeCloseTag("test"); - assertEquals("</test>\n", xw.getXML().toString()); - } - -} |