[Schmitzm-commits] r1422 - in trunk/schmitzm-core/src: main/java/de/schmitzm/io main/java/de/schmitzm/linux main/java/de/schmitzm/net/mail test/java/de/schmitzm test/java/de/schmitzm/linux test/java/de/schmitzm/net test/java/de/schmitzm/net/mail

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Jan 27 12:30:47 CET 2011


Author: alfonx
Date: 2011-01-27 12:30:45 +0100 (Thu, 27 Jan 2011)
New Revision: 1422

Added:
   trunk/schmitzm-core/src/test/java/de/schmitzm/linux/
   trunk/schmitzm-core/src/test/java/de/schmitzm/linux/LinuxUtilTest.java
   trunk/schmitzm-core/src/test/java/de/schmitzm/net/mail/
   trunk/schmitzm-core/src/test/java/de/schmitzm/net/mail/MailUtilTest.java
   trunk/schmitzm-core/src/test/java/de/schmitzm/net/mail/MailerTest.java
Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/io/MailerInterface.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/linux/LinuxUtil.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/net/mail/Mailer.java
   trunk/schmitzm-core/src/test/java/de/schmitzm/net/SitemapTest.java
Log:
mehr tests

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/io/MailerInterface.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/io/MailerInterface.java	2011-01-27 11:29:08 UTC (rev 1421)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/io/MailerInterface.java	2011-01-27 11:30:45 UTC (rev 1422)
@@ -2,11 +2,14 @@
 
 import java.util.Set;
 
