Search in sources :

Example 11 with MockMvcRequestSpecification

use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecification in project rest-assured by rest-assured.

the class MockMvcRequestSpecificationMergingTest method query_params_are_merged.

// @formatter:off
@Test
public void query_params_are_merged() {
    // Given
    MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().addQueryParam("param1", "value1").build();
    // When
    MockMvcRequestSpecification spec = RestAssuredMockMvc.given().queryParam("param2", "value2").spec(specToMerge);
    // Then
    Assertions.assertThat(implOf(spec).getQueryParams()).containsOnly(entry("param1", "value1"), entry("param2", "value2"));
}
Also used : MockMvcRequestSpecification(io.restassured.module.mockmvc.specification.MockMvcRequestSpecification) MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) Test(org.junit.Test)

Example 12 with MockMvcRequestSpecification

use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecification in project rest-assured by rest-assured.

the class MockMvcRequestSpecificationMergingTest method request_body_is_not_overwritten_when_not_defined_in_specification.

@Test
public void request_body_is_not_overwritten_when_not_defined_in_specification() {
    // Given
    MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().addQueryParam("param1", "value1").build();
    // When
    MockMvcRequestSpecification spec = RestAssuredMockMvc.given().body("body1").spec(specToMerge);
    // Then
    Assertions.assertThat(implOf(spec).getRequestBody()).isEqualTo("body1");
    Assertions.assertThat(implOf(spec).getQueryParams()).containsOnly(entry("param1", "value1"));
}
Also used : MockMvcRequestSpecification(io.restassured.module.mockmvc.specification.MockMvcRequestSpecification) MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) Test(org.junit.Test)

Example 13 with MockMvcRequestSpecification

use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecification 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"));
}
Also used : MockMvcRequestSpecification(io.restassured.module.mockmvc.specification.MockMvcRequestSpecification) MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) Test(org.junit.Test)

Example 14 with MockMvcRequestSpecification

use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecification 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");
}
Also used : MockMvcRequestSpecification(io.restassured.module.mockmvc.specification.MockMvcRequestSpecification) MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) MockMvcAuthenticationScheme(io.restassured.module.mockmvc.specification.MockMvcAuthenticationScheme) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) Test(org.junit.Test)

Example 15 with MockMvcRequestSpecification

use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecification 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"));
}
Also used : MockMvcRequestSpecification(io.restassured.module.mockmvc.specification.MockMvcRequestSpecification) MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) Header(io.restassured.http.Header) Test(org.junit.Test)

Aggregations

MockMvcRequestSpecBuilder (io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder)31 MockMvcRequestSpecification (io.restassured.module.mockmvc.specification.MockMvcRequestSpecification)31 Test (org.junit.Test)31 GreetingController (io.restassured.module.mockmvc.http.GreetingController)4 RestAssuredMockMvcConfig (io.restassured.module.mockmvc.config.RestAssuredMockMvcConfig)3 MockMvcAuthenticationScheme (io.restassured.module.mockmvc.specification.MockMvcAuthenticationScheme)3 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)3 Cookie (io.restassured.http.Cookie)2 Header (io.restassured.http.Header)2 MockHttpServletRequestBuilderInterceptor (io.restassured.module.mockmvc.intercept.MockHttpServletRequestBuilderInterceptor)2 PrintStream (java.io.PrintStream)2 StringWriter (java.io.StringWriter)2 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)2 MockMvc (org.springframework.test.web.servlet.MockMvc)2 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)2 RestAssuredConfig (io.restassured.config.RestAssuredConfig)1 PostController (io.restassured.module.mockmvc.http.PostController)1