本文整理汇总了Java中io.restassured.specification.RequestSpecification类的典型用法代码示例。如果您正苦于以下问题:Java RequestSpecification类的具体用法?Java RequestSpecification怎么用?Java RequestSpecification使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RequestSpecification类属于io.restassured.specification包,在下文中一共展示了RequestSpecification类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCRUDOperationsAllTogether
import io.restassured.specification.RequestSpecification; //导入依赖的package包/类
@Test
public void testCRUDOperationsAllTogether() {
final String token = queryForToken();
final RequestSpecification reqSpec = new RequestSpecBuilder()
.setContentType(ContentType.JSON)
.setAccept(ContentType.JSON)
.addHeader("Authorization", String.format("Bearer %s", token))
.setRelaxedHTTPSValidation("TLS")
.build();
final String newCustomerUrl = create(reqSpec);
final Customer createdCustomer = read(reqSpec, newCustomerUrl);
update(reqSpec, newCustomerUrl, createdCustomer);
delete(reqSpec, newCustomerUrl);
}
示例2: read
import io.restassured.specification.RequestSpecification; //导入依赖的package包/类
/**
* The R of CRUD
*
* @param reqSpec
* @param newCustomerUrl
* @return The created customer
*/
private Customer read(RequestSpecification reqSpec, String newCustomerUrl) {
// Retrieve the newly created customer
final Customer createdCustomer =
given()
.spec(reqSpec)
.when()
.get(newCustomerUrl)
.then()
.assertThat()
.statusCode(200)
.body("id", is(notNullValue()))
.extract()
.as(Customer.class);
return createdCustomer;
}
示例3: create
import io.restassured.specification.RequestSpecification; //导入依赖的package包/类
/**
* The C of CRUD
*
* @param reqSpec
* @return The URL of the created customer
*/
private String create(RequestSpecification reqSpec) {
final Customer newCustomer = Customer.ofType(PERSON)
.withBirthDate(LocalDate.of(1990, Month.AUGUST, 16))
.build();
// Create a new customer
final Response resp =
given()
.spec(reqSpec)
.body(newCustomer)
.when()
.post("/customers")
.then()
.assertThat()
.statusCode(201)
.extract().response();
final String newCustomerUrl = resp.header("Location");
assertThat(newCustomerUrl).contains("/customers/");
return newCustomerUrl;
}
示例4: update
import io.restassured.specification.RequestSpecification; //导入依赖的package包/类
/**
* The U of CRUD
*
* @param reqSpec
* @param newCustomerUrl
* @param createdCustomer
*/
private void update(RequestSpecification reqSpec, String newCustomerUrl, Customer createdCustomer) {
final Customer customerToUpdate = Customer.from(createdCustomer)
.withFirstName("John")
.withLastName("Doe")
.build();
// Update the customer
given()
.spec(reqSpec)
.body(customerToUpdate)
.when()
.put(newCustomerUrl)
.then()
.statusCode(204);
// Retrieve the updated customer
final Customer updatedCustomer =
given()
.spec(reqSpec)
.when()
.get(newCustomerUrl)
.then()
.assertThat()
.statusCode(200)
.extract()
.as(Customer.class);
assertThat(updatedCustomer.getFirstName()).isEqualTo("John");
assertThat(updatedCustomer.getLastName()).isEqualTo("Doe");
}
示例5: delete
import io.restassured.specification.RequestSpecification; //导入依赖的package包/类
/**
* The D of CRUD
*
* @param reqSpec
* @param newCustomerUrl
*/
private void delete(RequestSpecification reqSpec, String newCustomerUrl) {
// Delete the customer
given()
.spec(reqSpec)
.when()
.delete(newCustomerUrl)
.then()
.statusCode(204);
// Verify it has been deleted
given()
.spec(reqSpec)
.when()
.get(newCustomerUrl)
.then()
.assertThat()
.statusCode(404);
}
示例6: getRequestSpecification
import io.restassured.specification.RequestSpecification; //导入依赖的package包/类
private RequestSpecification getRequestSpecification(UserTimingRequest userTimingRequest) {
RequestSpecBuilder requestSpecBuilder = new RequestSpecBuilder();
requestSpecBuilder.setConfig(getConfiguration());
requestSpecBuilder.setBody(userTimingRequest);
requestSpecBuilder.setContentType(ContentType.JSON);
getFilters(requestSpecBuilder);
return requestSpecBuilder.build();
}
示例7: getSpec
import io.restassured.specification.RequestSpecification; //导入依赖的package包/类
public RequestSpecification getSpec() {
if (data == null)
return spec;
if (data.pathParams.any() && data.url.contains("{"))
for (Pair<String, String> param : data.pathParams)
data.url = data.url.replaceAll("\\{" + param.key + "}", param.value);
spec.contentType(data.contentType);
spec.baseUri(data.url);
if (data.queryParams.any()) {
spec.queryParams(data.queryParams.toMap());
data.url += "?" + PrintUtils.print(data.queryParams.toMap(), "&", "{0}={1}");
}
if (data.body != null)
spec.body(data.body);
if (data.headers.any())
spec.headers(data.headers.toMap());
return spec;
}
示例8: should_get_v1_if_not_logged
import io.restassured.specification.RequestSpecification; //导入依赖的package包/类
@Test
public void should_get_v1_if_not_logged() {
// given
final RequestSpecification requestConfiguration = new RequestSpecBuilder()
.setBaseUri(url.toString())
.build();
// when
given()
.spec(requestConfiguration)
.when()
.get("api/v1/products/{productId}/reviews", 0)
.then()
.assertThat()
.statusCode(200)
.body("$.reviews", not(hasKey("rating")));
}
示例9: to
import io.restassured.specification.RequestSpecification; //导入依赖的package包/类
@When("^I send an empty body to ([\\w-]+)(/[\\w-]+)$")
public void I_send_an_empty_body_to_service_api(String serviceName, String api) {
RequestSpecification request = request(serviceName);
request.header("Content-Type", "application/json");
request.header("token", "ZVtrRXcpTnYWpsjnIpS3olQFGek84E5Z");
request.body(new byte[0]);
Response response = request.post(api);
statusCode = response.getStatusCode();
}
示例10: id
import io.restassured.specification.RequestSpecification; //导入依赖的package包/类
@When("^I send lead with id (\\d+) to ([\\w-]+)(/[\\w-/]+)$")
public void I_send_lead_with_id_to_service_api(int leadId, String serviceName, String api) {
RequestSpecification request = request(serviceName);
request.header("Content-Type", "application/json");
request.header("token", "ZVtrRXcpTnYWpsjnIpS3olQFGek84E5Z");
request.body(Leads.getLead(leadId).toString());
Response response = request.post(api);
statusCode = response.getStatusCode();
}
示例11: execute
import io.restassured.specification.RequestSpecification; //导入依赖的package包/类
public ValidatableResponse execute() {
RequestSpecification request = given();
if (contentType != null) {
request.contentType(contentType);
}
if (headers != null) {
request.headers(headers);
}
if (cookie != null) {
request.cookie(cookie);
}
if (body != null) {
request.body(body);
}
String requestStr = createRequestLog();
ValidatableResponse response = request
.urlEncodingEnabled(false)
.request(method, url)
.then();
String responseStr = createResponseLog(response);
appendToFile(requestStr, responseStr);
return response;
}
示例12: getRequestSpec
import io.restassured.specification.RequestSpecification; //导入依赖的package包/类
/**
* @return a Rest Assured {@link RequestSpecification} with the baseUri
* (and anything else required by most Capture services).
*/
@Override
protected RequestSpecification getRequestSpec() {
return RestAssured.given()
.baseUri(CaptureEndpoint.BASE_URI.getUrl())
.relaxedHTTPSValidation() // trusts even invalid certs
// .log().all() // uncomment to log each request
.contentType(ContentType.JSON)
.accept(ContentType.JSON);
}
示例13: doRequest
import io.restassured.specification.RequestSpecification; //导入依赖的package包/类
public static RestResponse doRequest(
RestMethodTypes methodType, RequestSpecification spec, ResponseStatusType excpecedtStatus) {
Response response;
long time;
try {
time = currentTimeMillis();
response = methodType.method.apply(spec);
time = currentTimeMillis() - time;
} catch (Exception ex) { throw exception("Request failed"); }
RestResponse resp = new RestResponse(response, time);
if (verifyOkStatus)
resp.isStatus(excpecedtStatus);
return resp;
}
示例14: call
import io.restassured.specification.RequestSpecification; //导入依赖的package包/类
public RestResponse call() {
if (type == null)
throw exception("HttpMethodType not specified");
RequestSpecification spec = getSpec();
logger.info(format("Do %s request %s", type, data.url));
return doRequest(type, spec, expectedStatus);
}
示例15: beforeRequest
import io.restassured.specification.RequestSpecification; //导入依赖的package包/类
@Override
public void beforeRequest(RequestSpecification requestSpecification) {
String requestBody = this.requestFacade.getRequestBody();
if (requestBody != null) {
String processed = templatingEngine.processBody(requestBody);
requestSpecification.body(processed);
}
}