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 java.io.FileInputStream;
020
021 import javax.xml.parsers.DocumentBuilder;
022 import javax.xml.parsers.DocumentBuilderFactory;
023
024 import junit.framework.TestCase;
025
026 import org.apache.commons.feedparser.FeedParser;
027 import org.apache.commons.feedparser.FeedParserFactory;
028 import org.apache.commons.feedparser.FeedParserListener;
029 import org.apache.commons.feedparser.impl.DebugFeedParserListener;
030
031 /**
032 *
033 * @author <a href="mailto:burton@peerfear.org">Kevin A. Burton</a>
034 * @version $Id: TestFeedParserUTF8.java 373622 2006-01-30 22:53:00Z mvdb $
035 */
036 public class TestFeedParserUTF8 extends TestCase {
037
038 public TestFeedParserUTF8( String name ) throws Exception {
039 super( name );
040 }
041
042 public void testAssertXerces() throws Exception {
043
044 String v;
045
046 DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
047
048 v = db.getClass().getName();
049
050 if ( ! v.equals( "org.apache.xerces.jaxp.DocumentBuilderImpl" ) )
051 throw new Exception( "Incorrect version of Xerces: " + v );
052
053 v = org.apache.xerces.impl.Version.fVersion;
054
055 if ( v.indexOf( "2.6" ) == -1 )
056 throw new Exception( "Incorrect version of Xerces: " + v);
057
058 }
059
060 public void test( String path ) throws Exception {
061
062 FeedParser parser = FeedParserFactory.newFeedParser();
063
064 FeedParserListener listener = new DebugFeedParserListener();
065
066 parser.parse( listener,
067 new FileInputStream( "src/java/org/apache/commons/feedparser/test/" + path),
068 path );
069
070 }
071
072 public void test1() throws Exception {
073
074 test( "TestFeedParserUTF8.rss" );
075
076 }
077
078 public void test2() throws Exception {
079
080 test( "broken-UTF8-feed.rss" );
081 }
082
083 public void test3() throws Exception {
084
085 test( "broken-Invalid-byte-2-of-3-byte-UTF-8-sequence.xml" );
086 }
087
088 public void test4() throws Exception {
089
090 test( "broken-salon.rdf" );
091 }
092
093 public static void main( String[] args ) throws Exception {
094
095 TestFeedParserUTF8 test = new TestFeedParserUTF8( null );
096
097 //test.testGetWeblogLinkForResource();
098 //test.testParse();
099 test.test2();
100
101 }
102
103 }
104