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: MergeModletsTaskTest.java 3879 2011-10-24 00:59:27Z schulte2005 $
029     *
030     */
031    package org.jomc.ant.test;
032    
033    import org.apache.tools.ant.BuildException;
034    import org.apache.tools.ant.Project;
035    import org.jomc.ant.MergeModletsTask;
036    import org.jomc.ant.test.support.AntExecutionResult;
037    import static org.jomc.ant.test.support.Assert.assertException;
038    import static org.jomc.ant.test.support.Assert.assertExceptionMessage;
039    import static org.jomc.ant.test.support.Assert.assertExceptionMessageContaining;
040    import static org.jomc.ant.test.support.Assert.assertMessageLogged;
041    import static org.jomc.ant.test.support.Assert.assertMessageLoggedContaining;
042    import static org.jomc.ant.test.support.Assert.assertNoException;
043    import org.junit.Test;
044    import static org.junit.Assert.assertNotNull;
045    import static org.junit.Assert.fail;
046    
047    /**
048     * Test cases for class {@code org.jomc.ant.MergeModletsTask}.
049     *
050     * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a>
051     * @version $JOMC: MergeModletsTaskTest.java 3879 2011-10-24 00:59:27Z schulte2005 $
052     */
053    public class MergeModletsTaskTest extends JomcTaskTest
054    {
055    
056        /** Creates a new {@code MergeModletsTaskTest} instance. */
057        public MergeModletsTaskTest()
058        {
059            super();
060        }
061    
062        /** {@inheritDoc} */
063        @Override
064        public MergeModletsTask getJomcTask()
065        {
066            return (MergeModletsTask) super.getJomcTask();
067        }
068    
069        /** {@inheritDoc} */
070        @Override
071        protected MergeModletsTask newJomcTask()
072        {
073            return new MergeModletsTask();
074        }
075    
076        /** {@inheritDoc} */
077        @Override
078        protected String getBuildFileName()
079        {
080            return "merge-modlets-test.xml";
081        }
082    
083        @Test
084        public final void testMissingModletFile() throws Exception
085        {
086            final AntExecutionResult r = this.executeTarget( "test-missing-modlet-file" );
087            assertException( r, BuildException.class );
088            assertExceptionMessage( r, "Mandatory attribute 'modletFile' is missing a value." );
089        }
090    
091        @Test
092        public final void testMissingModletName() throws Exception
093        {
094            final AntExecutionResult r = this.executeTarget( "test-missing-modlet-name" );
095            assertException( r, BuildException.class );
096            assertExceptionMessage( r, "Mandatory attribute 'modletName' is missing a value." );
097        }
098    
099        @Test
100        public final void testExclusionMissingModletName() throws Exception
101        {
102            final AntExecutionResult r = this.executeTarget( "test-exclusion-missing-modlet-name" );
103            assertException( r, BuildException.class );
104            assertExceptionMessage( r, "Mandatory attribute 'name' is missing a value." );
105        }
106    
107        @Test
108        public final void testInclusionMissingModletName() throws Exception
109        {
110            final AntExecutionResult r = this.executeTarget( "test-inclusion-missing-modlet-name" );
111            assertException( r, BuildException.class );
112            assertExceptionMessage( r, "Mandatory attribute 'name' is missing a value." );
113        }
114    
115        @Test
116        public final void testModletResourceMissingLocation() throws Exception
117        {
118            final AntExecutionResult r = this.executeTarget( "test-modlet-resource-missing-locatiom" );
119            assertException( r, BuildException.class );
120            assertExceptionMessage( r, "Mandatory attribute 'location' is missing a value." );
121        }
122    
123        @Test
124        public final void testMergeModlets() throws Exception
125        {
126            final AntExecutionResult r = this.executeTarget( "test-merge-modlets" );
127            assertNoException( r );
128            assertMessageLoggedContaining( r, "Writing" );
129        }
130    
131        @Test
132        public final void testMergeModletsWithNoopStylesheet() throws Exception
133        {
134            final AntExecutionResult r = this.executeTarget( "test-merge-modlets-with-no-op-stylesheet" );
135            assertNoException( r );
136            assertMessageLoggedContaining( r, "Writing" );
137        }
138    
139        @Test
140        public final void testMergeModletsWithRedundantResources() throws Exception
141        {
142            final AntExecutionResult r = this.executeTarget( "test-merge-modlets-with-redundant-resources" );
143            assertNoException( r );
144            assertMessageLoggedContaining( r, "Writing" );
145        }
146    
147        @Test
148        public final void testMergeModletsWithIllegalTransformationResultStylesheet() throws Exception
149        {
150            final AntExecutionResult r =
151                this.executeTarget( "test-merge-modlets-with-illegal-transformation-result-stylesheet" );
152    
153            assertException( r, BuildException.class );
154            assertExceptionMessageContaining( r, "Illegal transformation result" );
155        }
156    
157        @Test
158        public final void testMergeModletsUnsupportedResource() throws Exception
159        {
160            final AntExecutionResult r = this.executeTarget( "test-merge-modlets-unsupported-resource" );
161            assertNoException( r );
162            assertMessageLoggedContaining( r, "not supported.", Project.MSG_WARN );
163        }
164    
165        @Test
166        public final void testMergeModletsExclusion() throws Exception
167        {
168            final AntExecutionResult r = this.executeTarget( "test-merge-modlets-exclusion" );
169            assertNoException( r );
170            assertMessageLogged( r, "Excluding modlet 'JOMC Ant Tasks Tests'.", Project.MSG_INFO );
171        }
172    
173        @Test
174        public final void testMergeModletsInclusion() throws Exception
175        {
176            final AntExecutionResult r = this.executeTarget( "test-merge-modlets-inclusion" );
177            assertNoException( r );
178            assertMessageLogged( r, "Including modlet 'JOMC Ant Tasks Tests'.", Project.MSG_INFO );
179        }
180    
181        @Test
182        public final void testMergeModletsAllAttributes() throws Exception
183        {
184            final AntExecutionResult r = this.executeTarget( "test-merge-modlets-all-attributes" );
185            assertNoException( r );
186            assertMessageLoggedContaining( r, "Writing", Project.MSG_INFO );
187        }
188    
189        @Test
190        public final void testIsModletExcluded() throws Exception
191        {
192            try
193            {
194                this.getJomcTask().isModletExcluded( null );
195                fail( "Expected 'NullPointerException' not thrown." );
196            }
197            catch ( final NullPointerException e )
198            {
199                assertNotNull( e.getMessage() );
200                System.out.println( e );
201            }
202        }
203    
204        @Test
205        public final void testIsModletIncluded() throws Exception
206        {
207            try
208            {
209                this.getJomcTask().isModletIncluded( null );
210                fail( "Expected 'NullPointerException' not thrown." );
211            }
212            catch ( final NullPointerException e )
213            {
214                assertNotNull( e.getMessage() );
215                System.out.println( e );
216            }
217        }
218    
219    }