0

I am using Rest Fixture with Fitnesse to make a GET request to url which returns non-xml response. Is there a way I could verify text/string (without xpath) in the content returned?

Kedarnath
  • 230
  • 1
  • 2
  • 11

3 Answers3

0

I found this solution. TEXT is a supported content handler along XML and JSON. It is possible to override the content handler as TEXT and expect the content. Regular expression can also be used to expect content.

| Table:smartrics.rest.fitnesse.fixture.RestFixtureConfig | overridesContentHandlerConfig|
| restfixture.content.handlers.map | application/smil=TEXT |
!| Table:smartrics.rest.fitnesse.fixture.RestFixture | ${host} ||overridesContentHandlerConfig |
| GET | www.someurl.com | 200 | | [\s\w\d<>/=\:'.]*stringtoverify[\s\w\d<>/=\:'.]* |    
Kedarnath
  • 230
  • 1
  • 2
  • 11
0

You can use fit mode + NetRunner plugin (for .Net).

See here example, how to parse input line to the object.

Manushin Igor
  • 2,709
  • 18
  • 32
0

Another way is to use Custom Comparators. This gives you more flexibility on customizing validation on custom/complicated results.

To use custom comparators: documented here (search for 'CustomComparators')

required property: CustomComparators = <prefix:classname>[,<prefix:class name>]

motivation: The Slim protocol is all String values. It means that comparison of an expected and actual result for complex datatypes is limited to String equality or Regular Expression matching. If that is not sufficient, a Custom Comparator can do more sophisticated comparisons. Once registered, a Custom Comparator is triggered by its prefix, followed by a colon, in front of the expected value.

Example Comparator implementation:

public class JSONAssertComparator implements CustomComparator {
    @Override   
    public boolean matches(String actual, String expected) {
        try {
            JSONAssert.assertEquals(expected, actual, false);
            return true;
        } catch (JSONException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
}

Example plugins.properties:

CustomComparators = json:com.acme.JSONAssertComparator

Example ScriptTable usage:

|script|Customer                                | 
|check|get|cust1|json:{id:cust1,name:"John Doe"}|
Xiawei Zhang
  • 1,530
  • 10
  • 24