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

310 lines
11 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.325419+02:00[Europe/Rome]
* <br>
* The generated test suite contains 8 tests
* <br>
* Covered targets: 12
* <br>
* Used time: 0h 5m 0s
* <br>
* Needed budget for current results: 100%
* <br>
* This file contains test cases that represent failed calls, but not indicative of faults.
*/
public class EvoMaster_others_Test {
private static String baseUrlOfSut = "http://localhost:8080";
@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("*/*")
.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_1() 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_2() 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_3() 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_4() 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_5() 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_6() 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_7() 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"));
}
}