|
- <?xml version="1.0"?>
- <!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
-
- <project name="war-test" basedir="." default="antunit"
- xmlns:au="antlib:org.apache.ant.antunit">
- <property name="working.dir" value="working"/>
-
- <import file="../antunit-base.xml" />
-
- <target name="init">
- <delete dir="${working.dir}"/>
- <mkdir dir="${working.dir}"/>
- <property name="warfile" location="${working.dir}/test.war"/>
- <property name="web.xml" location="web.xml"/>
- <property name="webxml.generated" location="${working.dir}/WEB-INF/web.xml"/>
-
- <!--failing on duplicates is half our testing-->
- <presetdef name="mkwar">
- <war destfile="${warfile}" duplicate="fail"/>
- </presetdef>
- <presetdef name="expandwar">
- <unzip src="${working.dir}/test.war" dest="${working.dir}"/>
- </presetdef>
- </target>
-
- <target name="tearDown">
- <delete dir="${working.dir}"/>
- </target>
-
- <!--test that you can patch a fileset reference into a lib element-->
- <target name="testlibrefs" depends="init">
- <mkwar webxml="${web.xml}">
- <fileset id="test" dir="." includes="web.xml"/>
- <lib refid="test"/>
- </mkwar>
- <expandwar/>
- <au:assertFileExists file="${webxml.generated}" />
- </target>
-
- <!--
- This checks that as of Java EE 5, the web.xml attr is optional.
- Here there is a web.xml, in the webinf fileset, rather than a fileset
- -->
- <target name="testWebXmlInWebinf" depends="init">
- <mkwar>
- <webinf dir="." includes="web.xml"/>
- </mkwar>
- <expandwar/>
- <au:assertFileExists file="${webxml.generated}" />
- </target>
-
- <target name="testWebXmlMissingFromUpdate" depends="init">
- <mkwar webxml="${web.xml}" />
- <!-- there is no web.xml file, but that is ok, as
- we are updating -->
- <mkwar update="true">
- <classes dir="." includes="web.xml"/>
- </mkwar>
- <expandwar/>
- <au:assertFileExists file="${webxml.generated}" />
- </target>
-
- <target name="testWebXmlInImplicitUpdate" depends="init">
- <mkwar webxml="${web.xml}" />
- <!-- when we are implicitly updating, the web.xml file does not get
- pulled in, but the command still succeeds.-->
- <mkwar webxml="${web.xml}" >
- <classes dir="." includes="web.xml"/>
- </mkwar>
- <expandwar/>
- <au:assertFileExists file="${webxml.generated}" />
- </target>
-
- <target name="NotestWebXmlFilesetInImplicitUpdate" depends="init">
- <mkwar webxml="${web.xml}" />
- <!-- when we are implicitly updating, the web.xml file does not get
- pulled in, but the command still succeeds.-->
- <mkwar >
- <webinf dir="." includes="web.xml"/>
- </mkwar>
- <expandwar/>
- <au:assertFileExists file="${webxml.generated}" />
- </target>
-
-
- <target name="testDuplicateWebXml" depends="init">
- <mkwar webxml="${web.xml}" >
- <webinf dir="." includes="web.xml"/>
- <webinf file="${web.xml}"/>
- <zipfileset file="${web.xml}" prefix="WEB-INF"/>
- </mkwar>
- <expandwar/>
- <au:assertFileExists file="${webxml.generated}" />
- </target>
-
- <target name="testDifferentDuplicateWebXml" depends="init">
- <copy file="${web.xml}" todir="${working.dir}" />
- <mkwar webxml="${web.xml}" >
- <webinf dir="${working.dir}" includes="web.xml"/>
- <webinf file="${web.xml}"/>
- <zipfileset file="${web.xml}" prefix="WEB-INF"/>
- </mkwar>
- <expandwar/>
- <au:assertFileExists file="${webxml.generated}" />
- <au:assertLogContains text="The duplicate entry is"/>
- </target>
-
-
- <!--
- this target does not have a web.xml file.
- Instead it pulls in
- -->
- <target name="testWebXmlOptional" depends="init">
- <mkwar needxmlfile="false">
- <classes dir="." includes="web.xml"/>
- </mkwar>
- <expandwar/>
- <au:assertFileExists file="${working.dir}/WEB-INF/classes/web.xml" />
- <au:assertFalse>
- <available file="${webxml.generated}" />
- </au:assertFalse>
- </target>
-
- <target name="testWebXmlOptionalFailure" depends="init">
- <au:expectfailure>
- <mkwar >
- <classes dir="." includes="web.xml"/>
- </mkwar>
- </au:expectfailure>
- </target>
-
- <target name="testWebXmlOptionalFailure2" depends="init">
- <au:expectfailure>
- <mkwar needxmlfile="true">
- <classes dir="." includes="web.xml"/>
- </mkwar>
- </au:expectfailure>
- </target>
-
- <target name="testClassesElement" depends="init">
- <mkwar needxmlfile="false">
- <classes dir="." includes="web.xml"/>
- </mkwar>
- <expandwar/>
- <au:assertFileExists file="${working.dir}/WEB-INF/classes/web.xml" />
- </target>
-
- <target name="testLibElement" depends="init">
- <mkwar needxmlfile="false">
- <lib dir="." includes="web.xml"/>
- </mkwar>
- <expandwar/>
- <au:assertFileExists file="${working.dir}/WEB-INF/lib/web.xml" />
- </target>
-
- <target name="testMappedClasspathFromManual">
- <mkdir dir="${input}"/>
- <mkdir dir="${output}/out"/>
- <war destfile="${output}/test.war" webxml="${ant.file}">
- <mappedresources>
- <restrict>
- <path path="${java.class.path}"/>
- <type type="file"/>
- </restrict>
- <chainedmapper>
- <flattenmapper/>
- <globmapper from="*" to="WEB-INF/lib/*"/>
- </chainedmapper>
- </mappedresources>
- </war>
- <unzip src="${output}/test.war" dest="${output}/out"/>
- <au:assertFileExists file="${output}/out/WEB-INF/lib/ant.jar"/>
- </target>
- </project>
|