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 2012/04/30 13:55:14 UTC

svn commit: r1332167 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/test/java/org/apache/axiom/om/ axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/ axiom-tests/src/test/java/org/apache/axiom/om/util/

Author: veithen
Date: Mon Apr 30 11:55:13 2012
New Revision: 1332167

URL: http://svn.apache.org/viewvc?rev=1332167&view=rev
Log:
No need to write to a temporary file if we don't read it afterwards. Just use NullOutputStream instead.

Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/AbstractTestCase.java
    webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMOutputTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/util/TextHelperTest.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/AbstractTestCase.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/AbstractTestCase.java?rev=1332167&r1=1332166&r2=1332167&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/AbstractTestCase.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/AbstractTestCase.java Mon Apr 30 11:55:13 2012
@@ -20,7 +20,6 @@
 package org.apache.axiom.om;
 
 import java.io.BufferedReader;
-import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -32,7 +31,6 @@ import javax.activation.DataSource;
 import javax.activation.URLDataSource;
 import javax.xml.parsers.DocumentBuilderFactory;
 
-import org.apache.axiom.attachments.Attachments;
 import org.custommonkey.xmlunit.XMLTestCase;
 import org.w3c.dom.Document;
 import org.w3c.dom.DocumentType;
@@ -40,10 +38,6 @@ import org.w3c.dom.DocumentType;
 /** Abstract base class for test cases. */
 public abstract class AbstractTestCase
         extends XMLTestCase {
-    protected String tempDir = "target" + File.separator + "generated" +
-            File.separator +
-            "temp";
-    
     public static final String[] soapFiles = {
         "emtyBodymessage.xml",
         "invalidMustUnderstandSOAP12.xml",
@@ -59,9 +53,6 @@ public abstract class AbstractTestCase
         "whitespacedMessage.xml"
     };
 
-    /** Basedir for all file I/O. Important when running tests from the reactor. */
-    public String basedir = System.getProperty("basedir");
-
     public AbstractTestCase() {
         this(null);
     }
@@ -69,10 +60,6 @@ public abstract class AbstractTestCase
     /** @param testName  */
     public AbstractTestCase(String testName) {
         super(testName);
-        if (basedir == null) {
-            basedir = new File(".").getAbsolutePath();
-        }
-        tempDir = new File(basedir, tempDir).getAbsolutePath();
     }
 
     public DataSource getTestResourceDataSource(String relativePath) {
@@ -113,14 +100,6 @@ public abstract class AbstractTestCase
         }
     }
 
-    public File getTempOutputFile(String filename) {
-        File f = new File(tempDir);
-        if (!f.exists()) {
-            f.mkdirs();
-        }
-        return new File(f, filename);
-    }
-
     public static Document toDocumentWithoutDTD(InputStream in) throws Exception {
         Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in);
         DocumentType docType = doc.getDoctype();

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMOutputTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMOutputTest.java?rev=1332167&r1=1332166&r2=1332167&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMOutputTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMOutputTest.java Mon Apr 30 11:55:13 2012
@@ -20,7 +20,6 @@
 package org.apache.axiom.om.impl.llom;
 
 import org.apache.axiom.attachments.ByteArrayDataSource;
-import org.apache.axiom.om.AbstractTestCase;
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMElement;
@@ -28,27 +27,20 @@ import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.OMOutputFormat;
 import org.apache.axiom.om.OMText;
+import org.apache.commons.io.output.NullOutputStream;
 
 import javax.activation.DataHandler;
-import java.io.File;
-import java.io.FileOutputStream;
 
-public class OMOutputTest extends AbstractTestCase {
+import junit.framework.TestCase;
+
+public class OMOutputTest extends TestCase {
 
     /** @param testName  */
     public OMOutputTest(String testName) {
         super(testName);
     }
 
-    String outFileName;
-
-    String outBase64FileName;
-
-    OMElement envelope;
-
-    File outMTOMFile;
-
-    File outBase64File;
+    private OMElement envelope;
 
     /*
      * @see TestCase#setUp()
@@ -57,11 +49,6 @@ public class OMOutputTest extends Abstra
         super.setUp();
         DataHandler dataHandler;
 
-        outFileName = "OMSerializeMTOMOut.txt";
-        outBase64FileName = "OMSerializeBase64Out.xml";
-        outMTOMFile = getTempOutputFile(outFileName);
-        outBase64File = getTempOutputFile(outBase64FileName);
-
         OMFactory fac = OMAbstractFactory.getOMFactory();
 
         OMNamespace soap = fac.createOMNamespace(
@@ -91,26 +78,13 @@ public class OMOutputTest extends Abstra
         text.addChild(textData);
     }
 
-    /*
-     * @see TestCase#tearDown()
-     */
-    protected void tearDown() throws Exception {
-        super.tearDown();
-        if (this.outMTOMFile.exists()) {
-            this.outMTOMFile.delete();
-        }
-        if (this.outBase64File.exists()) {
-            this.outBase64File.delete();
-        }
-    }
-
     public void testComplete() throws Exception {
         OMOutputFormat mtomOutputFormat = new OMOutputFormat();
         mtomOutputFormat.setDoOptimize(true);
         OMOutputFormat baseOutputFormat = new OMOutputFormat();
         baseOutputFormat.setDoOptimize(false);
 
-        envelope.serializeAndConsume(new FileOutputStream(outBase64File), baseOutputFormat);
-        envelope.serializeAndConsume(new FileOutputStream(outMTOMFile), mtomOutputFormat);
+        envelope.serializeAndConsume(new NullOutputStream(), baseOutputFormat);
+        envelope.serializeAndConsume(new NullOutputStream(), mtomOutputFormat);
     }
 }
\ No newline at end of file

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/util/TextHelperTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/util/TextHelperTest.java?rev=1332167&r1=1332166&r2=1332167&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/util/TextHelperTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/util/TextHelperTest.java Mon Apr 30 11:55:13 2012
@@ -19,7 +19,6 @@
 package org.apache.axiom.om.util;
 
 import org.apache.axiom.attachments.impl.BufferUtils;
-import org.apache.axiom.om.AbstractTestCase;
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMText;
@@ -36,11 +35,13 @@ import java.io.FileOutputStream;
 import java.io.InputStream;
 import java.io.SequenceInputStream;
 
+import junit.framework.TestCase;
+
 /**
  * Validate TextHelper code
  */
-public class TextHelperTest extends AbstractTestCase {
-
+public class TextHelperTest extends TestCase {
+    private File tempDir;
     private File file;
     private FileInputStream fis;
     private static final long SIZE = 101 * 1024; // More than the threshold
@@ -55,7 +56,9 @@ public class TextHelperTest extends Abst
 
     protected void setUp() throws Exception {
         super.setUp();
-        file = File.createTempFile("TextHelperTest", "txt");
+        tempDir = new File(System.getProperty("basedir", "."), "target/temp");
+        tempDir.mkdirs();
+        file = new File(tempDir, "TextHelperTest.txt");
         FileOutputStream fos = new FileOutputStream(file);
         BufferedOutputStream bos = new BufferedOutputStream(fos);
         for (long i = 0; i < SIZE; i++) {
@@ -147,7 +150,7 @@ public class TextHelperTest extends Abst
         OMFactory factory = OMAbstractFactory.getOMFactory();
         OMText omText = TextHelper.toOMText(b, 0, b.length, 
                                             factory, true,
-                                            this.tempDir);
+                                            tempDir.getAbsolutePath());
         
         // Ensure text is optimized
         assertTrue(omText != null);