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: CommitClassesTaskTest.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.ClassProcessingException; 036 import org.jomc.ant.CommitClassesTask; 037 import org.jomc.ant.test.support.AntExecutionResult; 038 import static org.jomc.ant.test.support.Assert.assertException; 039 import static org.jomc.ant.test.support.Assert.assertExceptionMessage; 040 import static org.jomc.ant.test.support.Assert.assertMessageLogged; 041 import static org.jomc.ant.test.support.Assert.assertMessageNotLogged; 042 import static org.jomc.ant.test.support.Assert.assertNoException; 043 import org.junit.Test; 044 045 /** 046 * Test cases for class {@code org.jomc.ant.CommitClassesTask}. 047 * 048 * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 049 * @version $JOMC: CommitClassesTaskTest.java 3879 2011-10-24 00:59:27Z schulte2005 $ 050 */ 051 public class CommitClassesTaskTest extends ClassFileProcessorTaskTest 052 { 053 054 /** Creates a new {@code CommitClassesTaskTest} instance. */ 055 public CommitClassesTaskTest() 056 { 057 super(); 058 } 059 060 /** {@inheritDoc} */ 061 @Override 062 public CommitClassesTask getJomcTask() 063 { 064 return (CommitClassesTask) super.getJomcTask(); 065 } 066 067 /** {@inheritDoc} */ 068 @Override 069 protected CommitClassesTask newJomcTask() 070 { 071 return new CommitClassesTask(); 072 } 073 074 /** {@inheritDoc} */ 075 @Override 076 protected String getBuildFileName() 077 { 078 return "commit-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 testStylesheetMissingLocationKey() throws Exception 091 { 092 final AntExecutionResult r = this.executeTarget( "test-stylesheet-missing-location" ); 093 assertException( r, BuildException.class ); 094 assertExceptionMessage( r, "Mandatory attribute 'location' is missing a value." ); 095 } 096 097 @Test 098 public final void testStylesheetNotFound() throws Exception 099 { 100 final AntExecutionResult r = this.executeTarget( "test-stylesheet-not-found" ); 101 assertException( r, BuildException.class ); 102 assertExceptionMessage( r, "XSLT document 'DOES_NOT_EXIST' not found." ); 103 } 104 105 @Test 106 public final void testOptionalStylesheetNotFound() throws Exception 107 { 108 final AntExecutionResult r = this.executeTarget( "test-optional-stylesheet-not-found" ); 109 assertNoException( r ); 110 assertMessageLogged( r, "XSLT document 'DOES_NOT_EXIST' not found." ); 111 } 112 113 @Test 114 public final void testSpecificationNotFound() throws Exception 115 { 116 final AntExecutionResult r = this.executeTarget( "test-specification-not-found" ); 117 assertNoException( r ); 118 assertMessageLogged( r, "Specification 'DOES NOT EXIST' not found.", Project.MSG_WARN ); 119 } 120 121 @Test 122 public final void testImplementationNotFound() throws Exception 123 { 124 final AntExecutionResult r = this.executeTarget( "test-implementation-not-found" ); 125 assertNoException( r ); 126 assertMessageLogged( r, "Implementation 'DOES NOT EXIST' not found.", Project.MSG_WARN ); 127 } 128 129 @Test 130 public final void testModuleNotFound() throws Exception 131 { 132 final AntExecutionResult r = this.executeTarget( "test-module-not-found" ); 133 assertNoException( r ); 134 assertMessageLogged( r, "Module 'DOES NOT EXIST' not found.", Project.MSG_WARN ); 135 } 136 137 @Test 138 public final void testClassProcessingDisabled() throws Exception 139 { 140 final AntExecutionResult r = this.executeTarget( "test-class-processing-disabled" ); 141 assertNoException( r ); 142 assertMessageLogged( r, "Class file processing disabled.", Project.MSG_INFO ); 143 } 144 145 @Test 146 public final void testCommitAntTasks() throws Exception 147 { 148 final AntExecutionResult r = this.executeTarget( "test-commit-ant-tasks" ); 149 assertNoException( r ); 150 assertMessageLogged( r, "Class file processing successful.", Project.MSG_INFO ); 151 } 152 153 @Test 154 public final void testCommitAntTasksWithNoopStylesheet() throws Exception 155 { 156 final AntExecutionResult r = this.executeTarget( "test-commit-ant-tasks-with-no-op-stylesheet" ); 157 assertNoException( r ); 158 assertMessageLogged( r, "Class file processing successful.", Project.MSG_INFO ); 159 } 160 161 @Test 162 public final void testCommitAntTasksWithRedundantResources() throws Exception 163 { 164 final AntExecutionResult r = this.executeTarget( "test-commit-ant-tasks-with-redundant-resources" ); 165 assertNoException( r ); 166 assertMessageLogged( r, "Class file processing successful.", Project.MSG_INFO ); 167 } 168 169 @Test 170 public final void testCommitOneSpecification() throws Exception 171 { 172 final AntExecutionResult r = this.executeTarget( "test-commit-one-specification" ); 173 assertNoException( r ); 174 assertMessageLogged( r, "Class file processing successful.", Project.MSG_INFO ); 175 assertMessageNotLogged( r, "Specification 'org.jomc.ant.test.JomcTask' not found." ); 176 } 177 178 @Test 179 public final void testCommitOneImplementation() throws Exception 180 { 181 final AntExecutionResult r = this.executeTarget( "test-commit-one-implementation" ); 182 assertNoException( r ); 183 assertMessageLogged( r, "Class file processing successful.", Project.MSG_INFO ); 184 assertMessageNotLogged( r, "Implementation 'org.jomc.ant.test.JomcToolTask' not found." ); 185 } 186 187 @Test 188 public final void testCommitOneModule() throws Exception 189 { 190 final AntExecutionResult r = this.executeTarget( "test-commit-one-module" ); 191 assertNoException( r ); 192 assertMessageLogged( r, "Class file processing successful.", Project.MSG_INFO ); 193 assertMessageNotLogged( r, "Module 'JOMC Ant Tasks Tests' not found." ); 194 } 195 196 @Test 197 public final void testCommitOneSpecificationWithNoopStylesheet() throws Exception 198 { 199 final AntExecutionResult r = this.executeTarget( "test-commit-one-specification-with-no-op-stylesheet" ); 200 assertNoException( r ); 201 assertMessageLogged( r, "Class file processing successful.", Project.MSG_INFO ); 202 assertMessageNotLogged( r, "Specification 'org.jomc.ant.test.JomcTask' not found." ); 203 } 204 205 @Test 206 public final void testCommitOneImplementationWithNoopStylesheet() throws Exception 207 { 208 final AntExecutionResult r = this.executeTarget( "test-commit-one-implementation-with-no-op-stylesheet" ); 209 assertNoException( r ); 210 assertMessageLogged( r, "Class file processing successful.", Project.MSG_INFO ); 211 assertMessageNotLogged( r, "Implementation 'org.jomc.ant.test.JomcToolTask' not found." ); 212 } 213 214 @Test 215 public final void testCommitOneModuleWithNoopStylesheet() throws Exception 216 { 217 final AntExecutionResult r = this.executeTarget( "test-commit-one-module-with-no-op-stylesheet" ); 218 assertNoException( r ); 219 assertMessageLogged( r, "Class file processing successful.", Project.MSG_INFO ); 220 assertMessageNotLogged( r, "Module 'JOMC Ant Tasks Tests' not found." ); 221 } 222 223 @Test 224 public final void testCommitAntTasksWithClasspathref() throws Exception 225 { 226 final AntExecutionResult r = this.executeTarget( "test-commit-ant-tasks-with-classpathref" ); 227 assertNoException( r ); 228 assertMessageLogged( r, "Class file processing successful.", Project.MSG_INFO ); 229 } 230 231 @Test 232 public final void testCommitAntTasksWithNestedClasspath() throws Exception 233 { 234 final AntExecutionResult r = this.executeTarget( "test-commit-ant-tasks-with-nested-classpath" ); 235 assertNoException( r ); 236 assertMessageLogged( r, "Class file processing successful.", Project.MSG_INFO ); 237 } 238 239 @Test 240 public final void testCommitAntTasksAllAttributes() throws Exception 241 { 242 final AntExecutionResult r = this.executeTarget( "test-commit-ant-tasks-all-attributes" ); 243 assertNoException( r ); 244 assertMessageLogged( r, "Class file processing successful.", Project.MSG_INFO ); 245 } 246 247 @Test 248 public final void testCommitAntTasksBrokenModel() throws Exception 249 { 250 final AntExecutionResult r = this.executeTarget( "test-commit-ant-tasks-broken-model" ); 251 assertException( r, ClassProcessingException.class ); 252 } 253 254 }