[jboss-svn-commits] JBL Code SVN: r5379 - in labs/jbossesb/trunk/product/core/common: src/org/jboss/soa/esb/notification src/org/jboss/soa/esb/services tests/src/org/jboss/soa/esb/notification

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Aug 1 10:25:30 EDT 2006


Author: tfennelly
Date: 2006-08-01 10:25:23 -0400 (Tue, 01 Aug 2006)
New Revision: 5379

Added:
   labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/notification/NotifyUtilUnitTest.java
Modified:
   labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotifyUtil.java
   labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/services/InotificationHandler.java
Log:
added tests for NotifyUtil

Modified: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotifyUtil.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotifyUtil.java	2006-08-01 14:16:35 UTC (rev 5378)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotifyUtil.java	2006-08-01 14:25:23 UTC (rev 5379)
@@ -33,8 +33,7 @@
 	public static void notifyOK(InotificationHandler p_oNH,
 			DomElement p_oParent, Serializable p_o, Map p_oCtx) {
 		try {
-			DomElement[] oaP = p_oParent
-					.getElementChildren(NotificationList.ELEMENT);
+			DomElement[] oaP = p_oParent.getElementChildren(NotificationList.ELEMENT);
 			for (int i1 = 0; i1 < oaP.length; i1++) {
 				NotificationList oCurr = new NotificationList(oaP[i1]);
 				if (!oCurr.isOK())
@@ -54,14 +53,20 @@
 		PrintStream oPS = new PrintStream(oBO);
 		try {
 			oPS.println(p_o.toString());
-			if (null != p_e)
+			if (null != p_e) {
 				p_e.printStackTrace(oPS);
+			}
 			oPS.close();
 
 			String sMsg = oBO.toString();
-			DomElement[] oaP = p_oParent
-					.getElementChildren(NotificationList.ELEMENT);
+			DomElement[] oaP = p_oParent.getElementChildren(NotificationList.ELEMENT);
 			// if (oaP.length<1) // Uncomment this line to send only to the list
+			
+			// REVIEW: What's going on here?  What's the difference between sending an
+			// error notification and sending a regular notification apart from there being an 
+			// error message? What's the difference between how the InotificationHandler
+			// interface is used on the notifyOK and notifyError methods?
+			
 			p_oNH.sendNotifications(sMsg);
 			for (int i1 = 0; i1 < oaP.length; i1++) {
 				NotificationList oCurr = new NotificationList(oaP[i1]);

Modified: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/services/InotificationHandler.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/services/InotificationHandler.java	2006-08-01 14:16:35 UTC (rev 5378)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/services/InotificationHandler.java	2006-08-01 14:25:23 UTC (rev 5379)
@@ -1,34 +1,35 @@
 /*
-* 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.
-*/
+ * 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.services;
 
 import org.jboss.soa.esb.helpers.*;
 import java.io.Serializable;
 
-public interface InotificationHandler
-{
-  public void sendNotifications (DomElement p_oP, Serializable p_o) throws Exception;
-  public void sendNotifications (Serializable p_o)                  throws Exception;
-} //____________________________________________________________________________
+public interface InotificationHandler {
+	
+	// REVIEW: Add some Javadoc for this interface!!!
+	
+	public void sendNotifications(DomElement p_oP, Serializable p_o) throws Exception;
+
+	public void sendNotifications(Serializable p_o) throws Exception;
+} // ____________________________________________________________________________

Added: labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/notification/NotifyUtilUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/notification/NotifyUtilUnitTest.java	2006-08-01 14:16:35 UTC (rev 5378)
+++ labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/notification/NotifyUtilUnitTest.java	2006-08-01 14:25:23 UTC (rev 5379)
@@ -0,0 +1,79 @@
+/*
+ * 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.notification;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.jboss.soa.esb.helpers.DomElement;
+import org.jboss.soa.esb.services.InotificationHandler;
+
+import junit.framework.TestCase;
+
+/**
+ * NotifyUtil unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class NotifyUtilUnitTest extends TestCase {
+
+	public void test_NotifyUtil() {
+		DomElement rootEl = new DomElement("rootEl");
+		
+		addNotificationConfig(rootEl, "message1", "ok");
+		addNotificationConfig(rootEl, "message2", "err");
+		addNotificationConfig(rootEl, "message3", "ok");
+		addNotificationConfig(rootEl, "message4", "err");
+		
+		TestNotificationHandler handler = new TestNotificationHandler();
+		NotifyUtil.notifyOK(handler, rootEl, "somemessage", new HashMap());
+		assertEquals(2, handler.messages.size());
+		assertEquals("message1 - somemessage", handler.messages.get(0));
+		assertEquals("message3 - somemessage", handler.messages.get(1));
+
+		handler.messages.clear();
+		NotifyUtil.notifyError(handler, rootEl, "somemessage", new HashMap(), new Exception("test"));
+		assertEquals(3, handler.messages.size());
+		assertTrue(handler.messages.get(0).startsWith("somemessage"));
+		assertTrue(handler.messages.get(1).startsWith("message2 - somemessage"));
+		assertTrue(handler.messages.get(2).startsWith("message4 - somemessage"));
+	}
+	
+	private void addNotificationConfig(DomElement rootEl, String message, String type) {
+		DomElement notifEl = new DomElement(NotificationList.ELEMENT);
+		notifEl.setAttr("message", message);
+		notifEl.setAttr(NotificationList.TYPE, type);
+		rootEl.addElemChild(notifEl);
+	}
+
+	private class TestNotificationHandler implements InotificationHandler {
+		private List<String> messages = new ArrayList<String>();
+		
+		public void sendNotifications(DomElement p_oP, Serializable p_o) throws Exception {
+			messages.add(p_oP.getAttr("message") + " - " + p_o);
+		}
+		public void sendNotifications(Serializable p_o) throws Exception {
+			messages.add(p_o.toString());
+		}
+	}
+}




More information about the jboss-svn-commits mailing list