JavaGen JUnitEJB Unit Testing

Public Targets

TargetDescription
itsetupshow ant settings
itcheckverify proper build settings
itjarpackage distribution
testdistpackage target and test distribution files
rtestrun unit test(s) with report
itestrun unit test(s) with no dependencies
testcyclestart,deploy,deploydelay,itest,undeploy,stop

Source: ejbtest-junitejb.xml

				<?xml version="1.0" encoding="UTF-8"?>
<project name="ejbtest">
	<description>
  + ==\_/============J=A=V=A=G=E=N===A=N=T===M=O=D=U=L=E=S================= +
  +  \(_)/                                                                  +
  +  -(_)-              JavaGen JUnitEJB Unit Testing                       +
  +  /(_)\                                                                  +
  + ======================================================================= +
  +    Copyright (c) 2002-2005 Outsource Cafe, Inc.  All rights reserved.   +
  + ======================================================================= +
  +
  + OUT OF DATE - NEEDS UPDATING - Oct 2003
  +
  + Supports EJB Integration tests using JUnitEJB. 
  +
  + Targets: 
  +   itest     - runs JUnitEJB unit test(s) generating reports, no dependencies
  +   testcycle - builds, deploys, starts server (if not running), and tests
  +
  + Note: the 'it' prefix stands for integration tests.
  +
  + Prerequisites: props-global.xml, classpath.xml, appserver-?.xml, ejb.xml
  +
  +
  + developer: RichardEasterling@OutsourceCafe.com
  + ======================================================================= +
  + Licensed 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.
  + =J=A=M===========================================J=A=V=A=G=E=N=.=C=O=M= +
	</description>
	<property name="EJBTEST.PRESENT" value="true"></property>
	<!-- ===================================================================== -->
	<!-- properties for both this module and the target test module -->
	<!-- ===================================================================== -->
	<property name="testtool.name" value="JUnitEJB"></property>
	<property name="target.module.folder" location="${basedir}"></property>
	<property name="target.dist.dir" location="${target.module.folder}/${dist.folder}"></property>
	<property name="target.dist.name" value="${module.name}-${module.version}.jar"></property>
	<property name="target.dist.file" location="${target.dist.dir}/${target.dist.name}"></property>
	<property name="test.dist.name" value="${module.name}${dist.test.suffix}-${module.version}.ear"></property>
	<property name="test.dist.file" location="${dist.dir}/${test.dist.name}"></property>
	<property name="test.dist.jar.name" value="${module.name}${dist.test.suffix}-${module.version}.jar"></property>
	<property name="test.dist.jar.file" location="${dist.dir}/${test.dist.jar.name}"></property>
	<property name="appxml.template.file" location="${jam.home}/misc/application-2-ejb-template.xml"></property>
	<property name="test.last.failed.file" location="${build.test.dir}/.lasttestsfailed"></property>
	<!-- ===================================================================== -->
	<!--jars -->
	<!-- ===================================================================== -->
	<property name="junitejb.jar" location="${maven.repo}/junitejb/jars/junitejb-SNAPSHOT.jar"></property>
	<!-- ===================================================================== -->
	<!-- classpaths -->
	<!-- ===================================================================== -->
	<path id="test.build.classpath">
		<path refid="build.classpath"></path>
		<pathelement location="${junit.jar}"></pathelement>
		<pathelement location="${junitejb.jar}"></pathelement>
	</path>
	<path id="test.run.classpath">
		<path refid="build.classpath"></path>
		<pathelement location="${junit.jar}"></pathelement>
		<pathelement location="${junitejb.jar}"></pathelement>
		<path refid="appserver.client.classpath"></path>
		<pathelement location="${build.itest.classes.dir}"></pathelement>
	</path>
	<!-- ===================================================================== -->
	<!-- setup -->
	<!-- ===================================================================== -->
	<target name="itsetup" depends="" description="show ant settings">
		<echo message="+ ==\_/===============&lt;JavaGen&gt;===================== +"></echo>
		<echo message="+  \(_)/                                             +"></echo>
		<echo message="+  -(_)-         Unit Test Settings                  +"></echo>
		<echo message="+  /(_)\                                             +"></echo>
		<echo message="+ ================================================== +"></echo>
		<echo message="module.name           = ${module.name}"></echo>
		<echo message="target.module.folder  = ${target.module.folder}"></echo>
		<echo message="target.dist.name      = ${target.dist.name}"></echo>
		<echo message="target.dist.dir       = ${target.dist.dir}"></echo>
		<echo message="test.dist.jar.file    = ${test.dist.jar.file}"></echo>
		<echo message="test.dist.file        = ${test.dist.file}"></echo>
		<echo message="testtool.name         = ${testtool.name}"></echo>
		<echo message="javagen.version       = ${javagen.version}"></echo>
		<echo message="appserver.name        = ${appserver.name}"></echo>
		<echo message="appserver.version     = ${appserver.version}"></echo>
		<echo message="appserver.deploy.dir  = ${appserver.deploy.dir}"></echo>
		<echo message="author                = ${author}"></echo>
		<echo message="user.home             = ${user.home}"></echo>
		<echo message="compiler.debug        = ${compiler.debug}"></echo>
		<echo message="java.home             = ${java.home}"></echo>
		<echo message="ant.home              = ${ant.home}"></echo>
		<echo message="xdoclet.home          = ${xdoclet.home}"></echo>
		<echo message="+ ================================================== +"></echo>
		<echo message=""></echo>
	</target>
	<!-- ===================================================================== -->
	<!-- list classpath -->
	<!-- ===================================================================== -->
	<target name="itcp" depends="">
		<pathconvert refid="test.run.classpath" property="test.classpath.list" pathsep="
