use of io.restassured.specification.RequestSpecification in project rest-assured by rest-assured.
the class JSONGetITest method specificationSyntax.
@Test
public void specificationSyntax() throws Exception {
final RequestSpecification requestSpecification = with().parameters("firstName", "John", "lastName", "Doe");
final ResponseSpecification responseSpecification = expect().body("greeting", equalTo("Greetings John Doe"));
given(requestSpecification, responseSpecification).get("/greet");
}
use of io.restassured.specification.RequestSpecification in project rest-assured by rest-assured.
the class JSONPostITest method requestContentType.
@Test
public void requestContentType() throws Exception {
final RequestSpecification requestSpecification = given().contentType(ContentType.URLENC).with().parameters("firstName", "John", "lastName", "Doe");
final ResponseSpecification responseSpecification = expect().contentType(ContentType.JSON).and().body("greeting", equalTo("Greetings John Doe"));
given(requestSpecification, responseSpecification).post("/greet");
}
use of io.restassured.specification.RequestSpecification in project rest-assured by rest-assured.
the class LogIfValidationFailsITest method doesnt_log_request_or_response_when_test_fails_when_using_non_static_request_spec_declared_before_enable_logging_since_config_is_immutable_and_spec_config_has_precedence_over_global_config.
@Test
public void doesnt_log_request_or_response_when_test_fails_when_using_non_static_request_spec_declared_before_enable_logging_since_config_is_immutable_and_spec_config_has_precedence_over_global_config() {
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
RequestSpecification specification = new RequestSpecBuilder().setConfig(RestAssured.config().logConfig(RestAssured.config().getLogConfig().defaultStream(captor).and().enablePrettyPrinting(true))).addHeader("Api-Key", "1234").build();
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails(LogDetail.HEADERS);
try {
RestAssured.given().spec(specification).param("firstName", "John").param("lastName", "Doe").header("Content-type", "application/json").when().get("/greet").then().body("firstName", equalTo("Hello, Johan2!"));
fail("Should throw AssertionError");
} catch (AssertionError e) {
assertThat(writer.toString(), isEmptyString());
}
}
use of io.restassured.specification.RequestSpecification in project rest-assured by rest-assured.
the class LogIfValidationFailsITest method logging_of_both_request_and_response_validation_works_when_test_fails_when_using_non_static_request_spec_declared_after_enable_logging.
@Test
public void logging_of_both_request_and_response_validation_works_when_test_fails_when_using_non_static_request_spec_declared_after_enable_logging() {
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails(LogDetail.HEADERS);
RequestSpecification specification = new RequestSpecBuilder().setConfig(RestAssured.config().logConfig(RestAssured.config().getLogConfig().defaultStream(captor).and().enablePrettyPrinting(true))).addHeader("Api-Key", "1234").build();
try {
RestAssured.given().spec(specification).param("firstName", "John").param("lastName", "Doe").header("Content-type", "application/json").when().get("/greet").then().body("firstName", equalTo("Hello, Johan2!"));
fail("Should throw AssertionError");
} catch (AssertionError e) {
assertThat(writer.toString(), equalTo("Headers:\t\tApi-Key=1234\n\t\t\t\tAccept=*/*\n\t\t\t\tContent-Type=application/json; charset=" + RestAssured.config().getEncoderConfig().defaultCharsetForContentType(ContentType.JSON) + "\n\nContent-Type: application/json;charset=utf-8\nContent-Length: 33\nServer: Jetty(9.3.2.v20150730)\n"));
}
}
use of io.restassured.specification.RequestSpecification in project rest-assured by rest-assured.
the class ProxyITest method using_proxy_with_specification.
@Test
public void using_proxy_with_specification() {
RequestSpecification specification = new RequestSpecBuilder().setProxy("localhost").build();
given().specification(specification).param("firstName", "John").param("lastName", "Doe").when().get("/greetJSON").then().header("Via", not(isEmptyOrNullString()));
}
Aggregations