[jboss-svn-commits] JBL Code SVN: r7377 - labs/jbossesb/workspace/jokum/qa/junit/src/org/jboss/soa/esb/listeners/message
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Nov 3 14:27:08 EST 2006
Author: jokum
Date: 2006-11-03 14:27:05 -0500 (Fri, 03 Nov 2006)
New Revision: 7377
Added:
labs/jbossesb/workspace/jokum/qa/junit/src/org/jboss/soa/esb/listeners/message/HttpListenerConfig.xml
labs/jbossesb/workspace/jokum/qa/junit/src/org/jboss/soa/esb/listeners/message/HttpListenerTest.java
labs/jbossesb/workspace/jokum/qa/junit/src/org/jboss/soa/esb/listeners/message/MessageBox.java
Log:
HttpListener QA test added
Added: labs/jbossesb/workspace/jokum/qa/junit/src/org/jboss/soa/esb/listeners/message/HttpListenerConfig.xml
===================================================================
--- labs/jbossesb/workspace/jokum/qa/junit/src/org/jboss/soa/esb/listeners/message/HttpListenerConfig.xml 2006-11-03 19:26:59 UTC (rev 7376)
+++ labs/jbossesb/workspace/jokum/qa/junit/src/org/jboss/soa/esb/listeners/message/HttpListenerConfig.xml 2006-11-03 19:27:05 UTC (rev 7377)
@@ -0,0 +1,13 @@
+<JBossESB parameterReloadSecs="60000"
+ commandConnFactoryClass="ConnectionFactory"
+ commandJndiType="jboss"
+ commandJndiURL="localhost"
+ commandIsTopic="false"
+ messageSelector="gpMsgSelector='HttpListener'"
+ commandJndiName="queue/A"
+ >
+
+ <HttpListenerTest listenerClass="org.jboss.soa.esb.listeners.message.HttpListener" maxThreads="10">
+ <action class="org.jboss.soa.esb.listeners.message.MessageBox" />
+ </HttpListenerTest>
+</JBossESB>
\ No newline at end of file
Added: labs/jbossesb/workspace/jokum/qa/junit/src/org/jboss/soa/esb/listeners/message/HttpListenerTest.java
===================================================================
--- labs/jbossesb/workspace/jokum/qa/junit/src/org/jboss/soa/esb/listeners/message/HttpListenerTest.java 2006-11-03 19:26:59 UTC (rev 7376)
+++ labs/jbossesb/workspace/jokum/qa/junit/src/org/jboss/soa/esb/listeners/message/HttpListenerTest.java 2006-11-03 19:27:05 UTC (rev 7377)
@@ -0,0 +1,88 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.soa.esb.listeners.message;
+
+import junit.framework.TestCase;
+
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.helpers.KeyValuePair;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+import org.jboss.soa.esb.message.format.MessageType;
+import org.jboss.soa.esb.util.ClassUtils;
+import org.jboss.soa.esb.util.JMSClientUtil;
+import org.jboss.soa.esb.util.NewListenerUtils;
+
+/**
+ * QA Tests for the JmsQueueListener.
+ *
+ */
+public class HttpListenerTest extends TestCase {
+
+ private NewListenerUtils.ListenersManagerExecThread listenersMgr;
+
+ protected void setUp() throws Exception {
+ // Start the listener...
+ listenersMgr = NewListenerUtils.startListeners(ClassUtils.toResourcePath(getClass().getPackage()) + "/HttpListenerConfig.xml");
+ }
+
+ public void test() throws Throwable {
+ // There should have been no exceptions...
+ listenersMgr.assertNotInException();
+
+ MessageBox.messages.clear();
+
+ // Check did the messagebox recevive the message from the JMSListener...
+ MessageBox.assertMessageCount(0, 10000);
+
+ String locatorURI = "http://localhost:5400";
+ InvokerLocator locator = new InvokerLocator(locatorURI);
+
+ Client remotingClient = new Client(locator);
+ remotingClient.connect();
+
+ String payload = "Hello is anyone there?";
+
+ // Message creation...
+ Message msg = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
+ ActionUtils.setTaskObject(msg,payload);
+
+ remotingClient.invoke(msg, null);
+
+ // Check did the messagebox recevive the message from the JMSListener...
+ MessageBox.assertMessageCount(1, 10000);
+
+ //Send a Shutdown message to the command queue...
+ JMSClientUtil.sendMessageToQueue("shutdown", JMSClientUtil.QUEUE.A, new KeyValuePair[] {new KeyValuePair("gpMsgSelector", "HttpListener")});
+ listenersMgr.assertShutdownOK(10000);
+
+ // There should have been no exceptions...
+ listenersMgr.assertNotInException();
+
+ }
+
+ protected void tearDown() throws Exception {
+ }
+}
Added: labs/jbossesb/workspace/jokum/qa/junit/src/org/jboss/soa/esb/listeners/message/MessageBox.java
===================================================================
--- labs/jbossesb/workspace/jokum/qa/junit/src/org/jboss/soa/esb/listeners/message/MessageBox.java 2006-11-03 19:26:59 UTC (rev 7376)
+++ labs/jbossesb/workspace/jokum/qa/junit/src/org/jboss/soa/esb/listeners/message/MessageBox.java 2006-11-03 19:27:05 UTC (rev 7377)
@@ -0,0 +1,96 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.listeners.message;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Vector;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.actions.ActionProcessingException;
+import org.jboss.soa.esb.actions.ActionProcessor;
+import org.jboss.soa.esb.actions.ActionUtils;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+
+/**
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ * @since Version 4.0
+ */
+public class MessageBox implements ActionProcessor {
+
+ private static Logger logger = Logger.getLogger(MessageBox.class);
+ public static List<Object> messages = new Vector<Object>();
+
+ public MessageBox(ConfigTree configTree){
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#process(java.lang.Object)
+ */
+ public Message process(Message message) throws ActionProcessingException {
+ Object oCurr = ActionUtils.getTaskObject(message);
+ if (null==oCurr)
+ oCurr="<null>";
+ logger.info("MessageBox received message: " + message);
+ messages.add(oCurr);
+ return message;
+ }
+
+ public static void assertMessageCount(int count, long maxWait) {
+ long endTime = System.currentTimeMillis() + maxWait;
+
+ while(System.currentTimeMillis() < endTime) {
+ if(messages.size() == count) {
+ return;
+ }
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ logger.error("Thread interupt...", e);
+ }
+ }
+ String errorMsg = "MessageBox failed to receive " + count + " messages. Message count = " + messages.size() + ". Waited for " + maxWait + "ms.";
+ logger.error(errorMsg);
+ TestCase.fail(errorMsg);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#getOkNotification(java.lang.Object)
+ */
+ public Serializable getOkNotification(Message message) {
+ return "OK" + ActionUtils.getTaskObject(message);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.actions.ActionProcessor#getErrorNotification(java.lang.Object)
+ */
+ public Serializable getErrorNotification(Message message) {
+ return "Error" + ActionUtils.getTaskObject(message);
+ }
+
+}
More information about the jboss-svn-commits
mailing list