Subversion Repositories javautils

Compare Revisions

No changes between revisions

Regard whitespace Rev 2 → Rev 3

/ViaThinkSoft Java Utils/test/de/viathinksoft/utils/mail/sender/RawMailSenderPlainTextTest.java
0,0 → 1,342
package de.viathinksoft.utils.mail.sender;
 
import static org.junit.Assert.fail;
 
import java.net.ConnectException;
 
import javax.mail.AuthenticationFailedException;
import javax.mail.MessagingException;
import javax.mail.internet.AddressException;
 
import org.junit.Test;
 
import de.viathinksoft.utils.mail.EMailAddress;
import de.viathinksoft.utils.mail.InvalidMailAddressException;
import de.viathinksoft.utils.mail.sender.PlainTextMailSender;
 
public class RawMailSenderPlainTextTest {
@Test
public void testPostMailNullPointer() throws MessagingException,
AuthentificateDataIncompleteException, InvalidMailAddressException {
PlainTextMailSender mailsender = new PlainTextMailSender();
 
try {
mailsender.sendMail();
fail();
} catch (AddressException e) {
} catch (MessagingException e) {
// if ((e.getCause() != null) && (e.getCause().getNextException() ==
// ConnectException)) {
if ((e.getCause() != null)
&& (e.getCause().getClass() == ConnectException.class)) {
// Wir erwarten eine Exception, da wir davon ausgehen, dass auf
// Localhost kein SMTP-Server läuft!
} else {
e.printStackTrace();
fail();
}
}
 
// -----------------------------------------------------
 
try {
mailsender.setRecipient((EMailAddress)null);
fail();
} catch (InvalidMailAddressException e1) {
}
 
try {
mailsender.sendMail();
fail();
} catch (AddressException e) {
} catch (MessagingException e) {
// if ((e.getCause() != null) && (e.getCause().getNextException() ==
// ConnectException)) {
if ((e.getCause() != null)
&& (e.getCause().getClass() == ConnectException.class)) {
// Wir erwarten eine Exception, da wir davon ausgehen, dass auf
// Localhost kein SMTP-Server läuft!
} else {
e.printStackTrace();
fail();
}
}
// -----------------------------------------------------
 
try {
mailsender.setRecipient((String)null);
fail();
} catch (InvalidMailAddressException e1) {
}
 
try {
mailsender.sendMail();
fail();
} catch (AddressException e) {
} catch (MessagingException e) {
// if ((e.getCause() != null) && (e.getCause().getNextException() ==
// ConnectException)) {
if ((e.getCause() != null)
&& (e.getCause().getClass() == ConnectException.class)) {
// Wir erwarten eine Exception, da wir davon ausgehen, dass auf
// Localhost kein SMTP-Server läuft!
} else {
e.printStackTrace();
fail();
}
}
 
// -----------------------------------------------------
 
mailsender.setRecipient(TestConfiguration.getSpamAddress());
 
mailsender.setSmtpHost(null);
mailsender.setSmtpUsername(null);
mailsender.setSmtpPassword(null);
mailsender.setSmtpPort(-1);
 
try {
mailsender.sendMail();
fail();
} catch (MessagingException e) {
// if ((e.getCause() != null) && (e.getCause().getNextException() ==
// ConnectException)) {
if ((e.getCause() != null)
&& (e.getCause().getClass() == ConnectException.class)) {
// Wir erwarten eine Exception, da wir davon ausgehen, dass auf
// Localhost kein SMTP-Server läuft!
} else {
e.printStackTrace();
fail();
}
}
 
// -----------------------------------------------------
 
mailsender.setSmtpHost(TestConfiguration.getSmtpHost());
mailsender.setSmtpUsername(null);
mailsender.setSmtpPassword(null);
mailsender.setSmtpPort(TestConfiguration.getSmtpPort());
 
mailsender.setSmtpAuth(true);
// mailsender.setSmtpAuthUser(null);
// mailsender.setSmtpAuthPass(null);
 
try {
mailsender.sendMail();
fail();
} catch (AuthentificateDataIncompleteException e) {
}
 
// -----------------------------------------------------
 
mailsender.setSmtpAuth(false);
 
try {
mailsender.setMailFrom((EMailAddress)null);
fail();
} catch (InvalidMailAddressException e1) {
}
mailsender.setSubject(null);
mailsender.setMessage(null);
 
try {
mailsender.sendMail();
} catch (AuthenticationFailedException e) {
// Diese Fehlermeldung KANN vom SMTP geworfen werden. MUSS aber
// nicht.
}
// -----------------------------------------------------
 
try {
mailsender.setMailFrom((String)null);
fail();
} catch (InvalidMailAddressException e1) {
}
 
try {
mailsender.sendMail();
} catch (AuthenticationFailedException e) {
// Diese Fehlermeldung KANN vom SMTP geworfen werden. MUSS aber
// nicht.
}
 
// -----------------------------------------------------
 
mailsender.setSmtpAuth(true);
mailsender.setSmtpUsername(TestConfiguration.getSmtpUsername());
mailsender.setSmtpPassword(TestConfiguration.getSmtpPassword());
 
mailsender.sendMail();
}
 
@Test
public void testPostMailBlank()
throws AuthentificateDataIncompleteException, InvalidMailAddressException {
PlainTextMailSender mailsender = new PlainTextMailSender();
 
mailsender.setRecipient(TestConfiguration.getSpamAddress());
mailsender.setSubject("JUnit-Test 1");
mailsender.setMessage("JUnit-Test 1 von Compuglobal");
 
try {
mailsender.sendMail();
fail();
} catch (MessagingException e) {
// if ((e.getCause() != null) && (e.getCause().getNextException() ==
// ConnectException)) {
if ((e.getCause() != null)
&& (e.getCause().getClass() == ConnectException.class)) {
// Wir erwarten eine Exception, da wir davon ausgehen, dass auf
// Localhost kein SMTP-Server läuft!
} else {
e.printStackTrace();
fail();
}
}
}
 
@Test
public void testPostMailWithData() throws MessagingException,
AuthentificateDataIncompleteException, InvalidMailAddressException
{
PlainTextMailSender mailsender = new PlainTextMailSender();
 
mailsender.setSmtpHost(TestConfiguration.getSmtpHost());
mailsender.setSmtpPort(TestConfiguration.getSmtpPort());
 
mailsender.setRecipient(TestConfiguration.getSpamAddress());
mailsender.setSubject("JUnit-Test 2");
mailsender.setMessage("JUnit-Test 2 von Compuglobal");
 
try {
mailsender.sendMail();
} catch (AuthenticationFailedException e) {
// Diese Fehlermeldung KANN vom SMTP geworfen werden. MUSS aber
// nicht.
}
}
 
@Test
public void testPostMailWithDataAndOrigin() throws MessagingException,
AuthentificateDataIncompleteException, InvalidMailAddressException {
PlainTextMailSender mailsender = new PlainTextMailSender();
 
mailsender.setSmtpHost(TestConfiguration.getSmtpHost());
mailsender.setSmtpPort(TestConfiguration.getSmtpPort());
 
mailsender.setMailFrom(TestConfiguration.getMailFrom());
 
mailsender.setRecipient(TestConfiguration.getSpamAddress());
mailsender.setSubject("JUnit-Test 3");
mailsender.setMessage("JUnit-Test 3 von Compuglobal");
 
try {
mailsender.sendMail();
} catch (AuthenticationFailedException e) {
// Diese Fehlermeldung KANN vom SMTP geworfen werden. MUSS aber
// nicht.
}
}
 
@Test
public void testPostMailWithDataAndOriginAndSmtpAuthIncompleteUserAndPwd()
throws MessagingException, InvalidMailAddressException {
PlainTextMailSender mailsender = new PlainTextMailSender();
 
mailsender.setSmtpHost(TestConfiguration.getSmtpHost());
// mailsender.setSmtpUsername(TestConfiguration.getSmtpUsername());
// mailsender.setSmtpPassword(TestConfiguration.getSmtpPassword());
mailsender.setSmtpPort(TestConfiguration.getSmtpPort());
 
mailsender.setMailFrom(TestConfiguration.getMailFrom());
 
mailsender.setSmtpAuth(true);
 
mailsender.setRecipient(TestConfiguration.getSpamAddress());
mailsender.setSubject("JUnit-Test 4a");
mailsender.setMessage("JUnit-Test 4a von Compuglobal");
 
try {
mailsender.sendMail();
 
fail();
} catch (AuthentificateDataIncompleteException e) {
}
}
 
@Test
public void testPostMailWithDataAndOriginAndSmtpAuthIncompleteUser()
throws MessagingException, InvalidMailAddressException {
PlainTextMailSender mailsender = new PlainTextMailSender();
 
mailsender.setSmtpHost(TestConfiguration.getSmtpHost());
// mailsender.setSmtpUsername(TestConfiguration.getSmtpUsername());
mailsender.setSmtpPassword(TestConfiguration.getSmtpPassword());
mailsender.setSmtpPort(TestConfiguration.getSmtpPort());
 
mailsender.setMailFrom(TestConfiguration.getMailFrom());
 
mailsender.setSmtpAuth(true);
 
mailsender.setRecipient(TestConfiguration.getSpamAddress());
mailsender.setSubject("JUnit-Test 4b");
mailsender.setMessage("JUnit-Test 4b von Compuglobal");
 
try {
mailsender.sendMail();
 
fail();
} catch (AuthentificateDataIncompleteException e) {
}
}
 
@Test
public void testPostMailWithDataAndOriginAndSmtpAuthIncompletePwd()
throws MessagingException, InvalidMailAddressException {
PlainTextMailSender mailsender = new PlainTextMailSender();
 
mailsender.setSmtpHost(TestConfiguration.getSmtpHost());
mailsender.setSmtpUsername(TestConfiguration.getSmtpUsername());
// mailsender.setSmtpPassword(TestConfiguration.getSmtpPassword());
mailsender.setSmtpPort(TestConfiguration.getSmtpPort());
 
mailsender.setMailFrom(TestConfiguration.getMailFrom());
 
mailsender.setSmtpAuth(true);
 
mailsender.setRecipient(TestConfiguration.getSpamAddress());
mailsender.setSubject("JUnit-Test 4c");
mailsender.setMessage("JUnit-Test 4c von Compuglobal");
 
try {
mailsender.sendMail();
 
fail();
} catch (AuthentificateDataIncompleteException e) {
}
}
 
@Test
public void testPostMailWithDataAndOriginAndSmtpAuthComplete()
throws MessagingException, AuthentificateDataIncompleteException, InvalidMailAddressException {
PlainTextMailSender mailsender = new PlainTextMailSender();
 
mailsender.setSmtpHost(TestConfiguration.getSmtpHost());
mailsender.setSmtpUsername(TestConfiguration.getSmtpUsername());
mailsender.setSmtpPassword(TestConfiguration.getSmtpPassword());
mailsender.setSmtpPort(TestConfiguration.getSmtpPort());
 
mailsender.setMailFrom(TestConfiguration.getMailFrom());
 
mailsender.setSmtpAuth(true);
 
mailsender.setRecipient(TestConfiguration.getSpamAddress());
mailsender.setSubject("JUnit-Test 4d");
mailsender.setMessage("JUnit-Test 4d von Compuglobal");
 
mailsender.sendMail();
}
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/ViaThinkSoft Java Utils/test/de/viathinksoft/utils/mail/sender/TestConfiguration.java
0,0 → 1,37
package de.viathinksoft.utils.mail.sender;
 
// Statische Klasse, die unsere Konfiguration für Tests verwaltet.
// Ginge auch als Singleton
 
public final class TestConfiguration {
public static String getSpamAddress() {
// Gott habe Mitleid mit dem Eigentümer dieser E-Mail-Adresse...
return "b973768@owlpic.com";
 
// Eine Wegwerfadresse für manuelle Tests kann auf
// www.10minutemail.com erstellt werden.
}
public static String getSmtpHost() {
return "";
}
public static String getSmtpUsername() {
return "";
}
public static String getSmtpPassword() {
return "";
}
public static int getSmtpPort() {
return 25;
}
public static String getMailFrom() {
return getSpamAddress();
}
private TestConfiguration() {
}
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/ViaThinkSoft Java Utils/test/de/viathinksoft/utils/mail/EMailAddressTest.java
0,0 → 1,153
package de.viathinksoft.utils.mail;
 
import static org.junit.Assert.*;
 
import java.net.IDN;
 
import org.junit.Test;
 
public class EMailAddressTest {
private static final String ExamplePunycode = "xn--zckzah"; // Japanese IDN Test TLD
private static final String ExampleUnicode = IDN.toUnicode(ExamplePunycode);
@Test
public void testAddressParsing() throws InvalidMailAddressException {
try {
new EMailAddress(null);
fail();
} catch (InvalidMailAddressException e) {
}
try {
new EMailAddress("");
fail();
} catch (InvalidMailAddressException e) {
}
try {
new EMailAddress("bla");
fail();
} catch (InvalidMailAddressException e) {
}
EMailAddress a;
// a = new EMailAddress("@");
// assertEquals(a.getLocalPartUnicode(), "");
// // assertEquals(a.getLocalPartASCII(), "");
// assertEquals(a.getDomainPartUnicode(), "");
// assertEquals(a.getDomainPartASCII(), "");
// assertEquals(a.getTldUnicode(), "");
// assertEquals(a.getTldASCII(), "");
// assertEquals(a.getTldUnicode(), "");
// assertEquals(a.getMailAddressASCII(), "");
try {
new EMailAddress("@");
// Es wird InvalidMailAddressException anstelle von
// local="" und domain="" ausgegeben,
// weil .split nicht so wie .explode reagiert
fail();
} catch (InvalidMailAddressException e) {
}
 
a = new EMailAddress("local@domain");
assertEquals(a.getLocalPart(), "local");
// assertEquals(a.getLocalPartASCII(), "local");
assertEquals(a.getDomainPartUnicode(), "domain");
assertEquals(a.getDomainPartPunycode(), "domain");
assertEquals(a.getTldUnicode(), "");
assertEquals(a.getTldPunycode(), "");
assertEquals(a.toString(), "local@domain");
assertEquals(a.getMailAddressUnicode(), "local@domain");
assertEquals(a.getMailAddressPunycodedDomain(), "local@domain");
 
a = new EMailAddress("local@domain.tld");
assertEquals(a.getLocalPart(), "local");
// assertEquals(a.getlocalPartASCII(), "local");
assertEquals(a.getDomainPartUnicode(), "domain.tld");
assertEquals(a.getDomainPartPunycode(), "domain.tld");
assertEquals(a.getTldUnicode(), "tld");
assertEquals(a.getTldPunycode(), "tld");
assertEquals(a.toString(), "local@domain.tld");
assertEquals(a.getMailAddressUnicode(), "local@domain.tld");
assertEquals(a.getMailAddressPunycodedDomain(), "local@domain.tld");
a = new EMailAddress("local@"+ExampleUnicode+".jp");
assertEquals(a.getLocalPart(), "local");
// assertEquals(a.getlocalPartASCII(), "local");
assertEquals(a.getDomainPartUnicode(), ExampleUnicode+".jp");
assertEquals(a.getDomainPartPunycode(), ExamplePunycode+".jp");
assertEquals(a.getTldUnicode(), "jp");
assertEquals(a.getTldPunycode(), "jp");
assertEquals(a.getMailAddressUnicode(), "local@"+ExampleUnicode+".jp");
assertEquals(a.getMailAddressPunycodedDomain(), "local@"+ExamplePunycode+".jp");
EMailAddress.USE_UNICODE_AS_STANDARD = true;
assertEquals(a.toString(), "local@"+ExampleUnicode+".jp");
EMailAddress.USE_UNICODE_AS_STANDARD = false;
assertEquals(a.toString(), "local@"+ExamplePunycode+".jp");
 
a = new EMailAddress("local@example."+ExampleUnicode);
assertEquals(a.getLocalPart(), "local");
// assertEquals(a.getlocalPartASCII(), "local");
assertEquals(a.getDomainPartUnicode(), "example."+ExampleUnicode);
assertEquals(a.getDomainPartPunycode(), "example."+ExamplePunycode);
assertEquals(a.getTldUnicode(), ExampleUnicode);
assertEquals(a.getTldPunycode(), ExamplePunycode);
assertEquals(a.getMailAddressUnicode(), "local@example."+ExampleUnicode);
assertEquals(a.getMailAddressPunycodedDomain(), "local@example."+ExamplePunycode);
EMailAddress.USE_UNICODE_AS_STANDARD = true;
assertEquals(a.toString(), "local@example."+ExampleUnicode);
EMailAddress.USE_UNICODE_AS_STANDARD = false;
assertEquals(a.toString(), "local@example."+ExamplePunycode);
}
@Test
public void testIsUnicode() {
assertFalse(EMailAddress.isUnicode(null));
assertFalse(EMailAddress.isUnicode(""));
assertFalse(EMailAddress.isUnicode(ExamplePunycode));
assertTrue(EMailAddress.isUnicode(ExampleUnicode));
}
@Test
public void testIsPunycode() {
assertFalse(EMailAddress.isPunycode(null));
assertFalse(EMailAddress.isPunycode(""));
assertTrue(EMailAddress.isPunycode(ExamplePunycode));
assertFalse(EMailAddress.isPunycode(ExampleUnicode));
}
@Test
public void testClone() throws InvalidMailAddressException, CloneNotSupportedException {
EMailAddress a = new EMailAddress("local@example."+ExampleUnicode);
EMailAddress b = (EMailAddress) a.clone();
assertFalse(a == b);
assertTrue(a.equals(b));
assertTrue(b.equals(a));
assertEquals(a.getDomainPartPunycode(), b.getDomainPartPunycode());
assertEquals(a.getDomainPartUnicode(), b.getDomainPartUnicode());
assertEquals(a.getLocalPart(), b.getLocalPart());
assertEquals(a.getMailAddressPunycodedDomain(), b.getMailAddressPunycodedDomain());
assertEquals(a.getMailAddressUnicode(), b.getMailAddressUnicode());
assertEquals(a.getTldPunycode(), b.getTldPunycode());
assertEquals(a.getTldUnicode(), b.getTldUnicode());
EMailAddress.USE_UNICODE_AS_STANDARD = true;
assertEquals(a.toString(), b.toString());
EMailAddress.USE_UNICODE_AS_STANDARD = false;
assertEquals(a.toString(), b.toString());
}
@Test
public void testEquals() throws InvalidMailAddressException {
EMailAddress a = new EMailAddress("local@example."+ExampleUnicode);
EMailAddress b = new EMailAddress("local@example."+ExampleUnicode);
assertFalse(a == b);
assertTrue(a.equals(b));
assertTrue(b.equals(a));
}
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property