Subversion Repositories javautils

Compare Revisions

No changes between revisions

Regard whitespace Rev 4 → Rev 5

/ViaThinkSoft Java Utils/test/com/iamcal/rfc3696/RFC3696EmailParserTest.java
0,0 → 1,101
package com.iamcal.rfc3696;
 
import static org.junit.Assert.*;
 
import java.io.File;
import java.io.IOException;
 
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
 
import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
 
public class RFC3696EmailParserTest {
static int errorCount;
private void checkXML(String xmlFile) throws ParserConfigurationException, SAXException, IOException {
File file = new File(xmlFile);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);
doc.getDocumentElement().normalize();
NodeList nodeLst = doc.getElementsByTagName("test");
for (int s = 0; s < nodeLst.getLength(); s++) {
 
Node fstNode = nodeLst.item(s);
 
if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
 
Element fstElmnt = (Element) fstNode;
 
String id;
String address;
boolean expected;
 
NodeList fstNmElmntLst;
Element fstNmElmnt;
NodeList fstNm;
String cont;
 
fstNmElmntLst = fstElmnt.getElementsByTagName("address");
fstNmElmnt = (Element) fstNmElmntLst.item(0);
fstNm = fstNmElmnt.getChildNodes();
try {
cont = ((Node) fstNm.item(0)).getNodeValue();
} catch (NullPointerException e) {
cont = "";
}
address = cont;
 
fstNmElmntLst = fstElmnt.getElementsByTagName("valid");
fstNmElmnt = (Element) fstNmElmntLst.item(0);
fstNm = fstNmElmnt.getChildNodes();
cont = ((Node) fstNm.item(0)).getNodeValue();
expected = Boolean.parseBoolean(cont);
 
fstNmElmntLst = fstElmnt.getElementsByTagName("id");
fstNmElmnt = (Element) fstNmElmntLst.item(0);
fstNm = fstNmElmnt.getChildNodes();
cont = ((Node) fstNm.item(0)).getNodeValue();
id = cont;
 
boolean actual = RFC3696EmailParser.isValidEmailAddress(address);
 
// assertEquals(expected, actual);
if (expected != actual) {
System.err.println("Mail Test #" + id + " FAILED! '"
+ address + "' is '" + actual + "' instead of '"
+ expected + "'!");
errorCount++;
}
}
}
}
 
@Test
public void performXMLTests() throws SAXException, IOException,
ParserConfigurationException {
 
// First: Null-Pointer Test
RFC3696EmailParser.isValidEmailAddress(null);
// Now check the XML testcases
checkXML("test/emailSayersTests.xml");
checkXML("test/emailExperimentalTests.xml");
 
if (errorCount > 0) {
System.err.println("==> " + errorCount + " ERRORS OCCOURED! <==");
fail();
}
}
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/ViaThinkSoft Java Utils/test/com/dominicsayers/isemail/PHPFunctionsTest.java
0,0 → 1,92
package com.dominicsayers.isemail;
 
import static org.junit.Assert.*;
 
import org.junit.Test;
 
