I'm new to Rest Assured and have been having trouble with a number of tests like this.
It is not clear what matchers I need to use for which tasks. So far I've been finding a lot of things that _don't_ work before I find a method that does.
Things I am trying to do:
1. Verify the body has a specified label/value
Naive solution. expect().body("id",equalsTo("text")) ** FAILS
Working List<String> check = new ArrayList<String>(); check.add("text"); expect().body("id",equalsTo(check));
2. Verify the body has a label present with a string.
Naive solution: expect().body("id",isA(String.class)) ** FAILS
3. Verify the body does NOT have a specified label.
Naive solution: expect().body("missing",empty()) ** Fails
I really need either a list of matchers that work with specified JSON body values, or details on how to create them.
If I missed this somewhere, I'd love someone to tell me where to go.
--
{}
- "uid": "51015ad9cc145",
- "expires": "2013-01-24 10:06:29",
- "errors": [
],
- 2330
- "items": [
]
- {
}
- "id": "testlabelone",
- "title": "test site - Test Label One (DEV)",
- "features": {
},
- "storedCard": false,
- "standbyPage": false,
- "requireAccount": false,
- "captcha": 2
- "locale": {
},
- "default": "en_US.utf8",
- "locales": [
]
- "en_US.utf8",
- "fr_CA.utf8",
- "en_GB.utf8"
- "goog": {
},
- "id": "2342342",
- "urchinLabel": "label-abc",
- "urchinUA": "UA-32253326-3"
- "related": [
]
- {
},
- "id": "ywjj33kf3d",
- "title": "Basic Password Tests - GA"
- {
}
- "id": "fai60k0729",
- "title": "Bulk Buying"
Fails:
Tests that I want to have working:
- body("uid",hasItem(String.class))
Creates a matcher for Iterables that only matches when a single pass over the examined Iterable yields at least one item that is matched by the specified itemMatcher. Whilst matching, the traversal of the examined Iterable will stop as soon as a matching item is found.For example:assertThat(Arrays.asList("foo", "bar"), hasItem(startsWith("ba")))
- body("",hasItem("uid"))
- ...
Tests that I want to have working:
- Test for existence. Is the label found with any value associated with it in the json?
- empty() : doesn't work - error
- notNullValue() : doesn't work - _always_ true, even when key value isn't there.
- "non-existent.size()" is(0) : doesn't work - _always_ returns 1
--