Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 16077 invoked from network); 7 Feb 2005 06:14:35 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 7 Feb 2005 06:14:35 -0000 Received: (qmail 16839 invoked by uid 500); 7 Feb 2005 06:14:33 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 16762 invoked by uid 500); 7 Feb 2005 06:14:33 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 16748 invoked by uid 500); 7 Feb 2005 06:14:32 -0000 Received: (qmail 16743 invoked by uid 99); 7 Feb 2005 06:14:32 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Sun, 06 Feb 2005 22:14:31 -0800 Received: (qmail 16021 invoked by uid 65534); 7 Feb 2005 06:14:30 -0000 Message-ID: <20050207061430.16020.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: svnmailer-1.0.0-dev Date: Mon, 07 Feb 2005 06:14:29 -0000 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 To: commons-cvs@jakarta.apache.org From: burton@apache.org X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Author: burton Date: Sun Feb 6 22:14:27 2005 New Revision: 151685 URL: http://svn.apache.org/viewcvs?view=3Drev&rev=3D151685 Log: unit tests for comments RSS and RSS 2.0 comments Added: jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/fe= edparser/impl/CaptureOutputFeedParserListener.java jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/fe= edparser/test/DebugPerformance.java jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/fe= edparser/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/CaptureOutputFeedParserListene= r=2Ejava?view=3Dauto&rev=3D151685 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/fe= edparser/impl/CaptureOutputFeedParserListener.java (added) +++ jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/fe= edparser/impl/CaptureOutputFeedParserListener.java Sun Feb 6 22:14:27 2005 @@ -0,0 +1,61 @@ +/* + * Copyright 1999,2004 The Apache Software Foundation. + *=20 + * 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 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * 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 u= nit + * tests. + *=20 + * @author Kevin A. Burton (burtonato= r) + * @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 =3D (CapturePrintStream)out; + ByteArrayOutputStream bos =3D (ByteArrayOutputStream)cps.getOutput= Stream(); + + return bos.toString(); + =20 + } + =20 +} + +class CapturePrintStream extends PrintStream { + + public CapturePrintStream() { + super( new ByteArrayOutputStream() ); + } + + public OutputStream getOutputStream() { + return out; + } + =20 +} \ 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=3Da= uto&rev=3D151685 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/fe= edparser/test/DebugPerformance.java (added) +++ jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/fe= edparser/test/DebugPerformance.java Sun Feb 6 22:14:27 2005 @@ -0,0 +1,161 @@ +/* + * Copyright 1999,2004 The Apache Software Foundation. + *=20 + * 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 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * 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 Kevin A. Burton + * @version $Id: TestAtom.java 149187 2005-01-30 23:54:29Z burton $ + */ +public class DebugPerformance { + + static SAXParser parser =3D null; + + public static void doTestSAX() throws Exception { + + if ( parser =3D=3D null ) { + parser =3D 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 =3D + new org.apache.commons.feedparser.sax.RSSFeedParser(); + + handler.listener =3D new DefaultFeedParserListener() { + + public void onChannel( FeedParserState state, + String title, + String link, + String description ) throws FeedPa= rserException { + +// System.out.println( "onChannel: title: " + title ); + =20 + } + + public void onItem( FeedParserState state, + String title, + String link, + String description, + String permalink ) throws FeedParserE= xception { + +// System.out.println( "onItem: title: " + title ); + =20 + } + + public void onItemEnd() throws FeedParserException { + +// System.out.println( "onItemEnd"); + + } + + }; + + String resource =3D "file:/home/burton/index.rss"; + =20 + ResourceRequest request =3D ResourceRequestFactory + .getResourceRequest( resource ); + + parser.parse( request.getInputStream(), handler ); + + } + + public static void doTestDefault() throws Exception { + + FeedParser parser =3D FeedParserFactory.newFeedParser(); + FeedParserListener listener =3D new DefaultFeedParserListener() {}; + + String resource =3D "file:/home/burton/index.rss"; + =20 + ResourceRequest request =3D ResourceRequestFactory + .getResourceRequest( resource ); + =20 + parser.parse( listener, + request.getInputStream(), + resource ); + + } + + public static void main( String[] args ) throws Exception { + + DebugPerformance test =3D new DebugPerformance(); + =20 + //test.testGetWeblogLinkForResource(); + //test.test1(); + + doTestMethod( "doTestSAX", DebugPerformance.class, 100 ); + doTestMethod( "doTestDefault", DebugPerformance.class, 100 ); + =20 + } + + public static void doTestMethod( String name, Class clazz, int max ) = throws Exception { + + Method method =3D clazz.getMethod( name, null ); + + System.out.println( "Testing method: " + name ); + + long duration =3D 0; + =20 + for ( int i =3D 0; i <=3D max; ++i ) { + + long before =3D System.currentTimeMillis(); + =20 + method.invoke( null, null ); + + if ( i =3D=3D 0 ) + continue; //don't measure the first call + + long after =3D System.currentTimeMillis(); + duration +=3D after-before; + =20 + } + + System.out.println( "----------------" ); + System.out.println( "Total parse count: " + max ); + + System.out.println( "Total duration: " + duration + " millisecond= s" ); + + float totalAvgDuration =3D (float)duration / (float)max; + + System.out.println( "Total avg duration: " + totalAvgDuration + " = milliseconds" ); + + float totalPerSecond =3D 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=3Dauto&= rev=3D151685 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/fe= edparser/test/TestComments.java (added) +++ jakarta/commons/sandbox/feedparser/trunk/src/java/org/apache/commons/fe= edparser/test/TestComments.java Sun Feb 6 22:14:27 2005 @@ -0,0 +1,73 @@ +/* + * Copyright 1999,2004 The Apache Software Foundation. + *=20 + * 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 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * 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 Kevin A. Burton + * @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 =3D "file:tests/feeds/wordpress-comments.rss"; + =20 + FeedParser parser =3D FeedParserFactory.newFeedParser(); + + FeedParserListener listener =3D new CaptureOutputFeedParserListene= r(); + =20 + ResourceRequest request =3D ResourceRequestFactory.getResourceRequ= est( resource ); + =20 + parser.parse( listener, request.getInputStream(), resource ); + + String output =3D listener.toString(); + + if ( output.indexOf( "onComments: " ) =3D=3D -1 ) + throw new Exception(); + + if ( output.indexOf( "onCommentsFeed: " ) =3D=3D -1 ) + throw new Exception(); + + } + + public static void main( String[] args ) throws Exception { + + TestComments test =3D new TestComments( null ); + =20 + //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