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: JomcToolTaskTest.java 4613 2012-09-22 10:07:08Z schulte $
029 *
030 */
031package org.jomc.ant.test;
032
033import org.apache.tools.ant.BuildException;
034import org.jomc.ant.JomcToolTask;
035import org.jomc.ant.test.support.AntExecutionResult;
036import static org.jomc.ant.test.support.Assert.assertException;
037import static org.jomc.ant.test.support.Assert.assertExceptionMessage;
038import org.junit.Test;
039import static org.junit.Assert.assertNotNull;
040import static org.junit.Assert.fail;
041
042/**
043 * Test cases for class {@code org.jomc.ant.JomcToolTask}.
044 *
045 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
046 * @version $JOMC: JomcToolTaskTest.java 4613 2012-09-22 10:07:08Z schulte $
047 */
048public class JomcToolTaskTest extends JomcModelTaskTest
049{
050
051    /** Creates a new {@code JomcToolTaskTest} instance. */
052    public JomcToolTaskTest()
053    {
054        super();
055    }
056
057    /** {@inheritDoc} */
058    @Override
059    public JomcToolTask getJomcTask()
060    {
061        return (JomcToolTask) super.getJomcTask();
062    }
063
064    /** {@inheritDoc} */
065    @Override
066    protected JomcToolTask newJomcTask()
067    {
068        return new JomcToolTask();
069    }
070
071    /** {@inheritDoc} */
072    @Override
073    protected String getBuildFileName()
074    {
075        return "jomc-tool-task-test.xml";
076    }
077
078    @Test
079    public final void testConfigureJomcTool() throws Exception
080    {
081        try
082        {
083            this.getJomcTask().configureJomcTool( null );
084            fail( "Expected 'NullPointerException' not thrown." );
085        }
086        catch ( final NullPointerException e )
087        {
088            assertNotNull( e.getMessage() );
089            System.out.println( e );
090        }
091    }
092
093    @Test
094    public final void testGetSpecification() throws Exception
095    {
096        try
097        {
098            this.getJomcTask().getSpecification( null );
099            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}