BotEvaluation / MensaService

0 stars 0 forks source link

Test #15

Open BobCAE opened 2 years ago

BobCAE commented 2 years ago

I want to model a test.

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

Ok, let's model a test case. Are you familiar with REST API testing?

BobCAE commented 2 years ago

no

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

Ok. Please enter a name for the test case:

BobCAE commented 2 years ago

Create dish rating test

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

Test case will be named "Create dish rating test". Please enter the request method (e.g., GET, POST,...):

BobCAE commented 2 years ago

post

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

Please enter the request path (e.g., /mensa/Aachen/dishes):

BobCAE commented 2 years ago

/dishes/1/ratings

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

The test request will be POST /dishes/1/ratings. Do you want to include a JSON body to the request?

BobCAE commented 2 years ago

yes

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

Ok, please enter the request body:

BobCAE commented 2 years ago

{ "stars": 5, "comment": "Very delicious!" }

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

Request body was set. Do you want to include assertions on the response to this request?

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

1

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

Which response status code do you expect?

BobCAE commented 2 years ago

201

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

Added assertion to the test. 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 testCreatedishratingtest() {
    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 delicious!"
}""", "application/json", "*/*", new HashMap<>(), new Object[0]);

      Assert.assertEquals(201, result.getHttpCode());

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

  }