Search in sources :

Example 11 with MockMvcRequestSpecBuilder

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

the class MockMvcRequestSpecificationMergingTest method form_params_are_merged.

@Test
public void form_params_are_merged() {
    // Given
    MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().addFormParam("param1", "value1").build();
    // When
    MockMvcRequestSpecification spec = RestAssuredMockMvc.given().formParam("param2", "value2").spec(specToMerge);
    // Then
    Assertions.assertThat(implOf(spec).getFormParams()).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 MockMvcRequestSpecBuilder

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

the class MockMvcRequestSpecificationMergingTest method configurations_are_merged.

@Test
public void configurations_are_merged() {
    // Given
    RestAssuredMockMvcConfig cfg1 = new RestAssuredMockMvcConfig().with().jsonConfig(jsonConfig().with().numberReturnType(JsonPathConfig.NumberReturnType.FLOAT_AND_DOUBLE));
    MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().setConfig(cfg1).build();
    // When
    RestAssuredMockMvcConfig cfg2 = new RestAssuredMockMvcConfig().sessionConfig(sessionConfig().sessionIdName("php"));
    MockMvcRequestSpecification spec = RestAssuredMockMvc.given().config(cfg2).spec(specToMerge);
    // Then
    RestAssuredConfig mergedConfig = implOf(spec).getRestAssuredConfig();
    assertThat(mergedConfig.getSessionConfig().sessionIdName()).isEqualTo("php");
    assertThat(mergedConfig.getJsonConfig().numberReturnType()).isEqualTo(JsonPathConfig.NumberReturnType.FLOAT_AND_DOUBLE);
}
Also used : MockMvcRequestSpecification(io.restassured.module.mockmvc.specification.MockMvcRequestSpecification) RestAssuredMockMvcConfig(io.restassured.module.mockmvc.config.RestAssuredMockMvcConfig) MockMvcRequestSpecBuilder(io.restassured.module.mockmvc.specification.MockMvcRequestSpecBuilder) RestAssuredConfig(io.restassured.config.RestAssuredConfig) Test(org.junit.Test)

Example 13 with MockMvcRequestSpecBuilder

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

the class MockMvcRequestSpecificationMergingTest method attributes_are_merged.

@Test
public void attributes_are_merged() {
    // Given
    MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().addAttribute("param1", "value1").build();
    // When
    MockMvcRequestSpecification spec = RestAssuredMockMvc.given().attribute("param2", "value2").spec(specToMerge);
    // Then
    Assertions.assertThat(implOf(spec).getAttributes()).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 14 with MockMvcRequestSpecBuilder

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

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

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