Search in sources :

Example 31 with MockMvcRequestSpecBuilder

use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder 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 32 with MockMvcRequestSpecBuilder

use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder 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 33 with MockMvcRequestSpecBuilder

use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder 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 34 with MockMvcRequestSpecBuilder

use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder 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 35 with MockMvcRequestSpecBuilder

use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder 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)36 Test (org.junit.Test)36 MockMvcRequestSpecification (io.restassured.module.mockmvc.specification.MockMvcRequestSpecification)31 GreetingController (io.restassured.module.mockmvc.http.GreetingController)7 ResponseSpecBuilder (io.restassured.builder.ResponseSpecBuilder)4 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)4 RestAssuredMockMvcConfig (io.restassured.module.mockmvc.config.RestAssuredMockMvcConfig)3 MockMvcAuthenticationScheme (io.restassured.module.mockmvc.specification.MockMvcAuthenticationScheme)3 PrintStream (java.io.PrintStream)3 StringWriter (java.io.StringWriter)3 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)3 Cookie (io.restassured.http.Cookie)2 Header (io.restassured.http.Header)2 PostController (io.restassured.module.mockmvc.http.PostController)2 MockHttpServletRequestBuilderInterceptor (io.restassured.module.mockmvc.intercept.MockHttpServletRequestBuilderInterceptor)2 MockMvc (org.springframework.test.web.servlet.MockMvc)2 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)2 LogConfig (io.restassured.config.LogConfig)1 RestAssuredConfig (io.restassured.config.RestAssuredConfig)1 SecuredController (io.restassured.module.mockmvc.http.SecuredController)1