Open BobCAE opened 2 years ago
What is the assertion supposed to check?
2
Please enter the field name/key:
id
The assertion now looks as follows: has field "id" Do you want to further edit this assertion and assert something on the field "id"? (e.g., check that the field has a specific type)
type of id is number
I could not understand that. Please try again.
yes
Ok. What is the assertion supposed to check?
2
Please enter the field name/key:
id
The assertion now looks as follows: has field "id" has field "id" Do you want to further edit this assertion and assert something on the field "id"? (e.g., check that the field has a specific type)
yes
Ok. What is the assertion supposed to check?
1
What type is expected? (e.g., JSONObject, JSONArray, String, Number, Boolean)
Number
Here is an overview of the current assertions:
Do you want to add another assertion?
no
Ok. Here is the generated test method code:
public void testCase() {
MiniClient c = new MiniClient(mainPath);
c.setConnectorEndpoint(connector.getHttpEndpoint());
try {
c.setLogin(AnonymousAgentImpl.IDENTIFIER, "");
ClientResponse result = c.sendRequest("POST", "/dishes/1/ratings", """
{
"stars":5,
"comment": "very tasty"
}
""", "application/json", "*/*", new HashMap<>(), new Object[0]);
Assert.assertEquals(200, result.getHttpCode());
Object response = JSONValue.parse(result.getResponse().trim());
// Response body has field "id" has field "id" has type Number
assertThat(response, both(isA(JSONObject.class)).and(asJSONObject(hasField("id", both(isA(JSONObject.class)).and(asJSONObject(hasField("id", isA(Number.class))))))));
} catch (Exception e) {
e.printStackTrace();
fail("Exception: " + e);
}
}
Request method
POST
Request Path
dishes/1/ratings
Request Body
Expected Status Code
200 (OK)
Response Body Assertions