1   /****************************************************************
2    * Licensed to the Apache Software Foundation (ASF) under one   *
3    * or more contributor license agreements.  See the NOTICE file *
4    * distributed with this work for additional information        *
5    * regarding copyright ownership.  The ASF licenses this file   *
6    * to you under the Apache License, Version 2.0 (the            *
7    * "License"); you may not use this file except in compliance   *
8    * with the License.  You may obtain a copy of the License at   *
9    *                                                              *
10   *   http://www.apache.org/licenses/LICENSE-2.0                 *
11   *                                                              *
12   * Unless required by applicable law or agreed to in writing,   *
13   * software distributed under the License is distributed on an  *
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
15   * KIND, either express or implied.  See the License for the    *
16   * specific language governing permissions and limitations      *
17   * under the License.                                           *
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 RFC4408AsynchronousYamlTest extends RFC4408YamlTest {
35  
36      private static final String YAMLFILE2 = "rfc4408-tests.yml";
37      /**
38       * @param name
39       * @throws IOException
40       */
41      public RFC4408AsynchronousYamlTest(String name) throws IOException {
42          super(name);
43      }
44  
45      protected RFC4408AsynchronousYamlTest(SPFYamlTestDescriptor def) {
46          super(def);
47      }
48  
49      protected RFC4408AsynchronousYamlTest(SPFYamlTestDescriptor def, String test) {
50          super(def, test);
51      }
52  
53      protected String getFilename() {
54          return YAMLFILE2;
55      }
56  
57      public static Test suite() throws IOException {
58          return new RFC4408AsynchronousSuite();
59      }
60  
61      protected int getDnsServiceMockStyle() {
62          return FAKE_SERVER;
63      }
64  
65      protected int getSpfExecutorType() {
66          return STAGED_EXECUTOR_MULTITHREADED;
67      }
68  
69      static class RFC4408AsynchronousSuite extends TestSuite {
70  
71          public RFC4408AsynchronousSuite() throws IOException {
72              super();
73              List tests = SPFYamlTestDescriptor.loadTests(YAMLFILE2);
74              Iterator i = tests.iterator();
75              while (i.hasNext()) {
76                  SPFYamlTestDescriptor o = (SPFYamlTestDescriptor) i.next();
77                  addTest(new RFC4408AsynchronousYamlTest(o));
78              }
79          }
80  
81      }
82      
83      protected void setLogger(Logger logger) {
84          this.log = logger;
85      }
86      
87      /**
88       * This method has been created for spf spec people to let them better read the
89       * output of our tests against their yaml file
90       * 
91       * @param args
92       * @throws Throwable 
93       */
94      public static void main(String[] args) throws Throwable {
95          Logger l = new Log4JLogger(org.apache.log4j.Logger.getLogger("ROOT"));
96  
97          List tests = SPFYamlTestDescriptor.loadTests(YAMLFILE2);
98          Iterator i = tests.iterator();
99          while (i.hasNext()) {
100             SPFYamlTestDescriptor o = (SPFYamlTestDescriptor) i.next();
101             Iterator ttt = o.getTests().keySet().iterator();
102             while (ttt.hasNext()) {
103                 RFC4408AsynchronousYamlTest t = new RFC4408AsynchronousYamlTest(o,(String) ttt.next());
104                 t.setLogger(l);
105                 TestRunner.run(t);
106             }
107         }
108     }
109 
110 }