use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder in project rest-assured by rest-assured.
the class MockMvcStaticRequestAndResponseSpecTest method response_validation_fails_if_any_property_in_the_response_is_not_valid.
@Test
public void response_validation_fails_if_any_property_in_the_response_is_not_valid() {
RestAssuredMockMvc.requestSpecification = new MockMvcRequestSpecBuilder().addQueryParam("name", "Johan").build();
RestAssuredMockMvc.responseSpecification = new ResponseSpecBuilder().expectStatusCode(200).expectBody("content", equalTo("Hello, John!")).build();
exception.expect(AssertionError.class);
exception.expectMessage("1 expectation failed.\n" + "JSON path content doesn't match.\n" + "Expected: Hello, John!\n" + " Actual: Hello, Johan!");
try {
// When
RestAssuredMockMvc.given().standaloneSetup(new GreetingController()).when().get("/greeting").then().body("id", equalTo(1));
} finally {
RestAssuredMockMvc.reset();
}
}
use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder in project rest-assured by rest-assured.
the class MockMvcStaticRequestAndResponseSpecTest method response_validation_kicks_in_even_when_no_then_clause_is_specified.
@Test
public void response_validation_kicks_in_even_when_no_then_clause_is_specified() {
RestAssuredMockMvc.requestSpecification = new MockMvcRequestSpecBuilder().addQueryParam("name", "Johan").build();
RestAssuredMockMvc.responseSpecification = new ResponseSpecBuilder().expectStatusCode(200).expectBody("content", equalTo("Hello, John!")).build();
exception.expect(AssertionError.class);
exception.expectMessage("1 expectation failed.\n" + "JSON path content doesn't match.\n" + "Expected: Hello, John!\n" + " Actual: Hello, Johan!");
try {
// When
RestAssuredMockMvc.given().standaloneSetup(new GreetingController()).when().get("/greeting");
} finally {
RestAssuredMockMvc.reset();
}
}
use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder in project rest-assured by rest-assured.
the class MockMvcRequestSpecificationMergingTest method multi_parts_are_merged.
@Test
public void multi_parts_are_merged() {
// Given
MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().addMultiPart("param1", "value1").build();
// When
MockMvcRequestSpecification spec = RestAssuredMockMvc.given().multiPart("param2", "value2").spec(specToMerge);
// Then
Assertions.assertThat(implOf(spec).getMultiParts()).hasSize(2);
}
use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder in project rest-assured by rest-assured.
the class MockMvcRequestSpecificationMergingTest method logging_is_not_overwritten_when_not_defined_in_specification.
@Test
public void logging_is_not_overwritten_when_not_defined_in_specification() {
// Given
StringWriter writer = new StringWriter();
PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().setConfig(RestAssuredMockMvcConfig.newConfig().logConfig(LogConfig.logConfig().defaultStream(captor))).addQueryParam("name", "Johan").build();
// When
RestAssuredMockMvc.given().spec(specToMerge).log().params().standaloneSetup(new GreetingController()).when().get("/greeting").then().body("id", equalTo(1)).body("content", equalTo("Hello, Johan!"));
// Then
assertThat(writer.toString()).isEqualTo("Request params:\t<none>\n" + "Query params:\tname=Johan\n" + "Form params:\t<none>\n" + "Path params:\t<none>\n" + "Multiparts:\t\t<none>\n");
}
use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder in project rest-assured by rest-assured.
the class MockMvcRequestSpecificationMergingTest method headers_are_merged_when_defined_in_specification.
@Test
public void headers_are_merged_when_defined_in_specification() {
// Given
Header otherHeader = new Header("header1", "value1");
Header thisHeader = new Header("header2", "value2");
MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().addHeader(otherHeader).build();
// When
MockMvcRequestSpecification spec = RestAssuredMockMvc.given().header(thisHeader).spec(specToMerge);
// Then
Assertions.assertThat(implOf(spec).getRequestHeaders()).containsOnly(thisHeader, otherHeader);
}
Aggregations