You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by um...@apache.org on 2002/03/04 02:07:41 UTC

cvs commit: jakarta-ant/proposal/sandbox/filterreaders/src/testcases/org/apache/tools/ant/taskdefs CopyTest.java LoadFileTest.java MoveTest.java

umagesh     02/03/03 17:07:41

  Added:       proposal/sandbox/filterreaders/src/etc/testcases/taskdefs
                        copy.filterset copy.xml loadfile.xml move.xml
               proposal/sandbox/filterreaders/src/etc/testcases/taskdefs/expected
                        copy.filterset.filtered
               proposal/sandbox/filterreaders/src/testcases/org/apache/tools/ant/taskdefs
                        CopyTest.java LoadFileTest.java MoveTest.java
  Log:
  Add a few preliminary testcases...
  
  Revision  Changes    Path
  1.1                  jakarta-ant/proposal/sandbox/filterreaders/src/etc/testcases/taskdefs/copy.filterset
  
  Index: copy.filterset
  ===================================================================
  This is the @TITLE@.
  
  
  1.1                  jakarta-ant/proposal/sandbox/filterreaders/src/etc/testcases/taskdefs/copy.xml
  
  Index: copy.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <project name="copy-test" basedir="." default="test1">
  
    <target name="test1">
      <copy file="copy.xml" tofile="copytest1.tmp" />
    </target>
   
    <target name="test2">
      <copy file="copy.xml" todir="copytest1dir" overwrite="true"/>
    </target>
  
    <target name="test3">
      <!-- create an empty file -->
      <touch file="copytest3.tmp"/>
      <!--wait -->
      <sleep seconds="4"/>
      <!-- copy a different file to two places --> 
      <copy file="copy.xml" tofile="copytest3a.tmp" overwrite="true"/>
      <copy file="copy.xml" tofile="copytest3b.tmp" overwrite="true"/>
      <!--wait -->
      <sleep seconds="4"/>
      <!-- copy an old file onto a newer file (should not work) -->
      <copy file="copytest3.tmp" tofile="copytest3b.tmp" />
      <!-- copy an older file onto a new one, should succeed -->
      <copy file="copytest3.tmp" tofile="copytest3c.tmp"
        overwrite="true"
        preservelastmodified="true" />
      <!-- copy a newer file onto an older one (should work) -->
      <copy file="copytest3a.tmp" tofile="copytest3.tmp" 
        preservelastmodified="true" />
      <!-- expected state :
        3a.tmp==3.tmp==copy.xml
        timeof(3a.tmp)==timeof(3.tmp)==now()-4
        sizeof(3c)==0
        timeof(3c.tmp)<timeof(3a.tmp);
        3b.tmp==copy.xml
      -->
    </target>
    
    <target name="test_single_file_fileset">
      <copy tofile="copytest_single_file_fileset.tmp">
        <fileset dir="." includes="copy.xml"/>
      </copy>
    </target>
    
    <target name="testFilterSet">
      <copy file="copy.filterset" tofile="copy.filterset.tmp">
        <filterset>
          <filter token="TITLE" value="Apache Ant Project"/>
        </filterset>
      </copy>
    </target>
  
    <target name="testFilterChain">
      <copy file="copy.filterset" tofile="copy.filterchain.tmp">
        <filterchain>
          <replacetokens>
            <token key="TITLE" value="Apache Ant Project"/>
          </replacetokens>
        </filterchain>
      </copy>
    </target>
  
    <target name="cleanup"> 
      <delete file="copytest1.tmp"/>
      <delete file="copytest3.tmp"/>
      <delete file="copytest3a.tmp"/>
      <delete file="copytest3b.tmp"/>
      <delete file="copytest3c.tmp"/>
      <delete file="copytest_single_file_fileset.tmp"/>
      <delete file="copy.filterset.tmp"/>
      <delete file="copy.filterchain.tmp"/>
      <delete dir="copytest1dir"/>
    </target>
  
  
  </project>
  
  
  
  1.1                  jakarta-ant/proposal/sandbox/filterreaders/src/etc/testcases/taskdefs/loadfile.xml
  
  Index: loadfile.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  <project name="loadfile-test" basedir="." default="testLoadAFile">
  
  
    <target name="init">
    </target>
  
    <target name="testNoSourcefileDefined" depends="init">
      <loadfile property="foo" />
    </target>
  
    <target name="testNoPropertyDefined"
      depends="init">
      <loadfile srcFile="somefile" />
    </target>
  
  
    <target name="testNoSourcefilefound"
      depends="init">
      <loadfile property="missing" srcFile="somefile" />
    </target>
  
    <target name="testFailOnError"
      depends="init">
      <loadfile
        property="testFailOnError"
        srcFile="somefile"
        failonerror="false"/>
    </target>
  
    <target name="testLoadAFile"
      depends="init">
      <echo
        message="What's it going to be then, eh?"
        file="loadfile1.tmp"
        />
      <loadfile property="testLoadAFile" srcFile="loadfile1.tmp" />
      <echo>${testLoadAFile}</echo>
    </target>
  
    <target name="testLoadAFileEnc"
      depends="init">
      <loadfile property="testLoadAFileEnc"
        srcFile="loadfile.xml"
        encoding="ISO-8859-1"/>
    </target>
  
    <target name="testEvalProps"
      depends="init">
      <property name="weather" value="rain" />
      <echo
        message="All these moments will be lost in time, like teardrops in the ${weather}"
        file="loadfile1.tmp"
        />
      <loadfile property="testEvalProps"
          srcFile="loadfile1.tmp">
          <filterchain>
            <expandproperties/>
          </filterchain>
      </loadfile>
      <echo>${testLoadAFile}</echo>
    </target>
  
  
    <target name="testOneLine"
      depends="init">
      <echo
        message="1,&#10;2,&#13;3,&#13;&#10;4"
        file="loadfile1.tmp"
        />
      <loadfile property="testOneLine"
          srcFile="loadfile1.tmp">
        <filterchain>
          <striplinebreaks/>
        </filterchain>
      </loadfile>
      <echo>${testLoadAFile}</echo>
    </target>
  
  
    <target name="cleanup">
      <delete file="loadfile1.tmp"/>
    </target>
  
    </project>
  
  
  
  1.1                  jakarta-ant/proposal/sandbox/filterreaders/src/etc/testcases/taskdefs/move.xml
  
  Index: move.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <project name="move-test" basedir="." default="testFilterSet">
  
    <target name="testFilterSet">
      <copy file="copy.filterset" tofile="move.filterset"/>
      <move file="move.filterset" tofile="move.filterset.tmp">
        <filterset>
          <filter token="TITLE" value="Apache Ant Project"/>
        </filterset>
      </move>
    </target>
  
    <target name="testFilterChain">
      <copy file="copy.filterset" tofile="move.filterchain"/>
      <move file="move.filterchain" tofile="move.filterchain.tmp">
        <filterchain>
          <replacetokens>
            <token key="TITLE" value="Apache Ant Project"/>
          </replacetokens>
        </filterchain>
      </move>
    </target>
  
    <target name="cleanup"> 
      <delete file="move.filterset.tmp"/>
      <delete file="move.filterchain.tmp"/>
    </target>
  
  </project>
  
  
  
  1.1                  jakarta-ant/proposal/sandbox/filterreaders/src/etc/testcases/taskdefs/expected/copy.filterset.filtered
  
  Index: copy.filterset.filtered
  ===================================================================
  This is the Apache Ant Project.
  
  
  
  1.1                  jakarta-ant/proposal/sandbox/filterreaders/src/testcases/org/apache/tools/ant/taskdefs/CopyTest.java
  
  Index: CopyTest.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.tools.ant.taskdefs;
  
  import org.apache.tools.ant.BuildFileTest;
  import org.apache.tools.ant.Project;
  import org.apache.tools.ant.util.FileUtils;
  import java.io.File;
  import java.io.IOException;
  
  /**
   * Tests FileSet using the Copy task.
   *
   * @author David Rees <da...@ubiqsoft.com>
   */
  public class CopyTest extends BuildFileTest {
  
      public CopyTest(String name) {
          super(name);
      }
  
      public void setUp() {
          configureProject("src/etc/testcases/taskdefs/copy.xml");
      }
  
      public void test1() {
          executeTarget("test1");
          File f = new File(getProjectDir(), "copytest1.tmp");
          if ( !f.exists()) {
              fail("Copy failed");
          }
      }
  
      public void tearDown() {
          executeTarget("cleanup");
      }
  
      public void test2() {
          executeTarget("test2");
          File f = new File(getProjectDir(), "copytest1dir/copy.xml");
          if ( !f.exists()) {
              fail("Copy failed");
          }
      }
  
      public void test3() {
          executeTarget("test3");
          File file3  = new File(getProjectDir(), "copytest3.tmp");
          assertTrue(file3.exists());
          File file3a = new File(getProjectDir(), "copytest3a.tmp");
          assertTrue(file3a.exists());
          File file3b = new File(getProjectDir(), "copytest3b.tmp");
          assertTrue(file3b.exists());
          File file3c = new File(getProjectDir(), "copytest3c.tmp");
          assertTrue(file3c.exists());
  
          //file length checks rely on touch generating a zero byte file
          if(file3.length()==0) {
              fail("could not overwrite an existing, older file");
          }
          if(file3c.length()!=0) {
              fail("could not force overwrite an existing, newer file");
          }
          if(file3b.length()==0) {
              fail("unexpectedly overwrote an existing, newer file");
          }
  
          //file time checks for java1.2+
          if (Project.getJavaVersion() != Project.JAVA_1_1) {
              assertTrue(file3a.lastModified()==file3.lastModified());
              assertTrue(file3c.lastModified()<file3a.lastModified());
          }
  
      }
  
      public void testFilterSet() throws IOException {
          executeTarget("testFilterSet");
          FileUtils fileUtils = FileUtils.newFileUtils();
          File tmp  = new File(getProjectDir(), "copy.filterset.tmp");
          File check  = new File(getProjectDir(), "expected/copy.filterset.filtered");
          assertTrue(tmp.exists());
          assertTrue(fileUtils.contentEquals(tmp, check));
      }
  
      public void testFilterChain() throws IOException {
          executeTarget("testFilterChain");
          FileUtils fileUtils = FileUtils.newFileUtils();
          File tmp  = new File(getProjectDir(), "copy.filterchain.tmp");
          File check  = new File(getProjectDir(), "expected/copy.filterset.filtered");
          assertTrue(tmp.exists());
          assertTrue(fileUtils.contentEquals(tmp, check));
      }
  
      public void testSingleFileFileset() {
          executeTarget("test_single_file_fileset");
          File file  = new File(getProjectDir(),
                                          "copytest_single_file_fileset.tmp");
          assertTrue(file.exists());
      }
  }
  
  
  
  1.1                  jakarta-ant/proposal/sandbox/filterreaders/src/testcases/org/apache/tools/ant/taskdefs/LoadFileTest.java
  
  Index: LoadFileTest.java
  ===================================================================
  /*
   *  The Apache Software License, Version 1.1
   *
   *  Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
   *  reserved.
   *
   *  Redistribution and use in source and binary forms, with or without
   *  modification, are permitted provided that the following conditions
   *  are met:
   *
   *  1. Redistributions of source code must retain the above copyright
   *  notice, this list of conditions and the following disclaimer.
   *
   *  2. Redistributions in binary form must reproduce the above copyright
   *  notice, this list of conditions and the following disclaimer in
   *  the documentation and/or other materials provided with the
   *  distribution.
   *
   *  3. The end-user documentation included with the redistribution, if
   *  any, must include the following acknowlegement:
   *  "This product includes software developed by the
   *  Apache Software Foundation (http://www.apache.org/)."
   *  Alternately, this acknowlegement may appear in the software itself,
   *  if and wherever such third-party acknowlegements normally appear.
   *
   *  4. The names "The Jakarta Project", "Ant", and "Apache Software
   *  Foundation" must not be used to endorse or promote products derived
   *  from this software without prior written permission. For written
   *  permission, please contact apache@apache.org.
   *
   *  5. Products derived from this software may not be called "Apache"
   *  nor may "Apache" appear in their names without prior written
   *  permission of the Apache Group.
   *
   *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   *  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   *  DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   *  ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   *  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   *  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   *  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   *  SUCH DAMAGE.
   *  ====================================================================
   *
   *  This software consists of voluntary contributions made by many
   *  individuals on behalf of the Apache Software Foundation.  For more
   *  information on the Apache Software Foundation, please see
   *  <http://www.apache.org/>.
   */
  package org.apache.tools.ant.taskdefs;
  
  import org.apache.tools.ant.BuildFileTest;
  import org.apache.tools.ant.Project;
  import org.apache.tools.ant.BuildException;
  import java.io.File;
  
  /**
   * Test the load file task
   *
   * @author Steve Loughran
   * @created 10 December 2001
   */
  public class LoadFileTest extends BuildFileTest {
  
      /**
       * Constructor for the LoadFileTest object
       *
       * @param name Description of Parameter
       */
      public LoadFileTest(String name) {
          super(name);
      }
  
  
      /**
       * The JUnit setup method
       */
      public void setUp() {
          configureProject("src/etc/testcases/taskdefs/loadfile.xml");
      }
  
  
      /**
       * The teardown method for JUnit
       */
      public void tearDown() {
          executeTarget("cleanup");
      }
  
  
      /**
       * A unit test for JUnit
       */
      public void testNoSourcefileDefined() {
          expectBuildException("testNoSourcefileDefined",
                  "source file not defined");
      }
  
  
      /**
       * A unit test for JUnit
       */
      public void testNoPropertyDefined() {
          expectBuildException("testNoPropertyDefined",
                  "output property not defined");
      }
  
  
      /**
       * A unit test for JUnit
       */
      public void testNoSourcefilefound() {
          expectBuildExceptionContaining("testNoSourcefilefound",
                  "File not found",
                  "Unable to load file");
      }
  
      /**
       * A unit test for JUnit
       */
      public void testFailOnError()
              throws BuildException {
          expectPropertyUnset("testFailOnError","testFailOnError");
      }
  
  
      /**
       * A unit test for JUnit
       */
      public void testLoadAFile()
              throws BuildException {
          executeTarget("testLoadAFile");
          if(project.getProperty("testLoadAFile").indexOf("eh?")<0) {
              fail("property is not all in the file");
          }
      }
  
  
      /**
       * A unit test for JUnit
       */
      public void testLoadAFileEnc()
              throws BuildException {
          executeTarget("testLoadAFileEnc");
          if(project.getProperty("testLoadAFileEnc")==null) {
              fail("file load failed");
          }
      }
  
          /**
       * A unit test for JUnit
       */
      public void testEvalProps()
              throws BuildException {
          executeTarget("testEvalProps");
          if(project.getProperty("testEvalProps").indexOf("rain")<0) {
              fail("property eval broken");
          }
      }
  
          /**
       * A unit test for JUnit
       */
      public void testOneLine()
              throws BuildException {
              expectPropertySet("testOneLine","testOneLine","1,2,3,4");
  
      }
  }
  
  
  
  
  
  1.1                  jakarta-ant/proposal/sandbox/filterreaders/src/testcases/org/apache/tools/ant/taskdefs/MoveTest.java
  
  Index: MoveTest.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Ant", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.tools.ant.taskdefs;
  
  import org.apache.tools.ant.BuildFileTest;
  import org.apache.tools.ant.Project;
  import org.apache.tools.ant.util.FileUtils;
  import java.io.File;
  import java.io.IOException;
  
  /**
   * Tests the Move task.
   *
   * @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
   */
  public class MoveTest extends BuildFileTest {
  
      public MoveTest(String name) {
          super(name);
      }
  
      public void setUp() {
          configureProject("src/etc/testcases/taskdefs/move.xml");
      }
  
      public void tearDown() {
          executeTarget("cleanup");
      }
  
      public void testFilterSet() throws IOException {
          executeTarget("testFilterSet");
          FileUtils fileUtils = FileUtils.newFileUtils();
          File tmp  = new File(getProjectDir(), "move.filterset.tmp");
          File check  = new File(getProjectDir(), "expected/copy.filterset.filtered");
          assertTrue(tmp.exists());
          assertTrue(fileUtils.contentEquals(tmp, check));
      }
  
      public void testSingleFileFileset() {
          executeTarget("test_single_file_fileset");
          File file  = new File(getProjectDir(),
                                          "copytest_single_file_fileset.tmp");
          assertTrue(file.exists());
      }
  
      public void testFilterChain() throws IOException {
          executeTarget("testFilterChain");
          FileUtils fileUtils = FileUtils.newFileUtils();
          File tmp  = new File(getProjectDir(), "move.filterchain.tmp");
          File check  = new File(getProjectDir(), "expected/copy.filterset.filtered");
          assertTrue(tmp.exists());
          assertTrue(fileUtils.contentEquals(tmp, check));
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>