commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bur...@apache.org
Subject svn commit: r151685 - in jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser: impl/CaptureOutputFeedParserListener.java test/DebugPerformance.java test/TestComments.java
Date Mon, 07 Feb 2005 06:14:29 GMT
Author: burton
Date: Sun Feb  6 22:14:27 2005
New Revision: 151685

URL: http://svn.apache.org/viewcvs?view=rev&rev=151685
Log:
unit tests for comments RSS and RSS 2.0 comments

Added:
    jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/impl/CaptureOutputFeedParserListener.java
    jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/test/DebugPerformance.java
    jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/test/TestComments.java

Added: jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/impl/CaptureOutputFeedParserListener.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/impl/CaptureOutputFeedParserListener.java?view=auto&rev=151685
==============================================================================
--- jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/impl/CaptureOutputFeedParserListener.java
(added)
+++ jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/impl/CaptureOutputFeedParserListener.java
Sun Feb  6 22:14:27 2005
@@ -0,0 +1,61 @@
+/*
+ * Copyright 1999,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.feedparser.impl;
+
+import org.apache.commons.feedparser.*;
+import org.jdom.*;
+
+import java.util.*;
+import java.io.*;
+
+/**
+ * Code which can run a parse but capture the output to a string to verify
+ * certain methods were called via greping the output.  This is ONLY for unit
+ * tests.
+ * 
+ * @author <a href="mailto:burton@apache.org">Kevin A. Burton (burtonator)</a>
+ * @version $Id: DebugFeedParserListener.java 151683 2005-02-07 05:54:38Z burton $
+ */
+public class CaptureOutputFeedParserListener
+    extends DebugFeedParserListener {
+
+    public CaptureOutputFeedParserListener() {
+        super( new CapturePrintStream() );
+    }
+
+    public String toString() {
+
+        CapturePrintStream cps = (CapturePrintStream)out;
+        ByteArrayOutputStream bos = (ByteArrayOutputStream)cps.getOutputStream();
+
+        return bos.toString();
+        
+    }
+    
+}
+
+class CapturePrintStream extends PrintStream {
+
+    public CapturePrintStream() {
+        super( new ByteArrayOutputStream() );
+    }
+
+    public OutputStream getOutputStream() {
+        return out;
+    }
+    
+}
\ No newline at end of file

