Bug 53383 - assertResourceExists fails for URL
assertResourceExists fails for URL
Status: RESOLVED FIXED
Product: Ant
Classification: Unclassified
Component: AntUnit
1.2
PC Windows XP
: P2 minor (vote)
: 1.3
Assigned To: Ant Notifications List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2012-06-08 07:47 UTC by pascal.schumacher
Modified: 2014-05-01 09:58 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description pascal.schumacher 2012-06-08 07:47:04 UTC
Using assertResourceExists does not work for URLs:

"<au:assertResourceExists resource="http://ant.apache.org/index.html"/>

BUILD FAILED
D:\development\eclipse-projects\AntUnitTest\build.xml:6: Expected 
resource 'http://ant.apache.org/index.html' to exist"

According to the AntUnit 1.2 documentation;

"assertResourceExists
Asserts that a given resource exists. This is a generalization of 
assertFileExists and allows to test for arbitrary resources."

this should be possible.
Comment 1 Stefan Bodewig 2012-06-17 06:30:04 UTC
This workaround should work

      <au:assertTrue>
      <cond:resourceexists xmlns:cond="antlib:org.apache.tools.ant.types.conditions">
        <url url="http://ant.apache.org/index.html"/>
      </cond:resourceexists>
    </au:assertTrue>
Comment 2 Stefan Bodewig 2012-06-17 07:03:05 UTC
This is really ugly, I should have written assertResourceExists using a nested element rather than an attibute.

Ant's Resource-valued attributes only work in conjunction with property expanders that return Resources - they don't work if you use a plain String.  So this here works

    <url url="http://ant.apache.org/index.html" id="antsite"/>
    <au:assertTrue>
      <au:resourceExists resource="${ant.refid:antsite}"/>
    </au:assertTrue>

but this doesn't

    <au:assertTrue>
      <au:resourceExists resource="http://ant.apache.org/index.html"/>
    </au:assertTrue>

To make things worse the nested macrodef construction of assertResourceExists will evaluate the property to a string before it reaches resourceExists so even 

    <url url="http://ant.apache.org/index.html" id="antsite"/>
    <au:assertResourceExists resource="${ant.refid:antsite}"/>
 
will not work.

See my previous comment for a workaround, assertResourceExists as it stands will not work for anything other than a file at all.
Comment 3 Stefan Bodewig 2012-06-17 07:08:06 UTC
this should work for older versions of Ant that don't have the built-in resourcexists condition as well:

    <au:assertTrue>
      <au:resourceExists>
        <url url="http://ant.apache.org/index.html"/>
      </au:resourceExists>
    </au:assertTrue>
Comment 4 Stefan Bodewig 2014-05-01 09:58:35 UTC
I added a bunch of new assertions in AntUnit 1.3 with svn revision 1591586 that really work for non-file resources.