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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Jul 27 06:35:27 EDT 2006


Author: tfennelly
Date: 2006-07-27 06:34:47 -0400 (Thu, 27 Jul 2006)
New Revision: 5302

Added:
   labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/helpers/EsbEmailUnitTest.java
   labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/helpers/KeyValuePairUnitTest.java
   labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/helpers/testfile4.xml
Modified:
   labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/common/EsbSysProps.java
   labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/EsbEmail.java
   labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/KeyValuePair.java
   labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotificationList.java
   labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotifyEmail.java
Log:
Cleaned up EsbEmail - restructured to make it easier to test (and understand), added Javadocs.
Added unit tests for EsbEmail
Added tests for KeyValuePair

Modified: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/common/EsbSysProps.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/common/EsbSysProps.java	2006-07-27 01:32:14 UTC (rev 5301)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/common/EsbSysProps.java	2006-07-27 10:34:47 UTC (rev 5302)
@@ -24,26 +24,36 @@
 
 import org.jboss.soa.esb.helpers.KeyValuePair;
 
-public class EsbSysProps
-{
+public class EsbSysProps {
 	public static final String SMTP_HOST = "org.jboss.soa.esb.mail.smtp.host";
+
 	public static final String SMTP_USERNAME = "org.jboss.soa.esb.mail.smtp.user";
+
 	public static final String SMTP_PASSWORD = "org.jboss.soa.esb.mail.smtp.password";
+
 	public static final String SMTP_PORT = "org.jboss.soa.esb.mail.smtp.port";
+
 	public static final String JNDI_SERVER_TYPE = "org.jboss.soa.esb.jndi.server.type";
+
 	public static final String JNDI_SERVER_URL = "org.jboss.soa.esb.jndi.server.url";
+
 	public static final String PARAMS_REPOS_FACTORY_CLASS = "org.jboss.soa.esb.paramsRepository.factory.class";
+
 	public static final String OBJECT_STORE_CONFIG_FILE = "org.jboss.soa.esb.objStore.configfile";
+
 	public static final String ENCRYPT_FACTORY_CLASS = "jorg.jboss.soa.esb.encryption.factory.class";
 
 	public static final String DEFAULT_HOST = "localhost";
+
 	public static final String DEFAULT_USERNAME = "";
+
 	public static final String DEFAULT_PASSWORD = "";
+
 	public static final String DEFAULT_PORT = "25";
+
 	public static final String DEFAULT_SERVER_TYPE = "jboss";
-	
-	private static KeyValuePair[] s_oaKV = new KeyValuePair[]
-	{
+
+	private static KeyValuePair[] s_oaKV = new KeyValuePair[] {
 			new KeyValuePair(SMTP_HOST, getSmtpHost()),
 			new KeyValuePair(SMTP_USERNAME, getSmtpUsername()),
 			new KeyValuePair(SMTP_PASSWORD, getSmtpPassword()),
@@ -57,58 +67,53 @@
 
 	};
 
-	public static String dump()
-	{
+	public static String dump() {
 		StringBuilder sb = new StringBuilder("Dump of EsbSysProps:\n");
-		for (KeyValuePair oCurr : s_oaKV)
-			sb.append(oCurr.getKey()).append("=").append(oCurr.getValue())
-					.append("\n");
+		for (KeyValuePair oCurr : s_oaKV) {
+			sb.append(oCurr.getKey()).append("=").append(oCurr.getValue()).append("\n");
+		}
 		return sb.append("______________________________________").toString();
 	} // ________________________________
 
-	public static String getSmtpHost()
-	{
+	public static String getSmtpHost() {
 		return System.getProperty(SMTP_HOST, EsbSysProps.DEFAULT_HOST);
 	}
 
-	public static String getSmtpUsername()
-	{
+	public static String getSmtpUsername() {
 		return System.getProperty(SMTP_USERNAME, EsbSysProps.DEFAULT_USERNAME);
 	}
 
-	public static String getSmtpPassword()
-	{
+	public static String getSmtpPassword() {
 		return System.getProperty(SMTP_PASSWORD, EsbSysProps.DEFAULT_PASSWORD);
 	}
 
-	public static String getSmtpPort()
-	{
+	public static String getSmtpPort() {
 		return System.getProperty(SMTP_PORT, EsbSysProps.DEFAULT_PORT);
 	}
 
-	public static String getJndiServerType()
-	{
-		return System.getProperty(JNDI_SERVER_TYPE, EsbSysProps.DEFAULT_SERVER_TYPE);
+	public static String getJndiServerType() {
+		return System.getProperty(JNDI_SERVER_TYPE,
+				EsbSysProps.DEFAULT_SERVER_TYPE);
 	}
 
-	public static String getJndiServerURL()
-	{
+	public static String getJndiServerURL() {
 		return System.getProperty(JNDI_SERVER_URL, EsbSysProps.DEFAULT_HOST);
 	}
 
-	public static String getParamsReposFactoryClass()
-	{
-		return System.getProperty(PARAMS_REPOS_FACTORY_CLASS, org.jboss.soa.esb.parameters.DefaultReposFactory.class.getName());
+	public static String getParamsReposFactoryClass() {
+		return System.getProperty(PARAMS_REPOS_FACTORY_CLASS,
+				org.jboss.soa.esb.parameters.DefaultReposFactory.class
+						.getName());
 	}
 
-	public static String getObjStoreConfigFile()
-	{
+	public static String getObjStoreConfigFile() {
 		return System.getProperty(OBJECT_STORE_CONFIG_FILE);
 	}
 
-	public static String getEncryptionFactoryClass()
-	{
-		return System.getProperty(ENCRYPT_FACTORY_CLASS, org.jboss.soa.esb.services.DefaultEncryptionFactory.class.getName());
+	public static String getEncryptionFactoryClass() {
+		return System.getProperty(ENCRYPT_FACTORY_CLASS,
+				org.jboss.soa.esb.services.DefaultEncryptionFactory.class
+						.getName());
 	}
 
 }
\ No newline at end of file

Modified: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/EsbEmail.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/EsbEmail.java	2006-07-27 01:32:14 UTC (rev 5301)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/EsbEmail.java	2006-07-27 10:34:47 UTC (rev 5302)
@@ -1,155 +1,283 @@
 /*
-* 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.helpers;
 
-import java.util.*;
-import javax.mail.*;
-import javax.mail.internet.*;
-import javax.activation.*;
+import java.util.Properties;
 
-import org.jboss.soa.esb.util.*;
+import javax.activation.DataHandler;
+import javax.activation.FileDataSource;
+import javax.mail.Address;
+import javax.mail.Authenticator;
+import javax.mail.BodyPart;
+import javax.mail.MessagingException;
+import javax.mail.Multipart;
+import javax.mail.PasswordAuthentication;
+import javax.mail.Session;
+import javax.mail.Transport;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
 
-import org.jboss.soa.esb.common.*;
+import org.jboss.soa.esb.common.EsbSysProps;
 
 /**
-   * Simplifies sending of e-mails with attachments from java
-   * <p>Author: Heuristica - Buenos Aires - Argentina </p>
+ * Simplifies sending of e-mails with attachments from java.
+ * <p/>
+ * The message is sent via a subsequent call to the {@link #sendMessage()}
+ * method.
+ * 
+ * <h3 id="p_oMessageParms">Message Parmeters</h3>
+ * The class constructor is supplied the following parameters via a
+ * {@link org.jboss.soa.esb.helpers.DomElement} instance:
+ * <ol>
+ * 	<li><b>FROM</b>: valid e-mail address</li>
+ * 	<li><b>SENDTO</b>: valid comma separated list of e-mail addresses</li>
+ * 	<li><b>SUBJECT</b>: free text that will appear as subject of the e-mail</li>
+ * 	<li><b>MESSAGE</b>: free text that will appear as contents of the e-mail</li>
+ * 	<li><b>ATTACH</b>: list (as Text children) of valid accessible filenames to
+ * 			attach to the e-mail</li>
+ * </ol>
+ * All parameters except 'ATTACH' are attributes of the DomElement argument. ATTACH
+ * parameters (attachments) are added as child DomElements of the  supplied
+ * DomElement.
+ * 
+ * @author: Heuristica - Buenos Aires - Argentina
  */
-public class EsbEmail
-{
-  /**
-   * DomElement attribute : will be the contents of the From: field in the outgoing message
-   */
-  public static final String FROM     = "from";
-  /**
-   * DomElement attribute : comma separated list of recipients
-   */
-  public static final String SENDTO   = "sendTo";
-  /**
-   * DomElement attribute : comma separated list of Copy recipients
-   */
-  public static final String COPYTO   = "ccTo";
-  /**
-   * DomElement attribute : will be the contents of the Subject: field in the outgoing message
-   */
-  public static final String SUBJECT  = "subject";
-  /**
-   * DomElement attribute : Value of this attribute will be the  content of
-   * the e-mail's text
-   */
-  public static final String ATTACH   = "attachment";
-  /**
-   * DomElement child Text elements : Each child represents the name of a
-   * file to be attached in the outgoing message
-   */
-  public static final String MESSAGE  = "message";
+public class EsbEmail {
+	/**
+	 * DomElement attribute : will be the contents of the From: field in the
+	 * outgoing message
+	 */
+	public static final String FROM = "from";
 
-  /**
-   * Constructor attempts to send e-mail using the information provided
-   * in the argument
-   *  <p>
-   * <li> FROM valid e-mail address</li>
-   * <li> SENDTO valid comma separated list of e-mail addresses</li>
-   * <li> SUBJECT free text that will appear as subject of the e-mail</li>
-   * <li> MESSAGE free text that will appear as contents of the e-mail</li>
-   * <li> ATTACH list (as Text children) of valid accessible filenames to attach to the e-mail</li>
-   * <li> All elements except 'ATTACH' are attributes of the DomElement argument</li>
-   *  </p>
-   * @param p_oParms  A DomElement object containing the elements mentioned above
-   * @see DomElement
-   *
-   */
-  public EsbEmail(DomElement p_oParms) throws Exception
-  {
-    Authenticator oAuth = null;
-    String sSmtpUser  = EsbSysProps.getSmtpUsername();
-    if (null != sSmtpUser)
-        oAuth = new MyAuth(sSmtpUser,EsbSysProps.getSmtpPassword());
+	/**
+	 * DomElement attribute : comma separated list of recipients
+	 */
+	public static final String SENDTO = "sendTo";
 
-    Properties oMailP = new Properties();
-    oMailP.setProperty("mail.smtp.host",EsbSysProps.getSmtpHost());
-    try 
-    { String sPort = EsbSysProps.getSmtpPort();
-      Integer.parseInt(sPort);
-      oMailP.setProperty("mail.smtp.port",sPort);
-    }
-    catch (Exception e) { /* OK just leave standard port */ }
-    
-    javax.mail.Session oMailSess = javax.mail.Session.getDefaultInstance
-        (oMailP, oAuth);
-    MimeMessage oMess     = new MimeMessage(oMailSess);
+	/**
+	 * DomElement attribute : comma separated list of Copy recipients
+	 */
+	public static final String COPYTO = "ccTo";
 
-    String sFrom  = p_oParms.getAttr(FROM);
-    InternetAddress oFrom = new InternetAddress(sFrom);
+	/**
+	 * DomElement attribute : will be the contents of the Subject: field in the
+	 * outgoing message
+	 */
+	public static final String SUBJECT = "subject";
 
-    String sAtt = (String)p_oParms.getAttr(SUBJECT);
-    if (null != sAtt) oMess.setSubject(sAtt);
+	/**
+	 * DomElement attribute : Value of this attribute will be the content of the
+	 * e-mail's text
+	 */
+	public static final String ATTACH = "attachment";
 
-    oMess.setFrom(oFrom);
-    oMess.setReplyTo(new Address[] {oFrom});
-    InternetAddress[] oaTo = InternetAddress.parse(p_oParms.getAttr(SENDTO));
-    for (int i1=0; i1<oaTo.length;i1++)
-      oMess.addRecipient(MimeMessage.RecipientType.TO,oaTo[i1]);
+	/**
+	 * DomElement child Text elements : Each child represents the name of a file
+	 * to be attached in the outgoing message
+	 */
+	public static final String MESSAGE = "message";
 
-    sAtt = (String)p_oParms.getAttr(COPYTO);
-    if (null != sAtt)
-    { oaTo = InternetAddress.parse(sAtt);
-      for (int i1=0; i1<oaTo.length;i1++)
-        oMess.addRecipient(MimeMessage.RecipientType.CC,oaTo[i1]);
-    }
+	/**
+	 * The message to b sent via a subsequent call to {@link #sendMessage()}.
+	 */
+	private MimeMessage mailMessage;
 
-    BodyPart oBodyP;
-    Multipart oMultiP;
-    oMess.setContent(oMultiP = new MimeMultipart());
+	/**
+	 * Public constructor.
+	 * <p/>
+	 * Initialises the mail server session and creates the mail message using 
+	 * the information provided in the p_oMessageParms 
+	 * <a href="p_oMessageParms">listed above</a>.
+	 * <p/>
+	 * The message is sent via a subsequent call to the {@link #sendMessage()}
+	 * method.
+	 * 
+	 * @param p_oMessageParms
+	 *            A DomElement object containing the elements mentioned above
+	 * @throws MessagingException 
+	 * @throws AddressException 
+	 * @see DomElement
+	 * 
+	 */
+	public EsbEmail(DomElement p_oMessageParms) throws AddressException, MessagingException {
+		// REVIEW: How about typing the parameters a little better??? Looks as though that might have a huge ripple-on effect accross the codebase!!
+		// REVIEW: Does the session need to ne initialised every time???
+		Session oMailSess = initMailServerSession();
+		
+		// Initialise the oMailMess property... 
+		mailMessage = createMailMessage(p_oMessageParms, oMailSess);
+		
+		// Message can be "sent" via a subsequent call to the sendMessage method!
+	} // __________________________________
 
-    oMultiP.addBodyPart(oBodyP = new MimeBodyPart());
-    String sText = p_oParms.getAttr(MESSAGE);
-    if (null == sText) sText = "";
-    oBodyP.setText(sText+"\n");
+	/**
+	 * Send the mail message associated with this instance.
+	 * @throws MessagingException Unable to transport the message associated with this
+	 * EsbEmail instance.
+	 */
+	public void sendMessage() throws MessagingException {
+		Transport.send(mailMessage);
+	}
+	
+	/**
+	 * Get the {@link MimeMessage mail message} associated with this EsbMail
+	 * instance.
+	 * @return The mailMessage property value.
+	 */
+	public MimeMessage getMailMessage() {
+		return mailMessage;
+	}
 
-    String [] saFn = p_oParms.getTextChildren(ATTACH);
-    for (int i1=0; i1<saFn.length; i1++)
-    { oMultiP.addBodyPart(oBodyP = new MimeBodyPart());
-      String sFile = saFn[i1];
-      oBodyP.setDataHandler(new DataHandler(new FileDataSource(sFile)));
-      oBodyP.setFileName(sFile.substring(1 + sFile.lastIndexOf("\\")));
-    }
+	/**
+	 * Create the mail message instance to be {@link #sendMessage() sent}.
+	 * @param p_oMessageParms <a href="p_oMessageParms">Message parameters.</a>.
+	 * @param oMailSess Mail session on which the message is to be transported.
+	 * @return The message.
+	 * @throws AddressException
+	 * @throws MessagingException
+	 */
+	private MimeMessage createMailMessage(DomElement p_oMessageParms, Session oMailSess) throws AddressException, MessagingException {
+		MimeMessage oMessage = new MimeMessage(oMailSess);
+		
+		// Populate the message with the data supplied in the p_oMessageParms DomElement.
+		addMessageAddressing(p_oMessageParms, oMessage);
+		addMessageSubject(p_oMessageParms, oMessage);
+		addMessageContent(p_oMessageParms, oMessage);
+		
+		return oMessage;
+	}
 
-    try { Transport.send(oMess); }
-    catch (Exception e)
-    {	EsbUtil.getDefaultLogger(this.getClass()).error("Send Mail Failed",e);
-    	throw e;
-    }
-  } //__________________________________
+	/**
+	 * Add the message addressing information to the message.
+	 * @param p_oMessageParms <a href="p_oMessageParms">Message parameters.</a>.
+	 * @param oMessage The message.
+	 * @throws AddressException
+	 * @throws MessagingException
+	 */
+	private void addMessageAddressing(DomElement p_oMessageParms, MimeMessage oMessage) throws AddressException, MessagingException {
+		String sFrom = p_oMessageParms.getAttr(FROM);
+		InternetAddress oFrom = new InternetAddress(sFrom);
+	
+		oMessage.setFrom(oFrom);
+		oMessage.setReplyTo(new Address[] { oFrom });
+		InternetAddress[] oaTo = 
+			InternetAddress.parse(p_oMessageParms.getAttr(SENDTO));
+		
+		for (int i1 = 0; i1 < oaTo.length; i1++) {
+			oMessage.addRecipient(MimeMessage.RecipientType.TO, oaTo[i1]);
+		}
+	
+		String sCopyToAddress = (String) p_oMessageParms.getAttr(COPYTO);
+		if (null != sCopyToAddress) {
+			oaTo = InternetAddress.parse(sCopyToAddress);
+			for (int i1 = 0; i1 < oaTo.length; i1++) {
+				oMessage.addRecipient(MimeMessage.RecipientType.CC, oaTo[i1]);
+			}
+		}
+	}
 
-  private class MyAuth extends Authenticator
-  { private String m_sUser, m_sPwd;
-    private MyAuth(String p_sU, String p_sP)
-    { m_sUser = p_sU; m_sPwd  = p_sP;  }
-    protected PasswordAuthentication getPasswordAuthentication()
-    { return new PasswordAuthentication(m_sUser,m_sPwd);
-    } //________________________________
-  } //______________________________________________________
+	/**
+	 * Add the message Subject to the message.
+	 * @param p_oMessageParms <a href="p_oMessageParms">Message parameters.</a>.
+	 * @param oMessage The message.
+	 * @throws MessagingException
+	 */
+	private void addMessageSubject(DomElement p_oMessageParms, MimeMessage oMessage) throws MessagingException {
+		String sSubject = (String) p_oMessageParms.getAttr(SUBJECT);
 
-} //____________________________________________________________________________
+		if (null != sSubject) {
+			oMessage.setSubject(sSubject);
+		}
+	}
 
+	/**
+	 * Add the message content (body, attachments etc) to from the
+	 * message parameters to the message.
+	 * @param p_oMessageParms <a href="p_oMessageParms">Message parameters.</a>.
+	 * @param oMessage The message.
+	 * @throws MessagingException
+	 */
+	private void addMessageContent(DomElement p_oMessageParms, MimeMessage oMessage) throws MessagingException {
+		BodyPart oBodyP = new MimeBodyPart();
+		Multipart oMultiP = new MimeMultipart();
+
+		oMultiP.addBodyPart(oBodyP);
+		oMessage.setContent(oMultiP);
+		String sBodyPartText = p_oMessageParms.getAttr(MESSAGE);
+		if (null == sBodyPartText) {
+			sBodyPartText = "";
+		}
+		oBodyP.setText(sBodyPartText + "\n");
+
+		String[] saFn = p_oMessageParms.getTextChildren(ATTACH);
+		for (int i1 = 0; i1 < saFn.length; i1++) {
+			oMultiP.addBodyPart(oBodyP = new MimeBodyPart());
+			String sFile = saFn[i1];
+			oBodyP.setDataHandler(new DataHandler(new FileDataSource(sFile)));
+			oBodyP.setFileName(sFile.substring(1 + sFile.lastIndexOf("\\")));
+		}
+	}
+
+	/**
+	 * Initialise an authenticated {@link javax.mail.Session} with the mail server.
+	 * @return The {@link javax.mail.Session}. 
+	 */
+	private Session initMailServerSession() {
+		Authenticator oAuth = null;
+		String sSmtpUser = EsbSysProps.getSmtpUsername();
+		
+		if (null != sSmtpUser) {
+			oAuth = new MyAuth(sSmtpUser, EsbSysProps.getSmtpPassword());
+		}
+
+		Properties oMailP = new Properties();
+		oMailP.setProperty("mail.smtp.host", EsbSysProps.getSmtpHost());
+		try {
+			String sPort = EsbSysProps.getSmtpPort();
+			Integer.parseInt(sPort);
+			oMailP.setProperty("mail.smtp.port", sPort);
+		} catch (Exception e) { /* OK just leave standard port */
+		}
+		javax.mail.Session oMailSess = 
+			javax.mail.Session.getDefaultInstance(oMailP, oAuth);
+		return oMailSess;
+	}
+
+	private class MyAuth extends Authenticator {
+		private String m_sUser, m_sPwd;
+
+		private MyAuth(String p_sU, String p_sP) {
+			m_sUser = p_sU;
+			m_sPwd = p_sP;
+		}
+
+		protected PasswordAuthentication getPasswordAuthentication() {
+			return new PasswordAuthentication(m_sUser, m_sPwd);
+		} // ________________________________
+	} // ______________________________________________________
+
+} // ____________________________________________________________________________
+

Modified: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/KeyValuePair.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/KeyValuePair.java	2006-07-27 01:32:14 UTC (rev 5301)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/helpers/KeyValuePair.java	2006-07-27 10:34:47 UTC (rev 5302)
@@ -1,45 +1,56 @@
 /*
-* 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.helpers;
 
 import java.io.Serializable;
 
-public class KeyValuePair implements Serializable
-{
+public class KeyValuePair implements Serializable {
 	private static final long serialVersionUID = 1L;
 
 	private String mKey, mVal;
-	public KeyValuePair(String pKey, String pVal)
-		{ mKey = pKey; mVal = pVal; }
-	public String getKey() 		{ return mKey; }
-	public String getValue() 	{ return mVal; }
-	public String setKey(String arg0)
-		{String sRet = mKey;	mKey = arg0.toString(); return sRet; }
-	public String setValue(String arg0)
-		{String sRet = mVal;	mVal = arg0.toString(); return sRet; }
-	public String toString()
-		{ return mVal; }
-	public String dump()
-	{ return "KVpair["+mKey+"="+mVal+"]"; }
 
-} //____________________________________________________________________________
+	public KeyValuePair(String pKey, String pVal) {
+		if(pKey == null || pKey.trim().equals("")) {
+			throw new IllegalArgumentException("null or empty 'pKey' arg in call.");
+		}
+		
+		mKey = pKey;
+		mVal = pVal;
+	}
+
+	public String getKey() {
+		return mKey;
+	}
+
+	public String getValue() {
+		return mVal;
+	}
+
+	public String toString() {
+		return mVal;
+	}
+
+	public String dump() {
+		return "KVpair[" + mKey + "=" + mVal + "]";
+	}
+} // ____________________________________________________________________________

Modified: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotificationList.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotificationList.java	2006-07-27 01:32:14 UTC (rev 5301)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotificationList.java	2006-07-27 10:34:47 UTC (rev 5302)
@@ -1,105 +1,130 @@
 /*
-* 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;
 
 import org.jboss.soa.esb.helpers.*;
 
 /**
- * Holds lists of NotificationTarget objects so that the JbossEsbNotificationHandler
- * EJB behaviour can be controlled at runtime by client applications
- * <p>Description: Objects of this class will hold a list of objects that
- * extend the NotificationTarget base class.  It's main purpose is to allow
- * Rosetta users to configure lists of recipients of specific events, and request
- * the JbossEsbNotificationHandler EJB to take care of triggering the events to
- * each object specified as a child "target" element
+ * Holds lists of NotificationTarget objects so that the
+ * JbossEsbNotificationHandler EJB behaviour can be controlled at runtime by
+ * client applications
+ * <p>
+ * Description: Objects of this class will hold a list of objects that extend
+ * the NotificationTarget base class. It's main purpose is to allow Rosetta
+ * users to configure lists of recipients of specific events, and request the
+ * JbossEsbNotificationHandler EJB to take care of triggering the events to each
+ * object specified as a child "target" element
  * </p>
- * <p>Author: Heuristica - Buenos Aires - Argentina</p>
+ * <p>
+ * Author: Heuristica - Buenos Aires - Argentina
+ * </p>
+ * 
  * @version 1.0
  */
-public class NotificationList extends DomElement
-{
-  /**
-   * Mnemonic name for the XML element name for the serialized form of objects
-   * of this class
-   */
-  public  static final String ELEMENT       = "NotificationList";
-  public  static final String TYPE			= "type";
-  public  static final String CHILD_TGT     = "target";
+public class NotificationList extends DomElement {
+	/**
+	 * Mnemonic name for the XML element name for the serialized form of objects
+	 * of this class
+	 */
+	public static final String ELEMENT = "NotificationList";
 
-  private String  m_sType;
-  /**
-   * Instantiate an object according to the contents of &lt;arg 1&gt;
-   * @param p_oP DomElement - Parameter object containing the information
-   * needed to instantiate this object, including child elements named "target"
-   * that represent each individual NotificationTarget object
-   * @throws Exception - the getMessage() of the Exception explains the problem
-   */
-  public NotificationList(DomElement p_oP) throws Exception
-  { super(p_oP);
-    m_sType = p_oP.getAttr(TYPE);
-    if (null!=m_sType) m_sType = m_sType.toLowerCase();
-  } //__________________________________
+	public static final String TYPE = "type";
 
-  private NotificationTarget[] getTargets() throws Exception
-  { DomElement[] oaTgts  = super.getElementChildren(CHILD_TGT);
-    NotificationTarget[] oaRet  = new NotificationTarget[oaTgts.length];
-    for (int i1=0; i1<oaRet.length;i1++)
-      oaRet[i1] = NotificationTarget.fromParams(oaTgts[i1]);
+	public static final String CHILD_TGT = "target";
 
-    return oaRet;
-  } //__________________________________
-  /**
-   * Invoke the sendNotification() method for all targets in the list. The method
-   * iterates along it's NotificationTarget child nodes and invokes the sendNotification()
-   * method with the same object to all of them
-   * @param p_o Object - The event to notify to all targets
-   * @throws Exception - use Exception.getMessage() at runtime
-   */
-  public void sendNotification(Object p_o) throws Exception
-  { NotificationTarget[] oaTgt  = getTargets();
-    for (int i1=0; i1<oaTgt.length; i1++)
-      oaTgt[i1].sendNotification(p_o);
-  } //__________________________________
-  /**
-   * Is this an OK (success) NotificationList ?
-   * @return boolean - Yes, Attribute "type" of constructor parameters starts with "ok",
-   * OR there was no "type" attribute in the constructor
-   * <li>A NotificationList can be both OK and Error if no "type" attribute
-   * was specified at constructor time in the DomElement argument</li>
-   * @see DomElement#getAttr(String)
-   */
-  public boolean isOK()
-    { return (null==m_sType) ? true : m_sType.startsWith("ok"); }
-    /**
-     * Is this an Error (failure) NotificationList ?
-     * @return boolean - Yes, Attribute "type" of constructor parameters starts with "err",
-     * OR there was no "type" attribute in the constructor
-     * <li>A NotificationList can be both OK and Error if no "type" attribute
-     * was specified at constructor time in the DomElement argument</li>
-     * @see DomElement#getAttr(String)
-     */
-  public boolean isErr()
-    { return (null==m_sType) ? true : m_sType.startsWith("err"); }
+	private String m_sType;
 
-} //____________________________________________________________________________
+	/**
+	 * Instantiate an object according to the contents of &lt;arg 1&gt;
+	 * 
+	 * @param p_oP
+	 *            DomElement - Parameter object containing the information
+	 *            needed to instantiate this object, including child elements
+	 *            named "target" that represent each individual
+	 *            NotificationTarget object
+	 * @throws Exception -
+	 *             the getMessage() of the Exception explains the problem
+	 */
+	public NotificationList(DomElement p_oP) throws Exception {
+		super(p_oP);
+		m_sType = p_oP.getAttr(TYPE);
+		if (null != m_sType)
+			m_sType = m_sType.toLowerCase();
+	} // __________________________________
+
+	private NotificationTarget[] getTargets() throws Exception {
+		DomElement[] oaTgts = super.getElementChildren(CHILD_TGT);
+		NotificationTarget[] oaRet = new NotificationTarget[oaTgts.length];
+		for (int i1 = 0; i1 < oaRet.length; i1++)
+			oaRet[i1] = NotificationTarget.fromParams(oaTgts[i1]);
+
+		return oaRet;
+	} // __________________________________
+
+	/**
+	 * Invoke the sendNotification() method for all targets in the list. The
+	 * method iterates along it's NotificationTarget child nodes and invokes the
+	 * sendNotification() method with the same object to all of them
+	 * 
+	 * @param p_o
+	 *            Object - The event to notify to all targets
+	 * @throws Exception -
+	 *             use Exception.getMessage() at runtime
+	 */
+	public void sendNotification(Object p_o) throws Exception {
+		NotificationTarget[] oaTgt = getTargets();
+		
+		for (int i1 = 0; i1 < oaTgt.length; i1++) {
+			oaTgt[i1].sendNotification(p_o);
+		}
+	} // __________________________________
+
+	/**
+	 * Is this an OK (success) NotificationList ?
+	 * 
+	 * @return boolean - Yes, Attribute "type" of constructor parameters starts
+	 *         with "ok", OR there was no "type" attribute in the constructor
+	 *         <li>A NotificationList can be both OK and Error if no "type"
+	 *         attribute was specified at constructor time in the DomElement
+	 *         argument</li>
+	 * @see DomElement#getAttr(String)
+	 */
+	public boolean isOK() {
+		return (null == m_sType) ? true : m_sType.startsWith("ok");
+	}
+
+	/**
+	 * Is this an Error (failure) NotificationList ?
+	 * 
+	 * @return boolean - Yes, Attribute "type" of constructor parameters starts
+	 *         with "err", OR there was no "type" attribute in the constructor
+	 *         <li>A NotificationList can be both OK and Error if no "type"
+	 *         attribute was specified at constructor time in the DomElement
+	 *         argument</li>
+	 * @see DomElement#getAttr(String)
+	 */
+	public boolean isErr() {
+		return (null == m_sType) ? true : m_sType.startsWith("err");
+	}
+
+} // ____________________________________________________________________________

Modified: labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotifyEmail.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotifyEmail.java	2006-07-27 01:32:14 UTC (rev 5301)
+++ labs/jbossesb/trunk/product/core/common/src/org/jboss/soa/esb/notification/NotifyEmail.java	2006-07-27 10:34:47 UTC (rev 5302)
@@ -1,78 +1,94 @@
 /*
-* 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;
 
 import javax.mail.internet.*;
 
 import org.jboss.soa.esb.helpers.*;
+import org.jboss.soa.esb.util.EsbUtil;
 
 /**
  * This class will send an e-mail using the EsbEmail class
- * <p>Description: </p>
- * <p>Author: Heuristica - Buenos Aires - Argentina</p>
+ * <p>
+ * Description:
+ * </p>
+ * <p>
+ * Author: Heuristica - Buenos Aires - Argentina
+ * </p>
+ * 
  * @version 1.0
  */
-public class NotifyEmail extends NotificationTarget
-{
-  /**
-   * Instantiate a NotifyEmail object using the information contained in &lt;arg 1&gt;
-   * @param p_oP DomElement - See attributes and structure needed for the
-   * EsbEmail(DomElement) constructor - The MESSAGE attribute will be filled
-   * in at sendNotification(Object) time
-   * @throws Exception
-   * @see EsbEmail#EsbEmail(DomElement)
-   * @see NotifyEmail#sendNotification(Object)
-   */
-  public NotifyEmail(DomElement p_oP) throws Exception
-  { super (p_oP);
+public class NotifyEmail extends NotificationTarget {
+	/**
+	 * Instantiate a NotifyEmail object using the information contained in
+	 * &lt;arg 1&gt;
+	 * 
+	 * @param p_oP
+	 *            DomElement - See attributes and structure needed for the
+	 *            EsbEmail(DomElement) constructor - The MESSAGE attribute will
+	 *            be filled in at sendNotification(Object) time
+	 * @throws Exception
+	 * @see EsbEmail#EsbEmail(DomElement)
+	 * @see NotifyEmail#sendNotification(Object)
+	 */
+	public NotifyEmail(DomElement p_oP) throws Exception {
+		super(p_oP);
 
-  	String sAtt = (String)m_oParms.getAttr(EsbEmail.FROM);
-    if (null != sAtt) InternetAddress.parse(sAtt);
+		String sAtt = (String) m_oParms.getAttr(EsbEmail.FROM);
+		if (null != sAtt)
+			InternetAddress.parse(sAtt);
 
-    InternetAddress.parse(m_oParms.getAttr(EsbEmail.SENDTO));
+		InternetAddress.parse(m_oParms.getAttr(EsbEmail.SENDTO));
 
-    sAtt = (String)m_oParms.getAttr(EsbEmail.COPYTO);
-    if (null != sAtt) InternetAddress.parse(sAtt);
-  } //__________________________________
-  /**
-   * Send an Email using EsbEmail() using p_o.toString() to fill in the
-   * message text
-   * @param p_o Object - This object's toString() method will supply contents
-   * of mail message
-   */
-  public void sendNotification(Object p_o)
-  { try
-    { DomElement oP  = m_oParms.cloneObj();
-      String sMsg = oP.getAttr(EsbEmail.MESSAGE);
-      sMsg = ((null==sMsg)?p_o.toString():sMsg+"\n")+p_o.toString();
-      // HB added line for debugging
-      //System.out.println("Sending Email Notification ->" +sMsg );
+		sAtt = (String) m_oParms.getAttr(EsbEmail.COPYTO);
+		if (null != sAtt)
+			InternetAddress.parse(sAtt);
+	} // __________________________________
 
-      oP.setAttr(EsbEmail.MESSAGE,sMsg);
-      new EsbEmail(oP);
-    }
-    catch (Exception e) { e.printStackTrace();}
-  } //__________________________________
+	/**
+	 * Send an Email using EsbEmail() using p_o.toString() to fill in the
+	 * message text
+	 * 
+	 * @param p_o
+	 *            Object - This object's toString() method will supply contents
+	 *            of mail message
+	 */
+	public void sendNotification(Object p_o) {
+		try {
+			DomElement oP = m_oParms.cloneObj();
+			String sMsg = oP.getAttr(EsbEmail.MESSAGE);
+			sMsg = ((null == sMsg) ? p_o.toString() : sMsg + "\n")
+					+ p_o.toString();
+			// HB added line for debugging
+			// System.out.println("Sending Email Notification ->" +sMsg );
 
-} //____________________________________________________________________________
+			oP.setAttr(EsbEmail.MESSAGE, sMsg);
+			EsbEmail esbMail = new EsbEmail(oP);
+			esbMail.sendMessage();
+		} catch (Exception e) {
+			EsbUtil.getDefaultLogger(this.getClass()).error("Send Mail Failed", e);
+			e.printStackTrace();
+		}
+	} // __________________________________
+
+} // ____________________________________________________________________________

Added: labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/helpers/EsbEmailUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/helpers/EsbEmailUnitTest.java	2006-07-27 01:32:14 UTC (rev 5301)
+++ labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/helpers/EsbEmailUnitTest.java	2006-07-27 10:34:47 UTC (rev 5302)
@@ -0,0 +1,87 @@
+/*
+ * 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.helpers;
+
+import java.io.IOException;
+
+import javax.mail.Address;
+import javax.mail.MessagingException;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for the EsbEmail class.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class EsbEmailUnitTest extends TestCase {
+
+	private DomElement mailParams;
+	
+	@Override
+	protected void setUp() throws Exception {
+		mailParams = DomElement.fromInputStream(getClass().getResourceAsStream("testfile4.xml"));
+	}
+
+	public void test_EsbEmail() throws AddressException, MessagingException, IOException {
+		// Look at the source message in testfile4.xml before reading this test.
+		
+		EsbEmail esbMail = new EsbEmail(mailParams);
+		MimeMessage message = esbMail.getMailMessage();
+		Address[] addresses;
+
+		// Check the "from" address details...
+		addresses = message.getFrom();
+		assertEquals(1, addresses.length);
+		assertEquals("x.x at x.com", addresses[0].toString());
+		
+		// Check the "to" address details...
+		addresses = message.getRecipients(MimeMessage.RecipientType.TO); 
+		assertEquals(2, addresses.length);
+		assertEquals("b.b at b.com", addresses[0].toString());
+		assertEquals("c.c at c.com", addresses[1].toString());
+		
+		// Check the "cc" address details...
+		addresses = message.getRecipients(MimeMessage.RecipientType.CC); 
+		assertEquals(2, addresses.length);
+		assertEquals("d.d at c.com", addresses[0].toString());
+		assertEquals("e.e at e.com", addresses[1].toString());
+		
+		// Check the "subject"...
+		assertEquals("Unit Test - Subject", message.getSubject());
+		
+		// Check the message body, including attachments...
+		MimeMultipart content = (MimeMultipart) message.getContent(); // expect a cast exception if it's not the expected type!
+		assertEquals(3, content.getCount()); // the message and the 2 attachments - see testfile4.xml
+		MimeBodyPart part = (MimeBodyPart) content.getBodyPart(0); // the message
+		assertEquals("Unit Test - Message", ((String)part.getContent()).trim());
+		part = (MimeBodyPart) content.getBodyPart(1); // attachement 1
+		assertEquals("attachment1.txt", ((String)part.getFileName()).trim());
+		part = (MimeBodyPart) content.getBodyPart(2); // attachement 2
+		assertEquals("attachment2.txt", ((String)part.getFileName()).trim());
+	}
+	
+	// TODO: Add some negative tests!!!
+}

Added: labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/helpers/KeyValuePairUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/helpers/KeyValuePairUnitTest.java	2006-07-27 01:32:14 UTC (rev 5301)
+++ labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/helpers/KeyValuePairUnitTest.java	2006-07-27 10:34:47 UTC (rev 5302)
@@ -0,0 +1,58 @@
+/*
+ * 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.helpers;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for the KeyValuePair class.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class KeyValuePairUnitTest extends TestCase {
+
+	public void test_Constructor_args() {
+		try {
+			new KeyValuePair(null, "aaa");
+			fail("Expected IllegalArgumentException");
+		} catch(IllegalArgumentException e) {
+			// expected
+		}
+		try {
+			new KeyValuePair(" ", "aaa");
+			fail("Expected IllegalArgumentException");
+		} catch(IllegalArgumentException e) {
+			// expected
+		}
+		new KeyValuePair("a", "aaa");
+		new KeyValuePair("a", null);
+		new KeyValuePair("a", "");
+	}
+
+	public void test_methods() {
+		KeyValuePair kvp = new KeyValuePair("key", "value");
+		
+		assertEquals("key", kvp.getKey());
+		assertEquals("value", kvp.getValue());
+		assertEquals("value", kvp.toString());
+		assertEquals("KVpair[key=value]", kvp.dump());
+	}
+}

Added: labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/helpers/testfile4.xml
===================================================================
--- labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/helpers/testfile4.xml	2006-07-27 01:32:14 UTC (rev 5301)
+++ labs/jbossesb/trunk/product/core/common/tests/src/org/jboss/soa/esb/helpers/testfile4.xml	2006-07-27 10:34:47 UTC (rev 5302)
@@ -0,0 +1,9 @@
+<mailParams	from="x.x at x.com" 
+			sendTo="b.b at b.com,c.c at c.com" 
+			ccTo="d.d at c.com,e.e at e.com" 
+			subject="Unit Test - Subject" message="Unit Test - Message">
+			
+	<attachment>attachment1.txt</attachment>
+	<attachment>attachment2.txt</attachment>
+	
+</mailParams>
\ No newline at end of file




More information about the jboss-svn-commits mailing list