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: ModelHelperTest.java 4613 2012-09-22 10:07:08Z schulte $
29   *
30   */
31  package org.jomc.model.modlet.test;
32  
33  import org.jomc.model.ModelObject;
34  import org.jomc.model.Module;
35  import org.jomc.model.Modules;
36  import org.jomc.model.modlet.ModelHelper;
37  import org.jomc.modlet.Model;
38  import org.junit.Test;
39  import static org.junit.Assert.assertEquals;
40  import static org.junit.Assert.assertNotNull;
41  import static org.junit.Assert.assertNull;
42  import static org.junit.Assert.assertTrue;
43  import static org.junit.Assert.fail;
44  
45  /**
46   * Test cases for class {@code org.jomc.model.modlet.ModelHelper}.
47   *
48   * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 1.0
49   * @version $JOMC: ModelHelperTest.java 4613 2012-09-22 10:07:08Z schulte $
50   */
51  public class ModelHelperTest
52  {
53  
54      /** Creates a new {@code ModelHelperTest} instance. */
55      public ModelHelperTest()
56      {
57          super();
58      }
59  
60      @Test
61      public final void testModelHelper() throws Exception
62      {
63          try
64          {
65              ModelHelper.getModules( null );
66              fail( "Expected NullPointerException not thrown." );
67          }
68          catch ( final NullPointerException e )
69          {
70              assertNotNull( e.getMessage() );
71              System.out.println( e.toString() );
72          }
73  
74          try
75          {
76              ModelHelper.setModules( new Model(), null );
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              ModelHelper.setModules( null, new Modules() );
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          try
97          {
98              ModelHelper.addModules( new Model(), null );
99              fail( "Expected NullPointerException not thrown." );
100         }
101         catch ( final NullPointerException e )
102         {
103             assertNotNull( e.getMessage() );
104             System.out.println( e.toString() );
105         }
106 
107         try
108         {
109             ModelHelper.addModules( null, new Modules() );
110             fail( "Expected NullPointerException not thrown." );
111         }
112         catch ( final NullPointerException e )
113         {
114             assertNotNull( e.getMessage() );
115             System.out.println( e.toString() );
116         }
117 
118         try
119         {
120             ModelHelper.removeModules( null );
121             fail( "Expected NullPointerException not thrown." );
122         }
123         catch ( final NullPointerException e )
124         {
125             assertNotNull( e.getMessage() );
126             System.out.println( e.toString() );
127         }
128 
129         final Model model = new Model();
130         model.setIdentifier( ModelObject.MODEL_PUBLIC_ID );
131 
132         ModelHelper.setModules( model, new Modules() );
133 
134         assertNotNull( ModelHelper.getModules( model ) );
135         assertTrue( ModelHelper.getModules( model ).getModule().isEmpty() );
136 
137         try
138         {
139             ModelHelper.setModules( model, new Modules() );
140             fail( "Expected IllegalStateException not thrown." );
141         }
142         catch ( final IllegalStateException e )
143         {
144             assertNotNull( e.getMessage() );
145             System.out.println( e.toString() );
146         }
147 
148         final Module m = new Module();
149         m.setName( "TEST" );
150 
151         final Modules add = new Modules();
152         add.getModule().add( m );
153 
154         ModelHelper.addModules( model, add );
155         assertNotNull( ModelHelper.getModules( model ) );
156         assertEquals( 1, ModelHelper.getModules( model ).getModule().size() );
157 
158         ModelHelper.removeModules( model );
159         assertNull( ModelHelper.getModules( model ) );
160     }
161 
162 }