Loading ...
Sorry, an error occurred while loading the content.
 

Re: RestFixture to Test JSON

Expand Messages
  • fab_can
    with the RestFixture v2 you can set expectations using JavaScript expressions (an expectation is a block that evaluated returns a boolean); the var jsonbody is
    Message 1 of 5 , May 1, 2011
      with the RestFixture v2 you can set expectations using JavaScript expressions (an expectation is a block that evaluated returns a boolean); the var jsonbody is in scope containing the last response body (in JSON).
      if - for example - the last response has a body with

      { "resource" : { "name" : "test post", "data" : "some data" } }

      you can write expectations like

      jsonbody.resource.name=="test post" && jsonbody.resource.data=="some data"

      you can also do more complex code blocks. for details check this out
      http://rest-fixture.googlecode.com/files/RestFixture-2.0.beta.1.html

      Currently the service must return a content-type: application/json for the RestFixture to use the JS interpreter. I am working on a mechanism to override this default behaviour.

      Fabrizio





      --- In fitnesse@yahoogroups.com, "rhunter_71" <roywhunter@...> wrote:
      >
      > thanks,
      > I look forward to the updates. Right now, I am still trying to figure out how to write the body expectations. I am familiar with Fitnesse, but trying to test the JSON Interfaces is new to me.
      > Roy
      >
      > --- In fitnesse@yahoogroups.com, "fab_can" <fab_can@> wrote:
      > >
      > > Hi, I have delayed the release to support json dot notation via rhino. Have a look at the docs.
      > > When the rel is finalised (next week) I will post here.
      > >
      > > As for your table, shouldn't the uri path start with a / ?
      > > also, how do you intend to write the body expectations? The one you have doesn't look like an xpath
      > >
      > > BTW you should be seeing what goes in the wire in the fitnesse error logs for the page after execution. It will confirm what the server responds.
      > >
      > > Fabrizio
      > >
      > >
      > > --- In fitnesse@yahoogroups.com, "rhunter_71" <roywhunter@> wrote:
      > > >
      > > > I downloaded the latest version of the Restfixture from Github yesterday and was trying to get it working to test some JSON interfaces. I thought that JSON was going to be supported in this release, but I am seeing posts that indicates that it may not be. Can someone tell me if this is supported.
      > > >
      > > > currently when I attempt to run my tests, no-body is returned to me.
      > > >
      > > > This is what my current test looks like:
      > > >
      > > > !|smartrics.rest.fitnesse.fixture.RestFixture|http://localhost:8080/xyxservice|
      > > > |GET|\heartbeat?elementid=40:FC:89:31:DA:98&sourceid=tablet123|200|content-length: [\d]|COMPANY:xyz / SITE:Mine/ DEVICE:tablet123 / USER:Fred / VER:1.0|
      > > >
      > > >
      > > > thanks
      > > > Roy
      > > >
      > >
      >
    • rhunter_71
      Fabrizio, thanks for your information and pointers on this. It helped me overcome a couple of obstacles that I was having. Roy
      Message 2 of 5 , May 3, 2011
        Fabrizio,
        thanks for your information and pointers on this. It helped me overcome a couple of obstacles that I was having.
        Roy

        --- In fitnesse@yahoogroups.com, "fab_can" <fab_can@...> wrote:
        >
        > with the RestFixture v2 you can set expectations using JavaScript expressions (an expectation is a block that evaluated returns a boolean); the var jsonbody is in scope containing the last response body (in JSON).
        > if - for example - the last response has a body with
        >
        > { "resource" : { "name" : "test post", "data" : "some data" } }
        >
        > you can write expectations like
        >
        > jsonbody.resource.name=="test post" && jsonbody.resource.data=="some data"
        >
        > you can also do more complex code blocks. for details check this out
        > http://rest-fixture.googlecode.com/files/RestFixture-2.0.beta.1.html
        >
        > Currently the service must return a content-type: application/json for the RestFixture to use the JS interpreter. I am working on a mechanism to override this default behaviour.
        >
        > Fabrizio
        >
        >
        >
        >
        >
        > --- In fitnesse@yahoogroups.com, "rhunter_71" <roywhunter@> wrote:
        > >
        > > thanks,
        > > I look forward to the updates. Right now, I am still trying to figure out how to write the body expectations. I am familiar with Fitnesse, but trying to test the JSON Interfaces is new to me.
        > > Roy
        > >
        > > --- In fitnesse@yahoogroups.com, "fab_can" <fab_can@> wrote:
        > > >
        > > > Hi, I have delayed the release to support json dot notation via rhino. Have a look at the docs.
        > > > When the rel is finalised (next week) I will post here.
        > > >
        > > > As for your table, shouldn't the uri path start with a / ?
        > > > also, how do you intend to write the body expectations? The one you have doesn't look like an xpath
        > > >
        > > > BTW you should be seeing what goes in the wire in the fitnesse error logs for the page after execution. It will confirm what the server responds.
        > > >
        > > > Fabrizio
        > > >
        > > >
        > > > --- In fitnesse@yahoogroups.com, "rhunter_71" <roywhunter@> wrote:
        > > > >
        > > > > I downloaded the latest version of the Restfixture from Github yesterday and was trying to get it working to test some JSON interfaces. I thought that JSON was going to be supported in this release, but I am seeing posts that indicates that it may not be. Can someone tell me if this is supported.
        > > > >
        > > > > currently when I attempt to run my tests, no-body is returned to me.
        > > > >
        > > > > This is what my current test looks like:
        > > > >
        > > > > !|smartrics.rest.fitnesse.fixture.RestFixture|http://localhost:8080/xyxservice|
        > > > > |GET|\heartbeat?elementid=40:FC:89:31:DA:98&sourceid=tablet123|200|content-length: [\d]|COMPANY:xyz / SITE:Mine/ DEVICE:tablet123 / USER:Fred / VER:1.0|
        > > > >
        > > > >
        > > > > thanks
        > > > > Roy
        > > > >
        > > >
        > >
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.