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: MergeModulesTaskTest.java 4613 2012-09-22 10:07:08Z schulte $
29   *
30   */
31  package org.jomc.ant.test;
32  
33  import org.apache.tools.ant.BuildException;
34  import org.apache.tools.ant.Project;
35  import org.jomc.ant.MergeModulesTask;
36  import org.jomc.ant.test.support.AntExecutionResult;
37  import static org.jomc.ant.test.support.Assert.assertException;
38  import static org.jomc.ant.test.support.Assert.assertExceptionMessage;
39  import static org.jomc.ant.test.support.Assert.assertExceptionMessageContaining;
40  import static org.jomc.ant.test.support.Assert.assertMessageLogged;
41  import static org.jomc.ant.test.support.Assert.assertMessageLoggedContaining;
42  import static org.jomc.ant.test.support.Assert.assertNoException;
43  import org.junit.Test;
44  import static org.junit.Assert.assertNotNull;
45  import static org.junit.Assert.fail;
46  
47  /**
48   * Test cases for class {@code org.jomc.ant.MergeModulesTask}.
49   *
50   * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
51   * @version $JOMC: MergeModulesTaskTest.java 4613 2012-09-22 10:07:08Z schulte $
52   */
53  public class MergeModulesTaskTest extends JomcModelTaskTest
54  {
55  
56      /** Creates a new {@code MergeModulesTaskTest} instance. */
57      public MergeModulesTaskTest()
58      {
59          super();
60      }
61  
62      /** {@inheritDoc} */
63      @Override
64      public MergeModulesTask getJomcTask()
65      {
66          return (MergeModulesTask) super.getJomcTask();
67      }
68  
69      /** {@inheritDoc} */
70      @Override
71      protected MergeModulesTask newJomcTask()
72      {
73          return new MergeModulesTask();
74      }
75  
76      /** {@inheritDoc} */
77      @Override
78      protected String getBuildFileName()
79      {
80          return "merge-modules-test.xml";
81      }
82  
83      @Test
84      public final void testMissingModuleFile() throws Exception
85      {
86          final AntExecutionResult r = this.executeTarget( "test-missing-module-file" );
87          assertException( r, BuildException.class );
88          assertExceptionMessage( r, "Mandatory attribute 'moduleFile' is missing a value." );
89      }
90  
91      @Test
92      public final void testMissingModuleName() throws Exception
93      {
94          final AntExecutionResult r = this.executeTarget( "test-missing-module-name" );
95          assertException( r, BuildException.class );
96          assertExceptionMessage( r, "Mandatory attribute 'moduleName' is missing a value." );
97      }
98  
99      @Test
100     public final void testExclusionMissingModuleName() throws Exception
101     {
102         final AntExecutionResult r = this.executeTarget( "test-exclusion-missing-module-name" );
103         assertException( r, BuildException.class );
104         assertExceptionMessage( r, "Mandatory attribute 'name' is missing a value." );
105     }
106 
107     @Test
108     public final void testInclusionMissingModuleName() throws Exception
109     {
110         final AntExecutionResult r = this.executeTarget( "test-inclusion-missing-module-name" );
111         assertException( r, BuildException.class );
112         assertExceptionMessage( r, "Mandatory attribute 'name' is missing a value." );
113     }
114 
115     @Test
116     public final void testMergeModules() throws Exception
117     {
118         final AntExecutionResult r = this.executeTarget( "test-merge-modules" );
119         assertNoException( r );
120         assertMessageLoggedContaining( r, "Writing", Project.MSG_INFO );
121     }
122 
123     @Test
124     public final void testMergeModulesWithNoopStylesheet() throws Exception
125     {
126         final AntExecutionResult r = this.executeTarget( "test-merge-modules-with-no-op-stylesheet" );
127         assertNoException( r );
128         assertMessageLoggedContaining( r, "Writing", Project.MSG_INFO );
129     }
130 
131     @Test
132     public final void testMergeModulesWithRedundantResources() throws Exception
133     {
134         final AntExecutionResult r = this.executeTarget( "test-merge-modules-with-redundant-resources" );
135         assertNoException( r );
136         assertMessageLoggedContaining( r, "Writing", Project.MSG_INFO );
137     }
138 
139     @Test
140     public final void testMergeModulesWithIllegalTransformationResultStylesheet() throws Exception
141     {
142         final AntExecutionResult r =
143             this.executeTarget( "test-merge-modules-with-illegal-transformation-result-stylesheet" );
144 
145         assertException( r, BuildException.class );
146         assertExceptionMessageContaining( r, "Illegal transformation result" );
147     }
148 
149     @Test
150     public final void testMergeModulesUnsupportedResource() throws Exception
151     {
152         final AntExecutionResult r = this.executeTarget( "test-merge-modules-unsupported-resource" );
153         assertNoException( r );
154         assertMessageLoggedContaining( r, "not supported.", Project.MSG_WARN );
155     }
156 
157     @Test
158     public final void testMergeModulesExclusion() throws Exception
159     {
160         final AntExecutionResult r = this.executeTarget( "test-merge-modules-exclusion" );
161         assertNoException( r );
162         assertMessageLogged( r, "Excluding module 'JOMC Ant Tasks Tests'.", Project.MSG_INFO );
163     }
164 
165     @Test
166     public final void testMergeModulesInclusion() throws Exception
167     {
168         final AntExecutionResult r = this.executeTarget( "test-merge-modules-inclusion" );
169         assertNoException( r );
170         assertMessageLogged( r, "Including module 'JOMC Ant Tasks Tests'.", Project.MSG_INFO );
171     }
172 
173     @Test
174     public final void testMergeModulesAllAttributes() throws Exception
175     {
176         final AntExecutionResult r = this.executeTarget( "test-merge-modules-all-attributes" );
177         assertNoException( r );
178         assertMessageLoggedContaining( r, "Writing", Project.MSG_INFO );
179     }
180 
181     @Test
182     public final void testIsModuleExcluded() throws Exception
183     {
184         try
185         {
186             this.getJomcTask().isModuleExcluded( null );
187             fail( "Expected 'NullPointerException' not thrown." );
188         }
189         catch ( final NullPointerException e )
190         {
191             assertNotNull( e.getMessage() );
192             System.out.println( e );
193         }
194     }
195 
196     @Test
197     public final void testIsModuleIncluded() throws Exception
198     {
199         try
200         {
201             this.getJomcTask().isModuleIncluded( null );
202             fail( "Expected 'NullPointerException' not thrown." );
203         }
204         catch ( final NullPointerException e )
205         {
206             assertNotNull( e.getMessage() );
207             System.out.println( e );
208         }
209     }
210 
211 }