I am trying to write unit tests for my build.  Part of the build that I am
testing would create a war, but I do not want a war to be created every time
I run the tests.  However, I do want to see that the target to build the war
was executed.

I am using jUnit to run the ant tasks and am trying to override the target
that will create a war, replacing it with a simple property task that I can
test against.  

The target I am testing looks like:

      <target name="determineDeployOrigin" >
                <if>
                        <equals arg1="${buildWar}" arg2="yes" />
                        <then>
                                <antcall target="createWar" />
                                <property name="deploy.origin" 
value="${deploy.dir}/${deploy.warname}"
/>
                        </then>
                        <else>
                                <property name="deploy.origin" 
value="${deploy.webcontent}" />
                        </else>
                </if>
        </target>

I am testing this logic in Junit, simply by asserting that "deploy.origin"
and "executed.properly" are what I expect after overriding createWar:

   @Test
   public void determineWarDeployOrigin(){

      Target createWar = new Target();
      createWar.setName("createWar");
      
      Property createWarTestProperty = new Property();
      createWarTestProperty.setProject(project);
      createWarTestProperty.setName("executed.properly");
      createWarTestProperty.setValue("true");
      
      createWar.addTask(createWarTestProperty);

      if(project.getTargets().get("createWar") == null){
         fail("createWar target not found in web-deploy.xml");
      }
      project.addOrReplaceTarget("createWar", createWar);

      project.setProperty("buildWar", "yes");
      assertNull(project.getProperty("deploy.origin"));
      project.executeTarget("setLocalDeployProperties");
      project.executeTarget("determineDeployOrigin");

      assertEquals("true",project.getProperty("executed.properly"));
     
assertEquals("C:/builds/local/dist/RCMii.war",project.getProperty("deploy.origin"))
   }

The problem is that "executed.properly" is always null, unless I explicitly
call execute() on createWarTestProperty task.  Is there something that I am
doing wrong in creating the createWar target?
Any suggestions are appreciated...
-- 
View this message in context: 
http://www.nabble.com/Overriding-a-Target-programmatically---task-not-being-executed-tp17151073p17151073.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to