[Schmitzm-commits] r1312 - in trunk: src/schmitzm/geotools src/schmitzm/mail src/schmitzm/swing src/schmitzm/swing/resource/locales src/skrueger/geotools/io src/skrueger/i8n src_junit/schmitzm/geotools/styling src_junit/schmitzm/mail

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sun Nov 28 22:51:07 CET 2010


Author: alfonx
Date: 2010-11-28 22:51:04 +0100 (Sun, 28 Nov 2010)
New Revision: 1312

Added:
   trunk/src_junit/schmitzm/mail/MailerTest.java
Modified:
   trunk/src/schmitzm/geotools/JTSUtil.java
   trunk/src/schmitzm/mail/MailUtil.java
   trunk/src/schmitzm/mail/Mailer.java
   trunk/src/schmitzm/swing/ExceptionDialog.java
   trunk/src/schmitzm/swing/resource/locales/SwingResourceBundle.properties
   trunk/src/skrueger/geotools/io/GsServerSettings.java
   trunk/src/skrueger/i8n/SwitchLanguageDialog.java
   trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java
Log:
* MailUtil kann jetzt SMTP mail verschicken.
* GP /AS versichen jetzt BugReports per SMTP wenn m?\195?\182glich, sonst ?\195?\188ber Desktop

Modified: trunk/src/schmitzm/geotools/JTSUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/JTSUtil.java	2010-11-28 20:17:50 UTC (rev 1311)
+++ trunk/src/schmitzm/geotools/JTSUtil.java	2010-11-28 21:51:04 UTC (rev 1312)
@@ -49,7 +49,6 @@
 import com.vividsolutions.jts.geom.Envelope;
 import com.vividsolutions.jts.geom.Geometry;
 import com.vividsolutions.jts.geom.GeometryFactory;
-import com.vividsolutions.jts.geom.Location;
 import com.vividsolutions.jts.geom.Point;
 import com.vividsolutions.jts.io.ParseException;
 import com.vividsolutions.jts.io.WKTReader;

Modified: trunk/src/schmitzm/mail/MailUtil.java
===================================================================
--- trunk/src/schmitzm/mail/MailUtil.java	2010-11-28 20:17:50 UTC (rev 1311)
+++ trunk/src/schmitzm/mail/MailUtil.java	2010-11-28 21:51:04 UTC (rev 1312)
@@ -159,12 +159,17 @@
 	 *            destination address(es); can be {@code null}
 	 * @param err
 	 *            exception to create a mail for
+	 * @param smtpMailer
+	 *            if not <code>null</code>, sends the email via the mailer.
 	 * @param additionalInfo
 	 *            may be <code>null</code>, adds additional text provided by the
 	 *            caller
+	 * @throws MessagingException
+	 * @throws AddressException
 	 */
