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: GenerateResourcesTaskTest.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.GenerateResourcesTask; 036 import org.jomc.ant.ResourceProcessingException; 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.GenerateResourcesTask}. 047 * 048 * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 049 * @version $JOMC: GenerateResourcesTaskTest.java 3879 2011-10-24 00:59:27Z schulte2005 $ 050 */ 051 public class GenerateResourcesTaskTest extends ResourceFileProcessorTaskTest 052 { 053 054 /** Creates a new {@code GenerateResourcesTaskTest} instance. */ 055 public GenerateResourcesTaskTest() 056 { 057 super(); 058 } 059 060 /** {@inheritDoc} */ 061 @Override 062 public GenerateResourcesTask getJomcTask() 063 { 064 return (GenerateResourcesTask) super.getJomcTask(); 065 } 066 067 /** {@inheritDoc} */ 068 @Override 069 protected GenerateResourcesTask newJomcTask() 070 { 071 return new GenerateResourcesTask(); 072 } 073 074 /** {@inheritDoc} */ 075 @Override 076 protected String getBuildFileName() 077 { 078 return "generate-resources-test.xml"; 079 } 080 081 @Test 082 public final void testMissingResourcesDirectory() throws Exception 083 { 084 final AntExecutionResult r = this.executeTarget( "test-missing-resources-directory" ); 085 assertException( r, BuildException.class ); 086 assertExceptionMessage( r, "Mandatory attribute 'resourcesDirectory' 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 testResourceProcessingDisabled() throws Exception 115 { 116 final AntExecutionResult r = this.executeTarget( "test-resource-processing-disabled" ); 117 assertNoException( r ); 118 assertMessageLogged( r, "Resource file processing disabled.", Project.MSG_INFO ); 119 } 120 121 @Test 122 public final void testGenerateAntTaskResources() throws Exception 123 { 124 final AntExecutionResult r = this.executeTarget( "test-generate-ant-task-resources" ); 125 assertNoException( r ); 126 assertMessageLogged( r, "Resource file processing successful.", Project.MSG_INFO ); 127 } 128 129 @Test 130 public final void testGenerateAntTaskResourcesWithRedundantResources() throws Exception 131 { 132 final AntExecutionResult r = this.executeTarget( "test-generate-ant-task-resources-with-redundant-resources" ); 133 assertNoException( r ); 134 assertMessageLogged( r, "Resource file processing successful.", Project.MSG_INFO ); 135 } 136 137 @Test 138 public final void testGenerateOneSpecification() throws Exception 139 { 140 final AntExecutionResult r = this.executeTarget( "test-generate-one-specification" ); 141 assertNoException( r ); 142 assertMessageNotLogged( r, "Specification 'org.jomc.ant.test.JomcTask' not found." ); 143 assertMessageLogged( r, "Resource file processing successful.", Project.MSG_INFO ); 144 } 145 146 @Test 147 public final void testGenerateOneImplementation() throws Exception 148 { 149 final AntExecutionResult r = this.executeTarget( "test-generate-one-implementation" ); 150 assertNoException( r ); 151 assertMessageNotLogged( r, "Implementation 'org.jomc.ant.test.JomcToolTask' not found." ); 152 assertMessageLogged( r, "Resource file processing successful.", Project.MSG_INFO ); 153 } 154 155 @Test 156 public final void testGenerateOneModule() throws Exception 157 { 158 final AntExecutionResult r = this.executeTarget( "test-generate-one-module" ); 159 assertNoException( r ); 160 assertMessageNotLogged( r, "Module 'JOMC Ant Tasks Tests' not found." ); 161 assertMessageLogged( r, "Resource file processing successful.", Project.MSG_INFO ); 162 } 163 164 @Test 165 public final void testGenerateAntTaskResourcesWithClasspathref() throws Exception 166 { 167 final AntExecutionResult r = this.executeTarget( "test-generate-ant-task-resources-with-classpathref" ); 168 assertNoException( r ); 169 assertMessageLogged( r, "Resource file processing successful.", Project.MSG_INFO ); 170 } 171 172 @Test 173 public final void testGenerateAntTaskResourcesWithNestedClasspath() throws Exception 174 { 175 final AntExecutionResult r = this.executeTarget( "test-generate-ant-task-resources-with-nested-classpath" ); 176 assertNoException( r ); 177 assertMessageLogged( r, "Resource file processing successful.", Project.MSG_INFO ); 178 } 179 180 @Test 181 public final void testGenerateAntTaskResourcesAllAttributes() throws Exception 182 { 183 final AntExecutionResult r = this.executeTarget( "test-generate-ant-task-resources-all-attributes" ); 184 assertNoException( r ); 185 assertMessageLogged( r, "Resource file processing successful.", Project.MSG_INFO ); 186 } 187 188 @Test 189 public final void testGenerateAntTaskResourcesBrokenModel() throws Exception 190 { 191 final AntExecutionResult r = this.executeTarget( "test-generate-ant-task-resources-broken-model" ); 192 assertException( r, ResourceProcessingException.class ); 193 } 194 195 }