From 5951dfafe74a4115ef22dbb5d5d9b8c455bde0f5 Mon Sep 17 00:00:00 2001 From: Martin Ritchie Date: Tue, 22 Jun 2010 13:41:24 +0000 Subject: QPID-2555 : Modified the MANIFEST to include org.apache.qpid.common and org.apache.qpid.server.registry Patch provided by Sorin Suciu git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@956888 13f79535-47bb-0310-9956-ffa450edef68 --- java/broker-plugins/experimental/info/MANIFEST.MF | 4 +- .../main/java/org/apache/qpid/info/Activator.java | 196 ++++++++++++++++++--- .../org/apache/qpid/info/BrokerInfoService.java | 27 --- .../apache/qpid/info/BrokerInfoServiceImpl.java | 120 ------------- .../src/main/java/org/apache/qpid/info/Info.java | 64 +++++-- .../java/org/apache/qpid/info/util/HttpPoster.java | 124 ++++++++----- .../org/apache/qpid/info/test/ActivatorTest.java | 56 ------ .../qpid/info/test/BrokerInfoServiceImplTest.java | 66 ------- .../org/apache/qpid/info/test/HttpPosterTest.java | 59 +++++-- .../org/apache/qpid/info/test/InfoServlet.java | 11 +- .../java/org/apache/qpid/info/test/InfoTest.java | 70 +++++--- .../org/apache/qpid/info/test/XMLWriterTest.java | 35 ++-- .../apache/qpid/server/plugins/PluginManager.java | 1 + 13 files changed, 399 insertions(+), 434 deletions(-) delete mode 100644 java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/BrokerInfoService.java delete mode 100644 java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/BrokerInfoServiceImpl.java delete mode 100644 java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/ActivatorTest.java delete mode 100644 java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/BrokerInfoServiceImplTest.java (limited to 'java') diff --git a/java/broker-plugins/experimental/info/MANIFEST.MF b/java/broker-plugins/experimental/info/MANIFEST.MF index dabafe8305..0ffa869ea9 100644 --- a/java/broker-plugins/experimental/info/MANIFEST.MF +++ b/java/broker-plugins/experimental/info/MANIFEST.MF @@ -5,7 +5,9 @@ Bundle-SymbolicName: qpid_info_plugin;singleton:=true Bundle-Version: 1.0.0 Bundle-Activator: org.apache.qpid.info.Activator Import-Package: org.apache.qpid.server.configuration, - org.osgi.framework + org.osgi.framework, + org.apache.qpid.common, + org.apache.qpid.server.registry Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ClassPath: . Bundle-ActivationPolicy: lazy diff --git a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Activator.java b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Activator.java index 167a53fdc5..a442cf1f28 100644 --- a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Activator.java +++ b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Activator.java @@ -19,60 +19,204 @@ * */ -/** - * - * @author sorin - * - * Activator class for the tracking services - */ - package org.apache.qpid.info; import java.io.File; -import java.io.FileInputStream; +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 + * + */ public class Activator implements BundleActivator { + private final List soapPropList = Arrays.asList("soap.hostname", + "soap.port", "soap.path", "soap.action", "soap.envelope"); + + private final List httpPropList = Arrays.asList("http.url", + "http.envelope"); + + InfoServiceImpl service = null; + BundleContext _ctx = null; + Map infoprops = new HashMap(); + + /** + * Start bundle method + * + * @param ctx + * the bundle context + */ public void start(BundleContext ctx) throws Exception { if (null != ctx) { - BrokerInfoServiceImpl service = new BrokerInfoServiceImpl(ctx); - ctx.registerService(BrokerInfoService.class.getName(), service, - null); _ctx = ctx; - HttpPoster hp; - try - { - Properties props = new Properties(); - String QPID_WORK = System.getenv("QPID_WORK"); - props.load(new FileInputStream(QPID_WORK + File.separator - + "etc" + File.separator + "qpidinfo.properties")); - hp = new HttpPoster(props, service.invoke().toXML()); - hp.run(); - } catch (Exception ex) - { - // Silently drop any exception - } + 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 + */ public void stop(BundleContext ctx) throws Exception { - // no need to do anything here, osgi will unregister the service for us + sendInfo("SHUTDOWN"); + } + + /** + * Sends the information message + * + * @param action + * label that identifies if we are starting up or shutting down + */ + private void sendInfo(String action) + { + if ((null == _ctx) && (null == service)) + { + // invalid state + return; + } + + IniFileReader ifr = new IniFileReader(); + try + { + String QPID_HOME = System.getProperty("QPID_HOME"); + String cfgFilePath = QPID_HOME + File.separator + "etc" + + File.separator + "qpidinfo.properties"; + ifr.load(cfgFilePath); + } catch (Exception ex) + { + // drop the exception + return; + } + + // If we have no sections, something has gone really wrong, abort + if (ifr.getSections().size() == 0) + return; + + Info> 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 + */ + private void sendMessages(String protocol, IniFileReader ifr, + Info> info) + { + if (null != protocol) + { + // Set the global properties first (as they are the defaults) + Properties defaultProps = ifr.getSections().get(""); + if (protocol.toLowerCase().startsWith("http")) + { + for (String section : ifr.getSections().keySet()) + { + // Skip the defaults + if (section.equals("")) + continue; + Properties props = new Properties(); + props.putAll(defaultProps); + props.putAll(ifr.getSections().get(section)); + if (isValid(protocol, props)) + { + new HttpPoster(props, info.toXML()).run(); + } + } + + } else if (protocol.toLowerCase().startsWith("soap")) + { + for (String section : ifr.getSections().keySet()) + { + Properties props = new Properties(); + props.putAll(defaultProps); + props.putAll(ifr.getSections().get(section)); + if (isValid(protocol, props)) + { + new SoapClient(info.toMap(), props).sendSOAPMessage(); + } + } + } + } 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 + */ + private boolean isValid(String protocol, Properties props) + { + if (null == protocol) + return false; + String value = ""; + if (protocol.toLowerCase().startsWith("http")) + { + for (String prop : httpPropList) + { + if (null == props.get(prop)) + return false; + } + return true; + } + + if (protocol.toLowerCase().startsWith("soap")) + { + for (String prop : soapPropList) + { + value = props.getProperty(prop); + if (null == value) + { + return false; + } + } + return true; + } + return false; } +} // end class -} diff --git a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/BrokerInfoService.java b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/BrokerInfoService.java deleted file mode 100644 index 4c3c95d385..0000000000 --- a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/BrokerInfoService.java +++ /dev/null @@ -1,27 +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; - -public interface BrokerInfoService -{ - public Info invoke(); -} diff --git a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/BrokerInfoServiceImpl.java b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/BrokerInfoServiceImpl.java deleted file mode 100644 index fe10d55dea..0000000000 --- a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/BrokerInfoServiceImpl.java +++ /dev/null @@ -1,120 +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. - * - */ - -/** - * - * @author sorin - * - * Implementation for Info service - */ - -package org.apache.qpid.info; - -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.SortedMap; -import java.util.TreeMap; -import java.util.Map.Entry; - -import org.apache.qpid.server.configuration.ServerConfiguration; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; - -public class BrokerInfoServiceImpl implements BrokerInfoService -{ - - SortedMap brokerInfoMap = new TreeMap(); - - private final List qpidProps = Arrays.asList("QPID_HOME", - "QPID_WORK", "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"); - - private final BundleContext _ctx; - - public BrokerInfoServiceImpl(BundleContext ctx) - { - _ctx = ctx; - } - - public Info> invoke() - { - // Get current time - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ"); - brokerInfoMap.put("time", sdf.format(Calendar.getInstance().getTime())); - // Get the hostname - try - { - InetAddress addr = InetAddress.getLocalHost(); - String hostname = addr.getHostName(); - brokerInfoMap.put("hostname", hostname); - brokerInfoMap.put("ip", addr.getHostAddress()); - } catch (UnknownHostException e) - { - // - } - // Dump system props - Properties sysprops = System.getProperties(); - String propName; - for (Iterator> it = sysprops.entrySet() - .iterator(); it.hasNext();) - { - Entry en = it.next(); - propName = en.getKey().toString(); - if (qpidProps.indexOf(propName) >= 0) - { - brokerInfoMap.put(propName, en.getValue().toString()); - } - } - - if (null == _ctx) - { - return new Info>(brokerInfoMap); - } - - ServiceReference sref; - ServerConfiguration sc; - try - { - sref = _ctx - .getServiceReference(ServerConfiguration.class.getName()); - sc = (ServerConfiguration) _ctx.getService(sref); - if (null != sc) - { - brokerInfoMap.put("port", sc.getPorts().toString()); - } - } - catch (Exception e) - { - return new Info>(brokerInfoMap); - } - - return new Info>(brokerInfoMap); - } - -} diff --git a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Info.java b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Info.java index e4d33817a1..2c6db8df12 100644 --- a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Info.java +++ b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Info.java @@ -35,15 +35,24 @@ 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 + */ public class Info> { private T _info; + /** + * Constructor. + * @param info instantiates the object with a Map + */ public Info(T info) { _info = info; } + @Override public String toString() { String result = ""; @@ -55,21 +64,25 @@ public class Info> return result; } - public Properties toProps() - { + /** + * Renders Info map to a property object + * @return A Properties object representing the Info map + */ + public Properties toProps() { Properties props = new Properties(); - if (null == _info) - return null; - for (Iterator it = _info.keySet().iterator(); it.hasNext();) - { - String key = it.next(); - props.put(key, _info.get(key)); + if (null==_info) return null; + for (Iterator it = _info.keySet().iterator(); it.hasNext();) { + String key = it.next(); + props.put(key, _info.get(key)); } return props; } - - public StringBuffer toStringBuffer() - { + + /** + * Renders Info map to a StringBuffer + * @return A StringBuffer object representing the Info map + */ + public StringBuffer toStringBuffer() { StringBuffer sb = new StringBuffer(); for (Iterator it = _info.keySet().iterator(); it.hasNext();) { @@ -78,22 +91,39 @@ public class Info> } return sb; } - - public StringBuffer toXML() + + /** + * 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() { XMLWriter xw = new XMLWriter(new StringBuffer()); xw.writeXMLHeader(); Map attr = new HashMap(); xw.writeOpenTag("qpidinfo", attr); String key; - for (Iterator it = _info.keySet().iterator(); it.hasNext();) - { + for (Iterator 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 + */ + public HashMap toMap() { + String key; + HashMap infoMap = new HashMap(); + for (Iterator it = _info.keySet().iterator(); it.hasNext();) { + key = it.next(); + infoMap.put(key, _info.get(key).toString()); + } + return infoMap; + } } diff --git a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/HttpPoster.java b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/HttpPoster.java index c67a7682f3..d07f34dec0 100644 --- a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/HttpPoster.java +++ b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/HttpPoster.java @@ -36,62 +36,92 @@ import java.util.Properties; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.OutputStreamWriter; +import java.net.InetAddress; import java.net.URL; import java.net.URLConnection; +import java.net.UnknownHostException; + +public class HttpPoster implements Runnable +{ + private final String url; + + private final Hashtable header; -public class HttpPoster implements Runnable { - private final String url; - private final Hashtable header; private final List response = new ArrayList(); - private final StringBuffer _buf; - // - public HttpPoster(Properties props, StringBuffer buf) + + private final StringBuffer _buf; + + /** + * Constructor + * @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(); + try + { + String hostname = InetAddress.getLocalHost().getHostName(); + header.put("hostname", hostname); + } catch (UnknownHostException e) + { + // Silently ignoring the error ;) + } + } else + { + url = null; + header = null; + } + } + /** + * Posts the message from the _buf StringBuffer to the http server + */ + public void run() { - _buf = buf; - if (null!= props) { - url = props.getProperty("URL"); - header = new Hashtable(); - String hostname = props.getProperty("hostname"); - if (null!= hostname) header.put("hostname", hostname); - } else { - url = null; - header = null; - } - } - // - @Override - public void run() + if (null == url) + return; + String line; + URL urlDest; + URLConnection urlConn; + try { - if (null==url) return; - String line; - URL urlDest; - URLConnection urlConn; - try { - urlDest = new URL(url); - urlConn = urlDest.openConnection(); - urlConn.setDoOutput(true); - urlConn.setUseCaches(false); - for (Iterator it=header.keySet().iterator(); it.hasNext();) { - String prop = (String)it.next(); - urlConn.setRequestProperty(prop, header.get(prop)); - } - OutputStreamWriter wr = new OutputStreamWriter(urlConn.getOutputStream()); + urlDest = new URL(url); + urlConn = urlDest.openConnection(); + urlConn.setDoOutput(true); + urlConn.setUseCaches(false); + for (Iterator it = header.keySet().iterator(); it.hasNext();) + { + String prop = (String) it.next(); + urlConn.setRequestProperty(prop, header.get(prop)); + } + OutputStreamWriter wr = new OutputStreamWriter(urlConn + .getOutputStream()); wr.write(_buf.toString()); wr.flush(); // Get the response - BufferedReader rd = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); - while ((line = rd.readLine()) != null) { + BufferedReader rd = new BufferedReader(new InputStreamReader( + urlConn.getInputStream())); + while ((line = rd.readLine()) != null) + { response.add(line); - } - } catch (Exception ex) { - return; - } - } - - public List getResponse() + } + } catch (Exception ex) { - return response; - } - -} + return; + } + } + + /** + * Retrieves the response from the http server + * @return List response received from the http server + */ + public List getResponse() + { + return response; + } +} diff --git a/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/ActivatorTest.java b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/ActivatorTest.java deleted file mode 100644 index 69d569797e..0000000000 --- a/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/ActivatorTest.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.Activator; - -/* - * This test verifies whether the activator for the info service is starting Ok. - */ -public class ActivatorTest extends TestCase -{ - private Activator activator; - - protected void setUp() throws Exception - { - super.setUp(); - activator = new Activator(); - activator.start(null); - } - - protected void tearDown() throws Exception - { - super.tearDown(); - activator = null; - } - - public void testStart() - { - assertNotNull(activator); - } - - public void testGetBundleContext() - { - assertEquals(activator.getBundleContext(), null); - } - -} diff --git a/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/BrokerInfoServiceImplTest.java b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/BrokerInfoServiceImplTest.java deleted file mode 100644 index 1eaa491603..0000000000 --- a/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/BrokerInfoServiceImplTest.java +++ /dev/null @@ -1,66 +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.BrokerInfoServiceImpl; -import org.apache.qpid.info.Info; -import junit.framework.TestCase; - -/* - * This test verifies the invoke() method for the info service making sure that the parameters are returned - */ -public class BrokerInfoServiceImplTest extends TestCase -{ - - BrokerInfoServiceImpl bisi = null; - - public void testBrokerInfoServiceImpl() - { - bisi = new BrokerInfoServiceImpl(null); - assertNotNull(bisi); - } - - @SuppressWarnings("unchecked") - public void testInvoke() - { - bisi = new BrokerInfoServiceImpl(null); - assertNotNull(bisi); - Info> info = (Info>) bisi - .invoke(); - assertNotNull(info); - Properties props = info.toProps(); - assertNotNull(props); - List qpidProps = 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 : qpidProps) - { - assertNotNull(props.getProperty(tag)); - } - } - -} diff --git a/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/HttpPosterTest.java b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/HttpPosterTest.java index bb0ee9d259..6be421dd7d 100644 --- a/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/HttpPosterTest.java +++ b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/HttpPosterTest.java @@ -35,52 +35,73 @@ import junit.framework.TestCase; public class HttpPosterTest extends TestCase { - private HttpPoster hp; - - private Properties props; - - private StringBuffer sb; - private ServletTester tester; private String baseURL; private final String contextPath = "/info"; - protected void setUp() throws Exception + /* + * 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) { - super.setUp(); + 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(); - // - props = new Properties(); - props.put("URL", baseURL + contextPath); - props.put("hostname", "localhost"); - sb = new StringBuffer("test=TEST"); - hp = new HttpPoster(props, sb); - } + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#tearDown() + */ protected void tearDown() throws Exception { super.tearDown(); - hp = null; - props = null; - sb = null; tester.stop(); } - public void testHttpPoster() + /* + * 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 response = hp.getResponse(); assertTrue(response.size() > 0); assertEquals("OK
", response.get(0).toString()); + + // Failure Test + hp = getHttpPoster("http://localhost/nonexistent"); + hp.run(); + response = hp.getResponse(); + assertTrue(response.size() == 0); + } } diff --git a/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoServlet.java b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoServlet.java index 075013f912..6b12a2d80c 100644 --- a/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoServlet.java +++ b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoServlet.java @@ -1,5 +1,5 @@ /* - * + * * 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 @@ -7,17 +7,18 @@ * 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; @@ -53,4 +54,4 @@ public class InfoServlet extends GenericServlet System.out.println("ServletResponse: OK"); } -} +} \ No newline at end of file diff --git a/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoTest.java b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoTest.java index 2e9ac9a779..da3d844491 100644 --- a/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoTest.java +++ b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoTest.java @@ -1,5 +1,5 @@ /* - * + * * 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 @@ -7,17 +7,18 @@ * 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; @@ -39,6 +40,8 @@ public class InfoTest extends TestCase { super.setUp(); infoPayLoad = new HashMap(); + infoPayLoad.put("test", "Test"); + info = new Info>(infoPayLoad); } protected void tearDown() throws Exception @@ -48,48 +51,44 @@ public class InfoTest extends TestCase infoPayLoad = null; } - public void testInfo() - { - info = new Info>(infoPayLoad); - assertNotNull(info); - } - + /* + * Test the conversion toString() of the Info object + */ public void testToString() { - infoPayLoad.clear(); - infoPayLoad.put("test", "Test"); - info = new Info>(infoPayLoad); - assertNotNull(info.toString()); - assertEquals("test=Test\n", info.toString()); + 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"); - infoPayLoad.clear(); - infoPayLoad.put("test", "Test"); - info = new Info>(infoPayLoad); - assertNotNull(info.toProps()); - assertEquals(props, info.toProps()); + 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"); - infoPayLoad.clear(); - infoPayLoad.put("test", "Test"); - info = new Info>(infoPayLoad); assertNotNull(info.toStringBuffer()); assertEquals(sb.toString(), info.toStringBuffer().toString()); } + /* + * Test conversion toXML() of the info object + */ public void testToXML() { String INDEND = " "; - infoPayLoad.clear(); - infoPayLoad.put("test", "Test"); - info = new Info>(infoPayLoad); StringBuffer sb = new StringBuffer(); sb.append("\n"); sb.append("\n"); @@ -97,7 +96,24 @@ public class InfoTest extends TestCase sb.append(INDEND + "Test\n"); sb.append("\n"); sb.append("\n"); - assertEquals(info.toXML().toString(), sb.toString()); + 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 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/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/XMLWriterTest.java b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/XMLWriterTest.java index 980e6dfa56..f3e2e1d55d 100644 --- a/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/XMLWriterTest.java +++ b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/XMLWriterTest.java @@ -1,5 +1,5 @@ /* - * + * * 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 @@ -7,17 +7,18 @@ * 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; @@ -34,23 +35,11 @@ public class XMLWriterTest extends TestCase private XMLWriter xw = null; - protected void setUp() throws Exception - { - super.setUp(); - - } - - protected void tearDown() throws Exception - { - super.tearDown(); - - } - public void testXMLWriter() { xw = new XMLWriter(new StringBuffer("Test")); - assertNotNull(xw); - assertEquals("Test", xw.getXML().toString()); + assertNotNull("XMLWriter could not instantiate", xw); + assertEquals("XMLWriter.toString() failed","Test", xw.getXML().toString()); } public void testWriteXMLHeader() @@ -58,16 +47,16 @@ public class XMLWriterTest extends TestCase xw = new XMLWriter(new StringBuffer()); assertNotNull(xw); xw.writeXMLHeader(); - assertEquals("\n", xw.getXML().toString()); + assertEquals("XMLWriter.writeXMLHeader(...) failed","\n", xw.getXML().toString()); } public void testWriteTag() { String INDEND = " "; xw = new XMLWriter(new StringBuffer()); - assertNotNull(xw); + assertNotNull("XMLWriter could not instantiate", xw); xw.writeTag("test", new HashMap(), "TEST"); - assertEquals("\n" + INDEND + "TEST\n" + "\n", xw.getXML() + assertEquals("XMLWriter.writeTag(...) failed","\n" + INDEND + "TEST\n" + "\n", xw.getXML() .toString()); } @@ -77,10 +66,10 @@ public class XMLWriterTest extends TestCase assertNotNull(xw); HashMap attr = new HashMap(); xw.writeOpenTag("test", attr); - assertEquals("\n", xw.getXML().toString()); + assertEquals("XMLWriter.writeOpenTag(...) failed","\n", xw.getXML().toString()); attr.put("id", "1"); xw.writeOpenTag("test1", attr); - assertEquals("\n" + "\n", xw.getXML().toString()); + assertEquals("XMLWriter.writeOpenTag(...) failed","\n" + "\n", xw.getXML().toString()); } public void testWriteCloseTag() diff --git a/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java b/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java index 62d8f87641..93f0a6bc37 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java +++ b/java/broker/src/main/java/org/apache/qpid/server/plugins/PluginManager.java @@ -114,6 +114,7 @@ public class PluginManager implements Closeable "org.osgi.util.tracker; version=1.0.0," + "org.apache.qpid.junit.extensions.util; version=0.7," + "org.apache.qpid; version=0.7," + + "org.apache.qpid.common; version=0.7," + "org.apache.qpid.exchange; version=0.7," + "org.apache.qpid.framing; version=0.7," + "org.apache.qpid.protocol; version=0.7," + -- cgit v1.2.1