-	public static void sendDesktopExceptionMail(String mailDestAddr,
-			Throwable err, Object additionalInfo) {
+	public static void sendExceptionMail(String mailDestAddr, Throwable err,
+			Object additionalInfo, Mailer smtpMailer) throws AddressException,
+			MessagingException {
 		String exceptionMess = err.getMessage();
 		String exceptionStack = LangUtil.getStackTraceFromException(err);
 
@@ -186,7 +191,10 @@
 				.append(exceptionStack);
 		String mailSubject = "Exception-Report: " + exceptionMess;
 
-		sendDesktopMail(mailDestAddr, mailSubject, mailBody.toString());
+		if (smtpMailer != null)
+			smtpMailer.sendMail(mailDestAddr, mailSubject, mailBody.toString());
+		else
+			sendDesktopMail(mailDestAddr, mailSubject, mailBody.toString());
 	}
 
 	/**
@@ -202,139 +210,20 @@
 		sendDesktopExceptionMail(mailDestAddr, err, null);
 	}
 
-	/**
-	 * Verschickt eine Email, wobei der Login Klartext erfolgt. Die Email wird
-	 * auf dem Aktuellen Thread verschickt und kann natürlich theoretisch
-	 * längere zeit beanspruchen! Kein Parameter darf <code>null</code> sein.
-	 * 
-	 * @param settings
-	 *            A {@link Properties} instance containing all basic
-	 *            configuration of the mailservice.
-	 */
-	public static void sendMail_cleartext(final String recipientsAddress,
-			final String subject, final String text, Properties settings)
-			throws MessagingException {
-
-		final String mailhost = settings.getProperty("mail.smtp.host");
-		final String senderAddress = settings
-				.getProperty("mail.sender.address");
-		log.debug("try: Sende Mail via " + mailhost + " an "
-				+ recipientsAddress + " als " + senderAddress
-				+ " with Betreff = " + subject);
-
-		// It is expected that the client supplies values for the properties
-		// listed in Appendix A of the JavaMail spec
-		// (particularly mail.store.protocol, mail.transport.protocol,
-		// mail.host, mail.user, and mail.from
-		Properties mailProps = new Properties();
-		// mailProps.setProperty("mail.store.protocol",
-		// getCfg("mail.store.protocol"));
-		// mailProps.setProperty("mail.transport.protocol",
-		// getCfg("mail.transport.protocol"));
-		// mailProps.setProperty("mail.host", getCfg("mail.host"));
-		// mailProps.setProperty("mail.user", getCfg("mail.user"));
-		// mailProps.setProperty("mail.from", getCfg("mail.from"));
-		mailProps.setProperty("mail.smtp.user",
-				settings.getProperty("mail.smtp.user"));
-		mailProps.setProperty("mail.smtp.credential",
-				settings.getProperty("mail.smtp.credential"));
-		mailProps.setProperty("mail.sender.address",
-				settings.getProperty("mail.sender.address"));
-		mailProps.setProperty("mail.smtp.host",
-				settings.getProperty("mail.smtp.host"));
-		mailProps.setProperty("mail.smtp.auth",
-				settings.getProperty("mail.smtp.auth"));
-		// mailProps.setProperty("mail.smtp.starttls.enable",
-		// getCfg("mail.smtp.starttls.enable"));
-		// mailProps.setProperty("mail.smtp.ssl.protocols",
-		// getCfg("mail.smtp.ssl.protocols"));
-
-		final Session session = Session.getInstance(
-				mailProps,
-				new SimpleStringAuthenticator(settings
-						.getProperty("mail.smtp.user"), settings
-						.getProperty("mail.smtp.credential")));
-		// Session session = Session.getDefaultInstance(properties, auth);
-
-		// Eine neue Message erzeugen
-		final Message msg = new MimeMessage(session);
-
+	public static void sendDesktopExceptionMail(String destMailAddr,
+			Throwable error, Object additionalInfo) {
 		try {
-			// Hier werden die Absender- und Empfängeradressen gesetzt
-			msg.setFrom(new InternetAddress(senderAddress));
-			msg.setRecipients(Message.RecipientType.TO,
-					InternetAddress.parse(recipientsAddress, false));
-
-			// Der Betreff und Body der Message werden gesetzt
-			msg.setSubject(subject);
-
-			// msg.setContent(text, "text/plain");
-			msg.setText(text);
-
-			// Hier lassen sich HEADER-Informationen hinzufügen
-			// msg.setHeader("Test", "Test");
-			msg.setSentDate(new Date());
-
-			// Zum Schluss wird die Mail natürlich noch verschickt
-			Transport.send(msg);
-		} catch (final AddressException ae) {
-			throw new MessagingException(
-					"Email konnte nicht versendet werden:", ae);
-		} catch (final MessagingException me) {
-			throw me;
+			sendExceptionMail(destMailAddr, error, additionalInfo, null);
+		} catch (AddressException e) {
+			log.error(
+					"unexpected javax.mail exception while using Desktop mail",
+					e);
+		} catch (MessagingException e) {
+			log.error(
+					"unexpected javax.mail exception while using Desktop mail",
+					e);
 		}
 
-		log.debug("Verschicken erfolgreich!");
 	}
 
-	// Sample code from http://www.javapractices.com/topic/TopicAction.do?Id=242
-	// to quote the mail body by encodeUnusualChars(..)
-	// Maybe we can reuse this (untested) code in future
-
-	// private static final Pattern SIMPLE_CHARS =
-	// Pattern.compile("[a-zA-Z0-9]");
-	//
-	// private String encodeUnusualChars(String aText){
-	// StringBuilder result = new StringBuilder();
-	// CharacterIterator iter = new StringCharacterIterator(aText);
-	// for(char c = iter.first(); c != CharacterIterator.DONE; c = iter.next())
-	// {
-	// char[] chars = {c};
-	// String character = new String(chars);
-	// if(isSimpleCharacter(character)){
-	// result.append(c);
-	// }
-	// else {
-	// hexEncode(character, "UTF-8", result);
-	// }
-	// }
-	// return result.toString();
-	// }
-	//
-	// private boolean isSimpleCharacter(String aCharacter){
-	// Matcher matcher = SIMPLE_CHARS.matcher(aCharacter);
-	// return matcher.matches();
-	// }
-	//
-	// /**
-	// For the given character and encoding, appends one or more hex-encoded
-	// characters.
-	// For double-byte characters, two hex-encoded items will be appended.
-	// */
-	// private static void hexEncode(String aCharacter, String aEncoding,
-	// StringBuilder aOut) {
-	// try {
-	// String HEX_DIGITS = "0123456789ABCDEF";
-	// byte[] bytes = aCharacter.getBytes(aEncoding);
-	// for (int idx = 0; idx < bytes.length; idx++) {
-	// aOut.append('%');
-	// aOut.append(HEX_DIGITS.charAt((bytes[idx] & 0xf0) >> 4));
-	// aOut.append(HEX_DIGITS.charAt(bytes[idx] & 0xf));
-	// }
-	// }
-	// catch (UnsupportedEncodingException ex) {
-	// ex.printStackTrace();
-	// }
-	// }
-
 }

Modified: trunk/src/schmitzm/mail/Mailer.java
===================================================================
--- trunk/src/schmitzm/mail/Mailer.java	2010-11-28 20:17:50 UTC (rev 1311)
+++ trunk/src/schmitzm/mail/Mailer.java	2010-11-28 21:51:04 UTC (rev 1312)
@@ -28,4 +28,9 @@
 				smtpCredential, smtpAuth, smtpHost, mailSenderAddress);
 	}
 
