You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ta...@apache.org on 2015/03/09 14:40:44 UTC

svn commit: r1665232 - in /tika/trunk: ./ tika-core/src/test/java/org/apache/tika/parser/mock/ tika-parsers/src/test/java/org/apache/tika/parser/mock/ tika-parsers/src/test/resources/test-documents/mock/

Author: tallison
Date: Mon Mar  9 13:40:44 2015
New Revision: 1665232

URL: http://svn.apache.org/r1665232
Log:
TIKA-1553, add action types for printing to stdout and stderr

Modified:
    tika/trunk/CHANGES.txt
    tika/trunk/tika-core/src/test/java/org/apache/tika/parser/mock/MockParser.java
    tika/trunk/tika-parsers/src/test/java/org/apache/tika/parser/mock/MockParserTest.java
    tika/trunk/tika-parsers/src/test/resources/test-documents/mock/example.xml

Modified: tika/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/tika/trunk/CHANGES.txt?rev=1665232&r1=1665231&r2=1665232&view=diff
==============================================================================
--- tika/trunk/CHANGES.txt (original)
+++ tika/trunk/CHANGES.txt Mon Mar  9 13:40:44 2015
@@ -26,7 +26,7 @@ Release 1.8 - Current Development
     parse exceptions. (TIKA-1323)
 
   * Added MockParser for testing handling of exceptions, errors
-    and hangs in code that uses parsers. (TIKA-1533)
+    and hangs in code that uses parsers. (TIKA-1553)
 
   * The ForkParser service removed from Activator. Rollback of (TIKA-1354).
 

Modified: tika/trunk/tika-core/src/test/java/org/apache/tika/parser/mock/MockParser.java
URL: http://svn.apache.org/viewvc/tika/trunk/tika-core/src/test/java/org/apache/tika/parser/mock/MockParser.java?rev=1665232&r1=1665231&r2=1665232&view=diff
==============================================================================
--- tika/trunk/tika-core/src/test/java/org/apache/tika/parser/mock/MockParser.java (original)
+++ tika/trunk/tika-core/src/test/java/org/apache/tika/parser/mock/MockParser.java Mon Mar  9 13:40:44 2015
@@ -110,11 +110,23 @@ public class MockParser extends Abstract
             hang(action);
         } else if ("oom".equals(name)) {
             kabOOM();
+        } else if ("print_out".equals(name) || "print_err".equals(name)){
+            print(action, name);
         } else {
-            throw new RuntimeException("Didn't recognize mock action: "+name);
+            throw new IllegalArgumentException("Didn't recognize mock action: "+name);
         }
     }
 
+    private void print(Node action, String name) {
+        String content = action.getTextContent();
+        if ("print_out".equals(name)) {
+            System.out.println(content);
+        } else if ("print_err".equals(name)) {
+            System.err.println(content);
+        } else {
+            throw new IllegalArgumentException("must be print_out or print_err");
+        }
+    }
     private void hang(Node action) {
         boolean interruptible = true;
         boolean heavy = false;

Modified: tika/trunk/tika-parsers/src/test/java/org/apache/tika/parser/mock/MockParserTest.java
URL: http://svn.apache.org/viewvc/tika/trunk/tika-parsers/src/test/java/org/apache/tika/parser/mock/MockParserTest.java?rev=1665232&r1=1665231&r2=1665232&view=diff
==============================================================================
--- tika/trunk/tika-parsers/src/test/java/org/apache/tika/parser/mock/MockParserTest.java (original)
+++ tika/trunk/tika-parsers/src/test/java/org/apache/tika/parser/mock/MockParserTest.java Mon Mar  9 13:40:44 2015
@@ -21,8 +21,10 @@ import static junit.framework.TestCase.a
 import static junit.framework.TestCase.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.PrintStream;
 import java.util.Date;
 
 import org.apache.tika.TikaTest;
@@ -51,8 +53,27 @@ public class MockParserTest extends Tika
     @Test
     public void testExample() throws Exception {
         Metadata m = new Metadata();
-        assertThrowable("example.xml", m, IOException.class, "not another IOException");
-        assertMockParser(m);
+        PrintStream out = System.out;
+        PrintStream err = System.err;
+        ByteArrayOutputStream outBos = new ByteArrayOutputStream();
+        ByteArrayOutputStream errBos = new ByteArrayOutputStream();
+        PrintStream tmpOut = new PrintStream(outBos, true, IOUtils.UTF_8.toString());
+        PrintStream tmpErr = new PrintStream(errBos, true, IOUtils.UTF_8.toString());
+        System.setOut(tmpOut);
+        System.setErr(tmpErr);
+        try {
+            assertThrowable("example.xml", m, IOException.class, "not another IOException");
+            assertMockParser(m);
+        } finally {
+            System.setOut(out);
+            System.setErr(err);
+        }
+        String outString = new String(outBos.toByteArray(), IOUtils.UTF_8);
+        assertContains("writing to System.out", outString);
+
+        String errString = new String(errBos.toByteArray(), IOUtils.UTF_8);
+        assertContains("writing to System.err", errString);
+
     }
 
     @Test

Modified: tika/trunk/tika-parsers/src/test/resources/test-documents/mock/example.xml
URL: http://svn.apache.org/viewvc/tika/trunk/tika-parsers/src/test/resources/test-documents/mock/example.xml?rev=1665232&r1=1665231&r2=1665232&view=diff
==============================================================================
--- tika/trunk/tika-parsers/src/test/resources/test-documents/mock/example.xml (original)
+++ tika/trunk/tika-parsers/src/test/resources/test-documents/mock/example.xml Mon Mar  9 13:40:44 2015
@@ -29,10 +29,13 @@
     <!-- element is the name of the sax event to write, p=paragraph
         if the element is not specified, the default is <p> -->
     <write element="p">some content</write>
+    <!-- write something to System.out -->
+    <print_out>writing to System.out</print_out>
+    <!-- write something to System.err -->
+    <print_err>writing to System.err</print_err>
     <!-- hang
         millis: how many milliseconds to pause.  The actual hang time will probably
-            be a bit longer than the value specified.
-        heavy: whether or not the hang should do something computationally expensive.
+            be a bit longer than the value specified.        heavy: whether or not the hang should do something computationally expensive.
             If the value is false, this just does a Thread.sleep(millis).
             This attribute is optional, with default of heavy=false.
         pulse_millis: (required if "heavy" is true), how often to check to see