You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2009/01/22 21:09:04 UTC

svn commit: r736772 - in /webservices/commons/trunk/modules/axiom/modules/axiom-integration: ./ src/test/java/org/apache/axiom/om/impl/builder/ src/test/java/org/apache/axiom/om/impl/dom/jaxp/ src/test/java/org/apache/axiom/om/impl/jaxp/

Author: veithen
Date: Thu Jan 22 12:09:04 2009
New Revision: 736772

URL: http://svn.apache.org/viewvc?rev=736772&view=rev
Log:
Migrated integration tests to JUnit 4. Use parameterized tests to execute test cases against different implementations of XSLT, SAX, etc.

Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-integration/pom.xml
    webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/builder/SAXOMBuilderJAXBTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/builder/SAXOMBuilderSAXParserTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/builder/SAXOMBuilderXMLBeansTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/dom/jaxp/TransformerTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/dom/jaxp/ValidatorTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/jaxp/TransformerTest.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-integration/pom.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-integration/pom.xml?rev=736772&r1=736771&r2=736772&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-integration/pom.xml (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-integration/pom.xml Thu Jan 22 12:09:04 2009
@@ -45,6 +45,7 @@
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
+            <version>4.5</version>
         </dependency>
         <dependency>
             <groupId>xmlunit</groupId>

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/builder/SAXOMBuilderJAXBTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/builder/SAXOMBuilderJAXBTest.java?rev=736772&r1=736771&r2=736772&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/builder/SAXOMBuilderJAXBTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/builder/SAXOMBuilderJAXBTest.java Thu Jan 22 12:09:04 2009
@@ -19,6 +19,9 @@
 
 package org.apache.axiom.om.impl.builder;
 
+import static org.custommonkey.xmlunit.XMLAssert.assertXMLIdentical;
+import static org.custommonkey.xmlunit.XMLUnit.compareXML;
+
 import java.io.StringWriter;
 import java.util.ArrayList;
 import java.util.List;
@@ -28,9 +31,10 @@
 
 import org.apache.axiom.om.impl.builder.test.jaxb.Order;
 import org.apache.axiom.om.impl.builder.test.jaxb.OrderItem;
-import org.custommonkey.xmlunit.XMLTestCase;
+import org.junit.Test;
 
-public class SAXOMBuilderJAXBTest extends XMLTestCase {
+public class SAXOMBuilderJAXBTest {
+    @Test
     public void test() throws Exception {
         List<OrderItem> items = new ArrayList<OrderItem>(2);
         OrderItem item = new OrderItem();

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/builder/SAXOMBuilderSAXParserTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/builder/SAXOMBuilderSAXParserTest.java?rev=736772&r1=736771&r2=736772&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/builder/SAXOMBuilderSAXParserTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/builder/SAXOMBuilderSAXParserTest.java Thu Jan 22 12:09:04 2009
@@ -19,25 +19,49 @@
 
 package org.apache.axiom.om.impl.builder;
 
+import static org.custommonkey.xmlunit.XMLAssert.assertXMLIdentical;
+import static org.custommonkey.xmlunit.XMLUnit.compareXML;
+
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
 
 import javax.xml.parsers.SAXParserFactory;
 
 import org.apache.axiom.om.OMElement;
-import org.custommonkey.xmlunit.XMLTestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
 import org.xml.sax.InputSource;
 import org.xml.sax.XMLReader;
 
-public class SAXOMBuilderSAXParserTest extends XMLTestCase {
+@RunWith(Parameterized.class)
+public class SAXOMBuilderSAXParserTest {
+    private final SAXParserFactory factory;
+    
+    @Parameters
+    public static List<Object[]> parameters() {
+        return Arrays.asList(new Object[][] {
+                { org.apache.crimson.jaxp.SAXParserFactoryImpl.class },
+                { org.apache.xerces.jaxp.SAXParserFactoryImpl.class }
+        });
+    }
+    
+    public SAXOMBuilderSAXParserTest(Class<? extends SAXParserFactory> factoryClass) throws Exception {
+        this.factory = factoryClass.newInstance();
+    }
+
     private InputSource toInputSource(OMElement element) throws Exception {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         element.serialize(baos);
         return new InputSource(new ByteArrayInputStream(baos.toByteArray()));
     }
     
-    private void test(SAXParserFactory factory) throws Exception {
+    @Test
+    public void test() throws Exception {
         factory.setNamespaceAware(true);
         XMLReader reader = factory.newSAXParser().getXMLReader();
         SAXOMBuilder builder = new SAXOMBuilder();
@@ -56,12 +80,4 @@
             in.close();
         }
     }
-    
-    public void testCrimson() throws Exception {
-        test(new org.apache.crimson.jaxp.SAXParserFactoryImpl());
-    }
-    
-    public void testXerces() throws Exception {
-        test(new org.apache.xerces.jaxp.SAXParserFactoryImpl());
-    }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/builder/SAXOMBuilderXMLBeansTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/builder/SAXOMBuilderXMLBeansTest.java?rev=736772&r1=736771&r2=736772&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/builder/SAXOMBuilderXMLBeansTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/builder/SAXOMBuilderXMLBeansTest.java Thu Jan 22 12:09:04 2009
@@ -19,14 +19,18 @@
 
 package org.apache.axiom.om.impl.builder;
 
+import static org.custommonkey.xmlunit.XMLAssert.assertXMLIdentical;
+import static org.custommonkey.xmlunit.XMLUnit.compareXML;
+
 import java.io.StringWriter;
 
 import org.apache.axiom.om.impl.builder.test.xmlbeans.OrderDocument;
 import org.apache.axiom.om.impl.builder.test.xmlbeans.OrderDocument.Order;
 import org.apache.axiom.om.impl.builder.test.xmlbeans.OrderDocument.Order.Item;
-import org.custommonkey.xmlunit.XMLTestCase;
+import org.junit.Test;
 
-public class SAXOMBuilderXMLBeansTest extends XMLTestCase {
+public class SAXOMBuilderXMLBeansTest {
+    @Test
     public void test() throws Exception {
         OrderDocument document = OrderDocument.Factory.newInstance();
         Order order = document.addNewOrder();

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/dom/jaxp/TransformerTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/dom/jaxp/TransformerTest.java?rev=736772&r1=736771&r2=736772&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/dom/jaxp/TransformerTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/dom/jaxp/TransformerTest.java Thu Jan 22 12:09:04 2009
@@ -19,6 +19,9 @@
 
 package org.apache.axiom.om.impl.dom.jaxp;
 
+import java.util.Arrays;
+import java.util.List;
+
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.transform.Transformer;
@@ -28,11 +31,31 @@
 
 import org.custommonkey.xmlunit.XMLTestCase;
 import org.custommonkey.xmlunit.XMLUnit;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
+@RunWith(Parameterized.class)
 public class TransformerTest extends XMLTestCase {
-    private void testStylesheet(TransformerFactory tf) throws Exception {
+    private final TransformerFactory factory;
+    
+    @Parameters
+    public static List<Object[]> parameters() {
+        return Arrays.asList(new Object[][] {
+                { org.apache.xalan.processor.TransformerFactoryImpl.class },
+                { net.sf.saxon.TransformerFactoryImpl.class }
+        });
+    }
+    
+    public TransformerTest(Class<? extends TransformerFactory> factoryClass) throws Exception {
+        this.factory = factoryClass.newInstance();
+    }
+
+    @Test
+    public void testStylesheet() throws Exception {
         DocumentBuilderFactory dbf = new DOOMDocumentBuilderFactory();
         DocumentBuilder builder = dbf.newDocumentBuilder();
         Document input = builder.parse(TransformerTest.class.getResourceAsStream("input.xml"));
@@ -40,23 +63,16 @@
                 = builder.parse(TransformerTest.class.getResourceAsStream("stylesheet.xslt"));
         Document expected = builder.parse(TransformerTest.class.getResourceAsStream("output.xml"));
         Document actual = builder.newDocument();
-        Transformer transformer = tf.newTransformer(new DOMSource(stylesheet));
+        Transformer transformer = factory.newTransformer(new DOMSource(stylesheet));
         transformer.transform(new DOMSource(input), new DOMResult(actual));
         XMLUnit.setIgnoreWhitespace(true);
         assertXMLEqual(expected, actual);
     }
 
-    public void testStylesheetWithXalan() throws Exception {
-        testStylesheet(new org.apache.xalan.processor.TransformerFactoryImpl());
-    }
-    
-    public void testStyleSheetWithSaxon() throws Exception {
-        testStylesheet(new net.sf.saxon.TransformerFactoryImpl());
-    }
-    
     // This test failed with Saxon 8.9 because NodeImpl#compareDocumentPosition
     // threw an UnsupportedOperationException instead of a DOMException.
-    private void testIdentity(TransformerFactory tf) throws Exception {
+    @Test
+    public void testIdentity() throws Exception {
         DocumentBuilderFactory dbf = new DOOMDocumentBuilderFactory();
         DocumentBuilder builder = dbf.newDocumentBuilder();
         
@@ -71,17 +87,9 @@
         Document stylesheet
                 = builder.parse(TransformerTest.class.getResourceAsStream("identity.xslt"));
         Document output = builder.newDocument();
-        Transformer transformer = tf.newTransformer(new DOMSource(stylesheet));
+        Transformer transformer = factory.newTransformer(new DOMSource(stylesheet));
         transformer.transform(new DOMSource(document), new DOMResult(output));
         XMLUnit.setIgnoreWhitespace(false);
         assertXMLEqual(document, output);
     }
-
-    public void testIdentityWithXalan() throws Exception {
-        testIdentity(new org.apache.xalan.processor.TransformerFactoryImpl());
-    }
-    
-    public void testIdentityWithSaxon() throws Exception {
-        testIdentity(new net.sf.saxon.TransformerFactoryImpl());
-    }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/dom/jaxp/ValidatorTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/dom/jaxp/ValidatorTest.java?rev=736772&r1=736771&r2=736772&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/dom/jaxp/ValidatorTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/dom/jaxp/ValidatorTest.java Thu Jan 22 12:09:04 2009
@@ -27,10 +27,10 @@
 import javax.xml.validation.Validator;
 
 import org.apache.xerces.jaxp.validation.XMLSchemaFactory;
+import org.junit.Test;
 
-import junit.framework.TestCase;
-
-public class ValidatorTest extends TestCase {
+public class ValidatorTest {
+    @Test
     public void test() throws Exception {
         SchemaFactory factory = new XMLSchemaFactory();
         DocumentBuilderFactory dbf = new DOOMDocumentBuilderFactory();

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/jaxp/TransformerTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/jaxp/TransformerTest.java?rev=736772&r1=736771&r2=736772&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/jaxp/TransformerTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-integration/src/test/java/org/apache/axiom/om/impl/jaxp/TransformerTest.java Thu Jan 22 12:09:04 2009
@@ -19,8 +19,13 @@
 
 package org.apache.axiom.om.impl.jaxp;
 
+import static org.custommonkey.xmlunit.XMLAssert.assertXMLIdentical;
+import static org.custommonkey.xmlunit.XMLUnit.compareXML;
+
 import java.io.InputStream;
 import java.io.StringWriter;
+import java.util.Arrays;
+import java.util.List;
 
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerFactory;
@@ -28,14 +33,33 @@
 import javax.xml.transform.stream.StreamSource;
 
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
-import org.custommonkey.xmlunit.XMLTestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class TransformerTest {
+    private final TransformerFactory factory;
+    
+    @Parameters
+    public static List<Object[]> parameters() {
+        return Arrays.asList(new Object[][] {
+                { org.apache.xalan.processor.TransformerFactoryImpl.class },
+                { net.sf.saxon.TransformerFactoryImpl.class }
+        });
+    }
+    
+    public TransformerTest(Class<? extends TransformerFactory> factoryClass) throws Exception {
+        this.factory = factoryClass.newInstance();
+    }
 
-public class TransformerTest extends XMLTestCase {
     private InputStream getInput() {
         return TransformerTest.class.getResourceAsStream("test.xml");
     }
     
-    private void test(TransformerFactory factory) throws Exception {
+    @Test
+    public void test() throws Exception {
         Transformer transformer = factory.newTransformer();
         
         OMSource omSource = new OMSource(new StAXOMBuilder(getInput()).getDocumentElement());
@@ -49,12 +73,4 @@
         
         assertXMLIdentical(compareXML(out.toString(), omResult.getRootElement().toString()), true);
     }
-
-    public void testXalan() throws Exception {
-        test(new org.apache.xalan.processor.TransformerFactoryImpl());
-    }
-    
-    public void testSaxon() throws Exception {
-        test(new net.sf.saxon.TransformerFactoryImpl());
-    }
 }