topical media & game development

talk show tell print

professional-portal-11-build-portal-tests.xml / xml



  <?xml version="1.0"?>
  <project name="junitTest" default="help">
  
    <property environment="env"/>
    <property file="build.properties"/>
    <property name="deploy.dir" value="./deploy" />
    <property name="app.name" value="PORTAL"/>
    <property name="lib.path" value="."/>
    
    <!-- CVS -->
    <property name="cvs.username" value="" />
    <property name="cvs.hostname" value="" />
    <property name="cvs.dir" value="" />
    <property name="cvs.module" value="" /> 
   
    <!-- Setup the system classpath -->
    <path id="system.classpath">
      <pathelement path="{lib.path}/AntelopeTasks.jar"/>
      <pathelement path="{lib.path}/portal_interactive.jar"/>
      <pathelement path="{env.ANT_HOME}"/>
    </path>
   
    <!-- task definitions -->
    <taskdef name="if" classname="ise.antelope.tasks.IfTask" classpathref="system.classpath" />
    <taskdef name="interactive" classname="portal.Interactive" classpathref="system.classpath" />
  
    <target name="run_interactive_display_test">
      <interactive verbose="off">
        <input property="dir" text="Directory" type="dir" value="c:\Java_Portal_book\JUnit" /> 
        <input property="test" text="Test Selection" type="test" />
        <input property="junit" text="Run JUNIT GUI/non-GUI" type="junit" />
        <input property="cvs" text="Checkout code from CVS?" type="cvs" />
      </interactive>
      <echo> Directory : {dir} </echo>
      <echo> Test selection : {test} </echo>
      <echo> JUnit run selection : {junit} </echo>
      <echo> Checkout code from CVS? : {cvs} </echo>
                          
      <if name="cvs" value="Checkout code from CVS">
        <antcall target="cvs_code_checkout"/>
      </if>
          
      <if name="test" value="-- Select Test">
        <echo> No test selected. Please select a test. </echo>
        <else>
          <if name="junit" value="-- Select GUI/non-GUI">
            <echo> No JUnit option selected. Please select a JUnit option. </echo>
            <else>        
              <if name="test" value="Test1">
                <echo> Test1 selected </echo>
                <if name="junit" value="Run w/ GUI">
                  <antcall target="portal_test1_gui"/>
                <else>
                  <antcall target="portal_test1_nongui"/>
                </else>
                </if>
              <else>
                <if name="test" value="Test2">
                  <echo> Test2 selected </echo>
                  <if name="junit" value="Run w/ GUI">
                    <antcall target="portal_test2_gui"/>
                  <else>
                    <antcall target="portal_test2_nongui"/>
                  </else>
                  </if>
                            <else>
                              <echo> All tests [Test1/Test2] selected </echo>
                              <if name="junit" value="Run w/ GUI">
                                <antcall target="portal_test1_gui"/>
                    <antcall target="portal_test2_gui"/>
                  <else>
                    <antcall target="portal_test1_nongui"/>
                    <antcall target="portal_test2_nongui"/>
                  </else>
                                  </if>
                            </else>
                </if>
              </else>
                          </if>
                    </else>
          </if>        
        </else>
          </if>
    </target>
   
    <target name="run_commmandline_test">
      <!-- read from properties files -->
      <echo>Directory        : {dir} </echo>
      <echo>Test selection   : {test} </echo>
  
      <if name="test" value="-- Select a test">
        <echo> No test selected </echo>
        <else>
          <if name="test" value="Test1">
            <echo> Test1 </echo>
          <else>
            <antcall target="portal_tests"/>
          </else>
          </if>
        </else>
      </if>
    </target>
   
    <target name="portal_test1_gui">
      <java fork="yes" classname="junit.awtui.TestRunner" 
            taskname="junit" failonerror="true">
        <arg value="validateFormTestCase1"/>
        <classpath>
          <pathelement path="{lib.path}" />
          <pathelement path="{java.class.path}" />
        </classpath>
      </java>
    </target>
          
    <target name="portal_test2_gui">
      <java fork="yes" classname="junit.awtui.TestRunner" 
            taskname="junit" failonerror="true">
        <arg value="validateFormTestCase2"/>
        <classpath>
          <pathelement path="{lib.path}" />
          <pathelement path="{java.class.path}" />
        </classpath>
      </java>
    </target>
                  
    <target name="portal_test1_nongui">
      <echo message="Running JUnit tests." />
      <junit printsummary="true">
        <formatter type="xml" />         
        <test name="validateFormTestCase1" />
        <classpath>
          <pathelement location="." />
        </classpath>
      </junit>
      <junitreport todir=".">
        <fileset dir=".">
          <include name="TEST-*.xml" />
        </fileset>
        <report format="frames" todir="." />
      </junitreport>
    </target>
          
    <target name="portal_test2_nongui">
      <echo message="Running JUnit tests." />
      <junit printsummary="true">
        <formatter type="xml" />         
        <test name="validateFormTestCase2" />
        <classpath>
          <pathelement location="." />
        </classpath>
      </junit>
      <junitreport todir=".">
        <fileset dir=".">
          <include name="TEST-*.xml" />
        </fileset>
        <report format="frames" todir="." />
      </junitreport>
    </target>
          
    <target name="cvs_code_checkout">
      <echo message="Checking out test code from CVS." />
      <cvs cvsRoot=":pserver:{cvs.username}@{cvs.hostname}:{cvs.dir}" 
           command="co {cvs.module}" 
           dest="{lib.path}" />         
      <!-- move files for easy access -->
      <move todir="{lib.path}"> 
        <fileset dir="{lib.path}\CVSTests"/>
      </move>
      <delete dir="{lib.path}\CVSTests"/>
      <!-- compile code -->
      <antcall target="compile_portal_tests"/>
    </target>
                  
    <target name="compile_portal_tests">
      <echo message="Compiling Portal test code." />
      <javac srcdir="{lib.path}"
             destdir="{lib.path}" 
             classpathref="system.classpath" />
    </target>
          
    <target name="help" description="Help"> 
      <echo message="JUnit application"/>
      <echo message=""/>
      <echo message="Place help instructions here. "/>
      <echo message=""/>
          <echo message="Targets:"/>
          <echo message="run_interactive_display_test"/>
      <echo message="run_commmandline_test"/>  
          <echo message="portal_test1_gui"/>
      <echo message="portal_test2_gui"/>
      <echo message="portal_test1_nongui"/>
      <echo message="portal_test2_nongui"/>
      <echo message="cvs_code_checkout"/>
      <echo message="compile_portal_tests"/>                
      <echo message=""/>
          <echo message=""/>
          </target>
          
  </project>


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.