001    /*
002     *   Copyright (C) Christian Schulte, 2005-206
003     *   All rights reserved.
004     *
005     *   Redistribution and use in source and binary forms, with or without
006     *   modification, are permitted provided that the following conditions
007     *   are met:
008     *
009     *     o Redistributions of source code must retain the above copyright
010     *       notice, this list of conditions and the following disclaimer.
011     *
012     *     o Redistributions in binary form must reproduce the above copyright
013     *       notice, this list of conditions and the following disclaimer in
014     *       the documentation and/or other materials provided with the
015     *       distribution.
016     *
017     *   THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
018     *   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
019     *   AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
020     *   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
021     *   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
022     *   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
023     *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
024     *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025     *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
026     *   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027     *
028     *   $JOMC: ModletObjectTest.java 3851 2011-10-10 16:25:09Z schulte2005 $
029     *
030     */
031    package org.jomc.modlet.test;
032    
033    import java.util.ArrayList;
034    import java.util.List;
035    import javax.xml.bind.JAXBElement;
036    import javax.xml.namespace.QName;
037    import org.jomc.modlet.ModletObject;
038    import org.junit.Test;
039    import static org.junit.Assert.assertNotNull;
040    import static org.junit.Assert.fail;
041    
042    /**
043     * Test cases for class {@code org.jomc.modlet.ModletObject}.
044     *
045     * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.0
046     * @version $JOMC: ModletObjectTest.java 3851 2011-10-10 16:25:09Z schulte2005 $
047     */
048    public class ModletObjectTest
049    {
050    
051        /** Creates a new {@code ModletObjectTest} instance. */
052        public ModletObjectTest()
053        {
054            super();
055        }
056    
057        public static class TestModletObject extends ModletObject
058        {
059    
060            @Override
061            @SuppressWarnings( "deprecation" )
062            public JAXBElement getAnyElement( final List<Object> any, final String namespaceURI, final String localPart )
063            {
064                return super.getAnyElement( any, namespaceURI, localPart );
065            }
066    
067            @Override
068            public <T> JAXBElement<T> getAnyElement( final List<Object> any, final String namespaceURI,
069                                                     final String localPart, final Class<T> type )
070            {
071                return super.getAnyElement( any, namespaceURI, localPart, type );
072            }
073    
074            @Override
075            public <T> T getAnyObject( final List<Object> any, final Class<T> clazz )
076            {
077                return super.getAnyObject( any, clazz );
078            }
079    
080        }
081    
082        @Test
083        public final void testGetAnyElement() throws Exception
084        {
085            final TestModletObject modletObject = new TestModletObject();
086            final List<Object> any = new ArrayList<Object>( 10 );
087            final QName name = new QName( "http://jomc.org/modlet", "test" );
088            final JAXBElement<Object> element = new JAXBElement<Object>( name, Object.class, null, null );
089            any.add( element );
090            any.add( element );
091    
092            try
093            {
094                modletObject.getAnyElement( any, "http://jomc.org/modlet", "test" );
095                fail( "Expected 'IllegalStateException' not thrown." );
096            }
097            catch ( final IllegalStateException e )
098            {
099                assertNotNull( e.getMessage() );
100                System.out.println( e );
101            }
102    
103            try
104            {
105                modletObject.getAnyElement( any, "http://jomc.org/modlet", "test", Object.class );
106                fail( "Expected 'IllegalStateException' not thrown." );
107            }
108            catch ( final IllegalStateException e )
109            {
110                assertNotNull( e.getMessage() );
111                System.out.println( e );
112            }
113        }
114    
115        @Test
116        public final void testGetAnyObject() throws Exception
117        {
118            final TestModletObject modletObject = new TestModletObject();
119            final List<Object> any = new ArrayList<Object>( 10 );
120            any.add( "TEST" );
121            any.add( "TEST" );
122    
123            try
124            {
125                modletObject.getAnyObject( any, String.class );
126                fail( "Expected 'IllegalStateException' not thrown." );
127            }
128            catch ( final IllegalStateException e )
129            {
130                assertNotNull( e.getMessage() );
131                System.out.println( e );
132            }
133        }
134    
135    }