ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/vfile/test/src/subdir1 someFile.html
Date Sun, 14 Apr 2002 10:48:04 GMT
donaldp     02/04/14 03:48:03

  Added:       antlib/src/test/org/apache/antlib/core/test IfTestCase.java
                        PropertyTestCase.java PropertyTestType.java if.ant
                        property.ant
               antlib/src/test/org/apache/antlib/vfile/test
                        CopyFilesTaskTestCase.java copy.ant
               antlib/src/test/org/apache/antlib/vfile/test/src
                        emptyFile.txt file1.txt
               antlib/src/test/org/apache/antlib/vfile/test/src/subdir1
                        someFile.html
  Log:
  Add in the unit tests for tasks ... or at least those we have.
  
  Note that src/test/org/apache/antlib/core/test/PropertyTestCase.java has one of its tests
disabled because it required access to the container.
  
  Revision  Changes    Path
  1.1                  jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/core/test/IfTestCase.java
  
  Index: IfTestCase.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.antlib.core.test;
  
  import java.io.File;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.myrmidon.AbstractProjectTest;
  import org.apache.myrmidon.LogMessageTracker;
  
  /**
   * Test cases for the <if> task.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/04/14 10:48:03 $
   */
  public class IfTestCase
      extends AbstractProjectTest
  {
      private final static Resources REZ = getResourcesForTested( IfTestCase.class );
  
      public IfTestCase( String name )
      {
          super( name );
      }
  
      /**
       * Test checking whether a property is set and not 'false'.
       */
      public void testConditions()
          throws Exception
      {
          final File projectFile = getTestResource( "if.ant" );
  
          // Test when property is set to 'true'
          LogMessageTracker listener = new LogMessageTracker();
          listener.addExpectedMessage( "true-prop", "test-prop is set" );
          executeTarget( projectFile, "true-prop", listener );
  
          // Test when property is set to a value other than 'true' or 'false'
          executeTargetExpectError( projectFile, "set-prop", new String[ 0 ] );
  
          // Test when property is set to 'false'
          listener = new LogMessageTracker();
          listener.addExpectedMessage( "false-prop", "test-prop is not set" );
          executeTarget( projectFile, "false-prop", listener );
  
          // Test when property is not set
          listener = new LogMessageTracker();
          listener.addExpectedMessage( "not-set-prop", "test-prop is not set" );
          executeTarget( projectFile, "not-set-prop", listener );
      }
  
      /**
       * Test nested <condition> elements.
       */
      public void testNestedConditions()
          throws Exception
      {
          final File projectFile = getTestResource( "if.ant" );
  
          // Test when property is set to 'true'
          LogMessageTracker listener = new LogMessageTracker();
          listener.addExpectedMessage( "nested-conditions", "prop-true is set" );
          listener.addExpectedMessage( "nested-conditions", "prop-false is set" );
          listener.addExpectedMessage( "nested-conditions", "prop-true is true" );
          listener.addExpectedMessage( "nested-conditions",
                                       "prop-true is true and prop-false is not true" );
          executeTarget( projectFile, "nested-conditions", listener );
      }
  
      /**
       * Tests that the <if> task can handle multiple nested tasks.
       */
      public void testMultipleTasks() throws Exception
      {
          final File projectFile = getTestResource( "if.ant" );
  
          // Test when property is not set
          LogMessageTracker listener = new LogMessageTracker();
          listener.addExpectedMessage( "multiple-nested-tasks", "task 1" );
          listener.addExpectedMessage( "multiple-nested-tasks", "task 2" );
          listener.addExpectedMessage( "multiple-nested-tasks", "task 3" );
          listener.addExpectedMessage( "multiple-nested-tasks", "task 4" );
          executeTarget( projectFile, "multiple-nested-tasks", listener );
      }
  
      /**
       * Tests validation.
       */
      public void testValidation() throws Exception
      {
          final File projectFile = getTestResource( "if.ant" );
  
          // Check for missing condition
          String[] messages = {
              null,
              REZ.getString( "if.no-condition.error" )
          };
          executeTargetExpectError( projectFile, "no-condition", messages );
  
          // Check for too many conditions
          messages = new String[]
          {
              null,
              null,
              REZ.getString( "if.ifelse-duplicate.error" )
          };
          // 2 condition attributes.
          executeTargetExpectError( projectFile, "too-many-conditions", messages );
  
          // attribute condition + nested condition
          executeTargetExpectError( projectFile, "attribute-plus-nested-condition",
                                    messages );
  
          // 2 nested conditions
          executeTargetExpectError( projectFile, "2-nested-conditions", messages );
      }
  
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/core/test/PropertyTestCase.java
  
  Index: PropertyTestCase.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.antlib.core.test;
  
  import java.io.File;
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.myrmidon.AbstractProjectTest;
  import org.apache.myrmidon.LogMessageTracker;
  //import org.apache.myrmidon.components.workspace.DefaultTaskContext;
  //import org.apache.myrmidon.components.store.DefaultPropertyStore;
  
  /**
   * Test cases for <property> task.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/04/14 10:48:03 $
   */
  public class PropertyTestCase
      extends AbstractProjectTest
  {
      private final static Resources REZ = getResourcesForTested( PropertyTestCase.class );
  
      public PropertyTestCase( final String name )
      {
          super( name );
      }
  
      /**
       * Tests setting a property, using an attribute, text content, and
       * nested element.
       */
      public void testSetProperty()
          throws Exception
      {
          final File projectFile = getTestResource( "property.ant" );
  
          // Set by attribute
          LogMessageTracker tracker = new LogMessageTracker();
          tracker.addExpectedMessage( "set-attr", "test-prop = [some value]" );
          executeTarget( projectFile, "set-attr", tracker );
  
          // Set by text content
          tracker = new LogMessageTracker();
          tracker.addExpectedMessage( "set-content", "test-prop2 = [some value]" );
          executeTarget( projectFile, "set-content", tracker );
  
          // Set by nested element
          tracker = new LogMessageTracker();
          tracker.addExpectedMessage( "set-element", "test-prop3 = [value=[some value]]" );
          executeTarget( projectFile, "set-element", tracker );
      }
  
      /**
       * Tests the validation performed by the propery task.
       */
      public void testValidation()
          throws Exception
      {
          final File projectFile = getTestResource( "property.ant" );
  
          // Missing name
          String[] messages =
              {
                  null,
                  REZ.getString( "property.no-name.error" )
              };
          executeTargetExpectError( projectFile, "missing-name", messages );
  
          // Missing value
          messages = new String[]
          {
              null,
              REZ.getString( "property.no-value.error" )
          };
          executeTargetExpectError( projectFile, "missing-value", messages );
  
          // Too many values
          messages = new String[]
          {
              null,
              null,
              REZ.getString( "property.multi-set.error" )
          };
          executeTargetExpectError( projectFile, "too-many-values1", messages );
          executeTargetExpectError( projectFile, "too-many-values2", messages );
          executeTargetExpectError( projectFile, "too-many-values3", messages );
      }
  
      /**
       * Tests basic validation of property names.
       *
       * @todo Rework this test into container hierarchy as
       *  DefaultPropertyStore classloader is not visible to antlib
       */
      public void fixme_testNameValidation() throws Exception
      {
          final File projectFile = getTestResource( "property.ant" );
  
          final Resources rez = null;
  	//ResourceManager.getPackageResources( DefaultPropertyStore.class );
  
          // Invalid names
          String[] messages = new String[]
          {
              null,
              rez.getString( "bad-property-name.error", "badname!" )
          };
          executeTargetExpectError( projectFile, "bad-prop-name1", messages );
  
          messages = new String[]
          {
              null,
              rez.getString( "bad-property-name.error", "bad name" )
          };
          executeTargetExpectError( projectFile, "bad-prop-name2", messages );
  
          messages = new String[]
          {
              null,
              rez.getString( "bad-property-name.error", "" )
          };
          executeTargetExpectError( projectFile, "bad-prop-name3", messages );
      }
  
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/core/test/PropertyTestType.java
  
  Index: PropertyTestType.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.antlib.core.test;
  
  import org.apache.myrmidon.framework.DataType;
  
  /**
   * A test data-type used by the property tests.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/04/14 10:48:03 $
   *
   * @ant.data-type name="property-test-type"
   */
  public class PropertyTestType
      implements DataType
  {
      private String m_value;
  
      public void setValue( final String value )
      {
          m_value = value;
      }
  
      /**
       * Used in the test project file to check the value has been set.
       */
      public String toString()
      {
          return "value=[" + m_value + "]";
      }
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/core/test/if.ant
  
  Index: if.ant
  ===================================================================
  <project version="2.0">
      <target name="true-prop">
          <property name="test-prop" value="true"/>
          <if test="test-prop">
              <log>test-prop is set</log>
          </if>
          <if not-test="test-prop">
              <log>test-prop is not set</log>
          </if>
      </target>
  
      <target name="set-prop">
          <property name="test-prop" value="some value"/>
          <if test="test-prop">
              <log>test-prop is set</log>
          </if>
          <if not-test="test-prop">
              <log>test-prop is not set</log>
          </if>
      </target>
  
      <target name="not-set-prop">
          <if test="test-prop">
              <log>test-prop is set</log>
          </if>
          <if not-test="test-prop">
              <log>test-prop is not set</log>
          </if>
      </target>
  
      <target name="false-prop">
          <property name="test-prop" value="false"/>
          <if test="test-prop">
              <log>test-prop is set</log>
          </if>
          <if not-test="test-prop">
              <log>test-prop is not set</log>
          </if>
      </target>
  
      <target name="nested-conditions">
          <property name="prop-true" value="true"/>
          <property name="prop-false" value="false"/>
  
          <if>
              <condition>
                  <is-set property="prop-true"/>
              </condition>
              <log message="prop-true is set"/>
          </if>
  
          <if>
              <condition>
                  <is-set property="prop-false"/>
              </condition>
              <log message="prop-false is set"/>
          </if>
  
          <if>
              <condition>
                  <is-set property="prop-unset"/>
              </condition>
              <log message="prop-unset is set (shouldn't be here)"/>
          </if>
  
          <if>
              <condition>
                  <is-true property="prop-true"/>
              </condition>
              <log message="prop-true is true"/>
          </if>
  
          <if>
              <condition>
                  <is-true property="prop-false"/>
              </condition>
              <log message="prop-false is true (shouldn't be here)"/>
          </if>
  
          <!-- Compound condition -->
          <if>
              <condition>
                  <is-true property="prop-true"/>
                  <not>
                      <is-true property="prop-false"/>
                  </not>
              </condition>
              <log message="prop-true is true and prop-false is not true"/>
          </if>
      </target>
  
      <target name="multiple-nested-tasks">
          <property name="test-prop" value="true"/>
          <if test="test-prop">
              <log>task 1</log>
              <log>task 2</log>
              <log>task 3</log>
              <log>task 4</log>
          </if>
      </target>
  
      <target name="no-condition">
          <if>
              <log>no go</log>
          </if>
      </target>
  
      <target name="too-many-conditions">
          <if test="test-prop" not-test="test-prop">
              <log>no go</log>
          </if>
      </target>
  
      <target name="attribute-plus-nested-condition">
          <property name="test-prop" value="true"/>
          <if test="test-prop">
              <condition>
                  <is-set property="test-prop"/>
              </condition>
              <log>Double trouble.</log>
          </if>
      </target>
  
      <target name="2-nested-conditions">
          <property name="test-prop" value="true"/>
          <if>
              <condition>
                  <is-set property="test-prop"/>
              </condition>
              <condition>
                  <is-true property="test-prop"/>
              </condition>
              <log>2 conditions not permitted.</log>
          </if>
      </target>
  
  </project>
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/core/test/property.ant
  
  Index: property.ant
  ===================================================================
  <project version="2.0">
  
      <!-- Test setting property via attribute -->
      <target name="set-attr">
          <property name="test-prop" value="some value"/>
          <log>test-prop = [${test-prop}]</log>
      </target>
  
      <!-- Test setting property via content -->
      <target name="set-content">
          <property name="test-prop2">some value</property>
          <log>test-prop2 = [${test-prop2}]</log>
      </target>
  
      <!-- Test setting property via a nested element -->
      <target name="set-element">
          <property name="test-prop3">
              <property-test-type value="some value"/>
          </property>
          <log>test-prop3 = [${test-prop3}]</log>
      </target>
  
      <!-- Test missing property name -->
      <target name="missing-name">
          <property value="some value"/>
      </target>
  
      <!-- Test missing property value -->
      <target name="missing-value">
          <property name="some-prop"/>
      </target>
  
      <!-- Test setting the value more than once -->
      <target name="too-many-values1">
          <property name="some-prop" value="some value">another value</property>
      </target>
  
      <!-- Test setting the value more than once -->
      <target name="too-many-values2">
          <property name="some-prop" value="some value">
              <property-test-type value="value 2"/>
          </property>
      </target>
  
      <!-- Test setting the value more than once -->
      <target name="too-many-values3">
          <property name="some-prop">
              <property-test-type value="value 1"/>
              <property-test-type value="value 2"/>
              <property-test-type value="value 3"/>
          </property>
      </target>
  
      <!-- Test properties with invalid names -->
      <target name="bad-prop-name1">
          <property name="badname!" value="value"/>
      </target>
      <target name="bad-prop-name2">
          <property name="bad name" value="value"/>
      </target>
      <target name="bad-prop-name3">
          <property name="" value="value"/>
      </target>
  
  </project>
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/vfile/test/CopyFilesTaskTestCase.java
  
  Index: CopyFilesTaskTestCase.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.antlib.vfile.test;
  
  import java.io.File;
  import org.apache.myrmidon.AbstractProjectTest;
  
  /**
   * Test cases for the <v-copy> task.
   *
   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
   * @version $Revision: 1.1 $ $Date: 2002/04/14 10:48:03 $
   */
  public class CopyFilesTaskTestCase
      extends AbstractProjectTest
  {
      public CopyFilesTaskTestCase( String name )
      {
          super( name );
      }
  
      /**
       * A simple smoke test.
       */
      public void testCopy() throws Exception
      {
          final File projectFile = getTestResource( "copy.ant" );
          executeTarget( projectFile, "copy" );
      }
  }
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/vfile/test/copy.ant
  
  Index: copy.ant
  ===================================================================
  <project version="2.0">
      <target name="copy">
          <v-fileset id="src-files" dir="src"/>
          <v-copy destdir="dest">
              <v-fileset-ref id="src-files"/>
          </v-copy>
      </target>
  </project>
  
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/vfile/test/src/emptyFile.txt
  
  	<<Binary file>>
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/vfile/test/src/file1.txt
  
  Index: file1.txt
  ===================================================================
  A test file.
  
  
  1.1                  jakarta-ant-myrmidon/antlib/src/test/org/apache/antlib/vfile/test/src/subdir1/someFile.html
  
  Index: someFile.html
  ===================================================================
  <html>
  <body>
  <p>Yo!</p>
  </body>
  </html>
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message