+	public void sendMail(String mailDestAddr, Throwable error,
+			Object additionalInfo) throws AddressException, MessagingException {
+		MailUtil.sendExceptionMail(mailDestAddr, error, additionalInfo, this);
+	}
+
 }

Modified: trunk/src/schmitzm/swing/ExceptionDialog.java
===================================================================
--- trunk/src/schmitzm/swing/ExceptionDialog.java	2010-11-28 20:17:50 UTC (rev 1311)
+++ trunk/src/schmitzm/swing/ExceptionDialog.java	2010-11-28 21:51:04 UTC (rev 1312)
@@ -50,6 +50,7 @@
 
 import schmitzm.lang.LangUtil;
 import schmitzm.mail.MailUtil;
+import schmitzm.mail.Mailer;
 
 /**
  * Diese Klasse stellt eine modale Fehler-Meldung dar. Diese besteht neben einer
@@ -61,20 +62,22 @@
  * @version 1.0
  */
 public class ExceptionDialog extends JDialog {
-    /** Enthaelt die Empfaenger-Adresse, an die eine Exception gemailt wird.
-     *  Standardmaessig ist dieses Feld {@code null}, so dass die Mail-Option
-     *  <b>nicht</b> zur Verfuegung steht. Zunaechst ist ein Aufruf von
-     *  {@link #setMailDestinationAddress(String)} in der Applikation
-     *  erforderlich. */
-    protected static String destMailAddr = null;
-    
 	/**
+	 * Enthaelt die Empfaenger-Adresse, an die eine Exception gemailt wird.
+	 * Standardmaessig ist dieses Feld {@code null}, so dass die Mail-Option
+	 * <b>nicht</b> zur Verfuegung steht. Zunaechst ist ein Aufruf von
+	 * {@link #setMailDestinationAddress(String)} in der Applikation
+	 * erforderlich.
+	 */
+	protected static String destMailAddr = null;
+
+	/**
 	 * If not <code>null</code>, toString will be evaluated to create additional
 	 * information (e.g. program version) when sending exception reports (e.g.
 	 * by mail)
 	 */
-    private static Object additionalAppInfo = null;
-   
+	private static Object additionalAppInfo = null;
+
 	/** Speichert den angezeigten Fehler. */
 	protected Throwable err = null;
 	/** Label in dem die Meldung angezeigt wird. */
@@ -87,8 +90,8 @@
 	protected JButton copyToClipboardButton = null;
 	/** Button um die Exception auf die Console zu kopieren. */
 	protected JButton copyToConsoleButton = null;
-    /** Button um die Exception im Mail-Programm zu oeffnen. */
-    protected JButton mailButton = null;
+	/** Button um die Exception im Mail-Programm zu oeffnen. */
+	protected JButton mailButton = null;
 	/** Bereich, in dem die Details angezeigt werden. */
 	protected JTextArea detailsTextArea = null;
 	/** ScrollPane, in dem sich die TextArea fuer die Details befinden. */
@@ -106,8 +109,12 @@
 	 **/
 	private static boolean throwRuntimeExceptionsBack = false;
 
-	
 	/**
+	 * Wenn gesetzt, werden die Emails per SMTP verschickt.
+	 */
+	private static Mailer smtpMailer;
+
+	/**
 	 * Erzeugt einen neuen Fehler-Dialog. Dem Dialog wird zunaechst noch keine
 	 * Fehlermeldung zugeordnet.
 	 * 
@@ -197,17 +204,18 @@
 		// Vorlagen-Dialog erzeugen
 		this.err = err;
 		this.messageLabel = new JLabel(errMessage);
-		this.okButton = new JButton(SwingUtil.RESOURCE.getString("Ok"));
+		this.okButton = new JButton(SwingUtil.R("Ok"));
 		this.copyToConsoleButton = new JButton(
-				SwingUtil.RESOURCE.getString("ExceptionDialog.CopyToConsole"));
+				SwingUtil.R("ExceptionDialog.CopyToConsole"));
 		this.copyToClipboardButton = new JButton(
-				SwingUtil.RESOURCE.getString("ExceptionDialog.CopyToClipboard"));
-        this.mailButton = new JButton(SwingUtil.RESOURCE.getString("ExceptionDialog.Mail"));
-        this.mailButton.setEnabled( getMailDestinationAddress() != null );
-        if ( !mailButton.isEnabled() )
-          mailButton.setToolTipText( SwingUtil.RESOURCE.getString("ExceptionDialog.MailDisabled.Desc") );
-		this.detailsButton = new JToggleButton(
-				SwingUtil.RESOURCE.getString("Details"), showDetails);
+				SwingUtil.R("ExceptionDialog.CopyToClipboard"));
+		this.mailButton = new JButton(SwingUtil.R("ExceptionDialog.Mail"));
+		this.mailButton.setEnabled(getMailDestinationAddress() != null);
+		if (!mailButton.isEnabled())
+			mailButton.setToolTipText(SwingUtil
+					.R("ExceptionDialog.MailDisabled.Desc"));
+		this.detailsButton = new JToggleButton(SwingUtil.R("Details"),
+				showDetails);
 		this.detailsTextArea = new JTextArea(10, 60);
 		this.detailsTextArea.setEditable(false);
 		this.detailsPrintStream = new TextAreaPrintStream(detailsTextArea);
@@ -251,21 +259,41 @@
 					getError().printStackTrace();
 			}
 		});
-        this.mailButton.addActionListener(new ActionListener() {
+		this.mailButton.addActionListener(new ActionListener() {
 
-		public void actionPerformed(ActionEvent e) {
-              if (getError() == null)
-                return;
-              
-              MailUtil.sendDesktopExceptionMail(destMailAddr, getError(), getAdditionalAppInfo());
-          }
-      });
+			public void actionPerformed(ActionEvent e) {
+				if (getError() == null)
+					return;
 
+				/**
+				 * Zuerst wird versucht die Mail über SMTP zu verschicken
+				 */
+				if (smtpMailer != null) {
+					try {
+						smtpMailer.sendMail(destMailAddr, getError(),
+								getAdditionalAppInfo());
+
+						JOptionPane
+								.showMessageDialog(
+										ExceptionDialog.this,
+										SwingUtil
+												.R("ExceptionDialog.Mail.SendBySmtpOk"));
+
+						return;
+					} catch (Exception ee) {
+					}
+				}
+
+				MailUtil.sendDesktopExceptionMail(destMailAddr, getError(),
+						getAdditionalAppInfo());
+			}
+		});
+
 		pack();
 		SwingUtil.setRelativeFramePosition(this,
 				SwingUtil.getParentWindow(parent), 0.5, 0.5);
 	}
