Rev 17 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 17 | Rev 24 | ||
---|---|---|---|
1 | package de.viathinksoft.utils.mail.syntaxchecker; |
1 | package de.viathinksoft.utils.mail.syntaxchecker; |
2 | 2 | ||
3 | import static org.junit.Assert.*; |
3 | import static org.junit.Assert.*; |
4 | 4 | ||
5 | import java.io.File; |
5 | import java.io.File; |
6 | import java.io.IOException; |
6 | import java.io.IOException; |
7 | 7 | ||
8 | import javax.xml.parsers.DocumentBuilder; |
8 | import javax.xml.parsers.DocumentBuilder; |
9 | import javax.xml.parsers.DocumentBuilderFactory; |
9 | import javax.xml.parsers.DocumentBuilderFactory; |
10 | import javax.xml.parsers.ParserConfigurationException; |
10 | import javax.xml.parsers.ParserConfigurationException; |
11 | 11 | ||
12 | import org.junit.Test; |
12 | import org.junit.Test; |
13 | import org.w3c.dom.Document; |
13 | import org.w3c.dom.Document; |
14 | import org.w3c.dom.Element; |
14 | import org.w3c.dom.Element; |
15 | import org.w3c.dom.Node; |
15 | import org.w3c.dom.Node; |
16 | import org.w3c.dom.NodeList; |
16 | import org.w3c.dom.NodeList; |
17 | import org.xml.sax.SAXException; |
17 | import org.xml.sax.SAXException; |
18 | 18 | ||
19 | import de.viathinksoft.utils.mail.address.EMailAddress; |
19 | import de.viathinksoft.utils.mail.address.EMailAddress; |
20 | 20 | ||
- | 21 | @Deprecated |
|
21 | public class MailSyntaxCheckerTest { |
22 | public class MailSyntaxCheckerTest { |
22 | 23 | ||
23 | static int errorCount; |
24 | static int errorCount; |
24 | 25 | ||
25 | private void checkXML(String xmlFile) throws ParserConfigurationException, SAXException, IOException { |
26 | private void checkXML(String xmlFile) throws ParserConfigurationException, SAXException, IOException { |
26 | File file = new File(xmlFile); |
27 | File file = new File(xmlFile); |
27 | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
28 | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
28 | DocumentBuilder db = dbf.newDocumentBuilder(); |
29 | DocumentBuilder db = dbf.newDocumentBuilder(); |
29 | Document doc = db.parse(file); |
30 | Document doc = db.parse(file); |
30 | doc.getDocumentElement().normalize(); |
31 | doc.getDocumentElement().normalize(); |
31 | NodeList nodeLst = doc.getElementsByTagName("test"); |
32 | NodeList nodeLst = doc.getElementsByTagName("test"); |
32 | 33 | ||
33 | for (int s = 0; s < nodeLst.getLength(); s++) { |
34 | for (int s = 0; s < nodeLst.getLength(); s++) { |
34 | 35 | ||
35 | Node fstNode = nodeLst.item(s); |
36 | Node fstNode = nodeLst.item(s); |
36 | 37 | ||
37 | if (fstNode.getNodeType() == Node.ELEMENT_NODE) { |
38 | if (fstNode.getNodeType() == Node.ELEMENT_NODE) { |
38 | 39 | ||
39 | Element fstElmnt = (Element) fstNode; |
40 | Element fstElmnt = (Element) fstNode; |
40 | 41 | ||
41 | String id; |
42 | String id; |
42 | String address; |
43 | String address; |
43 | boolean expected; |
44 | boolean expected; |
44 | 45 | ||
45 | NodeList fstNmElmntLst; |
46 | NodeList fstNmElmntLst; |
46 | Element fstNmElmnt; |
47 | Element fstNmElmnt; |
47 | NodeList fstNm; |
48 | NodeList fstNm; |
48 | String cont; |
49 | String cont; |
49 | 50 | ||
50 | fstNmElmntLst = fstElmnt.getElementsByTagName("address"); |
51 | fstNmElmntLst = fstElmnt.getElementsByTagName("address"); |
51 | fstNmElmnt = (Element) fstNmElmntLst.item(0); |
52 | fstNmElmnt = (Element) fstNmElmntLst.item(0); |
52 | fstNm = fstNmElmnt.getChildNodes(); |
53 | fstNm = fstNmElmnt.getChildNodes(); |
53 | try { |
54 | try { |
54 | cont = ((Node) fstNm.item(0)).getNodeValue(); |
55 | cont = ((Node) fstNm.item(0)).getNodeValue(); |
55 | } catch (NullPointerException e) { |
56 | } catch (NullPointerException e) { |
56 | cont = ""; |
57 | cont = ""; |
57 | } |
58 | } |
58 | address = cont; |
59 | address = cont; |
59 | 60 | ||
60 | fstNmElmntLst = fstElmnt.getElementsByTagName("valid"); |
61 | fstNmElmntLst = fstElmnt.getElementsByTagName("valid"); |
61 | fstNmElmnt = (Element) fstNmElmntLst.item(0); |
62 | fstNmElmnt = (Element) fstNmElmntLst.item(0); |
62 | fstNm = fstNmElmnt.getChildNodes(); |
63 | fstNm = fstNmElmnt.getChildNodes(); |
63 | cont = ((Node) fstNm.item(0)).getNodeValue(); |
64 | cont = ((Node) fstNm.item(0)).getNodeValue(); |
64 | expected = Boolean.parseBoolean(cont); |
65 | expected = Boolean.parseBoolean(cont); |
65 | 66 | ||
66 | fstNmElmntLst = fstElmnt.getElementsByTagName("id"); |
67 | fstNmElmntLst = fstElmnt.getElementsByTagName("id"); |
67 | fstNmElmnt = (Element) fstNmElmntLst.item(0); |
68 | fstNmElmnt = (Element) fstNmElmntLst.item(0); |
68 | fstNm = fstNmElmnt.getChildNodes(); |
69 | fstNm = fstNmElmnt.getChildNodes(); |
69 | cont = ((Node) fstNm.item(0)).getNodeValue(); |
70 | cont = ((Node) fstNm.item(0)).getNodeValue(); |
70 | id = cont; |
71 | id = cont; |
71 | 72 | ||
72 | boolean actual = MailSyntaxChecker.isMailValid(address); |
73 | boolean actual = MailSyntaxChecker.isMailValid(address); |
73 | 74 | ||
74 | // assertEquals(expected, actual); |
75 | // assertEquals(expected, actual); |
75 | if (expected != actual) { |
76 | if (expected != actual) { |
76 | System.err.println("Mail Test #" + id + " FAILED! '" |
77 | System.err.println("Mail Test #" + id + " FAILED! '" |
77 | + address + "' is '" + actual + "' instead of '" |
78 | + address + "' is '" + actual + "' instead of '" |
78 | + expected + "'!"); |
79 | + expected + "'!"); |
79 | errorCount++; |
80 | errorCount++; |
80 | } |
81 | } |
81 | } |
82 | } |
82 | } |
83 | } |
83 | } |
84 | } |
84 | 85 | ||
85 | @Test |
86 | @Test |
86 | public void performXMLTests() throws SAXException, IOException, |
87 | public void performXMLTests() throws SAXException, IOException, |
87 | ParserConfigurationException { |
88 | ParserConfigurationException { |
88 | 89 | ||
89 | // First: Null-Pointer Test |
90 | // First: Null-Pointer Test |
90 | 91 | ||
91 | try { |
92 | try { |
92 | MailSyntaxChecker.isMailValid((String)null); |
93 | MailSyntaxChecker.isMailValid((String)null); |
93 | fail(); |
94 | fail(); |
94 | } catch (NullPointerException e) { |
95 | } catch (NullPointerException e) { |
95 | } |
96 | } |
96 | 97 | ||
97 | try { |
98 | try { |
98 | MailSyntaxChecker.isMailValid((EMailAddress)null); |
99 | MailSyntaxChecker.isMailValid((EMailAddress)null); |
99 | fail(); |
100 | fail(); |
100 | } catch (NullPointerException e) { |
101 | } catch (NullPointerException e) { |
101 | } |
102 | } |
102 | 103 | ||
103 | // Now check the XML testcases |
104 | // Now check the XML testcases |
104 | 105 | ||
105 | checkXML("test/eMailTests/SayersTests.xml"); |
106 | checkXML("test/eMailTests/SayersTests.xml"); |
106 | checkXML("test/eMailTests/emailExperimentalTests.xml"); |
107 | checkXML("test/eMailTests/emailExperimentalTests.xml"); |
107 | 108 | ||
108 | if (errorCount > 0) { |
109 | if (errorCount > 0) { |
109 | System.err.println("==> " + errorCount + " ERRORS OCCOURED! <=="); |
110 | System.err.println("==> " + errorCount + " ERRORS OCCOURED! <=="); |
110 | fail(); |
111 | fail(); |
111 | } |
112 | } |
112 | } |
113 | } |
113 | } |
114 | } |
114 | 115 |