sqt/assignment-w13/comments-api/src/test/java/em/EvoMaster_successes_Test.java

164 lines
6.2 KiB
Java

package em;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import java.util.Map;
import java.util.List;
import static org.evomaster.client.java.controller.api.EMTestUtils.*;
import org.evomaster.client.java.controller.SutHandler;
import io.restassured.RestAssured;
import static io.restassured.RestAssured.given;
import io.restassured.response.ValidatableResponse;
import static org.hamcrest.Matchers.*;
import io.restassured.config.JsonConfig;
import io.restassured.path.json.config.JsonPathConfig;
import static io.restassured.config.RedirectConfig.redirectConfig;
import static org.evomaster.client.java.controller.contentMatchers.NumberMatcher.*;
import static org.evomaster.client.java.controller.contentMatchers.StringMatcher.*;
import static org.evomaster.client.java.controller.contentMatchers.SubStringMatcher.*;
import static org.evomaster.client.java.controller.expect.ExpectationHandler.expectationHandler;
import org.evomaster.client.java.controller.expect.ExpectationHandler;
import io.restassured.path.json.JsonPath;
import java.util.Arrays;
/**
* This file was automatically generated by EvoMaster on 2023-05-28T14:22:53.312136+02:00[Europe/Rome]
* <br>
* The generated test suite contains 4 tests
* <br>
* Covered targets: 9
* <br>
* Used time: 0h 5m 0s
* <br>
* Needed budget for current results: 100%
* <br>
* This file contains test cases that represent successful calls.
*/
public class EvoMaster_successes_Test {
private static String baseUrlOfSut = "http://localhost:8080";
/** [ems] - expectations master switch - is the variable that activates/deactivates expectations individual test cases
* by default, expectations are turned off. The variable needs to be set to [true] to enable expectations
*/
private static boolean ems = false;
/**
* sco - supported code oracle - checking that the response status code is among those supported according to the schema
*/
private static boolean sco = false;
@BeforeClass
public static void initClass() {
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
RestAssured.useRelaxedHTTPSValidation();
RestAssured.urlEncodingEnabled = false;
RestAssured.config = RestAssured.config()
.jsonConfig(JsonConfig.jsonConfig().numberReturnType(JsonPathConfig.NumberReturnType.DOUBLE))
.redirect(redirectConfig().followRedirects(false));
}
@Test(timeout = 60000)
public void test_0() throws Exception {
given().accept("application/json")
.get(baseUrlOfSut + "/api/comments?type=Review")
.then()
.statusCode(200)
.assertThat()
.contentType("application/json")
.body("size()", equalTo(14))
.body("[0].'userName'", containsString("qvJGGVwpV1l9f"))
.body("[0].'text'", containsString("_W25b55Y"))
.body("[0].'date'", containsString("2023-05-28T14:17:53.936339"))
.body("[0].'type'", containsString("Review"))
.body("[1].'userName'", containsString("axiFfR_z"))
.body("[1].'text'", containsString("98JIw7gD83jBdpgD"))
.body("[1].'date'", containsString("M"))
.body("[1].'type'", containsString("Review"))
.body("[2].'userName'", containsString("johnSmith"))
.body("[2].'text'", containsString("Great book!"))
.body("[2].'date'", containsString("2017-02-16T20:44:53.950"))
.body("[2].'type'", containsString("Review"))
; // Skipping assertions on the remaining 11 elements. This limit of 3 elements can be increased in the configurations
}
@Test(timeout = 60000)
public void test_1() throws Exception {
given().accept("application/json")
.get(baseUrlOfSut + "/api/comments/c4")
.then()
.statusCode(200)
.assertThat()
.contentType("application/json")
.body("'userName'", containsString("oliviaClark"))
.body("'text'", containsString("Please, give me a call before the delivery"))
.body("'date'", containsString("2015-06-22T20:12:45.950"))
.body("'type'", containsString("Request"));
}
@Test(timeout = 60000)
public void test_2() throws Exception {
ExpectationHandler expectationHandler = expectationHandler();
ValidatableResponse res_0 = given().accept("*/*")
.get(baseUrlOfSut + "/docs/swagger.yaml")
.then()
.statusCode(200)
.assertThat()
.contentType("application/octet-stream");
expectationHandler.expect(ems)
/*
Note: No supported codes appear to be defined. https://swagger.io/docs/specification/describing-responses/.
This is somewhat unexpected, so the code below is likely to lead to a failed expectation
*/
.that(sco, Arrays.asList().contains(res_0.extract().statusCode()));
}
@Test(timeout = 60000)
public void test_3() throws Exception {
given().accept("application/json")
.contentType("application/json")
.body(" { " +
" \"id\": \"RGUxO9tPdi\", " +
" \"userName\": \"axiFfR_z\", " +
" \"text\": \"98JIw7gD83jBdpgD\", " +
" \"date\": \"M\", " +
" \"type\": \"Review\" " +
" } ")
.post(baseUrlOfSut + "/api/comments")
.then()
.statusCode(201)
.assertThat()
.contentType("application/json")
.body("'userName'", containsString("axiFfR_z"))
.body("'text'", containsString("98JIw7gD83jBdpgD"))
.body("'date'", containsString("M"))
.body("'type'", containsString("Review"));
}
}