"></pathconvert>
		<echo message="+ test.run.classpath================================= +"></echo>
		<echo message="${test.classpath.list}"></echo>
	</target>
	<!-- ===================================================================== -->
	<!-- sanity checks -->
	<!-- ===================================================================== -->
	<target name="itcheck" depends="check.appserver" description="verify proper build settings">
		<available property="jdk1.3+" classname="java.lang.StrictMath"></available>
		<condition property="junit.present">
			<and>
				<isset property="JBOSS3.PRESENT"></isset>
				<available file="${jboss.dist}/${jboss.configuration.lib}/${junit.jar.name}"></available>
			</and>
		</condition>
		<fail if="junit.present">Jar file "${junit.jar.name}" NOT found in jboss directory: ${jboss.dist}/${jboss.configuration.lib}. This will cause unit test problems using "junitejb". </fail>
		<antcall target="check-junit"></antcall>
	</target>
	<!-- ===================================================================== -->
	<!-- init -->
	<!-- ===================================================================== -->
	<target name="itinit" depends="">
		<mkdir dir="${src.itest.dir}"></mkdir>
		<mkdir dir="${gen.itest.dir}"></mkdir>
		<mkdir dir="${module.lib.dir}"></mkdir>
		<mkdir dir="${src.resources.dir}"></mkdir>
		<mkdir dir="${build.itest.classes.dir}"></mkdir>
		<mkdir dir="${build.itest.metainf.dir}"></mkdir>
		<!--
		<mkdir dir="${xdoclet.build.dir}"/>
		-->
	</target>
	<!-- =================================================================== -->
	<!-- creates unit tests war = JUnitEE -->
	<!-- =================================================================== -->
	<target name="itgen" depends="itinit">
		<copy file="${appxml.template.file}" tofile="${build.itest.metainf.dir}/application.xml" overwrite="true">
			<filterset>
				<filter token="TARGET-JAR" value="${target.dist.name}"></filter>
				<filter token="TEST-JAR" value="${test.dist.jar.name}"></filter>
			</filterset>
		</copy>
		<!--
		<taskdef name="webdoclet" classname="xdoclet.modules.web.WebDocletTask" classpathref="xdoclet.classpath"/>
		<webdoclet destdir="${build.webinf.dir}" mergeDir="${src.merge.dir}">
			<fileset dir="${src.java.dir}" includes="**/*Servlet.java"/>
			<fileset dir="${gen.java.dir}" includes="**/*Servlet.java"/>
			<deploymentdescriptor servletspec="${servlet.spec.version}" distributable="false"/>
		</webdoclet>
		-->
	</target>
	<!-- =================================================================== -->
	<!-- compiles the source code                                            -->
	<!-- =================================================================== -->
	<target name="itcompile" depends="itgen">
		<javac destdir="${build.itest.classes.dir}" classpathref="test.build.classpath" debug="${compiler.debug}" deprecation="${compiler.deprecation}" optimize="${compiler.optimize}" compiler="${compiler.type}">
			<!--
			<src path="${xdoclet.build.dir}"/>
			-->
			<src path="${src.itest.dir}"></src>
			<src path="${gen.itest.dir}"></src>
		</javac>
		<copy todir="${build.itest.classes.dir}">
			<fileset dir="${src.itest.dir}" includes="**/*.properties,**/*.xml"></fileset>
			<fileset dir="${gen.itest.dir}" includes="**/*.properties,**/*.xml"></fileset>
			<!--
			<fileset dir="${xdoclet.build.dir}" includes="**/*.properties"/>
			<fileset dir="${src.resources.dir}" includes="**/*.properties,**/*.xml"/>
			-->
		</copy>
	</target>
	<!-- =================================================================== -->
	<!-- check for target dist file -->
	<!-- =================================================================== -->
	<target name="dist.target.file.exists">
		<available property="target.dist.file.found" file="${target.dist.file}" type="file"></available>
		<echo message="target.dist.file.found = ${target.dist.file.found}"></echo>
	</target>
	<!--
	<target name="dist.target" depends="dist.target.file.exists" unless="target.dist.file.found">
		<ant dir="${target.module.folder}" antfile="ejb-build.xml" target="dist" inheritAll="false"/>
	</target>
