BotEvaluation / MensaService

0 stars 0 forks source link

[API Test]: #6

Open BobCAE opened 2 years ago

BobCAE commented 2 years ago

Request method

POST

Request Path

dishes/1/ratings

Request Body

{
  "stars": 4,
  "comment": "Nice"
}

Expected Status Code

201 (Created)

Response Body Assertions

api-testing-bot[bot] commented 2 years ago

What is the assertion supposed to check?

  1. Whether the body (or field value) has a specific type (e.g., if it is a JSONObject, a Number, ...)
  2. Whether it contains a field (e.g., if the JSONObject contains a field "id")
  3. Whether it is a list and contains an entry of a specific type
  4. Whether it is a list and contains an entry that contains a specific field
  5. Whether it is a list and all entries have a specific type
  6. Whether it is a list and all entries contain a specific field
BobCAE commented 2 years ago

1

api-testing-bot[bot] commented 2 years ago

What type is expected? (e.g., JSONObject, JSONArray, String, Number, Boolean)

BobCAE commented 2 years ago

json object

api-testing-bot[bot] commented 2 years ago

Here is an overview of the current assertions:

Do you want to add another assertion?

BobCAE commented 2 years ago

yes

api-testing-bot[bot] commented 2 years ago

Ok. Which type of assertion should be added? Please enter a number:

  1. Assertion on the response status code (e.g., check that status code 200 is returned)
  2. Assertion on the response body (e.g., check that response contains field "id")
BobCAE commented 2 years ago

2

api-testing-bot[bot] commented 2 years ago

What is the assertion supposed to check?

  1. Whether the body (or field value) has a specific type (e.g., if it is a JSONObject, a Number, ...)
  2. Whether it contains a field (e.g., if the JSONObject contains a field "id")
  3. Whether it is a list and contains an entry of a specific type
  4. Whether it is a list and contains an entry that contains a specific field
  5. Whether it is a list and all entries have a specific type
  6. Whether it is a list and all entries contain a specific field
BobCAE commented 2 years ago

2

api-testing-bot[bot] commented 2 years ago

Please enter the field name/key:

BobCAE commented 2 years ago

id

api-testing-bot[bot] commented 2 years ago

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)

BobCAE commented 2 years ago

yes

api-testing-bot[bot] commented 2 years ago

Ok. What is the assertion supposed to check?

  1. Whether the body (or field value) has a specific type (e.g., if it is a JSONObject, a Number, ...)
  2. Whether it contains a field (e.g., if the JSONObject contains a field "id")
  3. Whether it is a list and contains an entry of a specific type
  4. Whether it is a list and contains an entry that contains a specific field
  5. Whether it is a list and all entries have a specific type
  6. Whether it is a list and all entries contain a specific field
BobCAE commented 2 years ago

1

api-testing-bot[bot] commented 2 years ago

What type is expected? (e.g., JSONObject, JSONArray, String, Number, Boolean)

BobCAE commented 2 years ago

number

api-testing-bot[bot] commented 2 years ago

Here is an overview of the current assertions:

Do you want to add another assertion?

BobCAE commented 2 years ago

no

api-testing-bot[bot] commented 2 years ago

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": 4,
  "comment": "Nice"
}
""", "application/json", "*/*", new HashMap<>(), new Object[0]);

      Assert.assertEquals(201, result.getHttpCode());
  Object response = JSONValue.parse(result.getResponse().trim());
      // Response body has type JSON Object
      assertThat(response, isA(JSONObject.class));

      // Response body has field "id" has type Number
      assertThat(response, both(isA(JSONObject.class)).and(asJSONObject(hasField("id", isA(Number.class)))));

    } catch (Exception e) {
      e.printStackTrace();
      fail("Exception: " + e);
    }

  }