From: <jbo...@li...> - 2006-06-27 17:46:46
|
Author: estebanschifman Date: 2006-06-27 13:46:39 -0400 (Tue, 27 Jun 2006) New Revision: 4840 Added: labs/jbossesb/trunk/ESBCore/Tests/src/org/jboss/soa/esb/tests/TestNotification.java Log: New class to unit test Rosetta Notification framework Added: labs/jbossesb/trunk/ESBCore/Tests/src/org/jboss/soa/esb/tests/TestNotification.java =================================================================== --- labs/jbossesb/trunk/ESBCore/Tests/src/org/jboss/soa/esb/tests/TestNotification.java 2006-06-27 17:44:16 UTC (rev 4839) +++ labs/jbossesb/trunk/ESBCore/Tests/src/org/jboss/soa/esb/tests/TestNotification.java 2006-06-27 17:46:39 UTC (rev 4840) @@ -0,0 +1,102 @@ +/* +* 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.tests; + +import java.util.*; +import java.text.SimpleDateFormat; + +import org.jboss.soa.esb.helpers.*; +import org.jboss.soa.esb.notification.*; +import org.jboss.soa.esb.services.*; + +// DON'T FORGET !! +// The Rosetta Application server has to be up and running +// (set JNDI_SERVER appropriately) +// For e-mail notification: System properties for smtp +// (server, user, password, port) must be set up in app server + +public class TestNotification +{ + private static final String JNDI_SERVER = "localhost"; + private static InotificationHandler m_oH; + + public TestNotification () throws Exception + { performTest(); } + + static void performTest() throws Exception + { + // get a handle to your business delegate + m_oH = NotificationHandlerFactory.getNotifHandler("remote",JNDI_SERVER); + + DomElement oEl = new DomElement("MyFileList"); + oEl.setAttr(NotificationList.TYPE,"OK"); + + oEl.addElemChild(fileListTarget()); + + NotificationList oNL = new NotificationList(oEl); + System.out.println(oNL.toString()); + + Date oNow = new Date(System.currentTimeMillis()); + SimpleDateFormat oStamp = new SimpleDateFormat("dd/MMM/yyyy HH:mm:ss.SSS"); + StringBuilder sb = new StringBuilder(oStamp.format(oNow)) + .append(" This message from Notification test"); + + m_oH.sendNotifications(oNL,sb.toString()); + } //________________________________ + + static DomElement emailTarget() throws Exception + { + DomElement oTgt = new DomElement(NotificationList.CHILD_TGT); + oTgt.setAttr(NotificationTarget.PRM_NOTIF_CLASS,"NotifyEmail"); + oTgt.setAttr(EsbEmail.FROM,"my...@my..."); + oTgt.setAttr(EsbEmail.SENDTO,"som...@ta...");; + oTgt.setAttr(EsbEmail.SUBJECT,"TEST from Rosetta"); + oTgt.setAttr(EsbEmail.MESSAGE,"This is the text of your message"); + + // This class does NOT send the e-mails, the app server does + // consequently these paths would have to be accessible in the + // application server (filesystem / mounts) + String[] sa = {"C:/tmp/tomcat.sh","E;/tmp/program.js"}; + for (String sCurr : sa) + oTgt.addTextChild(EsbEmail.ATTACH,sCurr); + + return oTgt; + } //________________________________ + + static DomElement fileListTarget() throws Exception + { + DomElement oTgt = new DomElement(NotificationList.CHILD_TGT); + oTgt.setAttr(NotificationTarget.PRM_NOTIF_CLASS,"NotifyFiles"); + + // This class does NOT write the files, the app server does + // consequently these paths would have to be accessible in the + // application server (filesystem / mounts) + String[] sa = {"file:///E:/tmp/file1.notif","file:///E:/tmp/file2.notif"}; + for (String sCurr : sa) + { DomElement oFile = new DomElement(NotifyFiles.CHILD_FILE); + oFile.setAttr(NotifyFiles.ATT_URI,sCurr); + oFile.setAttr(NotifyFiles.ATT_APPEND,Boolean.toString(true)); + oTgt.addElemChild(oFile); + } + return oTgt; + } //________________________________ +} //____________________________________________________________________________ |