-->
	<target name="itjar" depends="itcompile" description="package distribution">
		<delete file="${test.dist.jar.file}"></delete>
		<mkdir dir="${dist.dir}"></mkdir>
		<jar jarfile="${test.dist.jar.file}">
			<fileset dir="${build.itest.classes.dir}" includes="**"></fileset>
			<zipfileset src="${junitejb.jar}" excludes="**/MANIFEST.MF"></zipfileset>
		</jar>
	</target>
	<!--
	<target name="ear" depends="dist.target, jar">
-->
	<target name="itear" depends="itjar">
		<delete file="${test.dist.file}"></delete>
		<ear destfile="${test.dist.file}" appxml="${src.metainf.dir}/application.xml">
			<fileset dir="${dist.dir}" includes="*.war,*.jar"></fileset>
			<!--
			<fileset dir="${target.dist.dir}" includes="*.war,*.jar"/>
			-->
			<fileset dir="${module.lib.dir}" includes="*.jar"></fileset>
		</ear>
		<!--   
			<fileset dir="${junit.dist.dir}" includes="junit*.jar"/>
		<delete file="${war.file}"/>
		-->
	</target>
	<!-- =================================================================== -->
	<!-- creates distribution target and test archives -->
	<!-- =================================================================== -->
	<target name="testdist" depends="itear" description="package target and test distribution files"></target>
	<!-- =================================================================== -->
	<!-- check src and unit test(s) are uptodate for rtest target -->
	<!-- =================================================================== -->
	<target name="itcheck.uptodate">
		<condition property="iitests.uptodate">
			<and>
				<uptodate>
					<srcfiles dir="${src.java.dir}" includes="**/*.java"></srcfiles>
					<srcfiles dir="${gen.java.dir}" includes="**/*.java"></srcfiles>
					<srcfiles dir="${xdoclet.build.java.dir}" includes="**/*.java"></srcfiles>
					<mapper type="glob" from="*.java" to="${build.classes.dir}/*.class"></mapper>
				</uptodate>
				<uptodate>
					<srcfiles dir="${src.itest.dir}" includes="**/*.java"></srcfiles>
					<srcfiles dir="${gen.itest.dir}" includes="**/*.java"></srcfiles>
					<mapper type="glob" from="*.java" to="${build.itest.classes.dir}/*.class"></mapper>
				</uptodate>
				<uptodate>
					<srcfiles dir="${src.itest.dir}" excludes="**/*.java"></srcfiles>
					<srcfiles dir="${gen.itest.dir}" excludes="**/*.java"></srcfiles>
					<mapper type="glob" from="*" to="${build.itest.classes.dir}/*"></mapper>
				</uptodate>
				<!--
				-->
				<not>
					<available file="${test.last.failed.file}"></available>
				</not>
				<not>
					<isset property="testcase"></isset>
				</not>
				<uptodate>
					<srcfiles dir="${src.itest.dir}" includes="**/*.java"></srcfiles>
					<srcfiles dir="${gen.itest.dir}" includes="**/*.java"></srcfiles>
					<mapper type="package" from="*Test.java" to="${build.itest.reports.dir}/TEST-*Test.xml"></mapper>
				</uptodate>
			</and>
		</condition>
		<echo>itests.uptodate = ${itests.uptodate}</echo>
	</target>
	<!-- =================================================================== -->
	<!-- run unit test(s) producing report -->
	<!-- =================================================================== -->
	<target name="rtest" depends="itcheck.uptodate" unless="itests.uptodate" description="run unit test(s) with report">
		<delete dir="${build.test.docs.dir}" failonerror="false"></delete>
		<delete dir="${build.itest.reports.dir}" failonerror="false"></delete>
		<mkdir dir="${build.test.docs.dir}"></mkdir>
		<mkdir dir="${build.itest.reports.dir}"></mkdir>
		<junit printsummary="false" errorProperty="test.failed" failureProperty="test.failed">
			<classpath refid="test.run.classpath"></classpath>
			<formatter type="brief" usefile="false"></formatter>
			<formatter type="xml"></formatter>
			<sysproperty key="java.naming.factory.initial" value="${appserver.java.naming.factory.initial}"></sysproperty>
			<sysproperty key="java.naming.provider.url" value="${appserver.java.naming.provider.url}"></sysproperty>
			<sysproperty key="java.naming.factory.url.pkgs" value="${appserver.java.naming.factory.url.pkgs}"></sysproperty>
			<test name="${testcase}" todir="${build.itest.reports.dir}" if="testcase"></test>
			<batchtest todir="${build.itest.reports.dir}" unless="testcase">
				<fileset dir="${build.itest.classes.dir}" includes="**/*Test.class"></fileset>
			</batchtest>
		</junit>
		<junitreport todir="${build.test.docs.dir}">
			<fileset dir="${build.itest.reports.dir}">
				<include name="TEST-*.xml"></include>
			</fileset>
			<report format="noframes" todir="${build.test.docs.dir}"></report>
		</junitreport>
		<echo message="last build failed tests" file="${test.last.failed.file}"></echo>
		<fail message="Tests failed. Check log and/or reports." if="test.failed"></fail>
		<!-- Remove test failed file, as these tests succeeded -->
		<delete file="${test.last.failed.file}" failonerror="false"></delete>
	</target>
	<!-- =================================================================== -->
	<!-- run AllTests class -->
	<!-- =================================================================== -->
	<target name="itest" depends="" description="run unit test(s) with no dependencies">
		<java fork="yes" classname="junit.textui.TestRunner" taskname="junit" failonerror="true">
			<arg value="AllTests"></arg>
			<sysproperty key="java.naming.factory.initial" value="${appserver.java.naming.factory.initial}"></sysproperty>
			<sysproperty key="java.naming.provider.url" value="${appserver.java.naming.provider.url}"></sysproperty>
			<sysproperty key="java.naming.factory.url.pkgs" value="${appserver.java.naming.factory.url.pkgs}"></sysproperty>
			<classpath refid="test.run.classpath"></classpath>
		</java>
	</target>
	<!-- =================================================================== -->
	<!-- testcycle: start,deploy,deploydelay,test,undeploy,stop -->
	<!-- =================================================================== -->
	<target name="testcycle" depends="started" description="start,deploy,deploydelay,itest,undeploy,stop">
		<parallel>
			<antcall target="start"></antcall>
			<sequential>
				<echo>START-WAIT</echo>
				<echo>server.started   = ${server.started}</echo>
				<waitfor maxwait="${appserver.start.delay}" maxwaitunit="second" checkevery="5" checkeveryunit="second">
					<isset property="server.started"></isset>
				</waitfor>
				<echo>END-WAIT</echo>
				<antcall target="poststartsequence"></antcall>
			</sequential>
		</parallel>
	</target>
	<!-- =================================================================== -->
	<!-- post-start sequence supports testcycle -->
	<!-- =================================================================== -->
	<target name="poststartsequence" depends="deploy,deploydelay,itest,undeploy,stop"></target>
</project>