use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder in project rest-assured by rest-assured.
the class MockMvcRequestSpecificationMergingTest method content_type_is_not_overwritten_when_not_defined_in_specification.
@Test
public void content_type_is_not_overwritten_when_not_defined_in_specification() {
// Given
MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().addQueryParam("param1", "value1").build();
// When
MockMvcRequestSpecification spec = RestAssuredMockMvc.given().contentType(ContentType.XML).spec(specToMerge);
// Then
Assertions.assertThat(implOf(spec).getRequestContentType()).isEqualTo(ContentType.XML.toString());
Assertions.assertThat(implOf(spec).getQueryParams()).containsOnly(entry("param1", "value1"));
}
use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder in project rest-assured by rest-assured.
the class MockMvcRequestSpecificationMergingTest method authentication_is_overwritten_when_defined_in_specification.
@Test
public void authentication_is_overwritten_when_defined_in_specification() {
// Given
MockMvcAuthenticationScheme otherAuth = RestAssuredMockMvc.principal("other");
MockMvcAuthenticationScheme thisAuth = RestAssuredMockMvc.principal("this");
MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().setAuth(otherAuth).build();
// When
MockMvcRequestSpecification spec = RestAssuredMockMvc.given().spec(new MockMvcRequestSpecBuilder().setAuth(thisAuth).build()).spec(specToMerge);
// Then
assertThat(((TestingAuthenticationToken) implOf(spec).getAuthentication()).getPrincipal()).isEqualTo("other");
}
use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder in project rest-assured by rest-assured.
the class MockMvcRequestSpecificationMergingTest method headers_are_not_overwritten_when_not_defined_in_specification.
@Test
public void headers_are_not_overwritten_when_not_defined_in_specification() {
// Given
Header thisHeader = new Header("cookie2", "value2");
MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().addQueryParam("param1", "value1").build();
// When
MockMvcRequestSpecification spec = RestAssuredMockMvc.given().header(thisHeader).spec(specToMerge);
// Then
Assertions.assertThat(implOf(spec).getRequestHeaders()).containsOnly(thisHeader);
Assertions.assertThat(implOf(spec).getQueryParams()).containsOnly(entry("param1", "value1"));
}
use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder in project rest-assured by rest-assured.
the class MockMvcRequestSpecificationMergingTest method cookies_are_merged_when_defined_in_specification.
@Test
public void cookies_are_merged_when_defined_in_specification() {
// Given
Cookie otherCookie = new Cookie.Builder("cookie1", "value1").build();
Cookie thisCookie = new Cookie.Builder("cookie2", "value2").build();
MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().addCookie(otherCookie).build();
// When
MockMvcRequestSpecification spec = RestAssuredMockMvc.given().cookie(thisCookie).spec(specToMerge);
// Then
Assertions.assertThat(implOf(spec).getCookies()).containsOnly(thisCookie, otherCookie);
}
use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder in project rest-assured by rest-assured.
the class MockMvcRequestSpecificationMergingTest method logging_is_overwritten_when_defined_in_specification.
@Test
public void logging_is_overwritten_when_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))).and().log(LogDetail.ALL).build();
// When
RestAssuredMockMvc.given().log().params().spec(specToMerge).standaloneSetup(new GreetingController()).when().get("/greeting?name={name}", "Johan").then().body("id", equalTo(1)).body("content", equalTo("Hello, Johan!"));
// Then
assertThat(writer.toString()).isEqualTo("Request method:\tGET\n" + "Request URI:\thttp://localhost:8080/greeting?name=Johan\n" + "Proxy:\t\t\t<none>\n" + "Request params:\t<none>\n" + "Query params:\t<none>\n" + "Form params:\t<none>\n" + "Path params:\t<none>\n" + "Headers:\t\t<none>\n" + "Cookies:\t\t<none>\n" + "Multiparts:\t\t<none>\n" + "Body:\t\t\t<none>\n");
}
Aggregations