001/* $Id: CatalogTestCase.java 1127117 2011-05-24 15:28:41Z simonetripodi $
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one or more
004 * contributor license agreements.  See the NOTICE file distributed with
005 * this work for additional information regarding copyright ownership.
006 * The ASF licenses this file to You under the Apache License, Version 2.0
007 * (the "License"); you may not use this file except in compliance with
008 * the License.  You may obtain a copy of the License at
009 *
010 *      http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.commons.digester3.annotations.catalog;
019
020import java.util.Collection;
021import java.util.Stack;
022
023import org.apache.commons.digester3.annotations.AbstractAnnotatedPojoTestCase;
024import org.apache.commons.digester3.binder.AbstractRulesModule;
025import org.apache.commons.digester3.binder.RulesModule;
026import org.junit.Test;
027
028/**
029 * @since 2.1
030 */
031public final class CatalogTestCase
032    extends AbstractAnnotatedPojoTestCase
033{
034
035    @Test
036    public void testCatalog()
037        throws Exception
038    {
039        Catalog catalog = new Catalog();
040
041        Book book = new Book( "0-596-00184-3" );
042        book.setTitle( "Ant, The Definitive Guide" );
043        book.setAuthor( "Jesse Tilly & Eric M. Burke" );
044        book.setDesc( "Complete build management for Java." );
045        catalog.addItem( book );
046
047        book = new Book( "0201310058" );
048        book.setTitle( "Effective Java" );
049        book.setAuthor( "Joshua Bloch" );
050        book.setDesc( "Tips for experienced Java software developers." );
051        catalog.addItem( book );
052
053        AudioVisual dvd = new AudioVisual();
054        dvd.setName( "Drunken Master" );
055        dvd.setCategory( "martial arts" );
056        dvd.setDesc( "Hilarious slapstick starring Jackie Chan." );
057        dvd.setRuntime( 106 );
058        dvd.setYearMade( 1978 );
059        catalog.addItem( dvd );
060
061        dvd = new AudioVisual();
062        dvd.setName( "The Piano" );
063        dvd.setCategory( "drama" );
064        dvd.setDesc( "Character drama set in New Zealand during the Victorian era." );
065        dvd.setRuntime( 121 );
066        dvd.setYearMade( 1993 );
067        catalog.addItem( dvd );
068
069        this.verifyExpectedEqualsToParsed( catalog );
070    }
071
072    @Override
073    protected Collection<RulesModule> getAuxModules()
074    {
075        Collection<RulesModule> modules = new Stack<RulesModule>();
076        modules.add( new AbstractRulesModule()
077        {
078
079            @Override
080            public void configure()
081            {
082                forPattern( "catalog/dvd/attr" ).setProperty( "id" ).extractingValueFromAttribute( "value" );
083            }
084
085        } );
086        return modules;
087    }
088
089}