You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2011/04/07 18:54:15 UTC

svn commit: r1089944 - in /webservices/commons/trunk/modules/axiom/modules: axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/ axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/ axiom-testsuite/ axiom-testsuite/src/main/java/org/apache/axiom/ts/

Author: veithen
Date: Thu Apr  7 16:54:14 2011
New Revision: 1089944

URL: http://svn.apache.org/viewvc?rev=1089944&view=rev
Log:
Implemented a smarter way (based on LDAP filter expressions) to exclude test cases. This applies to tests that are executed several times with different parameters.

Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/pom.xml
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestCase.java
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestSuiteBuilder.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java?rev=1089944&r1=1089943&r2=1089944&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java Thu Apr  7 16:54:14 2011
@@ -23,6 +23,7 @@ import junit.framework.TestSuite;
 
 import org.apache.axiom.om.impl.dom.factory.OMDOMMetaFactory;
 import org.apache.axiom.ts.OMTestSuiteBuilder;
+import org.apache.axiom.ts.om.container.TestSerialize;
 import org.apache.axiom.ts.om.element.TestGetXMLStreamReaderCDATAEventFromElement;
 import org.apache.axiom.ts.om.element.TestGetXMLStreamReaderWithOMSourcedElementDescendant;
 import org.apache.axiom.ts.om.element.TestSetTextQName;
@@ -57,6 +58,13 @@ public class OMImplementationTest extend
         // WSCOMMONS-453
         builder.exclude(TestGetXMLStreamReaderWithOMSourcedElementDescendant.class);
         
+        // TODO: this case is not working because Axiom generates an XML declaration
+        //       but uses another charset encoding to serialize the document
+        builder.exclude(TestSerialize.class, "(&(file=iso-8859-1.xml)(container=document))");
+        
+        // TODO: this case is not working because Axiom doesn't serialize the DTD
+        builder.exclude(TestSerialize.class, "(&(file=spaces.xml)(container=document))");
+        
         return builder.build();
     }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.java?rev=1089944&r1=1089943&r2=1089944&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/OMImplementationTest.java Thu Apr  7 16:54:14 2011
@@ -23,6 +23,7 @@ import junit.framework.TestSuite;
 
 import org.apache.axiom.om.impl.llom.factory.OMLinkedListMetaFactory;
 import org.apache.axiom.ts.OMTestSuiteBuilder;
+import org.apache.axiom.ts.om.container.TestSerialize;
 import org.apache.axiom.ts.om.element.TestGetXMLStreamReaderWithOMSourcedElementDescendant;
 import org.apache.axiom.ts.om.node.TestInsertSiblingAfterOnChild;
 import org.apache.axiom.ts.om.node.TestInsertSiblingBeforeOnChild;
@@ -40,6 +41,13 @@ public class OMImplementationTest extend
         // WSCOMMONS-453
         builder.exclude(TestGetXMLStreamReaderWithOMSourcedElementDescendant.class);
         
