1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.james.jspf;
21
22 import org.apache.james.jspf.core.Logger;
23 import org.apache.james.jspf.impl.Log4JLogger;
24 import org.apache.james.jspf.tester.SPFYamlTestDescriptor;
25
26 import java.io.IOException;
27 import java.util.Iterator;
28 import java.util.List;
29
30 import junit.framework.Test;
31 import junit.framework.TestSuite;
32 import junit.textui.TestRunner;
33
34 public class RFC4408YamlTest extends AbstractYamlTest {
35
36 private static final String YAMLFILE2 = "rfc4408-tests-2008.08.yml";
37
38
39
40
41
42 public RFC4408YamlTest(String name) throws IOException {
43 super(name);
44 }
45
46 protected RFC4408YamlTest(SPFYamlTestDescriptor def) {
47 super(def);
48 }
49
50 protected RFC4408YamlTest(SPFYamlTestDescriptor def, String test) {
51 super(def, test);
52 }
53
54 protected String getFilename() {
55 return YAMLFILE2;
56 }
57
58 public static Test suite() throws IOException {
59 return new RFC4408Suite();
60 }
61
62 static class RFC4408Suite extends TestSuite {
63
64 public RFC4408Suite() throws IOException {
65 super();
66 try {
67 List tests = SPFYamlTestDescriptor.loadTests(YAMLFILE2);
68 Iterator i = tests.iterator();
69 while (i.hasNext()) {
70 SPFYamlTestDescriptor o = (SPFYamlTestDescriptor) i.next();
71 Iterator ttt = o.getTests().keySet().iterator();
72 while (ttt.hasNext()) {
73 addTest(new RFC4408YamlTest(o,(String) ttt.next()));
74 }
75 }
76 } catch (RuntimeException e) {
77 if ("Unable to load the file".equals(e.getMessage())) {
78 System.err.println("WARNING: RFC4408 tests disabled.");
79 System.err.println("The RFC4408 test-suite is not bundled with jspf due to licensing issues.");
80 System.err.println("You can download the yaml testsuite at the following url:");
81 System.err.println(" http://www.openspf.org/source/project/test-suite/");
82 System.err.println("and place an rfc4408-tests.yml file in the /src/test/resources/org/apache/james/jspf folder.");
83 }
84 }
85 }
86
87 }
88
89 protected void setLogger(Logger logger) {
90 this.log = logger;
91 }
92
93
94
95
96
97
98
99
100 public static void main(String[] args) throws Throwable {
101 Logger l = new Log4JLogger(org.apache.log4j.Logger.getLogger("ROOT"));
102
103 List tests = SPFYamlTestDescriptor.loadTests(YAMLFILE2);
104 Iterator i = tests.iterator();
105 while (i.hasNext()) {
106 SPFYamlTestDescriptor o = (SPFYamlTestDescriptor) i.next();
107 Iterator ttt = o.getTests().keySet().iterator();
108 while (ttt.hasNext()) {
109 RFC4408YamlTest t = new RFC4408YamlTest(o,(String) ttt.next());
110 t.setLogger(l);
111 TestRunner.run(t);
112 }
113 }
114 }
115
116 }