436 lines
16 KiB
Java
436 lines
16 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.345854+02:00[Europe/Rome]
|
|
* <br>
|
|
* The generated test suite contains 13 tests
|
|
* <br>
|
|
* Covered targets: 23
|
|
* <br>
|
|
* Used time: 0h 5m 0s
|
|
* <br>
|
|
* Needed budget for current results: 100%
|
|
* <br>
|
|
*
|
|
*/
|
|
public class EvoMaster_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_with500() throws Exception {
|
|
ExpectationHandler expectationHandler = expectationHandler();
|
|
|
|
given().accept("*/*")
|
|
.delete(baseUrlOfSut + "/api/comments/Xfecwx7ykcU8h")
|
|
.then()
|
|
.statusCode(404)
|
|
.assertThat()
|
|
.contentType("text/plain")
|
|
.body(containsString("The comment with idXfecwx7ykcU8h was not found"));
|
|
|
|
|
|
ValidatableResponse res_1 = given().accept("application/json")
|
|
.get(baseUrlOfSut + "/api/comments?limit=0")
|
|
.then()
|
|
.statusCode(500)
|
|
.assertThat()
|
|
.contentType("application/json")
|
|
.body("'status'", numberMatches(500.0))
|
|
.body("'error'", containsString("Internal Server Error"))
|
|
.body("'message'", containsString(""))
|
|
.body("'path'", containsString("/api/comments"));
|
|
|
|
expectationHandler.expect(ems)
|
|
.that(sco, Arrays.asList(200, 400).contains(res_1.extract().statusCode()));
|
|
}
|
|
|
|
|
|
@Test(timeout = 60000)
|
|
public void test_1() 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_2() 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_3() 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_4() throws Exception {
|
|
|
|
given().accept("*/*")
|
|
.contentType("application/json")
|
|
.body(" { " +
|
|
" \"id\": \"SP5w\", " +
|
|
" \"userName\": \"2jkp_\", " +
|
|
" \"text\": \"A8ILiY\", " +
|
|
" \"date\": \"aMw9K33eDwJPJQ\", " +
|
|
" \"type\": \"EVOMASTER\" " +
|
|
" } ")
|
|
.put(baseUrlOfSut + "/api/comments")
|
|
.then()
|
|
.statusCode(400)
|
|
.assertThat()
|
|
.contentType("text/plain")
|
|
.body(containsString("You must complete all fields"));
|
|
|
|
|
|
given().accept("application/json")
|
|
.contentType("application/json")
|
|
.body(" { " +
|
|
" \"id\": \"c4\", " +
|
|
" \"userName\": \"zcww\", " +
|
|
" \"text\": \"HHJZBHxA45E\", " +
|
|
" \"date\": \"HUfmN2tdsk9BBw\", " +
|
|
" \"type\": \"Request\" " +
|
|
" } ")
|
|
.put(baseUrlOfSut + "/api/comments")
|
|
.then()
|
|
.statusCode(200)
|
|
.assertThat()
|
|
.contentType("application/json")
|
|
.body("'userName'", containsString("oliviaClark"))
|
|
.body("'text'", containsString("HHJZBHxA45E"))
|
|
.body("'date'", containsString("2015-06-22T20:12:45.950"))
|
|
.body("'type'", containsString("Request"));
|
|
|
|
|
|
given().accept("*/*")
|
|
.get(baseUrlOfSut + "/api/comments?" +
|
|
"type=EVOMASTER&" +
|
|
"offset=810")
|
|
.then()
|
|
.statusCode(400)
|
|
.assertThat()
|
|
.contentType("text/plain")
|
|
.body(containsString("type must be one of Review, Request, Complain or All"));
|
|
|
|
|
|
given().accept("application/json")
|
|
.get(baseUrlOfSut + "/api/comments?" +
|
|
"type=Review&" +
|
|
"offset=495")
|
|
.then()
|
|
.statusCode(200)
|
|
.assertThat()
|
|
.contentType("application/json")
|
|
.body("size()", equalTo(3588))
|
|
.body("[0].'userName'", containsString("UgtpP7r"))
|
|
.body("[0].'text'", containsString("yvuBzF5"))
|
|
.body("[0].'date'", containsString("R4phZkv"))
|
|
.body("[0].'type'", containsString("Review"))
|
|
.body("[1].'userName'", containsString("0JTDt8DMpvecUiKk"))
|
|
.body("[1].'text'", containsString("GN"))
|
|
.body("[1].'date'", containsString("2023-05-28T14:18:01.578488"))
|
|
.body("[1].'type'", containsString("Review"))
|
|
.body("[2].'userName'", containsString("G3kU3PYYvEW"))
|
|
.body("[2].'text'", containsString("IXAIM6dL"))
|
|
.body("[2].'date'", containsString("2023-05-28T14:18:13.051255"))
|
|
.body("[2].'type'", containsString("Review"))
|
|
; // Skipping assertions on the remaining 3585 elements. This limit of 3 elements can be increased in the configurations
|
|
|
|
|
|
given().accept("application/json")
|
|
.get(baseUrlOfSut + "/api/comments?" +
|
|
"contains=&" +
|
|
"order=%2Bdate&" +
|
|
"limit=815")
|
|
.then()
|
|
.statusCode(200)
|
|
.assertThat()
|
|
.contentType("application/json")
|
|
.body("size()", equalTo(814))
|
|
.body("[0].'userName'", containsString("w_7LJ9orIAjHn"))
|
|
.body("[0].'text'", containsString("OgotIEObttyLUsy4"))
|
|
.body("[0].'date'", containsString(""))
|
|
.body("[0].'type'", nullValue())
|
|
.body("[1].'userName'", containsString("EBaD9sSzMAOMlA"))
|
|
.body("[1].'text'", containsString("KhHClZl"))
|
|
.body("[1].'date'", containsString(""))
|
|
.body("[1].'type'", containsString("Review"))
|
|
.body("[2].'userName'", containsString("5geooRP_wV818vW"))
|
|
.body("[2].'text'", containsString("PKajv4qEU5kk"))
|
|
.body("[2].'date'", containsString(""))
|
|
.body("[2].'type'", containsString("Request"))
|
|
; // Skipping assertions on the remaining 811 elements. This limit of 3 elements can be increased in the configurations
|
|
|
|
}
|
|
|
|
|
|
@Test(timeout = 60000)
|
|
public void test_5() 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"));
|
|
|
|
}
|
|
|
|
|
|
@Test(timeout = 60000)
|
|
public void test_6() throws Exception {
|
|
|
|
given().accept("*/*")
|
|
.delete(baseUrlOfSut + "/api/comments/c89")
|
|
.then()
|
|
.statusCode(204)
|
|
.assertThat()
|
|
.body(isEmptyOrNullString());
|
|
|
|
|
|
given().accept("*/*")
|
|
.delete(baseUrlOfSut + "/api/comments/W7BZcyb5")
|
|
.then()
|
|
.statusCode(404)
|
|
.assertThat()
|
|
.contentType("text/plain")
|
|
.body(containsString("The comment with idW7BZcyb5 was not found"));
|
|
|
|
|
|
given().accept("*/*")
|
|
.delete(baseUrlOfSut + "/api/comments/LxPIWU")
|
|
.then()
|
|
.statusCode(404)
|
|
.assertThat()
|
|
.contentType("text/plain")
|
|
.body(containsString("The comment with idLxPIWU was not found"));
|
|
|
|
}
|
|
|
|
|
|
@Test(timeout = 60000)
|
|
public void test_7() throws Exception {
|
|
|
|
given().accept("*/*")
|
|
.contentType("application/json")
|
|
.body(" { " +
|
|
" \"id\": \"V9pVZUoa\", " +
|
|
" \"userName\": \"xLC9t3yQTzn\", " +
|
|
" \"text\": \"R9LcFjsFHcJ4V7m\", " +
|
|
" \"date\": \"uK2E\", " +
|
|
" \"type\": \"EVOMASTER\" " +
|
|
" } ")
|
|
.put(baseUrlOfSut + "/api/comments")
|
|
.then()
|
|
.statusCode(400)
|
|
.assertThat()
|
|
.contentType("text/plain")
|
|
.body(containsString("You must complete all fields"));
|
|
|
|
}
|
|
|
|
|
|
@Test(timeout = 60000)
|
|
public void test_8() throws Exception {
|
|
|
|
given().accept("*/*")
|
|
.get(baseUrlOfSut + "/api/comments?" +
|
|
"order=EVOMASTER&" +
|
|
"offset=724&" +
|
|
"limit=417")
|
|
.then()
|
|
.statusCode(400)
|
|
.assertThat()
|
|
.contentType("text/plain")
|
|
.body(containsString("order must be one of date, -date or +date"));
|
|
|
|
}
|
|
|
|
|
|
@Test(timeout = 60000)
|
|
public void test_9() throws Exception {
|
|
|
|
given().accept("*/*")
|
|
.contentType("application/json")
|
|
.body(" { " +
|
|
" \"id\": \"XLVOdwbS\", " +
|
|
" \"userName\": \"6HlUf_W\", " +
|
|
" \"text\": \"TbeAKfNS2whm\", " +
|
|
" \"type\": \"EVOMASTER\" " +
|
|
" } ")
|
|
.post(baseUrlOfSut + "/api/comments")
|
|
.then()
|
|
.statusCode(400)
|
|
.assertThat()
|
|
.contentType("text/plain")
|
|
.body(containsString("You must complete the username and text fields"));
|
|
|
|
}
|
|
|
|
|
|
@Test(timeout = 60000)
|
|
public void test_10() throws Exception {
|
|
|
|
given().accept("*/*")
|
|
.get(baseUrlOfSut + "/api/comments/d0wE8XG9YRX")
|
|
.then()
|
|
.statusCode(404)
|
|
.assertThat()
|
|
.contentType("text/plain")
|
|
.body(containsString("The comment with idd0wE8XG9YRX was not found"));
|
|
|
|
}
|
|
|
|
|
|
@Test(timeout = 60000)
|
|
public void test_11() throws Exception {
|
|
|
|
given().accept("*/*")
|
|
.contentType("application/json")
|
|
.body(" { " +
|
|
" \"id\": \"W\", " +
|
|
" \"userName\": \"brLFT4ANfBbU6b\", " +
|
|
" \"text\": \"Pgh7eDjby_YI\", " +
|
|
" \"date\": \"3KVFP6MokMl3Zltx\", " +
|
|
" \"type\": \"Review\" " +
|
|
" } ")
|
|
.put(baseUrlOfSut + "/api/comments")
|
|
.then()
|
|
.statusCode(404)
|
|
.assertThat()
|
|
.contentType("text/plain")
|
|
.body(containsString("The comment with id W was not found"));
|
|
|
|
}
|
|
|
|
|
|
@Test(timeout = 60000)
|
|
public void test_12() throws Exception {
|
|
|
|
given().accept("*/*")
|
|
.delete(baseUrlOfSut + "/api/comments/ANsGVci")
|
|
.then()
|
|
.statusCode(404)
|
|
.assertThat()
|
|
.contentType("text/plain")
|
|
.body(containsString("The comment with idANsGVci was not found"));
|
|
|
|
}
|
|
|
|
|
|
}
|