You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Kamal <bh...@tt.com.au> on 2008/09/28 13:58:43 UTC

Mock webservices - possible use for Cocoon 3.0

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 
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.

It is a bit of a learning curve for me and I suspect nothing will come 
from this endeavour (I bet someone is going to tell me someone has 
already done this), but if anyone has any pointers about this project 
(including any suggestions on how to create a REST based web service in 
Java), I am glad to hear them. Also, some example code (including maven 
pom files) would be appreciated

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Mock webservices - possible use for Cocoon 3.0

Posted by Reinhard Pötz <re...@apache.org>.
Luca Morandini wrote:
> 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).

Same impression here.

The Cocoon 3 integration tests should give you some hints how the
testing can be done via HTTP. See the cocoon-sample and
cocoon-sample-webapp module.

>> 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.

Yes, or you can use the Cocoon 3 REST module which provides a JSR311
inspired controller implementation. Also see
http://cocoon.apache.org/3.0/features.html for a basic example.

Regarding your testing question above, those REST controller classes can
be unit tested easily.

-- 
Reinhard Pötz                           Managing Director, {Indoqa} GmbH
                         http://www.indoqa.com/en/people/reinhard.poetz/

Member of the Apache Software Foundation
Apache Cocoon Committer, PMC member                  reinhard@apache.org
________________________________________________________________________

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Mock webservices - possible use for Cocoon 3.0

Posted by Luca Morandini <lm...@ieee.org>.
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: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org