Author: veithen Date: Thu Feb 5 09:39:38 2009 New Revision: 741057 URL: http://svn.apache.org/viewvc?rev=741057&view=rev Log: WSCOMMONS-419: Load test files as classpath resources instead of accessing them directly (part 2).
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/IteratorTest.java webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMDTDTest.java webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/SpacesTest.java webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/ElementImportTest.java webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/serializer/OMSerializerTest.java webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/util/OMElementHelperTest.java webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/SOAP11FaultImplConversionTest.java webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/SOAPFactoryTest.java webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/WrongEnvelopeNamespaceTester.java webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/xpath/XPathTestBase.java Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/IteratorTest.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/IteratorTest.java?rev=741057&r1=741056&r2=741057&view=diff ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/IteratorTest.java (original) +++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/IteratorTest.java Thu Feb 5 09:39:38 2009 @@ -24,10 +24,9 @@ import org.apache.axiom.soap.SOAP11Constants; import javax.activation.DataHandler; -import javax.activation.FileDataSource; +import javax.activation.DataSource; import javax.xml.namespace.QName; import javax.xml.stream.XMLInputFactory; -import java.io.File; import java.util.Iterator; public class IteratorTest extends AbstractTestCase { @@ -184,20 +183,20 @@ } private OMElement createSampleXMLForTesting() throws Exception { - File imageSource = new File("test-resources/mtom/img/test.jpg"); + String imageSource = "mtom/img/test.jpg"; OMFactory fac = OMAbstractFactory.getOMFactory(); OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my"); OMElement data = fac.createOMElement("mtomSample", omNs); OMElement image = fac.createOMElement("image", omNs); - FileDataSource dataSource = new FileDataSource(imageSource); + DataSource dataSource = getTestResourceDataSource(imageSource); DataHandler expectedDH = new DataHandler(dataSource); OMText textData = fac.createOMText(expectedDH, true); image.addChild(textData); OMElement imageName = fac.createOMElement("fileName", omNs); - imageName.setText(imageSource.getAbsolutePath()); + imageName.setText(imageSource); data.addChild(image); data.addChild(imageName); Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMDTDTest.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMDTDTest.java?rev=741057&r1=741056&r2=741057&view=diff ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMDTDTest.java (original) +++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMDTDTest.java Thu Feb 5 09:39:38 2009 @@ -19,7 +19,6 @@ package org.apache.axiom.om; -import junit.framework.TestCase; import org.apache.axiom.om.impl.builder.StAXOMBuilder; import org.apache.axiom.om.util.StAXUtils; @@ -27,17 +26,16 @@ import javax.xml.stream.XMLStreamReader; import java.io.ByteArrayOutputStream; -import java.io.FileInputStream; import java.io.InputStream; import java.util.Iterator; -public class OMDTDTest extends TestCase { +public class OMDTDTest extends AbstractTestCase { private OMDocument document; protected void setUp() throws Exception { try { - StAXOMBuilder stAXOMBuilder = new StAXOMBuilder("test-resources/xml/dtd.xml"); + StAXOMBuilder stAXOMBuilder = new StAXOMBuilder(getTestResource("xml/dtd.xml")); document = this.document = stAXOMBuilder.getDocument(); } catch (Exception e) { e.printStackTrace(); @@ -83,7 +81,7 @@ // that intentionally points to a non existing URL. With a network // detached reader this should not produce errors. - InputStream is = new FileInputStream("test-resources/xml/web_w_dtd2.xml"); + InputStream is = getTestResource("xml/web_w_dtd2.xml"); XMLStreamReader reader = StAXUtils.createNetworkDetachedXMLStreamReader(is); StAXOMBuilder builder = new StAXOMBuilder(reader); OMElement root = builder.getDocumentElement(); Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/SpacesTest.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/SpacesTest.java?rev=741057&r1=741056&r2=741057&view=diff ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/SpacesTest.java (original) +++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/SpacesTest.java Thu Feb 5 09:39:38 2009 @@ -22,7 +22,6 @@ import org.apache.axiom.om.impl.builder.StAXOMBuilder; import org.apache.axiom.om.impl.llom.factory.OMXMLBuilderFactory; import org.custommonkey.xmlunit.Diff; -import org.custommonkey.xmlunit.XMLTestCase; import org.w3c.dom.Document; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -34,22 +33,21 @@ import javax.xml.stream.XMLStreamException; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Iterator; -public class SpacesTest extends XMLTestCase { - private static final String filePath = "test-resources/xml/spaces.xml"; - private static final String filePath2 = "test-resources/xml/spaces2.xml"; +public class SpacesTest extends AbstractTestCase { + private static final String filePath = "xml/spaces.xml"; + private static final String filePath2 = "xml/spaces2.xml"; private OMElement rootElement; public void testCData() throws Exception { - checkOMConformance(new FileInputStream(filePath)); + checkOMConformance(getTestResource(filePath)); } private void checkOMConformance(InputStream iStream) throws Exception { @@ -70,7 +68,7 @@ InputSource resultXML = new InputSource(new InputStreamReader( new ByteArrayInputStream(baos.toByteArray()))); - Document dom1 = newDocument(new InputSource(new FileInputStream(file))); + Document dom1 = newDocument(new InputSource(getTestResource(file))); Document dom2 = newDocument(resultXML); Diff diff = compareXML(dom1, dom2); assertXMLEqual(diff, true); Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/ElementImportTest.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/ElementImportTest.java?rev=741057&r1=741056&r2=741057&view=diff ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/ElementImportTest.java (original) +++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/dom/ElementImportTest.java Thu Feb 5 09:39:38 2009 @@ -20,6 +20,8 @@ package org.apache.axiom.om.impl.dom; import junit.framework.TestCase; + +import org.apache.axiom.om.AbstractTestCase; import org.apache.axiom.om.OMElement; import org.apache.axiom.om.OMTestUtils; import org.apache.axiom.om.impl.dom.factory.OMDOMFactory; @@ -27,16 +29,15 @@ import org.w3c.dom.Node; import javax.xml.parsers.DocumentBuilderFactory; -import java.io.FileInputStream; /** @author Ruchith Fernando (ruchith.ferna...@gmail.com) */ -public class ElementImportTest extends TestCase { +public class ElementImportTest extends AbstractTestCase { public void testImport() throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); Document doc = dbf.newDocumentBuilder().parse( - new FileInputStream("test-resources/xml/sigEncr.xml")); + getTestResource("xml/sigEncr.xml")); Node n = new OMDOMFactory().getDocument().importNode(doc.getDocumentElement(), true); OMTestUtils.compare(doc.getDocumentElement(), (OMElement) n); } Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/serializer/OMSerializerTest.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/serializer/OMSerializerTest.java?rev=741057&r1=741056&r2=741057&view=diff ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/serializer/OMSerializerTest.java (original) +++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/serializer/OMSerializerTest.java Thu Feb 5 09:39:38 2009 @@ -152,7 +152,7 @@ public void testDefaultNsSerialization() { try { - StAXOMBuilder builder = new StAXOMBuilder("test-resources/xml/original.xml"); + StAXOMBuilder builder = new StAXOMBuilder(getTestResource("xml/original.xml")); String xml = builder.getDocumentElement().toString(); assertEquals("There shouldn't be any xmlns=\"\"", -1, xml.indexOf("xmlns=\"\"")); } catch (Exception e) { Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/util/OMElementHelperTest.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/util/OMElementHelperTest.java?rev=741057&r1=741056&r2=741057&view=diff ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/util/OMElementHelperTest.java (original) +++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/util/OMElementHelperTest.java Thu Feb 5 09:39:38 2009 @@ -19,27 +19,25 @@ package org.apache.axiom.om.util; +import org.apache.axiom.om.AbstractTestCase; import org.apache.axiom.om.OMAbstractFactory; import org.apache.axiom.om.OMElement; import org.apache.axiom.om.impl.builder.StAXOMBuilder; import org.apache.axiom.om.impl.dom.DOOMAbstractFactory; -import org.custommonkey.xmlunit.XMLTestCase; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -public class OMElementHelperTest extends XMLTestCase { +public class OMElementHelperTest extends AbstractTestCase { - private String testXMLFilePath = "test-resources/soap/soapmessage.xml"; + private String testXMLFilePath = "soap/soapmessage.xml"; public void testImportOMElement() { try { XMLStreamReader xmlStreamReader = XMLInputFactory.newInstance() - .createXMLStreamReader(new FileInputStream(testXMLFilePath)); + .createXMLStreamReader(getTestResource(testXMLFilePath)); OMElement documentElement = new StAXOMBuilder(OMAbstractFactory.getOMFactory(), xmlStreamReader) .getDocumentElement(); @@ -59,9 +57,6 @@ } catch (XMLStreamException e) { e.printStackTrace(); fail(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - fail(); } } } Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/SOAP11FaultImplConversionTest.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/SOAP11FaultImplConversionTest.java?rev=741057&r1=741056&r2=741057&view=diff ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/SOAP11FaultImplConversionTest.java (original) +++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/SOAP11FaultImplConversionTest.java Thu Feb 5 09:39:38 2009 @@ -19,22 +19,21 @@ package org.apache.axiom.soap; -import junit.framework.TestCase; +import org.apache.axiom.om.AbstractTestCase; import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamReader; -import java.io.FileInputStream; import java.io.InputStream; -public class SOAP11FaultImplConversionTest extends TestCase { +public class SOAP11FaultImplConversionTest extends AbstractTestCase { - private String soap11FaulXmlPath = "test-resources/soap/soap11/soapfault2.xml"; + private String soap11FaulXmlPath = "soap/soap11/soapfault2.xml"; public void testConversion() { try { - InputStream is = new FileInputStream(soap11FaulXmlPath); + InputStream is = getTestResource(soap11FaulXmlPath); XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE) ; XMLStreamReader reader = xmlInputFactory.createXMLStreamReader(is); Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/SOAPFactoryTest.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/SOAPFactoryTest.java?rev=741057&r1=741056&r2=741057&view=diff ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/SOAPFactoryTest.java (original) +++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/SOAPFactoryTest.java Thu Feb 5 09:39:38 2009 @@ -19,20 +19,18 @@ package org.apache.axiom.soap; -import junit.framework.TestCase; +import org.apache.axiom.om.AbstractTestCase; import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -public class SOAPFactoryTest extends TestCase { +public class SOAPFactoryTest extends AbstractTestCase { - protected static final String SOAP11_FILE_NAME = "test-resources/soap/soap11/soap11message.xml"; - protected static final String SOAP12_FILE_NAME = "test-resources/soap/soap12message.xml"; + protected static final String SOAP11_FILE_NAME = "soap/soap11/soap11message.xml"; + protected static final String SOAP12_FILE_NAME = "soap/soap12message.xml"; private static Log log = LogFactory.getLog(SOAPFactoryTest.class); public void testSOAPFactory() { @@ -40,18 +38,16 @@ try { SOAPEnvelope soapEnvelope = (SOAPEnvelope) new StAXSOAPModelBuilder(XMLInputFactory.newInstance(). - createXMLStreamReader(new FileInputStream(SOAP11_FILE_NAME)), null) + createXMLStreamReader(getTestResource(SOAP11_FILE_NAME)), null) .getDocumentElement(); assertTrue(soapEnvelope != null); soapEnvelope = (SOAPEnvelope) new StAXSOAPModelBuilder(XMLInputFactory.newInstance(). - createXMLStreamReader(new FileInputStream(SOAP12_FILE_NAME)), null) + createXMLStreamReader(getTestResource(SOAP12_FILE_NAME)), null) .getDocumentElement(); assertTrue(soapEnvelope != null); } catch (XMLStreamException e) { fail("Can not load soap envelope. Exception = " + e); - } catch (FileNotFoundException e) { - fail("Given XML can not be found. Exception = " + e); } } Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/WrongEnvelopeNamespaceTester.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/WrongEnvelopeNamespaceTester.java?rev=741057&r1=741056&r2=741057&view=diff ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/WrongEnvelopeNamespaceTester.java (original) +++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/WrongEnvelopeNamespaceTester.java Thu Feb 5 09:39:38 2009 @@ -19,27 +19,23 @@ package org.apache.axiom.soap; -import junit.framework.TestCase; +import org.apache.axiom.om.AbstractTestCase; import org.apache.axiom.om.impl.builder.StAXBuilder; import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamReader; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -public class WrongEnvelopeNamespaceTester extends TestCase { +public class WrongEnvelopeNamespaceTester extends AbstractTestCase { public void testCode() { try { - String filename = "test-resources/soap/wrongEnvelopeNamespace.xml"; + String filename = "soap/wrongEnvelopeNamespace.xml"; XMLStreamReader xmlr = XMLInputFactory.newInstance() - .createXMLStreamReader(new FileInputStream(filename)); + .createXMLStreamReader(getTestResource(filename)); StAXBuilder builder = new StAXSOAPModelBuilder(xmlr, null); //exception here fail("Builder must fail here due to wrong SOAP namespace"); } catch (SOAPProcessingException e) { assertTrue(true); - } catch (FileNotFoundException e) { - fail("Only SOAPProcessingException can be thrown here"); } catch (Exception e) { fail("Only SOAPProcessingException can be thrown here"); } Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/xpath/XPathTestBase.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/xpath/XPathTestBase.java?rev=741057&r1=741056&r2=741057&view=diff ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/xpath/XPathTestBase.java (original) +++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/xpath/XPathTestBase.java Thu Feb 5 09:39:38 2009 @@ -38,15 +38,26 @@ import org.jaxen.pattern.Pattern; import org.jaxen.saxpath.helpers.XPathReaderFactory; +import java.net.MalformedURLException; +import java.net.URL; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public abstract class XPathTestBase extends TestCase { protected static String VAR_URI = "http://jaxen.org/test-harness/var"; - protected static String TESTS_ROOT = "test-resources/"; + protected static String TESTS_ROOT; protected static String TESTS_XML = TESTS_ROOT + "xml/test/tests.xml"; + static { + URL testsXmlUrl = XPathTestBase.class.getClassLoader().getResource("xml/test/tests.xml"); + try { + TESTS_ROOT = new URL(testsXmlUrl, "../..").toExternalForm(); + } catch (MalformedURLException ex) { + throw new RuntimeException(ex); + } + } + protected static boolean verbose = false; protected static boolean debug = false; private ContextSupport contextSupport;