当前位置: 首页>>代码示例>>Java>>正文


Java RequestSpecification类代码示例

本文整理汇总了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);
}
 
开发者ID:dserradji,项目名称:reactive-customer-service,代码行数:18,代码来源:CustomerServiceIT.java

示例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;
}
 
开发者ID:dserradji,项目名称:reactive-customer-service,代码行数:24,代码来源:CustomerServiceIT.java

示例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;
}
 
开发者ID:dserradji,项目名称:reactive-customer-service,代码行数:30,代码来源:CustomerServiceIT.java

示例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");
}
 
开发者ID:dserradji,项目名称:reactive-customer-service,代码行数:38,代码来源:CustomerServiceIT.java

示例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);
}
 
开发者ID:dserradji,项目名称:reactive-customer-service,代码行数:26,代码来源:CustomerServiceIT.java

示例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();
}
 
开发者ID:kaygee,项目名称:timings-client,代码行数:9,代码来源:TimingsFacade.java

示例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;
}
 
开发者ID:epam,项目名称:JDI,代码行数:19,代码来源:RestMethod.java

示例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")));

}
 
开发者ID:arquillian,项目名称:arquillian-cube,代码行数:20,代码来源:ReviewsIT.java

示例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();
}
 
开发者ID:intellead,项目名称:intellead-integration-tests,代码行数:10,代码来源:Steps.java

示例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();
}
 
开发者ID:intellead,项目名称:intellead-integration-tests,代码行数:10,代码来源:Steps.java

示例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;
}
 
开发者ID:Atypon-OpenSource,项目名称:wayf-cloud,代码行数:32,代码来源:LoggingHttpRequestFactory.java

示例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);
}
 
开发者ID:Frameworkium,项目名称:frameworkium-examples,代码行数:14,代码来源:BaseCaptureService.java

示例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;
}
 
开发者ID:epam,项目名称:JDI,代码行数:15,代码来源:RestRequest.java

示例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);
}
 
开发者ID:epam,项目名称:JDI,代码行数:8,代码来源:RestMethod.java

示例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);
    }
}
 
开发者ID:ctco,项目名称:cukes,代码行数:9,代码来源:PreprocessRestRequestBody.java


注:本文中的io.restassured.specification.RequestSpecification类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。