-	
+
 	/**
 	 * Liefert die angezeigte Fehlermeldung.
 	 */
@@ -278,8 +306,8 @@
 	 */
 	public void setMessage(String mess) {
 		if (mess == null || mess.trim().equals(""))
-			mess = getError() != null ? getError().getMessage()
-					: SwingUtil.RESOURCE.getString("Error");
+			mess = getError() != null ? getError().getMessage() : SwingUtil
+					.R("Error");
 		messageLabel.setText(mess);
 	}
 
@@ -302,20 +330,26 @@
 		detailsTextArea.select(0, 0);
 	}
 
-	   /**
-     * Liefert die Mail-Adresse(n), an die eine Exception gemailt wird.
-     */
-    public static String getMailDestinationAddress()  {
-      return destMailAddr;
-    }
+	/**
+	 * Liefert die Mail-Adresse(n), an die eine Exception gemailt wird.
+	 */
+	public static String getMailDestinationAddress() {
+		return destMailAddr;
+	}
 
-    /**
-     * Setzt die Mail-Adresse(n), an die eine Exception gemailt wird.
-     */
-    public static void setMailDestinationAddress(String mailAddr)  {
-      destMailAddr = mailAddr;
-    }
+	/**
+	 * Setzt die Mail-Adresse(n), an die eine Exception gemailt wird.
+	 */
+	public static void setMailDestinationAddress(String mailAddr) {
+		destMailAddr = mailAddr;
+	}
 
