View Javadoc

1   /* $Id: CatalogTestCase.java 1127117 2011-05-24 15:28:41Z simonetripodi $
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one or more
4    * contributor license agreements.  See the NOTICE file distributed with
5    * this work for additional information regarding copyright ownership.
6    * The ASF licenses this file to You under the Apache License, Version 2.0
7    * (the "License"); you may not use this file except in compliance with
8    * the License.  You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.commons.digester3.annotations.catalog;
19  
20  import java.util.Collection;
21  import java.util.Stack;
22  
23  import org.apache.commons.digester3.annotations.AbstractAnnotatedPojoTestCase;
24  import org.apache.commons.digester3.binder.AbstractRulesModule;
25  import org.apache.commons.digester3.binder.RulesModule;
26  import org.junit.Test;
27  
28  /**
29   * @since 2.1
30   */
31  public final class CatalogTestCase
32      extends AbstractAnnotatedPojoTestCase
33  {
34  
35      @Test
36      public void testCatalog()
37          throws Exception
38      {
39          Catalog catalog = new Catalog();
40  
41          Book book = new Book( "0-596-00184-3" );
42          book.setTitle( "Ant, The Definitive Guide" );
43          book.setAuthor( "Jesse Tilly & Eric M. Burke" );
44          book.setDesc( "Complete build management for Java." );
45          catalog.addItem( book );
46  
47          book = new Book( "0201310058" );
48          book.setTitle( "Effective Java" );
49          book.setAuthor( "Joshua Bloch" );
50          book.setDesc( "Tips for experienced Java software developers." );
51          catalog.addItem( book );
52  
53          AudioVisual dvd = new AudioVisual();
54          dvd.setName( "Drunken Master" );
55          dvd.setCategory( "martial arts" );
56          dvd.setDesc( "Hilarious slapstick starring Jackie Chan." );
57          dvd.setRuntime( 106 );
58          dvd.setYearMade( 1978 );
59          catalog.addItem( dvd );
60  
61          dvd = new AudioVisual();
62          dvd.setName( "The Piano" );
63          dvd.setCategory( "drama" );
64          dvd.setDesc( "Character drama set in New Zealand during the Victorian era." );
65          dvd.setRuntime( 121 );
66          dvd.setYearMade( 1993 );
67          catalog.addItem( dvd );
68  
69          this.verifyExpectedEqualsToParsed( catalog );
70      }
71  
72      @Override
73      protected Collection<RulesModule> getAuxModules()
74      {
75          Collection<RulesModule> modules = new Stack<RulesModule>();
76          modules.add( new AbstractRulesModule()
77          {
78  
79              @Override
80              public void configure()
81              {
82                  forPattern( "catalog/dvd/attr" ).setProperty( "id" ).extractingValueFromAttribute( "value" );
83              }
84  
85          } );
86          return modules;
87      }
88  
89  }