001    /*
002     * Copyright 1999,2004 The Apache Software Foundation.
003     * 
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     * 
008     *      http://www.apache.org/licenses/LICENSE-2.0
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    package org.apache.commons.feedparser.test;
018    
019    import junit.framework.TestCase;
020    
021    import org.apache.commons.feedparser.FeedParser;
022    import org.apache.commons.feedparser.FeedParserFactory;
023    import org.apache.commons.feedparser.FeedParserListener;
024    import org.apache.commons.feedparser.impl.CaptureOutputFeedParserListener;
025    import org.apache.commons.feedparser.network.ResourceRequest;
026    import org.apache.commons.feedparser.network.ResourceRequestFactory;
027    
028    /**
029     *
030     * @author <a href="mailto:burton@peerfear.org">Kevin A. Burton</a>
031     * @version $Id: BaseTestCase.java 373622 2006-01-30 22:53:00Z mvdb $
032     */
033    public class BaseTestCase extends TestCase {
034    
035        public BaseTestCase( String name ) throws Exception {
036            super( name );
037        }
038    
039        /**
040         * Run a parse on the given feed and then capture the event output as a
041         * string for unit testing.  We can then grep across the string assering
042         * that the correct events are called.
043         *
044         * 
045         */
046        public String captureOutputFromTest( String resource ) throws Exception {
047    
048            FeedParser parser = FeedParserFactory.newFeedParser();
049    
050            FeedParserListener listener = new CaptureOutputFeedParserListener();
051            
052            ResourceRequest request = ResourceRequestFactory.getResourceRequest( resource );
053            
054            parser.parse( listener, request.getInputStream(), resource );
055    
056            String output = listener.toString();
057    
058            return output;
059            
060        }
061    
062    }