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: JomcToolTaskTest.java 3879 2011-10-24 00:59:27Z schulte2005 $
29   *
30   */
31  package org.jomc.ant.test;
32  
33  import org.apache.tools.ant.BuildException;
34  import org.jomc.ant.JomcToolTask;
35  import org.jomc.ant.test.support.AntExecutionResult;
36  import static org.jomc.ant.test.support.Assert.assertException;
37  import static org.jomc.ant.test.support.Assert.assertExceptionMessage;
38  import org.junit.Test;
39  import static org.junit.Assert.assertNotNull;
40  import static org.junit.Assert.fail;
41  
42  /**
43   * Test cases for class {@code org.jomc.ant.JomcToolTask}.
44   *
45   * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a>
46   * @version $JOMC: JomcToolTaskTest.java 3879 2011-10-24 00:59:27Z schulte2005 $
47   */
48  public class JomcToolTaskTest extends JomcModelTaskTest
49  {
50  
51      /** Creates a new {@code JomcToolTaskTest} instance. */
52      public JomcToolTaskTest()
53      {
54          super();
55      }
56  
57      /** {@inheritDoc} */
58      @Override
59      public JomcToolTask getJomcTask()
60      {
61          return (JomcToolTask) super.getJomcTask();
62      }
63  
64      /** {@inheritDoc} */
65      @Override
66      protected JomcToolTask newJomcTask()
67      {
68          return new JomcToolTask();
69      }
70  
71      /** {@inheritDoc} */
72      @Override
73      protected String getBuildFileName()
74      {
75          return "jomc-tool-task-test.xml";
76      }
77  
78      @Test
79      public final void testConfigureJomcTool() throws Exception
80      {
81          try
82          {
83              this.getJomcTask().configureJomcTool( null );
84              fail( "Expected 'NullPointerException' not thrown." );
85          }
86          catch ( final NullPointerException e )
87          {
88              assertNotNull( e.getMessage() );
89              System.out.println( e );
90          }
91      }
92  
93      @Test
94      public final void testGetSpecification() throws Exception
95      {
96          try
97          {
98              this.getJomcTask().getSpecification( null );
99              fail( "Expected 'NullPointerException' not thrown." );
100         }
101         catch ( final NullPointerException e )
102         {
103             assertNotNull( e.getMessage() );
104             System.out.println( e );
105         }
106     }
107 
108     @Test
109     public final void testGetImplementation() throws Exception
110     {
111         try
112         {
113             this.getJomcTask().getImplementation( null );
114             fail( "Expected 'NullPointerException' not thrown." );
115         }
116         catch ( final NullPointerException e )
117         {
118             assertNotNull( e.getMessage() );
119             System.out.println( e );
120         }
121     }
122 
123     @Test
124     public final void testGetModule() throws Exception
125     {
126         try
127         {
128             this.getJomcTask().getModule( null );
129             fail( "Expected 'NullPointerException' not thrown." );
130         }
131         catch ( final NullPointerException e )
132         {
133             assertNotNull( e.getMessage() );
134             System.out.println( e );
135         }
136     }
137 
138     @Test
139     public final void testVelocityPropertyMissingKey() throws Exception
140     {
141         final AntExecutionResult r = this.executeTarget( "test-velocity-property-missing-key" );
142         assertException( r, BuildException.class );
143         assertExceptionMessage( r, "Mandatory attribute 'key' is missing a value." );
144     }
145 
146     @Test
147     public final void testVelocityPropertyResourceMissingLocation() throws Exception
148     {
149         final AntExecutionResult r = this.executeTarget( "test-velocity-property-resource-missing-location" );
150         assertException( r, BuildException.class );
151         assertExceptionMessage( r, "Mandatory attribute 'location' is missing a value." );
152     }
153 
154     @Test
155     public final void testTemplateParameterMissingKey() throws Exception
156     {
157         final AntExecutionResult r = this.executeTarget( "test-template-parameter-missing-key" );
158         assertException( r, BuildException.class );
159         assertExceptionMessage( r, "Mandatory attribute 'key' is missing a value." );
160     }
161 
162     @Test
163     public final void testTemplateParameterResourceMissingLocation() throws Exception
164     {
165         final AntExecutionResult r = this.executeTarget( "test-template-parameter-resource-missing-location" );
166         assertException( r, BuildException.class );
167         assertExceptionMessage( r, "Mandatory attribute 'location' is missing a value." );
168     }
169 
170     @Test
171     public final void testInvalidMultipleLocaleElements() throws Exception
172     {
173         final AntExecutionResult r = this.executeTarget( "test-invalid-multiple-locale-elements" );
174         assertException( r, BuildException.class );
175         assertExceptionMessage( r, "Multiple nested 'locale' elements." );
176     }
177 
178 }