[jbpm-commits] JBoss JBPM SVN: r4471 - in jbpm4/branches/email/modules/pvm: src/main/java/org/jbpm/pvm and 13 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Apr 7 02:03:24 EDT 2009


Author: alex.guizar at jboss.com
Date: 2009-04-07 02:03:24 -0400 (Tue, 07 Apr 2009)
New Revision: 4471

Added:
   jbpm4/branches/email/modules/pvm/.settings/org.eclipse.jdt.ui.prefs
   jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MailSessionBinding.java
   jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/PatternDescriptor.java
   jbpm4/branches/email/modules/pvm/src/test/java/org/jbpm/pvm/internal/wire/MailSessionWireTest.java
Removed:
   jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/deploy/
   jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/api/
   jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/model/
   jbpm4/branches/email/modules/pvm/src/test/java/org/jbpm/pvm/internal/execution/
   jbpm4/branches/email/modules/pvm/src/test/java/org/jbpm/pvm/spring/
   jbpm4/branches/email/modules/pvm/src/test/java/org/jbpm/pvm/variables/
Modified:
   jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/filter/WildCardAddressFilter.java
   jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/producer/MailContext.java
   jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/server/SmtpServer.java
   jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/service/SynchronousMailService.java
   jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/PropertiesBinding.java
   jbpm4/branches/email/modules/pvm/src/test/java/org/jbpm/pvm/internal/email/filter/WildCardAddressFilterTest.java
   jbpm4/branches/email/modules/pvm/src/test/resources/jbpm.wire.bindings.xml
Log:
provide mail session binding

Added: jbpm4/branches/email/modules/pvm/.settings/org.eclipse.jdt.ui.prefs
===================================================================
--- jbpm4/branches/email/modules/pvm/.settings/org.eclipse.jdt.ui.prefs	                        (rev 0)
+++ jbpm4/branches/email/modules/pvm/.settings/org.eclipse.jdt.ui.prefs	2009-04-07 06:03:24 UTC (rev 4471)
@@ -0,0 +1,3 @@
+#Mon Apr 06 21:23:03 CDT 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates/>

Modified: jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/filter/WildCardAddressFilter.java
===================================================================
--- jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/filter/WildCardAddressFilter.java	2009-04-07 00:38:39 UTC (rev 4470)
+++ jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/filter/WildCardAddressFilter.java	2009-04-07 06:03:24 UTC (rev 4471)
@@ -10,12 +10,19 @@
  * Allows filtering of to/cc/bcc recipient lists based on 
  * regular expressions for include and exclude patterns.
  * @author Brad Davis
