use of io.restassured.builder.ResponseSpecBuilder in project rest-assured by rest-assured.
the class LogIfValidationFailsITest method logging_of_both_request_and_response_validation_works_when_test_fails_when_using_static_response_and_request_specs_declared_before_enable_logging.
@Test
public void logging_of_both_request_and_response_validation_works_when_test_fails_when_using_static_response_and_request_specs_declared_before_enable_logging() {
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
RestAssured.responseSpecification = new ResponseSpecBuilder().expectStatusCode(200).build();
RestAssured.requestSpecification = new RequestSpecBuilder().setConfig(RestAssuredConfig.config().logConfig(new LogConfig(captor, true))).addHeader("Api-Key", "1234").build();
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails(LogDetail.HEADERS);
try {
RestAssured.given().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\t" + "Api-Key=1234" + LINE_SEPARATOR + "\t\t\t\tAccept=*/*" + LINE_SEPARATOR + "\t\t\t\tContent-Type=application/json; charset=" + RestAssured.config().getEncoderConfig().defaultCharsetForContentType(ContentType.JSON) + LINE_SEPARATOR + LINE_SEPARATOR + "Content-Type: application/json;charset=utf-8\nContent-Length: 33\nServer: Jetty(9.3.2.v20150730)\n"));
}
}
use of io.restassured.builder.ResponseSpecBuilder in project rest-assured by rest-assured.
the class LogIfValidationFailsITest method logging_is_applied_when_using_non_static_response_specifications.
@Test
public void logging_is_applied_when_using_non_static_response_specifications() {
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
try {
RestAssured.given().config(RestAssured.config().logConfig(LogConfig.logConfig().defaultStream(captor).and().enableLoggingOfRequestAndResponseIfValidationFails())).param("firstName", "John").param("lastName", "Doe").when().get("/greet").then().spec(new ResponseSpecBuilder().expectStatusCode(400).build());
fail("Test out to have failed by now");
} catch (AssertionError e) {
assertThat(writer.toString(), not(isEmptyOrNullString()));
}
}
use of io.restassured.builder.ResponseSpecBuilder in project rest-assured by rest-assured.
the class SpecificationBuilderITest method mergesStaticallyDefinedResponseSpecificationsCorrectly.
@Test
public void mergesStaticallyDefinedResponseSpecificationsCorrectly() throws Exception {
RestAssured.responseSpecification = new ResponseSpecBuilder().expectCookie("Cookie1", "Value1").build();
ResponseSpecification reqSpec1 = new ResponseSpecBuilder().expectCookie("Cookie2", "Value2").build();
ResponseSpecification reqSpec2 = new ResponseSpecBuilder().expectCookie("Cookie3", "Value3").build();
try {
Cookies cookies = given().cookie("Cookie1", "Value1").cookie("Cookie2", "Value2").when().get("/reflect").then().assertThat().spec(reqSpec1).extract().detailedCookies();
assertThat(cookies.size(), is(2));
assertThat(cookies.hasCookieWithName("Cookie1"), is(true));
assertThat(cookies.hasCookieWithName("Cookie2"), is(true));
cookies = given().cookie("Cookie1", "Value1").cookie("Cookie3", "Value3").when().get("/reflect").then().assertThat().spec(reqSpec2).extract().detailedCookies();
assertThat(cookies.size(), is(2));
assertThat(cookies.hasCookieWithName("Cookie1"), is(true));
assertThat(cookies.hasCookieWithName("Cookie3"), is(true));
} finally {
RestAssured.reset();
}
}
use of io.restassured.builder.ResponseSpecBuilder in project rest-assured by rest-assured.
the class SpecificationBuilderITest method expectingSpecificationMergesTheCurrentSpecificationWithTheSuppliedOne.
@Test
public void expectingSpecificationMergesTheCurrentSpecificationWithTheSuppliedOne() throws Exception {
final ResponseSpecBuilder builder = new ResponseSpecBuilder();
builder.expectBody("store.book.size()", is(4)).expectStatusCode(200);
final ResponseSpecification responseSpecification = builder.build();
expect().specification(responseSpecification).body("store.book[0].author", equalTo("Nigel Rees")).when().get("/jsonStore");
}
use of io.restassured.builder.ResponseSpecBuilder in project rest-assured by rest-assured.
the class GivenWhenThenResponseSpecITest method simple_given_when_then_works.
@Test
public void simple_given_when_then_works() {
exception.expect(AssertionError.class);
exception.expectMessage("2 expectations failed.\n" + "Expected status code <201> but was <200>.\n" + "\n" + "JSON path greeting doesn't match.\n" + "Expected: Greetings John Doo\n" + " Actual: Greetings John Doe");
ResponseSpecification specification = new ResponseSpecBuilder().expectStatusCode(201).expectBody("greeting", equalTo("Greetings John Doo")).build();
given().param("firstName", "John").param("lastName", "Doe").when().get("/greet").then().spec(specification);
}
Aggregations