Search in sources :

Example 26 with MockMvcRequestSpecification

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

the class MockMvcRequestSpecificationMergingTest method interception_is_overwritten_when_defined_in_specification.

@Test
public void interception_is_overwritten_when_defined_in_specification() {
    // Given
    MockHttpServletRequestBuilderInterceptor otherInterceptor = new MockHttpServletRequestBuilderInterceptor() {

        public void intercept(MockHttpServletRequestBuilder requestBuilder) {
        }
    };
    MockHttpServletRequestBuilderInterceptor thisInterceptor = new MockHttpServletRequestBuilderInterceptor() {

        public void intercept(MockHttpServletRequestBuilder requestBuilder) {
        }
    };
    MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().setMockHttpServletRequestBuilderInterceptor(otherInterceptor).build();
    // When
    MockMvcRequestSpecification spec = RestAssuredMockMvc.given().interceptor(thisInterceptor).spec(specToMerge);
    // Then
    Assertions.assertThat(implOf(spec).getInterceptor()).isEqualTo(otherInterceptor);
}
Also used : MockMvcRequestSpecification(io.restassured.module.mockmvc.specification.MockMvcRequestSpecification) MockHttpServletRequestBuilderInterceptor(io.restassured.module.mockmvc.intercept.MockHttpServletRequestBuilderInterceptor) MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) Test(org.junit.Test)

Example 27 with MockMvcRequestSpecification

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

the class MockMvcRequestSpecificationMergingTest method interception_is_not_overwritten_when_not_defined_in_specification.

@Test
public void interception_is_not_overwritten_when_not_defined_in_specification() {
    // Given
    MockHttpServletRequestBuilderInterceptor thisInterceptor = new MockHttpServletRequestBuilderInterceptor() {

        public void intercept(MockHttpServletRequestBuilder requestBuilder) {
        }
    };
    MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().addQueryParam("param1", "value1").build();
    // When
    MockMvcRequestSpecification spec = RestAssuredMockMvc.given().interceptor(thisInterceptor).spec(specToMerge);
    // Then
    Assertions.assertThat(implOf(spec).getInterceptor()).isEqualTo(thisInterceptor);
    Assertions.assertThat(implOf(spec).getQueryParams()).containsOnly(entry("param1", "value1"));
}
Also used : MockMvcRequestSpecification(io.restassured.module.mockmvc.specification.MockMvcRequestSpecification) MockHttpServletRequestBuilderInterceptor(io.restassured.module.mockmvc.intercept.MockHttpServletRequestBuilderInterceptor) MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) Test(org.junit.Test)

Example 28 with MockMvcRequestSpecification

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

the class MockMvcRequestSpecificationMergingTest method base_path_is_overwritten_when_defined_in_specification.

@Test
public void base_path_is_overwritten_when_defined_in_specification() {
    // Given
    RestAssuredMockMvc.basePath = "/something";
    MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().setBasePath("basePath").build();
    // When
    MockMvcRequestSpecification spec = RestAssuredMockMvc.given().body("body1").spec(specToMerge);
    // Then
    RestAssuredMockMvc.reset();
    Assertions.assertThat(implOf(spec).getBasePath()).isEqualTo("basePath");
}
Also used : MockMvcRequestSpecification(io.restassured.module.mockmvc.specification.MockMvcRequestSpecification) MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) Test(org.junit.Test)

Example 29 with MockMvcRequestSpecification

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

the class MockMvcRequestSpecificationMergingTest method cookies_are_not_overwritten_when_not_defined_in_specification.

@Test
public void cookies_are_not_overwritten_when_not_defined_in_specification() {
    // Given
    Cookie thisCookie = new Cookie.Builder("cookie2", "value2").build();
    MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().addQueryParam("param1", "value1").build();
    // When
    MockMvcRequestSpecification spec = RestAssuredMockMvc.given().cookie(thisCookie).spec(specToMerge);
    // Then
    Assertions.assertThat(implOf(spec).getCookies()).containsOnly(thisCookie);
    Assertions.assertThat(implOf(spec).getQueryParams()).containsOnly(entry("param1", "value1"));
}
Also used : Cookie(io.restassured.http.Cookie) MockMvcRequestSpecification(io.restassured.module.mockmvc.specification.MockMvcRequestSpecification) MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) Test(org.junit.Test)

Example 30 with MockMvcRequestSpecification

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

the class MockMvcRequestSpecificationMergingTest method mock_mvc_factory_is_not_overwritten_when_not_defined_in_specification.

@Test
public void mock_mvc_factory_is_not_overwritten_when_not_defined_in_specification() {
    // Given
    MockMvc mockMvcInstance = MockMvcBuilders.standaloneSetup(new GreetingController()).build();
    MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().addQueryParam("param1", "value1").build();
    // When
    MockMvcRequestSpecification spec = RestAssuredMockMvc.given().mockMvc(mockMvcInstance).spec(specToMerge);
    // Then
    assertThat(Whitebox.getInternalState(implOf(spec).getMockMvcFactory(), "mockMvc")).isSameAs(mockMvcInstance);
    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) GreetingController(io.restassured.module.mockmvc.http.GreetingController) MockMvc(org.springframework.test.web.servlet.MockMvc) 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