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: ValidateClassesTaskTest.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.apache.tools.ant.Project;
035import org.jomc.ant.ClassProcessingException;
036import org.jomc.ant.ValidateClassesTask;
037import org.jomc.ant.test.support.AntExecutionResult;
038import static org.jomc.ant.test.support.Assert.assertException;
039import static org.jomc.ant.test.support.Assert.assertExceptionMessage;
040import static org.jomc.ant.test.support.Assert.assertMessageLogged;
041import static org.jomc.ant.test.support.Assert.assertMessageNotLogged;
042import static org.jomc.ant.test.support.Assert.assertNoException;
043import org.junit.Test;
044
045/**
046 * Test cases for class {@code org.jomc.ant.ValidateClassesTask}.
047 *
048 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
049 * @version $JOMC: ValidateClassesTaskTest.java 4613 2012-09-22 10:07:08Z schulte $
050 */
051public class ValidateClassesTaskTest extends ClassFileProcessorTaskTest
052{
053
054    /** Creates a new {@code ValidateClassesTaskTest} instance. */
055    public ValidateClassesTaskTest()
056    {
057        super();
058    }
059
060    /** {@inheritDoc} */
061    @Override
062    public ValidateClassesTask getJomcTask()
063    {
064        return (ValidateClassesTask) super.getJomcTask();
065    }
066
067    /** {@inheritDoc} */
068    @Override
069    protected ValidateClassesTask newJomcTask()
070    {
071        return new ValidateClassesTask();
072    }
073
074    /** {@inheritDoc} */
075    @Override
076    protected String getBuildFileName()
077    {
078        return "validate-classes-test.xml";
079    }
080
081    @Test
082    public final void testMissingClassesDirectory() throws Exception
083    {
084        final AntExecutionResult r = this.executeTarget( "test-missing-classes-directory" );
085        assertException( r, BuildException.class );
086        assertExceptionMessage( r, "Mandatory attribute 'classesDirectory' is missing a value." );
087    }
088
089    @Test
090    public final void testSpecificationNotFound() throws Exception
091    {
092        final AntExecutionResult r = this.executeTarget( "test-specification-not-found" );
093        assertNoException( r );
094        assertMessageLogged( r, "Specification 'DOES NOT EXIST' not found.", Project.MSG_WARN );
095    }
096
097    @Test
098    public final void testImplementationNotFound() throws Exception
099    {
100        final AntExecutionResult r = this.executeTarget( "test-implementation-not-found" );
101        assertNoException( r );
102        assertMessageLogged( r, "Implementation 'DOES NOT EXIST' not found.", Project.MSG_WARN );
103    }
104
105    @Test
106    public final void testModuleNotFound() throws Exception
107    {
108        final AntExecutionResult r = this.executeTarget( "test-module-not-found" );
109        assertNoException( r );
110        assertMessageLogged( r, "Module 'DOES NOT EXIST' not found.", Project.MSG_WARN );
111    }
112
113    @Test
114    public final void testClassProcessingDisabled() throws Exception
115    {
116        final AntExecutionResult r = this.executeTarget( "test-class-processing-disabled" );
117        assertNoException( r );
118        assertMessageLogged( r, "Class file processing disabled.", Project.MSG_INFO );
119    }
120
121    @Test
122    public final void testValidateAntTasks() throws Exception
123    {
124        final AntExecutionResult r = this.executeTarget( "test-validate-ant-tasks" );
125        assertNoException( r );
126    }
127
128    @Test
129    public final void testValidateAntTasksWithRedundantResources() throws Exception
130    {
131        final AntExecutionResult r = this.executeTarget( "test-validate-ant-tasks-with-redundant-resources" );
132        assertNoException( r );
133    }
134
135    @Test
136    public final void testValidateIllegalAntTasks() throws Exception
137    {
138        final AntExecutionResult r = this.executeTarget( "test-validate-illegal-ant-tasks" );
139        assertException( r, ClassProcessingException.class );
140    }
141
142    @Test
143    public final void testValidateOneSpecification() throws Exception
144    {
145        final AntExecutionResult r = this.executeTarget( "test-validate-one-specification" );
146        assertNoException( r );
147        assertMessageNotLogged( r, "Specification 'org.jomc.ant.test.JomcTask' not found." );
148    }
149
150    @Test
151    public final void testValidateOneIllegalSpecification() throws Exception
152    {
153        final AntExecutionResult r = this.executeTarget( "test-validate-one-illegal-specification" );
154        assertException( r, ClassProcessingException.class );
155    }
156
157    @Test
158    public final void testValidateOneImplementation() throws Exception
159    {
160        final AntExecutionResult r = this.executeTarget( "test-validate-one-implementation" );
161        assertNoException( r );
162        assertMessageNotLogged( r, "Implementation 'org.jomc.ant.test.JomcToolTask' not found." );
163    }
164
165    @Test
166    public final void testValidateOneIllegalImplementation() throws Exception
167    {
168        final AntExecutionResult r = this.executeTarget( "test-validate-one-illegal-implementation" );
169        assertException( r, ClassProcessingException.class );
170    }
171
172    @Test
173    public final void testValidateOneModule() throws Exception
174    {
175        final AntExecutionResult r = this.executeTarget( "test-validate-one-module" );
176        assertNoException( r );
177        assertMessageNotLogged( r, "Module 'JOMC Ant Tasks Tests' not found." );
178    }
179
180    @Test
181    public final void testValidateOneIllegalModule() throws Exception
182    {
183        final AntExecutionResult r = this.executeTarget( "test-validate-one-illegal-module" );
184        assertException( r, ClassProcessingException.class );
185    }
186
187    @Test
188    public final void testValidateAntTasksWithClasspathref() throws Exception
189    {
190        final AntExecutionResult r = this.executeTarget( "test-validate-ant-tasks-with-classpathref" );
191        assertNoException( r );
192    }
193
194    @Test
195    public final void testValidateAntTasksWithNestedClasspath() throws Exception
196    {
197        final AntExecutionResult r = this.executeTarget( "test-validate-ant-tasks-with-nested-classpath" );
198        assertNoException( r );
199    }
200
201    @Test
202    public final void testValidateAntTasksDeprecatedAttributes() throws Exception
203    {
204        final AntExecutionResult r = this.executeTarget( "test-validate-ant-tasks-deprecated-attributes" );
205        assertNoException( r );
206    }
207
208    @Test
209    public final void testValidateAntTasksAllAttributes() throws Exception
210    {
211        final AntExecutionResult r = this.executeTarget( "test-validate-ant-tasks-all-attributes" );
212        assertNoException( r );
213    }
214
215    @Test
216    public final void testValidateAntTasksBrokenModel() throws Exception
217    {
218        final AntExecutionResult r = this.executeTarget( "test-validate-ant-tasks-broken-model" );
219        assertException( r, ClassProcessingException.class );
220    }
221
222}