- *
  */
 public class WildCardAddressFilter implements AddressFilter {
 
-	protected Collection<String> includePatterns;
-	protected Collection<String> excludePatterns;
+	/** 
+	 * patterns of addresses to be included.
+	 * all addresses are included when omitted.
+	 */
+	protected Collection<Pattern> includePatterns;
+	/**
+	 * patterns of addresses to be excluded.
+	 * no addresses are excluded when omitted.
+	 */
+	protected Collection<Pattern> excludePatterns;
 	
 	public Collection<InternetAddress> filter(final Collection<InternetAddress> addresses)
 	{
@@ -41,39 +48,48 @@
 	 */
 	protected boolean keepAddress(InternetAddress address)
 	{	
-		if(includePatterns!=null)
+		return includeAddress(address) && !excludeAddress(address);
+	}
+
+	protected boolean includeAddress(InternetAddress address)
+	{
+		if (includePatterns == null || includePatterns.isEmpty()) 
+			return true;
+
+		for (Pattern pattern : includePatterns)
 		{
-			for(String pattern : includePatterns)
-			{
-				if(Pattern.matches(pattern, address.toString()))
-				{
-					return true;
-				}
-			}
+			if (pattern.matcher(address.toString()).matches()) 
+				return true;
 		}
-		if(excludePatterns!=null)
+		return false;
+	}
+
+	protected boolean excludeAddress(InternetAddress address)
+	{
+		if (excludePatterns == null || excludePatterns.isEmpty())
+			return false;
+
+		for (Pattern pattern : excludePatterns)
 		{
-			for(String pattern : excludePatterns)
-			{
-				if(Pattern.matches(pattern, address.toString()))
-				{
-					return false;
-				}
-			}
+			if (pattern.matcher(address.toString()).matches())
+				return true;
 		}
-		if(includePatterns==null||includePatterns.isEmpty())
-		{
-			//Includes were not set, which means if it wasn't excluded, include it.
-			return true;
-		}
 		return false;
 	}
 
-	public void setIncludePatterns(Collection<String> includePatterns) {
+	public Collection<Pattern> getIncludePatterns() {
+		return includePatterns;
+	}
+
+	public void setIncludePatterns(Collection<Pattern> includePatterns) {
 		this.includePatterns = includePatterns;
 	}
 
-	public void setExcludePatterns(Collection<String> excludePatterns) {
+	public void setExcludePatterns(Collection<Pattern> excludePatterns) {
 		this.excludePatterns = excludePatterns;
 	}
+
+	public Collection<Pattern> getExcludePatterns() {
+		return excludePatterns;
+	}
 }

Modified: jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/producer/MailContext.java
===================================================================
--- jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/producer/MailContext.java	2009-04-07 00:38:39 UTC (rev 4470)
+++ jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/producer/MailContext.java	2009-04-07 06:03:24 UTC (rev 4471)
@@ -12,7 +12,6 @@
 	private Collection<String> toAddresses;
 	private Collection<String> ccAddresses;
 	private Collection<String> bccAddresses;
-	
 	public Collection<User> getActors() {
 		return actors;
 	}

Modified: jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/server/SmtpServer.java
===================================================================
--- jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/server/SmtpServer.java	2009-04-07 00:38:39 UTC (rev 4470)
+++ jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/server/SmtpServer.java	2009-04-07 06:03:24 UTC (rev 4471)
@@ -20,6 +20,10 @@
 		return Session.getDefaultInstance(properties, null);
 	}
 
+	public Properties getProperties() {
+		return properties;
+	}
+
 	public void setProperties(Properties properties) {
 		this.properties = properties;
 	}

Modified: jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/service/SynchronousMailService.java
===================================================================
--- jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/service/SynchronousMailService.java	2009-04-07 00:38:39 UTC (rev 4470)
+++ jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/service/SynchronousMailService.java	2009-04-07 06:03:24 UTC (rev 4471)
@@ -1,15 +1,9 @@
 package org.jbpm.pvm.internal.email.service;
 
-import java.util.Arrays;
 import java.util.Collection;
-import java.util.HashSet;
 
-import javax.mail.Address;
-import javax.mail.MessagingException;
 import javax.mail.Session;
 import javax.mail.internet.InternetAddress;
-import javax.mail.internet.MimeMessage;
-import javax.mail.internet.MimeMessage.RecipientType;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -70,11 +64,11 @@
 					}
 				}
 			}
-			
-			
 		}
-		
-		
 	}
-	
+
+	public Collection<MailServerConfiguration> getServerConfigs() {
+		return serverConfigs;
+	}
+
 }