+        // TODO: this case is not working because Axiom generates an XML declaration
+        //       but uses another charset encoding to serialize the document
+        builder.exclude(TestSerialize.class, "(&(file=iso-8859-1.xml)(container=document))");
+        
+        // TODO: this case is not working because Axiom doesn't serialize the DTD
+        builder.exclude(TestSerialize.class, "(&(file=spaces.xml)(container=document))");
+        
         return builder.build();
     }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/pom.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/pom.xml?rev=1089944&r1=1089943&r2=1089944&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/pom.xml (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/pom.xml Thu Apr  7 16:54:14 2011
@@ -61,6 +61,12 @@
             <version>${project.version}</version>
         </dependency>
         <dependency>
+            <!-- We use this only for LDAP like filters -->
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <version>4.2.0</version>
+        </dependency>
+        <dependency>
             <groupId>${project.groupId}</groupId>
             <artifactId>axiom-api</artifactId>
             <classifier>tests</classifier>

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestCase.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestCase.java?rev=1089944&r1=1089943&r2=1089944&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestCase.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestCase.java Thu Apr  7 16:54:14 2011
@@ -18,9 +18,8 @@
  */
 package org.apache.axiom.ts;
 
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.Dictionary;
+import java.util.Hashtable;
 
 import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMMetaFactory;
@@ -29,7 +28,7 @@ import org.custommonkey.xmlunit.XMLTestC
 
 public abstract class AxiomTestCase extends XMLTestCase {
     protected final OMMetaFactory metaFactory;
-    private final Map/*<String,String>*/ properties = new HashMap();
+    private final Dictionary/*<String,String>*/ properties = new Hashtable();
 
     public AxiomTestCase(OMMetaFactory metaFactory) {
         this.metaFactory = metaFactory;
@@ -41,8 +40,8 @@ public abstract class AxiomTestCase exte
         properties.put(name, value);
     }
     
-    public Map getTestProperties() {
-        return Collections.unmodifiableMap(properties);
+    public Dictionary getTestProperties() {
+        return properties;
     }
 
     protected void assertConsumed(OMContainer container) {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestSuiteBuilder.java?rev=1089944&r1=1089943&r2=1089944&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestSuiteBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/AxiomTestSuiteBuilder.java Thu Apr  7 16:54:14 2011
@@ -18,26 +18,55 @@
  */
 package org.apache.axiom.ts;
 
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
 
 import junit.framework.TestSuite;
 
 import org.apache.axiom.om.OMMetaFactory;
-import org.apache.axiom.ts.om.container.TestSerialize;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
 
 public abstract class AxiomTestSuiteBuilder {
+    private static class Exclude {
+        private final Class testClass;
+        private final Filter filter;
+        
+        public Exclude(Class testClass, Filter filter) {
+            this.testClass = testClass;
+            this.filter = filter;
+        }
+        
+        public boolean accept(AxiomTestCase test) {
+            return (testClass == null || test.getClass().equals(testClass))
+                    && (filter == null || filter.match(test.getTestProperties()));
+        }
+    }
+    
     protected final OMMetaFactory metaFactory;
-    private final Set/*<Class>*/ excludedTests = new HashSet();
+    private final List/*<Exclude>*/ excludes = new ArrayList();
     private TestSuite suite;
     
     public AxiomTestSuiteBuilder(OMMetaFactory metaFactory) {
         this.metaFactory = metaFactory;
     }
     
+    public final void exclude(Class testClass, String filter) {
+        try {
+            excludes.add(new Exclude(testClass, filter == null ? null : FrameworkUtil.createFilter(filter)));
+        } catch (InvalidSyntaxException ex) {
+            throw new IllegalArgumentException("Invalid filter expression", ex);
+        }
+    }
+    
     public final void exclude(Class testClass) {
-        excludedTests.add(testClass);
+        exclude(testClass, null);
+    }
+    
+    public final void exclude(String filter) {
+        exclude(null, filter);
     }
     
     protected abstract void addTests();
@@ -49,21 +78,11 @@ public abstract class AxiomTestSuiteBuil
     }
     
     protected final void addTest(AxiomTestCase test) {
-        if (!excludedTests.contains(test.getClass())) {
-            // TODO: quick & dirty hack; need to implement a generic way to exclude tests based on properties
-            if (test instanceof TestSerialize) {
-                Map props = test.getTestProperties();
-                if (props.get("file").equals("iso-8859-1.xml") && props.get("container").equals("document")) {
-                    // TODO: this case is not working because Axiom generates an XML declaration
-                    //       but uses another charset encoding to serialize the document
-                    return;
-                }
-                if (props.get("file").equals("spaces.xml") && props.get("container").equals("document")) {
-                    // TODO: this case is not working because Axiom doesn't serialize the DTD
-                    return;
-                }
+        for (Iterator it = excludes.iterator(); it.hasNext(); ) {
+            if (((Exclude)it.next()).accept(test)) {
+                return;
             }
-            suite.addTest(test);
         }
+        suite.addTest(test);
     }
 }