+import javax.mail.MessagingException;
+import javax.mail.internet.AddressException;
+
 public interface MailerInterface {
 
-	void sendMail(String recipientsAddress, String subject, String text);
+	void sendMail(String recipientsAddress, String subject, String text) throws AddressException, MessagingException;
 
 	void sendMail(String mailDestAddr, Throwable error,
-			Set<Object> additionalInfo) ;
+			Set<Object> additionalInfo) throws AddressException, MessagingException;
 
 }

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/linux/LinuxUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/linux/LinuxUtil.java	2011-01-27 11:29:08 UTC (rev 1421)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/linux/LinuxUtil.java	2011-01-27 11:30:45 UTC (rev 1422)
@@ -4,12 +4,12 @@
 import java.io.IOException;
 
 /**
- * Utility methods to do linux specific stuff, e.g. symbolic links
+ * Utility methods to do Linux/Unix specific stuff, e.g. symbolic links
  */
 public class LinuxUtil {
 
 	/**
-	 * Creates a symbolic link
+	 * Creates a symbolic link by running the <code>/bin/ln</code> programm.
 	 * 
 	 * @param from
 	 *            an existing {@link File}

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/net/mail/Mailer.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/net/mail/Mailer.java	2011-01-27 11:29:08 UTC (rev 1421)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/net/mail/Mailer.java	2011-01-27 11:30:45 UTC (rev 1422)
@@ -2,6 +2,9 @@
 
 import java.util.Set;
 
+import javax.mail.MessagingException;
+import javax.mail.internet.AddressException;
+
 import de.schmitzm.io.MailerInterface;
 
 /**
@@ -25,24 +28,24 @@
 
 	@Override
 	public void sendMail(final String recipientsAddress, final String subject,
-			final String text) {
-		try {
+			final String text) throws AddressException, MessagingException {
+//		try {
 			MailUtil.sendSmtpMail(recipientsAddress, subject, text, smtpUser,
 					smtpCredential, smtpAuth, smtpHost, mailSenderAddress);
-		} catch (Exception e) {
-			throw new RuntimeException(e);
-		}
+//		} catch (Exception e) {
+//			throw new RuntimeException(e);
+//		}
 	}
 
 	@Override
 	public void sendMail(String mailDestAddr, Throwable error,
-			Set<Object> additionalInfo) {
-		try {
+			Set<Object> additionalInfo) throws AddressException, MessagingException {
+//		try {
 			MailUtil.sendExceptionMail(mailDestAddr, error, additionalInfo,
 					this);
-		} catch (Exception e) {
-			throw new RuntimeException(e);
-		}
+//		} catch (Exception e) {
+//			throw new RuntimeException(e);
+//		}
 	}
 
 }

Added: trunk/schmitzm-core/src/test/java/de/schmitzm/linux/LinuxUtilTest.java
===================================================================
--- trunk/schmitzm-core/src/test/java/de/schmitzm/linux/LinuxUtilTest.java	2011-01-27 11:29:08 UTC (rev 1421)
+++ trunk/schmitzm-core/src/test/java/de/schmitzm/linux/LinuxUtilTest.java	2011-01-27 11:30:45 UTC (rev 1422)
@@ -0,0 +1,37 @@
+package de.schmitzm.linux;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import de.schmitzm.testing.TestingClass;
+import de.schmitzm.testing.TestingUtil;
+public class LinuxUtilTest extends TestingClass {
+
+	@Before
+	public void setUp() throws Exception {
+	}
+
+	@After
+	public void tearDown() throws Exception {
+	}
+
+	@Test
+	public void testCreateSymlink() throws IOException, InterruptedException {
+		File from = TestingUtil.getNewTempDir();
+		File to = new File(TestingUtil.getNewTempDir(), "link");
+		assertFalse(to.exists());
+
+		LinuxUtil.createSymlink(from, to);
+		assertTrue(to.exists());
+		
+		to.delete();
+	}
+
+}
\ No newline at end of file


Property changes on: trunk/schmitzm-core/src/test/java/de/schmitzm/linux/LinuxUtilTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native

Modified: trunk/schmitzm-core/src/test/java/de/schmitzm/net/SitemapTest.java
===================================================================
--- trunk/schmitzm-core/src/test/java/de/schmitzm/net/SitemapTest.java	2011-01-27 11:29:08 UTC (rev 1421)
+++ trunk/schmitzm-core/src/test/java/de/schmitzm/net/SitemapTest.java	2011-01-27 11:30:45 UTC (rev 1422)
@@ -1,5 +1,7 @@
 package de.schmitzm.net;
 
+import static org.junit.Assert.assertTrue;
+
 import org.junit.Test;
 
 import de.schmitzm.net.Sitemap.CHANGEFREQ;
@@ -13,7 +15,11 @@
 		s.addUrl("http://www.wikisquare.de/UeberUns", null, CHANGEFREQ.monthly, 0.6);
 		s.addUrl("http://www.wikisquare.de/publications", null, null, null);
 		String xml = s.getXmlString();
-		System.out.println(xml);
+		
+		log.debug(xml);
+		
+		assertTrue(xml.contains("<changefreq>monthly</changefreq>"));
+		assertTrue(xml.contains("<priority>0.6</priority>"));
 	}
 
 }
\ No newline at end of file

Added: trunk/schmitzm-core/src/test/java/de/schmitzm/net/mail/MailUtilTest.java
===================================================================
--- trunk/schmitzm-core/src/test/java/de/schmitzm/net/mail/MailUtilTest.java	2011-01-27 11:29:08 UTC (rev 1421)
+++ trunk/schmitzm-core/src/test/java/de/schmitzm/net/mail/MailUtilTest.java	2011-01-27 11:30:45 UTC (rev 1422)
@@ -0,0 +1,59 @@
+package de.schmitzm.net.mail;
+
+
+import static org.junit.Assert.fail;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+import de.schmitzm.testing.TestingClass;
+
+public class MailUtilTest extends TestingClass {
+
+	@Test
+	public void testSendSmtpMail_BugReport() {
+		String recipientsAddress = "bugreport at wikisquare.de";
+		String subject = "junit MailUtilTest";
+		String text = "MailUtilTest works";
+		String smtpUser = "bugreport";
+		String smtpCredential = "";
+		String smtpAuth = "";
+		String smtpHost = "mail.wikisquare.de";
+		String mailSenderAddress = "bugreport at wikisquare.de";
+		try {
+			MailUtil.sendSmtpMail(recipientsAddress, subject, text, smtpUser,
+					smtpCredential, smtpAuth, smtpHost, mailSenderAddress);
+		} catch (Exception e) {
+			log.info("failed to send a test-mail to bugreport at wikisquare.de", e);
+			fail(e.getMessage());
+		}
+	}
+
+	@Test
+	@Ignore
+	// Since the mailserver is now local to hudson, this test is not valid
+	// anymore
+	public void testSendSmtpMail_ToOtherEmail() {
+		String recipientsAddress = "christian.altenhofen at sidion.de";
+		String subject = "junit MailUtilTest";
+		String text = "Sending a test from bugreport at wikisquare.de to an external mail-address (christian.altenhofen at sidion.de) must fail!. Secure the mail server!";
+		String smtpUser = "bugreport";
+		String smtpCredential = "";
+		String smtpAuth = "";
+		String smtpHost = "mail.wikisquare.de";
+		String mailSenderAddress = "christian.altenhofen at sidion.de";
+		try {
+			MailUtil.sendSmtpMail(recipientsAddress, subject, text, smtpUser,
+					smtpCredential, smtpAuth, smtpHost, mailSenderAddress);
+			fail("Sending a test from bugreport at wikisquare.de to christian.altenhofen at sidion.de must fail!. Secure the mail server!");
+		} catch (Exception e) {
+		}
+
+		try {
+			MailUtil.sendSmtpMail(recipientsAddress, subject, text, smtpUser,
+					smtpCredential, smtpAuth, smtpHost, mailSenderAddress);
+			fail("Sending a test from bugreport at wikisquare.de as christian.altenhofen at sidion.de to christian.altenhofen at sidion.de must fail!. Secure the mail server!");
+		} catch (Exception e) {
+		}
+	}
+}
\ No newline at end of file


Property changes on: trunk/schmitzm-core/src/test/java/de/schmitzm/net/mail/MailUtilTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native

Added: trunk/schmitzm-core/src/test/java/de/schmitzm/net/mail/MailerTest.java
===================================================================
--- trunk/schmitzm-core/src/test/java/de/schmitzm/net/mail/MailerTest.java	2011-01-27 11:29:08 UTC (rev 1421)
+++ trunk/schmitzm-core/src/test/java/de/schmitzm/net/mail/MailerTest.java	2011-01-27 11:30:45 UTC (rev 1422)
@@ -0,0 +1,121 @@
+package de.schmitzm.net.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 de.schmitzm.testing.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 = "mail.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;
+	}
+}
\ No newline at end of file


Property changes on: trunk/schmitzm-core/src/test/java/de/schmitzm/net/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