public class PHPFunctionsTest {
 
@Test
public void preg_match_allTest() {
String[][] a = PHPFunctions.preg_match_all("hell(.)w(.)rld",
"helloworld, hellawirld, hellaworle, ...");
assertEquals(3, a.length);
assertEquals(2, a[0].length);
assertEquals("helloworld", a[0][0]);
assertEquals("hellawirld", a[0][1]);
assertEquals(2, a[1].length);
assertEquals("o", a[1][0]);
assertEquals("a", a[1][1]);
assertEquals(2, a[2].length);
assertEquals("o", a[2][0]);
assertEquals("i", a[2][1]);
}
@Test
public void preg_matchTest() {
assertEquals(1, PHPFunctions.preg_match("(h|e)(l|o)", "hl"));
assertEquals(1, PHPFunctions.preg_match("(h|e)(l|o)", "eo"));
assertEquals(1, PHPFunctions.preg_match("(h|e)(l|o)", "eol"));
assertEquals(1, PHPFunctions.preg_match("(h|e)(l|o)", "hol"));
assertEquals(1, PHPFunctions.preg_match("(h|e)(l|o)", "hoho"));
assertEquals(0, PHPFunctions.preg_match("(h|e)(l|o)", "iee"));
}
@Test
public void preg_splitTest() {
String[] s = PHPFunctions.preg_split("[\\s,]+", "hypertext language, programming");
assertEquals(3, s.length);
assertEquals("hypertext", s[0]);
assertEquals("language", s[1]);
assertEquals("programming", s[2]);
s = PHPFunctions.preg_split("\\.", ".hello.");
assertEquals(3, s.length);
assertEquals("", s[0]);
assertEquals("hello", s[1]);
assertEquals("", s[2]);
 
}
@Test
public void preg_match_to_arrayTest() {
String[] s = PHPFunctions.preg_match_to_array("(?i)^(?:http://)?([^/]+)", "http://www.php.net/index.html");
assertEquals(2, s.length);
assertEquals("http://www.php.net", s[0]);
assertEquals("www.php.net", s[1]);
s = PHPFunctions.preg_match_to_array("t(.st)", "test tost taste toast");
assertEquals(2, s.length);
assertEquals("test", s[0]);
assertEquals("est", s[1]);
}
@Test
public void substr1Test() {
assertEquals("3456789", PHPFunctions.substr("123456789", 2));
}
 
@Test
public void substr2Test() {
assertEquals("345", PHPFunctions.substr("123456789", 2, 3));
}
@Test
public void preg_repalceTest() {
String zeichenkette = "Der schnelle braune Fuchs sprang über den faulen Hund.";
zeichenkette = PHPFunctions.preg_replace("schnelle", "langsame", zeichenkette);
zeichenkette = PHPFunctions.preg_replace("braune", "schwarze", zeichenkette);
zeichenkette = PHPFunctions.preg_replace("Fuchs", "Bär", zeichenkette);
assertEquals("Der langsame schwarze Bär sprang über den faulen Hund.", zeichenkette);
}
 
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/ViaThinkSoft Java Utils/test/com/dominicsayers/isemail/IsEMailTest.java
0,0 → 1,102
package com.dominicsayers.isemail;
 
import static org.junit.Assert.*;
 
import java.io.File;
import java.io.IOException;
 
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
 
import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
 
public class IsEMailTest {
static int errorCount;
private void checkXML(String xmlFile) throws ParserConfigurationException, SAXException, IOException {
File file = new File(xmlFile);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);
doc.getDocumentElement().normalize();
NodeList nodeLst = doc.getElementsByTagName("test");
for (int s = 0; s < nodeLst.getLength(); s++) {
 
Node fstNode = nodeLst.item(s);
 
if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
 
Element fstElmnt = (Element) fstNode;
 
String id;
String address;
boolean expected;
 
NodeList fstNmElmntLst;
Element fstNmElmnt;
NodeList fstNm;
String cont;
 
fstNmElmntLst = fstElmnt.getElementsByTagName("address");
fstNmElmnt = (Element) fstNmElmntLst.item(0);
fstNm = fstNmElmnt.getChildNodes();
try {
cont = ((Node) fstNm.item(0)).getNodeValue();
} catch (NullPointerException e) {
cont = "";
}
address = cont;
 
fstNmElmntLst = fstElmnt.getElementsByTagName("valid");
fstNmElmnt = (Element) fstNmElmntLst.item(0);
fstNm = fstNmElmnt.getChildNodes();
cont = ((Node) fstNm.item(0)).getNodeValue();
expected = Boolean.parseBoolean(cont);
 
fstNmElmntLst = fstElmnt.getElementsByTagName("id");
fstNmElmnt = (Element) fstNmElmntLst.item(0);
fstNm = fstNmElmnt.getChildNodes();
cont = ((Node) fstNm.item(0)).getNodeValue();
id = cont;
 
boolean actual = IsEMail.is_email(address);
EMailSyntaxDiagnosis diagnosis = IsEMail.is_email_diagnosis(address);
 
// assertEquals(expected, actual);
if (expected != actual) {
System.err.println("Mail Test #" + id + " FAILED! '"
+ address + "' is '" + actual + "' ('" + diagnosis + "') instead of '"
+ expected + "'!");
errorCount++;
}
}
}
}
 
@Test
public void performXMLTests() throws SAXException, IOException,
ParserConfigurationException {
 
// First: Null-Pointer Test
IsEMail.is_email(null);
// Now check the XML testcases
checkXML("test/emailSayersTests.xml");
checkXML("test/emailExperimentalTests.xml");
 
if (errorCount > 0) {
System.err.println("==> " + errorCount + " ERRORS OCCOURED! <==");
fail();
}
}
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/ViaThinkSoft Java Utils/test/com/dominicsayers/isemail/MXLookupTest.java
0,0 → 1,57
package com.dominicsayers.isemail;
 
import static org.junit.Assert.*;
 
import javax.naming.NamingException;
 
import org.junit.Test;
 
public class MXLookupTest {
 
@Test
public void doLookupTest() throws NamingException {
 
// Achtung! Diese Testdaten können sich jederzeit ändern!
 
// Host='' ist möglicherweise der localhost...
assertEquals(0, DNSLookup.doLookup("", DNSType.MX));
// try {
// MXLookup.doLookup("");
// fail();
// } catch (NamingException e) {
// }
 
try {
DNSLookup.doLookup(null, DNSType.MX);
fail();
} catch (NullPointerException e) {
// Wir erwarten eine NullPointerException
}
 
try {
DNSLookup.doLookup("invalid", DNSType.MX); // Invalid defined TLD
fail();
} catch (NamingException e) {
}
 
try {
DNSLookup.doLookup("viathinkksoft.de", DNSType.MX); // Domain not
// assigned
fail();
} catch (NamingException e) {
}
 
try {
DNSLookup.doLookup("yahoo.ccc", DNSType.MX); // Invalid TLD
fail();
} catch (NamingException e) {
}
 
assertEquals(4, DNSLookup.doLookup("google.de", DNSType.MX));
assertEquals(2, DNSLookup.doLookup("yahoo.de", DNSType.MX));
assertEquals(2, DNSLookup.doLookup("example.de", DNSType.MX));
assertEquals(0, DNSLookup.doLookup("example.com", DNSType.MX));
assertEquals(1, DNSLookup.doLookup("ai", DNSType.MX));
assertEquals(4, DNSLookup.doLookup("whitehouse.gov", DNSType.MX));
}
}
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property