Search in sources :

Example 16 with MockMvcRequestSpecBuilder

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

Example 17 with MockMvcRequestSpecBuilder

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");
}
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 18 with MockMvcRequestSpecBuilder

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"));
}
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)

Example 19 with MockMvcRequestSpecBuilder

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);
}
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 20 with MockMvcRequestSpecBuilder

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");
}
Also used : MockMvcRequestSpecification(io.restassured.module.mockmvc.specification.MockMvcRequestSpecification) PrintStream(java.io.PrintStream) MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) StringWriter(java.io.StringWriter) GreetingController(io.restassured.module.mockmvc.http.GreetingController) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) 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