View Javadoc

1   /*
2    *   Copyright (C) Christian Schulte, 2005-206
3    *   All rights reserved.
4    *
5    *   Redistribution and use in source and binary forms, with or without
6    *   modification, are permitted provided that the following conditions
7    *   are met:
8    *
9    *     o Redistributions of source code must retain the above copyright
10   *       notice, this list of conditions and the following disclaimer.
11   *
12   *     o Redistributions in binary form must reproduce the above copyright
13   *       notice, this list of conditions and the following disclaimer in
14   *       the documentation and/or other materials provided with the
15   *       distribution.
16   *
17   *   THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
18   *   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19   *   AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
20   *   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
21   *   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22   *   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23   *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24   *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25   *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26   *   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27   *
28   *   $JOMC: DefaultModletProviderTest.java 4200 2012-01-25 09:46:13Z schulte2005 $
29   *
30   */
31  package org.jomc.modlet.test;
32  
33  import org.jomc.modlet.DefaultModletProvider;
34  import org.jomc.modlet.ModelContextFactory;
35  import org.junit.Test;
36  import static org.junit.Assert.assertEquals;
37  import static org.junit.Assert.assertFalse;
38  import static org.junit.Assert.assertNotNull;
39  import static org.junit.Assert.assertTrue;
40  import static org.junit.Assert.fail;
41  
42  /**
43   * Test cases for class {@code org.jomc.modlet.DefaultModletProvider}.
44   *
45   * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.0
46   * @version $JOMC: DefaultModletProviderTest.java 4200 2012-01-25 09:46:13Z schulte2005 $
47   */
48  public class DefaultModletProviderTest extends ModletProviderTest
49  {
50  
51      /** Creates a new {@code DefaultModletProviderTest} instance. */
52      public DefaultModletProviderTest()
53      {
54          super();
55      }
56  
57      /** {@inheritDoc} */
58      @Override
59      public DefaultModletProvider getModletProvider()
60      {
61          return (DefaultModletProvider) super.getModletProvider();
62      }
63  
64      /** {@inheritDoc} */
65      @Override
66      public DefaultModletProvider newModletProvider()
67      {
68          return new DefaultModletProvider();
69      }
70  
71      @Test
72      public final void testFindModletsAtLocation() throws Exception
73      {
74          try
75          {
76              this.getModletProvider().findModlets( null, "TEST" );
77              fail( "Expected NullPointerException not thrown." );
78          }
79          catch ( final NullPointerException e )
80          {
81              assertNotNull( e.getMessage() );
82              System.out.println( e.toString() );
83          }
84  
85          try
86          {
87              this.getModletProvider().findModlets( ModelContextFactory.newInstance().newModelContext(), null );
88              fail( "Expected NullPointerException not thrown." );
89          }
90          catch ( final NullPointerException e )
91          {
92              assertNotNull( e.getMessage() );
93              System.out.println( e.toString() );
94          }
95      }
96  
97      @Test
98      public final void testDefaultEnabled() throws Exception
99      {
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 }