Kamal wrote:
Hi,
I have been thinking about testing REST based web services of late. It occurred to me that these web services are very difficult to test

Really ? My impression is the opposite: a REST-style web service should be usable by humans and machines alike, which makes them easier to test (easier then the RPC-style web services, anyway).


against. I was thinking that maybe there is some funky way of mocking a web service, using XPath and regexes to match on the requst, and use a templating language to generate the response (based on variables generated from the XPath and regexes). I was thinking maybe Cocoon 3.0 might help me here.

I think you could do the same with 2.1 or 2.2 as well. I did some experiments myself and come out with sitemap fragments
like these:

       <!--
Intecepts all URIs starting with "api/" and calls the corresponding
         Flowscript function based on the HTTP method. Actually, the
function
         name is a concatenation of the last part of the URI and "Set"
or "Get"
         depending on the HTTP method.
       -->
       <map:match pattern="api/*">
         <map:select type="request-method">
           <map:when test="GET">
             <map:call function="{1}Get"/>
           </map:when>
           <map:when test="PUT">
             <map:call function="{1}Set"/>
           </map:when>
         </map:select>
       </map:match>

       <!--
         Emits as JSON the obj collection object received from Flowscript.
       -->
       <map:match pattern="apipages/send-json">
<map:read src="module:flow-attr:json" mime-type="text/javascript"/>
       </map:match>

       <!--
         Emits as XML the obj collection object received from
Flowscript. URI
         format is send-{set|map}.xml
       -->
       <map:match pattern="apipages/send-*.xml">
         <map:generate type="jx" src="pages/{1}.jx">
           <map:parameter name="obj" value="{flow-attr:obj}"/>
         </map:generate>
         <map:serialize type="xml"/>
       </map:match>

Regards,

--------------------
   Luca Morandini
www.lucamorandini.it
--------------------


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

Reply via email to