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: DefaultModletProviderTest.java 4200 2012-01-25 09:46:13Z schulte2005 $
029     *
030     */
031    package org.jomc.modlet.test;
032    
033    import org.jomc.modlet.DefaultModletProvider;
034    import org.jomc.modlet.ModelContextFactory;
035    import org.junit.Test;
036    import static org.junit.Assert.assertEquals;
037    import static org.junit.Assert.assertFalse;
038    import static org.junit.Assert.assertNotNull;
039    import static org.junit.Assert.assertTrue;
040    import static org.junit.Assert.fail;
041    
042    /**
043     * Test cases for class {@code org.jomc.modlet.DefaultModletProvider}.
044     *
045     * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.0
046     * @version $JOMC: DefaultModletProviderTest.java 4200 2012-01-25 09:46:13Z schulte2005 $
047     */
048    public class DefaultModletProviderTest extends ModletProviderTest
049    {
050    
051        /** Creates a new {@code DefaultModletProviderTest} instance. */
052        public DefaultModletProviderTest()
053        {
054            super();
055        }
056    
057        /** {@inheritDoc} */
058        @Override
059        public DefaultModletProvider getModletProvider()
060        {
061            return (DefaultModletProvider) super.getModletProvider();
062        }
063    
064        /** {@inheritDoc} */
065        @Override
066        public DefaultModletProvider newModletProvider()
067        {
068            return new DefaultModletProvider();
069        }
070    
071        @Test
072        public final void testFindModletsAtLocation() throws Exception
073        {
074            try
075            {
076                this.getModletProvider().findModlets( null, "TEST" );
077                fail( "Expected NullPointerException not thrown." );
078            }
079            catch ( final NullPointerException e )
080            {
081                assertNotNull( e.getMessage() );
082                System.out.println( e.toString() );
083            }
084    
085            try
086            {
087                this.getModletProvider().findModlets( ModelContextFactory.newInstance().newModelContext(), null );
088                fail( "Expected NullPointerException not thrown." );
089            }
090            catch ( final NullPointerException e )
091            {
092                assertNotNull( e.getMessage() );
093                System.out.println( e.toString() );
094            }
095        }
096    
097        @Test
098        public final void testDefaultEnabled() throws Exception
099        {
100            System.clearProperty( "org.jomc.modlet.DefaultModletProvider.defaultEnabled" );
101            DefaultModletProvider.setDefaultEnabled( null );
102            assertTrue( DefaultModletProvider.isDefaultEnabled() );
103            DefaultModletProvider.setDefaultEnabled( null );
104            System.setProperty( "org.jomc.modlet.DefaultModletProvider.defaultEnabled", "false" );
105            assertFalse( DefaultModletProvider.isDefaultEnabled() );
106            System.clearProperty( "org.jomc.modlet.DefaultModletProvider.defaultEnabled" );
107            DefaultModletProvider.setDefaultEnabled( null );
108            assertTrue( DefaultModletProvider.isDefaultEnabled() );
109        }
110    
111        @Test
112        public final void testDefaultModletLocation() throws Exception
113        {
114            System.clearProperty( "org.jomc.modlet.DefaultModletProvider.defaultModletLocation" );
115            DefaultModletProvider.setDefaultModletLocation( null );
116            assertEquals( "META-INF/jomc-modlet.xml", DefaultModletProvider.getDefaultModletLocation() );
117            DefaultModletProvider.setDefaultModletLocation( null );
118            System.setProperty( "org.jomc.modlet.DefaultModletProvider.defaultModletLocation", "TEST" );
119            assertEquals( "TEST", DefaultModletProvider.getDefaultModletLocation() );
120            System.clearProperty( "org.jomc.modlet.DefaultModletProvider.defaultModletLocation" );
121            DefaultModletProvider.setDefaultModletLocation( null );
122            assertEquals( "META-INF/jomc-modlet.xml", DefaultModletProvider.getDefaultModletLocation() );
123        }
124    
125        @Test
126        public final void testDefaultValidating() throws Exception
127        {
128            System.clearProperty( "org.jomc.modlet.DefaultModletProvider.defaultValidating" );
129            DefaultModletProvider.setDefaultValidating( null );
130            assertTrue( DefaultModletProvider.isDefaultValidating() );
131            DefaultModletProvider.setDefaultValidating( null );
132            System.setProperty( "org.jomc.modlet.DefaultModletProvider.defaultValidating", "false" );
133            assertFalse( DefaultModletProvider.isDefaultValidating() );
134            System.clearProperty( "org.jomc.modlet.DefaultModletProvider.defaultValidating" );
135            DefaultModletProvider.setDefaultValidating( null );
136            assertTrue( DefaultModletProvider.isDefaultValidating() );
137        }
138    
139        @Test
140        public final void testModletLocation() throws Exception
141        {
142            DefaultModletProvider.setDefaultModletLocation( null );
143            this.getModletProvider().setModletLocation( null );
144            assertNotNull( this.getModletProvider().getModletLocation() );
145    
146            DefaultModletProvider.setDefaultModletLocation( "TEST" );
147            this.getModletProvider().setModletLocation( null );
148            assertEquals( "TEST", this.getModletProvider().getModletLocation() );
149    
150            DefaultModletProvider.setDefaultModletLocation( null );
151            this.getModletProvider().setModletLocation( null );
152        }
153    
154        @Test
155        public final void testEnabled() throws Exception
156        {
157            DefaultModletProvider.setDefaultEnabled( null );
158            this.getModletProvider().setEnabled( null );
159            assertTrue( this.getModletProvider().isEnabled() );
160    
161            DefaultModletProvider.setDefaultEnabled( false );
162            this.getModletProvider().setEnabled( null );
163            assertFalse( this.getModletProvider().isEnabled() );
164    
165            DefaultModletProvider.setDefaultEnabled( null );
166            this.getModletProvider().setEnabled( null );
167        }
168    
169        @Test
170        public final void testValidating() throws Exception
171        {
172            DefaultModletProvider.setDefaultValidating( null );
173            this.getModletProvider().setValidating( null );
174            assertTrue( this.getModletProvider().isValidating() );
175    
176            DefaultModletProvider.setDefaultValidating( false );
177            this.getModletProvider().setValidating( null );
178            assertFalse( this.getModletProvider().isValidating() );
179    
180            DefaultModletProvider.setDefaultValidating( null );
181            this.getModletProvider().setValidating( null );
182        }
183    
184    }