Bug 53383 - assertResourceExists fails for URL
Summary: assertResourceExists fails for URL
Alias: None
Product: Ant
Classification: Unclassified
Component: AntUnit (show other bugs)
Version: 1.2
Hardware: PC Windows XP
: P2 minor (vote)
Target Milestone: 1.3
Assignee: Ant Notifications List
Depends on:
Reported: 2012-06-08 07:47 UTC by pascal.schumacher
Modified: 2014-05-01 09:58 UTC (History)
0 users


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"/>

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;

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

      <cond:resourceexists xmlns:cond="antlib:org.apache.tools.ant.types.conditions">
        <url url="http://ant.apache.org/index.html"/>
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:resourceExists resource="${ant.refid:antsite}"/>

but this doesn't

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

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:

        <url url="http://ant.apache.org/index.html"/>
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.