View Javadoc

1   package org.apache.commons.digester3.xmlrules;
2   
3   import static org.apache.commons.digester3.binder.DigesterLoader.newLoader;
4   import static org.junit.Assert.*;
5   
6   import java.net.URL;
7   import java.util.Date;
8   
9   import org.apache.commons.beanutils.ConvertUtils;
10  import org.apache.commons.beanutils.converters.DateConverter;
11  import org.apache.commons.digester3.Digester;
12  import org.junit.Test;
13  
14  /*
15   * Licensed to the Apache Software Foundation (ASF) under one
16   * or more contributor license agreements.  See the NOTICE file
17   * distributed with this work for additional information
18   * regarding copyright ownership.  The ASF licenses this file
19   * to you under the Apache License, Version 2.0 (the
20   * "License"); you may not use this file except in compliance
21   * with the License.  You may obtain a copy of the License at
22   *
23   *   http://www.apache.org/licenses/LICENSE-2.0
24   *
25   * Unless required by applicable law or agreed to in writing,
26   * software distributed under the License is distributed on an
27   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
28   * KIND, either express or implied.  See the License for the
29   * specific language governing permissions and limitations
30   * under the License.
31   */
32  
33  public final class SetNamespaceURITestCase
34  {
35  
36      @Test
37      public void atomWithNamespaceParse()
38          throws Exception
39      {
40          // Drive commons-beanutils how to convert dates
41          DateConverter dateConverter = new DateConverter();
42          dateConverter.setPatterns( new String[] { "yyyy-MM-dd'T'HH:mm" } );
43          ConvertUtils.register( dateConverter, Date.class );
44  
45          final URL rules = getClass().getResource( "atom-rules.xml" );
46          final URL input = getClass().getResource( "atom-content.xml" );
47  
48          Digester digester = newLoader( new FromXmlRulesModule()
49          {
50  
51              @Override
52              protected void loadRules()
53              {
54                  loadXMLRules( rules );
55              }
56  
57          } )
58          .setNamespaceAware( true )
59          .newDigester();
60          Feed feed = digester.parse( input.openStream() );
61          assertNotNull( feed );
62      }
63  
64  }