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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Jul 31 13:02:35 EDT 2006


Author: tfennelly
Date: 2006-07-31 13:02:28 -0400 (Mon, 31 Jul 2006)
New Revision: 5364

Added:
   labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/notification/NotifySqlTableUnitTest.java
   labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/notification/NotifySqlTable_testfile1.xml
Modified:
   labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotifySqlTable.java
Log:
Added tests for NotifySqlTable

Modified: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotifySqlTable.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotifySqlTable.java	2006-07-31 16:48:31 UTC (rev 5363)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotifySqlTable.java	2006-07-31 17:02:28 UTC (rev 5364)
@@ -1,24 +1,24 @@
 /*
-* 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.notification;
 
@@ -28,79 +28,95 @@
 import org.jboss.soa.esb.helpers.*;
 import org.jboss.soa.esb.helpers.persist.*;
 
-public class NotifySqlTable extends NotificationTarget
-{
-  public    static final String CHILD_COLUMN= "column";
+public class NotifySqlTable extends NotificationTarget {
+	public static final String CHILD_COLUMN = "column";
 
-  public    static final String ATT_TABLE       = "table";
-  public    static final String ATT_DATA        = "dataColumn";
+	public static final String ATT_TABLE = "table";
 
-  public    static final String ATT_NAME        = "name";
-  public    static final String ATT_VALUE       = "value";
+	public static final String ATT_DATA = "dataColumn";
 
-  private String    m_sDriver   ,m_sURL   ,m_sUser    ,m_sPwd
-                    ,m_sTable   ,m_sDataCol;
-  private Properties m_oCols;
+	public static final String ATT_NAME = "name";
 
-  public NotifySqlTable(DomElement p_oP) throws Exception
-  { super (p_oP);
-    m_sDriver   = getAttr(SimpleDataSource.DRIVER);
-    m_sURL      = getAttr(SimpleDataSource.URL);
-    m_sUser     = getAttr(SimpleDataSource.USER);
-    m_sPwd      = getAttr(SimpleDataSource.PASSWORD);
-    m_sTable    = getAttr(ATT_TABLE);
-    m_sDataCol  = getAttr(ATT_DATA);
+	public static final String ATT_VALUE = "value";
 
-    m_oCols     = new Properties();
-    DomElement[] oaP  = p_oP.getElementChildren(CHILD_COLUMN);
-    for (int i1=0; i1<oaP.length;i1++)
-    { DomElement oCurr  = oaP[i1];
-      String sCol = oCurr.getAttr(ATT_NAME);
-      if (null==sCol)           continue;
-      sCol  = sCol.trim();
-      if (sCol.length()<1)      continue;
-      String sVal = oCurr.getAttr(ATT_VALUE);
-      if (null==sVal) sVal  = "";
-      m_oCols.setProperty(sCol,sVal);
-    }
-  } //__________________________________
+	protected String m_sDriver, m_sURL, m_sUser, m_sPwd, m_sTable, m_sDataCol;
 
-  private String getAttr(String p_sAtt) throws Exception
-  { String sRet = m_oParms.getAttr(p_sAtt);
-    if (null==sRet) throw new Exception ("Missing "+p_sAtt+" attribute");
-    sRet  = sRet.trim();
-    if (p_sAtt.equals(SimpleDataSource.PASSWORD))   return sRet;
-    if (sRet.length()<1) throw new Exception ("Empty "+p_sAtt+" attribute");
-    return sRet;
-  } //__________________________________
+	protected Properties m_oCols;
 
-  public String getInsertStmt()
-  { String[] saCols = new String[m_oCols.size()];
-    m_oCols.keySet().toArray(saCols);
+	public NotifySqlTable(DomElement p_oP) throws Exception {
+		super(p_oP);
+		m_sDriver = getAttr(SimpleDataSource.DRIVER);
+		m_sURL = getAttr(SimpleDataSource.URL);
+		m_sUser = getAttr(SimpleDataSource.USER);
+		m_sPwd = getAttr(SimpleDataSource.PASSWORD);
+		m_sTable = getAttr(ATT_TABLE);
+		m_sDataCol = getAttr(ATT_DATA);
 
-    StringBuffer sbCol = new StringBuffer("insert into ").append(m_sTable).append(" ");
-    StringBuffer sbPrm = new StringBuffer(" values ");
-    for (int i1=0; i1<saCols.length; i1++)
-    { String sIn = (i1==0) ? "(" : ",";
-      String sCurrCol = saCols[i1];
-      sbCol.append(sIn).append("\"").append(sCurrCol).append("\"");
-      sbPrm.append(sIn).append("'").append(m_oCols.getProperty(sCurrCol)).append("'");
-    }
-    return sbCol.append(")").append(sbPrm).append(")").toString();
- } //__________________________________
+		m_oCols = new Properties();
+		DomElement[] oaP = p_oP.getElementChildren(CHILD_COLUMN);
+		for (int i1 = 0; i1 < oaP.length; i1++) {
+			DomElement oCurr = oaP[i1];
+			String sCol = oCurr.getAttr(ATT_NAME);
+			if (null == sCol) {
+				continue;
+			}
+			sCol = sCol.trim();
+			if (sCol.length() < 1) {
+				continue;
+			}
+			String sVal = oCurr.getAttr(ATT_VALUE);
+			if (null == sVal) {
+				sVal = "";
+			}
+			m_oCols.setProperty(sCol, sVal);
+		}
+	} // __________________________________
 
-  public void sendNotification(java.io.Serializable p_o)
-  { m_oCols.setProperty(m_sDataCol,p_o.toString());
-    JdbcCleanConn oConn = null;
-    try
-    { oConn = new JdbcCleanConn(new SimpleDataSource
-    		(m_sDriver,m_sURL,m_sUser,m_sPwd));
-      PreparedStatement PS = oConn.prepareStatement(getInsertStmt());
-      oConn.execUpdWait(PS,3);
-      oConn.commit();
-    }
-    catch (Exception e) {e.printStackTrace(System.err); }
-    finally {if (null != oConn) oConn.release();}
-  } //__________________________________
+	private String getAttr(String p_sAtt) throws Exception {
+		String sRet = m_oParms.getAttr(p_sAtt);
+		if (null == sRet) {
+			throw new Exception("Missing " + p_sAtt + " attribute");
+		}
+		sRet = sRet.trim();
+		if (p_sAtt.equals(SimpleDataSource.PASSWORD)) {
+			return sRet;
+		}
+		if (sRet.length() < 1) {
+			throw new Exception("Empty " + p_sAtt + " attribute");
+		}
+		return sRet;
+	} // __________________________________
 
-} //____________________________________________________________________________
+	public String getInsertStmt() {
+		String[] saCols = new String[m_oCols.size()];
+		m_oCols.keySet().toArray(saCols);
+
+		StringBuffer sbCol = new StringBuffer("insert into ").append(m_sTable).append(" ");
+		StringBuffer sbPrm = new StringBuffer(" values ");
+		for (int i1 = 0; i1 < saCols.length; i1++) {
+			String sIn = (i1 == 0) ? "(" : ",";
+			String sCurrCol = saCols[i1];
+			sbCol.append(sIn).append("\"").append(sCurrCol).append("\"");
+			sbPrm.append(sIn).append("'").append(m_oCols.getProperty(sCurrCol)).append("'");
+		}
+		return sbCol.append(")").append(sbPrm).append(")").toString();
+	} // __________________________________
+
+	public void sendNotification(java.io.Serializable p_o) {
+		m_oCols.setProperty(m_sDataCol, p_o.toString());
+		JdbcCleanConn oConn = null;
+		try {
+			oConn = new JdbcCleanConn(new SimpleDataSource(m_sDriver, m_sURL, m_sUser, m_sPwd));
+			PreparedStatement PS = oConn.prepareStatement(getInsertStmt());
+			oConn.execUpdWait(PS, 3);
+			oConn.commit();
+		} catch (Exception e) {
+			e.printStackTrace(System.err);
+		} finally {
+			if (null != oConn) {
+				oConn.release();
+			}
+		}
+	} // __________________________________
+
+} // ____________________________________________________________________________

Added: labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/notification/NotifySqlTableUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/notification/NotifySqlTableUnitTest.java	2006-07-31 16:48:31 UTC (rev 5363)
+++ labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/notification/NotifySqlTableUnitTest.java	2006-07-31 17:02:28 UTC (rev 5364)
@@ -0,0 +1,52 @@
+/*
+ * 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 org.jboss.soa.esb.helpers.DomElement;
+
+import junit.framework.TestCase;
+
+/**
+ * NotifySqlTable unit tests.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class NotifySqlTableUnitTest extends TestCase {
+
+	public void test_NotifySqlTable() throws Exception {
+		DomElement domEl = DomElement.fromInputStream(getClass().getResourceAsStream("NotifySqlTable_testfile1.xml"));
+		NotifySqlTable nst = new NotifySqlTable(domEl);
+		
+		assertEquals("driver-class", nst.m_sDriver);
+		assertEquals("connection-url", nst.m_sURL);
+		assertEquals("user-name", nst.m_sUser);
+		assertEquals("password", nst.m_sPwd);
+		assertEquals("table", nst.m_sTable);
+		assertEquals("dataColumn", nst.m_sDataCol);
+		
+		assertEquals(3, nst.m_oCols.size());
+		assertEquals("colvalue1", nst.m_oCols.getProperty("colname1"));
+		assertEquals("colvalue2", nst.m_oCols.getProperty("colname2"));
+		assertEquals("colvalue3", nst.m_oCols.getProperty("colname3"));
+
+		assertEquals("insert into table (\"colname3\",\"colname2\",\"colname1\") values ('colvalue3','colvalue2','colvalue1')", nst.getInsertStmt());
+	}
+}

Added: labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/notification/NotifySqlTable_testfile1.xml
===================================================================
--- labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/notification/NotifySqlTable_testfile1.xml	2006-07-31 16:48:31 UTC (rev 5363)
+++ labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/notification/NotifySqlTable_testfile1.xml	2006-07-31 17:02:28 UTC (rev 5364)
@@ -0,0 +1,12 @@
+<notif	driver-class="driver-class" 
+		connection-url="connection-url" 
+		user-name="user-name" 
+		password="password" 
+		table="table"
+		dataColumn="dataColumn">
+		
+		<column name="colname1" value="colvalue1"/>
+		<column name="colname2" value="colvalue2"/>
+		<column name="colname3" value="colvalue3"/>
+		
+</notif>
\ No newline at end of file




More information about the jboss-svn-commits mailing list