public final class EndPoints { public static final String users = "/users/{id}"; ... } given().pathParams("id", someId).get(EndPoints.users)...; // given().get(EndPoints.users, someId)....
// url http://host:port/appname/rest/someEndpoints private static final basePath = "/appname/rest/"; .. // , // : RestAssured.basePath = basePath; // : given().basePath(basePath)... // ,
// : given().header("content-type", "application/json").header("accept", "application/json")...; // : given().contentType(ContentType.JSON).accept(ContentType.JSON)...;
// : Response response = given()...when().get(someEndpoint); Assert.assertEquals(200, response.then().extract().statusCode()); // : given()...when().get(someEndpoint).then().statusCode(200);
RequestSpecification requestSpec = new RequestSpecBuilder() .setBaseUri("http://localhost") .setPort(8080) .setAccept(ContentType.JSON) .setContentType(ContentType.ANY) ... .log(LogDetail.ALL) .build(); // : RestAssured.requestSpecification = requestSpec; // : given().spec(requestSpec)...when().get(someEndpoint);
ResponseSpecification responseSpec = new ResponseSpecBuilder() .expectStatusCode(200) .expectBody(containsString("success")) .build(); // : RestAssured.responseSpecification = responseSpec; // : given()...when().get(someEndpoint).then().spec(responseSpec)...;
given().contentType(ContentType.JSON).body(somePojo) .when().post(EndPoints.add) .then() .statusCode(201); // : SomePojo pojo = given(). .when().get(EndPoints.get) .then().extract().body().as(SomePojo.class);
// find, findAll , collect . // it Map<String, ?> map = get(EndPoints.anyendpoint).path("rootelement.find { it.title =~ 'anythingRegExp'}"); // , Map<String, ?> map = get(EndPoints.anyendpoint).path("rootelement.findAll { element -> element.title.length() > 4 }"); // sum, max, min , String expensiveCar = get(EndPoints.cars).path("cars.find { it.title == 'Toyota Motor Corporation'}.models.max { it.averagePrice }.title");
Source: https://habr.com/ru/post/421005/
All Articles