Added: jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MailSessionBinding.java
===================================================================
--- jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MailSessionBinding.java	                        (rev 0)
+++ jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MailSessionBinding.java	2009-04-07 06:03:24 UTC (rev 4471)
@@ -0,0 +1,108 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbpm.pvm.internal.wire.binding;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jbpm.pvm.internal.email.filter.WildCardAddressFilter;
+import org.jbpm.pvm.internal.email.server.MailServerConfiguration;
+import org.jbpm.pvm.internal.email.server.SmtpServer;
+import org.jbpm.pvm.internal.email.service.MailService;
+import org.jbpm.pvm.internal.email.service.SynchronousMailService;
+import org.jbpm.pvm.internal.util.XmlUtil;
+import org.jbpm.pvm.internal.wire.Descriptor;
+import org.jbpm.pvm.internal.wire.descriptor.CollectionDescriptor;
+import org.jbpm.pvm.internal.wire.descriptor.ListDescriptor;
+import org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor;
+import org.jbpm.pvm.internal.wire.descriptor.PatternDescriptor;
+import org.jbpm.pvm.internal.wire.descriptor.PropertiesDescriptor;
+import org.jbpm.pvm.internal.xml.Parse;
+import org.jbpm.pvm.internal.xml.Parser;
+import org.w3c.dom.Element;
+
+/**
+ * Parses a descriptor for creating a {@link MailService}.
+ * 
+ * @author Alejandro Guizar
+ */
+public class MailSessionBinding extends WireDescriptorBinding {
+
+	private static final PropertiesBinding propertiesBinding = new PropertiesBinding();
+
+	public MailSessionBinding() {
+		super("mail-session");
+	}
+
+	public Object parse(Element element, Parse parse, Parser parser) {
+		// mail servers
+		List<Descriptor> serverDescriptors = new ArrayList<Descriptor>();
+		for (Element serverElement : XmlUtil.elements(element, "mail-server")) {
+			// smtp properties
+			Element smtpElement = XmlUtil.element(serverElement, "smtp-properties");
+			PropertiesDescriptor propertiesDescriptor = propertiesBinding.parse(smtpElement, parse,
+					parser);
+			ObjectDescriptor smtpDescriptor = new ObjectDescriptor(SmtpServer.class);
+			smtpDescriptor.addInjection("properties", propertiesDescriptor);
+
+			// address filter
+			Element filterElement = XmlUtil.element(serverElement, "wildcard-address-filter");
+
+			// includes
+			List<Descriptor> includeDescriptors = new ArrayList<Descriptor>();
+			for (Element includeElement : XmlUtil.elements(filterElement, "include")) {
+				includeDescriptors.add(new PatternDescriptor(XmlUtil.getContentText(includeElement), 0));
+			}
+			CollectionDescriptor includesDescriptor = new ListDescriptor();
+			includesDescriptor.setValueDescriptors(includeDescriptors);
+
+			// excludes
+			List<Descriptor> excludeDescriptors = new ArrayList<Descriptor>();
+			for (Element excludeElement : XmlUtil.elements(filterElement, "exclude")) {
+				excludeDescriptors.add(new PatternDescriptor(XmlUtil.getContentText(excludeElement), 0));
+			}
+			CollectionDescriptor excludesDescriptor = new ListDescriptor();
+			excludesDescriptor.setValueDescriptors(excludeDescriptors);
+
+			// address filter
+			ObjectDescriptor filterDescriptor = new ObjectDescriptor(WildCardAddressFilter.class);
+			filterDescriptor.addInjection("includePatterns", includesDescriptor);
+			filterDescriptor.addInjection("excludePatterns", excludesDescriptor);
+
+			// mail server
+			ObjectDescriptor serverDescriptor = new ObjectDescriptor(MailServerConfiguration.class);
+			serverDescriptor.addInjection("server", smtpDescriptor);
+			serverDescriptor.addInjection("filter", filterDescriptor);
+			serverDescriptors.add(serverDescriptor);
+		}
+
+		// mail servers
+		CollectionDescriptor serversDescriptor = new ListDescriptor();
+		serversDescriptor.setValueDescriptors(serverDescriptors);
+
+		// mail session
+		ObjectDescriptor sessionDescriptor = new ObjectDescriptor(SynchronousMailService.class);
+		sessionDescriptor.addInjection("serverConfigs", serversDescriptor);
+		return sessionDescriptor;
+	}
+
+}

Modified: jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/PropertiesBinding.java
===================================================================
--- jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/PropertiesBinding.java	2009-04-07 00:38:39 UTC (rev 4470)
+++ jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/PropertiesBinding.java	2009-04-07 06:03:24 UTC (rev 4471)
@@ -44,7 +44,7 @@
     super("properties");
   }
 
