You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ba...@apache.org on 2008/07/27 23:44:34 UTC
svn commit: r680195 -
/james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/
Author: bago
Date: Sun Jul 27 14:44:34 2008
New Revision: 680195
URL: http://svn.apache.org/viewvc?rev=680195&view=rev
Log:
Extract Yaml loading logic/dto to its own class (SPFYamlTestDescriptor)
Added:
james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/SPFYamlTestDescriptor.java (with props)
Modified:
james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/AbstractYamlTest.java
james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/MailZoneAsynchronousYamlTest.java
james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/MailZoneYamlTest.java
james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/RFC4408AsynchronousYamlTest.java
james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/RFC4408YamlTest.java
james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/SPFYamlTest.java
james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/YamlTest.java
Modified: james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/AbstractYamlTest.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/AbstractYamlTest.java?rev=680195&r1=680194&r2=680195&view=diff
==============================================================================
--- james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/AbstractYamlTest.java (original)
+++ james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/AbstractYamlTest.java Sun Jul 27 14:44:34 2008
@@ -42,9 +42,6 @@
import org.apache.james.jspf.parser.RFC4408SPF1Parser;
import org.apache.james.jspf.wiring.WiringService;
import org.apache.james.jspf.wiring.WiringServiceException;
-import org.jvyaml.Constructor;
-import org.jvyaml.DefaultYAMLFactory;
-import org.jvyaml.YAMLFactory;
import org.xbill.DNS.Cache;
import org.xbill.DNS.DClass;
import org.xbill.DNS.ExtendedNonblockingResolver;
@@ -56,12 +53,7 @@
import org.xbill.DNS.SimpleResolver;
import org.xbill.DNS.TextParseException;
-import java.io.BufferedReader;
-import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -69,7 +61,6 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
-import java.util.Set;
import junit.framework.TestCase;
@@ -114,7 +105,7 @@
protected abstract String getFilename();
protected List internalLoadTests(String filename) throws IOException {
- return loadTests(filename);
+ return SPFYamlTestDescriptor.loadTests(filename);
}
protected AbstractYamlTest(String name) throws IOException {
@@ -141,33 +132,6 @@
// assertNotNull(test);
}
- public static List loadTests(String filename) throws IOException {
- List tests = new ArrayList();
-
- InputStream is = SPFYamlTest.class.getResourceAsStream(filename);
-
- if (is != null) {
- Reader br = new BufferedReader(new InputStreamReader(is));
- YAMLFactory fact = new DefaultYAMLFactory();
-
- Constructor ctor = fact.createConstructor(fact.createComposer(fact.createParser(fact.createScanner(br)),fact.createResolver()));
- int i = 1;
- while(ctor.checkData()) {
- Object o = ctor.getData();
- if (o instanceof HashMap) {
- HashMap m = (HashMap) o;
- SPFYamlTestDescriptor ts = new SPFYamlTestDescriptor(m, i);
- tests.add(ts);
- }
- i++;
- }
-
- return tests;
- } else {
- throw new FileNotFoundException("Unable to load the file");
- }
- }
-
protected void runTest() throws Throwable {
if (log == null) {
@@ -532,44 +496,4 @@
return spfExecutorType;
}
- protected static class SPFYamlTestDescriptor {
- private String comment;
- private HashMap tests;
- private HashMap zonedata;
-
- public SPFYamlTestDescriptor(HashMap source, int i) {
- this.setComment((String) source.get("description"));
- if (this.getComment() == null) {
- this.setComment("Test #"+i);
- }
- this.setTests((HashMap) source.get("tests"));
- this.setZonedata((HashMap) source.get("zonedata"));
- }
-
- public String getComment() {
- return comment;
- }
- public void setComment(String comment) {
- this.comment = comment;
- }
- public HashMap getTests() {
- return tests;
- }
- public void setTests(HashMap tests) {
- this.tests = tests;
- }
- public HashMap getZonedata() {
- return zonedata;
- }
- public void setZonedata(HashMap zonedata) {
- this.zonedata = new HashMap();
- Set keys = zonedata.keySet();
- for (Iterator i = keys.iterator(); i.hasNext(); ) {
- String hostname = (String) i.next();
- String lowercase = hostname.toLowerCase(Locale.US);
- this.zonedata.put(lowercase, zonedata.get(hostname));
- }
- }
- }
-
}
\ No newline at end of file
Modified: james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/MailZoneAsynchronousYamlTest.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/MailZoneAsynchronousYamlTest.java?rev=680195&r1=680194&r2=680195&view=diff
==============================================================================
--- james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/MailZoneAsynchronousYamlTest.java (original)
+++ james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/MailZoneAsynchronousYamlTest.java Sun Jul 27 14:44:34 2008
@@ -56,10 +56,6 @@
return new MailZoneAsynchronousSuite();
}
- protected List internalLoadTests(String filename) throws IOException {
- return loadTests(filename);
- }
-
protected DNSService getDNSService() {
DNSService dns = super.getDNSService();
// Remove record limits for this test
@@ -80,7 +76,7 @@
public MailZoneAsynchronousSuite() throws IOException {
super();
- List tests = loadTests(YAMLFILE2);
+ List tests = SPFYamlTestDescriptor.loadTests(YAMLFILE2);
Iterator i = tests.iterator();
while (i.hasNext()) {
SPFYamlTestDescriptor o = (SPFYamlTestDescriptor) i.next();
Modified: james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/MailZoneYamlTest.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/MailZoneYamlTest.java?rev=680195&r1=680194&r2=680195&view=diff
==============================================================================
--- james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/MailZoneYamlTest.java (original)
+++ james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/MailZoneYamlTest.java Sun Jul 27 14:44:34 2008
@@ -56,10 +56,6 @@
return new MailZoneSuite();
}
- protected List internalLoadTests(String filename) throws IOException {
- return loadTests(filename);
- }
-
protected DNSService getDNSService() {
DNSService dns = super.getDNSService();
// Remove record limits for this test
@@ -71,7 +67,7 @@
public MailZoneSuite() throws IOException {
super();
- List tests = loadTests(YAMLFILE2);
+ List tests = SPFYamlTestDescriptor.loadTests(YAMLFILE2);
Iterator i = tests.iterator();
while (i.hasNext()) {
SPFYamlTestDescriptor o = (SPFYamlTestDescriptor) i.next();
Modified: james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/RFC4408AsynchronousYamlTest.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/RFC4408AsynchronousYamlTest.java?rev=680195&r1=680194&r2=680195&view=diff
==============================================================================
--- james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/RFC4408AsynchronousYamlTest.java (original)
+++ james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/RFC4408AsynchronousYamlTest.java Sun Jul 27 14:44:34 2008
@@ -57,10 +57,6 @@
return new RFC4408AsynchronousSuite();
}
- protected List internalLoadTests(String filename) throws IOException {
- return loadTests(filename);
- }
-
protected int getDnsServiceMockStyle() {
return FAKE_SERVER;
}
@@ -73,7 +69,7 @@
public RFC4408AsynchronousSuite() throws IOException {
super();
- List tests = loadTests(YAMLFILE2);
+ List tests = SPFYamlTestDescriptor.loadTests(YAMLFILE2);
Iterator i = tests.iterator();
while (i.hasNext()) {
SPFYamlTestDescriptor o = (SPFYamlTestDescriptor) i.next();
@@ -97,7 +93,7 @@
public static void main(String[] args) throws Throwable {
Logger l = new Log4JLogger(org.apache.log4j.Logger.getLogger("ROOT"));
- List tests = loadTests(YAMLFILE2);
+ List tests = SPFYamlTestDescriptor.loadTests(YAMLFILE2);
Iterator i = tests.iterator();
while (i.hasNext()) {
SPFYamlTestDescriptor o = (SPFYamlTestDescriptor) i.next();
Modified: james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/RFC4408YamlTest.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/RFC4408YamlTest.java?rev=680195&r1=680194&r2=680195&view=diff
==============================================================================
--- james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/RFC4408YamlTest.java (original)
+++ james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/RFC4408YamlTest.java Sun Jul 27 14:44:34 2008
@@ -58,16 +58,12 @@
return new RFC4408Suite();
}
- protected List internalLoadTests(String filename) throws IOException {
- return loadTests(filename);
- }
-
static class RFC4408Suite extends TestSuite {
public RFC4408Suite() throws IOException {
super();
try {
- List tests = loadTests(YAMLFILE2);
+ List tests = SPFYamlTestDescriptor.loadTests(YAMLFILE2);
Iterator i = tests.iterator();
while (i.hasNext()) {
SPFYamlTestDescriptor o = (SPFYamlTestDescriptor) i.next();
@@ -103,7 +99,7 @@
public static void main(String[] args) throws Throwable {
Logger l = new Log4JLogger(org.apache.log4j.Logger.getLogger("ROOT"));
- List tests = loadTests(YAMLFILE2);
+ List tests = SPFYamlTestDescriptor.loadTests(YAMLFILE2);
Iterator i = tests.iterator();
while (i.hasNext()) {
SPFYamlTestDescriptor o = (SPFYamlTestDescriptor) i.next();
Modified: james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/SPFYamlTest.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/SPFYamlTest.java?rev=680195&r1=680194&r2=680195&view=diff
==============================================================================
--- james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/SPFYamlTest.java (original)
+++ james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/SPFYamlTest.java Sun Jul 27 14:44:34 2008
@@ -47,13 +47,11 @@
return new SPFSuite();
}
-
-
static class SPFSuite extends TestSuite {
public SPFSuite() throws IOException {
super();
- List tests = loadTests(YAMLFILE);
+ List tests = SPFYamlTestDescriptor.loadTests(YAMLFILE);
Iterator i = tests.iterator();
while (i.hasNext()) {
SPFYamlTestDescriptor o = (SPFYamlTestDescriptor) i.next();
Added: james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/SPFYamlTestDescriptor.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/SPFYamlTestDescriptor.java?rev=680195&view=auto
==============================================================================
--- james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/SPFYamlTestDescriptor.java (added)
+++ james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/SPFYamlTestDescriptor.java Sun Jul 27 14:44:34 2008
@@ -0,0 +1,109 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.jspf;
+
+import org.jvyaml.Constructor;
+import org.jvyaml.DefaultYAMLFactory;
+import org.jvyaml.YAMLFactory;
+
+import java.io.BufferedReader;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+
+/**
+ * Describe a test loaded from a YAML file using the format
+ * described in the OpenSPF testsuite.
+ */
+public class SPFYamlTestDescriptor {
+ private String comment;
+ private HashMap tests;
+ private HashMap zonedata;
+
+ public SPFYamlTestDescriptor(HashMap source, int i) {
+ this.setComment((String) source.get("description"));
+ if (this.getComment() == null) {
+ this.setComment("Test #"+i);
+ }
+ this.setTests((HashMap) source.get("tests"));
+ this.setZonedata((HashMap) source.get("zonedata"));
+ }
+
+ public String getComment() {
+ return comment;
+ }
+ public void setComment(String comment) {
+ this.comment = comment;
+ }
+ public HashMap getTests() {
+ return tests;
+ }
+ public void setTests(HashMap tests) {
+ this.tests = tests;
+ }
+ public HashMap getZonedata() {
+ return zonedata;
+ }
+ public void setZonedata(HashMap zonedata) {
+ this.zonedata = new HashMap();
+ Set keys = zonedata.keySet();
+ for (Iterator i = keys.iterator(); i.hasNext(); ) {
+ String hostname = (String) i.next();
+ String lowercase = hostname.toLowerCase(Locale.US);
+ this.zonedata.put(lowercase, zonedata.get(hostname));
+ }
+ }
+
+ public static List loadTests(String filename) throws IOException {
+ List tests = new ArrayList();
+
+ InputStream is = SPFYamlTest.class.getResourceAsStream(filename);
+
+ if (is != null) {
+ Reader br = new BufferedReader(new InputStreamReader(is));
+ YAMLFactory fact = new DefaultYAMLFactory();
+
+ Constructor ctor = fact.createConstructor(fact.createComposer(fact.createParser(fact.createScanner(br)),fact.createResolver()));
+ int i = 1;
+ while(ctor.checkData()) {
+ Object o = ctor.getData();
+ if (o instanceof HashMap) {
+ HashMap m = (HashMap) o;
+ SPFYamlTestDescriptor ts = new SPFYamlTestDescriptor(m, i);
+ tests.add(ts);
+ }
+ i++;
+ }
+
+ return tests;
+ } else {
+ throw new FileNotFoundException("Unable to load the file");
+ }
+ }
+
+}
\ No newline at end of file
Propchange: james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/SPFYamlTestDescriptor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/SPFYamlTestDescriptor.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/YamlTest.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/YamlTest.java?rev=680195&r1=680194&r2=680195&view=diff
==============================================================================
--- james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/YamlTest.java (original)
+++ james/jspf/branches/multimodule-proposal/resolver/src/test/java/org/apache/james/jspf/YamlTest.java Sun Jul 27 14:44:34 2008
@@ -50,15 +50,11 @@
return new BasicSuite();
}
- protected List internalLoadTests(String filename) throws IOException {
- return loadTests(filename);
- }
-
static class BasicSuite extends TestSuite {
public BasicSuite() throws IOException {
super();
- List tests = loadTests(YAMLFILE2);
+ List tests = SPFYamlTestDescriptor.loadTests(YAMLFILE2);
Iterator i = tests.iterator();
while (i.hasNext()) {
SPFYamlTestDescriptor o = (SPFYamlTestDescriptor) i.next();
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org