001package org.apache.commons.digester3.xmlrules;
002
003import static org.apache.commons.digester3.binder.DigesterLoader.newLoader;
004import static org.junit.Assert.*;
005
006import java.net.URL;
007import java.util.Date;
008
009import org.apache.commons.beanutils.ConvertUtils;
010import org.apache.commons.beanutils.converters.DateConverter;
011import org.apache.commons.digester3.Digester;
012import org.junit.Test;
013
014/*
015 * Licensed to the Apache Software Foundation (ASF) under one
016 * or more contributor license agreements.  See the NOTICE file
017 * distributed with this work for additional information
018 * regarding copyright ownership.  The ASF licenses this file
019 * to you under the Apache License, Version 2.0 (the
020 * "License"); you may not use this file except in compliance
021 * with the License.  You may obtain a copy of the License at
022 *
023 *   http://www.apache.org/licenses/LICENSE-2.0
024 *
025 * Unless required by applicable law or agreed to in writing,
026 * software distributed under the License is distributed on an
027 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
028 * KIND, either express or implied.  See the License for the
029 * specific language governing permissions and limitations
030 * under the License.
031 */
032
033public final class SetNamespaceURITestCase
034{
035
036    @Test
037    public void atomWithNamespaceParse()
038        throws Exception
039    {
040        // Drive commons-beanutils how to convert dates
041        DateConverter dateConverter = new DateConverter();
042        dateConverter.setPatterns( new String[] { "yyyy-MM-dd'T'HH:mm" } );
043        ConvertUtils.register( dateConverter, Date.class );
044
045        final URL rules = getClass().getResource( "atom-rules.xml" );
046        final URL input = getClass().getResource( "atom-content.xml" );
047
048        Digester digester = newLoader( new FromXmlRulesModule()
049        {
050
051            @Override
052            protected void loadRules()
053            {
054                loadXMLRules( rules );
055            }
056
057        } )
058        .setNamespaceAware( true )
059        .newDigester();
060        Feed feed = digester.parse( input.openStream() );
061        assertNotNull( feed );
062    }
063
064}