-  public Object parse(Element element, Parse parse, Parser parser) {
+  public PropertiesDescriptor parse(Element element, Parse parse, Parser parser) {
     PropertiesDescriptor descriptor = new PropertiesDescriptor();
     
     if (element.hasAttribute("file")) {

Added: jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/PatternDescriptor.java
===================================================================
--- jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/PatternDescriptor.java	                        (rev 0)
+++ jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/PatternDescriptor.java	2009-04-07 06:03:24 UTC (rev 4471)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbpm.pvm.internal.wire.descriptor;
+
+import java.util.regex.Pattern;
+
+import org.jbpm.pvm.internal.wire.WireContext;
+
+/**
+ * @author Alejandro Guizar
+ */
+public class PatternDescriptor extends AbstractDescriptor {
+
+	private static final long serialVersionUID = 1L;
+
+	protected String regex;
+	protected int flags;
+
+	public PatternDescriptor() {
+	}
+
+	public PatternDescriptor(String regex, int flags) {
+		this.regex = regex;
+		this.flags = flags;
+	}
+
+	public Object construct(WireContext wireContext) {
+		return Pattern.compile(regex, flags);
+	}
+
+}

Modified: jbpm4/branches/email/modules/pvm/src/test/java/org/jbpm/pvm/internal/email/filter/WildCardAddressFilterTest.java
===================================================================
--- jbpm4/branches/email/modules/pvm/src/test/java/org/jbpm/pvm/internal/email/filter/WildCardAddressFilterTest.java	2009-04-07 00:38:39 UTC (rev 4470)
+++ jbpm4/branches/email/modules/pvm/src/test/java/org/jbpm/pvm/internal/email/filter/WildCardAddressFilterTest.java	2009-04-07 06:03:24 UTC (rev 4471)
@@ -1,7 +1,9 @@
 package org.jbpm.pvm.internal.email.filter;
 
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashSet;
+import java.util.regex.Pattern;
 
 import javax.mail.internet.InternetAddress;
 
@@ -16,7 +18,7 @@
 	{
 		WildCardAddressFilter filter = new WildCardAddressFilter();
 		//Ensure it is-a AddressFilter.
-		this.assertTrue(AddressFilter.class.isAssignableFrom(filter.getClass()));
+		assertTrue(AddressFilter.class.isAssignableFrom(filter.getClass()));
 	}
 	
 	/**
@@ -30,7 +32,7 @@
 		addresses.add(new InternetAddress("test at jboss.org"));
 		
 		Collection<InternetAddress> filteredAddresses = filter.filter(addresses);
-		this.assertTrue(filteredAddresses.contains(new InternetAddress("test at jboss.org")));
+		assertTrue(filteredAddresses.contains(new InternetAddress("test at jboss.org")));
 	}
 	
 	/**
@@ -45,13 +47,12 @@
 		addresses.add(new InternetAddress("test at jboss.org"));
 		addresses.add(new InternetAddress("test at amentra.com"));
 		
-		Collection<String> regExIncludes = new HashSet<String>();
-		regExIncludes.add(".+ at jboss.org");
+		Collection<Pattern> regExIncludes = Collections.singleton(Pattern.compile(".+ at jboss.org"));
 		filter.setIncludePatterns(regExIncludes);
 		
 		Collection<InternetAddress> filteredAddresses = filter.filter(addresses);
-		this.assertTrue(filteredAddresses.contains(new InternetAddress("test at jboss.org")));
-		this.assertTrue(!filteredAddresses.contains(new InternetAddress("test at amentra.com")));
+		assertTrue(filteredAddresses.contains(new InternetAddress("test at jboss.org")));
+		assertTrue(!filteredAddresses.contains(new InternetAddress("test at amentra.com")));
 	}
 	
 	/**
@@ -65,19 +66,17 @@
 		addresses.add(new InternetAddress("test at jboss.org"));
 		addresses.add(new InternetAddress("test at amentra.com"));
 		
-		Collection<String> regExIncludes = new HashSet<String>();
-		regExIncludes.add(".+ at jboss.org");
+		Collection<Pattern> regExIncludes = Collections.singleton(Pattern.compile(".+ at jboss.org"));
 		filter.setIncludePatterns(regExIncludes);
 		
-		Collection<String> regExExcludes = new HashSet<String>();
-		regExExcludes.add(".+ at jboss.org");
+		Collection<Pattern> regExExcludes = Collections.singleton(Pattern.compile(".+ at amentra.com"));
 		filter.setExcludePatterns(regExExcludes);
 		
 		Collection<InternetAddress> filteredAddresses = filter.filter(addresses);
 		//Includes jboss
-		this.assertTrue(filteredAddresses.contains(new InternetAddress("test at jboss.org")));
+		assertTrue(filteredAddresses.contains(new InternetAddress("test at jboss.org")));
 		//Does not include amentra.
-		this.assertTrue(!filteredAddresses.contains(new InternetAddress("test at amentra.com")));
+		assertTrue(!filteredAddresses.contains(new InternetAddress("test at amentra.com")));
 	}
 	
 	/**
@@ -93,19 +92,15 @@
 		addresses.add(new InternetAddress("test at amentra.com"));
 		addresses.add(new InternetAddress("test at redhat.com"));
 		
-		Collection<String> regExExcludes = new HashSet<String>();
-		regExExcludes.add(".+ at jboss.org");
+		Collection<Pattern> regExExcludes = Collections.singleton(Pattern.compile(".+ at jboss.org"));
 		filter.setExcludePatterns(regExExcludes);
 		
 		Collection<InternetAddress> filteredAddresses = filter.filter(addresses);
 		//Does not include jboss
-		this.assertTrue(!filteredAddresses.contains(new InternetAddress("test at jboss.org")));
+		assertTrue(!filteredAddresses.contains(new InternetAddress("test at jboss.org")));
 		//Does include amentra
-		this.assertTrue(filteredAddresses.contains(new InternetAddress("test at amentra.com")));
+		assertTrue(filteredAddresses.contains(new InternetAddress("test at amentra.com")));
 		//Does include redhat
-		this.assertTrue(filteredAddresses.contains(new InternetAddress("test at redhat.com")));
+		assertTrue(filteredAddresses.contains(new InternetAddress("test at redhat.com")));
 	}
-	
-	
-	
 }

Added: jbpm4/branches/email/modules/pvm/src/test/java/org/jbpm/pvm/internal/wire/MailSessionWireTest.java
===================================================================
--- jbpm4/branches/email/modules/pvm/src/test/java/org/jbpm/pvm/internal/wire/MailSessionWireTest.java	                        (rev 0)
+++ jbpm4/branches/email/modules/pvm/src/test/java/org/jbpm/pvm/internal/wire/MailSessionWireTest.java	2009-04-07 06:03:24 UTC (rev 4471)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, 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.jbpm.pvm.internal.wire;
+
+import java.util.Collection;
+import java.util.Properties;
+import java.util.regex.Pattern;
+
+import org.jbpm.pvm.internal.email.filter.WildCardAddressFilter;
+import org.jbpm.pvm.internal.email.server.MailServerConfiguration;
+import org.jbpm.pvm.internal.email.service.MailService;
+import org.jbpm.pvm.internal.email.service.SynchronousMailService;
+
+/**
+ * @author Alejandro Guizar
+ */
+public class MailSessionWireTest extends WireTestCase {
+
+	public void testMailSession() {
+    WireContext wireContext = createWireContext(
+        "<objects>" +
+        "  <mail-session>" +
+        "    <mail-server>" +
+        "      <wildcard-address-filter>" +
+        "        <include>.+ at jbpm.org</include>" +
+        "        <exclude>.+ at jboss.com</exclude>" +
+        "      </wildcard-address-filter>" +
+        "      <smtp-properties>" +
+        "        <property name='mail.host' value='localhost' />" +
+        "        <property name='mail.user' value='aguizar' />" +
+        "        <property name='mail.from' value='noreply at jbpm.org' />" +
+        "      </smtp-properties>" +
+        "    </mail-server>" +
+        "  </mail-session>" +
+        "</objects>"
+      );
+
+    MailService mailService = wireContext.get(MailService.class);
+    assertTrue("expected sync mail service", mailService instanceof SynchronousMailService);
+
+    SynchronousMailService syncMailService = (SynchronousMailService) mailService;
+    Collection<MailServerConfiguration> serverConfigs = syncMailService.getServerConfigs();
+    assertEquals(1, serverConfigs.size());
+
+    MailServerConfiguration serverConfig = serverConfigs.iterator().next();
+    WildCardAddressFilter addressFilter = (WildCardAddressFilter) serverConfig.getFilter();
+    
+    Collection<Pattern> includePatterns = addressFilter.getIncludePatterns();
+    assertEquals(1, includePatterns.size());
+    assertEquals(".+ at jbpm.org", includePatterns.iterator().next().toString());
+
+    Collection<Pattern> excludePatterns = addressFilter.getExcludePatterns();
+    assertEquals(1, excludePatterns.size());
+    assertEquals(".+ at jboss.com", excludePatterns.iterator().next().toString());
+
+    Properties properties = serverConfig.getServer().getProperties();
+    assertEquals(3, properties.size());
+    assertEquals("localhost", properties.getProperty("mail.host"));
+    assertEquals("aguizar", properties.getProperty("mail.user"));
+    assertEquals("noreply at jbpm.org", properties.getProperty("mail.from"));
+	}
+}

Modified: jbpm4/branches/email/modules/pvm/src/test/resources/jbpm.wire.bindings.xml
===================================================================
--- jbpm4/branches/email/modules/pvm/src/test/resources/jbpm.wire.bindings.xml	2009-04-07 00:38:39 UTC (rev 4470)
+++ jbpm4/branches/email/modules/pvm/src/test/resources/jbpm.wire.bindings.xml	2009-04-07 06:03:24 UTC (rev 4471)
@@ -51,6 +51,7 @@
   <binding class="org.jbpm.pvm.internal.wire.binding.IdentitySessionBinding" />
   <binding class="org.jbpm.pvm.internal.wire.binding.IdentitySessionFactoryBinding" />
   <binding class="org.jbpm.pvm.internal.wire.binding.RepositorySessionBinding" />
+  <binding class="org.jbpm.pvm.internal.wire.binding.MailSessionBinding" />
   
   <!-- db sessions -->
   <binding class="org.jbpm.pvm.internal.wire.binding.PvmDbSessionBinding" />




More information about the jbpm-commits mailing list