Added: jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/test/DebugPerformance.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/test/DebugPerformance.java?view=auto&rev=151685
==============================================================================
--- jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/test/DebugPerformance.java
(added)
+++ jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/test/DebugPerformance.java
Sun Feb  6 22:14:27 2005
@@ -0,0 +1,161 @@
+/*
+ * Copyright 1999,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.feedparser.test;
+
+import java.applet.*;
+import java.util.*;
+import java.io.*;
+import java.net.*;
+import java.security.*;
+import java.lang.reflect.*;
+
+import junit.framework.*;
+
+import org.apache.commons.feedparser.*;
+import org.apache.commons.feedparser.impl.*;
+import org.apache.commons.feedparser.network.*;
+
+import javax.xml.parsers.*;
+import org.xml.sax.*;
+import org.xml.sax.helpers.*;
+
+/**
+ *
+ * @author <a href="mailto:burton@peerfear.org">Kevin A. Burton</a>
+ * @version $Id: TestAtom.java 149187 2005-01-30 23:54:29Z burton $
+ */
+public class DebugPerformance {
+
+    static SAXParser parser = null;
+
+    public static void doTestSAX() throws Exception {
+
+        if ( parser == null ) {
+            parser = SAXParserFactory.newInstance().newSAXParser();
+
+            //need to enable SAX2 locals and namespace
+            parser.getXMLReader().setFeature( "http://xml.org/sax/features/namespaces", true
);
+        }
+
+         org.apache.commons.feedparser.sax.RSSFeedParser handler =
+              new org.apache.commons.feedparser.sax.RSSFeedParser();
+
+         handler.listener = new DefaultFeedParserListener() {
+
+                 public void onChannel( FeedParserState state,
+                                        String title,
+                                        String link,
+                                        String description ) throws FeedParserException {
+
+//                      System.out.println( "onChannel: title: " + title );
+                    
+                 }
+
+                 public void onItem( FeedParserState state,
+                                     String title,
+                                     String link,
+                                     String description,
+                                     String permalink ) throws FeedParserException {
+
+//                     System.out.println( "onItem: title: " + title );
+                    
+                 }
+
+                 public void onItemEnd() throws FeedParserException {
+
+//                     System.out.println( "onItemEnd");
+
+                 }
+
+             };
+
+        String resource = "file:/home/burton/index.rss";
+        
+        ResourceRequest request = ResourceRequestFactory
+            .getResourceRequest( resource );
+
+        parser.parse( request.getInputStream(), handler );
+
+    }
+
+    public static void doTestDefault() throws Exception {
+
+        FeedParser parser = FeedParserFactory.newFeedParser();
+        FeedParserListener listener = new DefaultFeedParserListener() {};
+
+        String resource = "file:/home/burton/index.rss";
+        
+        ResourceRequest request = ResourceRequestFactory
+            .getResourceRequest( resource );
+        
+        parser.parse( listener,
+                      request.getInputStream(),
+                      resource );
+
+    }
+
+    public static void main( String[] args ) throws Exception {
+
+        DebugPerformance test = new DebugPerformance();
+        
+        //test.testGetWeblogLinkForResource();
+        //test.test1();
+
+        doTestMethod( "doTestSAX", DebugPerformance.class, 100 );
+        doTestMethod( "doTestDefault", DebugPerformance.class, 100 );
+        
+    }
+
+    public static void  doTestMethod( String name, Class clazz, int max ) throws Exception
{
+
+        Method method = clazz.getMethod( name, null );
+
+        System.out.println( "Testing method: " + name );
+
+        long duration = 0;
+        
+        for ( int i = 0; i <= max; ++i ) {
+
+            long before = System.currentTimeMillis();
+            
+            method.invoke( null, null );
+
+            if ( i == 0 )
+                continue; //don't measure the first call
+
+            long after = System.currentTimeMillis();
+            duration += after-before;
+            
+        }
+
+        System.out.println( "----------------" );
+        System.out.println( "Total parse count: " + max );
+
+        System.out.println( "Total duration: " + duration + "  milliseconds" );
+
+        float totalAvgDuration = (float)duration / (float)max;
+
+        System.out.println( "Total avg duration: " + totalAvgDuration + "  milliseconds"
);
+
+        float totalPerSecond = 1000 / totalAvgDuration;
+
+        System.out.println( "Total per second: " + totalPerSecond );
+
+    }
+
+}
+

Added: jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/test/TestComments.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/test/TestComments.java?view=auto&rev=151685
==============================================================================
--- jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/test/TestComments.java
(added)
+++ jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/feedparser/test/TestComments.java
Sun Feb  6 22:14:27 2005
@@ -0,0 +1,73 @@
+/*
+ * Copyright 1999,2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.feedparser.test;
+
+import java.applet.*;
+import java.util.*;
+import java.io.*;
+import java.net.*;
+import java.security.*;
+
+import junit.framework.*;
+
+import org.apache.commons.feedparser.*;
+import org.apache.commons.feedparser.impl.*;
+import org.apache.commons.feedparser.network.*;
+
+/**
+ *
+ * @author <a href="mailto:burton@peerfear.org">Kevin A. Burton</a>
+ * @version $Id: TestAtom.java 149187 2005-01-30 23:54:29Z burton $
+ */
+public class TestComments extends TestCase {
+
+    public TestComments( String name ) throws Exception {
+        super( name );
+    }
+
+    public void test1() throws Exception {
+
+        String resource = "file:tests/feeds/wordpress-comments.rss";
+        
+        FeedParser parser = FeedParserFactory.newFeedParser();
+
+        FeedParserListener listener = new CaptureOutputFeedParserListener();
+        
+        ResourceRequest request = ResourceRequestFactory.getResourceRequest( resource );
+        
+        parser.parse( listener, request.getInputStream(), resource );
+
+        String output = listener.toString();
+
+        if ( output.indexOf( "onComments: " ) == -1 )
+            throw new Exception();
+
+        if ( output.indexOf( "onCommentsFeed: " ) == -1 )
+            throw new Exception();
+
+    }
+
+    public static void main( String[] args ) throws Exception {
+
+        TestComments test = new TestComments( null );
+        
+        //test.testGetWeblogLinkForResource();
+        test.test1();
+
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message