Search in sources :

Example 16 with MockMvcRequestSpecification

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

use of io.restassured.module.mockmvc.specification.MockMvcRequestSpecification 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)

Example 18 with MockMvcRequestSpecification

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

the class MockMvcRequestSpecificationMergingTest method base_path_is_not_overwritten_when_not_defined_in_specification.

@Test
public void base_path_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).getBasePath()).isEqualTo(RestAssuredMockMvc.basePath);
    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 19 with MockMvcRequestSpecification

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

the class MockMvcRequestSpecificationMergingTest method content_type_is_overwritten_when_defined_in_specification.

@Test
public void content_type_is_overwritten_when_defined_in_specification() {
    // Given
    MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().setContentType(ContentType.JSON).build();
    // When
    MockMvcRequestSpecification spec = RestAssuredMockMvc.given().contentType(ContentType.XML).spec(specToMerge);
    // Then
    Assertions.assertThat(implOf(spec).getRequestContentType()).isEqualTo(ContentType.JSON.toString());
}
Also used : MockMvcRequestSpecification(io.restassured.module.mockmvc.specification.MockMvcRequestSpecification) MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) Test(org.junit.Test)

Example 20 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_using_dsl_and_defined_in_specification.

@Test
public void authentication_is_overwritten_when_using_dsl_and_defined_in_specification() {
    // Given
    MockMvcAuthenticationScheme otherAuth = RestAssuredMockMvc.principal("other");
    MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().setAuth(otherAuth).build();
    // When
    MockMvcRequestSpecification spec = RestAssuredMockMvc.given().auth().principal("this").and().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)

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