+	/**
+	 * Setzt die Mail-Adresse(n), an die eine Exception gemailt wird.
+	 */
+	public static void setSmtpMailer(Mailer smtpMailer_) {
+		smtpMailer = smtpMailer_;
+	}
 
 	/**
 	 * Zeigt einen Fehler-Dialog an.
@@ -395,7 +429,8 @@
 	}
 
 	/**
-	 * This method will construct the {@link ExceptionDialog} on the Event Dispatching Thread, even if it has been started from another thread! 
+	 * This method will construct the {@link ExceptionDialog} on the Event
+	 * Dispatching Thread, even if it has been started from another thread!
 	 */
 	private static void constructDialog(final Component parent,
 			final Throwable err, final String title, final String errMessage,

Modified: trunk/src/schmitzm/swing/resource/locales/SwingResourceBundle.properties
===================================================================
--- trunk/src/schmitzm/swing/resource/locales/SwingResourceBundle.properties	2010-11-28 20:17:50 UTC (rev 1311)
+++ trunk/src/schmitzm/swing/resource/locales/SwingResourceBundle.properties	2010-11-28 21:51:04 UTC (rev 1312)
@@ -94,6 +94,7 @@
 ExceptionDialog.CopyToConsole=Copy to console
 ExceptionDialog.Mail=Mail
 ExceptionDialog.MailDisabled.Desc=Mailing currently not available, because a destination mail address for bug reporting is not set in this application (ExceptionDialog.setMailDestinationAddress(..))
+ExceptionDialog.Mail.SendBySmtpOk=<html>An email has been send to bugreport at wikisquare.de.<br>If you supplied your email-address, expect feedback from tzeggai at wikisquare.de.</html>
 
 ManualInputOption.PasswordVisible.visibility=visible
 

Modified: trunk/src/skrueger/geotools/io/GsServerSettings.java
===================================================================
--- trunk/src/skrueger/geotools/io/GsServerSettings.java	2010-11-28 20:17:50 UTC (rev 1311)
+++ trunk/src/skrueger/geotools/io/GsServerSettings.java	2010-11-28 21:51:04 UTC (rev 1312)
@@ -14,6 +14,9 @@
  * This class can serialize all important parameters needed to define the
  * connection into a {@link String} with {@link #toPropertiesString()} and
  * re-import the String with {@link #parsePropertiesString(String)}.
+ * 
+ * TODO THis is wrong, should not extend AbstractGTServerSettings since it is
+ * not a GeoTools specific server setting
  */
 public class GsServerSettings extends AbstractGTServerSettings<Void, Void> {
 

Modified: trunk/src/skrueger/i8n/SwitchLanguageDialog.java
===================================================================
--- trunk/src/skrueger/i8n/SwitchLanguageDialog.java	2010-11-28 20:17:50 UTC (rev 1311)
+++ trunk/src/skrueger/i8n/SwitchLanguageDialog.java	2010-11-28 21:51:04 UTC (rev 1312)
@@ -30,16 +30,12 @@
 package skrueger.i8n;
 
 import java.awt.Component;
-import java.awt.GridBagConstraints;
-import java.awt.GridBagLayout;
-import java.awt.Insets;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.util.ArrayList;
 import java.util.List;
 
 import javax.swing.ImageIcon;
-import javax.swing.JButton;
 import javax.swing.JComboBox;
 import javax.swing.JLabel;
 import javax.swing.JPanel;

Modified: trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java
===================================================================
--- trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java	2010-11-28 20:17:50 UTC (rev 1311)
+++ trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java	2010-11-28 21:51:04 UTC (rev 1312)
@@ -1,6 +1,9 @@
 package schmitzm.geotools.styling;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 
 import java.awt.Color;
 import java.awt.Dimension;

Added: trunk/src_junit/schmitzm/mail/MailerTest.java
===================================================================
--- trunk/src_junit/schmitzm/mail/MailerTest.java	2010-11-28 20:17:50 UTC (rev 1311)
+++ trunk/src_junit/schmitzm/mail/MailerTest.java	2010-11-28 21:51:04 UTC (rev 1312)
@@ -0,0 +1,121 @@
+package schmitzm.mail;
+
+import static org.junit.Assert.fail;
+
+import javax.mail.MessagingException;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import schmitzm.junit.TestingClass;
+
+public class MailerTest extends TestingClass {
+
+	private String mailSenderAddress;
+	private String smtpHost;
+	private String smtpAuth;
+	private String smtpCredential;
+	private String smtpUser;
+	private String text;
+	private String subject;
+	private String recipientsAddress;
+
+	@Before
+	public void setUp() throws Exception {
+
+		recipientsAddress = "bugreport at wikisquare.de";
+		subject = "junit MailUtilTest";
+		text = "MailUtilTest works";
+		smtpUser = "bugreport";
+		smtpCredential = "";
+		smtpAuth = "";
+		smtpHost = "www.wikisquare.de";
+		mailSenderAddress = "bugreport at wikisquare.de";
+	}
+
+	@After
+	public void tearDown() throws Exception {
+	}
+
+	@Test
+	public void testSendMail() {
+		try {
+			Mailer m = createMailer();
+
+			try {
+				m.sendMail(recipientsAddress, subject, text);
+			} catch (MessagingException me) {
+				if (me.getMessage().contains("Unknown SMTP host")) {
+					log.info("Mail testing skipped because the system is not online.");
+				} else
+					throw me;
+			}
+
+		} catch (Exception e) {
+			log.info("failed to send a test-mail to bugreport at wikisquare.de", e);
+			fail(e.getMessage());
+		}
+	}
+
+	@Test
+	@Ignore
+	public void testSendLongException() {
+		try {
+			Mailer m = createMailer();
+			RuntimeException e = new RuntimeException("Hallo, testing only!",
+					new RuntimeException(new RuntimeException("TEST")));
+
+			try {
+				m.sendMail(recipientsAddress, e, null);
+			} catch (MessagingException me) {
+				if (me.getMessage().contains("Unknown SMTP host")) {
+					log.info("Mail testing skipped because the system is not online.");
+				} else
+					throw me;
+			}
+
+		} catch (Exception e) {
+			log.info(
+					"failed to send a long test-mail to bugreport at wikisquare.de",
+					e);
+			fail(e.getMessage());
+		}
+	}
+
+	@Test
+	@Ignore
+	public void testSendLongText() {
+
+		try {
+			Mailer m = createMailer();
+			StringBuffer text = new StringBuffer();
+			int i = 0;
+			while (i++ < 10000) {
+				text.append("texttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttext"
+						+ i + "\n");
+			}
+			try {
+				m.sendMail(recipientsAddress, "JUNIT", text.toString());
+			} catch (MessagingException me) {
+				if (me.getMessage().contains("Unknown SMTP host")) {
+					log.info("Mail testing skipped because the system is not online.");
+				} else
+					throw me;
+			}
+
+		} catch (Exception e) {
+			log.info(
+					"failed to send a long test-mail to bugreport at wikisquare.de",
+					e);
+			fail(e.getMessage());
+		}
+	}
+
+	private Mailer createMailer() {
+		Mailer m = new Mailer(smtpUser, smtpCredential, smtpAuth, smtpHost,
+				mailSenderAddress);
+		return m;
+	}
+}


Property changes on: trunk/src_junit/schmitzm/mail/MailerTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native



More information about the Schmitzm-commits mailing list